| 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.beast; |
| 27 |
|
| 28 |
import dr.app.gui.FileDrop; |
| 29 |
import dr.app.gui.components.WholeNumberField; |
| 30 |
import jam.html.SimpleLinkListener; |
| 31 |
import jam.panels.OptionsPanel; |
| 32 |
|
| 33 |
import javax.swing.*; |
| 34 |
import javax.swing.border.Border; |
| 35 |
import javax.swing.border.EmptyBorder; |
| 36 |
import javax.swing.border.TitledBorder; |
| 37 |
import javax.swing.event.ChangeEvent; |
| 38 |
import javax.swing.event.ChangeListener; |
| 39 |
import java.awt.*; |
| 40 |
import java.awt.event.ActionEvent; |
| 41 |
import java.awt.event.ActionListener; |
| 42 |
import java.io.File; |
| 43 |
|
| 44 |
|
| 45 |
public class BeastDialog { |
| 46 |
private final JFrame frame; |
| 47 |
|
| 48 |
private final OptionsPanel optionPanel; |
| 49 |
|
| 50 |
private final WholeNumberField seedText = new WholeNumberField((long) 1, Long.MAX_VALUE); |
| 51 |
private final JCheckBox overwriteCheckBox = new JCheckBox("Allow overwriting of log files"); |
| 52 |
private final JCheckBox beagleCheckBox = new JCheckBox("The BEAGLE library is required to run BEAST:"); |
| 53 |
private final JCheckBox beagleInfoCheckBox = new JCheckBox("Show list of available BEAGLE resources and Quit"); |
| 54 |
private final JComboBox beagleResourceCombo = new JComboBox(new Object[]{"CPU", "GPU"}); |
| 55 |
private final JCheckBox beagleSSECheckBox = new JCheckBox("Use CPU's SSE extensions when possible"); |
| 56 |
private final JComboBox beaglePrecisionCombo = new JComboBox(new Object[]{"Double", "Single"}); |
| 57 |
private final JComboBox beagleScalingCombo = new JComboBox(new Object[]{"Default", "Dynamic", "Delayed", "Always", "Never"}); |
| 58 |
|
| 59 |
private final JComboBox threadsCombo = new JComboBox(new Object[]{"Automatic", 0, 1, 2, 3, 4, 5, 6, 7, 8}); |
| 60 |
|
| 61 |
private File inputFile = null; |
| 62 |
|
| 63 |
public BeastDialog(final JFrame frame, final String titleString, final Icon icon) { |
| 64 |
this.frame = frame; |
| 65 |
|
| 66 |
optionPanel = new OptionsPanel(12, 12); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
JPanel panel = new JPanel(new BorderLayout()); |
| 71 |
panel.setOpaque(false); |
| 72 |
|
| 73 |
final OptionsPanel optionPanel3 = new OptionsPanel(0, 3); |
| 74 |
|
| 75 |
final JLabel titleIcon = new JLabel(); |
| 76 |
titleIcon.setIcon(icon); |
| 77 |
|
| 78 |
final JEditorPane titleText = new JEditorPane("text/html", "<html>" + titleString + "</html>"); |
| 79 |
titleText.setOpaque(false); |
| 80 |
titleText.setEditable(false); |
| 81 |
titleText.addHyperlinkListener(new SimpleLinkListener()); |
| 82 |
optionPanel3.addComponent(titleText); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
optionPanel.addComponents(titleIcon, optionPanel3); |
| 89 |
|
| 90 |
final JButton inputFileButton = new JButton("Choose File..."); |
| 91 |
final JTextField inputFileNameText = new JTextField("not selected", 16); |
| 92 |
|
| 93 |
inputFileButton.addActionListener(new ActionListener() { |
| 94 |
public void actionPerformed(ActionEvent ae) { |
| 95 |
FileDialog dialog = new FileDialog(frame, |
| 96 |
"Select target file...", |
| 97 |
FileDialog.LOAD); |
| 98 |
|
| 99 |
dialog.setVisible(true); |
| 100 |
if (dialog.getFile() == null) { |
| 101 |
|
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
inputFile = new File(dialog.getDirectory(), dialog.getFile()); |
| 106 |
inputFileNameText.setText(inputFile.getName()); |
| 107 |
|
| 108 |
} |
| 109 |
}); |
| 110 |
inputFileNameText.setEditable(false); |
| 111 |
|
| 112 |
JPanel panel1 = new JPanel(new BorderLayout(0, 0)); |
| 113 |
panel1.add(inputFileNameText, BorderLayout.CENTER); |
| 114 |
panel1.add(inputFileButton, BorderLayout.EAST); |
| 115 |
inputFileNameText.setToolTipText( |
| 116 |
"<html>Drag a BEAST XML file here or use the button to<br>" + |
| 117 |
"select one from a file dialog box.</html>"); |
| 118 |
inputFileButton.setToolTipText( |
| 119 |
"<html>Drag a BEAST XML file here or use the button to<br>" + |
| 120 |
"select one from a file dialog box.</html>"); |
| 121 |
optionPanel.addComponentWithLabel("BEAST XML File: ", panel1); |
| 122 |
|
| 123 |
Color focusColor = UIManager.getColor("Focus.color"); |
| 124 |
Border focusBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, focusColor); |
| 125 |
new FileDrop(null, inputFileNameText, focusBorder, new FileDrop.Listener() { |
| 126 |
public void filesDropped(java.io.File[] files) { |
| 127 |
inputFile = files[0]; |
| 128 |
inputFileNameText.setText(inputFile.getName()); |
| 129 |
} |
| 130 |
}); |
| 131 |
|
| 132 |
overwriteCheckBox.setToolTipText( |
| 133 |
"<html>Specify whether BEAST will overwrite existing log files<br>" + |
| 134 |
"with the same name.</html>"); |
| 135 |
optionPanel.addComponent(overwriteCheckBox); |
| 136 |
|
| 137 |
optionPanel.addSeparator(); |
| 138 |
|
| 139 |
seedText.setColumns(12); |
| 140 |
seedText.setToolTipText( |
| 141 |
"<html>Specify a particular random number seed to replicate<br>" + |
| 142 |
"precisely the sequence of steps in the MCMC chain. By<br>" + |
| 143 |
"default this uses system information to provide a new<br>" + |
| 144 |
"seed each run.</html>"); |
| 145 |
|
| 146 |
optionPanel.addComponentWithLabel("Random number seed: ", seedText); |
| 147 |
|
| 148 |
threadsCombo.setToolTipText( |
| 149 |
"<html>Specify how large a thread pool to use.<br>" + |
| 150 |
"In most circumstances this should be set to 'automatic'<br>" + |
| 151 |
"but in some circumstances it may be desirable to restict<br>" + |
| 152 |
"the number of cores being used. 0 will turn off threading</html>"); |
| 153 |
|
| 154 |
optionPanel.addComponentWithLabel("Thread pool size: ", threadsCombo); |
| 155 |
|
| 156 |
optionPanel.addSeparator(); |
| 157 |
|
| 158 |
optionPanel.addSpanningComponent(beagleCheckBox); |
| 159 |
beagleCheckBox.setSelected(true); |
| 160 |
|
| 161 |
final OptionsPanel optionPanel1 = new OptionsPanel(0, 6); |
| 162 |
|
| 163 |
optionPanel1.setBorder(new TitledBorder("")); |
| 164 |
|
| 165 |
OptionsPanel optionPanel2 = new OptionsPanel(0, 3); |
| 166 |
optionPanel2.setBorder(BorderFactory.createEmptyBorder()); |
| 167 |
final JLabel label1 = optionPanel2.addComponentWithLabel("Prefer use of: ", beagleResourceCombo); |
| 168 |
optionPanel2.addComponent(beagleSSECheckBox); |
| 169 |
beagleSSECheckBox.setSelected(true); |
| 170 |
final JLabel label2 = optionPanel2.addComponentWithLabel("Prefer precision: ", beaglePrecisionCombo); |
| 171 |
final JLabel label3 = optionPanel2.addComponentWithLabel("Rescaling scheme: ", beagleScalingCombo); |
| 172 |
optionPanel2.addComponent(beagleInfoCheckBox); |
| 173 |
optionPanel2.setBorder(BorderFactory.createEmptyBorder()); |
| 174 |
|
| 175 |
optionPanel1.addComponent(optionPanel2); |
| 176 |
|
| 177 |
final JEditorPane beagleInfo = new JEditorPane("text/html", |
| 178 |
"<html><div style=\"font-family:'helvetica neue light',helvetica,sans-serif;font-size:12;\"><p>BEAGLE is a high-performance phylogenetic library that can make use of<br>" + |
| 179 |
"additional computational resources such as graphics boards. It must be<br>" + |
| 180 |
"downloaded and installed independently of BEAST:</p>" + |
| 181 |
"<pre><a href=\"http://github.com/beagle-dev/beagle-lib/\">http://github.com/beagle-dev/beagle-lib/</a></pre></div></html>"); |
| 182 |
beagleInfo.setOpaque(false); |
| 183 |
beagleInfo.setEditable(false); |
| 184 |
beagleInfo.addHyperlinkListener(new SimpleLinkListener()); |
| 185 |
optionPanel1.addComponent(beagleInfo); |
| 186 |
optionPanel1.setBorder(BorderFactory.createEmptyBorder()); |
| 187 |
optionPanel.addSpanningComponent(optionPanel1); |
| 188 |
|
| 189 |
beagleInfoCheckBox.setEnabled(false); |
| 190 |
beagleCheckBox.addChangeListener(new ChangeListener() { |
| 191 |
public void stateChanged(ChangeEvent e) { |
| 192 |
beagleInfo.setEnabled(beagleCheckBox.isSelected()); |
| 193 |
beagleInfoCheckBox.setEnabled(beagleCheckBox.isSelected()); |
| 194 |
label1.setEnabled(beagleCheckBox.isSelected()); |
| 195 |
beagleResourceCombo.setEnabled(beagleCheckBox.isSelected()); |
| 196 |
beagleSSECheckBox.setEnabled(beagleCheckBox.isSelected()); |
| 197 |
label2.setEnabled(beagleCheckBox.isSelected()); |
| 198 |
beaglePrecisionCombo.setEnabled(beagleCheckBox.isSelected()); |
| 199 |
label3.setEnabled(beagleCheckBox.isSelected()); |
| 200 |
beagleScalingCombo.setEnabled(beagleCheckBox.isSelected()); |
| 201 |
} |
| 202 |
}); |
| 203 |
|
| 204 |
beagleCheckBox.setSelected(true); |
| 205 |
beagleCheckBox.setEnabled(false); |
| 206 |
beagleResourceCombo.setSelectedItem("CPU"); |
| 207 |
} |
| 208 |
|
| 209 |
public boolean showDialog(String title) { |
| 210 |
|
| 211 |
JOptionPane optionPane = new JOptionPane(optionPanel, |
| 212 |
JOptionPane.PLAIN_MESSAGE, |
| 213 |
JOptionPane.OK_CANCEL_OPTION, |
| 214 |
null, |
| 215 |
new String[]{"Run", "Quit"}, |
| 216 |
"Run"); |
| 217 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 218 |
|
| 219 |
final JDialog dialog = optionPane.createDialog(frame, title); |
| 220 |
|
| 221 |
dialog.pack(); |
| 222 |
|
| 223 |
dialog.setVisible(true); |
| 224 |
|
| 225 |
return (optionPane.getValue() != null ? optionPane.getValue().equals("Run") : false); |
| 226 |
} |
| 227 |
|
| 228 |
public long getSeed() { |
| 229 |
return seedText.getLongValue(); |
| 230 |
} |
| 231 |
|
| 232 |
public void setSeed(long seed) { |
| 233 |
seedText.setValue(seed); |
| 234 |
} |
| 235 |
|
| 236 |
public boolean allowOverwrite() { |
| 237 |
return overwriteCheckBox.isSelected(); |
| 238 |
} |
| 239 |
|
| 240 |
public void setAllowOverwrite(boolean allowOverwrite) { |
| 241 |
overwriteCheckBox.setSelected(allowOverwrite); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
public boolean preferBeagleGPU() { |
| 250 |
return beagleResourceCombo.getSelectedItem().equals("GPU"); |
| 251 |
} |
| 252 |
|
| 253 |
public boolean preferBeagleCPU() { |
| 254 |
return (beagleResourceCombo.getSelectedItem().equals("CPU")); |
| 255 |
} |
| 256 |
|
| 257 |
public void setPreferBeagleGPU() { |
| 258 |
beagleResourceCombo.setSelectedItem("GPU"); |
| 259 |
} |
| 260 |
|
| 261 |
public boolean preferBeagleSSE() { |
| 262 |
return beagleSSECheckBox.isSelected(); |
| 263 |
} |
| 264 |
|
| 265 |
public void setPreferBeagleSSE(boolean preferBeagleSSE) { |
| 266 |
beagleSSECheckBox.setSelected(preferBeagleSSE); |
| 267 |
} |
| 268 |
|
| 269 |
public boolean preferBeagleSingle() { |
| 270 |
return beaglePrecisionCombo.getSelectedItem().equals("Single"); |
| 271 |
} |
| 272 |
|
| 273 |
public boolean preferBeagleDouble() { |
| 274 |
return beaglePrecisionCombo.getSelectedItem().equals("Double"); |
| 275 |
} |
| 276 |
|
| 277 |
public void setPreferBeagleSingle() { |
| 278 |
beaglePrecisionCombo.setSelectedItem("Single"); |
| 279 |
} |
| 280 |
|
| 281 |
public String scalingScheme() { |
| 282 |
return ((String) beagleScalingCombo.getSelectedItem()).toLowerCase(); |
| 283 |
} |
| 284 |
|
| 285 |
public void setScalingScheme(String scalingScheme) { |
| 286 |
beagleScalingCombo.setSelectedItem(scalingScheme); |
| 287 |
} |
| 288 |
|
| 289 |
public boolean showBeagleInfo() { |
| 290 |
return beagleInfoCheckBox.isSelected(); |
| 291 |
} |
| 292 |
|
| 293 |
public int getThreadPoolSize() { |
| 294 |
if (threadsCombo.getSelectedIndex() == 0) { |
| 295 |
|
| 296 |
return -1; |
| 297 |
} |
| 298 |
return (Integer) threadsCombo.getSelectedItem(); |
| 299 |
} |
| 300 |
|
| 301 |
public File getInputFile() { |
| 302 |
return inputFile; |
| 303 |
} |
| 304 |
} |