Debian Codegraph @

src/dr/app/beauti/priorspanel/PriorDialog.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.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 * @author Andrew Rambaut
37 * @author Alexei Drummond
38 * @author Walter Xie
39 * @version $Id: PriorDialog.java,v 1.4 2006/09/05 13:29:34 rambaut Exp $
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 * Set the parameter to be controlled
57 *
58 * @param parameter
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 // setSize because optionsPanel is shrunk in dialog
96 dialog.setSize(new java.awt.Dimension(priorSettingsPanel.getWidth() + 100, priorSettingsPanel.getHeight() + 100));
97 }
98
99 // System.out.println("panel width = " + panel.getWidth());
100 // System.out.println("panel height = " + panel.getHeight());
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 }