2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignViewportI;
24 import jalview.bin.Cache;
25 import jalview.commands.EditCommand;
26 import jalview.commands.EditCommand.Action;
27 import jalview.commands.EditCommand.Edit;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.SearchResultMatchI;
33 import jalview.datamodel.SearchResults;
34 import jalview.datamodel.SearchResultsI;
35 import jalview.datamodel.Sequence;
36 import jalview.datamodel.SequenceFeature;
37 import jalview.datamodel.SequenceGroup;
38 import jalview.datamodel.SequenceI;
39 import jalview.io.SequenceAnnotationReport;
40 import jalview.renderer.ResidueShaderI;
41 import jalview.schemes.ResidueProperties;
42 import jalview.structure.SelectionListener;
43 import jalview.structure.SelectionSource;
44 import jalview.structure.SequenceListener;
45 import jalview.structure.StructureSelectionManager;
46 import jalview.structure.VamsasSource;
47 import jalview.util.Comparison;
48 import jalview.util.MappingUtils;
49 import jalview.util.MessageManager;
50 import jalview.util.Platform;
51 import jalview.viewmodel.AlignmentViewport;
53 import java.awt.BorderLayout;
54 import java.awt.Color;
56 import java.awt.FontMetrics;
57 import java.awt.Point;
58 import java.awt.event.MouseEvent;
59 import java.awt.event.MouseListener;
60 import java.awt.event.MouseMotionListener;
61 import java.awt.event.MouseWheelEvent;
62 import java.awt.event.MouseWheelListener;
63 import java.util.Collections;
64 import java.util.List;
66 import javax.swing.JPanel;
67 import javax.swing.SwingUtilities;
68 import javax.swing.ToolTipManager;
74 * @version $Revision: 1.130 $
76 public class SeqPanel extends JPanel
77 implements MouseListener, MouseMotionListener, MouseWheelListener,
78 SequenceListener, SelectionListener
81 * a class that holds computed mouse position
82 * - column of the alignment (0...)
83 * - sequence offset (0...)
84 * - annotation row offset (0...)
85 * where annotation offset is -1 unless the alignment is shown
86 * in wrapped mode, annotations are shown, and the mouse is
87 * over an annnotation row
92 * alignment column position of cursor (0...)
97 * index in alignment of sequence under cursor,
98 * or nearest above if cursor is not over a sequence
103 * index in annotations array of annotation under the cursor
104 * (only possible in wrapped mode with annotations shown),
105 * or -1 if cursor is not over an annotation row
107 final int annotationIndex;
109 MousePos(int col, int seq, int ann)
113 annotationIndex = ann;
116 boolean isOverAnnotation()
118 return annotationIndex != -1;
122 public boolean equals(Object obj)
124 if (obj == null || !(obj instanceof MousePos))
128 MousePos o = (MousePos) obj;
129 boolean b = (column == o.column && seqIndex == o.seqIndex
130 && annotationIndex == o.annotationIndex);
131 // System.out.println(obj + (b ? "= " : "!= ") + this);
136 * A simple hashCode that ensures that instances that satisfy equals() have
140 public int hashCode()
142 return column + seqIndex + annotationIndex;
146 * toString method for debug output purposes only
149 public String toString()
151 return String.format("c%d:s%d:a%d", column, seqIndex,
156 private static final int MAX_TOOLTIP_LENGTH = 300;
158 public SeqCanvas seqCanvas;
160 public AlignmentPanel ap;
163 * last position for mouseMoved event
165 private MousePos lastMousePosition;
167 protected int lastres;
169 protected int startseq;
171 protected AlignViewport av;
173 ScrollThread scrollThread = null;
175 boolean mouseDragging = false;
177 boolean editingSeqs = false;
179 boolean groupEditing = false;
181 // ////////////////////////////////////////
182 // ///Everything below this is for defining the boundary of the rubberband
183 // ////////////////////////////////////////
186 boolean changeEndSeq = false;
188 boolean changeStartSeq = false;
190 boolean changeEndRes = false;
192 boolean changeStartRes = false;
194 SequenceGroup stretchGroup = null;
196 boolean remove = false;
198 Point lastMousePress;
200 boolean mouseWheelPressed = false;
202 StringBuffer keyboardNo1;
204 StringBuffer keyboardNo2;
206 java.net.URL linkImageURL;
208 private final SequenceAnnotationReport seqARep;
210 StringBuilder tooltipText = new StringBuilder();
214 EditCommand editCommand;
216 StructureSelectionManager ssm;
218 SearchResultsI lastSearchResults;
221 * Creates a new SeqPanel object
226 public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
228 linkImageURL = getClass().getResource("/images/link.gif");
229 seqARep = new SequenceAnnotationReport(linkImageURL.toString());
230 ToolTipManager.sharedInstance().registerComponent(this);
231 ToolTipManager.sharedInstance().setInitialDelay(0);
232 ToolTipManager.sharedInstance().setDismissDelay(10000);
234 setBackground(Color.white);
236 seqCanvas = new SeqCanvas(alignPanel);
237 setLayout(new BorderLayout());
238 add(seqCanvas, BorderLayout.CENTER);
240 this.ap = alignPanel;
242 if (!viewport.isDataset())
244 addMouseMotionListener(this);
245 addMouseListener(this);
246 addMouseWheelListener(this);
247 ssm = viewport.getStructureSelectionManager();
248 ssm.addStructureViewerListener(this);
249 ssm.addSelectionListener(this);
253 int startWrapBlock = -1;
255 int wrappedBlock = -1;
258 * Computes the column and sequence row (and possibly annotation row when in
259 * wrapped mode) for the given mouse position
264 MousePos findMousePosition(MouseEvent evt)
266 int col = findColumn(evt);
271 int charHeight = av.getCharHeight();
272 int alignmentHeight = av.getAlignment().getHeight();
273 if (av.getWrapAlignment())
275 int hgap = charHeight;
276 if (av.getScaleAboveWrapped())
281 final int alignmentHeightPixels = alignmentHeight * charHeight + hgap;
282 final int annotationHeight = seqCanvas.getAnnotationHeight();
283 final int cHeight = alignmentHeightPixels + annotationHeight
284 + SeqCanvas.SEQS_ANNOTATION_GAP;
286 int yOffsetPx = y % cHeight; // yPos below repeating width(s)
287 if (yOffsetPx >= alignmentHeightPixels
288 + SeqCanvas.SEQS_ANNOTATION_GAP)
291 * mouse is over annotations; find annotation index, also
292 * last sequence above (for backwards compatible behaviour)
294 AlignmentAnnotation[] anns = av.getAlignment()
295 .getAlignmentAnnotation();
296 int rowOffsetPx = yOffsetPx - alignmentHeightPixels
297 - SeqCanvas.SEQS_ANNOTATION_GAP;
298 annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
299 seqIndex = alignmentHeight - 1;
304 * mouse is over sequence (or the space above sequences)
309 seqIndex = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
315 seqIndex = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
316 alignmentHeight - 1);
319 return new MousePos(col, seqIndex, annIndex);
322 * Returns the aligned sequence position (base 0) at the mouse position, or
323 * the closest visible one
328 int findColumn(MouseEvent evt)
333 int startRes = av.getRanges().getStartRes();
334 if (av.getWrapAlignment())
337 int hgap = av.getCharHeight();
338 if (av.getScaleAboveWrapped())
340 hgap += av.getCharHeight();
343 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
344 + hgap + seqCanvas.getAnnotationHeight();
347 y = Math.max(0, y - hgap);
348 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
350 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
356 wrappedBlock = y / cHeight;
357 wrappedBlock += startRes / cwidth;
358 // allow for wrapped view scrolled right (possible from Overview)
359 int startOffset = startRes % cwidth;
360 res = wrappedBlock * cwidth + startOffset
361 + +Math.min(cwidth - 1, x / av.getCharWidth());
366 * make sure we calculate relative to visible alignment,
367 * rather than right-hand gutter
369 x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
370 res = (x / av.getCharWidth()) + startRes;
371 res = Math.min(res, av.getRanges().getEndRes());
374 if (av.hasHiddenColumns())
376 res = av.getAlignment().getHiddenColumns()
377 .visibleToAbsoluteColumn(res);
384 * When all of a sequence of edits are complete, put the resulting edit list
385 * on the history stack (undo list), and reset flags for editing in progress.
391 if (editCommand != null && editCommand.getSize() > 0)
393 ap.alignFrame.addHistoryItem(editCommand);
394 av.firePropertyChange("alignment", null,
395 av.getAlignment().getSequences());
400 * Tidy up come what may...
405 groupEditing = false;
414 seqCanvas.cursorY = getKeyboardNo1() - 1;
415 scrollToVisible(true);
418 void setCursorColumn()
420 seqCanvas.cursorX = getKeyboardNo1() - 1;
421 scrollToVisible(true);
424 void setCursorRowAndColumn()
426 if (keyboardNo2 == null)
428 keyboardNo2 = new StringBuffer();
432 seqCanvas.cursorX = getKeyboardNo1() - 1;
433 seqCanvas.cursorY = getKeyboardNo2() - 1;
434 scrollToVisible(true);
438 void setCursorPosition()
440 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
442 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
443 scrollToVisible(true);
446 void moveCursor(int dx, int dy)
448 seqCanvas.cursorX += dx;
449 seqCanvas.cursorY += dy;
451 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
453 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
455 int original = seqCanvas.cursorX - dx;
456 int maxWidth = av.getAlignment().getWidth();
458 if (!hidden.isVisible(seqCanvas.cursorX))
460 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
461 int[] region = hidden.getRegionWithEdgeAtRes(visx);
463 if (region != null) // just in case
468 seqCanvas.cursorX = region[1] + 1;
473 seqCanvas.cursorX = region[0] - 1;
476 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
479 if (seqCanvas.cursorX >= maxWidth
480 || !hidden.isVisible(seqCanvas.cursorX))
482 seqCanvas.cursorX = original;
486 scrollToVisible(false);
490 * Scroll to make the cursor visible in the viewport.
493 * just jump to the location rather than scrolling
495 void scrollToVisible(boolean jump)
497 if (seqCanvas.cursorX < 0)
499 seqCanvas.cursorX = 0;
501 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
503 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
506 if (seqCanvas.cursorY < 0)
508 seqCanvas.cursorY = 0;
510 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
512 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
517 boolean repaintNeeded = true;
520 // only need to repaint if the viewport did not move, as otherwise it will
522 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
527 if (av.getWrapAlignment())
529 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
530 int x = av.getAlignment().getHiddenColumns()
531 .absoluteToVisibleColumn(seqCanvas.cursorX);
532 av.getRanges().scrollToWrappedVisible(x);
536 av.getRanges().scrollToVisible(seqCanvas.cursorX,
541 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
543 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
544 seqCanvas.cursorX, seqCanvas.cursorY);
554 void setSelectionAreaAtCursor(boolean topLeft)
556 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
558 if (av.getSelectionGroup() != null)
560 SequenceGroup sg = av.getSelectionGroup();
561 // Find the top and bottom of this group
562 int min = av.getAlignment().getHeight(), max = 0;
563 for (int i = 0; i < sg.getSize(); i++)
565 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
580 sg.setStartRes(seqCanvas.cursorX);
581 if (sg.getEndRes() < seqCanvas.cursorX)
583 sg.setEndRes(seqCanvas.cursorX);
586 min = seqCanvas.cursorY;
590 sg.setEndRes(seqCanvas.cursorX);
591 if (sg.getStartRes() > seqCanvas.cursorX)
593 sg.setStartRes(seqCanvas.cursorX);
596 max = seqCanvas.cursorY + 1;
601 // Only the user can do this
602 av.setSelectionGroup(null);
606 // Now add any sequences between min and max
607 sg.getSequences(null).clear();
608 for (int i = min; i < max; i++)
610 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
615 if (av.getSelectionGroup() == null)
617 SequenceGroup sg = new SequenceGroup();
618 sg.setStartRes(seqCanvas.cursorX);
619 sg.setEndRes(seqCanvas.cursorX);
620 sg.addSequence(sequence, false);
621 av.setSelectionGroup(sg);
624 ap.paintAlignment(false, false);
628 void insertGapAtCursor(boolean group)
630 groupEditing = group;
631 startseq = seqCanvas.cursorY;
632 lastres = seqCanvas.cursorX;
633 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
637 void deleteGapAtCursor(boolean group)
639 groupEditing = group;
640 startseq = seqCanvas.cursorY;
641 lastres = seqCanvas.cursorX + getKeyboardNo1();
642 editSequence(false, false, seqCanvas.cursorX);
646 void insertNucAtCursor(boolean group, String nuc)
648 // TODO not called - delete?
649 groupEditing = group;
650 startseq = seqCanvas.cursorY;
651 lastres = seqCanvas.cursorX;
652 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
656 void numberPressed(char value)
658 if (keyboardNo1 == null)
660 keyboardNo1 = new StringBuffer();
663 if (keyboardNo2 != null)
665 keyboardNo2.append(value);
669 keyboardNo1.append(value);
677 if (keyboardNo1 != null)
679 int value = Integer.parseInt(keyboardNo1.toString());
683 } catch (Exception x)
694 if (keyboardNo2 != null)
696 int value = Integer.parseInt(keyboardNo2.toString());
700 } catch (Exception x)
714 public void mouseReleased(MouseEvent evt)
716 MousePos pos = findMousePosition(evt);
717 if (pos.annotationIndex != -1)
719 // mouse is over annotation row in wrapped mode
723 boolean didDrag = mouseDragging; // did we come here after a drag
724 mouseDragging = false;
725 mouseWheelPressed = false;
727 if (evt.isPopupTrigger()) // Windows: mouseReleased
729 showPopupMenu(evt, pos);
736 doMouseReleasedDefineMode(evt, didDrag);
750 public void mousePressed(MouseEvent evt)
752 lastMousePress = evt.getPoint();
753 MousePos pos = findMousePosition(evt);
754 if (pos.annotationIndex != -1)
756 // mouse is over an annotation row in wrapped mode
760 if (SwingUtilities.isMiddleMouseButton(evt))
762 mouseWheelPressed = true;
766 boolean isControlDown = Platform.isControlDown(evt);
767 if (evt.isShiftDown() || isControlDown)
777 doMousePressedDefineMode(evt, pos);
781 int seq = pos.seqIndex;
782 int res = pos.column;
784 if (seq < 0 || res < 0)
789 if ((seq < av.getAlignment().getHeight())
790 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
807 public void mouseOverSequence(SequenceI sequence, int index, int pos)
809 String tmp = sequence.hashCode() + " " + index + " " + pos;
811 if (lastMessage == null || !lastMessage.equals(tmp))
813 // System.err.println("mouseOver Sequence: "+tmp);
814 ssm.mouseOverSequence(sequence, index, pos, av);
820 * Highlight the mapped region described by the search results object (unless
821 * unchanged). This supports highlight of protein while mousing over linked
822 * cDNA and vice versa. The status bar is also updated to show the location of
823 * the start of the highlighted region.
826 public void highlightSequence(SearchResultsI results)
828 if (results == null || results.equals(lastSearchResults))
832 lastSearchResults = results;
834 boolean wasScrolled = false;
836 if (av.isFollowHighlight())
838 // don't allow highlight of protein/cDNA to also scroll a complementary
839 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
840 // over residue to change abruptly, causing highlighted residue in panel 2
841 // to change, causing a scroll in panel 1 etc)
842 ap.setToScrollComplementPanel(false);
843 wasScrolled = ap.scrollToPosition(results, false);
846 seqCanvas.revalidate();
848 ap.setToScrollComplementPanel(true);
851 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
852 if (seqCanvas.highlightSearchResults(results, noFastPaint))
854 setStatusMessage(results);
859 public VamsasSource getVamsasSource()
861 return this.ap == null ? null : this.ap.av;
865 public void updateColours(SequenceI seq, int index)
867 System.out.println("update the seqPanel colours");
872 * Action on mouse movement is to update the status bar to show the current
873 * sequence position, and (if features are shown) to show any features at the
874 * position in a tooltip. Does nothing if the mouse move does not change
880 public void mouseMoved(MouseEvent evt)
884 // This is because MacOSX creates a mouseMoved
885 // If control is down, other platforms will not.
889 final MousePos mousePos = findMousePosition(evt);
890 if (mousePos.equals(lastMousePosition))
893 * just a pixel move without change of 'cell'
897 lastMousePosition = mousePos;
899 if (mousePos.isOverAnnotation())
901 mouseMovedOverAnnotation(mousePos);
904 final int seq = mousePos.seqIndex;
906 final int column = mousePos.column;
907 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
909 lastMousePosition = null;
910 setToolTipText(null);
911 ap.alignFrame.statusBar.setText("");
915 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
917 if (column >= sequence.getLength())
923 * set status bar message, returning residue position in sequence
925 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
926 final int pos = setStatusMessage(sequence, column, seq);
927 if (ssm != null && !isGapped)
929 mouseOverSequence(sequence, column, pos);
932 tooltipText.setLength(6); // Cuts the buffer back to <html>
934 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
937 for (int g = 0; g < groups.length; g++)
939 if (groups[g].getStartRes() <= column
940 && groups[g].getEndRes() >= column)
942 if (!groups[g].getName().startsWith("JTreeGroup")
943 && !groups[g].getName().startsWith("JGroup"))
945 tooltipText.append(groups[g].getName());
948 if (groups[g].getDescription() != null)
950 tooltipText.append(": " + groups[g].getDescription());
957 * add any features at the position to the tooltip; if over a gap, only
958 * add features that straddle the gap (pos may be the residue before or
961 if (av.isShowSequenceFeatures())
963 List<SequenceFeature> features = ap.getFeatureRenderer()
964 .findFeaturesAtColumn(sequence, column + 1);
965 seqARep.appendFeatures(tooltipText, pos, features,
966 this.ap.getSeqPanel().seqCanvas.fr);
968 if (tooltipText.length() == 6) // <html>
970 setToolTipText(null);
975 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
977 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
978 tooltipText.append("...");
980 String textString = tooltipText.toString();
981 if (lastTooltip == null || !lastTooltip.equals(textString))
983 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
985 setToolTipText(formattedTooltipText);
986 lastTooltip = textString;
992 * When the view is in wrapped mode, and the mouse is over an annotation row,
993 * shows the corresponding tooltip and status message (if any)
998 protected void mouseMovedOverAnnotation(MousePos pos)
1000 final int column = pos.column;
1001 final int rowIndex = pos.annotationIndex;
1003 if (!av.getWrapAlignment() || !av.isShowAnnotation() || rowIndex < 0)
1007 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
1009 String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
1011 setToolTipText(tooltip);
1012 lastTooltip = tooltip;
1014 String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
1016 ap.alignFrame.statusBar.setText(msg);
1019 private Point lastp = null;
1024 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
1027 public Point getToolTipLocation(MouseEvent event)
1029 int x = event.getX(), w = getWidth();
1030 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
1033 if (!event.isShiftDown() || p == null)
1035 p = (tooltipText != null && tooltipText.length() > 6)
1036 ? new Point(event.getX() + wdth, event.getY() - 20)
1040 * TODO: try to modify position region is not obcured by tooltip
1048 * set when the current UI interaction has resulted in a change that requires
1049 * shading in overviews and structures to be recalculated. this could be
1050 * changed to a something more expressive that indicates what actually has
1051 * changed, so selective redraws can be applied (ie. only structures, only
1054 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1057 * set if av.getSelectionGroup() refers to a group that is defined on the
1058 * alignment view, rather than a transient selection
1060 // private boolean editingDefinedGroup = false; // TODO: refactor to
1061 // avcontroller or viewModel
1064 * Sets the status message in alignment panel, showing the sequence number
1065 * (index) and id, and residue and residue position if not at a gap, for the
1066 * given sequence and column position. Returns the residue position returned
1067 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1068 * if at a gapped position.
1071 * aligned sequence object
1075 * index of sequence in alignment
1076 * @return sequence position of residue at column, or adjacent residue if at a
1079 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1081 char sequenceChar = sequence.getCharAt(column);
1082 int pos = sequence.findPosition(column);
1083 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1089 * Builds the status message for the current cursor location and writes it to
1090 * the status bar, for example
1093 * Sequence 3 ID: FER1_SOLLC
1094 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1095 * Sequence 5 ID: FER1_PEA Residue: B (3)
1096 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1101 * sequence position in the alignment (1..)
1102 * @param sequenceChar
1103 * the character under the cursor
1105 * the sequence residue position (if not over a gap)
1107 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1108 char sequenceChar, int residuePos)
1110 StringBuilder text = new StringBuilder(32);
1113 * Sequence number (if known), and sequence name.
1115 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1116 text.append("Sequence").append(seqno).append(" ID: ")
1117 .append(sequence.getName());
1119 String residue = null;
1122 * Try to translate the display character to residue name (null for gap).
1124 boolean isGapped = Comparison.isGap(sequenceChar);
1128 boolean nucleotide = av.getAlignment().isNucleotide();
1129 String displayChar = String.valueOf(sequenceChar);
1132 residue = ResidueProperties.nucleotideName.get(displayChar);
1136 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1137 : ("*".equals(displayChar) ? "STOP"
1138 : ResidueProperties.aa2Triplet.get(displayChar));
1140 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1141 .append(": ").append(residue == null ? displayChar : residue);
1143 text.append(" (").append(Integer.toString(residuePos)).append(")");
1145 ap.alignFrame.statusBar.setText(text.toString());
1149 * Set the status bar message to highlight the first matched position in
1154 private void setStatusMessage(SearchResultsI results)
1156 AlignmentI al = this.av.getAlignment();
1157 int sequenceIndex = al.findIndex(results);
1158 if (sequenceIndex == -1)
1162 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1163 for (SearchResultMatchI m : results.getResults())
1165 SequenceI seq = m.getSequence();
1166 if (seq.getDatasetSequence() != null)
1168 seq = seq.getDatasetSequence();
1173 int start = m.getStart();
1174 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1185 public void mouseDragged(MouseEvent evt)
1187 MousePos pos = findMousePosition(evt);
1188 if (pos.isOverAnnotation())
1190 // mouse is over annotation row in wrapped mode
1194 if (mouseWheelPressed)
1196 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1197 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1199 int oldWidth = av.getCharWidth();
1201 // Which is bigger, left-right or up-down?
1202 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1203 .abs(evt.getX() - lastMousePress.getX()))
1206 * on drag up or down, decrement or increment font size
1208 int fontSize = av.font.getSize();
1209 boolean fontChanged = false;
1211 if (evt.getY() < lastMousePress.getY())
1216 else if (evt.getY() > lastMousePress.getY())
1229 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1231 av.setFont(newFont, true);
1232 av.setCharWidth(oldWidth);
1236 ap.av.getCodingComplement().setFont(newFont, true);
1237 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1238 .getSplitViewContainer();
1239 splitFrame.adjustLayout();
1240 splitFrame.repaint();
1247 * on drag left or right, decrement or increment character width
1250 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1252 newWidth = av.getCharWidth() - 1;
1253 av.setCharWidth(newWidth);
1255 else if (evt.getX() > lastMousePress.getX())
1257 newWidth = av.getCharWidth() + 1;
1258 av.setCharWidth(newWidth);
1262 ap.paintAlignment(false, false);
1266 * need to ensure newWidth is set on cdna, regardless of which
1267 * panel the mouse drag happened in; protein will compute its
1268 * character width as 1:1 or 3:1
1270 av.getCodingComplement().setCharWidth(newWidth);
1271 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1272 .getSplitViewContainer();
1273 splitFrame.adjustLayout();
1274 splitFrame.repaint();
1279 FontMetrics fm = getFontMetrics(av.getFont());
1280 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1282 lastMousePress = evt.getPoint();
1289 doMouseDraggedDefineMode(evt);
1293 int res = pos.column;
1300 if ((lastres == -1) || (lastres == res))
1305 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1307 // dragLeft, delete gap
1308 editSequence(false, false, res);
1312 editSequence(true, false, res);
1315 mouseDragging = true;
1316 if ((scrollThread != null) && (scrollThread.isRunning()))
1318 scrollThread.setEvent(evt);
1322 // TODO: Make it more clever than many booleans
1323 synchronized void editSequence(boolean insertGap, boolean editSeq,
1327 int fixedRight = -1;
1328 boolean fixedColumns = false;
1329 SequenceGroup sg = av.getSelectionGroup();
1331 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1333 // No group, but the sequence may represent a group
1334 if (!groupEditing && av.hasHiddenRows())
1336 if (av.isHiddenRepSequence(seq))
1338 sg = av.getRepresentedSequences(seq);
1339 groupEditing = true;
1343 StringBuilder message = new StringBuilder(64);
1346 message.append("Edit group:");
1347 if (editCommand == null)
1349 editCommand = new EditCommand(
1350 MessageManager.getString("action.edit_group"));
1355 message.append("Edit sequence: " + seq.getName());
1356 String label = seq.getName();
1357 if (label.length() > 10)
1359 label = label.substring(0, 10);
1361 if (editCommand == null)
1363 editCommand = new EditCommand(MessageManager
1364 .formatMessage("label.edit_params", new String[]
1371 message.append(" insert ");
1375 message.append(" delete ");
1378 message.append(Math.abs(startres - lastres) + " gaps.");
1379 ap.alignFrame.statusBar.setText(message.toString());
1381 // Are we editing within a selection group?
1382 if (groupEditing || (sg != null
1383 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1385 fixedColumns = true;
1387 // sg might be null as the user may only see 1 sequence,
1388 // but the sequence represents a group
1391 if (!av.isHiddenRepSequence(seq))
1396 sg = av.getRepresentedSequences(seq);
1399 fixedLeft = sg.getStartRes();
1400 fixedRight = sg.getEndRes();
1402 if ((startres < fixedLeft && lastres >= fixedLeft)
1403 || (startres >= fixedLeft && lastres < fixedLeft)
1404 || (startres > fixedRight && lastres <= fixedRight)
1405 || (startres <= fixedRight && lastres > fixedRight))
1411 if (fixedLeft > startres)
1413 fixedRight = fixedLeft - 1;
1416 else if (fixedRight < startres)
1418 fixedLeft = fixedRight;
1423 if (av.hasHiddenColumns())
1425 fixedColumns = true;
1426 int y1 = av.getAlignment().getHiddenColumns()
1427 .getNextHiddenBoundary(true, startres);
1428 int y2 = av.getAlignment().getHiddenColumns()
1429 .getNextHiddenBoundary(false, startres);
1431 if ((insertGap && startres > y1 && lastres < y1)
1432 || (!insertGap && startres < y2 && lastres > y2))
1438 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1439 // Selection spans a hidden region
1440 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1448 fixedRight = y2 - 1;
1455 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1456 int g, groupSize = vseqs.size();
1457 SequenceI[] groupSeqs = new SequenceI[groupSize];
1458 for (g = 0; g < groupSeqs.length; g++)
1460 groupSeqs[g] = vseqs.get(g);
1466 // If the user has selected the whole sequence, and is dragging to
1467 // the right, we can still extend the alignment and selectionGroup
1468 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1469 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1471 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1472 fixedRight = sg.getEndRes();
1475 // Is it valid with fixed columns??
1476 // Find the next gap before the end
1477 // of the visible region boundary
1478 boolean blank = false;
1479 for (; fixedRight > lastres; fixedRight--)
1483 for (g = 0; g < groupSize; g++)
1485 for (int j = 0; j < startres - lastres; j++)
1487 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1502 if (sg.getSize() == av.getAlignment().getHeight())
1504 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1506 .getNextHiddenBoundary(false, startres)))
1512 int alWidth = av.getAlignment().getWidth();
1513 if (av.hasHiddenRows())
1515 int hwidth = av.getAlignment().getHiddenSequences()
1517 if (hwidth > alWidth)
1522 // We can still insert gaps if the selectionGroup
1523 // contains all the sequences
1524 sg.setEndRes(sg.getEndRes() + startres - lastres);
1525 fixedRight = alWidth + startres - lastres;
1536 else if (!insertGap)
1538 // / Are we able to delete?
1539 // ie are all columns blank?
1541 for (g = 0; g < groupSize; g++)
1543 for (int j = startres; j < lastres; j++)
1545 if (groupSeqs[g].getLength() <= j)
1550 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1552 // Not a gap, block edit not valid
1562 // dragging to the right
1563 if (fixedColumns && fixedRight != -1)
1565 for (int j = lastres; j < startres; j++)
1567 insertChar(j, groupSeqs, fixedRight);
1572 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1573 startres - lastres);
1578 // dragging to the left
1579 if (fixedColumns && fixedRight != -1)
1581 for (int j = lastres; j > startres; j--)
1583 deleteChar(startres, groupSeqs, fixedRight);
1588 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1589 lastres - startres);
1595 // ///Editing a single sequence///////////
1599 // dragging to the right
1600 if (fixedColumns && fixedRight != -1)
1602 for (int j = lastres; j < startres; j++)
1604 insertChar(j, new SequenceI[] { seq }, fixedRight);
1609 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1610 startres - lastres);
1617 // dragging to the left
1618 if (fixedColumns && fixedRight != -1)
1620 for (int j = lastres; j > startres; j--)
1622 if (!Comparison.isGap(seq.getCharAt(startres)))
1627 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1632 // could be a keyboard edit trying to delete none gaps
1634 for (int m = startres; m < lastres; m++)
1636 if (!Comparison.isGap(seq.getCharAt(m)))
1645 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1651 {// insertGap==false AND editSeq==TRUE;
1652 if (fixedColumns && fixedRight != -1)
1654 for (int j = lastres; j < startres; j++)
1656 insertChar(j, new SequenceI[] { seq }, fixedRight);
1661 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1662 startres - lastres);
1669 seqCanvas.repaint();
1672 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1674 int blankColumn = fixedColumn;
1675 for (int s = 0; s < seq.length; s++)
1677 // Find the next gap before the end of the visible region boundary
1678 // If lastCol > j, theres a boundary after the gap insertion
1680 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1682 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1684 // Theres a space, so break and insert the gap
1689 if (blankColumn <= j)
1691 blankColumn = fixedColumn;
1697 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1699 appendEdit(Action.INSERT_GAP, seq, j, 1);
1704 * Helper method to add and perform one edit action.
1711 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1715 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1716 av.getAlignment().getGapCharacter());
1718 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1721 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1724 appendEdit(Action.DELETE_GAP, seq, j, 1);
1726 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1736 public void mouseEntered(MouseEvent e)
1743 if ((scrollThread != null) && (scrollThread.isRunning()))
1745 scrollThread.stopScrolling();
1746 scrollThread = null;
1757 public void mouseExited(MouseEvent e)
1759 if (av.getWrapAlignment())
1764 if (mouseDragging && scrollThread == null)
1766 scrollThread = new ScrollThread();
1771 * Handler for double-click on a position with one or more sequence features.
1772 * Opens the Amend Features dialog to allow feature details to be amended, or
1773 * the feature deleted.
1776 public void mouseClicked(MouseEvent evt)
1778 SequenceGroup sg = null;
1779 MousePos pos = findMousePosition(evt);
1780 if (pos.isOverAnnotation())
1782 // mouse is over annotation label in wrapped mode
1786 if (evt.getClickCount() > 1)
1788 sg = av.getSelectionGroup();
1789 if (sg != null && sg.getSize() == 1
1790 && sg.getEndRes() - sg.getStartRes() < 2)
1792 av.setSelectionGroup(null);
1795 int column = pos.column;
1798 * find features at the position (if not gapped), or straddling
1799 * the position (if at a gap)
1801 SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);// findSeq(evt));
1802 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1803 .findFeaturesAtColumn(sequence, column + 1);
1805 if (!features.isEmpty())
1808 * highlight the first feature at the position on the alignment
1810 SearchResultsI highlight = new SearchResults();
1811 highlight.addResult(sequence, features.get(0).getBegin(), features
1813 seqCanvas.highlightSearchResults(highlight, false);
1816 * open the Amend Features dialog; clear highlighting afterwards,
1817 * whether changes were made or not
1819 List<SequenceI> seqs = Collections.singletonList(sequence);
1820 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1822 av.setSearchResults(null); // clear highlighting
1823 seqCanvas.repaint(); // draw new/amended features
1829 public void mouseWheelMoved(MouseWheelEvent e)
1832 double wheelRotation = e.getPreciseWheelRotation();
1833 if (wheelRotation > 0)
1835 if (e.isShiftDown())
1837 av.getRanges().scrollRight(true);
1842 av.getRanges().scrollUp(false);
1845 else if (wheelRotation < 0)
1847 if (e.isShiftDown())
1849 av.getRanges().scrollRight(false);
1853 av.getRanges().scrollUp(true);
1858 * update status bar and tooltip for new position
1859 * (need to synthesize a mouse movement to refresh tooltip)
1862 ToolTipManager.sharedInstance().mouseMoved(e);
1871 protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
1873 if (pos.isOverAnnotation())
1875 // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1876 // MessageManager.getString(
1877 // "label.cannot_edit_annotations_in_wrapped_view"),
1878 // MessageManager.getString("label.wrapped_view_no_edit"),
1879 // JvOptionPane.WARNING_MESSAGE);
1883 final int res = pos.column;
1884 final int seq = pos.seqIndex;
1886 updateOverviewAndStructs = false;
1888 startWrapBlock = wrappedBlock;
1890 if (seq < 0 || res < 0)
1895 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1897 if ((sequence == null) || (res > sequence.getLength()))
1902 stretchGroup = av.getSelectionGroup();
1904 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1906 stretchGroup = av.getAlignment().findGroup(sequence, res);
1907 if (stretchGroup != null)
1909 // only update the current selection if the popup menu has a group to
1911 av.setSelectionGroup(stretchGroup);
1915 if (evt.isPopupTrigger()) // Mac: mousePressed
1917 showPopupMenu(evt, pos);
1922 * defer right-mouse click handling to mouseReleased on Windows
1923 * (where isPopupTrigger() will answer true)
1924 * NB isRightMouseButton is also true for Cmd-click on Mac
1926 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1933 seqCanvas.cursorX = res;
1934 seqCanvas.cursorY = seq;
1935 seqCanvas.repaint();
1939 if (stretchGroup == null)
1941 createStretchGroup(res, sequence);
1944 if (stretchGroup != null)
1946 stretchGroup.addPropertyChangeListener(seqCanvas);
1949 seqCanvas.repaint();
1952 private void createStretchGroup(int res, SequenceI sequence)
1954 // Only if left mouse button do we want to change group sizes
1955 // define a new group here
1956 SequenceGroup sg = new SequenceGroup();
1957 sg.setStartRes(res);
1959 sg.addSequence(sequence, false);
1960 av.setSelectionGroup(sg);
1963 if (av.getConservationSelected())
1965 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1969 if (av.getAbovePIDThreshold())
1971 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1974 // TODO: stretchGroup will always be not null. Is this a merge error ?
1975 // or is there a threading issue here?
1976 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1978 // Edit end res position of selected group
1979 changeEndRes = true;
1981 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1983 // Edit end res position of selected group
1984 changeStartRes = true;
1986 stretchGroup.getWidth();
1991 * Build and show a pop-up menu at the right-click mouse position
1996 void showPopupMenu(MouseEvent evt, MousePos pos)
1998 final int column = pos.column;
1999 final int seq = pos.seqIndex;
2000 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
2001 List<SequenceFeature> features = ap.getFeatureRenderer()
2002 .findFeaturesAtColumn(sequence, column + 1);
2004 PopupMenu pop = new PopupMenu(ap, null, features);
2005 pop.show(this, evt.getX(), evt.getY());
2009 * Update the display after mouse up on a selection or group
2012 * mouse released event details
2014 * true if this event is happening after a mouse drag (rather than a
2017 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
2019 if (stretchGroup == null)
2024 stretchGroup.removePropertyChangeListener(seqCanvas);
2026 // always do this - annotation has own state
2027 // but defer colourscheme update until hidden sequences are passed in
2028 boolean vischange = stretchGroup.recalcConservation(true);
2029 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
2031 if (stretchGroup.cs != null)
2033 stretchGroup.cs.alignmentChanged(stretchGroup,
2034 av.getHiddenRepSequences());
2036 ResidueShaderI groupColourScheme = stretchGroup
2037 .getGroupColourScheme();
2038 String name = stretchGroup.getName();
2039 if (stretchGroup.cs.conservationApplied())
2041 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2043 if (stretchGroup.cs.getThreshold() > 0)
2045 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2048 PaintRefresher.Refresh(this, av.getSequenceSetId());
2049 // TODO: structure colours only need updating if stretchGroup used to or now
2050 // does contain sequences with structure views
2051 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2052 updateOverviewAndStructs = false;
2053 changeEndRes = false;
2054 changeStartRes = false;
2055 stretchGroup = null;
2065 public void doMouseDraggedDefineMode(MouseEvent evt)
2067 MousePos pos = findMousePosition(evt);
2068 if (pos.isOverAnnotation())
2070 // mouse is over annotation in wrapped mode
2074 int res = pos.column;
2075 int y = pos.seqIndex;
2077 if (wrappedBlock != startWrapBlock)
2082 if (stretchGroup == null)
2087 if (res >= av.getAlignment().getWidth())
2089 res = av.getAlignment().getWidth() - 1;
2092 if (stretchGroup.getEndRes() == res)
2094 // Edit end res position of selected group
2095 changeEndRes = true;
2097 else if (stretchGroup.getStartRes() == res)
2099 // Edit start res position of selected group
2100 changeStartRes = true;
2103 if (res < av.getRanges().getStartRes())
2105 res = av.getRanges().getStartRes();
2110 if (res > (stretchGroup.getStartRes() - 1))
2112 stretchGroup.setEndRes(res);
2113 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2116 else if (changeStartRes)
2118 if (res < (stretchGroup.getEndRes() + 1))
2120 stretchGroup.setStartRes(res);
2121 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2125 int dragDirection = 0;
2131 else if (y < oldSeq)
2136 while ((y != oldSeq) && (oldSeq > -1)
2137 && (y < av.getAlignment().getHeight()))
2139 // This routine ensures we don't skip any sequences, as the
2140 // selection is quite slow.
2141 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2143 oldSeq += dragDirection;
2150 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2152 if (stretchGroup.getSequences(null).contains(nextSeq))
2154 stretchGroup.deleteSequence(seq, false);
2155 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2161 stretchGroup.addSequence(seq, false);
2164 stretchGroup.addSequence(nextSeq, false);
2165 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2174 mouseDragging = true;
2176 if ((scrollThread != null) && (scrollThread.isRunning()))
2178 scrollThread.setEvent(evt);
2182 void scrollCanvas(MouseEvent evt)
2186 if ((scrollThread != null) && (scrollThread.isRunning()))
2188 scrollThread.stopScrolling();
2189 scrollThread = null;
2191 mouseDragging = false;
2195 if (scrollThread == null)
2197 scrollThread = new ScrollThread();
2200 mouseDragging = true;
2201 scrollThread.setEvent(evt);
2206 // this class allows scrolling off the bottom of the visible alignment
2207 class ScrollThread extends Thread
2211 private volatile boolean threadRunning = true;
2213 public ScrollThread()
2218 public void setEvent(MouseEvent e)
2223 public void stopScrolling()
2225 threadRunning = false;
2228 public boolean isRunning()
2230 return threadRunning;
2236 while (threadRunning)
2240 if (mouseDragging && (evt.getY() < 0)
2241 && (av.getRanges().getStartSeq() > 0))
2243 av.getRanges().scrollUp(true);
2246 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2247 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2249 av.getRanges().scrollUp(false);
2252 if (mouseDragging && (evt.getX() < 0))
2254 av.getRanges().scrollRight(false);
2256 else if (mouseDragging && (evt.getX() >= getWidth()))
2258 av.getRanges().scrollRight(true);
2265 } catch (Exception ex)
2273 * modify current selection according to a received message.
2276 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2277 HiddenColumns hidden, SelectionSource source)
2279 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2280 // handles selection messages...
2281 // TODO: extend config options to allow user to control if selections may be
2282 // shared between viewports.
2283 boolean iSentTheSelection = (av == source
2284 || (source instanceof AlignViewport
2285 && ((AlignmentViewport) source).getSequenceSetId()
2286 .equals(av.getSequenceSetId())));
2288 if (iSentTheSelection)
2290 // respond to our own event by updating dependent dialogs
2291 if (ap.getCalculationDialog() != null)
2293 ap.getCalculationDialog().validateCalcTypes();
2299 // process further ?
2300 if (!av.followSelection)
2306 * Ignore the selection if there is one of our own pending.
2308 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2314 * Check for selection in a view of which this one is a dna/protein
2317 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2322 // do we want to thread this ? (contention with seqsel and colsel locks, I
2325 * only copy colsel if there is a real intersection between
2326 * sequence selection and this panel's alignment
2328 boolean repaint = false;
2329 boolean copycolsel = false;
2331 SequenceGroup sgroup = null;
2332 if (seqsel != null && seqsel.getSize() > 0)
2334 if (av.getAlignment() == null)
2336 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2337 + " ViewId=" + av.getViewId()
2338 + " 's alignment is NULL! returning immediately.");
2341 sgroup = seqsel.intersect(av.getAlignment(),
2342 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2343 if ((sgroup != null && sgroup.getSize() > 0))
2348 if (sgroup != null && sgroup.getSize() > 0)
2350 av.setSelectionGroup(sgroup);
2354 av.setSelectionGroup(null);
2356 av.isSelectionGroupChanged(true);
2361 // the current selection is unset or from a previous message
2362 // so import the new colsel.
2363 if (colsel == null || colsel.isEmpty())
2365 if (av.getColumnSelection() != null)
2367 av.getColumnSelection().clear();
2373 // TODO: shift colSel according to the intersecting sequences
2374 if (av.getColumnSelection() == null)
2376 av.setColumnSelection(new ColumnSelection(colsel));
2380 av.getColumnSelection().setElementsFrom(colsel,
2381 av.getAlignment().getHiddenColumns());
2384 av.isColSelChanged(true);
2388 if (copycolsel && av.hasHiddenColumns()
2389 && (av.getAlignment().getHiddenColumns() == null))
2391 System.err.println("Bad things");
2393 if (repaint) // always true!
2395 // probably finessing with multiple redraws here
2396 PaintRefresher.Refresh(this, av.getSequenceSetId());
2397 // ap.paintAlignment(false);
2400 // lastly, update dependent dialogs
2401 if (ap.getCalculationDialog() != null)
2403 ap.getCalculationDialog().validateCalcTypes();
2409 * If this panel is a cdna/protein translation view of the selection source,
2410 * tries to map the source selection to a local one, and returns true. Else
2417 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2418 ColumnSelection colsel, HiddenColumns hidden,
2419 SelectionSource source)
2421 if (!(source instanceof AlignViewportI))
2425 final AlignViewportI sourceAv = (AlignViewportI) source;
2426 if (sourceAv.getCodingComplement() != av
2427 && av.getCodingComplement() != sourceAv)
2433 * Map sequence selection
2435 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2436 av.setSelectionGroup(sg);
2437 av.isSelectionGroupChanged(true);
2440 * Map column selection
2442 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2444 ColumnSelection cs = new ColumnSelection();
2445 HiddenColumns hs = new HiddenColumns();
2446 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2447 av.setColumnSelection(cs);
2448 av.getAlignment().setHiddenColumns(hs);
2450 // lastly, update any dependent dialogs
2451 if (ap.getCalculationDialog() != null)
2453 ap.getCalculationDialog().validateCalcTypes();
2456 PaintRefresher.Refresh(this, av.getSequenceSetId());
2463 * @return null or last search results handled by this panel
2465 public SearchResultsI getLastSearchResults()
2467 return lastSearchResults;