2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import java.awt.FlowLayout;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.concurrent.Callable;
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JComponent;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.JTextField;
36 import jalview.util.MessageManager;
39 * A dialog where a name and description may be edited
41 public class EditNameDialog
43 private static final Font COURIER_12 = new Font("Courier", Font.PLAIN,
48 JTextField description;
50 JButton ok = new JButton(MessageManager.getString("action.accept"));
52 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
56 public String getName()
61 public String getDescription()
63 if (description.getText().length() < 1)
69 return description.getText();
81 public EditNameDialog(String name, String desc, String label1,
85 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
86 JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
87 JPanel descriptionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
89 panel.add(descriptionPanel);
91 JLabel nameLabel = new JLabel(label1);
92 // nameLabel.setFont(COURIER_12);
93 namePanel.add(nameLabel);
95 id = new JTextField(name, 40);
98 description = new JTextField(desc, 40);
101 * optionally add field for description
103 if (desc != null || label2 != null)
105 JLabel descLabel = new JLabel(label2);
106 // descLabel.setFont(COURIER_12);
107 descriptionPanel.add(descLabel);
108 descriptionPanel.add(description);
113 * Shows the dialog, and runs the response action if OK is selected
117 public void showDialog(JComponent parent, String title,
118 Callable<Void> action)
120 String ok = MessageManager.getString("action.ok");
121 String cancel = MessageManager.getString("action.cancel");
122 String[] options = new String[] { ok, cancel };
125 JvOptionPane.newOptionDialog(parent)
126 .setResponseHandler(JvOptionPane.OK_OPTION, action)
127 .showInternalDialog(panel, title, JvOptionPane.OK_CANCEL_OPTION,
128 JvOptionPane.PLAIN_MESSAGE, null, options, ok);
131 List<Callable<Void>> actions = new ArrayList<>();
133 actions.add(JvOptionPane.NULLCALLABLE);
135 JvOptionPane.frameDialog(panel, title, JvOptionPane.PLAIN_MESSAGE,
136 options, ok, actions, false);