| 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.tools; |
| 27 |
|
| 28 |
import dr.app.gui.components.RealNumberField; |
| 29 |
import dr.app.gui.FileDrop; |
| 30 |
import jam.panels.OptionsPanel; |
| 31 |
import dr.app.gui.components.WholeNumberField; |
| 32 |
|
| 33 |
import javax.swing.*; |
| 34 |
import javax.swing.border.Border; |
| 35 |
import javax.swing.border.EmptyBorder; |
| 36 |
import java.awt.*; |
| 37 |
import java.awt.event.ActionEvent; |
| 38 |
import java.awt.event.ActionListener; |
| 39 |
import java.awt.event.ItemListener; |
| 40 |
import java.awt.event.ItemEvent; |
| 41 |
import java.io.File; |
| 42 |
|
| 43 |
public class TreeAnnotatorDialog { |
| 44 |
private JFrame frame; |
| 45 |
|
| 46 |
private OptionsPanel optionPanel; |
| 47 |
|
| 48 |
private WholeNumberField burninStatesText = new WholeNumberField(0, Long.MAX_VALUE); |
| 49 |
private WholeNumberField burninTreesText = new WholeNumberField(0, Long.MAX_VALUE); |
| 50 |
private RealNumberField limitText = new RealNumberField(0.0, 1.0); |
| 51 |
|
| 52 |
private JComboBox summaryTreeCombo = new JComboBox(TreeAnnotator.Target.values()); |
| 53 |
private JComboBox nodeHeightsCombo = new JComboBox(TreeAnnotator.HeightsSummary.values()); |
| 54 |
|
| 55 |
private File targetFile = null; |
| 56 |
private File inputFile = null; |
| 57 |
private File outputFile = null; |
| 58 |
|
| 59 |
public TreeAnnotatorDialog(final JFrame frame) { |
| 60 |
this.frame = frame; |
| 61 |
|
| 62 |
optionPanel = new OptionsPanel(12, 12); |
| 63 |
|
| 64 |
this.frame = frame; |
| 65 |
|
| 66 |
JPanel panel = new JPanel(new BorderLayout()); |
| 67 |
panel.setOpaque(false); |
| 68 |
|
| 69 |
final JRadioButton burninStatesRadio = new JRadioButton("Specify the burnin as the number of states"); |
| 70 |
optionPanel.addSpanningComponent(burninStatesRadio); |
| 71 |
burninStatesText.setColumns(12); |
| 72 |
burninStatesText.setValue(0); |
| 73 |
burninStatesText.setToolTipText("<html>Specify the burnin as the number of states<br> in the MCMC chain</html>"); |
| 74 |
final JLabel burninStatesLabel = optionPanel.addComponentWithLabel("Burnin (as states): ", burninStatesText); |
| 75 |
|
| 76 |
final JRadioButton burninTreesRadio = new JRadioButton("Specify the burnin as the number of trees"); |
| 77 |
optionPanel.addSpanningComponent(burninTreesRadio); |
| 78 |
burninTreesText.setColumns(12); |
| 79 |
burninTreesText.setValue(0); |
| 80 |
burninTreesText.setToolTipText("<html>Specify the burnin as the number of trees<br> in the tree file</html>"); |
| 81 |
final JLabel burninTreesLabel = optionPanel.addComponentWithLabel("Burnin (as trees): ", burninTreesText); |
| 82 |
|
| 83 |
ButtonGroup group = new ButtonGroup(); |
| 84 |
group.add(burninStatesRadio); |
| 85 |
group.add(burninTreesRadio); |
| 86 |
|
| 87 |
|
| 88 |
burninStatesRadio.addItemListener(new ItemListener() { |
| 89 |
@Override |
| 90 |
public void itemStateChanged(ItemEvent e) { |
| 91 |
burninStatesLabel.setEnabled(burninStatesRadio.isSelected()); |
| 92 |
burninStatesText.setEnabled(burninStatesRadio.isSelected()); |
| 93 |
|
| 94 |
burninTreesLabel.setEnabled(!burninStatesRadio.isSelected()); |
| 95 |
burninTreesText.setEnabled(!burninStatesRadio.isSelected()); |
| 96 |
} |
| 97 |
}); |
| 98 |
burninStatesRadio.setSelected(true); |
| 99 |
|
| 100 |
limitText.setColumns(12); |
| 101 |
limitText.setValue(0.0); |
| 102 |
limitText.setToolTipText("<html>Specify a lower limit on the posterior probability<br>" + |
| 103 |
"below which a clade will not be annotated</html>"); |
| 104 |
optionPanel.addComponentWithLabel("Posterior probability limit: ", limitText); |
| 105 |
|
| 106 |
optionPanel.addComponentWithLabel("Target tree type: ", summaryTreeCombo); |
| 107 |
optionPanel.addComponentWithLabel("Node heights: ", nodeHeightsCombo); |
| 108 |
|
| 109 |
optionPanel.addSeparator(); |
| 110 |
|
| 111 |
final JButton targetFileButton = new JButton("Choose File..."); |
| 112 |
final JTextField targetFileNameText = new JTextField("not selected", 16); |
| 113 |
|
| 114 |
targetFileButton.addActionListener( new ActionListener() { |
| 115 |
public void actionPerformed(ActionEvent ae) { |
| 116 |
FileDialog dialog = new FileDialog(frame, |
| 117 |
"Select target file...", |
| 118 |
FileDialog.LOAD); |
| 119 |
|
| 120 |
dialog.setVisible(true); |
| 121 |
if (dialog.getFile() == null) { |
| 122 |
|
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
targetFile = new File(dialog.getDirectory(), dialog.getFile()); |
| 127 |
targetFileNameText.setText(targetFile.getName()); |
| 128 |
|
| 129 |
}}); |
| 130 |
targetFileNameText.setEditable(false); |
| 131 |
|
| 132 |
JPanel panel1 = new JPanel(new BorderLayout(0,0)); |
| 133 |
panel1.add(targetFileNameText, BorderLayout.CENTER); |
| 134 |
panel1.add(targetFileButton, BorderLayout.EAST); |
| 135 |
final JLabel label1 = optionPanel.addComponentWithLabel("Target Tree File: ", panel1); |
| 136 |
|
| 137 |
JButton inputFileButton = new JButton("Choose File..."); |
| 138 |
final JTextField inputFileNameText = new JTextField("not selected", 16); |
| 139 |
|
| 140 |
inputFileButton.addActionListener( new ActionListener() { |
| 141 |
public void actionPerformed(ActionEvent ae) { |
| 142 |
FileDialog dialog = new FileDialog(frame, |
| 143 |
"Select input tree file...", |
| 144 |
FileDialog.LOAD); |
| 145 |
|
| 146 |
dialog.setVisible(true); |
| 147 |
if (dialog.getFile() == null) { |
| 148 |
|
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
inputFile = new File(dialog.getDirectory(), dialog.getFile()); |
| 153 |
inputFileNameText.setText(inputFile.getName()); |
| 154 |
|
| 155 |
}}); |
| 156 |
inputFileNameText.setEditable(false); |
| 157 |
|
| 158 |
label1.setEnabled(false); |
| 159 |
targetFileNameText.setEnabled(false); |
| 160 |
targetFileButton.setEnabled(false); |
| 161 |
|
| 162 |
summaryTreeCombo.addItemListener(new ItemListener() { |
| 163 |
public void itemStateChanged(ItemEvent itemEvent) { |
| 164 |
boolean selected = summaryTreeCombo.getSelectedItem().equals(TreeAnnotator.Target.USER_TARGET_TREE); |
| 165 |
label1.setEnabled(selected); |
| 166 |
targetFileNameText.setEnabled(selected); |
| 167 |
targetFileButton.setEnabled(selected); |
| 168 |
} |
| 169 |
}); |
| 170 |
|
| 171 |
JPanel panel2 = new JPanel(new BorderLayout(0,0)); |
| 172 |
panel2.add(inputFileNameText, BorderLayout.CENTER); |
| 173 |
panel2.add(inputFileButton, BorderLayout.EAST); |
| 174 |
|
| 175 |
Color focusColor = UIManager.getColor("Focus.color"); |
| 176 |
Border focusBorder = BorderFactory.createMatteBorder( 2, 2, 2, 2, focusColor ); |
| 177 |
new FileDrop( null, inputFileNameText, focusBorder, new FileDrop.Listener() |
| 178 |
{ public void filesDropped( java.io.File[] files ) |
| 179 |
{ |
| 180 |
inputFile = files[0]; |
| 181 |
inputFileNameText.setText(inputFile.getName()); |
| 182 |
} |
| 183 |
}); |
| 184 |
|
| 185 |
optionPanel.addComponentWithLabel("Input Tree File: ", panel2); |
| 186 |
|
| 187 |
JButton outputFileButton = new JButton("Choose File..."); |
| 188 |
final JTextField outputFileNameText = new JTextField("not selected", 16); |
| 189 |
|
| 190 |
outputFileButton.addActionListener( new ActionListener() { |
| 191 |
public void actionPerformed(ActionEvent ae) { |
| 192 |
FileDialog dialog = new FileDialog(frame, |
| 193 |
"Select output file...", |
| 194 |
FileDialog.SAVE); |
| 195 |
|
| 196 |
dialog.setVisible(true); |
| 197 |
if (dialog.getFile() == null) { |
| 198 |
|
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
outputFile = new File(dialog.getDirectory(), dialog.getFile()); |
| 203 |
outputFileNameText.setText(outputFile.getName()); |
| 204 |
|
| 205 |
}}); |
| 206 |
outputFileNameText.setEditable(false); |
| 207 |
|
| 208 |
JPanel panel3 = new JPanel(new BorderLayout(0,0)); |
| 209 |
panel3.add(outputFileNameText, BorderLayout.CENTER); |
| 210 |
panel3.add(outputFileButton, BorderLayout.EAST); |
| 211 |
optionPanel.addComponentWithLabel("Output File: ", panel3); |
| 212 |
} |
| 213 |
|
| 214 |
public boolean showDialog(String title) { |
| 215 |
|
| 216 |
JOptionPane optionPane = new JOptionPane(optionPanel, |
| 217 |
JOptionPane.PLAIN_MESSAGE, |
| 218 |
JOptionPane.OK_CANCEL_OPTION, |
| 219 |
null, |
| 220 |
new String[] { "Run", "Quit" }, |
| 221 |
null); |
| 222 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 223 |
|
| 224 |
final JDialog dialog = optionPane.createDialog(frame, title); |
| 225 |
|
| 226 |
dialog.pack(); |
| 227 |
|
| 228 |
dialog.setVisible(true); |
| 229 |
|
| 230 |
return optionPane.getValue().equals("Run"); |
| 231 |
} |
| 232 |
|
| 233 |
public long getBurninStates() { |
| 234 |
return burninStatesText.getLongValue(); |
| 235 |
} |
| 236 |
|
| 237 |
public int getBurninTrees() { |
| 238 |
return burninTreesText.getValue(); |
| 239 |
} |
| 240 |
|
| 241 |
public double getPosteriorLimit() { |
| 242 |
return limitText.getValue(); |
| 243 |
} |
| 244 |
|
| 245 |
public TreeAnnotator.Target getTargetOption() { |
| 246 |
return (TreeAnnotator.Target)summaryTreeCombo.getSelectedItem(); |
| 247 |
} |
| 248 |
|
| 249 |
public TreeAnnotator.HeightsSummary getHeightsOption() { |
| 250 |
return (TreeAnnotator.HeightsSummary)nodeHeightsCombo.getSelectedItem(); |
| 251 |
} |
| 252 |
|
| 253 |
public String getTargetFileName() { |
| 254 |
if (targetFile == null) return null; |
| 255 |
return targetFile.getPath(); |
| 256 |
} |
| 257 |
|
| 258 |
public String getInputFileName() { |
| 259 |
if (inputFile == null) return null; |
| 260 |
return inputFile.getPath(); |
| 261 |
} |
| 262 |
|
| 263 |
public String getOutputFileName() { |
| 264 |
if (outputFile == null) return null; |
| 265 |
return outputFile.getPath(); |
| 266 |
} |
| 267 |
|
| 268 |
} |