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 seqCanvas.calculateWrappedGeometry(seqCanvas.getWidth(),
276 seqCanvas.getHeight());
279 * yPos modulo height of repeating width
281 int yOffsetPx = y % seqCanvas.wrappedRepeatHeightPx;
284 * height of sequences plus space / scale above,
285 * plus gap between sequences and annotations
287 int alignmentHeightPixels = seqCanvas.wrappedSpaceAboveAlignment
288 + alignmentHeight * charHeight
289 + SeqCanvas.SEQS_ANNOTATION_GAP;
290 if (yOffsetPx >= alignmentHeightPixels)
293 * mouse is over annotations; find annotation index, also set
294 * last sequence above (for backwards compatible behaviour)
296 AlignmentAnnotation[] anns = av.getAlignment()
297 .getAlignmentAnnotation();
298 int rowOffsetPx = yOffsetPx - alignmentHeightPixels;
299 annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
300 seqIndex = alignmentHeight - 1;
305 * mouse is over sequence (or the space above sequences)
307 yOffsetPx -= seqCanvas.wrappedSpaceAboveAlignment;
310 seqIndex = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
316 seqIndex = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
317 alignmentHeight - 1);
320 return new MousePos(col, seqIndex, annIndex);
323 * Returns the aligned sequence position (base 0) at the mouse position, or
324 * the closest visible one
329 int findColumn(MouseEvent evt)
334 final int startRes = av.getRanges().getStartRes();
335 final int charWidth = av.getCharWidth();
337 if (av.getWrapAlignment())
339 int hgap = av.getCharHeight();
340 if (av.getScaleAboveWrapped())
342 hgap += av.getCharHeight();
345 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
346 + hgap + seqCanvas.getAnnotationHeight();
349 y = Math.max(0, y - hgap);
350 x -= seqCanvas.getLabelWidthWest();
353 // mouse is over left scale
357 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
362 if (x >= cwidth * charWidth)
364 // mouse is over right scale
368 wrappedBlock = y / cHeight;
369 wrappedBlock += startRes / cwidth;
370 // allow for wrapped view scrolled right (possible from Overview)
371 int startOffset = startRes % cwidth;
372 res = wrappedBlock * cwidth + startOffset
373 + Math.min(cwidth - 1, x / charWidth);
378 * make sure we calculate relative to visible alignment,
379 * rather than right-hand gutter
381 x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
382 res = (x / charWidth) + startRes;
383 res = Math.min(res, av.getRanges().getEndRes());
386 if (av.hasHiddenColumns())
388 res = av.getAlignment().getHiddenColumns()
389 .visibleToAbsoluteColumn(res);
396 * When all of a sequence of edits are complete, put the resulting edit list
397 * on the history stack (undo list), and reset flags for editing in progress.
403 if (editCommand != null && editCommand.getSize() > 0)
405 ap.alignFrame.addHistoryItem(editCommand);
406 av.firePropertyChange("alignment", null,
407 av.getAlignment().getSequences());
412 * Tidy up come what may...
417 groupEditing = false;
426 seqCanvas.cursorY = getKeyboardNo1() - 1;
427 scrollToVisible(true);
430 void setCursorColumn()
432 seqCanvas.cursorX = getKeyboardNo1() - 1;
433 scrollToVisible(true);
436 void setCursorRowAndColumn()
438 if (keyboardNo2 == null)
440 keyboardNo2 = new StringBuffer();
444 seqCanvas.cursorX = getKeyboardNo1() - 1;
445 seqCanvas.cursorY = getKeyboardNo2() - 1;
446 scrollToVisible(true);
450 void setCursorPosition()
452 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
454 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
455 scrollToVisible(true);
458 void moveCursor(int dx, int dy)
460 seqCanvas.cursorX += dx;
461 seqCanvas.cursorY += dy;
463 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
465 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
467 int original = seqCanvas.cursorX - dx;
468 int maxWidth = av.getAlignment().getWidth();
470 if (!hidden.isVisible(seqCanvas.cursorX))
472 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
473 int[] region = hidden.getRegionWithEdgeAtRes(visx);
475 if (region != null) // just in case
480 seqCanvas.cursorX = region[1] + 1;
485 seqCanvas.cursorX = region[0] - 1;
488 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
491 if (seqCanvas.cursorX >= maxWidth
492 || !hidden.isVisible(seqCanvas.cursorX))
494 seqCanvas.cursorX = original;
498 scrollToVisible(false);
502 * Scroll to make the cursor visible in the viewport.
505 * just jump to the location rather than scrolling
507 void scrollToVisible(boolean jump)
509 if (seqCanvas.cursorX < 0)
511 seqCanvas.cursorX = 0;
513 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
515 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
518 if (seqCanvas.cursorY < 0)
520 seqCanvas.cursorY = 0;
522 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
524 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
529 boolean repaintNeeded = true;
532 // only need to repaint if the viewport did not move, as otherwise it will
534 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
539 if (av.getWrapAlignment())
541 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
542 int x = av.getAlignment().getHiddenColumns()
543 .absoluteToVisibleColumn(seqCanvas.cursorX);
544 av.getRanges().scrollToWrappedVisible(x);
548 av.getRanges().scrollToVisible(seqCanvas.cursorX,
553 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
555 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
556 seqCanvas.cursorX, seqCanvas.cursorY);
566 void setSelectionAreaAtCursor(boolean topLeft)
568 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
570 if (av.getSelectionGroup() != null)
572 SequenceGroup sg = av.getSelectionGroup();
573 // Find the top and bottom of this group
574 int min = av.getAlignment().getHeight(), max = 0;
575 for (int i = 0; i < sg.getSize(); i++)
577 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
592 sg.setStartRes(seqCanvas.cursorX);
593 if (sg.getEndRes() < seqCanvas.cursorX)
595 sg.setEndRes(seqCanvas.cursorX);
598 min = seqCanvas.cursorY;
602 sg.setEndRes(seqCanvas.cursorX);
603 if (sg.getStartRes() > seqCanvas.cursorX)
605 sg.setStartRes(seqCanvas.cursorX);
608 max = seqCanvas.cursorY + 1;
613 // Only the user can do this
614 av.setSelectionGroup(null);
618 // Now add any sequences between min and max
619 sg.getSequences(null).clear();
620 for (int i = min; i < max; i++)
622 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
627 if (av.getSelectionGroup() == null)
629 SequenceGroup sg = new SequenceGroup();
630 sg.setStartRes(seqCanvas.cursorX);
631 sg.setEndRes(seqCanvas.cursorX);
632 sg.addSequence(sequence, false);
633 av.setSelectionGroup(sg);
636 ap.paintAlignment(false, false);
640 void insertGapAtCursor(boolean group)
642 groupEditing = group;
643 startseq = seqCanvas.cursorY;
644 lastres = seqCanvas.cursorX;
645 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
649 void deleteGapAtCursor(boolean group)
651 groupEditing = group;
652 startseq = seqCanvas.cursorY;
653 lastres = seqCanvas.cursorX + getKeyboardNo1();
654 editSequence(false, false, seqCanvas.cursorX);
658 void insertNucAtCursor(boolean group, String nuc)
660 // TODO not called - delete?
661 groupEditing = group;
662 startseq = seqCanvas.cursorY;
663 lastres = seqCanvas.cursorX;
664 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
668 void numberPressed(char value)
670 if (keyboardNo1 == null)
672 keyboardNo1 = new StringBuffer();
675 if (keyboardNo2 != null)
677 keyboardNo2.append(value);
681 keyboardNo1.append(value);
689 if (keyboardNo1 != null)
691 int value = Integer.parseInt(keyboardNo1.toString());
695 } catch (Exception x)
706 if (keyboardNo2 != null)
708 int value = Integer.parseInt(keyboardNo2.toString());
712 } catch (Exception x)
726 public void mouseReleased(MouseEvent evt)
728 MousePos pos = findMousePosition(evt);
729 if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
734 boolean didDrag = mouseDragging; // did we come here after a drag
735 mouseDragging = false;
736 mouseWheelPressed = false;
738 if (evt.isPopupTrigger()) // Windows: mouseReleased
740 showPopupMenu(evt, pos);
747 doMouseReleasedDefineMode(evt, didDrag);
761 public void mousePressed(MouseEvent evt)
763 lastMousePress = evt.getPoint();
764 MousePos pos = findMousePosition(evt);
765 if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
770 if (SwingUtilities.isMiddleMouseButton(evt))
772 mouseWheelPressed = true;
776 boolean isControlDown = Platform.isControlDown(evt);
777 if (evt.isShiftDown() || isControlDown)
787 doMousePressedDefineMode(evt, pos);
791 int seq = pos.seqIndex;
792 int res = pos.column;
794 if ((seq < av.getAlignment().getHeight())
795 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
812 public void mouseOverSequence(SequenceI sequence, int index, int pos)
814 String tmp = sequence.hashCode() + " " + index + " " + pos;
816 if (lastMessage == null || !lastMessage.equals(tmp))
818 // System.err.println("mouseOver Sequence: "+tmp);
819 ssm.mouseOverSequence(sequence, index, pos, av);
825 * Highlight the mapped region described by the search results object (unless
826 * unchanged). This supports highlight of protein while mousing over linked
827 * cDNA and vice versa. The status bar is also updated to show the location of
828 * the start of the highlighted region.
831 public void highlightSequence(SearchResultsI results)
833 if (results == null || results.equals(lastSearchResults))
837 lastSearchResults = results;
839 boolean wasScrolled = false;
841 if (av.isFollowHighlight())
843 // don't allow highlight of protein/cDNA to also scroll a complementary
844 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
845 // over residue to change abruptly, causing highlighted residue in panel 2
846 // to change, causing a scroll in panel 1 etc)
847 ap.setToScrollComplementPanel(false);
848 wasScrolled = ap.scrollToPosition(results, false);
851 seqCanvas.revalidate();
853 ap.setToScrollComplementPanel(true);
856 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
857 if (seqCanvas.highlightSearchResults(results, noFastPaint))
859 setStatusMessage(results);
864 public VamsasSource getVamsasSource()
866 return this.ap == null ? null : this.ap.av;
870 public void updateColours(SequenceI seq, int index)
872 System.out.println("update the seqPanel colours");
877 * Action on mouse movement is to update the status bar to show the current
878 * sequence position, and (if features are shown) to show any features at the
879 * position in a tooltip. Does nothing if the mouse move does not change
885 public void mouseMoved(MouseEvent evt)
889 // This is because MacOSX creates a mouseMoved
890 // If control is down, other platforms will not.
894 final MousePos mousePos = findMousePosition(evt);
895 if (mousePos.equals(lastMousePosition))
898 * just a pixel move without change of 'cell'
902 lastMousePosition = mousePos;
904 if (mousePos.isOverAnnotation())
906 mouseMovedOverAnnotation(mousePos);
909 final int seq = mousePos.seqIndex;
911 final int column = mousePos.column;
912 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
914 lastMousePosition = null;
915 setToolTipText(null);
917 ap.alignFrame.setStatus("");
921 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
923 if (column >= sequence.getLength())
929 * set status bar message, returning residue position in sequence
931 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
932 final int pos = setStatusMessage(sequence, column, seq);
933 if (ssm != null && !isGapped)
935 mouseOverSequence(sequence, column, pos);
938 tooltipText.setLength(6); // Cuts the buffer back to <html>
940 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
943 for (int g = 0; g < groups.length; g++)
945 if (groups[g].getStartRes() <= column
946 && groups[g].getEndRes() >= column)
948 if (!groups[g].getName().startsWith("JTreeGroup")
949 && !groups[g].getName().startsWith("JGroup"))
951 tooltipText.append(groups[g].getName());
954 if (groups[g].getDescription() != null)
956 tooltipText.append(": " + groups[g].getDescription());
963 * add any features at the position to the tooltip; if over a gap, only
964 * add features that straddle the gap (pos may be the residue before or
967 if (av.isShowSequenceFeatures())
969 List<SequenceFeature> features = ap.getFeatureRenderer()
970 .findFeaturesAtColumn(sequence, column + 1);
971 seqARep.appendFeatures(tooltipText, pos, features,
972 this.ap.getSeqPanel().seqCanvas.fr);
974 if (tooltipText.length() == 6) // <html>
976 setToolTipText(null);
981 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
983 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
984 tooltipText.append("...");
986 String textString = tooltipText.toString();
987 if (lastTooltip == null || !lastTooltip.equals(textString))
989 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
991 setToolTipText(formattedTooltipText);
992 lastTooltip = textString;
998 * When the view is in wrapped mode, and the mouse is over an annotation row,
999 * shows the corresponding tooltip and status message (if any)
1004 protected void mouseMovedOverAnnotation(MousePos pos)
1006 final int column = pos.column;
1007 final int rowIndex = pos.annotationIndex;
1009 if (column < 0 || !av.getWrapAlignment() || !av.isShowAnnotation()
1014 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
1016 String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
1018 setToolTipText(tooltip);
1019 lastTooltip = tooltip;
1021 String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
1023 ap.alignFrame.setStatus(msg);
1026 private Point lastp = null;
1031 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
1034 public Point getToolTipLocation(MouseEvent event)
1036 if (tooltipText == null || tooltipText.length() <= 6)
1042 int x = event.getX();
1044 // switch sides when tooltip is too close to edge
1045 int wdth = (w - x < 200) ? -(w / 2) : 5;
1047 if (!event.isShiftDown() || p == null)
1049 p = new Point(event.getX() + wdth, event.getY() - 20);
1053 * TODO: try to set position so region is not obscured by tooltip
1061 * set when the current UI interaction has resulted in a change that requires
1062 * shading in overviews and structures to be recalculated. this could be
1063 * changed to a something more expressive that indicates what actually has
1064 * changed, so selective redraws can be applied (ie. only structures, only
1067 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1070 * set if av.getSelectionGroup() refers to a group that is defined on the
1071 * alignment view, rather than a transient selection
1073 // private boolean editingDefinedGroup = false; // TODO: refactor to
1074 // avcontroller or viewModel
1077 * Sets the status message in alignment panel, showing the sequence number
1078 * (index) and id, and residue and residue position if not at a gap, for the
1079 * given sequence and column position. Returns the residue position returned
1080 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1081 * if at a gapped position.
1084 * aligned sequence object
1088 * index of sequence in alignment
1089 * @return sequence position of residue at column, or adjacent residue if at a
1092 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1094 char sequenceChar = sequence.getCharAt(column);
1095 int pos = sequence.findPosition(column);
1096 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1102 * Builds the status message for the current cursor location and writes it to
1103 * the status bar, for example
1106 * Sequence 3 ID: FER1_SOLLC
1107 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1108 * Sequence 5 ID: FER1_PEA Residue: B (3)
1109 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1114 * sequence position in the alignment (1..)
1115 * @param sequenceChar
1116 * the character under the cursor
1118 * the sequence residue position (if not over a gap)
1120 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1121 char sequenceChar, int residuePos)
1123 StringBuilder text = new StringBuilder(32);
1126 * Sequence number (if known), and sequence name.
1128 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1129 text.append("Sequence").append(seqno).append(" ID: ")
1130 .append(sequence.getName());
1132 String residue = null;
1135 * Try to translate the display character to residue name (null for gap).
1137 boolean isGapped = Comparison.isGap(sequenceChar);
1141 boolean nucleotide = av.getAlignment().isNucleotide();
1142 String displayChar = String.valueOf(sequenceChar);
1145 residue = ResidueProperties.nucleotideName.get(displayChar);
1149 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1150 : ("*".equals(displayChar) ? "STOP"
1151 : ResidueProperties.aa2Triplet.get(displayChar));
1153 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1154 .append(": ").append(residue == null ? displayChar : residue);
1156 text.append(" (").append(Integer.toString(residuePos)).append(")");
1158 ap.alignFrame.setStatus(text.toString());
1162 * Set the status bar message to highlight the first matched position in
1167 private void setStatusMessage(SearchResultsI results)
1169 AlignmentI al = this.av.getAlignment();
1170 int sequenceIndex = al.findIndex(results);
1171 if (sequenceIndex == -1)
1175 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1176 for (SearchResultMatchI m : results.getResults())
1178 SequenceI seq = m.getSequence();
1179 if (seq.getDatasetSequence() != null)
1181 seq = seq.getDatasetSequence();
1186 int start = m.getStart();
1187 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1198 public void mouseDragged(MouseEvent evt)
1200 MousePos pos = findMousePosition(evt);
1201 if (pos.isOverAnnotation() || pos.column == -1)
1206 if (mouseWheelPressed)
1208 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1209 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1211 int oldWidth = av.getCharWidth();
1213 // Which is bigger, left-right or up-down?
1214 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1215 .abs(evt.getX() - lastMousePress.getX()))
1218 * on drag up or down, decrement or increment font size
1220 int fontSize = av.font.getSize();
1221 boolean fontChanged = false;
1223 if (evt.getY() < lastMousePress.getY())
1228 else if (evt.getY() > lastMousePress.getY())
1241 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1243 av.setFont(newFont, true);
1244 av.setCharWidth(oldWidth);
1248 ap.av.getCodingComplement().setFont(newFont, true);
1249 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1250 .getSplitViewContainer();
1251 splitFrame.adjustLayout();
1252 splitFrame.repaint();
1259 * on drag left or right, decrement or increment character width
1262 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1264 newWidth = av.getCharWidth() - 1;
1265 av.setCharWidth(newWidth);
1267 else if (evt.getX() > lastMousePress.getX())
1269 newWidth = av.getCharWidth() + 1;
1270 av.setCharWidth(newWidth);
1274 ap.paintAlignment(false, false);
1278 * need to ensure newWidth is set on cdna, regardless of which
1279 * panel the mouse drag happened in; protein will compute its
1280 * character width as 1:1 or 3:1
1282 av.getCodingComplement().setCharWidth(newWidth);
1283 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1284 .getSplitViewContainer();
1285 splitFrame.adjustLayout();
1286 splitFrame.repaint();
1291 FontMetrics fm = getFontMetrics(av.getFont());
1292 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1294 lastMousePress = evt.getPoint();
1301 dragStretchGroup(evt);
1305 int res = pos.column;
1312 if ((lastres == -1) || (lastres == res))
1317 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1319 // dragLeft, delete gap
1320 editSequence(false, false, res);
1324 editSequence(true, false, res);
1327 mouseDragging = true;
1328 if ((scrollThread != null) && (scrollThread.isRunning()))
1330 scrollThread.setEvent(evt);
1334 // TODO: Make it more clever than many booleans
1335 synchronized void editSequence(boolean insertGap, boolean editSeq,
1339 int fixedRight = -1;
1340 boolean fixedColumns = false;
1341 SequenceGroup sg = av.getSelectionGroup();
1343 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1345 // No group, but the sequence may represent a group
1346 if (!groupEditing && av.hasHiddenRows())
1348 if (av.isHiddenRepSequence(seq))
1350 sg = av.getRepresentedSequences(seq);
1351 groupEditing = true;
1355 StringBuilder message = new StringBuilder(64);
1358 message.append("Edit group:");
1359 if (editCommand == null)
1361 editCommand = new EditCommand(
1362 MessageManager.getString("action.edit_group"));
1367 message.append("Edit sequence: " + seq.getName());
1368 String label = seq.getName();
1369 if (label.length() > 10)
1371 label = label.substring(0, 10);
1373 if (editCommand == null)
1375 editCommand = new EditCommand(MessageManager
1376 .formatMessage("label.edit_params", new String[]
1383 message.append(" insert ");
1387 message.append(" delete ");
1390 message.append(Math.abs(startres - lastres) + " gaps.");
1391 ap.alignFrame.setStatus(message.toString());
1393 // Are we editing within a selection group?
1394 if (groupEditing || (sg != null
1395 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1397 fixedColumns = true;
1399 // sg might be null as the user may only see 1 sequence,
1400 // but the sequence represents a group
1403 if (!av.isHiddenRepSequence(seq))
1408 sg = av.getRepresentedSequences(seq);
1411 fixedLeft = sg.getStartRes();
1412 fixedRight = sg.getEndRes();
1414 if ((startres < fixedLeft && lastres >= fixedLeft)
1415 || (startres >= fixedLeft && lastres < fixedLeft)
1416 || (startres > fixedRight && lastres <= fixedRight)
1417 || (startres <= fixedRight && lastres > fixedRight))
1423 if (fixedLeft > startres)
1425 fixedRight = fixedLeft - 1;
1428 else if (fixedRight < startres)
1430 fixedLeft = fixedRight;
1435 if (av.hasHiddenColumns())
1437 fixedColumns = true;
1438 int y1 = av.getAlignment().getHiddenColumns()
1439 .getNextHiddenBoundary(true, startres);
1440 int y2 = av.getAlignment().getHiddenColumns()
1441 .getNextHiddenBoundary(false, startres);
1443 if ((insertGap && startres > y1 && lastres < y1)
1444 || (!insertGap && startres < y2 && lastres > y2))
1450 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1451 // Selection spans a hidden region
1452 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1460 fixedRight = y2 - 1;
1467 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1468 int g, groupSize = vseqs.size();
1469 SequenceI[] groupSeqs = new SequenceI[groupSize];
1470 for (g = 0; g < groupSeqs.length; g++)
1472 groupSeqs[g] = vseqs.get(g);
1478 // If the user has selected the whole sequence, and is dragging to
1479 // the right, we can still extend the alignment and selectionGroup
1480 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1481 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1483 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1484 fixedRight = sg.getEndRes();
1487 // Is it valid with fixed columns??
1488 // Find the next gap before the end
1489 // of the visible region boundary
1490 boolean blank = false;
1491 for (; fixedRight > lastres; fixedRight--)
1495 for (g = 0; g < groupSize; g++)
1497 for (int j = 0; j < startres - lastres; j++)
1499 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1514 if (sg.getSize() == av.getAlignment().getHeight())
1516 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1518 .getNextHiddenBoundary(false, startres)))
1524 int alWidth = av.getAlignment().getWidth();
1525 if (av.hasHiddenRows())
1527 int hwidth = av.getAlignment().getHiddenSequences()
1529 if (hwidth > alWidth)
1534 // We can still insert gaps if the selectionGroup
1535 // contains all the sequences
1536 sg.setEndRes(sg.getEndRes() + startres - lastres);
1537 fixedRight = alWidth + startres - lastres;
1548 else if (!insertGap)
1550 // / Are we able to delete?
1551 // ie are all columns blank?
1553 for (g = 0; g < groupSize; g++)
1555 for (int j = startres; j < lastres; j++)
1557 if (groupSeqs[g].getLength() <= j)
1562 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1564 // Not a gap, block edit not valid
1574 // dragging to the right
1575 if (fixedColumns && fixedRight != -1)
1577 for (int j = lastres; j < startres; j++)
1579 insertChar(j, groupSeqs, fixedRight);
1584 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1585 startres - lastres);
1590 // dragging to the left
1591 if (fixedColumns && fixedRight != -1)
1593 for (int j = lastres; j > startres; j--)
1595 deleteChar(startres, groupSeqs, fixedRight);
1600 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1601 lastres - startres);
1607 // ///Editing a single sequence///////////
1611 // dragging to the right
1612 if (fixedColumns && fixedRight != -1)
1614 for (int j = lastres; j < startres; j++)
1616 insertChar(j, new SequenceI[] { seq }, fixedRight);
1621 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1622 startres - lastres);
1629 // dragging to the left
1630 if (fixedColumns && fixedRight != -1)
1632 for (int j = lastres; j > startres; j--)
1634 if (!Comparison.isGap(seq.getCharAt(startres)))
1639 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1644 // could be a keyboard edit trying to delete none gaps
1646 for (int m = startres; m < lastres; m++)
1648 if (!Comparison.isGap(seq.getCharAt(m)))
1657 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1663 {// insertGap==false AND editSeq==TRUE;
1664 if (fixedColumns && fixedRight != -1)
1666 for (int j = lastres; j < startres; j++)
1668 insertChar(j, new SequenceI[] { seq }, fixedRight);
1673 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1674 startres - lastres);
1681 seqCanvas.repaint();
1684 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1686 int blankColumn = fixedColumn;
1687 for (int s = 0; s < seq.length; s++)
1689 // Find the next gap before the end of the visible region boundary
1690 // If lastCol > j, theres a boundary after the gap insertion
1692 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1694 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1696 // Theres a space, so break and insert the gap
1701 if (blankColumn <= j)
1703 blankColumn = fixedColumn;
1709 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1711 appendEdit(Action.INSERT_GAP, seq, j, 1);
1716 * Helper method to add and perform one edit action.
1723 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1727 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1728 av.getAlignment().getGapCharacter());
1730 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1733 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1736 appendEdit(Action.DELETE_GAP, seq, j, 1);
1738 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1748 public void mouseEntered(MouseEvent e)
1755 if ((scrollThread != null) && (scrollThread.isRunning()))
1757 scrollThread.stopScrolling();
1758 scrollThread = null;
1769 public void mouseExited(MouseEvent e)
1771 ap.alignFrame.setStatus(" ");
1772 if (av.getWrapAlignment())
1777 if (mouseDragging && scrollThread == null)
1779 scrollThread = new ScrollThread();
1784 * Handler for double-click on a position with one or more sequence features.
1785 * Opens the Amend Features dialog to allow feature details to be amended, or
1786 * the feature deleted.
1789 public void mouseClicked(MouseEvent evt)
1791 SequenceGroup sg = null;
1792 MousePos pos = findMousePosition(evt);
1793 if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
1798 if (evt.getClickCount() > 1)
1800 sg = av.getSelectionGroup();
1801 if (sg != null && sg.getSize() == 1
1802 && sg.getEndRes() - sg.getStartRes() < 2)
1804 av.setSelectionGroup(null);
1807 int column = pos.column;
1810 * find features at the position (if not gapped), or straddling
1811 * the position (if at a gap)
1813 SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);
1814 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1815 .findFeaturesAtColumn(sequence, column + 1);
1817 if (!features.isEmpty())
1820 * highlight the first feature at the position on the alignment
1822 SearchResultsI highlight = new SearchResults();
1823 highlight.addResult(sequence, features.get(0).getBegin(), features
1825 seqCanvas.highlightSearchResults(highlight, false);
1828 * open the Amend Features dialog; clear highlighting afterwards,
1829 * whether changes were made or not
1831 List<SequenceI> seqs = Collections.singletonList(sequence);
1832 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1834 av.setSearchResults(null); // clear highlighting
1835 seqCanvas.repaint(); // draw new/amended features
1841 public void mouseWheelMoved(MouseWheelEvent e)
1844 double wheelRotation = e.getPreciseWheelRotation();
1845 if (wheelRotation > 0)
1847 if (e.isShiftDown())
1849 av.getRanges().scrollRight(true);
1854 av.getRanges().scrollUp(false);
1857 else if (wheelRotation < 0)
1859 if (e.isShiftDown())
1861 av.getRanges().scrollRight(false);
1865 av.getRanges().scrollUp(true);
1870 * update status bar and tooltip for new position
1871 * (need to synthesize a mouse movement to refresh tooltip)
1874 ToolTipManager.sharedInstance().mouseMoved(e);
1883 protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
1885 if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
1890 final int res = pos.column;
1891 final int seq = pos.seqIndex;
1893 updateOverviewAndStructs = false;
1895 startWrapBlock = wrappedBlock;
1897 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1899 if ((sequence == null) || (res > sequence.getLength()))
1904 stretchGroup = av.getSelectionGroup();
1906 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1908 stretchGroup = av.getAlignment().findGroup(sequence, res);
1909 if (stretchGroup != null)
1911 // only update the current selection if the popup menu has a group to
1913 av.setSelectionGroup(stretchGroup);
1917 if (evt.isPopupTrigger()) // Mac: mousePressed
1919 showPopupMenu(evt, pos);
1924 * defer right-mouse click handling to mouseReleased on Windows
1925 * (where isPopupTrigger() will answer true)
1926 * NB isRightMouseButton is also true for Cmd-click on Mac
1928 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1935 seqCanvas.cursorX = res;
1936 seqCanvas.cursorY = seq;
1937 seqCanvas.repaint();
1941 if (stretchGroup == null)
1943 createStretchGroup(res, sequence);
1946 if (stretchGroup != null)
1948 stretchGroup.addPropertyChangeListener(seqCanvas);
1951 seqCanvas.repaint();
1954 private void createStretchGroup(int res, SequenceI sequence)
1956 // Only if left mouse button do we want to change group sizes
1957 // define a new group here
1958 SequenceGroup sg = new SequenceGroup();
1959 sg.setStartRes(res);
1961 sg.addSequence(sequence, false);
1962 av.setSelectionGroup(sg);
1965 if (av.getConservationSelected())
1967 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1971 if (av.getAbovePIDThreshold())
1973 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1976 // TODO: stretchGroup will always be not null. Is this a merge error ?
1977 // or is there a threading issue here?
1978 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1980 // Edit end res position of selected group
1981 changeEndRes = true;
1983 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1985 // Edit end res position of selected group
1986 changeStartRes = true;
1988 stretchGroup.getWidth();
1993 * Build and show a pop-up menu at the right-click mouse position
1998 void showPopupMenu(MouseEvent evt, MousePos pos)
2000 final int column = pos.column;
2001 final int seq = pos.seqIndex;
2002 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
2003 List<SequenceFeature> features = ap.getFeatureRenderer()
2004 .findFeaturesAtColumn(sequence, column + 1);
2006 PopupMenu pop = new PopupMenu(ap, null, features);
2007 pop.show(this, evt.getX(), evt.getY());
2011 * Update the display after mouse up on a selection or group
2014 * mouse released event details
2016 * true if this event is happening after a mouse drag (rather than a
2019 protected void doMouseReleasedDefineMode(MouseEvent evt,
2022 if (stretchGroup == null)
2027 stretchGroup.removePropertyChangeListener(seqCanvas);
2029 // always do this - annotation has own state
2030 // but defer colourscheme update until hidden sequences are passed in
2031 boolean vischange = stretchGroup.recalcConservation(true);
2032 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
2034 if (stretchGroup.cs != null)
2036 stretchGroup.cs.alignmentChanged(stretchGroup,
2037 av.getHiddenRepSequences());
2039 ResidueShaderI groupColourScheme = stretchGroup
2040 .getGroupColourScheme();
2041 String name = stretchGroup.getName();
2042 if (stretchGroup.cs.conservationApplied())
2044 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2046 if (stretchGroup.cs.getThreshold() > 0)
2048 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2051 PaintRefresher.Refresh(this, av.getSequenceSetId());
2052 // TODO: structure colours only need updating if stretchGroup used to or now
2053 // does contain sequences with structure views
2054 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2055 updateOverviewAndStructs = false;
2056 changeEndRes = false;
2057 changeStartRes = false;
2058 stretchGroup = null;
2063 * Resizes the borders of a selection group depending on the direction of
2068 protected void dragStretchGroup(MouseEvent evt)
2070 if (stretchGroup == null)
2075 MousePos pos = findMousePosition(evt);
2076 if (pos.isOverAnnotation() || pos.column == -1 || pos.seqIndex == -1)
2081 int res = pos.column;
2082 int y = pos.seqIndex;
2084 if (wrappedBlock != startWrapBlock)
2089 if (res >= av.getAlignment().getWidth())
2091 res = av.getAlignment().getWidth() - 1;
2094 if (stretchGroup.getEndRes() == res)
2096 // Edit end res position of selected group
2097 changeEndRes = true;
2099 else if (stretchGroup.getStartRes() == res)
2101 // Edit start res position of selected group
2102 changeStartRes = true;
2105 if (res < av.getRanges().getStartRes())
2107 res = av.getRanges().getStartRes();
2112 if (res > (stretchGroup.getStartRes() - 1))
2114 stretchGroup.setEndRes(res);
2115 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2118 else if (changeStartRes)
2120 if (res < (stretchGroup.getEndRes() + 1))
2122 stretchGroup.setStartRes(res);
2123 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2127 int dragDirection = 0;
2133 else if (y < oldSeq)
2138 while ((y != oldSeq) && (oldSeq > -1)
2139 && (y < av.getAlignment().getHeight()))
2141 // This routine ensures we don't skip any sequences, as the
2142 // selection is quite slow.
2143 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2145 oldSeq += dragDirection;
2152 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2154 if (stretchGroup.getSequences(null).contains(nextSeq))
2156 stretchGroup.deleteSequence(seq, false);
2157 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2163 stretchGroup.addSequence(seq, false);
2166 stretchGroup.addSequence(nextSeq, false);
2167 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2176 mouseDragging = true;
2178 if ((scrollThread != null) && (scrollThread.isRunning()))
2180 scrollThread.setEvent(evt);
2184 void scrollCanvas(MouseEvent evt)
2188 if ((scrollThread != null) && (scrollThread.isRunning()))
2190 scrollThread.stopScrolling();
2191 scrollThread = null;
2193 mouseDragging = false;
2197 if (scrollThread == null)
2199 scrollThread = new ScrollThread();
2202 mouseDragging = true;
2203 scrollThread.setEvent(evt);
2208 // this class allows scrolling off the bottom of the visible alignment
2209 class ScrollThread extends Thread
2213 private volatile boolean threadRunning = true;
2215 public ScrollThread()
2220 public void setEvent(MouseEvent e)
2225 public void stopScrolling()
2227 threadRunning = false;
2230 public boolean isRunning()
2232 return threadRunning;
2238 while (threadRunning)
2242 if (mouseDragging && (evt.getY() < 0)
2243 && (av.getRanges().getStartSeq() > 0))
2245 av.getRanges().scrollUp(true);
2248 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2249 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2251 av.getRanges().scrollUp(false);
2254 if (mouseDragging && (evt.getX() < 0))
2256 av.getRanges().scrollRight(false);
2258 else if (mouseDragging && (evt.getX() >= getWidth()))
2260 av.getRanges().scrollRight(true);
2267 } catch (Exception ex)
2275 * modify current selection according to a received message.
2278 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2279 HiddenColumns hidden, SelectionSource source)
2281 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2282 // handles selection messages...
2283 // TODO: extend config options to allow user to control if selections may be
2284 // shared between viewports.
2285 boolean iSentTheSelection = (av == source
2286 || (source instanceof AlignViewport
2287 && ((AlignmentViewport) source).getSequenceSetId()
2288 .equals(av.getSequenceSetId())));
2290 if (iSentTheSelection)
2292 // respond to our own event by updating dependent dialogs
2293 if (ap.getCalculationDialog() != null)
2295 ap.getCalculationDialog().validateCalcTypes();
2301 // process further ?
2302 if (!av.followSelection)
2308 * Ignore the selection if there is one of our own pending.
2310 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2316 * Check for selection in a view of which this one is a dna/protein
2319 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2324 // do we want to thread this ? (contention with seqsel and colsel locks, I
2327 * only copy colsel if there is a real intersection between
2328 * sequence selection and this panel's alignment
2330 boolean repaint = false;
2331 boolean copycolsel = false;
2333 SequenceGroup sgroup = null;
2334 if (seqsel != null && seqsel.getSize() > 0)
2336 if (av.getAlignment() == null)
2338 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2339 + " ViewId=" + av.getViewId()
2340 + " 's alignment is NULL! returning immediately.");
2343 sgroup = seqsel.intersect(av.getAlignment(),
2344 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2345 if ((sgroup != null && sgroup.getSize() > 0))
2350 if (sgroup != null && sgroup.getSize() > 0)
2352 av.setSelectionGroup(sgroup);
2356 av.setSelectionGroup(null);
2358 av.isSelectionGroupChanged(true);
2363 // the current selection is unset or from a previous message
2364 // so import the new colsel.
2365 if (colsel == null || colsel.isEmpty())
2367 if (av.getColumnSelection() != null)
2369 av.getColumnSelection().clear();
2375 // TODO: shift colSel according to the intersecting sequences
2376 if (av.getColumnSelection() == null)
2378 av.setColumnSelection(new ColumnSelection(colsel));
2382 av.getColumnSelection().setElementsFrom(colsel,
2383 av.getAlignment().getHiddenColumns());
2386 av.isColSelChanged(true);
2390 if (copycolsel && av.hasHiddenColumns()
2391 && (av.getAlignment().getHiddenColumns() == null))
2393 System.err.println("Bad things");
2395 if (repaint) // always true!
2397 // probably finessing with multiple redraws here
2398 PaintRefresher.Refresh(this, av.getSequenceSetId());
2399 // ap.paintAlignment(false);
2402 // lastly, update dependent dialogs
2403 if (ap.getCalculationDialog() != null)
2405 ap.getCalculationDialog().validateCalcTypes();
2411 * If this panel is a cdna/protein translation view of the selection source,
2412 * tries to map the source selection to a local one, and returns true. Else
2419 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2420 ColumnSelection colsel, HiddenColumns hidden,
2421 SelectionSource source)
2423 if (!(source instanceof AlignViewportI))
2427 final AlignViewportI sourceAv = (AlignViewportI) source;
2428 if (sourceAv.getCodingComplement() != av
2429 && av.getCodingComplement() != sourceAv)
2435 * Map sequence selection
2437 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2438 av.setSelectionGroup(sg);
2439 av.isSelectionGroupChanged(true);
2442 * Map column selection
2444 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2446 ColumnSelection cs = new ColumnSelection();
2447 HiddenColumns hs = new HiddenColumns();
2448 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2449 av.setColumnSelection(cs);
2450 av.getAlignment().setHiddenColumns(hs);
2452 // lastly, update any dependent dialogs
2453 if (ap.getCalculationDialog() != null)
2455 ap.getCalculationDialog().validateCalcTypes();
2458 PaintRefresher.Refresh(this, av.getSequenceSetId());
2465 * @return null or last search results handled by this panel
2467 public SearchResultsI getLastSearchResults()
2469 return lastSearchResults;