update author list in license for (JAL-826)
[jalview.git] / src / jalview / gui / EditNameDialog.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.awt.*;
21 import javax.swing.*;
22
23 public class EditNameDialog
24 {
25   JTextField id, description;
26
27   JButton ok = new JButton("Accept");
28
29   JButton cancel = new JButton("Cancel");
30
31   boolean accept = false;
32
33   public String getName()
34   {
35     return id.getText();
36   }
37
38   public String getDescription()
39   {
40     if (description.getText().length() < 1)
41     {
42       return null;
43     }
44     else
45     {
46       return description.getText();
47     }
48   }
49
50   public EditNameDialog(String name, String desc, String label1,
51           String label2, String title, JComponent parent)
52   {
53     JLabel idlabel = new JLabel(label1);
54     JLabel desclabel = new JLabel(label2);
55     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));
56     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));
57     id = new JTextField(name, 40);
58     description = new JTextField(desc, 40);
59     JPanel panel = new JPanel(new BorderLayout());
60     JPanel panel2 = new JPanel(new BorderLayout());
61     panel2.add(idlabel, BorderLayout.WEST);
62     panel2.add(id, BorderLayout.CENTER);
63     panel.add(panel2, BorderLayout.NORTH);
64     if (desc != null || label2 != null)
65     {
66       panel2 = new JPanel(new BorderLayout());
67       panel2.add(desclabel, BorderLayout.WEST);
68       panel2.add(description, BorderLayout.CENTER);
69       panel.add(panel2, BorderLayout.SOUTH);
70     }
71     int reply = JOptionPane.showInternalConfirmDialog(parent, panel, title,
72             JOptionPane.OK_CANCEL_OPTION);
73     if (!parent.requestFocusInWindow())
74     {
75       System.err.println("Bad focus for dialog!");
76     }
77     if (reply == JOptionPane.OK_OPTION)
78     {
79       accept = true;
80     }
81   }
82 }