JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / gui / EditNameDialog.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.util.MessageManager;
24
25 import java.awt.BorderLayout;
26 import java.awt.Font;
27
28 import javax.swing.JButton;
29 import javax.swing.JComponent;
30 import javax.swing.JLabel;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JTextField;
34
35 public class EditNameDialog
36 {
37   JTextField id, description;
38
39   JButton ok = new JButton(MessageManager.getString("action.accept"));
40
41   JButton cancel = new JButton(MessageManager.getString("action.cancel"));
42
43   boolean accept = false;
44
45   public String getName()
46   {
47     return id.getText();
48   }
49
50   public String getDescription()
51   {
52     if (description.getText().length() < 1)
53     {
54       return null;
55     }
56     else
57     {
58       return description.getText();
59     }
60   }
61
62   public EditNameDialog(String name, String desc, String label1,
63           String label2, String title, JComponent parent)
64   {
65     JLabel idlabel = new JLabel(label1);
66     JLabel desclabel = new JLabel(label2);
67     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));
68     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));
69     id = new JTextField(name, 40);
70     description = new JTextField(desc, 40);
71     JPanel panel = new JPanel(new BorderLayout());
72     JPanel panel2 = new JPanel(new BorderLayout());
73     panel2.add(idlabel, BorderLayout.WEST);
74     panel2.add(id, BorderLayout.CENTER);
75     panel.add(panel2, BorderLayout.NORTH);
76     if (desc != null || label2 != null)
77     {
78       panel2 = new JPanel(new BorderLayout());
79       panel2.add(desclabel, BorderLayout.WEST);
80       panel2.add(description, BorderLayout.CENTER);
81       panel.add(panel2, BorderLayout.SOUTH);
82     }
83     int reply = JOptionPane.showInternalConfirmDialog(parent, panel, title,
84             JOptionPane.OK_CANCEL_OPTION);
85     if (!parent.requestFocusInWindow())
86     {
87       System.err.println("Bad focus for dialog!");
88     }
89     if (reply == JOptionPane.OK_OPTION)
90     {
91       accept = true;
92     }
93   }
94 }