Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * SelectTraitDialog.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 dr.app.beauti.options.TraitData;
30 import jam.panels.OptionsPanel;
31
32 import javax.swing.*;
33 import javax.swing.border.EmptyBorder;
34 import java.util.Collection;
35
36 /**
37 * @author Andrew Rambaut
38 * @author Alexei Drummond
39 * @version $Id: PriorDialog.java,v 1.4 2006/09/05 13:29:34 rambaut Exp $
40 */
41 public class SelectTraitDialog {
42
43 private JFrame frame;
44
45 JComboBox traitCombo;
46 JCheckBox copyCheck;
47 JTextField nameField;
48
49 OptionsPanel optionPanel;
50
51 public SelectTraitDialog(JFrame frame) {
52 this.frame = frame;
53
54 traitCombo = new JComboBox();
55
56 copyCheck = new JCheckBox("Name trait partition:");
57 nameField = new JTextField();
58 nameField.setColumns(20);
59
60 optionPanel = new OptionsPanel(12, 12);
61
62 copyCheck.addItemListener(
63 new java.awt.event.ItemListener() {
64 public void itemStateChanged(java.awt.event.ItemEvent ev) {
65 nameField.setEnabled(copyCheck.isSelected());
66 }
67 }
68 );
69
70 }
71
72 public int showDialog(Collection<TraitData> traits, String defaultName) {
73 optionPanel.removeAll();
74 if (traits == null) {
75 optionPanel.addSpanningComponent(new JLabel("Create a new data partition using the selected trait(s)."));
76 optionPanel.addComponentWithLabel("Name trait partition:", nameField);
77 nameField.setText(defaultName != null ? defaultName : "untitled_traits");
78 nameField.setEnabled(true);
79 nameField.selectAll();
80 } else {
81 traitCombo.removeAllItems();
82 for (Object model : traits) {
83 traitCombo.addItem(model);
84 }
85 optionPanel.addSpanningComponent(new JLabel("Create a new data partition using the following trait."));
86 optionPanel.addComponentWithLabel("Trait:", traitCombo);
87 optionPanel.addComponents(copyCheck, nameField);
88 nameField.setEnabled(copyCheck.isSelected());
89 }
90
91 JOptionPane optionPane = new JOptionPane(optionPanel,
92 JOptionPane.QUESTION_MESSAGE,
93 JOptionPane.OK_CANCEL_OPTION,
94 null,
95 null,
96 null);
97 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
98
99 final JDialog dialog = optionPane.createDialog(frame, "Create New Partition");
100 dialog.pack();
101
102 int result;
103 boolean isValid;
104
105 do {
106 dialog.setVisible(true);
107
108 isValid = true;
109 result = JOptionPane.CANCEL_OPTION;
110
111 Integer value = (Integer) optionPane.getValue();
112 if (value != null && value != -1) {
113 result = value;
114 }
115 if (result != JOptionPane.CANCEL_OPTION) {
116 String name = getName().trim();
117 if (name.isEmpty()) {
118 isValid = false;
119 }
120 }
121 } while (!isValid);
122
123 return result;
124 }
125
126 public TraitData getTrait() {
127 return (TraitData) traitCombo.getSelectedItem();
128 }
129
130 public boolean getMakeCopy() {
131 return copyCheck.isSelected();
132 }
133
134 public String getName() {
135 return nameField.getText();
136 }
137
138 }