Debian Codegraph @

src/dr/app/beauti/tipdatepanel/SetValueDialog.java

raw symbols SCIP
1 /*
2 * SetValueDialog.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.tipdatepanel;
27
28 import jam.panels.OptionsPanel;
29
30 import javax.swing.*;
31 import javax.swing.border.EmptyBorder;
32
33
34 /**
35 * @author Andrew Rambaut
36 * @author Alexei Drummond
37 * @author Walter Xie
38 * @version $Id: GuessTraitDialog.java,v 1.4 2009/05/25 13:29:34 rambaut Exp $
39 */
40 public class SetValueDialog {
41
42 private JFrame frame;
43 private final OptionsPanel optionPanel;
44 private String title = "Set Values for Taxa";
45
46 JLabel descriptionText = new JLabel();
47
48 private final JTextField valueText = new JTextField(16);
49
50 public SetValueDialog(JFrame frame, String title) {
51 this.frame = frame;
52
53 this.title = title;
54
55 optionPanel = new OptionsPanel(12, 12);
56
57 optionPanel.addSpanningComponent(descriptionText);
58 optionPanel.addComponentWithLabel("Value: ", valueText);
59 }
60
61 public void setDescription(String description) {
62 descriptionText.setText(description);
63 }
64
65 public void setTitle(String title) {
66 this.title = title;
67 }
68
69 public int showDialog() {
70
71 JOptionPane optionPane = new JOptionPane(optionPanel,
72 JOptionPane.QUESTION_MESSAGE,
73 JOptionPane.OK_CANCEL_OPTION,
74 null,
75 null,
76 null);
77 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
78
79 final JDialog dialog = optionPane.createDialog(frame, title);
80 dialog.pack();
81
82 dialog.setVisible(true);
83
84 int result = JOptionPane.CANCEL_OPTION;
85 Integer value = (Integer) optionPane.getValue();
86 if (value != null && value != -1) {
87 result = value;
88 }
89
90 return result;
91 }
92
93 public String getValue() {
94 return valueText.getText();
95 }
96 }