Merge branch 'develop' into alpha/JAL-3362_Jalview_212_alpha
[jalview.git] / src / jalview / gui / EditNameDialog.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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.BorderLayout;
26 import java.awt.Font;
27
28 import javax.swing.JButton;
29 import javax.swing.JComponent;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33
34 public class EditNameDialog
35 {
36   JTextField id, description;
37
38   JButton ok = new JButton(MessageManager.getString("action.accept"));
39
40   JButton cancel = new JButton(MessageManager.getString("action.cancel"));
41
42   boolean accept = false;
43
44   public String getName()
45   {
46     return id.getText();
47   }
48
49   public String getDescription()
50   {
51     if (description.getText().length() < 1)
52     {
53       return null;
54     }
55     else
56     {
57       return description.getText();
58     }
59   }
60
61   public EditNameDialog(String name, String desc, String label1,
62           String label2, String title, JComponent parent)
63   {
64     JLabel idlabel = new JLabel(label1);
65     JLabel desclabel = new JLabel(label2);
66     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));
67     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));
68     id = new JTextField(name, 40);
69     description = new JTextField(desc, 40);
70     JPanel panel = new JPanel(new BorderLayout());
71     JPanel panel2 = new JPanel(new BorderLayout());
72     panel2.add(idlabel, BorderLayout.WEST);
73     panel2.add(id, BorderLayout.CENTER);
74     panel.add(panel2, BorderLayout.NORTH);
75     if (desc != null || label2 != null)
76     {
77       panel2 = new JPanel(new BorderLayout());
78       panel2.add(desclabel, BorderLayout.WEST);
79       panel2.add(description, BorderLayout.CENTER);
80       panel.add(panel2, BorderLayout.SOUTH);
81     }
82     int reply = JvOptionPane.showInternalConfirmDialog(parent, panel, title,
83             JvOptionPane.OK_CANCEL_OPTION);
84     if (!parent.requestFocusInWindow())
85     {
86       System.err.println("Bad focus for dialog!");
87     }
88     if (reply == JvOptionPane.OK_OPTION)
89     {
90       accept = true;
91     }
92   }
93 }