From: gmungoc Date: Mon, 9 Jul 2018 19:03:03 +0000 (+0100) Subject: JAL-3048 EditNameDialog modified for JalviewJS (layout, i18n) X-Git-Tag: Release_2_11_4_0~45^2~18^2~556 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0eecb83722155f32d5eade88a5e8b4a5caca1a67;p=jalview.git JAL-3048 EditNameDialog modified for JalviewJS (layout, i18n) --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index ae5b0e7..daf3d11 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -686,7 +686,7 @@ label.sequence_details_for = Sequence Details for {0} label.sequence_name = Sequence Name label.sequence_description = Sequence Description label.edit_sequence_name_description = Edit Sequence Name/Description -label.spaces_converted_to_backslashes = Spaces have been converted to _ +label.spaces_converted_to_underscores = Spaces have been converted to _ label.no_spaces_allowed_sequence_name = No spaces allowed in Sequence Name label.select_outline_colour = Select Outline Colour label.web_browser_not_found_unix = Unixers\: Couldn't find default web browser.\nAdd the full path to your browser in Preferences." @@ -1363,3 +1363,6 @@ label.most_bound_molecules = Most Bound Molecules label.most_polymer_residues = Most Polymer Residues label.cached_structures = Cached Structures label.free_text_search = Free Text Search +label.annotation_name = Annotation Name +label.annotation_description = Annotation Description +label.edit_annotation_name_description = Edit Annotation Name/Description diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 555977d..b41c855 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -636,7 +636,7 @@ label.sequence_details_for = Detalles de la secuencia para {0} label.sequence_name = Nombre de la secuencia label.sequence_description = Descripción de la secuencia label.edit_sequence_name_description = Editar el nombre/descripción de la secuencia -label.spaces_converted_to_backslashes = Los espacios se han convertido en _ +label.spaces_converted_to_underscores = Los espacios se han convertido en _ label.no_spaces_allowed_sequence_name = No se permiten espacios en el nombre de la secuencia label.select_outline_colour = Seleccionar el color del límite label.web_browser_not_found_unix = Unixers\: No es posible encontrar el navegador web por defecto.\nA\u00F1ada la ruta completa de su navegador en la pesta\u00F1a de Preferencias. @@ -1364,3 +1364,6 @@ label.most_bound_molecules = M label.most_polymer_residues = Más Residuos de Polímeros label.cached_structures = Estructuras en Caché label.free_text_search = Búsqueda de texto libre +label.annotation_name = Nombre de la anotación +label.annotation_description = Descripción de la anotación +label.edit_annotation_name_description = Editar el nombre/descripción de la anotación diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 6f8b225..294b8db 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -34,6 +34,7 @@ import jalview.io.FormatAdapter; import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.util.dialogrunner.RunResponse; import java.awt.Color; import java.awt.Cursor; @@ -51,8 +52,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -210,41 +209,33 @@ public class AnnotationLabels extends JPanel AlignmentAnnotation[] aa = ap.av.getAlignment() .getAlignmentAnnotation(); - boolean fullRepaint = false; - if (evt.getActionCommand().equals(ADDNEW)) + String action = evt.getActionCommand(); + if (ADDNEW.equals(action)) { + /* + * non-returning dialog + */ AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null, null, new Annotation[ap.av.getAlignment().getWidth()]); - - if (!editLabelDescription(newAnnotation)) - { - return; - } - - ap.av.getAlignment().addAnnotation(newAnnotation); - ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0); - fullRepaint = true; + editLabelDescription(newAnnotation, true); } - else if (evt.getActionCommand().equals(EDITNAME)) + else if (EDITNAME.equals(action)) { - String name = aa[selectedRow].label; - editLabelDescription(aa[selectedRow]); - if (!name.equalsIgnoreCase(aa[selectedRow].label)) - { - fullRepaint = true; - } + /* + * non-returning dialog + */ + editLabelDescription(aa[selectedRow], false); } - else if (evt.getActionCommand().equals(HIDE)) + else if (HIDE.equals(action)) { aa[selectedRow].visible = false; } - else if (evt.getActionCommand().equals(DELETE)) + else if (DELETE.equals(action)) { ap.av.getAlignment().deleteAnnotation(aa[selectedRow]); ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]); - fullRepaint = true; } - else if (evt.getActionCommand().equals(SHOWALL)) + else if (SHOWALL.equals(action)) { for (int i = 0; i < aa.length; i++) { @@ -253,13 +244,12 @@ public class AnnotationLabels extends JPanel aa[i].visible = true; } } - fullRepaint = true; } - else if (evt.getActionCommand().equals(OUTPUT_TEXT)) + else if (OUTPUT_TEXT.equals(action)) { new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]); } - else if (evt.getActionCommand().equals(COPYCONS_SEQ)) + else if (COPYCONS_SEQ.equals(action)) { SequenceI cons = null; if (aa[selectedRow].groupRef != null) @@ -274,46 +264,54 @@ public class AnnotationLabels extends JPanel { copy_annotseqtoclipboard(cons); } - } - else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE)) + else if (TOGGLE_LABELSCALE.equals(action)) { aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel; } - ap.refresh(fullRepaint); - + ap.refresh(true); } /** - * DOCUMENT ME! + * Shows a dialog where the annotation name and description may be edited. If + * parameter addNew is true, then on confirmation, a new AlignmentAnnotation + * is added, else an existing annotation is updated. * - * @param e - * DOCUMENT ME! + * @param annotation + * @param addNew */ - boolean editLabelDescription(AlignmentAnnotation annotation) + void editLabelDescription(AlignmentAnnotation annotation, boolean addNew) { - // TODO i18n + String name = MessageManager.getString("label.annotation_name"); + String description = MessageManager + .getString("label.annotation_description"); + String title = MessageManager + .getString("label.edit_annotation_name_description"); EditNameDialog dialog = new EditNameDialog(annotation.label, - annotation.description, " Annotation Name ", - "Annotation Description ", "Edit Annotation Name/Description", - ap.alignFrame); - - if (!dialog.accept) - { - return false; - } - - annotation.label = dialog.getName(); - - String text = dialog.getDescription(); - if (text != null && text.length() == 0) - { - text = null; - } - annotation.description = text; + annotation.description, name, description); - return true; + dialog.showDialog(ap.alignFrame, title, + new RunResponse(JvOptionPane.OK_OPTION) + { + @Override + public void run() + { + annotation.label = dialog.getName(); + String text = dialog.getDescription(); + if (text != null && text.length() == 0) + { + text = null; + } + annotation.description = text; + if (addNew) + { + ap.av.getAlignment().addAnnotation(annotation); + ap.av.getAlignment().setAnnotationIndex(annotation, 0); + } + ap.refresh(true); + } + }); } @Override @@ -783,12 +781,13 @@ public class AnnotationLabels extends JPanel protected void showOrHideAdjuster(MouseEvent evt) { boolean was = resizePanel; - resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH; + resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT + && evt.getX() < HEIGHT_ADJUSTER_WIDTH; if (resizePanel != was) { - setCursor(Cursor.getPredefinedCursor( - resizePanel ? Cursor.S_RESIZE_CURSOR + setCursor(Cursor + .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR : Cursor.DEFAULT_CURSOR)); repaint(); } diff --git a/src/jalview/gui/EditNameDialog.java b/src/jalview/gui/EditNameDialog.java index 0ec4a87..e150b89 100644 --- a/src/jalview/gui/EditNameDialog.java +++ b/src/jalview/gui/EditNameDialog.java @@ -21,26 +21,34 @@ package jalview.gui; import jalview.util.MessageManager; +import jalview.util.dialogrunner.RunResponse; -import java.awt.BorderLayout; +import java.awt.FlowLayout; import java.awt.Font; +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; +/** + * 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 +67,61 @@ 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 = JvOptionPane.showInternalConfirmDialog(parent, panel, title, - JvOptionPane.OK_CANCEL_OPTION); - if (!parent.requestFocusInWindow()) - { - System.err.println("Bad focus for dialog!"); - } - if (reply == JvOptionPane.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. Note the + * RunResponse should be constructed to act on dialog return value + * JvOptionPane.OK_OPTION. + * + * @param action + */ + public void showDialog(JComponent parent, String title, + RunResponse action) + { + Object[] options = new Object[] { MessageManager.getString("action.ok"), + MessageManager.getString("action.cancel") }; + JvOptionPane.newOptionDialog(parent).response(action) + .showInternalDialog(panel, title, + JvOptionPane.YES_NO_CANCEL_OPTION, + JvOptionPane.PLAIN_MESSAGE, null, options, + MessageManager.getString("action.ok")); + } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 776fcd2..26c2759 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -52,6 +52,7 @@ import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; import jalview.util.StringUtils; import jalview.util.UrlLink; +import jalview.util.dialogrunner.RunResponse; import java.awt.Color; import java.awt.event.ActionEvent; @@ -1270,7 +1271,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener @Override public void actionPerformed(ActionEvent actionEvent) { - editSequence_actionPerformed(actionEvent); + editSequence_actionPerformed(); } }); makeReferenceSeq.setText( @@ -1749,30 +1750,27 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Shows a dialog where group name and description may be edited */ protected void groupName_actionPerformed() { - SequenceGroup sg = getGroup(); EditNameDialog dialog = new EditNameDialog(sg.getName(), sg.getDescription(), - " " + MessageManager.getString("label.group_name") + " ", - MessageManager.getString("label.group_description") + " ", + MessageManager.getString("label.group_name"), + MessageManager.getString("label.group_description")); + dialog.showDialog(ap.alignFrame, MessageManager.getString("label.edit_group_name_description"), - ap.alignFrame); - - if (!dialog.accept) - { - return; - } - - sg.setName(dialog.getName()); - sg.setDescription(dialog.getDescription()); - refresh(); + new RunResponse(JvOptionPane.OK_OPTION) + { + @Override + public void run() + { + sg.setName(dialog.getName()); + sg.setDescription(dialog.getDescription()); + refresh(); + } + }); } /** @@ -1793,48 +1791,41 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Shows a dialog where sequence name and description may be edited */ void sequenceName_actionPerformed() { EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence.getDescription(), - " " + MessageManager.getString("label.sequence_name") - + " ", - MessageManager.getString("label.sequence_description") + " ", + MessageManager.getString("label.sequence_name"), + MessageManager.getString("label.sequence_description")); + dialog.showDialog(ap.alignFrame, MessageManager.getString( "label.edit_sequence_name_description"), - ap.alignFrame); - - if (!dialog.accept) - { - return; - } - - if (dialog.getName() != null) - { - if (dialog.getName().indexOf(" ") > -1) - { - JvOptionPane.showMessageDialog(ap, - MessageManager - .getString("label.spaces_converted_to_backslashes"), - MessageManager - .getString("label.no_spaces_allowed_sequence_name"), - JvOptionPane.WARNING_MESSAGE); - } - - sequence.setName(dialog.getName().replace(' ', '_')); - ap.paintAlignment(false, false); - } - - sequence.setDescription(dialog.getDescription()); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - + new RunResponse(JvOptionPane.OK_OPTION) + { + @Override + public void run() + { + if (dialog.getName() != null) + { + if (dialog.getName().indexOf(" ") > -1) + { + JvOptionPane.showMessageDialog(ap, + MessageManager.getString( + "label.spaces_converted_to_underscores"), + MessageManager.getString( + "label.no_spaces_allowed_sequence_name"), + JvOptionPane.WARNING_MESSAGE); + } + sequence.setName(dialog.getName().replace(' ', '_')); + ap.paintAlignment(false, false); + } + sequence.setDescription(dialog.getDescription()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + } + }); } /** @@ -2078,7 +2069,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } - public void editSequence_actionPerformed(ActionEvent actionEvent) + /** + * Shows a dialog where sequence characters may be edited. Any changes are + * applied, and added as an available 'Undo' item in the edit commands + * history. + */ + public void editSequence_actionPerformed() { SequenceGroup sg = ap.av.getSelectionGroup(); @@ -2092,24 +2088,28 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener EditNameDialog dialog = new EditNameDialog( sequence.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1), - null, MessageManager.getString("label.edit_sequence"), null, + null, MessageManager.getString("label.edit_sequence"), null); + dialog.showDialog(ap.alignFrame, MessageManager.getString("label.edit_sequence"), - ap.alignFrame); - - if (dialog.accept) - { - EditCommand editCommand = new EditCommand( - MessageManager.getString("label.edit_sequences"), - Action.REPLACE, - dialog.getName().replace(' ', ap.av.getGapCharacter()), - sg.getSequencesAsArray(ap.av.getHiddenRepSequences()), - sg.getStartRes(), sg.getEndRes() + 1, ap.av.getAlignment()); - - ap.alignFrame.addHistoryItem(editCommand); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - } + new RunResponse(JvOptionPane.OK_OPTION) + { + @Override + public void run() + { + EditCommand editCommand = new EditCommand( + MessageManager.getString("label.edit_sequences"), + Action.REPLACE, + dialog.getName().replace(' ', + ap.av.getGapCharacter()), + sg.getSequencesAsArray( + ap.av.getHiddenRepSequences()), + sg.getStartRes(), sg.getEndRes() + 1, + ap.av.getAlignment()); + ap.alignFrame.addHistoryItem(editCommand); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + } + }); } } diff --git a/src/jalview/util/dialogrunner/DialogRunner.java b/src/jalview/util/dialogrunner/DialogRunner.java index fa98869..fa85ef4 100644 --- a/src/jalview/util/dialogrunner/DialogRunner.java +++ b/src/jalview/util/dialogrunner/DialogRunner.java @@ -204,7 +204,10 @@ public class DialogRunner implements DialogRunnerI defaultResponse.wasRun = true; defaultResponse.run(); } - System.err.println("Doing nothing for " + response); + else + { + System.err.println("Doing nothing for " + response); + } return; } boolean wasRun = false;