JAL-1354 replacement of bare strings in GUI dialogs with i18n bundle lookup via jalvi...
[jalview.git] / src / jalview / gui / EditNameDialog.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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 jalview.util.MessageManager;
21
22 import java.awt.*;
23 import javax.swing.*;
24
25 public class EditNameDialog
26 {
27   JTextField id, description;
28
29   JButton ok = new JButton(MessageManager.getString("action.accept"));
30
31   JButton cancel = new JButton(MessageManager.getString("action.cancel"));
32
33   boolean accept = false;
34
35   public String getName()
36   {
37     return id.getText();
38   }
39
40   public String getDescription()
41   {
42     if (description.getText().length() < 1)
43     {
44       return null;
45     }
46     else
47     {
48       return description.getText();
49     }
50   }
51
52   public EditNameDialog(String name, String desc, String label1,
53           String label2, String title, JComponent parent)
54   {
55     JLabel idlabel = new JLabel(label1);
56     JLabel desclabel = new JLabel(label2);
57     idlabel.setFont(new Font("Courier", Font.PLAIN, 12));
58     desclabel.setFont(new Font("Courier", Font.PLAIN, 12));
59     id = new JTextField(name, 40);
60     description = new JTextField(desc, 40);
61     JPanel panel = new JPanel(new BorderLayout());
62     JPanel panel2 = new JPanel(new BorderLayout());
63     panel2.add(idlabel, BorderLayout.WEST);
64     panel2.add(id, BorderLayout.CENTER);
65     panel.add(panel2, BorderLayout.NORTH);
66     if (desc != null || label2 != null)
67     {
68       panel2 = new JPanel(new BorderLayout());
69       panel2.add(desclabel, BorderLayout.WEST);
70       panel2.add(description, BorderLayout.CENTER);
71       panel.add(panel2, BorderLayout.SOUTH);
72     }
73     int reply = JOptionPane.showInternalConfirmDialog(parent, panel, title,
74             JOptionPane.OK_CANCEL_OPTION);
75     if (!parent.requestFocusInWindow())
76     {
77       System.err.println("Bad focus for dialog!");
78     }
79     if (reply == JOptionPane.OK_OPTION)
80     {
81       accept = true;
82     }
83   }
84 }