关于parameter panel制作:
1,丛次:最外层---Layout:borderLayout.center(paramPanel)
---customPanel(包含paramPanel,并将paramPanel放到JScrollPanel中。设置parameterChanged)
次外层---Layout:分为两层panel,外层:FlowLayout.leading, 内层:GridBagLayout---
---paramPanel:内层分别为三个titleBorderPanel,外层包含三个titleBorderPanel
最内层---layout:GridBagLayout,titleBorderPanel
Code Following:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Hashtable;
import javax.swing.JScrollPane;
import com.kensingtonspace.sdk.impl.EasyCustomPanel;
import com.kensingtonspace.sdk.node.NodeException;
public class NewSim4CustomPane extends EasyCustomPanel{
private NewSim4ParamPanel sim4Param;
public void initialise(Hashtable parameters, Hashtable inputDescriptors) {
super.initialise(parameters, inputDescriptors);
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(600,300));
sim4Param = new NewSim4ParamPanel();
sim4Param.initialise(parameters, inputDescriptors);
this.add(new JScrollPane(sim4Param), BorderLayout.CENTER);
}
public void parameterChanged(String s) throws NodeException {
super.parameterChanged(s);
this.sim4Param.parameterChanged(s);
}
public void inputDescriptionChanged(String input) throws NodeException {
super.inputDescriptionChanged(input);
this.sim4Param.inputDescriptionChanged(input);
}
}
--------------------------------------------------------------------------------------------------------------------------------
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.Hashtable;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import com.kensingtonspace.sdk.impl.EasyCustomPanel;
import com.kensingtonspace.sdk.node.NodeException;
public class NewSim4ParamPanel extends EasyCustomPanel{
private NewSim4CreateTitleBorderPanel titleBorderPanel1;
private NewSim4CreateTitleBorderPanel titleBorderPanel2;
private NewSim4CreateTitleBorderPanel titleBorderPanel3;
public void initialise(Hashtable parameters, Hashtable inputDescriptors) {
super.initialise(parameters, inputDescriptors);
FlowLayout fl = new FlowLayout(FlowLayout.LEADING);
this.setLayout(fl);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
JPanel jpparam = new JPanel();
jpparam.setLayout(gridbag);
//titleBorderPanel1
JComponent[] jcomponent1 = {new JTextField(), new JTextField(), new JTextField(), new JTextField()};
String[] labelName1 = {"Word size for blast hits", "Limits for terminating word extensions", "Threshold for MSP scores when determining the basic `exon cores'", "Threshold for MSP scores when aligning as-yet-unmatched fragments"};
String[] panel1 = {NewSim4Constants.W_F_B_H,NewSim4Constants.L_F_T_W_E,NewSim4Constants.T_F_MSP_SCORES_D,NewSim4Constants.T_F_MSP_SCORES_A};
String borderTitle1 = "Parameters internal to the blast-like procedure";
titleBorderPanel1 = new NewSim4CreateTitleBorderPanel(parameters,taskEditor,labelName1,panel1,4,jcomponent1, borderTitle1);
c.gridx = 0; c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.HORIZONTAL;
c.gridheight = 1;
c.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(titleBorderPanel1, c);
jpparam.add(titleBorderPanel1);
//titleBorderPanel2
JPanel jpparam2 = new JPanel();
FlowLayout f2 = new FlowLayout(FlowLayout.LEADING);
jpparam2.setLayout(f2);
JComponent[] jcomponent2 = {new JTextField()};
String[] labelName2 = {"Bound for 'diagonal' distance within consecutive MSPs in an exon"};
String[] panel2 = {NewSim4Constants.BOUND};
String borderTitle2 = "Additional algorithm parameters";
titleBorderPanel2 = new NewSim4CreateTitleBorderPanel(parameters,taskEditor,labelName2,panel2,1,jcomponent2, borderTitle2);
c.gridx = 0; c.gridy = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.HORIZONTAL;
c.gridheight = 1;
c.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(titleBorderPanel2, c);
jpparam.add(titleBorderPanel2);
//titleBorderPanel3
JPanel jpparam3 = new JPanel();
FlowLayout f3 = new FlowLayout(FlowLayout.LEFT);
jpparam3.setLayout(f3);
JComponent[] jcomponent3 = {new JComboBox(), new JComboBox(),new JTextField(), new JTextField(), new JComboBox(), new JComboBox()};
String[] labelName3 = {"Search direction", "Output format", "Report the fragment containing the poly-A tail (if found)", "MSPs' weight",
"Requests an additional search for small marginal exons", "Controls the set of characters allowed in the input sequences"};
String[] panel3 = {NewSim4Constants.S_D, NewSim4Constants.OUTPUT_FORMAT,NewSim4Constants.REPORT, NewSim4Constants.MSPS_WEIGHT,NewSim4Constants.REQUESTS, NewSim4Constants.CONTROLS};
String borderTitle3 = "Context Parameters";
titleBorderPanel3 = new NewSim4CreateTitleBorderPanel(parameters,taskEditor,labelName3,panel3,6,jcomponent3, borderTitle3);
c.gridx = 0; c.gridy = 2;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.HORIZONTAL;
c.gridheight = 1;
c.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(titleBorderPanel3, c);
jpparam.add(titleBorderPanel3);
this.add(jpparam);
}
public void parameterChanged(String name) throws NodeException {
super.parameterChanged(name);
titleBorderPanel1.parameterChanged(name);
titleBorderPanel2.parameterChanged(name);
titleBorderPanel3.parameterChanged(name);
}
}
--------------------------------------------------------------------------------------------------------------
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.sql.ResultSet;
import java.util.Hashtable;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import bioscience.util.datamanager.ksc.KSequenceCollection;
import com.kensingtonspace.sdk.node.NodeDescriptor;
import com.kensingtonspace.sdk.node.NodeException;
import com.kensingtonspace.tasknode.util.TaskNodeEditor;
public class NewSim4CreateTitleBorderPanel extends JPanel{
private static final long serialVersionUID = -8595914862995289867L;
NodeDescriptor node;
protected JLabel label;
protected JTextField textfield;
protected JComboBox combobox;
protected JComponent jc;
protected Hashtable parameters;
private TaskNodeEditor taskEditor;
private String borderTitle;
private int noOfLabel = 0;
private JComponent[] al_jc;
private String cpntname = null;
private String[] componentName = null;
public NewSim4CreateTitleBorderPanel(Hashtable parameters, TaskNodeEditor taskEditor,
String[] labelName, String[] componentName, int noOfLabel, JComponent[] al_jc, String borderTitle){
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gridbag);
this.setBorder(BorderFactory.createTitledBorder
(borderTitle));
this.parameters = parameters;
this.borderTitle = borderTitle;
this.noOfLabel = noOfLabel;
this.componentName = componentName;
this.al_jc = al_jc;
int j=0;
for(int i=0; i<noOfLabel; i++){
String labname = labelName[i];
cpntname = componentName[i];
JComponent jcType = (JComponent)al_jc[i];
label = new JLabel(labname);
c.gridx = 0;
c.gridy = i;
c.gridwidth = 1;
c.weightx = 1;
c.weighty = 0;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(1, 0, 1, 0);
gridbag.setConstraints(label, c);
this.add(label);
if (jcType instanceof JTextField) {
jc = taskEditor.createProperty(cpntname, false).getUI();
label.setLabelFor(jc);
c.gridx = 1;
c.gridy = i;
c.gridwidth = 1;
c.gridheight = 1;//
c.weightx = 1;
c.insets = new Insets(1, 30, 1, 10);
jc.setMaximumSize(jc.getPreferredSize());
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(jc, c);
this.add(jc);
}else if(jcType instanceof JComboBox){
String[][] comboBoxItems = {NewSim4Constants.ComboBox_S_D, NewSim4Constants.ComboBox_REQUESTS,NewSim4Constants.ComboBox_CONTROLS};
jc = taskEditor.createProperty(cpntname, false).getUI();
jc.setSize(new Dimension(200,20));
label.setLabelFor(jc);
c.gridx = 1;
c.gridy = i;
c.gridwidth = 1;
c.weightx = 1;
c.insets = new Insets(1, 30, 1, 10);
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(jc, c);
this.add(jc);
}
}
}
public String getStringValue(JComponent jc){
if (jc instanceof JTextField) {
String value_textfield = ((JTextField)jc).getText().trim();
return value_textfield;
}else {
String value_combobox = ((String)((JComboBox)jc).getSelectedItem()).trim();
return value_combobox;
}
}
public void parameterChanged(String name) throws NodeException {
for(int i=0; i<noOfLabel; i++){
if(name.equals(componentName[i])){
this.getStringValue(al_jc[i]);
}
if(name.equals(NewSim4Constants.OUTPUT_FORMAT)){
boolean flag = false;
node = (NodeDescriptor) parameters.get(NodeDescriptor.KEY_NODE_DESCRIPTOR);
String aValue = (String)parameters.get(NewSim4Constants.OUTPUT_FORMAT);
if(aValue.equals("1") || aValue.equals("2") || aValue.equals("5")){
node.removeOutput(NewSim4Node.SC);
node.removeOutput(NewSim4Node.TABLE_FORMAT_EXPORT);
}else {
node.addOutput(NewSim4Node.SC, KSequenceCollection.class, true);
node.addOutput(NewSim4Node.TABLE_FORMAT_EXPORT, ResultSet.class);
}
}
}
}
}
Swing Panel Nest
最新推荐文章于 2021-12-18 14:48:30 发布