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