Debian Codegraph @

src/dr/app/beauti/util/PartitionNameDialog.java

raw symbols SCIP
1 /*
2 * PartitionNameDialog.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.util;
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$
39 */
40 public class PartitionNameDialog {
41
42 private JFrame frame;
43 private final OptionsPanel optionPanel;
44
45 JLabel descriptionText = new JLabel();
46
47 private final JTextField valueText = new JTextField(16);
48
49 public PartitionNameDialog(JFrame frame) {
50 this.frame = frame;
51
52 optionPanel = new OptionsPanel(12, 12);
53
54 optionPanel.addSpanningComponent(descriptionText);
55 optionPanel.addComponentWithLabel("New Name: ", valueText);
56 }
57
58 public void setDescription(String description) {
59 descriptionText.setText(description);
60 }
61
62 public int showDialog() {
63
64 JOptionPane optionPane = new JOptionPane(optionPanel,
65 JOptionPane.QUESTION_MESSAGE,
66 JOptionPane.OK_CANCEL_OPTION,
67 null,
68 null,
69 null);
70 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
71
72 final JDialog dialog = optionPane.createDialog(frame, "Rename partition");
73 dialog.pack();
74
75 dialog.setVisible(true);
76
77 int result = JOptionPane.CANCEL_OPTION;
78 Integer value = (Integer) optionPane.getValue();
79 if (value != null && value != -1) {
80 result = value;
81 }
82
83 return result;
84 }
85
86 public String getName() {
87 return valueText.getText().trim();
88 }
89 }