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