b80aca7d2a908ac9e04ba2a29dfeb6a1288448d9
[jalview.git] / src / jalview / appletgui / 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.appletgui;\r
21 \r
22 import java.awt.*;\r
23 import java.awt.event.*;\r
24 \r
25 public class EditNameDialog extends Dialog implements ActionListener\r
26 {\r
27   TextField id, description;\r
28   Button ok = new Button("Accept");\r
29   Button cancel = new Button("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       return null;\r
41     else\r
42       return description.getText();\r
43   }\r
44 \r
45   public EditNameDialog(String name,\r
46                         String desc,\r
47                         String label1,\r
48                         String label2,\r
49                         AlignmentPanel ap,\r
50                         String title)\r
51   {\r
52     super(ap.alignFrame, title, true);\r
53 \r
54     id = new TextField(name, 40);\r
55     description = new TextField(desc, 40);\r
56     Panel panel = new Panel(new BorderLayout());\r
57     Panel panel2 = new Panel(new BorderLayout());\r
58     panel2.add(new Label(label1), BorderLayout.WEST);\r
59     panel2.add(id, BorderLayout.CENTER);\r
60     panel.add(panel2, BorderLayout.NORTH);\r
61     panel2 = new Panel(new BorderLayout());\r
62     panel2.add(new Label(label2), BorderLayout.WEST);\r
63     panel2.add(description, BorderLayout.CENTER);\r
64     panel.add(panel2, BorderLayout.CENTER);\r
65 \r
66     panel2 = new Panel(new FlowLayout());\r
67 \r
68     panel2.add(ok);\r
69     panel2.add(cancel);\r
70     ok.addActionListener(this);\r
71     cancel.addActionListener(this);\r
72 \r
73     panel.add(panel2, BorderLayout.SOUTH);\r
74 \r
75     add(panel, BorderLayout.NORTH);\r
76 \r
77     setBounds(ap.alignFrame.getBounds().x\r
78               + (ap.alignFrame.getSize().width - 500) / 2,\r
79               ap.alignFrame.getBounds().y\r
80               + (ap.alignFrame.getSize().height - 120) / 2,\r
81               500, 130);\r
82 \r
83     show();\r
84   }\r
85 \r
86   public void actionPerformed(ActionEvent evt)\r
87   {\r
88     if(evt.getSource()==ok)\r
89       accept = true;\r
90 \r
91     setVisible(false);\r
92   }\r
93 }\r