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