One class for edit name/description
[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 \r
33   public String getName()\r
34   {\r
35     return id.getText();\r
36   }\r
37 \r
38   public String getDescription()\r
39   {\r
40     if (description.getText().length() < 1)\r
41       return null;\r
42     else\r
43       return description.getText();\r
44   }\r
45 \r
46   public EditNameDialog(String name,\r
47                         String desc,\r
48                         String label1,\r
49                         String label2,\r
50                         String title)\r
51   {\r
52     JLabel idlabel = new JLabel( label1);\r
53     JLabel desclabel = new JLabel(label2);\r
54     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
55     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));\r
56     id = new JTextField(name, 40);\r
57     description = new JTextField(desc, 40);\r
58     JPanel panel = new JPanel(new BorderLayout());\r
59     JPanel panel2 = new JPanel(new BorderLayout());\r
60     panel2.add(idlabel, BorderLayout.WEST);\r
61     panel2.add(id, BorderLayout.CENTER);\r
62     panel.add(panel2, BorderLayout.NORTH);\r
63     panel2 = new JPanel(new BorderLayout());\r
64     panel2.add(desclabel, BorderLayout.WEST);\r
65     panel2.add(description, BorderLayout.CENTER);\r
66     panel.add(panel2, BorderLayout.SOUTH);\r
67 \r
68 \r
69      int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
70         panel, title,\r
71         JOptionPane.OK_CANCEL_OPTION );\r
72 \r
73      if (reply == JOptionPane.OK_OPTION)\r
74      {\r
75        accept = true;\r
76      }\r
77   }\r
78 }\r