📄 testsetupdialog.java
字号:
package abchr.gui;
import abchr.*;
import guiutils.FlexibleGridLayout;
import guiutils.LineLayout;
import org.jdom.Document;
import org.jdom.Namespace;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestSetupDialog extends JDialog {
private boolean ok;
private SaveConfigAction saveSetupAction;
private TestNameModule testNameModule;
private TestNameSetupPanel testNameSetupPanel;
private RawTestConfig testConfig;
private TestConfigSetupPanel testConfigSetupPanel;
private RatingScaleModule ratingScaleConfig;
private RatingScaleSetupPanel ratingScaleSetupPanel;
private EncryptionKeyModule encryptionKeyModule;
private EncryptionKeySetupPanel encryptionKeySetupPanel;
private ABXConfigModule abxConfigModule;
private ABXSetupPanel abxSetupPanel;
private ConfigModule[] configModules;
public TestSetupDialog(ProjectFrame owner) {
super(owner,"Setup Test",true);
this.setResizable(false);
this.getContentPane().setLayout(new BorderLayout());
JPanel centerPanel=new JPanel(new FlexibleGridLayout(10,2,5,5,true));
centerPanel.setBorder(BorderFactory.createEmptyBorder(8,8,8,8));
/*testNameSetupPanel=new TestNameSetupPanel();
this.getContentPane().add(testNameSetupPanel,BorderLayout.NORTH);
testConfigSetupPanel=new TestConfigSetupPanel();
this.getContentPane().add(testConfigSetupPanel,BorderLayout.CENTER);*/
JPanel p=testNameSetupPanel=new TestNameSetupPanel();
for(int i=0,n=p.getComponentCount();i<n;i++) {
centerPanel.add(p.getComponent(0));
}
p=testConfigSetupPanel=new TestConfigSetupPanel();
for(int i=0,n=p.getComponentCount();i<n;i++) {
centerPanel.add(p.getComponent(0));
}
this.getContentPane().add(centerPanel,BorderLayout.CENTER);
JPanel bottomPanel=new JPanel(new LineLayout(LineLayout.RIGHT_ALIGN,true));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
encryptionKeySetupPanel=new EncryptionKeySetupPanel();
bottomPanel.add(encryptionKeySetupPanel);
bottomPanel.add(LineLayout.lineBreak());
ratingScaleSetupPanel=new RatingScaleSetupPanel(this);
bottomPanel.add(ratingScaleSetupPanel);
bottomPanel.add(LineLayout.lineBreak());
abxSetupPanel=new ABXSetupPanel();
bottomPanel.add(abxSetupPanel);
bottomPanel.add(LineLayout.lineBreak());
saveSetupAction=new SaveConfigAction(this) {
public void actionPerformed(ActionEvent e) {
try {
testConfigSetupPanel.updateConfig();
} catch(IllegalStateException e1) {
JOptionPane.showMessageDialog(TestSetupDialog.this,e1.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
return;
}
super.actionPerformed(e);
}
};
JButton saveButton=new JButton(saveSetupAction);
bottomPanel.add(saveButton);
JButton cancelButton=new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(getOwner(),"Discard current setup?","Cancel",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION) {
ok=false;
hide();
}
}
});
bottomPanel.add(cancelButton);
JButton okButton=new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
testConfigSetupPanel.updateConfig();
} catch(IllegalStateException e1) {
JOptionPane.showMessageDialog(TestSetupDialog.this,e1.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
return;
}
ok=true;
hide();
}
});
bottomPanel.add(okButton);
this.getContentPane().add(bottomPanel,BorderLayout.SOUTH);
}
public boolean isEncryptionActive() {
return encryptionKeyModule.getEncryptionKey()!=null;
}
public Document showDialog() {
Dimension size=this.getContentPane().getPreferredSize();
Insets insets=getOwner().getInsets();
this.setBounds(getOwner().getX()+10,getOwner().getY()+10,size.width+insets.left+insets.right,size.height+insets.top+insets.bottom);
testNameModule=new TestNameModule("");
testNameSetupPanel.setModel(testNameModule);
testConfig=new RawTestConfig();
testConfigSetupPanel.setModel(testConfig);
ratingScaleConfig=new RatingScaleModule();
ratingScaleSetupPanel.setModel(ratingScaleConfig);
encryptionKeyModule=new EncryptionKeyModule(null);
encryptionKeySetupPanel.setModel(encryptionKeyModule);
abxConfigModule=new ABXConfigModule();
abxSetupPanel.setModel(abxConfigModule);
configModules=new ConfigModule[]{testNameModule,testConfig,ratingScaleConfig,encryptionKeyModule,abxConfigModule};
ok=false;
this.show();
if(ok) {
RawTestConfig.setRelativePathOutput(null);
return getXML();
}
return null;
}
public Document getXML() {
org.jdom.Element root=new org.jdom.Element("config");
Namespace namespace=Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
root.addNamespaceDeclaration(namespace);
root.setAttribute("noNamespaceSchemaLocation","config.xsd",namespace);
org.jdom.Element element;
for(int i=0;i<configModules.length;i++) {
element=configModules[i].toXML();
if(element!=null){root.addContent(element);}
}
return new Document(root);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -