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;
117 public boolean equals(Object obj)
119 if (obj == null || !(obj instanceof MousePos))
123 MousePos o = (MousePos) obj;
124 boolean b = (column == o.column && seqIndex == o.seqIndex
125 && annotationIndex == o.annotationIndex);
126 // System.out.println(obj + (b ? "= " : "!= ") + this);
131 * A simple hashCode that ensures that instances that satisfy equals() have
135 public int hashCode()
137 return column + seqIndex + annotationIndex;
141 * toString method for debug output purposes only
144 public String toString()
146 return String.format("c%d:s%d:a%d", column, seqIndex,
151 private static final int MAX_TOOLTIP_LENGTH = 300;
153 public SeqCanvas seqCanvas;
155 public AlignmentPanel ap;
158 * last position for mouseMoved event
160 private MousePos lastMousePosition;
162 protected int lastres;
164 protected int startseq;
166 protected AlignViewport av;
168 ScrollThread scrollThread = null;
170 boolean mouseDragging = false;
172 boolean editingSeqs = false;
174 boolean groupEditing = false;
176 // ////////////////////////////////////////
177 // ///Everything below this is for defining the boundary of the rubberband
178 // ////////////////////////////////////////
181 boolean changeEndSeq = false;
183 boolean changeStartSeq = false;
185 boolean changeEndRes = false;
187 boolean changeStartRes = false;
189 SequenceGroup stretchGroup = null;
191 boolean remove = false;
193 Point lastMousePress;
195 boolean mouseWheelPressed = false;
197 StringBuffer keyboardNo1;
199 StringBuffer keyboardNo2;
201 java.net.URL linkImageURL;
203 private final SequenceAnnotationReport seqARep;
205 StringBuilder tooltipText = new StringBuilder();
209 EditCommand editCommand;
211 StructureSelectionManager ssm;
213 SearchResultsI lastSearchResults;
216 * Creates a new SeqPanel object
221 public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
223 linkImageURL = getClass().getResource("/images/link.gif");
224 seqARep = new SequenceAnnotationReport(linkImageURL.toString());
225 ToolTipManager.sharedInstance().registerComponent(this);
226 ToolTipManager.sharedInstance().setInitialDelay(0);
227 ToolTipManager.sharedInstance().setDismissDelay(10000);
229 setBackground(Color.white);
231 seqCanvas = new SeqCanvas(alignPanel);
232 setLayout(new BorderLayout());
233 add(seqCanvas, BorderLayout.CENTER);
235 this.ap = alignPanel;
237 if (!viewport.isDataset())
239 addMouseMotionListener(this);
240 addMouseListener(this);
241 addMouseWheelListener(this);
242 ssm = viewport.getStructureSelectionManager();
243 ssm.addStructureViewerListener(this);
244 ssm.addSelectionListener(this);
248 int startWrapBlock = -1;
250 int wrappedBlock = -1;
253 * Computes the column and sequence row (or possibly annotation row when in
254 * wrapped mode) for the given mouse position
259 MousePos findMousePosition(MouseEvent evt)
261 int col = findColumn(evt);
266 int charHeight = av.getCharHeight();
267 int alignmentHeight = av.getAlignment().getHeight();
268 if (av.getWrapAlignment())
270 int hgap = charHeight;
271 if (av.getScaleAboveWrapped())
276 final int alignmentHeightPixels = alignmentHeight * charHeight + hgap;
277 final int annotationHeight = seqCanvas.getAnnotationHeight();
278 final int cHeight = alignmentHeightPixels + annotationHeight;
280 int yOffsetPx = y % cHeight; // yPos below repeating width(s)
281 if (yOffsetPx > alignmentHeightPixels)
284 * mouse is over annotations
286 AlignmentAnnotation[] anns = av.getAlignment()
287 .getAlignmentAnnotation();
288 int rowOffsetPx = yOffsetPx - alignmentHeightPixels;
289 annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
290 // also last sequence in alignment (for backwards compatible behaviour)
291 seq = alignmentHeight - 1;
296 * mouse is over sequence (or the space above sequences)
301 seq = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
307 seq = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
308 alignmentHeight - 1);
312 return new MousePos(col, seqIndex, annIndex);
315 * Returns the aligned sequence position (base 0) at the mouse position, or
316 * the closest visible one
321 int findColumn(MouseEvent evt)
326 int startRes = av.getRanges().getStartRes();
327 if (av.getWrapAlignment())
330 int hgap = av.getCharHeight();
331 if (av.getScaleAboveWrapped())
333 hgap += av.getCharHeight();
336 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
337 + hgap + seqCanvas.getAnnotationHeight();
340 y = Math.max(0, y - hgap);
341 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
343 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
349 wrappedBlock = y / cHeight;
350 wrappedBlock += startRes / cwidth;
351 // allow for wrapped view scrolled right (possible from Overview)
352 int startOffset = startRes % cwidth;
353 res = wrappedBlock * cwidth + startOffset
354 + +Math.min(cwidth - 1, x / av.getCharWidth());
359 * make sure we calculate relative to visible alignment,
360 * rather than right-hand gutter
362 x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
363 res = (x / av.getCharWidth()) + startRes;
364 res = Math.min(res, av.getRanges().getEndRes());
367 if (av.hasHiddenColumns())
369 res = av.getAlignment().getHiddenColumns()
370 .visibleToAbsoluteColumn(res);
377 * When all of a sequence of edits are complete, put the resulting edit list
378 * on the history stack (undo list), and reset flags for editing in progress.
384 if (editCommand != null && editCommand.getSize() > 0)
386 ap.alignFrame.addHistoryItem(editCommand);
387 av.firePropertyChange("alignment", null,
388 av.getAlignment().getSequences());
393 * Tidy up come what may...
398 groupEditing = false;
407 seqCanvas.cursorY = getKeyboardNo1() - 1;
408 scrollToVisible(true);
411 void setCursorColumn()
413 seqCanvas.cursorX = getKeyboardNo1() - 1;
414 scrollToVisible(true);
417 void setCursorRowAndColumn()
419 if (keyboardNo2 == null)
421 keyboardNo2 = new StringBuffer();
425 seqCanvas.cursorX = getKeyboardNo1() - 1;
426 seqCanvas.cursorY = getKeyboardNo2() - 1;
427 scrollToVisible(true);
431 void setCursorPosition()
433 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
435 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
436 scrollToVisible(true);
439 void moveCursor(int dx, int dy)
441 seqCanvas.cursorX += dx;
442 seqCanvas.cursorY += dy;
444 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
446 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
448 int original = seqCanvas.cursorX - dx;
449 int maxWidth = av.getAlignment().getWidth();
451 if (!hidden.isVisible(seqCanvas.cursorX))
453 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
454 int[] region = hidden.getRegionWithEdgeAtRes(visx);
456 if (region != null) // just in case
461 seqCanvas.cursorX = region[1] + 1;
466 seqCanvas.cursorX = region[0] - 1;
469 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
472 if (seqCanvas.cursorX >= maxWidth
473 || !hidden.isVisible(seqCanvas.cursorX))
475 seqCanvas.cursorX = original;
479 scrollToVisible(false);
483 * Scroll to make the cursor visible in the viewport.
486 * just jump to the location rather than scrolling
488 void scrollToVisible(boolean jump)
490 if (seqCanvas.cursorX < 0)
492 seqCanvas.cursorX = 0;
494 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
496 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
499 if (seqCanvas.cursorY < 0)
501 seqCanvas.cursorY = 0;
503 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
505 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
510 boolean repaintNeeded = true;
513 // only need to repaint if the viewport did not move, as otherwise it will
515 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
520 if (av.getWrapAlignment())
522 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
523 int x = av.getAlignment().getHiddenColumns()
524 .absoluteToVisibleColumn(seqCanvas.cursorX);
525 av.getRanges().scrollToWrappedVisible(x);
529 av.getRanges().scrollToVisible(seqCanvas.cursorX,
534 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
536 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
537 seqCanvas.cursorX, seqCanvas.cursorY);
547 void setSelectionAreaAtCursor(boolean topLeft)
549 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
551 if (av.getSelectionGroup() != null)
553 SequenceGroup sg = av.getSelectionGroup();
554 // Find the top and bottom of this group
555 int min = av.getAlignment().getHeight(), max = 0;
556 for (int i = 0; i < sg.getSize(); i++)
558 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
573 sg.setStartRes(seqCanvas.cursorX);
574 if (sg.getEndRes() < seqCanvas.cursorX)
576 sg.setEndRes(seqCanvas.cursorX);
579 min = seqCanvas.cursorY;
583 sg.setEndRes(seqCanvas.cursorX);
584 if (sg.getStartRes() > seqCanvas.cursorX)
586 sg.setStartRes(seqCanvas.cursorX);
589 max = seqCanvas.cursorY + 1;
594 // Only the user can do this
595 av.setSelectionGroup(null);
599 // Now add any sequences between min and max
600 sg.getSequences(null).clear();
601 for (int i = min; i < max; i++)
603 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
608 if (av.getSelectionGroup() == null)
610 SequenceGroup sg = new SequenceGroup();
611 sg.setStartRes(seqCanvas.cursorX);
612 sg.setEndRes(seqCanvas.cursorX);
613 sg.addSequence(sequence, false);
614 av.setSelectionGroup(sg);
617 ap.paintAlignment(false, false);
621 void insertGapAtCursor(boolean group)
623 groupEditing = group;
624 startseq = seqCanvas.cursorY;
625 lastres = seqCanvas.cursorX;
626 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
630 void deleteGapAtCursor(boolean group)
632 groupEditing = group;
633 startseq = seqCanvas.cursorY;
634 lastres = seqCanvas.cursorX + getKeyboardNo1();
635 editSequence(false, false, seqCanvas.cursorX);
639 void insertNucAtCursor(boolean group, String nuc)
641 // TODO not called - delete?
642 groupEditing = group;
643 startseq = seqCanvas.cursorY;
644 lastres = seqCanvas.cursorX;
645 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
649 void numberPressed(char value)
651 if (keyboardNo1 == null)
653 keyboardNo1 = new StringBuffer();
656 if (keyboardNo2 != null)
658 keyboardNo2.append(value);
662 keyboardNo1.append(value);
670 if (keyboardNo1 != null)
672 int value = Integer.parseInt(keyboardNo1.toString());
676 } catch (Exception x)
687 if (keyboardNo2 != null)
689 int value = Integer.parseInt(keyboardNo2.toString());
693 } catch (Exception x)
707 public void mouseReleased(MouseEvent evt)
709 MousePos pos = findMousePosition(evt);
710 if (pos.annotationIndex != -1)
712 // mouse is over annotation row in wrapped mode
716 boolean didDrag = mouseDragging; // did we come here after a drag
717 mouseDragging = false;
718 mouseWheelPressed = false;
720 if (evt.isPopupTrigger()) // Windows: mouseReleased
722 showPopupMenu(evt, pos);
729 doMouseReleasedDefineMode(evt, didDrag);
743 public void mousePressed(MouseEvent evt)
745 lastMousePress = evt.getPoint();
746 MousePos pos = findMousePosition(evt);
747 if (pos.annotationIndex != -1)
749 // mouse is over an annotation row in wrapped mode
753 if (SwingUtilities.isMiddleMouseButton(evt))
755 mouseWheelPressed = true;
759 boolean isControlDown = Platform.isControlDown(evt);
760 if (evt.isShiftDown() || isControlDown)
770 doMousePressedDefineMode(evt, pos);
774 int seq = pos.seqIndex;
775 int res = pos.column;
777 if (seq < 0 || res < 0)
782 if ((seq < av.getAlignment().getHeight())
783 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
800 public void mouseOverSequence(SequenceI sequence, int index, int pos)
802 String tmp = sequence.hashCode() + " " + index + " " + pos;
804 if (lastMessage == null || !lastMessage.equals(tmp))
806 // System.err.println("mouseOver Sequence: "+tmp);
807 ssm.mouseOverSequence(sequence, index, pos, av);
813 * Highlight the mapped region described by the search results object (unless
814 * unchanged). This supports highlight of protein while mousing over linked
815 * cDNA and vice versa. The status bar is also updated to show the location of
816 * the start of the highlighted region.
819 public void highlightSequence(SearchResultsI results)
821 if (results == null || results.equals(lastSearchResults))
825 lastSearchResults = results;
827 boolean wasScrolled = false;
829 if (av.isFollowHighlight())
831 // don't allow highlight of protein/cDNA to also scroll a complementary
832 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
833 // over residue to change abruptly, causing highlighted residue in panel 2
834 // to change, causing a scroll in panel 1 etc)
835 ap.setToScrollComplementPanel(false);
836 wasScrolled = ap.scrollToPosition(results, false);
839 seqCanvas.revalidate();
841 ap.setToScrollComplementPanel(true);
844 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
845 if (seqCanvas.highlightSearchResults(results, noFastPaint))
847 setStatusMessage(results);
852 public VamsasSource getVamsasSource()
854 return this.ap == null ? null : this.ap.av;
858 public void updateColours(SequenceI seq, int index)
860 System.out.println("update the seqPanel colours");
865 * Action on mouse movement is to update the status bar to show the current
866 * sequence position, and (if features are shown) to show any features at the
867 * position in a tooltip. Does nothing if the mouse move does not change
873 public void mouseMoved(MouseEvent evt)
877 // This is because MacOSX creates a mouseMoved
878 // If control is down, other platforms will not.
882 final MousePos mousePos = findMousePosition(evt);
883 if (mousePos.equals(lastMousePosition))
886 * just a pixel move without change of 'cell'
890 lastMousePosition = mousePos;
892 if (mousePos.annotationIndex != -1)
894 mouseMovedOverAnnotation(mousePos);
897 final int seq = mousePos.seqIndex;
899 final int column = mousePos.column;
900 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
902 lastMousePosition = null;
903 setToolTipText(null);
904 ap.alignFrame.statusBar.setText("");
908 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
910 if (column >= sequence.getLength())
916 * set status bar message, returning residue position in sequence
918 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
919 final int pos = setStatusMessage(sequence, column, seq);
920 if (ssm != null && !isGapped)
922 mouseOverSequence(sequence, column, pos);
925 tooltipText.setLength(6); // Cuts the buffer back to <html>
927 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
930 for (int g = 0; g < groups.length; g++)
932 if (groups[g].getStartRes() <= column
933 && groups[g].getEndRes() >= column)
935 if (!groups[g].getName().startsWith("JTreeGroup")
936 && !groups[g].getName().startsWith("JGroup"))
938 tooltipText.append(groups[g].getName());
941 if (groups[g].getDescription() != null)
943 tooltipText.append(": " + groups[g].getDescription());
950 * add any features at the position to the tooltip; if over a gap, only
951 * add features that straddle the gap (pos may be the residue before or
954 if (av.isShowSequenceFeatures())
956 List<SequenceFeature> features = ap.getFeatureRenderer()
957 .findFeaturesAtColumn(sequence, column + 1);
958 seqARep.appendFeatures(tooltipText, pos, features,
959 this.ap.getSeqPanel().seqCanvas.fr);
961 if (tooltipText.length() == 6) // <html>
963 setToolTipText(null);
968 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
970 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
971 tooltipText.append("...");
973 String textString = tooltipText.toString();
974 if (lastTooltip == null || !lastTooltip.equals(textString))
976 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
978 setToolTipText(formattedTooltipText);
979 lastTooltip = textString;
985 * When the view is in wrapped mode, and the mouse is over an annotation row,
986 * shows the corresponding tooltip and status message (if any)
991 protected void mouseMovedOverAnnotation(MousePos pos)
993 final int column = pos.column;
994 final int rowIndex = pos.annotationIndex;
996 if (!av.getWrapAlignment() || !av.isShowAnnotation() || rowIndex < 0)
1000 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
1002 String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
1004 setToolTipText(tooltip);
1005 lastTooltip = tooltip;
1007 String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
1009 ap.alignFrame.statusBar.setText(msg);
1012 private Point lastp = null;
1017 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
1020 public Point getToolTipLocation(MouseEvent event)
1022 int x = event.getX(), w = getWidth();
1023 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
1026 if (!event.isShiftDown() || p == null)
1028 p = (tooltipText != null && tooltipText.length() > 6)
1029 ? new Point(event.getX() + wdth, event.getY() - 20)
1033 * TODO: try to modify position region is not obcured by tooltip
1041 * set when the current UI interaction has resulted in a change that requires
1042 * shading in overviews and structures to be recalculated. this could be
1043 * changed to a something more expressive that indicates what actually has
1044 * changed, so selective redraws can be applied (ie. only structures, only
1047 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1050 * set if av.getSelectionGroup() refers to a group that is defined on the
1051 * alignment view, rather than a transient selection
1053 // private boolean editingDefinedGroup = false; // TODO: refactor to
1054 // avcontroller or viewModel
1057 * Sets the status message in alignment panel, showing the sequence number
1058 * (index) and id, and residue and residue position if not at a gap, for the
1059 * given sequence and column position. Returns the residue position returned
1060 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1061 * if at a gapped position.
1064 * aligned sequence object
1068 * index of sequence in alignment
1069 * @return sequence position of residue at column, or adjacent residue if at a
1072 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1074 char sequenceChar = sequence.getCharAt(column);
1075 int pos = sequence.findPosition(column);
1076 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1082 * Builds the status message for the current cursor location and writes it to
1083 * the status bar, for example
1086 * Sequence 3 ID: FER1_SOLLC
1087 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1088 * Sequence 5 ID: FER1_PEA Residue: B (3)
1089 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1094 * sequence position in the alignment (1..)
1095 * @param sequenceChar
1096 * the character under the cursor
1098 * the sequence residue position (if not over a gap)
1100 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1101 char sequenceChar, int residuePos)
1103 StringBuilder text = new StringBuilder(32);
1106 * Sequence number (if known), and sequence name.
1108 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1109 text.append("Sequence").append(seqno).append(" ID: ")
1110 .append(sequence.getName());
1112 String residue = null;
1115 * Try to translate the display character to residue name (null for gap).
1117 boolean isGapped = Comparison.isGap(sequenceChar);
1121 boolean nucleotide = av.getAlignment().isNucleotide();
1122 String displayChar = String.valueOf(sequenceChar);
1125 residue = ResidueProperties.nucleotideName.get(displayChar);
1129 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1130 : ("*".equals(displayChar) ? "STOP"
1131 : ResidueProperties.aa2Triplet.get(displayChar));
1133 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1134 .append(": ").append(residue == null ? displayChar : residue);
1136 text.append(" (").append(Integer.toString(residuePos)).append(")");
1138 ap.alignFrame.statusBar.setText(text.toString());
1142 * Set the status bar message to highlight the first matched position in
1147 private void setStatusMessage(SearchResultsI results)
1149 AlignmentI al = this.av.getAlignment();
1150 int sequenceIndex = al.findIndex(results);
1151 if (sequenceIndex == -1)
1155 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1156 for (SearchResultMatchI m : results.getResults())
1158 SequenceI seq = m.getSequence();
1159 if (seq.getDatasetSequence() != null)
1161 seq = seq.getDatasetSequence();
1166 int start = m.getStart();
1167 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1178 public void mouseDragged(MouseEvent evt)
1180 MousePos pos = findMousePosition(evt);
1181 if (pos.annotationIndex != -1)
1183 // mouse is over annotation row in wrapped mode
1187 if (mouseWheelPressed)
1189 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1190 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1192 int oldWidth = av.getCharWidth();
1194 // Which is bigger, left-right or up-down?
1195 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1196 .abs(evt.getX() - lastMousePress.getX()))
1199 * on drag up or down, decrement or increment font size
1201 int fontSize = av.font.getSize();
1202 boolean fontChanged = false;
1204 if (evt.getY() < lastMousePress.getY())
1209 else if (evt.getY() > lastMousePress.getY())
1222 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1224 av.setFont(newFont, true);
1225 av.setCharWidth(oldWidth);
1229 ap.av.getCodingComplement().setFont(newFont, true);
1230 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1231 .getSplitViewContainer();
1232 splitFrame.adjustLayout();
1233 splitFrame.repaint();
1240 * on drag left or right, decrement or increment character width
1243 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1245 newWidth = av.getCharWidth() - 1;
1246 av.setCharWidth(newWidth);
1248 else if (evt.getX() > lastMousePress.getX())
1250 newWidth = av.getCharWidth() + 1;
1251 av.setCharWidth(newWidth);
1255 ap.paintAlignment(false, false);
1259 * need to ensure newWidth is set on cdna, regardless of which
1260 * panel the mouse drag happened in; protein will compute its
1261 * character width as 1:1 or 3:1
1263 av.getCodingComplement().setCharWidth(newWidth);
1264 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1265 .getSplitViewContainer();
1266 splitFrame.adjustLayout();
1267 splitFrame.repaint();
1272 FontMetrics fm = getFontMetrics(av.getFont());
1273 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1275 lastMousePress = evt.getPoint();
1282 doMouseDraggedDefineMode(evt);
1286 int res = pos.column;
1293 if ((lastres == -1) || (lastres == res))
1298 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1300 // dragLeft, delete gap
1301 editSequence(false, false, res);
1305 editSequence(true, false, res);
1308 mouseDragging = true;
1309 if ((scrollThread != null) && (scrollThread.isRunning()))
1311 scrollThread.setEvent(evt);
1315 // TODO: Make it more clever than many booleans
1316 synchronized void editSequence(boolean insertGap, boolean editSeq,
1320 int fixedRight = -1;
1321 boolean fixedColumns = false;
1322 SequenceGroup sg = av.getSelectionGroup();
1324 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1326 // No group, but the sequence may represent a group
1327 if (!groupEditing && av.hasHiddenRows())
1329 if (av.isHiddenRepSequence(seq))
1331 sg = av.getRepresentedSequences(seq);
1332 groupEditing = true;
1336 StringBuilder message = new StringBuilder(64);
1339 message.append("Edit group:");
1340 if (editCommand == null)
1342 editCommand = new EditCommand(
1343 MessageManager.getString("action.edit_group"));
1348 message.append("Edit sequence: " + seq.getName());
1349 String label = seq.getName();
1350 if (label.length() > 10)
1352 label = label.substring(0, 10);
1354 if (editCommand == null)
1356 editCommand = new EditCommand(MessageManager
1357 .formatMessage("label.edit_params", new String[]
1364 message.append(" insert ");
1368 message.append(" delete ");
1371 message.append(Math.abs(startres - lastres) + " gaps.");
1372 ap.alignFrame.statusBar.setText(message.toString());
1374 // Are we editing within a selection group?
1375 if (groupEditing || (sg != null
1376 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1378 fixedColumns = true;
1380 // sg might be null as the user may only see 1 sequence,
1381 // but the sequence represents a group
1384 if (!av.isHiddenRepSequence(seq))
1389 sg = av.getRepresentedSequences(seq);
1392 fixedLeft = sg.getStartRes();
1393 fixedRight = sg.getEndRes();
1395 if ((startres < fixedLeft && lastres >= fixedLeft)
1396 || (startres >= fixedLeft && lastres < fixedLeft)
1397 || (startres > fixedRight && lastres <= fixedRight)
1398 || (startres <= fixedRight && lastres > fixedRight))
1404 if (fixedLeft > startres)
1406 fixedRight = fixedLeft - 1;
1409 else if (fixedRight < startres)
1411 fixedLeft = fixedRight;
1416 if (av.hasHiddenColumns())
1418 fixedColumns = true;
1419 int y1 = av.getAlignment().getHiddenColumns()
1420 .getNextHiddenBoundary(true, startres);
1421 int y2 = av.getAlignment().getHiddenColumns()
1422 .getNextHiddenBoundary(false, startres);
1424 if ((insertGap && startres > y1 && lastres < y1)
1425 || (!insertGap && startres < y2 && lastres > y2))
1431 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1432 // Selection spans a hidden region
1433 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1441 fixedRight = y2 - 1;
1448 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1449 int g, groupSize = vseqs.size();
1450 SequenceI[] groupSeqs = new SequenceI[groupSize];
1451 for (g = 0; g < groupSeqs.length; g++)
1453 groupSeqs[g] = vseqs.get(g);
1459 // If the user has selected the whole sequence, and is dragging to
1460 // the right, we can still extend the alignment and selectionGroup
1461 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1462 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1464 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1465 fixedRight = sg.getEndRes();
1468 // Is it valid with fixed columns??
1469 // Find the next gap before the end
1470 // of the visible region boundary
1471 boolean blank = false;
1472 for (; fixedRight > lastres; fixedRight--)
1476 for (g = 0; g < groupSize; g++)
1478 for (int j = 0; j < startres - lastres; j++)
1480 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1495 if (sg.getSize() == av.getAlignment().getHeight())
1497 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1499 .getNextHiddenBoundary(false, startres)))
1505 int alWidth = av.getAlignment().getWidth();
1506 if (av.hasHiddenRows())
1508 int hwidth = av.getAlignment().getHiddenSequences()
1510 if (hwidth > alWidth)
1515 // We can still insert gaps if the selectionGroup
1516 // contains all the sequences
1517 sg.setEndRes(sg.getEndRes() + startres - lastres);
1518 fixedRight = alWidth + startres - lastres;
1529 else if (!insertGap)
1531 // / Are we able to delete?
1532 // ie are all columns blank?
1534 for (g = 0; g < groupSize; g++)
1536 for (int j = startres; j < lastres; j++)
1538 if (groupSeqs[g].getLength() <= j)
1543 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1545 // Not a gap, block edit not valid
1555 // dragging to the right
1556 if (fixedColumns && fixedRight != -1)
1558 for (int j = lastres; j < startres; j++)
1560 insertChar(j, groupSeqs, fixedRight);
1565 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1566 startres - lastres);
1571 // dragging to the left
1572 if (fixedColumns && fixedRight != -1)
1574 for (int j = lastres; j > startres; j--)
1576 deleteChar(startres, groupSeqs, fixedRight);
1581 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1582 lastres - startres);
1588 // ///Editing a single sequence///////////
1592 // dragging to the right
1593 if (fixedColumns && fixedRight != -1)
1595 for (int j = lastres; j < startres; j++)
1597 insertChar(j, new SequenceI[] { seq }, fixedRight);
1602 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1603 startres - lastres);
1610 // dragging to the left
1611 if (fixedColumns && fixedRight != -1)
1613 for (int j = lastres; j > startres; j--)
1615 if (!Comparison.isGap(seq.getCharAt(startres)))
1620 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1625 // could be a keyboard edit trying to delete none gaps
1627 for (int m = startres; m < lastres; m++)
1629 if (!Comparison.isGap(seq.getCharAt(m)))
1638 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1644 {// insertGap==false AND editSeq==TRUE;
1645 if (fixedColumns && fixedRight != -1)
1647 for (int j = lastres; j < startres; j++)
1649 insertChar(j, new SequenceI[] { seq }, fixedRight);
1654 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1655 startres - lastres);
1662 seqCanvas.repaint();
1665 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1667 int blankColumn = fixedColumn;
1668 for (int s = 0; s < seq.length; s++)
1670 // Find the next gap before the end of the visible region boundary
1671 // If lastCol > j, theres a boundary after the gap insertion
1673 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1675 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1677 // Theres a space, so break and insert the gap
1682 if (blankColumn <= j)
1684 blankColumn = fixedColumn;
1690 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1692 appendEdit(Action.INSERT_GAP, seq, j, 1);
1697 * Helper method to add and perform one edit action.
1704 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1708 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1709 av.getAlignment().getGapCharacter());
1711 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1714 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1717 appendEdit(Action.DELETE_GAP, seq, j, 1);
1719 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1729 public void mouseEntered(MouseEvent e)
1736 if ((scrollThread != null) && (scrollThread.isRunning()))
1738 scrollThread.stopScrolling();
1739 scrollThread = null;
1750 public void mouseExited(MouseEvent e)
1752 if (av.getWrapAlignment())
1757 if (mouseDragging && scrollThread == null)
1759 scrollThread = new ScrollThread();
1764 * Handler for double-click on a position with one or more sequence features.
1765 * Opens the Amend Features dialog to allow feature details to be amended, or
1766 * the feature deleted.
1769 public void mouseClicked(MouseEvent evt)
1771 SequenceGroup sg = null;
1772 MousePos pos = findMousePosition(evt);
1773 if (pos.annotationIndex != -1)
1775 // mouse is over annotation label in wrapped mode
1779 if (evt.getClickCount() > 1)
1781 sg = av.getSelectionGroup();
1782 if (sg != null && sg.getSize() == 1
1783 && sg.getEndRes() - sg.getStartRes() < 2)
1785 av.setSelectionGroup(null);
1788 int column = pos.column;
1791 * find features at the position (if not gapped), or straddling
1792 * the position (if at a gap)
1794 SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);// findSeq(evt));
1795 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1796 .findFeaturesAtColumn(sequence, column + 1);
1798 if (!features.isEmpty())
1801 * highlight the first feature at the position on the alignment
1803 SearchResultsI highlight = new SearchResults();
1804 highlight.addResult(sequence, features.get(0).getBegin(), features
1806 seqCanvas.highlightSearchResults(highlight, false);
1809 * open the Amend Features dialog; clear highlighting afterwards,
1810 * whether changes were made or not
1812 List<SequenceI> seqs = Collections.singletonList(sequence);
1813 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1815 av.setSearchResults(null); // clear highlighting
1816 seqCanvas.repaint(); // draw new/amended features
1822 public void mouseWheelMoved(MouseWheelEvent e)
1825 double wheelRotation = e.getPreciseWheelRotation();
1826 if (wheelRotation > 0)
1828 if (e.isShiftDown())
1830 av.getRanges().scrollRight(true);
1835 av.getRanges().scrollUp(false);
1838 else if (wheelRotation < 0)
1840 if (e.isShiftDown())
1842 av.getRanges().scrollRight(false);
1846 av.getRanges().scrollUp(true);
1851 * update status bar and tooltip for new position
1852 * (need to synthesize a mouse movement to refresh tooltip)
1855 ToolTipManager.sharedInstance().mouseMoved(e);
1864 protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
1866 if (pos.annotationIndex != -1)
1868 // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1869 // MessageManager.getString(
1870 // "label.cannot_edit_annotations_in_wrapped_view"),
1871 // MessageManager.getString("label.wrapped_view_no_edit"),
1872 // JvOptionPane.WARNING_MESSAGE);
1876 final int res = pos.column;
1877 final int seq = pos.seqIndex;
1879 updateOverviewAndStructs = false;
1881 startWrapBlock = wrappedBlock;
1883 if (seq < 0 || res < 0)
1888 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1890 if ((sequence == null) || (res > sequence.getLength()))
1895 stretchGroup = av.getSelectionGroup();
1897 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1899 stretchGroup = av.getAlignment().findGroup(sequence, res);
1900 if (stretchGroup != null)
1902 // only update the current selection if the popup menu has a group to
1904 av.setSelectionGroup(stretchGroup);
1908 if (evt.isPopupTrigger()) // Mac: mousePressed
1910 showPopupMenu(evt, pos);
1915 * defer right-mouse click handling to mouseReleased on Windows
1916 * (where isPopupTrigger() will answer true)
1917 * NB isRightMouseButton is also true for Cmd-click on Mac
1919 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1926 seqCanvas.cursorX = res;
1927 seqCanvas.cursorY = seq;
1928 seqCanvas.repaint();
1932 if (stretchGroup == null)
1934 createStretchGroup(res, sequence);
1937 if (stretchGroup != null)
1939 stretchGroup.addPropertyChangeListener(seqCanvas);
1942 seqCanvas.repaint();
1945 private void createStretchGroup(int res, SequenceI sequence)
1947 // Only if left mouse button do we want to change group sizes
1948 // define a new group here
1949 SequenceGroup sg = new SequenceGroup();
1950 sg.setStartRes(res);
1952 sg.addSequence(sequence, false);
1953 av.setSelectionGroup(sg);
1956 if (av.getConservationSelected())
1958 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1962 if (av.getAbovePIDThreshold())
1964 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1967 // TODO: stretchGroup will always be not null. Is this a merge error ?
1968 // or is there a threading issue here?
1969 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1971 // Edit end res position of selected group
1972 changeEndRes = true;
1974 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1976 // Edit end res position of selected group
1977 changeStartRes = true;
1979 stretchGroup.getWidth();
1984 * Build and show a pop-up menu at the right-click mouse position
1989 void showPopupMenu(MouseEvent evt, MousePos pos)
1991 final int column = pos.column;
1992 final int seq = pos.seqIndex;
1993 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1994 List<SequenceFeature> features = ap.getFeatureRenderer()
1995 .findFeaturesAtColumn(sequence, column + 1);
1997 PopupMenu pop = new PopupMenu(ap, null, features);
1998 pop.show(this, evt.getX(), evt.getY());
2002 * Update the display after mouse up on a selection or group
2005 * mouse released event details
2007 * true if this event is happening after a mouse drag (rather than a
2010 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
2012 if (stretchGroup == null)
2017 stretchGroup.removePropertyChangeListener(seqCanvas);
2019 // always do this - annotation has own state
2020 // but defer colourscheme update until hidden sequences are passed in
2021 boolean vischange = stretchGroup.recalcConservation(true);
2022 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
2024 if (stretchGroup.cs != null)
2026 stretchGroup.cs.alignmentChanged(stretchGroup,
2027 av.getHiddenRepSequences());
2029 ResidueShaderI groupColourScheme = stretchGroup
2030 .getGroupColourScheme();
2031 String name = stretchGroup.getName();
2032 if (stretchGroup.cs.conservationApplied())
2034 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2036 if (stretchGroup.cs.getThreshold() > 0)
2038 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2041 PaintRefresher.Refresh(this, av.getSequenceSetId());
2042 // TODO: structure colours only need updating if stretchGroup used to or now
2043 // does contain sequences with structure views
2044 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2045 updateOverviewAndStructs = false;
2046 changeEndRes = false;
2047 changeStartRes = false;
2048 stretchGroup = null;
2058 public void doMouseDraggedDefineMode(MouseEvent evt)
2060 MousePos pos = findMousePosition(evt);
2061 if (pos.annotationIndex != -1)
2063 // mouse is over annotation in wrapped mode
2067 int res = pos.column;
2068 int y = pos.seqIndex;
2070 if (wrappedBlock != startWrapBlock)
2075 if (stretchGroup == null)
2080 if (res >= av.getAlignment().getWidth())
2082 res = av.getAlignment().getWidth() - 1;
2085 if (stretchGroup.getEndRes() == res)
2087 // Edit end res position of selected group
2088 changeEndRes = true;
2090 else if (stretchGroup.getStartRes() == res)
2092 // Edit start res position of selected group
2093 changeStartRes = true;
2096 if (res < av.getRanges().getStartRes())
2098 res = av.getRanges().getStartRes();
2103 if (res > (stretchGroup.getStartRes() - 1))
2105 stretchGroup.setEndRes(res);
2106 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2109 else if (changeStartRes)
2111 if (res < (stretchGroup.getEndRes() + 1))
2113 stretchGroup.setStartRes(res);
2114 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2118 int dragDirection = 0;
2124 else if (y < oldSeq)
2129 while ((y != oldSeq) && (oldSeq > -1)
2130 && (y < av.getAlignment().getHeight()))
2132 // This routine ensures we don't skip any sequences, as the
2133 // selection is quite slow.
2134 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2136 oldSeq += dragDirection;
2143 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2145 if (stretchGroup.getSequences(null).contains(nextSeq))
2147 stretchGroup.deleteSequence(seq, false);
2148 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2154 stretchGroup.addSequence(seq, false);
2157 stretchGroup.addSequence(nextSeq, false);
2158 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2167 mouseDragging = true;
2169 if ((scrollThread != null) && (scrollThread.isRunning()))
2171 scrollThread.setEvent(evt);
2175 void scrollCanvas(MouseEvent evt)
2179 if ((scrollThread != null) && (scrollThread.isRunning()))
2181 scrollThread.stopScrolling();
2182 scrollThread = null;
2184 mouseDragging = false;
2188 if (scrollThread == null)
2190 scrollThread = new ScrollThread();
2193 mouseDragging = true;
2194 scrollThread.setEvent(evt);
2199 // this class allows scrolling off the bottom of the visible alignment
2200 class ScrollThread extends Thread
2204 private volatile boolean threadRunning = true;
2206 public ScrollThread()
2211 public void setEvent(MouseEvent e)
2216 public void stopScrolling()
2218 threadRunning = false;
2221 public boolean isRunning()
2223 return threadRunning;
2229 while (threadRunning)
2233 if (mouseDragging && (evt.getY() < 0)
2234 && (av.getRanges().getStartSeq() > 0))
2236 av.getRanges().scrollUp(true);
2239 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2240 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2242 av.getRanges().scrollUp(false);
2245 if (mouseDragging && (evt.getX() < 0))
2247 av.getRanges().scrollRight(false);
2249 else if (mouseDragging && (evt.getX() >= getWidth()))
2251 av.getRanges().scrollRight(true);
2258 } catch (Exception ex)
2266 * modify current selection according to a received message.
2269 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2270 HiddenColumns hidden, SelectionSource source)
2272 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2273 // handles selection messages...
2274 // TODO: extend config options to allow user to control if selections may be
2275 // shared between viewports.
2276 boolean iSentTheSelection = (av == source
2277 || (source instanceof AlignViewport
2278 && ((AlignmentViewport) source).getSequenceSetId()
2279 .equals(av.getSequenceSetId())));
2281 if (iSentTheSelection)
2283 // respond to our own event by updating dependent dialogs
2284 if (ap.getCalculationDialog() != null)
2286 ap.getCalculationDialog().validateCalcTypes();
2292 // process further ?
2293 if (!av.followSelection)
2299 * Ignore the selection if there is one of our own pending.
2301 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2307 * Check for selection in a view of which this one is a dna/protein
2310 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2315 // do we want to thread this ? (contention with seqsel and colsel locks, I
2318 * only copy colsel if there is a real intersection between
2319 * sequence selection and this panel's alignment
2321 boolean repaint = false;
2322 boolean copycolsel = false;
2324 SequenceGroup sgroup = null;
2325 if (seqsel != null && seqsel.getSize() > 0)
2327 if (av.getAlignment() == null)
2329 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2330 + " ViewId=" + av.getViewId()
2331 + " 's alignment is NULL! returning immediately.");
2334 sgroup = seqsel.intersect(av.getAlignment(),
2335 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2336 if ((sgroup != null && sgroup.getSize() > 0))
2341 if (sgroup != null && sgroup.getSize() > 0)
2343 av.setSelectionGroup(sgroup);
2347 av.setSelectionGroup(null);
2349 av.isSelectionGroupChanged(true);
2354 // the current selection is unset or from a previous message
2355 // so import the new colsel.
2356 if (colsel == null || colsel.isEmpty())
2358 if (av.getColumnSelection() != null)
2360 av.getColumnSelection().clear();
2366 // TODO: shift colSel according to the intersecting sequences
2367 if (av.getColumnSelection() == null)
2369 av.setColumnSelection(new ColumnSelection(colsel));
2373 av.getColumnSelection().setElementsFrom(colsel,
2374 av.getAlignment().getHiddenColumns());
2377 av.isColSelChanged(true);
2381 if (copycolsel && av.hasHiddenColumns()
2382 && (av.getAlignment().getHiddenColumns() == null))
2384 System.err.println("Bad things");
2386 if (repaint) // always true!
2388 // probably finessing with multiple redraws here
2389 PaintRefresher.Refresh(this, av.getSequenceSetId());
2390 // ap.paintAlignment(false);
2393 // lastly, update dependent dialogs
2394 if (ap.getCalculationDialog() != null)
2396 ap.getCalculationDialog().validateCalcTypes();
2402 * If this panel is a cdna/protein translation view of the selection source,
2403 * tries to map the source selection to a local one, and returns true. Else
2410 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2411 ColumnSelection colsel, HiddenColumns hidden,
2412 SelectionSource source)
2414 if (!(source instanceof AlignViewportI))
2418 final AlignViewportI sourceAv = (AlignViewportI) source;
2419 if (sourceAv.getCodingComplement() != av
2420 && av.getCodingComplement() != sourceAv)
2426 * Map sequence selection
2428 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2429 av.setSelectionGroup(sg);
2430 av.isSelectionGroupChanged(true);
2433 * Map column selection
2435 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2437 ColumnSelection cs = new ColumnSelection();
2438 HiddenColumns hs = new HiddenColumns();
2439 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2440 av.setColumnSelection(cs);
2441 av.getAlignment().setHiddenColumns(hs);
2443 // lastly, update any dependent dialogs
2444 if (ap.getCalculationDialog() != null)
2446 ap.getCalculationDialog().validateCalcTypes();
2449 PaintRefresher.Refresh(this, av.getSequenceSetId());
2456 * @return null or last search results handled by this panel
2458 public SearchResultsI getLastSearchResults()
2460 return lastSearchResults;