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 (or possibly annotation row when in
259 * wrapped mode) for the given mouse position
264 MousePos findMousePosition(MouseEvent evt)
266 int col = findColumn(evt);
271 int charHeight = av.getCharHeight();
272 int alignmentHeight = av.getAlignment().getHeight();
273 if (av.getWrapAlignment())
275 int hgap = charHeight;
276 if (av.getScaleAboveWrapped())
281 final int alignmentHeightPixels = alignmentHeight * charHeight + hgap;
282 final int annotationHeight = seqCanvas.getAnnotationHeight();
283 final int cHeight = alignmentHeightPixels + annotationHeight;
285 int yOffsetPx = y % cHeight; // yPos below repeating width(s)
286 if (yOffsetPx > alignmentHeightPixels)
289 * mouse is over annotations
291 AlignmentAnnotation[] anns = av.getAlignment()
292 .getAlignmentAnnotation();
293 int rowOffsetPx = yOffsetPx - alignmentHeightPixels;
294 annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
295 // also last sequence in alignment (for backwards compatible behaviour)
296 seq = alignmentHeight - 1;
301 * mouse is over sequence (or the space above sequences)
306 seq = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
312 seq = Math.min((y / charHeight) + av.getRanges().getStartSeq(),
313 alignmentHeight - 1);
317 return new MousePos(col, seqIndex, annIndex);
320 * Returns the aligned sequence position (base 0) at the mouse position, or
321 * the closest visible one
326 int findColumn(MouseEvent evt)
331 int startRes = av.getRanges().getStartRes();
332 if (av.getWrapAlignment())
335 int hgap = av.getCharHeight();
336 if (av.getScaleAboveWrapped())
338 hgap += av.getCharHeight();
341 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
342 + hgap + seqCanvas.getAnnotationHeight();
345 y = Math.max(0, y - hgap);
346 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
348 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
354 wrappedBlock = y / cHeight;
355 wrappedBlock += startRes / cwidth;
356 // allow for wrapped view scrolled right (possible from Overview)
357 int startOffset = startRes % cwidth;
358 res = wrappedBlock * cwidth + startOffset
359 + +Math.min(cwidth - 1, x / av.getCharWidth());
364 * make sure we calculate relative to visible alignment,
365 * rather than right-hand gutter
367 x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
368 res = (x / av.getCharWidth()) + startRes;
369 res = Math.min(res, av.getRanges().getEndRes());
372 if (av.hasHiddenColumns())
374 res = av.getAlignment().getHiddenColumns()
375 .visibleToAbsoluteColumn(res);
382 * When all of a sequence of edits are complete, put the resulting edit list
383 * on the history stack (undo list), and reset flags for editing in progress.
389 if (editCommand != null && editCommand.getSize() > 0)
391 ap.alignFrame.addHistoryItem(editCommand);
392 av.firePropertyChange("alignment", null,
393 av.getAlignment().getSequences());
398 * Tidy up come what may...
403 groupEditing = false;
412 seqCanvas.cursorY = getKeyboardNo1() - 1;
413 scrollToVisible(true);
416 void setCursorColumn()
418 seqCanvas.cursorX = getKeyboardNo1() - 1;
419 scrollToVisible(true);
422 void setCursorRowAndColumn()
424 if (keyboardNo2 == null)
426 keyboardNo2 = new StringBuffer();
430 seqCanvas.cursorX = getKeyboardNo1() - 1;
431 seqCanvas.cursorY = getKeyboardNo2() - 1;
432 scrollToVisible(true);
436 void setCursorPosition()
438 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
440 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
441 scrollToVisible(true);
444 void moveCursor(int dx, int dy)
446 seqCanvas.cursorX += dx;
447 seqCanvas.cursorY += dy;
449 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
451 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
453 int original = seqCanvas.cursorX - dx;
454 int maxWidth = av.getAlignment().getWidth();
456 if (!hidden.isVisible(seqCanvas.cursorX))
458 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
459 int[] region = hidden.getRegionWithEdgeAtRes(visx);
461 if (region != null) // just in case
466 seqCanvas.cursorX = region[1] + 1;
471 seqCanvas.cursorX = region[0] - 1;
474 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
477 if (seqCanvas.cursorX >= maxWidth
478 || !hidden.isVisible(seqCanvas.cursorX))
480 seqCanvas.cursorX = original;
484 scrollToVisible(false);
488 * Scroll to make the cursor visible in the viewport.
491 * just jump to the location rather than scrolling
493 void scrollToVisible(boolean jump)
495 if (seqCanvas.cursorX < 0)
497 seqCanvas.cursorX = 0;
499 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
501 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
504 if (seqCanvas.cursorY < 0)
506 seqCanvas.cursorY = 0;
508 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
510 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
515 boolean repaintNeeded = true;
518 // only need to repaint if the viewport did not move, as otherwise it will
520 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
525 if (av.getWrapAlignment())
527 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
528 int x = av.getAlignment().getHiddenColumns()
529 .absoluteToVisibleColumn(seqCanvas.cursorX);
530 av.getRanges().scrollToWrappedVisible(x);
534 av.getRanges().scrollToVisible(seqCanvas.cursorX,
539 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
541 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
542 seqCanvas.cursorX, seqCanvas.cursorY);
552 void setSelectionAreaAtCursor(boolean topLeft)
554 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
556 if (av.getSelectionGroup() != null)
558 SequenceGroup sg = av.getSelectionGroup();
559 // Find the top and bottom of this group
560 int min = av.getAlignment().getHeight(), max = 0;
561 for (int i = 0; i < sg.getSize(); i++)
563 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
578 sg.setStartRes(seqCanvas.cursorX);
579 if (sg.getEndRes() < seqCanvas.cursorX)
581 sg.setEndRes(seqCanvas.cursorX);
584 min = seqCanvas.cursorY;
588 sg.setEndRes(seqCanvas.cursorX);
589 if (sg.getStartRes() > seqCanvas.cursorX)
591 sg.setStartRes(seqCanvas.cursorX);
594 max = seqCanvas.cursorY + 1;
599 // Only the user can do this
600 av.setSelectionGroup(null);
604 // Now add any sequences between min and max
605 sg.getSequences(null).clear();
606 for (int i = min; i < max; i++)
608 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
613 if (av.getSelectionGroup() == null)
615 SequenceGroup sg = new SequenceGroup();
616 sg.setStartRes(seqCanvas.cursorX);
617 sg.setEndRes(seqCanvas.cursorX);
618 sg.addSequence(sequence, false);
619 av.setSelectionGroup(sg);
622 ap.paintAlignment(false, false);
626 void insertGapAtCursor(boolean group)
628 groupEditing = group;
629 startseq = seqCanvas.cursorY;
630 lastres = seqCanvas.cursorX;
631 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
635 void deleteGapAtCursor(boolean group)
637 groupEditing = group;
638 startseq = seqCanvas.cursorY;
639 lastres = seqCanvas.cursorX + getKeyboardNo1();
640 editSequence(false, false, seqCanvas.cursorX);
644 void insertNucAtCursor(boolean group, String nuc)
646 // TODO not called - delete?
647 groupEditing = group;
648 startseq = seqCanvas.cursorY;
649 lastres = seqCanvas.cursorX;
650 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
654 void numberPressed(char value)
656 if (keyboardNo1 == null)
658 keyboardNo1 = new StringBuffer();
661 if (keyboardNo2 != null)
663 keyboardNo2.append(value);
667 keyboardNo1.append(value);
675 if (keyboardNo1 != null)
677 int value = Integer.parseInt(keyboardNo1.toString());
681 } catch (Exception x)
692 if (keyboardNo2 != null)
694 int value = Integer.parseInt(keyboardNo2.toString());
698 } catch (Exception x)
712 public void mouseReleased(MouseEvent evt)
714 MousePos pos = findMousePosition(evt);
715 if (pos.annotationIndex != -1)
717 // mouse is over annotation row in wrapped mode
721 boolean didDrag = mouseDragging; // did we come here after a drag
722 mouseDragging = false;
723 mouseWheelPressed = false;
725 if (evt.isPopupTrigger()) // Windows: mouseReleased
727 showPopupMenu(evt, pos);
734 doMouseReleasedDefineMode(evt, didDrag);
748 public void mousePressed(MouseEvent evt)
750 lastMousePress = evt.getPoint();
751 MousePos pos = findMousePosition(evt);
752 if (pos.annotationIndex != -1)
754 // mouse is over an annotation row in wrapped mode
758 if (SwingUtilities.isMiddleMouseButton(evt))
760 mouseWheelPressed = true;
764 boolean isControlDown = Platform.isControlDown(evt);
765 if (evt.isShiftDown() || isControlDown)
775 doMousePressedDefineMode(evt, pos);
779 int seq = pos.seqIndex;
780 int res = pos.column;
782 if (seq < 0 || res < 0)
787 if ((seq < av.getAlignment().getHeight())
788 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
805 public void mouseOverSequence(SequenceI sequence, int index, int pos)
807 String tmp = sequence.hashCode() + " " + index + " " + pos;
809 if (lastMessage == null || !lastMessage.equals(tmp))
811 // System.err.println("mouseOver Sequence: "+tmp);
812 ssm.mouseOverSequence(sequence, index, pos, av);
818 * Highlight the mapped region described by the search results object (unless
819 * unchanged). This supports highlight of protein while mousing over linked
820 * cDNA and vice versa. The status bar is also updated to show the location of
821 * the start of the highlighted region.
824 public void highlightSequence(SearchResultsI results)
826 if (results == null || results.equals(lastSearchResults))
830 lastSearchResults = results;
832 boolean wasScrolled = false;
834 if (av.isFollowHighlight())
836 // don't allow highlight of protein/cDNA to also scroll a complementary
837 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
838 // over residue to change abruptly, causing highlighted residue in panel 2
839 // to change, causing a scroll in panel 1 etc)
840 ap.setToScrollComplementPanel(false);
841 wasScrolled = ap.scrollToPosition(results, false);
844 seqCanvas.revalidate();
846 ap.setToScrollComplementPanel(true);
849 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
850 if (seqCanvas.highlightSearchResults(results, noFastPaint))
852 setStatusMessage(results);
857 public VamsasSource getVamsasSource()
859 return this.ap == null ? null : this.ap.av;
863 public void updateColours(SequenceI seq, int index)
865 System.out.println("update the seqPanel colours");
870 * Action on mouse movement is to update the status bar to show the current
871 * sequence position, and (if features are shown) to show any features at the
872 * position in a tooltip. Does nothing if the mouse move does not change
878 public void mouseMoved(MouseEvent evt)
882 // This is because MacOSX creates a mouseMoved
883 // If control is down, other platforms will not.
887 final MousePos mousePos = findMousePosition(evt);
888 if (mousePos.equals(lastMousePosition))
891 * just a pixel move without change of 'cell'
895 lastMousePosition = mousePos;
897 if (mousePos.isOverAnnotation())
899 mouseMovedOverAnnotation(mousePos);
902 final int seq = mousePos.seqIndex;
904 final int column = mousePos.column;
905 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
907 lastMousePosition = null;
908 setToolTipText(null);
909 ap.alignFrame.statusBar.setText("");
913 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
915 if (column >= sequence.getLength())
921 * set status bar message, returning residue position in sequence
923 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
924 final int pos = setStatusMessage(sequence, column, seq);
925 if (ssm != null && !isGapped)
927 mouseOverSequence(sequence, column, pos);
930 tooltipText.setLength(6); // Cuts the buffer back to <html>
932 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
935 for (int g = 0; g < groups.length; g++)
937 if (groups[g].getStartRes() <= column
938 && groups[g].getEndRes() >= column)
940 if (!groups[g].getName().startsWith("JTreeGroup")
941 && !groups[g].getName().startsWith("JGroup"))
943 tooltipText.append(groups[g].getName());
946 if (groups[g].getDescription() != null)
948 tooltipText.append(": " + groups[g].getDescription());
955 * add any features at the position to the tooltip; if over a gap, only
956 * add features that straddle the gap (pos may be the residue before or
959 if (av.isShowSequenceFeatures())
961 List<SequenceFeature> features = ap.getFeatureRenderer()
962 .findFeaturesAtColumn(sequence, column + 1);
963 seqARep.appendFeatures(tooltipText, pos, features,
964 this.ap.getSeqPanel().seqCanvas.fr);
966 if (tooltipText.length() == 6) // <html>
968 setToolTipText(null);
973 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
975 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
976 tooltipText.append("...");
978 String textString = tooltipText.toString();
979 if (lastTooltip == null || !lastTooltip.equals(textString))
981 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
983 setToolTipText(formattedTooltipText);
984 lastTooltip = textString;
990 * When the view is in wrapped mode, and the mouse is over an annotation row,
991 * shows the corresponding tooltip and status message (if any)
996 protected void mouseMovedOverAnnotation(MousePos pos)
998 final int column = pos.column;
999 final int rowIndex = pos.annotationIndex;
1001 if (!av.getWrapAlignment() || !av.isShowAnnotation() || rowIndex < 0)
1005 AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
1007 String tooltip = AnnotationPanel.buildToolTip(anns[rowIndex], column,
1009 setToolTipText(tooltip);
1010 lastTooltip = tooltip;
1012 String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
1014 ap.alignFrame.statusBar.setText(msg);
1017 private Point lastp = null;
1022 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
1025 public Point getToolTipLocation(MouseEvent event)
1027 int x = event.getX(), w = getWidth();
1028 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
1031 if (!event.isShiftDown() || p == null)
1033 p = (tooltipText != null && tooltipText.length() > 6)
1034 ? new Point(event.getX() + wdth, event.getY() - 20)
1038 * TODO: try to modify position region is not obcured by tooltip
1046 * set when the current UI interaction has resulted in a change that requires
1047 * shading in overviews and structures to be recalculated. this could be
1048 * changed to a something more expressive that indicates what actually has
1049 * changed, so selective redraws can be applied (ie. only structures, only
1052 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1055 * set if av.getSelectionGroup() refers to a group that is defined on the
1056 * alignment view, rather than a transient selection
1058 // private boolean editingDefinedGroup = false; // TODO: refactor to
1059 // avcontroller or viewModel
1062 * Sets the status message in alignment panel, showing the sequence number
1063 * (index) and id, and residue and residue position if not at a gap, for the
1064 * given sequence and column position. Returns the residue position returned
1065 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1066 * if at a gapped position.
1069 * aligned sequence object
1073 * index of sequence in alignment
1074 * @return sequence position of residue at column, or adjacent residue if at a
1077 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1079 char sequenceChar = sequence.getCharAt(column);
1080 int pos = sequence.findPosition(column);
1081 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1087 * Builds the status message for the current cursor location and writes it to
1088 * the status bar, for example
1091 * Sequence 3 ID: FER1_SOLLC
1092 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1093 * Sequence 5 ID: FER1_PEA Residue: B (3)
1094 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1099 * sequence position in the alignment (1..)
1100 * @param sequenceChar
1101 * the character under the cursor
1103 * the sequence residue position (if not over a gap)
1105 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1106 char sequenceChar, int residuePos)
1108 StringBuilder text = new StringBuilder(32);
1111 * Sequence number (if known), and sequence name.
1113 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1114 text.append("Sequence").append(seqno).append(" ID: ")
1115 .append(sequence.getName());
1117 String residue = null;
1120 * Try to translate the display character to residue name (null for gap).
1122 boolean isGapped = Comparison.isGap(sequenceChar);
1126 boolean nucleotide = av.getAlignment().isNucleotide();
1127 String displayChar = String.valueOf(sequenceChar);
1130 residue = ResidueProperties.nucleotideName.get(displayChar);
1134 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1135 : ("*".equals(displayChar) ? "STOP"
1136 : ResidueProperties.aa2Triplet.get(displayChar));
1138 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1139 .append(": ").append(residue == null ? displayChar : residue);
1141 text.append(" (").append(Integer.toString(residuePos)).append(")");
1143 ap.alignFrame.statusBar.setText(text.toString());
1147 * Set the status bar message to highlight the first matched position in
1152 private void setStatusMessage(SearchResultsI results)
1154 AlignmentI al = this.av.getAlignment();
1155 int sequenceIndex = al.findIndex(results);
1156 if (sequenceIndex == -1)
1160 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1161 for (SearchResultMatchI m : results.getResults())
1163 SequenceI seq = m.getSequence();
1164 if (seq.getDatasetSequence() != null)
1166 seq = seq.getDatasetSequence();
1171 int start = m.getStart();
1172 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1183 public void mouseDragged(MouseEvent evt)
1185 MousePos pos = findMousePosition(evt);
1186 if (pos.isOverAnnotation())
1188 // mouse is over annotation row in wrapped mode
1192 if (mouseWheelPressed)
1194 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1195 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1197 int oldWidth = av.getCharWidth();
1199 // Which is bigger, left-right or up-down?
1200 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1201 .abs(evt.getX() - lastMousePress.getX()))
1204 * on drag up or down, decrement or increment font size
1206 int fontSize = av.font.getSize();
1207 boolean fontChanged = false;
1209 if (evt.getY() < lastMousePress.getY())
1214 else if (evt.getY() > lastMousePress.getY())
1227 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1229 av.setFont(newFont, true);
1230 av.setCharWidth(oldWidth);
1234 ap.av.getCodingComplement().setFont(newFont, true);
1235 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1236 .getSplitViewContainer();
1237 splitFrame.adjustLayout();
1238 splitFrame.repaint();
1245 * on drag left or right, decrement or increment character width
1248 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1250 newWidth = av.getCharWidth() - 1;
1251 av.setCharWidth(newWidth);
1253 else if (evt.getX() > lastMousePress.getX())
1255 newWidth = av.getCharWidth() + 1;
1256 av.setCharWidth(newWidth);
1260 ap.paintAlignment(false, false);
1264 * need to ensure newWidth is set on cdna, regardless of which
1265 * panel the mouse drag happened in; protein will compute its
1266 * character width as 1:1 or 3:1
1268 av.getCodingComplement().setCharWidth(newWidth);
1269 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1270 .getSplitViewContainer();
1271 splitFrame.adjustLayout();
1272 splitFrame.repaint();
1277 FontMetrics fm = getFontMetrics(av.getFont());
1278 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1280 lastMousePress = evt.getPoint();
1287 doMouseDraggedDefineMode(evt);
1291 int res = pos.column;
1298 if ((lastres == -1) || (lastres == res))
1303 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1305 // dragLeft, delete gap
1306 editSequence(false, false, res);
1310 editSequence(true, false, res);
1313 mouseDragging = true;
1314 if ((scrollThread != null) && (scrollThread.isRunning()))
1316 scrollThread.setEvent(evt);
1320 // TODO: Make it more clever than many booleans
1321 synchronized void editSequence(boolean insertGap, boolean editSeq,
1325 int fixedRight = -1;
1326 boolean fixedColumns = false;
1327 SequenceGroup sg = av.getSelectionGroup();
1329 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1331 // No group, but the sequence may represent a group
1332 if (!groupEditing && av.hasHiddenRows())
1334 if (av.isHiddenRepSequence(seq))
1336 sg = av.getRepresentedSequences(seq);
1337 groupEditing = true;
1341 StringBuilder message = new StringBuilder(64);
1344 message.append("Edit group:");
1345 if (editCommand == null)
1347 editCommand = new EditCommand(
1348 MessageManager.getString("action.edit_group"));
1353 message.append("Edit sequence: " + seq.getName());
1354 String label = seq.getName();
1355 if (label.length() > 10)
1357 label = label.substring(0, 10);
1359 if (editCommand == null)
1361 editCommand = new EditCommand(MessageManager
1362 .formatMessage("label.edit_params", new String[]
1369 message.append(" insert ");
1373 message.append(" delete ");
1376 message.append(Math.abs(startres - lastres) + " gaps.");
1377 ap.alignFrame.statusBar.setText(message.toString());
1379 // Are we editing within a selection group?
1380 if (groupEditing || (sg != null
1381 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1383 fixedColumns = true;
1385 // sg might be null as the user may only see 1 sequence,
1386 // but the sequence represents a group
1389 if (!av.isHiddenRepSequence(seq))
1394 sg = av.getRepresentedSequences(seq);
1397 fixedLeft = sg.getStartRes();
1398 fixedRight = sg.getEndRes();
1400 if ((startres < fixedLeft && lastres >= fixedLeft)
1401 || (startres >= fixedLeft && lastres < fixedLeft)
1402 || (startres > fixedRight && lastres <= fixedRight)
1403 || (startres <= fixedRight && lastres > fixedRight))
1409 if (fixedLeft > startres)
1411 fixedRight = fixedLeft - 1;
1414 else if (fixedRight < startres)
1416 fixedLeft = fixedRight;
1421 if (av.hasHiddenColumns())
1423 fixedColumns = true;
1424 int y1 = av.getAlignment().getHiddenColumns()
1425 .getNextHiddenBoundary(true, startres);
1426 int y2 = av.getAlignment().getHiddenColumns()
1427 .getNextHiddenBoundary(false, startres);
1429 if ((insertGap && startres > y1 && lastres < y1)
1430 || (!insertGap && startres < y2 && lastres > y2))
1436 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1437 // Selection spans a hidden region
1438 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1446 fixedRight = y2 - 1;
1453 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1454 int g, groupSize = vseqs.size();
1455 SequenceI[] groupSeqs = new SequenceI[groupSize];
1456 for (g = 0; g < groupSeqs.length; g++)
1458 groupSeqs[g] = vseqs.get(g);
1464 // If the user has selected the whole sequence, and is dragging to
1465 // the right, we can still extend the alignment and selectionGroup
1466 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1467 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1469 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1470 fixedRight = sg.getEndRes();
1473 // Is it valid with fixed columns??
1474 // Find the next gap before the end
1475 // of the visible region boundary
1476 boolean blank = false;
1477 for (; fixedRight > lastres; fixedRight--)
1481 for (g = 0; g < groupSize; g++)
1483 for (int j = 0; j < startres - lastres; j++)
1485 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1500 if (sg.getSize() == av.getAlignment().getHeight())
1502 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1504 .getNextHiddenBoundary(false, startres)))
1510 int alWidth = av.getAlignment().getWidth();
1511 if (av.hasHiddenRows())
1513 int hwidth = av.getAlignment().getHiddenSequences()
1515 if (hwidth > alWidth)
1520 // We can still insert gaps if the selectionGroup
1521 // contains all the sequences
1522 sg.setEndRes(sg.getEndRes() + startres - lastres);
1523 fixedRight = alWidth + startres - lastres;
1534 else if (!insertGap)
1536 // / Are we able to delete?
1537 // ie are all columns blank?
1539 for (g = 0; g < groupSize; g++)
1541 for (int j = startres; j < lastres; j++)
1543 if (groupSeqs[g].getLength() <= j)
1548 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1550 // Not a gap, block edit not valid
1560 // dragging to the right
1561 if (fixedColumns && fixedRight != -1)
1563 for (int j = lastres; j < startres; j++)
1565 insertChar(j, groupSeqs, fixedRight);
1570 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1571 startres - lastres);
1576 // dragging to the left
1577 if (fixedColumns && fixedRight != -1)
1579 for (int j = lastres; j > startres; j--)
1581 deleteChar(startres, groupSeqs, fixedRight);
1586 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1587 lastres - startres);
1593 // ///Editing a single sequence///////////
1597 // dragging to the right
1598 if (fixedColumns && fixedRight != -1)
1600 for (int j = lastres; j < startres; j++)
1602 insertChar(j, new SequenceI[] { seq }, fixedRight);
1607 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1608 startres - lastres);
1615 // dragging to the left
1616 if (fixedColumns && fixedRight != -1)
1618 for (int j = lastres; j > startres; j--)
1620 if (!Comparison.isGap(seq.getCharAt(startres)))
1625 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1630 // could be a keyboard edit trying to delete none gaps
1632 for (int m = startres; m < lastres; m++)
1634 if (!Comparison.isGap(seq.getCharAt(m)))
1643 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1649 {// insertGap==false AND editSeq==TRUE;
1650 if (fixedColumns && fixedRight != -1)
1652 for (int j = lastres; j < startres; j++)
1654 insertChar(j, new SequenceI[] { seq }, fixedRight);
1659 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1660 startres - lastres);
1667 seqCanvas.repaint();
1670 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1672 int blankColumn = fixedColumn;
1673 for (int s = 0; s < seq.length; s++)
1675 // Find the next gap before the end of the visible region boundary
1676 // If lastCol > j, theres a boundary after the gap insertion
1678 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1680 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1682 // Theres a space, so break and insert the gap
1687 if (blankColumn <= j)
1689 blankColumn = fixedColumn;
1695 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1697 appendEdit(Action.INSERT_GAP, seq, j, 1);
1702 * Helper method to add and perform one edit action.
1709 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1713 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1714 av.getAlignment().getGapCharacter());
1716 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1719 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1722 appendEdit(Action.DELETE_GAP, seq, j, 1);
1724 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1734 public void mouseEntered(MouseEvent e)
1741 if ((scrollThread != null) && (scrollThread.isRunning()))
1743 scrollThread.stopScrolling();
1744 scrollThread = null;
1755 public void mouseExited(MouseEvent e)
1757 if (av.getWrapAlignment())
1762 if (mouseDragging && scrollThread == null)
1764 scrollThread = new ScrollThread();
1769 * Handler for double-click on a position with one or more sequence features.
1770 * Opens the Amend Features dialog to allow feature details to be amended, or
1771 * the feature deleted.
1774 public void mouseClicked(MouseEvent evt)
1776 SequenceGroup sg = null;
1777 MousePos pos = findMousePosition(evt);
1778 if (pos.isOverAnnotation())
1780 // mouse is over annotation label in wrapped mode
1784 if (evt.getClickCount() > 1)
1786 sg = av.getSelectionGroup();
1787 if (sg != null && sg.getSize() == 1
1788 && sg.getEndRes() - sg.getStartRes() < 2)
1790 av.setSelectionGroup(null);
1793 int column = pos.column;
1796 * find features at the position (if not gapped), or straddling
1797 * the position (if at a gap)
1799 SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);// findSeq(evt));
1800 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1801 .findFeaturesAtColumn(sequence, column + 1);
1803 if (!features.isEmpty())
1806 * highlight the first feature at the position on the alignment
1808 SearchResultsI highlight = new SearchResults();
1809 highlight.addResult(sequence, features.get(0).getBegin(), features
1811 seqCanvas.highlightSearchResults(highlight, false);
1814 * open the Amend Features dialog; clear highlighting afterwards,
1815 * whether changes were made or not
1817 List<SequenceI> seqs = Collections.singletonList(sequence);
1818 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1820 av.setSearchResults(null); // clear highlighting
1821 seqCanvas.repaint(); // draw new/amended features
1827 public void mouseWheelMoved(MouseWheelEvent e)
1830 double wheelRotation = e.getPreciseWheelRotation();
1831 if (wheelRotation > 0)
1833 if (e.isShiftDown())
1835 av.getRanges().scrollRight(true);
1840 av.getRanges().scrollUp(false);
1843 else if (wheelRotation < 0)
1845 if (e.isShiftDown())
1847 av.getRanges().scrollRight(false);
1851 av.getRanges().scrollUp(true);
1856 * update status bar and tooltip for new position
1857 * (need to synthesize a mouse movement to refresh tooltip)
1860 ToolTipManager.sharedInstance().mouseMoved(e);
1869 protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
1871 if (pos.isOverAnnotation())
1873 // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1874 // MessageManager.getString(
1875 // "label.cannot_edit_annotations_in_wrapped_view"),
1876 // MessageManager.getString("label.wrapped_view_no_edit"),
1877 // JvOptionPane.WARNING_MESSAGE);
1881 final int res = pos.column;
1882 final int seq = pos.seqIndex;
1884 updateOverviewAndStructs = false;
1886 startWrapBlock = wrappedBlock;
1888 if (seq < 0 || res < 0)
1893 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1895 if ((sequence == null) || (res > sequence.getLength()))
1900 stretchGroup = av.getSelectionGroup();
1902 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1904 stretchGroup = av.getAlignment().findGroup(sequence, res);
1905 if (stretchGroup != null)
1907 // only update the current selection if the popup menu has a group to
1909 av.setSelectionGroup(stretchGroup);
1913 if (evt.isPopupTrigger()) // Mac: mousePressed
1915 showPopupMenu(evt, pos);
1920 * defer right-mouse click handling to mouseReleased on Windows
1921 * (where isPopupTrigger() will answer true)
1922 * NB isRightMouseButton is also true for Cmd-click on Mac
1924 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1931 seqCanvas.cursorX = res;
1932 seqCanvas.cursorY = seq;
1933 seqCanvas.repaint();
1937 if (stretchGroup == null)
1939 createStretchGroup(res, sequence);
1942 if (stretchGroup != null)
1944 stretchGroup.addPropertyChangeListener(seqCanvas);
1947 seqCanvas.repaint();
1950 private void createStretchGroup(int res, SequenceI sequence)
1952 // Only if left mouse button do we want to change group sizes
1953 // define a new group here
1954 SequenceGroup sg = new SequenceGroup();
1955 sg.setStartRes(res);
1957 sg.addSequence(sequence, false);
1958 av.setSelectionGroup(sg);
1961 if (av.getConservationSelected())
1963 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1967 if (av.getAbovePIDThreshold())
1969 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1972 // TODO: stretchGroup will always be not null. Is this a merge error ?
1973 // or is there a threading issue here?
1974 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1976 // Edit end res position of selected group
1977 changeEndRes = true;
1979 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1981 // Edit end res position of selected group
1982 changeStartRes = true;
1984 stretchGroup.getWidth();
1989 * Build and show a pop-up menu at the right-click mouse position
1994 void showPopupMenu(MouseEvent evt, MousePos pos)
1996 final int column = pos.column;
1997 final int seq = pos.seqIndex;
1998 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1999 List<SequenceFeature> features = ap.getFeatureRenderer()
2000 .findFeaturesAtColumn(sequence, column + 1);
2002 PopupMenu pop = new PopupMenu(ap, null, features);
2003 pop.show(this, evt.getX(), evt.getY());
2007 * Update the display after mouse up on a selection or group
2010 * mouse released event details
2012 * true if this event is happening after a mouse drag (rather than a
2015 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
2017 if (stretchGroup == null)
2022 stretchGroup.removePropertyChangeListener(seqCanvas);
2024 // always do this - annotation has own state
2025 // but defer colourscheme update until hidden sequences are passed in
2026 boolean vischange = stretchGroup.recalcConservation(true);
2027 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
2029 if (stretchGroup.cs != null)
2031 stretchGroup.cs.alignmentChanged(stretchGroup,
2032 av.getHiddenRepSequences());
2034 ResidueShaderI groupColourScheme = stretchGroup
2035 .getGroupColourScheme();
2036 String name = stretchGroup.getName();
2037 if (stretchGroup.cs.conservationApplied())
2039 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2041 if (stretchGroup.cs.getThreshold() > 0)
2043 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2046 PaintRefresher.Refresh(this, av.getSequenceSetId());
2047 // TODO: structure colours only need updating if stretchGroup used to or now
2048 // does contain sequences with structure views
2049 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2050 updateOverviewAndStructs = false;
2051 changeEndRes = false;
2052 changeStartRes = false;
2053 stretchGroup = null;
2063 public void doMouseDraggedDefineMode(MouseEvent evt)
2065 MousePos pos = findMousePosition(evt);
2066 if (pos.isOverAnnotation())
2068 // mouse is over annotation in wrapped mode
2072 int res = pos.column;
2073 int y = pos.seqIndex;
2075 if (wrappedBlock != startWrapBlock)
2080 if (stretchGroup == null)
2085 if (res >= av.getAlignment().getWidth())
2087 res = av.getAlignment().getWidth() - 1;
2090 if (stretchGroup.getEndRes() == res)
2092 // Edit end res position of selected group
2093 changeEndRes = true;
2095 else if (stretchGroup.getStartRes() == res)
2097 // Edit start res position of selected group
2098 changeStartRes = true;
2101 if (res < av.getRanges().getStartRes())
2103 res = av.getRanges().getStartRes();
2108 if (res > (stretchGroup.getStartRes() - 1))
2110 stretchGroup.setEndRes(res);
2111 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2114 else if (changeStartRes)
2116 if (res < (stretchGroup.getEndRes() + 1))
2118 stretchGroup.setStartRes(res);
2119 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2123 int dragDirection = 0;
2129 else if (y < oldSeq)
2134 while ((y != oldSeq) && (oldSeq > -1)
2135 && (y < av.getAlignment().getHeight()))
2137 // This routine ensures we don't skip any sequences, as the
2138 // selection is quite slow.
2139 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2141 oldSeq += dragDirection;
2148 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2150 if (stretchGroup.getSequences(null).contains(nextSeq))
2152 stretchGroup.deleteSequence(seq, false);
2153 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2159 stretchGroup.addSequence(seq, false);
2162 stretchGroup.addSequence(nextSeq, false);
2163 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2172 mouseDragging = true;
2174 if ((scrollThread != null) && (scrollThread.isRunning()))
2176 scrollThread.setEvent(evt);
2180 void scrollCanvas(MouseEvent evt)
2184 if ((scrollThread != null) && (scrollThread.isRunning()))
2186 scrollThread.stopScrolling();
2187 scrollThread = null;
2189 mouseDragging = false;
2193 if (scrollThread == null)
2195 scrollThread = new ScrollThread();
2198 mouseDragging = true;
2199 scrollThread.setEvent(evt);
2204 // this class allows scrolling off the bottom of the visible alignment
2205 class ScrollThread extends Thread
2209 private volatile boolean threadRunning = true;
2211 public ScrollThread()
2216 public void setEvent(MouseEvent e)
2221 public void stopScrolling()
2223 threadRunning = false;
2226 public boolean isRunning()
2228 return threadRunning;
2234 while (threadRunning)
2238 if (mouseDragging && (evt.getY() < 0)
2239 && (av.getRanges().getStartSeq() > 0))
2241 av.getRanges().scrollUp(true);
2244 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2245 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2247 av.getRanges().scrollUp(false);
2250 if (mouseDragging && (evt.getX() < 0))
2252 av.getRanges().scrollRight(false);
2254 else if (mouseDragging && (evt.getX() >= getWidth()))
2256 av.getRanges().scrollRight(true);
2263 } catch (Exception ex)
2271 * modify current selection according to a received message.
2274 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2275 HiddenColumns hidden, SelectionSource source)
2277 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2278 // handles selection messages...
2279 // TODO: extend config options to allow user to control if selections may be
2280 // shared between viewports.
2281 boolean iSentTheSelection = (av == source
2282 || (source instanceof AlignViewport
2283 && ((AlignmentViewport) source).getSequenceSetId()
2284 .equals(av.getSequenceSetId())));
2286 if (iSentTheSelection)
2288 // respond to our own event by updating dependent dialogs
2289 if (ap.getCalculationDialog() != null)
2291 ap.getCalculationDialog().validateCalcTypes();
2297 // process further ?
2298 if (!av.followSelection)
2304 * Ignore the selection if there is one of our own pending.
2306 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2312 * Check for selection in a view of which this one is a dna/protein
2315 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2320 // do we want to thread this ? (contention with seqsel and colsel locks, I
2323 * only copy colsel if there is a real intersection between
2324 * sequence selection and this panel's alignment
2326 boolean repaint = false;
2327 boolean copycolsel = false;
2329 SequenceGroup sgroup = null;
2330 if (seqsel != null && seqsel.getSize() > 0)
2332 if (av.getAlignment() == null)
2334 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2335 + " ViewId=" + av.getViewId()
2336 + " 's alignment is NULL! returning immediately.");
2339 sgroup = seqsel.intersect(av.getAlignment(),
2340 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2341 if ((sgroup != null && sgroup.getSize() > 0))
2346 if (sgroup != null && sgroup.getSize() > 0)
2348 av.setSelectionGroup(sgroup);
2352 av.setSelectionGroup(null);
2354 av.isSelectionGroupChanged(true);
2359 // the current selection is unset or from a previous message
2360 // so import the new colsel.
2361 if (colsel == null || colsel.isEmpty())
2363 if (av.getColumnSelection() != null)
2365 av.getColumnSelection().clear();
2371 // TODO: shift colSel according to the intersecting sequences
2372 if (av.getColumnSelection() == null)
2374 av.setColumnSelection(new ColumnSelection(colsel));
2378 av.getColumnSelection().setElementsFrom(colsel,
2379 av.getAlignment().getHiddenColumns());
2382 av.isColSelChanged(true);
2386 if (copycolsel && av.hasHiddenColumns()
2387 && (av.getAlignment().getHiddenColumns() == null))
2389 System.err.println("Bad things");
2391 if (repaint) // always true!
2393 // probably finessing with multiple redraws here
2394 PaintRefresher.Refresh(this, av.getSequenceSetId());
2395 // ap.paintAlignment(false);
2398 // lastly, update dependent dialogs
2399 if (ap.getCalculationDialog() != null)
2401 ap.getCalculationDialog().validateCalcTypes();
2407 * If this panel is a cdna/protein translation view of the selection source,
2408 * tries to map the source selection to a local one, and returns true. Else
2415 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2416 ColumnSelection colsel, HiddenColumns hidden,
2417 SelectionSource source)
2419 if (!(source instanceof AlignViewportI))
2423 final AlignViewportI sourceAv = (AlignViewportI) source;
2424 if (sourceAv.getCodingComplement() != av
2425 && av.getCodingComplement() != sourceAv)
2431 * Map sequence selection
2433 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2434 av.setSelectionGroup(sg);
2435 av.isSelectionGroupChanged(true);
2438 * Map column selection
2440 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2442 ColumnSelection cs = new ColumnSelection();
2443 HiddenColumns hs = new HiddenColumns();
2444 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2445 av.setColumnSelection(cs);
2446 av.getAlignment().setHiddenColumns(hs);
2448 // lastly, update any dependent dialogs
2449 if (ap.getCalculationDialog() != null)
2451 ap.getCalculationDialog().validateCalcTypes();
2454 PaintRefresher.Refresh(this, av.getSequenceSetId());
2461 * @return null or last search results handled by this panel
2463 public SearchResultsI getLastSearchResults()
2465 return lastSearchResults;