From 076e8c3064e29c735041c84abb792e60fa9522e5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 10 Aug 2016 11:33:10 +0100 Subject: [PATCH] JAL-2146 show Column no [Sequence no [Residue / pos]] on mouseover --- resources/lang/Messages.properties | 2 + resources/lang/Messages_es.properties | 7 +- src/jalview/appletgui/AnnotationPanel.java | 42 +++++++-- src/jalview/gui/AnnotationPanel.java | 137 ++++++++++++++++++++-------- 4 files changed, 141 insertions(+), 47 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 40c311f..f20558d 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1308,3 +1308,5 @@ status.fetching_3d_structures_for = Fetching 3D Structure for {0} status.obtaining_mapping_with_sifts = Obtaining mapping with SIFTS status.obtaining_mapping_with_nw_alignment = Obtaining mapping with NW alignment status.exporting_alignment_as_x_file = Exporting alignment as {0} file +label.column = Column +label.sequence = Sequence diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 618178d..3f04bad 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -468,8 +468,9 @@ label.create_sequence_feature = Crear funci label.edit_sequence = Editar secuencia label.edit_sequences = Editar secuencias label.sequence_details = Detalles de la secuencia -label.jmol_help = Ayuda de Jmol -label.all = Todo +label.jmol_help = Ayuda de Jmol +# Todos/Todas is gender-sensitive, but currently only used for feminine (cadena / anotación)! +label.all = Todas label.sort_by = Ordenar por label.sort_by_score = Ordenar por puntuación label.sort_by_density = Ordenar por densidad @@ -1314,3 +1315,5 @@ status.fetching_3d_structures_for_selected_entries=Buscando las estructuras 3D p status.fetching_dbrefs_for_sequences_without_valid_refs=Buscando referencias para {0} secuencia(s) sin referencia válida necesaria para mapeado SIFTS status.obtaining_mapping_with_nw_alignment=Obteniendo mapeo por alineamiento Needleman y Wunsch status.exporting_alignment_as_x_file = Exportando alineamiento como fichero tipo {0} +label.column = Columna +label.sequence = Secuencia diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 77700d0..dd652b1 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -22,8 +22,10 @@ package jalview.appletgui; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; +import jalview.datamodel.SequenceI; import jalview.renderer.AnnotationRenderer; import jalview.renderer.AwtRenderPanelI; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.awt.Color; @@ -457,21 +459,47 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, } } - int res = evt.getX() / av.getCharWidth() + av.getStartRes(); + int column = evt.getX() / av.getCharWidth() + av.getStartRes(); if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + column = av.getColumnSelection().adjustForHiddenColumns(column); } - if (row > -1 && res < aa[row].annotations.length - && aa[row].annotations[res] != null) + if (row > -1 && column < aa[row].annotations.length + && aa[row].annotations[column] != null) { - StringBuffer text = new StringBuffer("Sequence position " + (res + 1)); - if (aa[row].annotations[res].description != null) + StringBuilder text = new StringBuilder(); + text.append(MessageManager.getString("label.column")).append(" ") + .append(column + 1); + if (aa[row].annotations[column].description != null) { - text.append(" " + aa[row].annotations[res].description); + text.append(" ").append(aa[row].annotations[column].description); } + + /* + * if the annotation is sequence-specific, show the sequence number + * in the alignment, and (if not a gap) the residue and position + */ + SequenceI seqref = aa[row].sequenceRef; + if (seqref != null) + { + int seqIndex = av.getAlignment().findIndex(seqref); + if (seqIndex != -1) + { + text.append(", ") + .append(MessageManager.getString("label.sequence")) + .append(" ").append(seqIndex + 1); + char residue = seqref.getCharAt(column); + if (!Comparison.isGap(residue)) + { + int residuePos = seqref.findPosition(column); + text.append(": ").append(residue).append(" (") + .append(residuePos).append(")"); + } + } + } + ap.alignFrame.statusBar.setText(text.toString()); } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 60c182e..398f57d 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -26,6 +26,7 @@ import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; import jalview.renderer.AnnotationRenderer; import jalview.renderer.AwtRenderPanelI; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.awt.AlphaComposite; @@ -629,10 +630,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } /** - * DOCUMENT ME! + * Constructs the tooltip, and constructs and displays a status message, for + * the current mouse position * * @param evt - * DOCUMENT ME! */ @Override public void mouseMoved(MouseEvent evt) @@ -658,7 +659,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (evt.getY() < height) { row = i; - break; } } @@ -669,64 +669,125 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int column = (evt.getX() / av.getCharWidth()) + av.getStartRes(); if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + column = av.getColumnSelection().adjustForHiddenColumns(column); } - if (row > -1 && aa[row].annotations != null - && res < aa[row].annotations.length) + AlignmentAnnotation ann = aa[row]; + if (row > -1 && ann.annotations != null + && column < ann.annotations.length) + { + buildToolTip(ann, column, aa); + setStatusMessage(column, ann); + } + else { - if (aa[row].graphGroup > -1) + this.setToolTipText(null); + ap.alignFrame.statusBar.setText(" "); + } + } + + /** + * Builds a tooltip for the annotation at the current mouse position. + * + * @param ann + * @param column + * @param anns + */ + void buildToolTip(AlignmentAnnotation ann, int column, + AlignmentAnnotation[] anns) + { + if (ann.graphGroup > -1) + { + StringBuilder tip = new StringBuilder(32); + tip.append(""); + for (int i = 0; i < anns.length; i++) { - StringBuffer tip = new StringBuffer(""); - for (int gg = 0; gg < aa.length; gg++) + if (anns[i].graphGroup == ann.graphGroup + && anns[i].annotations[column] != null) { - if (aa[gg].graphGroup == aa[row].graphGroup - && aa[gg].annotations[res] != null) + tip.append(anns[i].label); + String description = anns[i].annotations[column].description; + if (description != null && description.length() > 0) { - tip.append(aa[gg].label + " " - + aa[gg].annotations[res].description + "
"); + tip.append(" ").append(description); } - } - if (tip.length() != 6) - { - tip.setLength(tip.length() - 4); - this.setToolTipText(tip.toString() + ""); + tip.append("
"); } } - else if (aa[row].annotations[res] != null - && aa[row].annotations[res].description != null - && aa[row].annotations[res].description.length() > 0) + if (tip.length() != 6) { - this.setToolTipText(JvSwingUtils.wrapTooltip(true, - aa[row].annotations[res].description)); + tip.setLength(tip.length() - 4); + this.setToolTipText(tip.toString() + ""); } - else + } + else if (ann.annotations[column] != null) + { + String description = ann.annotations[column].description; + if (description != null && description.length() > 0) { - // clear the tooltip. - this.setToolTipText(null); + this.setToolTipText(JvSwingUtils.wrapTooltip(true, description)); } + } + else + { + // clear the tooltip. + this.setToolTipText(null); + } + } - if (aa[row].annotations[res] != null) + /** + * Constructs and displays the status bar message + * + * @param column + * @param ann + */ + void setStatusMessage(int column, AlignmentAnnotation ann) + { + /* + * show alignment column and annotation description if any + */ + StringBuilder text = new StringBuilder(32); + text.append(MessageManager.getString("label.column")).append(" ") + .append(column + 1); + + if (ann.annotations[column] != null) + { + String description = ann.annotations[column].description; + if (description != null && description.trim().length() > 0) { - StringBuffer text = new StringBuffer("Sequence position " - + (res + 1)); + text.append(" ").append(description); + } + } - if (aa[row].annotations[res].description != null) + /* + * if the annotation is sequence-specific, show the sequence number + * in the alignment, and (if not a gap) the residue and position + */ + SequenceI seqref = ann.sequenceRef; + if (seqref != null) + { + int seqIndex = av.getAlignment().findIndex(seqref); + if (seqIndex != -1) + { + text.append(", ") + .append(MessageManager.getString("label.sequence")) + .append(" ") + .append(seqIndex + 1); + char residue = seqref.getCharAt(column); + if (!Comparison.isGap(residue)) { - text.append(" " + aa[row].annotations[res].description); + int residuePos = seqref.findPosition(column); + text.append(": ").append(residue).append(" (") + .append(residuePos).append(")"); } - - ap.alignFrame.statusBar.setText(text.toString()); } } - else - { - this.setToolTipText(null); - } + + ap.alignFrame.statusBar.setText(text.toString()); } /** -- 1.7.10.2