Formatting
[jalview.git] / src / jalview / gui / EditNameDialog.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 \r
20 package jalview.gui;\r
21 \r
22 import java.awt.*;\r
23 import javax.swing.*;\r
24 \r
25 public class EditNameDialog\r
26 {\r
27   JTextField id, description;\r
28   JButton ok = new JButton("Accept");\r
29   JButton cancel = new JButton("Cancel");\r
30   boolean accept = false;\r
31 \r
32   public String getName()\r
33   {\r
34     return id.getText();\r
35   }\r
36 \r
37   public String getDescription()\r
38   {\r
39     if (description.getText().length() < 1)\r
40     {\r
41       return null;\r
42     }\r
43     else\r
44     {\r
45       return description.getText();\r
46     }\r
47   }\r
48 \r
49   public EditNameDialog(String name,\r
50                         String desc,\r
51                         String label1,\r
52                         String label2,\r
53                         String title)\r
54   {\r
55     JLabel idlabel = new JLabel(label1);\r
56     JLabel desclabel = new JLabel(label2);\r
57     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
58     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
59     id = new JTextField(name, 40);\r
60     description = new JTextField(desc, 40);\r
61     JPanel panel = new JPanel(new BorderLayout());\r
62     JPanel panel2 = new JPanel(new BorderLayout());\r
63     panel2.add(idlabel, BorderLayout.WEST);\r
64     panel2.add(id, BorderLayout.CENTER);\r
65     panel.add(panel2, BorderLayout.NORTH);\r
66     panel2 = new JPanel(new BorderLayout());\r
67     panel2.add(desclabel, BorderLayout.WEST);\r
68     panel2.add(description, BorderLayout.CENTER);\r
69     panel.add(panel2, BorderLayout.SOUTH);\r
70 \r
71     int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
72         panel, title,\r
73         JOptionPane.OK_CANCEL_OPTION);\r
74 \r
75     if (reply == JOptionPane.OK_OPTION)\r
76     {\r
77       accept = true;\r
78     }\r
79   }\r
80 }\r