Debian Codegraph @

src/dr/app/beauti/datapanel/SelectModelDialog.java

raw symbols SCIP
1 /*
2 * SelectModelDialog.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.datapanel;
27
28 import dr.app.beauti.options.PartitionSubstitutionModel;
29 import jam.panels.OptionsPanel;
30
31 import javax.swing.*;
32 import javax.swing.border.EmptyBorder;
33
34 /**
35 * @author Andrew Rambaut
36 * @author Alexei Drummond
37 * @version $Id: PriorDialog.java,v 1.4 2006/09/05 13:29:34 rambaut Exp $
38 */
39 public class SelectModelDialog {
40
41 private JFrame frame;
42
43 JComboBox modelCombo;
44 JCheckBox copyCheck;
45 JTextField nameField;
46
47 OptionsPanel optionPanel;
48
49 public SelectModelDialog(JFrame frame) {
50 this.frame = frame;
51
52 modelCombo = new JComboBox();
53
54 copyCheck = new JCheckBox("Rename substitution model partition to:");
55 nameField = new JTextField();
56 nameField.setColumns(20);
57 nameField.setEnabled(false);
58
59 optionPanel = new OptionsPanel(12, 12);
60 optionPanel.addComponentWithLabel("Partition Model:", modelCombo);
61 optionPanel.addComponents(copyCheck, nameField);
62
63 copyCheck.addItemListener(
64 new java.awt.event.ItemListener() {
65 public void itemStateChanged(java.awt.event.ItemEvent ev) {
66 nameField.setEnabled(copyCheck.isSelected());
67 }
68 }
69 );
70
71 }
72
73 public int showDialog(Object[] models) {
74
75 modelCombo.removeAllItems();
76 for (Object model : models) {
77 modelCombo.addItem(model);
78 }
79
80 JOptionPane optionPane = new JOptionPane(optionPanel,
81 JOptionPane.QUESTION_MESSAGE,
82 JOptionPane.OK_CANCEL_OPTION,
83 null,
84 null,
85 null);
86 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
87
88 final JDialog dialog = optionPane.createDialog(frame, "Create New Model");
89 dialog.pack();
90
91 dialog.setVisible(true);
92
93 int result = JOptionPane.CANCEL_OPTION;
94 Integer value = (Integer) optionPane.getValue();
95 if (value != null && value != -1) {
96 result = value;
97 }
98
99 return result;
100 }
101
102 public PartitionSubstitutionModel getModel() {
103 return (PartitionSubstitutionModel)modelCombo.getSelectedItem();
104 }
105
106 public boolean getMakeCopy() {
107 return copyCheck.isSelected();
108 }
109
110 public String getName() {
111 return nameField.getText();
112 }
113
114 }