package de.FeatureModellingTool.Documentation;
import de.reuse.GroupMap;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.Connector.View_IDMap.View_IDMap;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.io.File;
import java.util.Iterator;
/**
* Created by IntelliJ IDEA.
* User: YangJun
* Date: 2005-01-15
* Time: 15:04:36
* To change this template use Options | File Templates.
*/
public class SetDialog extends JDialog implements ConstantDefinition {
private Container contentPane;
private JButton nextButton;
private JRadioButton htmlButton;
private JRadioButton rtfButton;
private JRadioButton singleButton;
private JRadioButton multiButton;
private JRadioButton entireButton;
private JRadioButton compressedButton;
private ButtonGroup docGroup;
private ButtonGroup fileGroup;
private ButtonGroup featureGroup;
private JFileChooser fileChooser = null;
private JFrame parent = null;
private File directory = null;
protected FeatureModel featureModel = null;
protected ConstraintModel constraintModel = null;
protected View_IDMap view_IDMap = null;
private int docType;
private int fileOutMode;
private int featureOutMode;
private boolean html;
private boolean rtf;
private boolean single;
private boolean multi;
private boolean entire;
private boolean compressed;
public SetDialog(JFrame parent, FeatureModel featureModel, View_IDMap view_IDMap) {
super(parent, "�ĵ��������", true);
this.parent = parent;
this.featureModel = featureModel;
this.view_IDMap = view_IDMap;
if (fileChooser == null) fileChooser = new JFileChooser();
preSet();
//��ư�ť
htmlButton = new JRadioButton("Html�ĵ����", html);
rtfButton = new JRadioButton("RTF�ĵ����", rtf);
docGroup = new ButtonGroup();
docGroup.add(htmlButton);
docGroup.add(rtfButton);
JPanel docPanel = new JPanel();
docPanel.setLayout(new BoxLayout(docPanel, BoxLayout.Y_AXIS));
docPanel.add(new Label(""));
docPanel.add(htmlButton);
docPanel.add(rtfButton);
singleButton = new JRadioButton("���Ϊһ���ļ�", single);
multiButton = new JRadioButton("����ͼ��֯�ļ�", multi);
fileGroup = new ButtonGroup();
fileGroup.add(singleButton);
fileGroup.add(multiButton);
JPanel filePanel = new JPanel();
filePanel.setLayout(new BoxLayout(filePanel, BoxLayout.Y_AXIS));
filePanel.setBorder(BorderFactory.createTitledBorder("���������"));
filePanel.add(singleButton);
filePanel.add(multiButton);
entireButton = new JRadioButton("�������feature����Ŀ", entire);
compressedButton = new JRadioButton("ֻ��������ݵ���Ŀ", compressed);
featureGroup = new ButtonGroup();
featureGroup.add(entireButton);
featureGroup.add(compressedButton);
JPanel featurePanel = new JPanel();
featurePanel.setLayout(new BoxLayout(featurePanel, BoxLayout.Y_AXIS));
featurePanel.setBorder(BorderFactory.createTitledBorder("������ݶ���"));
featurePanel.add(entireButton);
featurePanel.add(compressedButton);
JPanel fileFeature = new JPanel();
//fileFeature.setLayout(new BoxLayout(fileFeature,BoxLayout.X_AXIS));
fileFeature.setLayout(new FlowLayout());
fileFeature.add(filePanel);
fileFeature.add(featurePanel);
fileFeature.setMinimumSize(fileFeature.getPreferredSize());
nextButton = new JButton("��һ��");
JPanel nextPanel = new JPanel();
nextPanel.add(BorderLayout.CENTER, nextButton);
//�������岼��
contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(BorderLayout.NORTH, docPanel);
contentPane.add(BorderLayout.CENTER, fileFeature);
contentPane.add(BorderLayout.SOUTH, nextPanel);
//�Ի�����������
setSize(360, 250);
setResizable(false);
setLocationRelativeTo(null);
//��ť�����Եij�ʼ����
if (html) {
singleButton.setEnabled(false);
multiButton.setEnabled(false);
entireButton.setEnabled(false);
compressedButton.setEnabled(false);
} else {
singleButton.setEnabled(true);
multiButton.setEnabled(true);
entireButton.setEnabled(true);
compressedButton.setEnabled(true);
}
nextButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onNext();
}
});
htmlButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onHtmlOrRtf();
}
});
rtfButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onHtmlOrRtf();
}
});
}
private void onNext() {
if (htmlButton.isSelected())
docType = HTML;
else
docType = RTF;
if (singleButton.isSelected())
fileOutMode = SINGLE;
else
fileOutMode = MULTI;
if (entireButton.isSelected())
featureOutMode = ENTIRE;
else
featureOutMode = COMPRESSED;
if (setDirectory()) saveSet();
dispose();
}
//�����ĸ���ť��������rtf�ĵ����ʱ������
private void onHtmlOrRtf() {
if (htmlButton.isSelected()) {
html = true;
rtf = false;
singleButton.setEnabled(false);
multiButton.setEnabled(false);
entireButton.setEnabled(false);
compressedButton.setEnabled(false);
} else {
html = false;
rtf = true;
singleButton.setEnabled(true);
multiButton.setEnabled(true);
entireButton.setEnabled(true);
compressedButton.setEnabled(true);
}
}
protected void preSet() {
//text
html = true;
rtf = false;
single = true;
multi = false;
entire = true;
compressed = false;
}
protected void saveSet() {
}
//Yangjnu �������ļ�������ļ���
public boolean setDirectory() {
String oldName = "";
int oldMode = 0;
if (fileChooser != null) {
oldName = fileChooser.getName();
oldMode = fileChooser.getFileSelectionMode();
}
fileChooser.setDialogTitle("ѡ���ĵ������Ŀ���ļ���");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = fileChooser.showDialog(parent, "ȷ��");
if (result == JFileChooser.APPROVE_OPTION) {
directory = fileChooser.getSelectedFile();
if ((directory != null) && (directory.isDirectory())) {
if (docType == HTML)
outputHtmlDocument(directory); //���Html�ĵ�
else if (docType == RTF)
outputRtfDocument(directory); //���Rtf�ĵ�
else
; //���Ҫ���������ͣ�������
}
return true;//�ɹ��Ľ��������
} else {
if (fileChooser != null) {
fileChooser.setName(oldName);
fileChooser.setFileSelectionMode(oldMode);
}
return false;//������
}
}
protected GroupMap getView_FIDMap() {
if (view_IDMap == null) return null;
GroupMap gm = view_IDMap.getView_IDMap();
Iterator keyIterator = gm.keySet().iterator();
while (keyIterator != null && keyIterator.hasNext()) {
String key = (String) keyIterator.next();
Iterator idIterator = gm.get(key).iterator();
while (idIterator != null && idIterator.hasNext()) {
String id = (String) idIterator.next();
if (!featureModel.containsFeature(id)) {
gm.remove(key, id);
}
}
}
return gm;
}
/////////////////////////////////////////////////////
protected void outputHtmlDocument(File directory) {
GroupMap gm = getView_FIDMap();
DocsProducer producer = new DocsProducerImpl(featureModel, directory);
producer.featuresProduce();
producer.othersProduce(gm);
}
//YangJun
protected void outputRtfDocument(File directory) {
GroupMap gm = getView_FIDMap();
RtfDocsProducer producer = new RtfDocsProducer(featureModel, directory);
producer.docsProduce(gm, fileOutMode, featureOutMode);
}
}