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."
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
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.
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
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;
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;
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++)
{
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)
{
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
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();
}
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()
{
}
}
+ /**
+ * 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"));
+ }
}
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;
@Override
public void actionPerformed(ActionEvent actionEvent)
{
- editSequence_actionPerformed(actionEvent);
+ editSequence_actionPerformed();
}
});
makeReferenceSeq.setText(
}
/**
- * 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();
+ }
+ });
}
/**
}
/**
- * 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());
+ }
+ });
}
/**
}
- 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();
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());
+ }
+ });
}
}
defaultResponse.wasRun = true;
defaultResponse.run();
}
- System.err.println("Doing nothing for " + response);
+ else
+ {
+ System.err.println("Doing nothing for " + response);
+ }
return;
}
boolean wasRun = false;