| 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.beauti.priorspanel; |
| 27 |
|
| 28 |
import dr.app.beauti.options.Parameter; |
| 29 |
import dr.app.util.OSType; |
| 30 |
|
| 31 |
import javax.swing.*; |
| 32 |
import javax.swing.border.EmptyBorder; |
| 33 |
import java.awt.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class PriorDialog implements AbstractPriorDialog { |
| 42 |
|
| 43 |
private final JFrame frame; |
| 44 |
|
| 45 |
private final PriorSettingsPanel priorSettingsPanel; |
| 46 |
private Parameter parameter; |
| 47 |
|
| 48 |
public PriorDialog(JFrame frame) { |
| 49 |
this.frame = frame; |
| 50 |
|
| 51 |
priorSettingsPanel = new PriorSettingsPanel(frame); |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public void setParameter(final Parameter parameter) { |
| 61 |
this.parameter = parameter; |
| 62 |
priorSettingsPanel.setParameter(parameter); |
| 63 |
} |
| 64 |
|
| 65 |
public int showDialog() { |
| 66 |
|
| 67 |
JPanel panel = new JPanel(new BorderLayout(0, 6)); |
| 68 |
panel.add(new JLabel("Select prior distribution for " + parameter.getName()), BorderLayout.NORTH); |
| 69 |
panel.add(priorSettingsPanel, BorderLayout.CENTER); |
| 70 |
|
| 71 |
JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 72 |
scrollPane.setBorder(null); |
| 73 |
scrollPane.getViewport().setOpaque(false); |
| 74 |
|
| 75 |
JOptionPane optionPane = new JOptionPane(scrollPane, |
| 76 |
JOptionPane.PLAIN_MESSAGE, |
| 77 |
JOptionPane.OK_CANCEL_OPTION, |
| 78 |
null, |
| 79 |
null, |
| 80 |
null); |
| 81 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 82 |
|
| 83 |
final JDialog dialog = optionPane.createDialog(frame, "Prior for Parameter " + parameter.getName()); |
| 84 |
|
| 85 |
priorSettingsPanel.setDialog(dialog); |
| 86 |
|
| 87 |
if (OSType.isMac()) { |
| 88 |
dialog.setMinimumSize(new Dimension(dialog.getBounds().width, 300)); |
| 89 |
} else { |
| 90 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
| 91 |
Dimension d = tk.getScreenSize(); |
| 92 |
if (d.height < 700 && priorSettingsPanel.getHeight() > 450) { |
| 93 |
dialog.setSize(new java.awt.Dimension(priorSettingsPanel.getWidth() + 100, 550)); |
| 94 |
} else { |
| 95 |
|
| 96 |
dialog.setSize(new java.awt.Dimension(priorSettingsPanel.getWidth() + 100, priorSettingsPanel.getHeight() + 100)); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
dialog.pack(); |
| 104 |
dialog.setResizable(true); |
| 105 |
dialog.setVisible(true); |
| 106 |
|
| 107 |
int result = JOptionPane.CANCEL_OPTION; |
| 108 |
Integer value = (Integer) optionPane.getValue(); |
| 109 |
if (value != null && value != -1) { |
| 110 |
result = value; |
| 111 |
} |
| 112 |
|
| 113 |
return result; |
| 114 |
} |
| 115 |
|
| 116 |
public void getArguments(Parameter parameter) { |
| 117 |
priorSettingsPanel.getArguments(parameter); |
| 118 |
} |
| 119 |
|
| 120 |
public boolean hasInvalidInput(boolean showError) { |
| 121 |
return priorSettingsPanel.hasInvalidInput(showError); |
| 122 |
} |
| 123 |
} |