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