| 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.treespace.inputpanel; |
| 27 |
|
| 28 |
import dr.app.gui.components.RealNumberField; |
| 29 |
import jam.panels.OptionsPanel; |
| 30 |
import dr.app.gui.components.WholeNumberField; |
| 31 |
|
| 32 |
import javax.swing.*; |
| 33 |
import javax.swing.border.EmptyBorder; |
| 34 |
|
| 35 |
import dr.app.treespace.InputFile; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class InputFileSettingsDialog { |
| 42 |
|
| 43 |
private JFrame frame; |
| 44 |
|
| 45 |
private WholeNumberField burninField; |
| 46 |
private RealNumberField mrsdField; |
| 47 |
|
| 48 |
private OptionsPanel optionPanel; |
| 49 |
|
| 50 |
private InputFile inputFile = null; |
| 51 |
|
| 52 |
public InputFileSettingsDialog(JFrame frame) { |
| 53 |
this.frame = frame; |
| 54 |
|
| 55 |
burninField = new WholeNumberField(0, Integer.MAX_VALUE); |
| 56 |
burninField.setColumns(8); |
| 57 |
|
| 58 |
mrsdField = new RealNumberField(0, Double.POSITIVE_INFINITY); |
| 59 |
mrsdField.setColumns(20); |
| 60 |
|
| 61 |
optionPanel = new OptionsPanel(12, 12); |
| 62 |
} |
| 63 |
|
| 64 |
private void setupPanel(InputFile inputFile) { |
| 65 |
optionPanel.removeAll(); |
| 66 |
|
| 67 |
if (inputFile.getTree() != null) { |
| 68 |
if (inputFile.getType() == InputFile.Type.POSTERIOR_TREES) { |
| 69 |
optionPanel.addComponentWithLabel("Burnin (number of trees):", burninField); |
| 70 |
burninField.setValue(inputFile.getBurnin()); |
| 71 |
} |
| 72 |
|
| 73 |
optionPanel.addComponentWithLabel("Most recently sampled date:", mrsdField); |
| 74 |
mrsdField.setValue(inputFile.getMostRecentSampleDate()); |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
public int showDialog(InputFile inputFile) { |
| 80 |
|
| 81 |
this.inputFile = inputFile; |
| 82 |
|
| 83 |
setupPanel(inputFile); |
| 84 |
|
| 85 |
final JOptionPane optionPane = new JOptionPane(optionPanel, |
| 86 |
JOptionPane.QUESTION_MESSAGE, |
| 87 |
JOptionPane.OK_CANCEL_OPTION, |
| 88 |
null, |
| 89 |
null, |
| 90 |
null); |
| 91 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 92 |
|
| 93 |
final JDialog dialog = optionPane.createDialog(frame, "Edit Input File Settings"); |
| 94 |
dialog.pack(); |
| 95 |
|
| 96 |
|
| 97 |
int result = JOptionPane.CANCEL_OPTION; |
| 98 |
|
| 99 |
dialog.setVisible(true); |
| 100 |
|
| 101 |
Integer value = (Integer) optionPane.getValue(); |
| 102 |
if (value != null && value != -1) { |
| 103 |
result = value; |
| 104 |
} |
| 105 |
|
| 106 |
return result; |
| 107 |
} |
| 108 |
|
| 109 |
public InputFile getInputFile() { |
| 110 |
inputFile.setBurnin(burninField.getValue()); |
| 111 |
inputFile.setMostRecentSampleDate(mrsdField.getValue()); |
| 112 |
return inputFile; |
| 113 |
} |
| 114 |
|
| 115 |
} |