| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.beauti.datapanel; |
| 27 |
|
| 28 |
import dr.app.beauti.options.PartitionSubstitutionModel; |
| 29 |
import jam.panels.OptionsPanel; |
| 30 |
|
| 31 |
import javax.swing.*; |
| 32 |
import javax.swing.border.EmptyBorder; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class SelectModelDialog { |
| 40 |
|
| 41 |
private JFrame frame; |
| 42 |
|
| 43 |
JComboBox modelCombo; |
| 44 |
JCheckBox copyCheck; |
| 45 |
JTextField nameField; |
| 46 |
|
| 47 |
OptionsPanel optionPanel; |
| 48 |
|
| 49 |
public SelectModelDialog(JFrame frame) { |
| 50 |
this.frame = frame; |
| 51 |
|
| 52 |
modelCombo = new JComboBox(); |
| 53 |
|
| 54 |
copyCheck = new JCheckBox("Rename substitution model partition to:"); |
| 55 |
nameField = new JTextField(); |
| 56 |
nameField.setColumns(20); |
| 57 |
nameField.setEnabled(false); |
| 58 |
|
| 59 |
optionPanel = new OptionsPanel(12, 12); |
| 60 |
optionPanel.addComponentWithLabel("Partition Model:", modelCombo); |
| 61 |
optionPanel.addComponents(copyCheck, nameField); |
| 62 |
|
| 63 |
copyCheck.addItemListener( |
| 64 |
new java.awt.event.ItemListener() { |
| 65 |
public void itemStateChanged(java.awt.event.ItemEvent ev) { |
| 66 |
nameField.setEnabled(copyCheck.isSelected()); |
| 67 |
} |
| 68 |
} |
| 69 |
); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
public int showDialog(Object[] models) { |
| 74 |
|
| 75 |
modelCombo.removeAllItems(); |
| 76 |
for (Object model : models) { |
| 77 |
modelCombo.addItem(model); |
| 78 |
} |
| 79 |
|
| 80 |
JOptionPane optionPane = new JOptionPane(optionPanel, |
| 81 |
JOptionPane.QUESTION_MESSAGE, |
| 82 |
JOptionPane.OK_CANCEL_OPTION, |
| 83 |
null, |
| 84 |
null, |
| 85 |
null); |
| 86 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 87 |
|
| 88 |
final JDialog dialog = optionPane.createDialog(frame, "Create New Model"); |
| 89 |
dialog.pack(); |
| 90 |
|
| 91 |
dialog.setVisible(true); |
| 92 |
|
| 93 |
int result = JOptionPane.CANCEL_OPTION; |
| 94 |
Integer value = (Integer) optionPane.getValue(); |
| 95 |
if (value != null && value != -1) { |
| 96 |
result = value; |
| 97 |
} |
| 98 |
|
| 99 |
return result; |
| 100 |
} |
| 101 |
|
| 102 |
public PartitionSubstitutionModel getModel() { |
| 103 |
return (PartitionSubstitutionModel)modelCombo.getSelectedItem(); |
| 104 |
} |
| 105 |
|
| 106 |
public boolean getMakeCopy() { |
| 107 |
return copyCheck.isSelected(); |
| 108 |
} |
| 109 |
|
| 110 |
public String getName() { |
| 111 |
return nameField.getText(); |
| 112 |
} |
| 113 |
|
| 114 |
} |