X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FEditNameDialog.java;h=ff0fe3a8a7b7f6e4f76f9f3fa0d0aeed70860aa2;hb=140b350c1bb78f0d6b46f9fcbfc523a05c32beba;hp=1e6b38df1649592e3c10ac38b8deffd9eb00e415;hpb=838e4f91d4a53dd315640dbc9ff6ef7a815ee576;p=jalview.git diff --git a/src/jalview/gui/EditNameDialog.java b/src/jalview/gui/EditNameDialog.java index 1e6b38d..ff0fe3a 100644 --- a/src/jalview/gui/EditNameDialog.java +++ b/src/jalview/gui/EditNameDialog.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,27 +20,36 @@ */ package jalview.gui; -import jalview.util.MessageManager; - -import java.awt.BorderLayout; +import java.awt.FlowLayout; import java.awt.Font; +import java.util.concurrent.Callable; +import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; +import jalview.util.MessageManager; + +/** + * A dialog where a name and description may be edited + */ public class EditNameDialog { - JTextField id, description; + private static final Font COURIER_12 = new Font("Courier", Font.PLAIN, + 12); + + JTextField id; + + JTextField description; JButton ok = new JButton(MessageManager.getString("action.accept")); JButton cancel = new JButton(MessageManager.getString("action.cancel")); - boolean accept = false; + private JPanel panel; public String getName() { @@ -59,36 +68,58 @@ public class EditNameDialog } } + /** + * Constructor + * + * @param name + * @param desc + * @param label1 + * @param label2 + */ public EditNameDialog(String name, String desc, String label1, - String label2, String title, JComponent parent) + String label2) { - JLabel idlabel = new JLabel(label1); - JLabel desclabel = new JLabel(label2); - idlabel.setFont(new Font("Courier", Font.PLAIN, 12)); - desclabel.setFont(new Font("Courier", Font.PLAIN, 12)); + panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + JPanel descriptionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + panel.add(namePanel); + panel.add(descriptionPanel); + + JLabel nameLabel = new JLabel(label1); + nameLabel.setFont(COURIER_12); + namePanel.add(nameLabel); + id = new JTextField(name, 40); + namePanel.add(id); + description = new JTextField(desc, 40); - JPanel panel = new JPanel(new BorderLayout()); - JPanel panel2 = new JPanel(new BorderLayout()); - panel2.add(idlabel, BorderLayout.WEST); - panel2.add(id, BorderLayout.CENTER); - panel.add(panel2, BorderLayout.NORTH); + + /* + * optionally add field for description + */ if (desc != null || label2 != null) { - panel2 = new JPanel(new BorderLayout()); - panel2.add(desclabel, BorderLayout.WEST); - panel2.add(description, BorderLayout.CENTER); - panel.add(panel2, BorderLayout.SOUTH); - } - int reply = JOptionPane.showInternalConfirmDialog(parent, panel, title, - JOptionPane.OK_CANCEL_OPTION); - if (!parent.requestFocusInWindow()) - { - System.err.println("Bad focus for dialog!"); - } - if (reply == JOptionPane.OK_OPTION) - { - accept = true; + JLabel descLabel = new JLabel(label2); + descLabel.setFont(COURIER_12); + descriptionPanel.add(descLabel); + descriptionPanel.add(description); } } + + /** + * Shows the dialog, and runs the response action if OK is selected + * + * @param action + */ + public void showDialog(JComponent parent, String title, Callable action) + { + Object[] options = new Object[] { MessageManager.getString("action.ok"), + MessageManager.getString("action.cancel") }; + JvOptionPane.newOptionDialog(parent).setResponseHandler(0, action) + .showInternalDialog(panel, title, + JvOptionPane.YES_NO_CANCEL_OPTION, + JvOptionPane.PLAIN_MESSAGE, null, options, + MessageManager.getString("action.ok")); + } }