Debian Codegraph @

src/dr/app/beauti/priorspanel/SelectParametersDialog.java

raw symbols SCIP
1 /*
2 * SelectParametersDialog.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 jam.panels.OptionsPanel;
30
31 import javax.swing.*;
32 import javax.swing.border.EmptyBorder;
33 import java.util.List;
34
35
36 /**
37 * @author Andrew Rambaut
38 * @version $Id: PriorDialog.java,v 1.4 2006/09/05 13:29:34 rambaut Exp $
39 */
40 public class SelectParametersDialog {
41
42 private final JFrame frame;
43
44 private JComboBox parameterCombo = new JComboBox();
45
46 OptionsPanel optionPanel = new OptionsPanel(12, 12);
47
48
49 public SelectParametersDialog(final JFrame frame) {
50 this.frame = frame;
51 }
52
53 public int showDialog(String message, List<Parameter> parameterList) {
54
55 optionPanel.removeAll();
56
57 if (message != null && !message.isEmpty()) {
58 optionPanel.addSpanningComponent(new JLabel(message));
59 }
60
61 parameterCombo.removeAllItems();
62 for (Parameter parameter : parameterList) {
63 parameterCombo.addItem(parameter);
64 }
65 optionPanel.addComponentWithLabel("Parameter:", parameterCombo);
66
67 JOptionPane optionPane = new JOptionPane(optionPanel,
68 JOptionPane.QUESTION_MESSAGE,
69 JOptionPane.OK_CANCEL_OPTION,
70 null,
71 null,
72 null);
73 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
74
75 int result = JOptionPane.CANCEL_OPTION;
76
77 final JDialog dialog = optionPane.createDialog(frame, "Add Parameter");
78 dialog.pack();
79
80 dialog.setVisible(true);
81
82 Integer value = (Integer) optionPane.getValue();
83 if (value != null && value != -1) {
84 result = value;
85 }
86
87 return result;
88 }
89
90 public Parameter getSelectedParameter() {
91 return (Parameter)parameterCombo.getSelectedItem();
92 }
93
94 }