From: gmungoc Date: Fri, 2 Feb 2018 15:56:43 +0000 (+0000) Subject: JAL-984 merged to spikes-mungo X-Git-Tag: Release_2_11_0~62^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=673150e058ad2a7649093c0c4afde99e1ac5e6e3;p=jalview.git JAL-984 merged to spikes-mungo --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 0f801eb..3f5aa94 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1344,7 +1344,7 @@ label.filters = Filters label.join_conditions = Join conditions with label.score = Score label.colour_by_label = Colour by label -label.variable_colour = Variable colour +label.variable_colour = Variable colour... label.select_colour = Select colour option.enable_disable_autosearch = When ticked, search is performed automatically option.autosearch = Autosearch diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index d035e73..e42d6b8 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1345,7 +1345,7 @@ label.filters = Filtros label.join_conditions = Combinar condiciones con label.score = Puntuación label.colour_by_label = Colorear por texto -label.variable_colour = Color variable +label.variable_colour = Color variable... label.select_colour = Seleccionar color option.enable_disable_autosearch = Marcar para buscar automáticamente option.autosearch = Auto búsqueda diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index d8f65a5..c049326 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -31,6 +31,7 @@ import jalview.util.ParseHtmlBodyAndLinks; import java.awt.Checkbox; import java.awt.CheckboxMenuItem; import java.awt.Color; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.FontMetrics; @@ -269,6 +270,8 @@ public class AnnotationLabels extends Panel public void mouseMoved(MouseEvent evt) { resizePanel = evt.getY() < 10 && evt.getX() < 14; + setCursor(Cursor.getPredefinedCursor( + resizePanel ? Cursor.S_RESIZE_CURSOR : Cursor.DEFAULT_CURSOR)); int row = getSelectedRow(evt.getY() + scrollOffset); if (row > -1) @@ -406,6 +409,7 @@ public class AnnotationLabels extends Panel resizePanel = false; dragEvent = null; dragCancelled = false; + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); repaint(); ap.annotationPanel.repaint(); } @@ -418,6 +422,8 @@ public class AnnotationLabels extends Panel resizePanel = true; repaint(); } + setCursor(Cursor.getPredefinedCursor( + resizePanel ? Cursor.S_RESIZE_CURSOR : Cursor.DEFAULT_CURSOR)); } @Override @@ -905,10 +911,10 @@ public class AnnotationLabels extends Panel g.translate(0, +scrollOffset); if (resizePanel) { - g.setColor(Color.red); - g.setPaintMode(); - g.drawLine(2, 8, 5, 2); - g.drawLine(5, 2, 8, 8); + // g.setColor(Color.red); + // g.setPaintMode(); + // g.drawLine(2, 8, 5, 2); + // g.drawLine(5, 2, 8, 8); } else if (!dragCancelled && dragEvent != null && aa != null) { diff --git a/src/jalview/appletgui/IdwidthAdjuster.java b/src/jalview/appletgui/IdwidthAdjuster.java index 75e3243..e9722fe 100755 --- a/src/jalview/appletgui/IdwidthAdjuster.java +++ b/src/jalview/appletgui/IdwidthAdjuster.java @@ -20,7 +20,7 @@ */ package jalview.appletgui; -import java.awt.Color; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; @@ -54,11 +54,13 @@ public class IdwidthAdjuster extends Panel addMouseMotionListener(this); } + @Override public void mousePressed(MouseEvent evt) { oldX = evt.getX(); } + @Override public void mouseReleased(MouseEvent evt) { active = false; @@ -85,18 +87,24 @@ public class IdwidthAdjuster extends Panel // } } + @Override public void mouseEntered(MouseEvent evt) { active = true; + setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); + repaint(); } + @Override public void mouseExited(MouseEvent evt) { active = false; + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); repaint(); } + @Override public void mouseDragged(MouseEvent evt) { active = true; @@ -112,25 +120,28 @@ public class IdwidthAdjuster extends Panel } } + @Override public void mouseMoved(MouseEvent evt) { } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void paint(Graphics g) { - g.setColor(Color.white); - g.fillRect(0, 0, getSize().width, getSize().height); - if (active) - { - if (image != null) - { - g.drawImage(image, getSize().width - 20, 2, this); - } - } + // g.setColor(Color.white); + // g.fillRect(0, 0, getSize().width, getSize().height); + // if (active) + // { + // if (image != null) + // { + // g.drawImage(image, getSize().width - 20, 2, this); + // } + // } } } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index de69907..4e181b3 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.analysis.AlignSeq; import jalview.analysis.AlignmentUtils; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; @@ -29,9 +30,12 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.FileFormat; import jalview.io.FormatAdapter; +import jalview.util.Comparison; import jalview.util.MessageManager; +import jalview.util.Platform; import java.awt.Color; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; @@ -62,63 +66,71 @@ import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; /** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ + * The panel that holds the labels for alignment annotations, providing + * tooltips, context menus, drag to reorder rows, and drag to adjust panel + * height */ public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener { + // width in pixels within which height adjuster arrows are shown and active + private static final int HEIGHT_ADJUSTER_WIDTH = 50; + private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern .compile("<"); - String TOGGLE_LABELSCALE = MessageManager + private static final Font font = new Font("Arial", Font.PLAIN, 11); + + private static final String TOGGLE_LABELSCALE = MessageManager .getString("label.scale_label_to_column"); - String ADDNEW = MessageManager.getString("label.add_new_row"); + private static final String ADDNEW = MessageManager + .getString("label.add_new_row"); - String EDITNAME = MessageManager + private static final String EDITNAME = MessageManager .getString("label.edit_label_description"); - String HIDE = MessageManager.getString("label.hide_row"); + private static final String HIDE = MessageManager + .getString("label.hide_row"); - String DELETE = MessageManager.getString("label.delete_row"); + private static final String DELETE = MessageManager + .getString("label.delete_row"); - String SHOWALL = MessageManager.getString("label.show_all_hidden_rows"); + private static final String SHOWALL = MessageManager + .getString("label.show_all_hidden_rows"); - String OUTPUT_TEXT = MessageManager.getString("label.export_annotation"); + private static final String OUTPUT_TEXT = MessageManager + .getString("label.export_annotation"); - String COPYCONS_SEQ = MessageManager + private static final String COPYCONS_SEQ = MessageManager .getString("label.copy_consensus_sequence"); - boolean resizePanel = false; + private static Image adjusterImage; - Image image; + private static int adjusterImageHeight; - AlignmentPanel ap; + private final boolean debugRedraw = false; - AlignViewport av; + private AlignmentPanel ap; - boolean resizing = false; + AlignViewport av; - MouseEvent dragEvent; + private MouseEvent dragEvent; - int oldY; + private int oldY; - int selectedRow; + private int selectedRow; private int scrollOffset = 0; - Font font = new Font("Arial", Font.PLAIN, 11); - private boolean hasHiddenRows; + private boolean resizePanel = false; + /** - * Creates a new AnnotationLabels object. + * Creates a new AnnotationLabels object * * @param ap - * DOCUMENT ME! */ public AnnotationLabels(AlignmentPanel ap) { @@ -126,12 +138,32 @@ public class AnnotationLabels extends JPanel av = ap.av; ToolTipManager.sharedInstance().registerComponent(this); + if (adjusterImage == null) + { + loadAdjusterImage(); + } + + addMouseListener(this); + addMouseMotionListener(this); + addMouseWheelListener(ap.getAnnotationPanel()); + } + + public AnnotationLabels(AlignViewport av) + { + this.av = av; + } + + /** + * Loads the gif for the panel height adjustment + */ + protected void loadAdjusterImage() + { java.net.URL url = getClass().getResource("/images/idwidth.gif"); Image temp = null; if (url != null) { - temp = java.awt.Toolkit.getDefaultToolkit().createImage(url); + temp = Toolkit.getDefaultToolkit().createImage(url); } try @@ -148,16 +180,8 @@ public class AnnotationLabels extends JPanel Graphics2D g = (Graphics2D) bi.getGraphics(); g.rotate(Math.toRadians(90)); g.drawImage(temp, 0, -bi.getWidth(this), this); - image = bi; - - addMouseListener(this); - addMouseMotionListener(this); - addMouseWheelListener(ap.getAnnotationPanel()); - } - - public AnnotationLabels(AlignViewport av) - { - this.av = av; + adjusterImage = bi; + adjusterImageHeight = bi.getHeight(); } /** @@ -605,10 +629,9 @@ public class AnnotationLabels extends JPanel } /** - * DOCUMENT ME! + * Reorders annotation rows after a drag of a label * * @param evt - * DOCUMENT ME! */ @Override public void mouseReleased(MouseEvent evt) @@ -623,6 +646,9 @@ public class AnnotationLabels extends JPanel getSelectedRow(evt.getY() - getScrollOffset()); int end = selectedRow; + /* + * if dragging to resize instead, start == end + */ if (start != end) { // Swap these annotations @@ -646,31 +672,13 @@ public class AnnotationLabels extends JPanel } /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! - */ - @Override - public void mouseEntered(MouseEvent evt) - { - if (evt.getY() < 10) - { - resizePanel = true; - repaint(); - } - } - - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! + * Removes the height adjuster image on leaving the panel, unless currently + * dragging it */ @Override public void mouseExited(MouseEvent evt) { - if (dragEvent == null) + if (resizePanel && dragEvent == null) { resizePanel = false; repaint(); @@ -678,10 +686,11 @@ public class AnnotationLabels extends JPanel } /** - * DOCUMENT ME! + * A mouse drag may be either an adjustment of the panel height (if flag + * resizePanel is set on), or a reordering of the annotation rows. The former + * is dealt with by this method, the latter in mouseReleased. * * @param evt - * DOCUMENT ME! */ @Override public void mouseDragged(MouseEvent evt) @@ -715,15 +724,14 @@ public class AnnotationLabels extends JPanel } /** - * DOCUMENT ME! + * Updates the tooltip as the mouse moves over the labels * * @param evt - * DOCUMENT ME! */ @Override public void mouseMoved(MouseEvent evt) { - resizePanel = evt.getY() < 10; + showOrHideAdjuster(evt); getSelectedRow(evt.getY() - getScrollOffset()); @@ -799,6 +807,26 @@ public class AnnotationLabels extends JPanel } } + /** + * Shows the height adjuster image if the mouse moves into the top left + * region, or hides it if the mouse leaves the regio + * + * @param evt + */ + protected void showOrHideAdjuster(MouseEvent evt) + { + boolean was = resizePanel; + resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH; + + if (resizePanel != was) + { + setCursor(Cursor.getPredefinedCursor( + resizePanel ? Cursor.S_RESIZE_CURSOR + : Cursor.DEFAULT_CURSOR)); + repaint(); + } + } + @Override public void mouseClicked(MouseEvent evt) { @@ -818,11 +846,9 @@ public class AnnotationLabels extends JPanel // process modifiers SequenceGroup sg = ap.av.getSelectionGroup(); if (sg == null || sg == aa[selectedRow].groupRef - || !(jalview.util.Platform.isControlDown(evt) - || evt.isShiftDown())) + || !(Platform.isControlDown(evt) || evt.isShiftDown())) { - if (jalview.util.Platform.isControlDown(evt) - || evt.isShiftDown()) + if (Platform.isControlDown(evt) || evt.isShiftDown()) { // clone a new selection group from the associated group ap.av.setSelectionGroup( @@ -881,8 +907,7 @@ public class AnnotationLabels extends JPanel // we make a copy rather than edit the current selection if no // modifiers pressed // see Enhancement JAL-1557 - if (!(jalview.util.Platform.isControlDown(evt) - || evt.isShiftDown())) + if (!(Platform.isControlDown(evt) || evt.isShiftDown())) { sg = new SequenceGroup(sg); sg.clear(); @@ -890,7 +915,7 @@ public class AnnotationLabels extends JPanel } else { - if (jalview.util.Platform.isControlDown(evt)) + if (Platform.isControlDown(evt)) { sg.addOrRemove(aa[selectedRow].sequenceRef, true); } @@ -935,8 +960,8 @@ public class AnnotationLabels extends JPanel if (dseqs[0] == null) { dseqs[0] = new Sequence(sq); - dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps( - jalview.util.Comparison.GapChars, sq.getSequenceAsString())); + dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars, + sq.getSequenceAsString())); sq.setDatasetSequence(dseqs[0]); } @@ -1018,8 +1043,6 @@ public class AnnotationLabels extends JPanel drawComponent(g, false, width); } - private final boolean debugRedraw = false; - /** * Draw the full set of annotation Labels for the alignment at the given * cursor @@ -1204,7 +1227,7 @@ public class AnnotationLabels extends JPanel if (resizePanel) { - g.drawImage(image, 2, 0 - getScrollOffset(), this); + // g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this); } else if (dragEvent != null && aa != null) { @@ -1225,4 +1248,9 @@ public class AnnotationLabels extends JPanel { return scrollOffset; } + + @Override + public void mouseEntered(MouseEvent e) + { + } } diff --git a/src/jalview/gui/IdwidthAdjuster.java b/src/jalview/gui/IdwidthAdjuster.java index 8400543..99792c6 100755 --- a/src/jalview/gui/IdwidthAdjuster.java +++ b/src/jalview/gui/IdwidthAdjuster.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.AlignViewportI; import java.awt.Color; +import java.awt.Cursor; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseEvent; @@ -198,7 +199,12 @@ public class IdwidthAdjuster extends JPanel { if (image != null) { - g.drawImage(image, getWidth() - 20, 2, this); + // g.drawImage(image, getWidth() - 20, 2, this); + setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); + } + else + { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 97d051b..0cf7ef4 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -550,24 +550,27 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { desc = String.format("%s %d-%d", sf.getType(), start, end); } + String tooltip = desc; String description = sf.getDescription(); if (description != null) { description = StringUtils.stripHtmlTags(description); - if (description.length() <= 6) + if (description.length() > 12) { - desc = desc + " " + description; + desc = desc + " " + description.substring(0, 12) + ".."; } else { - desc = desc + " " + description.substring(0, 6) + ".."; + desc = desc + " " + description; } + tooltip = tooltip + " " + description; } if (sf.getFeatureGroup() != null) { - desc = desc + " (" + sf.getFeatureGroup() + ")"; + tooltip = tooltip + (" (" + sf.getFeatureGroup() + ")"); } JMenuItem item = new JMenuItem(desc); + item.setToolTipText(tooltip); item.addActionListener(new ActionListener() { @Override