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