| 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.bss; |
| 27 |
|
| 28 |
import jam.panels.OptionsPanel; |
| 29 |
|
| 30 |
import java.awt.BorderLayout; |
| 31 |
import java.awt.Dimension; |
| 32 |
import java.awt.Frame; |
| 33 |
import java.awt.event.ActionEvent; |
| 34 |
import java.awt.event.ActionListener; |
| 35 |
import java.awt.event.ItemEvent; |
| 36 |
import java.awt.event.ItemListener; |
| 37 |
|
| 38 |
import javax.swing.JButton; |
| 39 |
import javax.swing.JDialog; |
| 40 |
import javax.swing.JFrame; |
| 41 |
import javax.swing.JLabel; |
| 42 |
import javax.swing.JPanel; |
| 43 |
import javax.swing.SwingConstants; |
| 44 |
import javax.swing.SwingUtilities; |
| 45 |
|
| 46 |
import dr.app.gui.components.RealNumberField; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public class BranchSubstitutionModelEditor { |
| 53 |
|
| 54 |
|
| 55 |
private PartitionDataList dataList = null; |
| 56 |
private int row; |
| 57 |
|
| 58 |
|
| 59 |
private OptionsPanel optionPanel; |
| 60 |
private DisabledItemsComboBox substitutionCombo; |
| 61 |
private RealNumberField[] substitutionParameterFields; |
| 62 |
|
| 63 |
|
| 64 |
private JButton done; |
| 65 |
private JButton cancel; |
| 66 |
|
| 67 |
|
| 68 |
private JDialog window; |
| 69 |
private Frame owner; |
| 70 |
|
| 71 |
public BranchSubstitutionModelEditor(PartitionDataList dataList, int row) { |
| 72 |
|
| 73 |
this.dataList = dataList; |
| 74 |
this.row = row; |
| 75 |
|
| 76 |
substitutionParameterFields = new RealNumberField[PartitionData.substitutionParameterNames.length]; |
| 77 |
window = new JDialog(owner, "Setup substitution model for partition " + (row + 1)); |
| 78 |
optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER); |
| 79 |
|
| 80 |
substitutionCombo = new DisabledItemsComboBox(); |
| 81 |
substitutionCombo.setOpaque(false); |
| 82 |
|
| 83 |
int indexOf = 0; |
| 84 |
for (String substitutionModel : PartitionData.substitutionModels) { |
| 85 |
|
| 86 |
if (PartitionData.substitutionCompatibleDataTypes[indexOf] == dataList.get(row).dataTypeIndex) { |
| 87 |
|
| 88 |
substitutionCombo.addItem(substitutionModel, false); |
| 89 |
|
| 90 |
} else { |
| 91 |
|
| 92 |
substitutionCombo.addItem(substitutionModel, true); |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
indexOf++; |
| 97 |
} |
| 98 |
|
| 99 |
substitutionCombo.addItemListener(new ListenSubstitutionCombo()); |
| 100 |
|
| 101 |
for (int i = 0; i < PartitionData.substitutionParameterNames.length; i++) { |
| 102 |
|
| 103 |
substitutionParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE); |
| 104 |
substitutionParameterFields[i].setColumns(8); |
| 105 |
substitutionParameterFields[i].setValue(this.dataList.get(row).substitutionParameterValues[i]); |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
setSubstitutionArguments(); |
| 110 |
|
| 111 |
|
| 112 |
JPanel buttonsHolder = new JPanel(); |
| 113 |
buttonsHolder.setOpaque(false); |
| 114 |
|
| 115 |
cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON)); |
| 116 |
cancel.addActionListener(new ListenCancel()); |
| 117 |
buttonsHolder.add(cancel); |
| 118 |
|
| 119 |
done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON)); |
| 120 |
done.addActionListener(new ListenOk()); |
| 121 |
buttonsHolder.add(done); |
| 122 |
|
| 123 |
|
| 124 |
owner = Utils.getActiveFrame(); |
| 125 |
window.setLocationRelativeTo(owner); |
| 126 |
window.getContentPane().setLayout(new BorderLayout()); |
| 127 |
window.getContentPane().add(optionPanel, BorderLayout.CENTER); |
| 128 |
window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH); |
| 129 |
window.pack(); |
| 130 |
|
| 131 |
|
| 132 |
substitutionCombo.setSelectedIndex(dataList.get(row).substitutionModelIndex); |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
private void setSubstitutionArguments() { |
| 137 |
|
| 138 |
optionPanel.removeAll(); |
| 139 |
optionPanel.addComponents(new JLabel("Substitution model:"), substitutionCombo); |
| 140 |
optionPanel.addSeparator(); |
| 141 |
optionPanel.addLabel("Set parameter values:"); |
| 142 |
|
| 143 |
int index = substitutionCombo.getSelectedIndex(); |
| 144 |
|
| 145 |
for (int i = 0; i < PartitionData.substitutionParameterIndices[index].length; i++) { |
| 146 |
|
| 147 |
int k = PartitionData.substitutionParameterIndices[index][i]; |
| 148 |
|
| 149 |
JPanel panel = new JPanel(new BorderLayout(6, 6)); |
| 150 |
panel.add(substitutionParameterFields[k], BorderLayout.WEST); |
| 151 |
panel.setOpaque(false); |
| 152 |
optionPanel.addComponentWithLabel(PartitionData.substitutionParameterNames[k] + ":", panel); |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
window.validate(); |
| 157 |
window.repaint(); |
| 158 |
} |
| 159 |
|
| 160 |
private class ListenSubstitutionCombo implements ItemListener { |
| 161 |
public void itemStateChanged(ItemEvent ie) { |
| 162 |
|
| 163 |
setSubstitutionArguments(); |
| 164 |
|
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
public void collectSettings() { |
| 169 |
|
| 170 |
dataList.get(row).substitutionModelIndex = substitutionCombo.getSelectedIndex(); |
| 171 |
for (int i = 0; i < PartitionData.substitutionParameterNames.length; i++) { |
| 172 |
|
| 173 |
dataList.get(row).substitutionParameterValues[i] = substitutionParameterFields[i].getValue(); |
| 174 |
|
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
private class ListenOk implements ActionListener { |
| 179 |
public void actionPerformed(ActionEvent ev) { |
| 180 |
|
| 181 |
window.setVisible(false); |
| 182 |
collectSettings(); |
| 183 |
|
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
private class ListenCancel implements ActionListener { |
| 188 |
public void actionPerformed(ActionEvent ev) { |
| 189 |
|
| 190 |
window.setVisible(false); |
| 191 |
|
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
public void showWindow() { |
| 196 |
window.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); |
| 197 |
window.setSize(new Dimension(450, 400)); |
| 198 |
window.setMinimumSize(new Dimension(100, 100)); |
| 199 |
window.setResizable(true); |
| 200 |
window.setModal(true); |
| 201 |
window.setVisible(true); |
| 202 |
} |
| 203 |
|
| 204 |
public void launch() { |
| 205 |
|
| 206 |
if (SwingUtilities.isEventDispatchThread()) { |
| 207 |
showWindow(); |
| 208 |
} else { |
| 209 |
SwingUtilities.invokeLater(new Runnable() { |
| 210 |
public void run() { |
| 211 |
showWindow(); |
| 212 |
} |
| 213 |
}); |
| 214 |
} |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
} |