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);
294 * mouse is over sequence (or the space above sequences)
299 seq = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
305 seq = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
306 alignmentHeight - 1);
310 return new MousePos(col, seqIndex, annIndex);
313 * Returns the aligned sequence position (base 0) at the mouse position, or
314 * the closest visible one
319 int findColumn(MouseEvent evt)
324 int startRes = av.getRanges().getStartRes();
325 if (av.getWrapAlignment())
328 int hgap = av.getCharHeight();
329 if (av.getScaleAboveWrapped())
331 hgap += av.getCharHeight();
334 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
335 + hgap + seqCanvas.getAnnotationHeight();
338 y = Math.max(0, y - hgap);
339 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
341 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
347 wrappedBlock = y / cHeight;
348 wrappedBlock += startRes / cwidth;
349 // allow for wrapped view scrolled right (possible from Overview)
350 int startOffset = startRes % cwidth;
351 res = wrappedBlock * cwidth + startOffset
352 + +Math.min(cwidth - 1, x / av.getCharWidth());
356 if (x > seqCanvas.getX() + seqCanvas.getWidth())
358 // make sure we calculate relative to visible alignment, rather than
360 x = seqCanvas.getX() + seqCanvas.getWidth();
362 res = (x / av.getCharWidth()) + startRes;
363 if (res > av.getRanges().getEndRes())
366 res = av.getRanges().getEndRes();
370 if (av.hasHiddenColumns())
372 res = av.getAlignment().getHiddenColumns()
373 .visibleToAbsoluteColumn(res);
381 * Answers the index in the alignment (0...) of the sequence under the mouse
382 * position. If the mouse is below the alignment (say, over annotations),
383 * answers the index of the last sequence.
388 int findSeq(MouseEvent evt)
393 int charHeight = av.getCharHeight();
394 int alignmentHeight = av.getAlignment().getHeight();
395 if (av.getWrapAlignment())
397 int hgap = charHeight;
398 if (av.getScaleAboveWrapped())
403 int alignmentHeightPixels = alignmentHeight * charHeight;
404 int cHeight = alignmentHeightPixels + hgap
405 + seqCanvas.getAnnotationHeight();
409 int yOffsetPx = y % cHeight; // yPos below repeating width(s)
410 // if (yOffsetPx > alignmentHeightPixels)
412 // seq = -1; // cursor is over annotation or below alignment entirely
416 seq = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
421 seq = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
422 alignmentHeight - 1);
429 * When all of a sequence of edits are complete, put the resulting edit list
430 * on the history stack (undo list), and reset flags for editing in progress.
436 if (editCommand != null && editCommand.getSize() > 0)
438 ap.alignFrame.addHistoryItem(editCommand);
439 av.firePropertyChange("alignment", null,
440 av.getAlignment().getSequences());
445 * Tidy up come what may...
450 groupEditing = false;
459 seqCanvas.cursorY = getKeyboardNo1() - 1;
460 scrollToVisible(true);
463 void setCursorColumn()
465 seqCanvas.cursorX = getKeyboardNo1() - 1;
466 scrollToVisible(true);
469 void setCursorRowAndColumn()
471 if (keyboardNo2 == null)
473 keyboardNo2 = new StringBuffer();
477 seqCanvas.cursorX = getKeyboardNo1() - 1;
478 seqCanvas.cursorY = getKeyboardNo2() - 1;
479 scrollToVisible(true);
483 void setCursorPosition()
485 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
487 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
488 scrollToVisible(true);
491 void moveCursor(int dx, int dy)
493 seqCanvas.cursorX += dx;
494 seqCanvas.cursorY += dy;
496 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
498 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
500 int original = seqCanvas.cursorX - dx;
501 int maxWidth = av.getAlignment().getWidth();
503 if (!hidden.isVisible(seqCanvas.cursorX))
505 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
506 int[] region = hidden.getRegionWithEdgeAtRes(visx);
508 if (region != null) // just in case
513 seqCanvas.cursorX = region[1] + 1;
518 seqCanvas.cursorX = region[0] - 1;
521 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
524 if (seqCanvas.cursorX >= maxWidth
525 || !hidden.isVisible(seqCanvas.cursorX))
527 seqCanvas.cursorX = original;
531 scrollToVisible(false);
535 * Scroll to make the cursor visible in the viewport.
538 * just jump to the location rather than scrolling
540 void scrollToVisible(boolean jump)
542 if (seqCanvas.cursorX < 0)
544 seqCanvas.cursorX = 0;
546 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
548 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
551 if (seqCanvas.cursorY < 0)
553 seqCanvas.cursorY = 0;
555 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
557 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
562 boolean repaintNeeded = true;
565 // only need to repaint if the viewport did not move, as otherwise it will
567 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
572 if (av.getWrapAlignment())
574 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
575 int x = av.getAlignment().getHiddenColumns()
576 .absoluteToVisibleColumn(seqCanvas.cursorX);
577 av.getRanges().scrollToWrappedVisible(x);
581 av.getRanges().scrollToVisible(seqCanvas.cursorX,
586 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
588 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
589 seqCanvas.cursorX, seqCanvas.cursorY);
599 void setSelectionAreaAtCursor(boolean topLeft)
601 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
603 if (av.getSelectionGroup() != null)
605 SequenceGroup sg = av.getSelectionGroup();
606 // Find the top and bottom of this group
607 int min = av.getAlignment().getHeight(), max = 0;
608 for (int i = 0; i < sg.getSize(); i++)
610 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
625 sg.setStartRes(seqCanvas.cursorX);
626 if (sg.getEndRes() < seqCanvas.cursorX)
628 sg.setEndRes(seqCanvas.cursorX);
631 min = seqCanvas.cursorY;
635 sg.setEndRes(seqCanvas.cursorX);
636 if (sg.getStartRes() > seqCanvas.cursorX)
638 sg.setStartRes(seqCanvas.cursorX);
641 max = seqCanvas.cursorY + 1;
646 // Only the user can do this
647 av.setSelectionGroup(null);
651 // Now add any sequences between min and max
652 sg.getSequences(null).clear();
653 for (int i = min; i < max; i++)
655 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
660 if (av.getSelectionGroup() == null)
662 SequenceGroup sg = new SequenceGroup();
663 sg.setStartRes(seqCanvas.cursorX);
664 sg.setEndRes(seqCanvas.cursorX);
665 sg.addSequence(sequence, false);
666 av.setSelectionGroup(sg);
669 ap.paintAlignment(false, false);
673 void insertGapAtCursor(boolean group)
675 groupEditing = group;
676 startseq = seqCanvas.cursorY;
677 lastres = seqCanvas.cursorX;
678 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
682 void deleteGapAtCursor(boolean group)
684 groupEditing = group;
685 startseq = seqCanvas.cursorY;
686 lastres = seqCanvas.cursorX + getKeyboardNo1();
687 editSequence(false, false, seqCanvas.cursorX);
691 void insertNucAtCursor(boolean group, String nuc)
693 // TODO not called - delete?
694 groupEditing = group;
695 startseq = seqCanvas.cursorY;
696 lastres = seqCanvas.cursorX;
697 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
701 void numberPressed(char value)
703 if (keyboardNo1 == null)
705 keyboardNo1 = new StringBuffer();
708 if (keyboardNo2 != null)
710 keyboardNo2.append(value);
714 keyboardNo1.append(value);
722 if (keyboardNo1 != null)
724 int value = Integer.parseInt(keyboardNo1.toString());
728 } catch (Exception x)
739 if (keyboardNo2 != null)
741 int value = Integer.parseInt(keyboardNo2.toString());
745 } catch (Exception x)
759 public void mouseReleased(MouseEvent evt)
761 boolean didDrag = mouseDragging; // did we come here after a drag
762 mouseDragging = false;
763 mouseWheelPressed = false;
765 if (evt.isPopupTrigger()) // Windows: mouseReleased
774 doMouseReleasedDefineMode(evt, didDrag);
788 public void mousePressed(MouseEvent evt)
790 lastMousePress = evt.getPoint();
792 if (SwingUtilities.isMiddleMouseButton(evt))
794 mouseWheelPressed = true;
798 boolean isControlDown = Platform.isControlDown(evt);
799 if (evt.isShiftDown() || isControlDown)
809 doMousePressedDefineMode(evt);
813 int seq = findSeq(evt);
814 int res = findColumn(evt);
816 if (seq < 0 || res < 0)
821 if ((seq < av.getAlignment().getHeight())
822 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
839 public void mouseOverSequence(SequenceI sequence, int index, int pos)
841 String tmp = sequence.hashCode() + " " + index + " " + pos;
843 if (lastMessage == null || !lastMessage.equals(tmp))
845 // System.err.println("mouseOver Sequence: "+tmp);
846 ssm.mouseOverSequence(sequence, index, pos, av);
852 * Highlight the mapped region described by the search results object (unless
853 * unchanged). This supports highlight of protein while mousing over linked
854 * cDNA and vice versa. The status bar is also updated to show the location of
855 * the start of the highlighted region.
858 public void highlightSequence(SearchResultsI results)
860 if (results == null || results.equals(lastSearchResults))
864 lastSearchResults = results;
866 boolean wasScrolled = false;
868 if (av.isFollowHighlight())
870 // don't allow highlight of protein/cDNA to also scroll a complementary
871 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
872 // over residue to change abruptly, causing highlighted residue in panel 2
873 // to change, causing a scroll in panel 1 etc)
874 ap.setToScrollComplementPanel(false);
875 wasScrolled = ap.scrollToPosition(results, false);
878 seqCanvas.revalidate();
880 ap.setToScrollComplementPanel(true);
883 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
884 if (seqCanvas.highlightSearchResults(results, noFastPaint))
886 setStatusMessage(results);
891 public VamsasSource getVamsasSource()
893 return this.ap == null ? null : this.ap.av;
897 public void updateColours(SequenceI seq, int index)
899 System.out.println("update the seqPanel colours");
904 * Action on mouse movement is to update the status bar to show the current
905 * sequence position, and (if features are shown) to show any features at the
906 * position in a tooltip. Does nothing if the mouse move does not change
912 public void mouseMoved(MouseEvent evt)
916 // This is because MacOSX creates a mouseMoved
917 // If control is down, other platforms will not.
921 final MousePos mousePos = findMousePosition(evt);
922 if (mousePos.equals(lastMousePosition))
925 * just a pixel move without change of 'cell'
929 lastMousePosition = mousePos;
931 if (mousePos.annotationIndex != -1)
933 mouseMovedOverAnnotation(mousePos);
936 final int seq = mousePos.seqIndex;// findSeq(evt);
938 final int column = mousePos.column;
939 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
941 lastMousePosition = null;
942 setToolTipText(null);
943 ap.alignFrame.statusBar.setText("");
947 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
949 if (column >= sequence.getLength())
955 * set status bar message, returning residue position in sequence
957 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
958 final int pos = setStatusMessage(sequence, column, seq);
959 if (ssm != null && !isGapped)
961 mouseOverSequence(sequence, column, pos);
964 tooltipText.setLength(6); // Cuts the buffer back to <html>
966 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
969 for (int g = 0; g < groups.length; g++)
971 if (groups[g].getStartRes() <= column
972 && groups[g].getEndRes() >= column)
974 if (!groups[g].getName().startsWith("JTreeGroup")
975 && !groups[g].getName().startsWith("JGroup"))
977 tooltipText.append(groups[g].getName());
980 if (groups[g].getDescription() != null)
982 tooltipText.append(": " + groups[g].getDescription());
989 * add any features at the position to the tooltip; if over a gap, only
990 * add features that straddle the gap (pos may be the residue before or
993 if (av.isShowSequenceFeatures())
995 List<SequenceFeature> features = ap.getFeatureRenderer()
996 .findFeaturesAtColumn(sequence, column + 1);
997 seqARep.appendFeatures(tooltipText, pos, features,
998 this.ap.getSeqPanel().seqCanvas.fr);
1000 if (tooltipText.length() == 6) // <html>
1002 setToolTipText(null);
1007 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
1009 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
1010 tooltipText.append("...");
1012 String textString = tooltipText.toString();
1013 if (lastTooltip == null || !lastTooltip.equals(textString))
1015 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
1017 setToolTipText(formattedTooltipText);
1018 lastTooltip = textString;
1024 * When the view is in wrapped mode, and the mouse is over an annotation row,
1025 * shows the corresponding tooltip and status message (if any)
1030 protected void mouseMovedOverAnnotation(MousePos pos)
1032 final int column = pos.column;
1033 final int rowIndex = pos.annotationIndex;
1035 if (!av.getWrapAlignment() || !av.isShowAnnotation() || rowIndex < 0)
1039 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
1041 String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
1043 setToolTipText(tooltip);
1044 lastTooltip = tooltip;
1046 String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
1048 ap.alignFrame.statusBar.setText(msg);
1051 private Point lastp = null;
1056 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
1059 public Point getToolTipLocation(MouseEvent event)
1061 int x = event.getX(), w = getWidth();
1062 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
1065 if (!event.isShiftDown() || p == null)
1067 p = (tooltipText != null && tooltipText.length() > 6)
1068 ? new Point(event.getX() + wdth, event.getY() - 20)
1072 * TODO: try to modify position region is not obcured by tooltip
1080 * set when the current UI interaction has resulted in a change that requires
1081 * shading in overviews and structures to be recalculated. this could be
1082 * changed to a something more expressive that indicates what actually has
1083 * changed, so selective redraws can be applied (ie. only structures, only
1086 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1089 * set if av.getSelectionGroup() refers to a group that is defined on the
1090 * alignment view, rather than a transient selection
1092 // private boolean editingDefinedGroup = false; // TODO: refactor to
1093 // avcontroller or viewModel
1096 * Sets the status message in alignment panel, showing the sequence number
1097 * (index) and id, and residue and residue position if not at a gap, for the
1098 * given sequence and column position. Returns the residue position returned
1099 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1100 * if at a gapped position.
1103 * aligned sequence object
1107 * index of sequence in alignment
1108 * @return sequence position of residue at column, or adjacent residue if at a
1111 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1113 char sequenceChar = sequence.getCharAt(column);
1114 int pos = sequence.findPosition(column);
1115 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1121 * Builds the status message for the current cursor location and writes it to
1122 * the status bar, for example
1125 * Sequence 3 ID: FER1_SOLLC
1126 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1127 * Sequence 5 ID: FER1_PEA Residue: B (3)
1128 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1133 * sequence position in the alignment (1..)
1134 * @param sequenceChar
1135 * the character under the cursor
1137 * the sequence residue position (if not over a gap)
1139 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1140 char sequenceChar, int residuePos)
1142 StringBuilder text = new StringBuilder(32);
1145 * Sequence number (if known), and sequence name.
1147 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1148 text.append("Sequence").append(seqno).append(" ID: ")
1149 .append(sequence.getName());
1151 String residue = null;
1154 * Try to translate the display character to residue name (null for gap).
1156 boolean isGapped = Comparison.isGap(sequenceChar);
1160 boolean nucleotide = av.getAlignment().isNucleotide();
1161 String displayChar = String.valueOf(sequenceChar);
1164 residue = ResidueProperties.nucleotideName.get(displayChar);
1168 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1169 : ("*".equals(displayChar) ? "STOP"
1170 : ResidueProperties.aa2Triplet.get(displayChar));
1172 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1173 .append(": ").append(residue == null ? displayChar : residue);
1175 text.append(" (").append(Integer.toString(residuePos)).append(")");
1177 ap.alignFrame.statusBar.setText(text.toString());
1181 * Set the status bar message to highlight the first matched position in
1186 private void setStatusMessage(SearchResultsI results)
1188 AlignmentI al = this.av.getAlignment();
1189 int sequenceIndex = al.findIndex(results);
1190 if (sequenceIndex == -1)
1194 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1195 for (SearchResultMatchI m : results.getResults())
1197 SequenceI seq = m.getSequence();
1198 if (seq.getDatasetSequence() != null)
1200 seq = seq.getDatasetSequence();
1205 int start = m.getStart();
1206 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1217 public void mouseDragged(MouseEvent evt)
1219 if (mouseWheelPressed)
1221 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1222 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1224 int oldWidth = av.getCharWidth();
1226 // Which is bigger, left-right or up-down?
1227 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1228 .abs(evt.getX() - lastMousePress.getX()))
1231 * on drag up or down, decrement or increment font size
1233 int fontSize = av.font.getSize();
1234 boolean fontChanged = false;
1236 if (evt.getY() < lastMousePress.getY())
1241 else if (evt.getY() > lastMousePress.getY())
1254 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1256 av.setFont(newFont, true);
1257 av.setCharWidth(oldWidth);
1261 ap.av.getCodingComplement().setFont(newFont, true);
1262 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1263 .getSplitViewContainer();
1264 splitFrame.adjustLayout();
1265 splitFrame.repaint();
1272 * on drag left or right, decrement or increment character width
1275 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1277 newWidth = av.getCharWidth() - 1;
1278 av.setCharWidth(newWidth);
1280 else if (evt.getX() > lastMousePress.getX())
1282 newWidth = av.getCharWidth() + 1;
1283 av.setCharWidth(newWidth);
1287 ap.paintAlignment(false, false);
1291 * need to ensure newWidth is set on cdna, regardless of which
1292 * panel the mouse drag happened in; protein will compute its
1293 * character width as 1:1 or 3:1
1295 av.getCodingComplement().setCharWidth(newWidth);
1296 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1297 .getSplitViewContainer();
1298 splitFrame.adjustLayout();
1299 splitFrame.repaint();
1304 FontMetrics fm = getFontMetrics(av.getFont());
1305 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1307 lastMousePress = evt.getPoint();
1314 doMouseDraggedDefineMode(evt);
1318 int res = findColumn(evt);
1325 if ((lastres == -1) || (lastres == res))
1330 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1332 // dragLeft, delete gap
1333 editSequence(false, false, res);
1337 editSequence(true, false, res);
1340 mouseDragging = true;
1341 if ((scrollThread != null) && (scrollThread.isRunning()))
1343 scrollThread.setEvent(evt);
1347 // TODO: Make it more clever than many booleans
1348 synchronized void editSequence(boolean insertGap, boolean editSeq,
1352 int fixedRight = -1;
1353 boolean fixedColumns = false;
1354 SequenceGroup sg = av.getSelectionGroup();
1356 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1358 // No group, but the sequence may represent a group
1359 if (!groupEditing && av.hasHiddenRows())
1361 if (av.isHiddenRepSequence(seq))
1363 sg = av.getRepresentedSequences(seq);
1364 groupEditing = true;
1368 StringBuilder message = new StringBuilder(64);
1371 message.append("Edit group:");
1372 if (editCommand == null)
1374 editCommand = new EditCommand(
1375 MessageManager.getString("action.edit_group"));
1380 message.append("Edit sequence: " + seq.getName());
1381 String label = seq.getName();
1382 if (label.length() > 10)
1384 label = label.substring(0, 10);
1386 if (editCommand == null)
1388 editCommand = new EditCommand(MessageManager
1389 .formatMessage("label.edit_params", new String[]
1396 message.append(" insert ");
1400 message.append(" delete ");
1403 message.append(Math.abs(startres - lastres) + " gaps.");
1404 ap.alignFrame.statusBar.setText(message.toString());
1406 // Are we editing within a selection group?
1407 if (groupEditing || (sg != null
1408 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1410 fixedColumns = true;
1412 // sg might be null as the user may only see 1 sequence,
1413 // but the sequence represents a group
1416 if (!av.isHiddenRepSequence(seq))
1421 sg = av.getRepresentedSequences(seq);
1424 fixedLeft = sg.getStartRes();
1425 fixedRight = sg.getEndRes();
1427 if ((startres < fixedLeft && lastres >= fixedLeft)
1428 || (startres >= fixedLeft && lastres < fixedLeft)
1429 || (startres > fixedRight && lastres <= fixedRight)
1430 || (startres <= fixedRight && lastres > fixedRight))
1436 if (fixedLeft > startres)
1438 fixedRight = fixedLeft - 1;
1441 else if (fixedRight < startres)
1443 fixedLeft = fixedRight;
1448 if (av.hasHiddenColumns())
1450 fixedColumns = true;
1451 int y1 = av.getAlignment().getHiddenColumns()
1452 .getNextHiddenBoundary(true, startres);
1453 int y2 = av.getAlignment().getHiddenColumns()
1454 .getNextHiddenBoundary(false, startres);
1456 if ((insertGap && startres > y1 && lastres < y1)
1457 || (!insertGap && startres < y2 && lastres > y2))
1463 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1464 // Selection spans a hidden region
1465 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1473 fixedRight = y2 - 1;
1480 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1481 int g, groupSize = vseqs.size();
1482 SequenceI[] groupSeqs = new SequenceI[groupSize];
1483 for (g = 0; g < groupSeqs.length; g++)
1485 groupSeqs[g] = vseqs.get(g);
1491 // If the user has selected the whole sequence, and is dragging to
1492 // the right, we can still extend the alignment and selectionGroup
1493 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1494 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1496 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1497 fixedRight = sg.getEndRes();
1500 // Is it valid with fixed columns??
1501 // Find the next gap before the end
1502 // of the visible region boundary
1503 boolean blank = false;
1504 for (; fixedRight > lastres; fixedRight--)
1508 for (g = 0; g < groupSize; g++)
1510 for (int j = 0; j < startres - lastres; j++)
1512 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1527 if (sg.getSize() == av.getAlignment().getHeight())
1529 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1531 .getNextHiddenBoundary(false, startres)))
1537 int alWidth = av.getAlignment().getWidth();
1538 if (av.hasHiddenRows())
1540 int hwidth = av.getAlignment().getHiddenSequences()
1542 if (hwidth > alWidth)
1547 // We can still insert gaps if the selectionGroup
1548 // contains all the sequences
1549 sg.setEndRes(sg.getEndRes() + startres - lastres);
1550 fixedRight = alWidth + startres - lastres;
1561 else if (!insertGap)
1563 // / Are we able to delete?
1564 // ie are all columns blank?
1566 for (g = 0; g < groupSize; g++)
1568 for (int j = startres; j < lastres; j++)
1570 if (groupSeqs[g].getLength() <= j)
1575 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1577 // Not a gap, block edit not valid
1587 // dragging to the right
1588 if (fixedColumns && fixedRight != -1)
1590 for (int j = lastres; j < startres; j++)
1592 insertChar(j, groupSeqs, fixedRight);
1597 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1598 startres - lastres);
1603 // dragging to the left
1604 if (fixedColumns && fixedRight != -1)
1606 for (int j = lastres; j > startres; j--)
1608 deleteChar(startres, groupSeqs, fixedRight);
1613 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1614 lastres - startres);
1620 // ///Editing a single sequence///////////
1624 // dragging to the right
1625 if (fixedColumns && fixedRight != -1)
1627 for (int j = lastres; j < startres; j++)
1629 insertChar(j, new SequenceI[] { seq }, fixedRight);
1634 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1635 startres - lastres);
1642 // dragging to the left
1643 if (fixedColumns && fixedRight != -1)
1645 for (int j = lastres; j > startres; j--)
1647 if (!Comparison.isGap(seq.getCharAt(startres)))
1652 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1657 // could be a keyboard edit trying to delete none gaps
1659 for (int m = startres; m < lastres; m++)
1661 if (!Comparison.isGap(seq.getCharAt(m)))
1670 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1676 {// insertGap==false AND editSeq==TRUE;
1677 if (fixedColumns && fixedRight != -1)
1679 for (int j = lastres; j < startres; j++)
1681 insertChar(j, new SequenceI[] { seq }, fixedRight);
1686 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1687 startres - lastres);
1694 seqCanvas.repaint();
1697 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1699 int blankColumn = fixedColumn;
1700 for (int s = 0; s < seq.length; s++)
1702 // Find the next gap before the end of the visible region boundary
1703 // If lastCol > j, theres a boundary after the gap insertion
1705 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1707 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1709 // Theres a space, so break and insert the gap
1714 if (blankColumn <= j)
1716 blankColumn = fixedColumn;
1722 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1724 appendEdit(Action.INSERT_GAP, seq, j, 1);
1729 * Helper method to add and perform one edit action.
1736 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1740 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1741 av.getAlignment().getGapCharacter());
1743 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1746 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1749 appendEdit(Action.DELETE_GAP, seq, j, 1);
1751 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1761 public void mouseEntered(MouseEvent e)
1768 if ((scrollThread != null) && (scrollThread.isRunning()))
1770 scrollThread.stopScrolling();
1771 scrollThread = null;
1782 public void mouseExited(MouseEvent e)
1784 if (av.getWrapAlignment())
1789 if (mouseDragging && scrollThread == null)
1791 scrollThread = new ScrollThread();
1796 * Handler for double-click on a position with one or more sequence features.
1797 * Opens the Amend Features dialog to allow feature details to be amended, or
1798 * the feature deleted.
1801 public void mouseClicked(MouseEvent evt)
1803 SequenceGroup sg = null;
1804 SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
1805 if (evt.getClickCount() > 1)
1807 sg = av.getSelectionGroup();
1808 if (sg != null && sg.getSize() == 1
1809 && sg.getEndRes() - sg.getStartRes() < 2)
1811 av.setSelectionGroup(null);
1814 int column = findColumn(evt);
1817 * find features at the position (if not gapped), or straddling
1818 * the position (if at a gap)
1820 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1821 .findFeaturesAtColumn(sequence, column + 1);
1823 if (!features.isEmpty())
1826 * highlight the first feature at the position on the alignment
1828 SearchResultsI highlight = new SearchResults();
1829 highlight.addResult(sequence, features.get(0).getBegin(), features
1831 seqCanvas.highlightSearchResults(highlight, false);
1834 * open the Amend Features dialog; clear highlighting afterwards,
1835 * whether changes were made or not
1837 List<SequenceI> seqs = Collections.singletonList(sequence);
1838 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1840 av.setSearchResults(null); // clear highlighting
1841 seqCanvas.repaint(); // draw new/amended features
1847 public void mouseWheelMoved(MouseWheelEvent e)
1850 double wheelRotation = e.getPreciseWheelRotation();
1851 if (wheelRotation > 0)
1853 if (e.isShiftDown())
1855 av.getRanges().scrollRight(true);
1860 av.getRanges().scrollUp(false);
1863 else if (wheelRotation < 0)
1865 if (e.isShiftDown())
1867 av.getRanges().scrollRight(false);
1871 av.getRanges().scrollUp(true);
1876 * update status bar and tooltip for new position
1877 * (need to synthesize a mouse movement to refresh tooltip)
1880 ToolTipManager.sharedInstance().mouseMoved(e);
1889 public void doMousePressedDefineMode(MouseEvent evt)
1891 final int res = findColumn(evt);
1892 final int seq = findSeq(evt);
1894 updateOverviewAndStructs = false;
1896 startWrapBlock = wrappedBlock;
1898 if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
1900 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1901 MessageManager.getString(
1902 "label.cannot_edit_annotations_in_wrapped_view"),
1903 MessageManager.getString("label.wrapped_view_no_edit"),
1904 JvOptionPane.WARNING_MESSAGE);
1908 if (seq < 0 || res < 0)
1913 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1915 if ((sequence == null) || (res > sequence.getLength()))
1920 stretchGroup = av.getSelectionGroup();
1922 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1924 stretchGroup = av.getAlignment().findGroup(sequence, res);
1925 if (stretchGroup != null)
1927 // only update the current selection if the popup menu has a group to
1929 av.setSelectionGroup(stretchGroup);
1933 if (evt.isPopupTrigger()) // Mac: mousePressed
1940 * defer right-mouse click handling to mouseReleased on Windows
1941 * (where isPopupTrigger() will answer true)
1942 * NB isRightMouseButton is also true for Cmd-click on Mac
1944 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1951 seqCanvas.cursorX = findColumn(evt);
1952 seqCanvas.cursorY = findSeq(evt);
1953 seqCanvas.repaint();
1957 if (stretchGroup == null)
1959 createStretchGroup(res, sequence);
1962 if (stretchGroup != null)
1964 stretchGroup.addPropertyChangeListener(seqCanvas);
1967 seqCanvas.repaint();
1970 private void createStretchGroup(int res, SequenceI sequence)
1972 // Only if left mouse button do we want to change group sizes
1973 // define a new group here
1974 SequenceGroup sg = new SequenceGroup();
1975 sg.setStartRes(res);
1977 sg.addSequence(sequence, false);
1978 av.setSelectionGroup(sg);
1981 if (av.getConservationSelected())
1983 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1987 if (av.getAbovePIDThreshold())
1989 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1992 // TODO: stretchGroup will always be not null. Is this a merge error ?
1993 // or is there a threading issue here?
1994 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1996 // Edit end res position of selected group
1997 changeEndRes = true;
1999 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
2001 // Edit end res position of selected group
2002 changeStartRes = true;
2004 stretchGroup.getWidth();
2009 * Build and show a pop-up menu at the right-click mouse position
2015 void showPopupMenu(MouseEvent evt)
2017 final int column = findColumn(evt);
2018 final int seq = findSeq(evt);
2019 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
2020 List<SequenceFeature> features = ap.getFeatureRenderer()
2021 .findFeaturesAtColumn(sequence, column + 1);
2023 PopupMenu pop = new PopupMenu(ap, null, features);
2024 pop.show(this, evt.getX(), evt.getY());
2028 * Update the display after mouse up on a selection or group
2031 * mouse released event details
2033 * true if this event is happening after a mouse drag (rather than a
2036 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
2038 if (stretchGroup == null)
2043 stretchGroup.removePropertyChangeListener(seqCanvas);
2045 // always do this - annotation has own state
2046 // but defer colourscheme update until hidden sequences are passed in
2047 boolean vischange = stretchGroup.recalcConservation(true);
2048 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
2050 if (stretchGroup.cs != null)
2052 stretchGroup.cs.alignmentChanged(stretchGroup,
2053 av.getHiddenRepSequences());
2055 ResidueShaderI groupColourScheme = stretchGroup
2056 .getGroupColourScheme();
2057 String name = stretchGroup.getName();
2058 if (stretchGroup.cs.conservationApplied())
2060 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2062 if (stretchGroup.cs.getThreshold() > 0)
2064 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2067 PaintRefresher.Refresh(this, av.getSequenceSetId());
2068 // TODO: structure colours only need updating if stretchGroup used to or now
2069 // does contain sequences with structure views
2070 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2071 updateOverviewAndStructs = false;
2072 changeEndRes = false;
2073 changeStartRes = false;
2074 stretchGroup = null;
2084 public void doMouseDraggedDefineMode(MouseEvent evt)
2086 int res = findColumn(evt);
2087 int y = findSeq(evt);
2089 if (wrappedBlock != startWrapBlock)
2094 if (stretchGroup == null)
2099 if (res >= av.getAlignment().getWidth())
2101 res = av.getAlignment().getWidth() - 1;
2104 if (stretchGroup.getEndRes() == res)
2106 // Edit end res position of selected group
2107 changeEndRes = true;
2109 else if (stretchGroup.getStartRes() == res)
2111 // Edit start res position of selected group
2112 changeStartRes = true;
2115 if (res < av.getRanges().getStartRes())
2117 res = av.getRanges().getStartRes();
2122 if (res > (stretchGroup.getStartRes() - 1))
2124 stretchGroup.setEndRes(res);
2125 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2128 else if (changeStartRes)
2130 if (res < (stretchGroup.getEndRes() + 1))
2132 stretchGroup.setStartRes(res);
2133 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2137 int dragDirection = 0;
2143 else if (y < oldSeq)
2148 while ((y != oldSeq) && (oldSeq > -1)
2149 && (y < av.getAlignment().getHeight()))
2151 // This routine ensures we don't skip any sequences, as the
2152 // selection is quite slow.
2153 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2155 oldSeq += dragDirection;
2162 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2164 if (stretchGroup.getSequences(null).contains(nextSeq))
2166 stretchGroup.deleteSequence(seq, false);
2167 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2173 stretchGroup.addSequence(seq, false);
2176 stretchGroup.addSequence(nextSeq, false);
2177 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2186 mouseDragging = true;
2188 if ((scrollThread != null) && (scrollThread.isRunning()))
2190 scrollThread.setEvent(evt);
2194 void scrollCanvas(MouseEvent evt)
2198 if ((scrollThread != null) && (scrollThread.isRunning()))
2200 scrollThread.stopScrolling();
2201 scrollThread = null;
2203 mouseDragging = false;
2207 if (scrollThread == null)
2209 scrollThread = new ScrollThread();
2212 mouseDragging = true;
2213 scrollThread.setEvent(evt);
2218 // this class allows scrolling off the bottom of the visible alignment
2219 class ScrollThread extends Thread
2223 private volatile boolean threadRunning = true;
2225 public ScrollThread()
2230 public void setEvent(MouseEvent e)
2235 public void stopScrolling()
2237 threadRunning = false;
2240 public boolean isRunning()
2242 return threadRunning;
2248 while (threadRunning)
2252 if (mouseDragging && (evt.getY() < 0)
2253 && (av.getRanges().getStartSeq() > 0))
2255 av.getRanges().scrollUp(true);
2258 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2259 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2261 av.getRanges().scrollUp(false);
2264 if (mouseDragging && (evt.getX() < 0))
2266 av.getRanges().scrollRight(false);
2268 else if (mouseDragging && (evt.getX() >= getWidth()))
2270 av.getRanges().scrollRight(true);
2277 } catch (Exception ex)
2285 * modify current selection according to a received message.
2288 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2289 HiddenColumns hidden, SelectionSource source)
2291 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2292 // handles selection messages...
2293 // TODO: extend config options to allow user to control if selections may be
2294 // shared between viewports.
2295 boolean iSentTheSelection = (av == source
2296 || (source instanceof AlignViewport
2297 && ((AlignmentViewport) source).getSequenceSetId()
2298 .equals(av.getSequenceSetId())));
2300 if (iSentTheSelection)
2302 // respond to our own event by updating dependent dialogs
2303 if (ap.getCalculationDialog() != null)
2305 ap.getCalculationDialog().validateCalcTypes();
2311 // process further ?
2312 if (!av.followSelection)
2318 * Ignore the selection if there is one of our own pending.
2320 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2326 * Check for selection in a view of which this one is a dna/protein
2329 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2334 // do we want to thread this ? (contention with seqsel and colsel locks, I
2337 * only copy colsel if there is a real intersection between
2338 * sequence selection and this panel's alignment
2340 boolean repaint = false;
2341 boolean copycolsel = false;
2343 SequenceGroup sgroup = null;
2344 if (seqsel != null && seqsel.getSize() > 0)
2346 if (av.getAlignment() == null)
2348 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2349 + " ViewId=" + av.getViewId()
2350 + " 's alignment is NULL! returning immediately.");
2353 sgroup = seqsel.intersect(av.getAlignment(),
2354 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2355 if ((sgroup != null && sgroup.getSize() > 0))
2360 if (sgroup != null && sgroup.getSize() > 0)
2362 av.setSelectionGroup(sgroup);
2366 av.setSelectionGroup(null);
2368 av.isSelectionGroupChanged(true);
2373 // the current selection is unset or from a previous message
2374 // so import the new colsel.
2375 if (colsel == null || colsel.isEmpty())
2377 if (av.getColumnSelection() != null)
2379 av.getColumnSelection().clear();
2385 // TODO: shift colSel according to the intersecting sequences
2386 if (av.getColumnSelection() == null)
2388 av.setColumnSelection(new ColumnSelection(colsel));
2392 av.getColumnSelection().setElementsFrom(colsel,
2393 av.getAlignment().getHiddenColumns());
2396 av.isColSelChanged(true);
2400 if (copycolsel && av.hasHiddenColumns()
2401 && (av.getAlignment().getHiddenColumns() == null))
2403 System.err.println("Bad things");
2405 if (repaint) // always true!
2407 // probably finessing with multiple redraws here
2408 PaintRefresher.Refresh(this, av.getSequenceSetId());
2409 // ap.paintAlignment(false);
2412 // lastly, update dependent dialogs
2413 if (ap.getCalculationDialog() != null)
2415 ap.getCalculationDialog().validateCalcTypes();
2421 * If this panel is a cdna/protein translation view of the selection source,
2422 * tries to map the source selection to a local one, and returns true. Else
2429 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2430 ColumnSelection colsel, HiddenColumns hidden,
2431 SelectionSource source)
2433 if (!(source instanceof AlignViewportI))
2437 final AlignViewportI sourceAv = (AlignViewportI) source;
2438 if (sourceAv.getCodingComplement() != av
2439 && av.getCodingComplement() != sourceAv)
2445 * Map sequence selection
2447 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2448 av.setSelectionGroup(sg);
2449 av.isSelectionGroupChanged(true);
2452 * Map column selection
2454 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2456 ColumnSelection cs = new ColumnSelection();
2457 HiddenColumns hs = new HiddenColumns();
2458 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2459 av.setColumnSelection(cs);
2460 av.getAlignment().setHiddenColumns(hs);
2462 // lastly, update any dependent dialogs
2463 if (ap.getCalculationDialog() != null)
2465 ap.getCalculationDialog().validateCalcTypes();
2468 PaintRefresher.Refresh(this, av.getSequenceSetId());
2475 * @return null or last search results handled by this panel
2477 public SearchResultsI getLastSearchResults()
2479 return lastSearchResults;