Debian Codegraph @

src/dr/app/beauti/sitemodelspanel/GLMSettingsDialog.java

raw symbols SCIP
1 /*
2 * PriorDialog.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @author Andrew Rambaut
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 * Set the trait to be controlled
55 *
56 * @param trait
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 // setSize because optionsPanel is shrunk in dialog
97 dialog.setSize(new Dimension(glmSettingsPanel.getWidth() + 100, glmSettingsPanel.getHeight() + 100));
98 }
99
100 // System.out.println("panel width = " + panel.getWidth());
101 // System.out.println("panel height = " + panel.getHeight());
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 }