| 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.BeautiOptions; |
| 29 |
import dr.app.beauti.BeautiFrame; |
| 30 |
|
| 31 |
import javax.swing.*; |
| 32 |
import javax.swing.border.EmptyBorder; |
| 33 |
import java.awt.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class DefaultPriorTableDialog { |
| 45 |
|
| 46 |
private BeautiFrame frame; |
| 47 |
private PriorsPanel priorsPanel; |
| 48 |
|
| 49 |
public DefaultPriorTableDialog(BeautiFrame frame) { |
| 50 |
this.frame = frame; |
| 51 |
priorsPanel = new PriorsPanel(frame, true); |
| 52 |
} |
| 53 |
|
| 54 |
public JButton findButton(String label, Container container) { |
| 55 |
for (Component comp : container.getComponents()) { |
| 56 |
if (comp instanceof JButton) { |
| 57 |
JButton button = (JButton)comp; |
| 58 |
if (button.getText().equals(label)) { |
| 59 |
return button; |
| 60 |
} |
| 61 |
} else if (comp instanceof Container) { |
| 62 |
JButton button = findButton(label, (Container) comp); |
| 63 |
if (button != null) { |
| 64 |
return button; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
public boolean showDialog(BeautiOptions options) { |
| 73 |
priorsPanel.setParametersList(options); |
| 74 |
|
| 75 |
Object[] buttons; |
| 76 |
JOptionPane optionPane; |
| 77 |
|
| 78 |
String title; |
| 79 |
|
| 80 |
if (priorsPanel.hasUndefinedPrior) { |
| 81 |
title = "Undefined Priors"; |
| 82 |
} else { |
| 83 |
title = "Unchanged Default Priors"; |
| 84 |
} |
| 85 |
buttons = new String[] {"Continue", "Cancel"}; |
| 86 |
optionPane = new JOptionPane(priorsPanel, |
| 87 |
JOptionPane.PLAIN_MESSAGE, |
| 88 |
JOptionPane.OK_CANCEL_OPTION, |
| 89 |
null, |
| 90 |
buttons, |
| 91 |
buttons[0]); |
| 92 |
|
| 93 |
JButton button = findButton("Continue", optionPane); |
| 94 |
if (button != null) { |
| 95 |
priorsPanel.setContinueButton(button); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 119 |
optionPane.setPreferredSize(new java.awt.Dimension(800, 600)); |
| 120 |
|
| 121 |
final JDialog dialog = optionPane.createDialog(frame, title); |
| 122 |
dialog.pack(); |
| 123 |
dialog.setResizable(true); |
| 124 |
dialog.setVisible(true); |
| 125 |
|
| 126 |
return optionPane.getValue() != null && optionPane.getValue().equals("Continue"); |
| 127 |
} |
| 128 |
} |