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.AlignmentI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.HiddenColumns;
31 import jalview.datamodel.SearchResultMatchI;
32 import jalview.datamodel.SearchResults;
33 import jalview.datamodel.SearchResultsI;
34 import jalview.datamodel.Sequence;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.io.SequenceAnnotationReport;
39 import jalview.renderer.ResidueShaderI;
40 import jalview.schemes.ResidueProperties;
41 import jalview.structure.SelectionListener;
42 import jalview.structure.SelectionSource;
43 import jalview.structure.SequenceListener;
44 import jalview.structure.StructureSelectionManager;
45 import jalview.structure.VamsasSource;
46 import jalview.util.Comparison;
47 import jalview.util.MappingUtils;
48 import jalview.util.MessageManager;
49 import jalview.util.Platform;
50 import jalview.viewmodel.AlignmentViewport;
52 import java.awt.BorderLayout;
53 import java.awt.Color;
55 import java.awt.FontMetrics;
56 import java.awt.Point;
57 import java.awt.event.MouseEvent;
58 import java.awt.event.MouseListener;
59 import java.awt.event.MouseMotionListener;
60 import java.awt.event.MouseWheelEvent;
61 import java.awt.event.MouseWheelListener;
62 import java.util.Collections;
63 import java.util.List;
65 import javax.swing.JPanel;
66 import javax.swing.SwingUtilities;
67 import javax.swing.ToolTipManager;
73 * @version $Revision: 1.130 $
75 public class SeqPanel extends JPanel
76 implements MouseListener, MouseMotionListener, MouseWheelListener,
77 SequenceListener, SelectionListener
79 private static final int MAX_TOOLTIP_LENGTH = 300;
81 public SeqCanvas seqCanvas;
83 public AlignmentPanel ap;
86 * last column position for mouseMoved event
88 private int lastMouseColumn;
91 * last sequence offset for mouseMoved event
93 private int lastMouseSeq;
95 protected int lastres;
97 protected int startseq;
99 protected AlignViewport av;
101 ScrollThread scrollThread = null;
103 boolean mouseDragging = false;
105 boolean editingSeqs = false;
107 boolean groupEditing = false;
109 // ////////////////////////////////////////
110 // ///Everything below this is for defining the boundary of the rubberband
111 // ////////////////////////////////////////
114 boolean changeEndSeq = false;
116 boolean changeStartSeq = false;
118 boolean changeEndRes = false;
120 boolean changeStartRes = false;
122 SequenceGroup stretchGroup = null;
124 boolean remove = false;
126 Point lastMousePress;
128 boolean mouseWheelPressed = false;
130 StringBuffer keyboardNo1;
132 StringBuffer keyboardNo2;
134 java.net.URL linkImageURL;
136 private final SequenceAnnotationReport seqARep;
138 StringBuilder tooltipText = new StringBuilder();
142 EditCommand editCommand;
144 StructureSelectionManager ssm;
146 SearchResultsI lastSearchResults;
149 * Creates a new SeqPanel object
154 public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
156 linkImageURL = getClass().getResource("/images/link.gif");
157 seqARep = new SequenceAnnotationReport(linkImageURL.toString());
158 ToolTipManager.sharedInstance().registerComponent(this);
159 ToolTipManager.sharedInstance().setInitialDelay(0);
160 ToolTipManager.sharedInstance().setDismissDelay(10000);
162 setBackground(Color.white);
164 seqCanvas = new SeqCanvas(alignPanel);
165 setLayout(new BorderLayout());
166 add(seqCanvas, BorderLayout.CENTER);
168 this.ap = alignPanel;
170 if (!viewport.isDataset())
172 addMouseMotionListener(this);
173 addMouseListener(this);
174 addMouseWheelListener(this);
175 ssm = viewport.getStructureSelectionManager();
176 ssm.addStructureViewerListener(this);
177 ssm.addSelectionListener(this);
180 lastMouseColumn = -1;
184 int startWrapBlock = -1;
186 int wrappedBlock = -1;
189 * Returns the aligned sequence position (base 0) at the mouse position, or
190 * the closest visible one
195 int findColumn(MouseEvent evt)
200 int startRes = av.getRanges().getStartRes();
201 if (av.getWrapAlignment())
204 int hgap = av.getCharHeight();
205 if (av.getScaleAboveWrapped())
207 hgap += av.getCharHeight();
210 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
211 + hgap + seqCanvas.getAnnotationHeight();
214 y = Math.max(0, y - hgap);
215 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
217 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
223 wrappedBlock = y / cHeight;
224 wrappedBlock += startRes / cwidth;
225 // allow for wrapped view scrolled right (possible from Overview)
226 int startOffset = startRes % cwidth;
227 res = wrappedBlock * cwidth + startOffset
228 + +Math.min(cwidth - 1, x / av.getCharWidth());
232 if (x > seqCanvas.getX() + seqCanvas.getWidth())
234 // make sure we calculate relative to visible alignment, rather than
236 x = seqCanvas.getX() + seqCanvas.getWidth();
238 res = (x / av.getCharWidth()) + startRes;
239 if (res > av.getRanges().getEndRes())
242 res = av.getRanges().getEndRes();
246 if (av.hasHiddenColumns())
248 res = av.getAlignment().getHiddenColumns()
249 .visibleToAbsoluteColumn(res);
256 int findSeq(MouseEvent evt)
261 if (av.getWrapAlignment())
263 int hgap = av.getCharHeight();
264 if (av.getScaleAboveWrapped())
266 hgap += av.getCharHeight();
269 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
270 + hgap + seqCanvas.getAnnotationHeight();
274 seq = Math.min((y % cHeight) / av.getCharHeight(),
275 av.getAlignment().getHeight() - 1);
280 (y / av.getCharHeight()) + av.getRanges().getStartSeq(),
281 av.getAlignment().getHeight() - 1);
288 * When all of a sequence of edits are complete, put the resulting edit list
289 * on the history stack (undo list), and reset flags for editing in progress.
295 if (editCommand != null && editCommand.getSize() > 0)
297 ap.alignFrame.addHistoryItem(editCommand);
298 av.firePropertyChange("alignment", null,
299 av.getAlignment().getSequences());
304 * Tidy up come what may...
309 groupEditing = false;
318 seqCanvas.cursorY = getKeyboardNo1() - 1;
319 scrollToVisible(true);
322 void setCursorColumn()
324 seqCanvas.cursorX = getKeyboardNo1() - 1;
325 scrollToVisible(true);
328 void setCursorRowAndColumn()
330 if (keyboardNo2 == null)
332 keyboardNo2 = new StringBuffer();
336 seqCanvas.cursorX = getKeyboardNo1() - 1;
337 seqCanvas.cursorY = getKeyboardNo2() - 1;
338 scrollToVisible(true);
342 void setCursorPosition()
344 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
346 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
347 scrollToVisible(true);
350 void moveCursor(int dx, int dy)
352 seqCanvas.cursorX += dx;
353 seqCanvas.cursorY += dy;
355 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
357 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
359 int original = seqCanvas.cursorX - dx;
360 int maxWidth = av.getAlignment().getWidth();
362 if (!hidden.isVisible(seqCanvas.cursorX))
364 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
365 int[] region = hidden.getRegionWithEdgeAtRes(visx);
367 if (region != null) // just in case
372 seqCanvas.cursorX = region[1] + 1;
377 seqCanvas.cursorX = region[0] - 1;
380 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
383 if (seqCanvas.cursorX >= maxWidth
384 || !hidden.isVisible(seqCanvas.cursorX))
386 seqCanvas.cursorX = original;
390 scrollToVisible(false);
394 * Scroll to make the cursor visible in the viewport.
397 * just jump to the location rather than scrolling
399 void scrollToVisible(boolean jump)
401 if (seqCanvas.cursorX < 0)
403 seqCanvas.cursorX = 0;
405 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
407 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
410 if (seqCanvas.cursorY < 0)
412 seqCanvas.cursorY = 0;
414 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
416 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
421 boolean repaintNeeded = true;
424 // only need to repaint if the viewport did not move, as otherwise it will
426 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
431 if (av.getWrapAlignment())
433 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
434 int x = av.getAlignment().getHiddenColumns()
435 .absoluteToVisibleColumn(seqCanvas.cursorX);
436 av.getRanges().scrollToWrappedVisible(x);
440 av.getRanges().scrollToVisible(seqCanvas.cursorX,
445 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
447 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
448 seqCanvas.cursorX, seqCanvas.cursorY);
458 void setSelectionAreaAtCursor(boolean topLeft)
460 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
462 if (av.getSelectionGroup() != null)
464 SequenceGroup sg = av.getSelectionGroup();
465 // Find the top and bottom of this group
466 int min = av.getAlignment().getHeight(), max = 0;
467 for (int i = 0; i < sg.getSize(); i++)
469 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
484 sg.setStartRes(seqCanvas.cursorX);
485 if (sg.getEndRes() < seqCanvas.cursorX)
487 sg.setEndRes(seqCanvas.cursorX);
490 min = seqCanvas.cursorY;
494 sg.setEndRes(seqCanvas.cursorX);
495 if (sg.getStartRes() > seqCanvas.cursorX)
497 sg.setStartRes(seqCanvas.cursorX);
500 max = seqCanvas.cursorY + 1;
505 // Only the user can do this
506 av.setSelectionGroup(null);
510 // Now add any sequences between min and max
511 sg.getSequences(null).clear();
512 for (int i = min; i < max; i++)
514 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
519 if (av.getSelectionGroup() == null)
521 SequenceGroup sg = new SequenceGroup();
522 sg.setStartRes(seqCanvas.cursorX);
523 sg.setEndRes(seqCanvas.cursorX);
524 sg.addSequence(sequence, false);
525 av.setSelectionGroup(sg);
528 ap.paintAlignment(false, false);
532 void insertGapAtCursor(boolean group)
534 groupEditing = group;
535 startseq = seqCanvas.cursorY;
536 lastres = seqCanvas.cursorX;
537 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
541 void deleteGapAtCursor(boolean group)
543 groupEditing = group;
544 startseq = seqCanvas.cursorY;
545 lastres = seqCanvas.cursorX + getKeyboardNo1();
546 editSequence(false, false, seqCanvas.cursorX);
550 void insertNucAtCursor(boolean group, String nuc)
552 // TODO not called - delete?
553 groupEditing = group;
554 startseq = seqCanvas.cursorY;
555 lastres = seqCanvas.cursorX;
556 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
560 void numberPressed(char value)
562 if (keyboardNo1 == null)
564 keyboardNo1 = new StringBuffer();
567 if (keyboardNo2 != null)
569 keyboardNo2.append(value);
573 keyboardNo1.append(value);
581 if (keyboardNo1 != null)
583 int value = Integer.parseInt(keyboardNo1.toString());
587 } catch (Exception x)
598 if (keyboardNo2 != null)
600 int value = Integer.parseInt(keyboardNo2.toString());
604 } catch (Exception x)
618 public void mouseReleased(MouseEvent evt)
620 boolean didDrag = mouseDragging; // did we come here after a drag
621 mouseDragging = false;
622 mouseWheelPressed = false;
624 if (evt.isPopupTrigger()) // Windows: mouseReleased
633 doMouseReleasedDefineMode(evt, didDrag);
647 public void mousePressed(MouseEvent evt)
649 lastMousePress = evt.getPoint();
651 if (SwingUtilities.isMiddleMouseButton(evt))
653 mouseWheelPressed = true;
657 boolean isControlDown = Platform.isControlDown(evt);
658 if (evt.isShiftDown() || isControlDown)
668 doMousePressedDefineMode(evt);
672 int seq = findSeq(evt);
673 int res = findColumn(evt);
675 if (seq < 0 || res < 0)
680 if ((seq < av.getAlignment().getHeight())
681 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
698 public void mouseOverSequence(SequenceI sequence, int index, int pos)
700 String tmp = sequence.hashCode() + " " + index + " " + pos;
702 if (lastMessage == null || !lastMessage.equals(tmp))
704 // System.err.println("mouseOver Sequence: "+tmp);
705 ssm.mouseOverSequence(sequence, index, pos, av);
711 * Highlight the mapped region described by the search results object (unless
712 * unchanged). This supports highlight of protein while mousing over linked
713 * cDNA and vice versa. The status bar is also updated to show the location of
714 * the start of the highlighted region.
717 public void highlightSequence(SearchResultsI results)
719 if (results == null || results.equals(lastSearchResults))
723 lastSearchResults = results;
725 boolean wasScrolled = false;
727 if (av.isFollowHighlight())
729 // don't allow highlight of protein/cDNA to also scroll a complementary
730 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
731 // over residue to change abruptly, causing highlighted residue in panel 2
732 // to change, causing a scroll in panel 1 etc)
733 ap.setToScrollComplementPanel(false);
734 wasScrolled = ap.scrollToPosition(results, false);
737 seqCanvas.revalidate();
739 ap.setToScrollComplementPanel(true);
742 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
743 if (seqCanvas.highlightSearchResults(results, noFastPaint))
745 setStatusMessage(results);
750 public VamsasSource getVamsasSource()
752 return this.ap == null ? null : this.ap.av;
756 public void updateColours(SequenceI seq, int index)
758 System.out.println("update the seqPanel colours");
763 * Action on mouse movement is to update the status bar to show the current
764 * sequence position, and (if features are shown) to show any features at the
765 * position in a tooltip. Does nothing if the mouse move does not change
771 public void mouseMoved(MouseEvent evt)
775 // This is because MacOSX creates a mouseMoved
776 // If control is down, other platforms will not.
780 final int column = findColumn(evt);
781 final int seq = findSeq(evt);
783 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
788 if (column == lastMouseColumn && seq == lastMouseSeq)
791 * just a pixel move without change of residue
795 lastMouseColumn = column;
798 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
800 if (column >= sequence.getLength())
806 * set status bar message, returning residue position in sequence
808 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
809 final int pos = setStatusMessage(sequence, column, seq);
810 if (ssm != null && !isGapped)
812 mouseOverSequence(sequence, column, pos);
815 tooltipText.setLength(6); // Cuts the buffer back to <html>
817 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
820 for (int g = 0; g < groups.length; g++)
822 if (groups[g].getStartRes() <= column
823 && groups[g].getEndRes() >= column)
825 if (!groups[g].getName().startsWith("JTreeGroup")
826 && !groups[g].getName().startsWith("JGroup"))
828 tooltipText.append(groups[g].getName());
831 if (groups[g].getDescription() != null)
833 tooltipText.append(": " + groups[g].getDescription());
840 * add any features at the position to the tooltip; if over a gap, only
841 * add features that straddle the gap (pos may be the residue before or
844 if (av.isShowSequenceFeatures())
846 List<SequenceFeature> features = ap.getFeatureRenderer()
847 .findFeaturesAtColumn(sequence, column + 1);
848 seqARep.appendFeatures(tooltipText, pos, features,
849 this.ap.getSeqPanel().seqCanvas.fr);
851 if (tooltipText.length() == 6) // <html>
853 setToolTipText(null);
858 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
860 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
861 tooltipText.append("...");
863 String textString = tooltipText.toString();
864 if (lastTooltip == null || !lastTooltip.equals(textString))
866 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
868 setToolTipText(formattedTooltipText);
869 lastTooltip = textString;
874 private Point lastp = null;
879 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
882 public Point getToolTipLocation(MouseEvent event)
884 int x = event.getX(), w = getWidth();
885 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
888 if (!event.isShiftDown() || p == null)
890 p = (tooltipText != null && tooltipText.length() > 6)
891 ? new Point(event.getX() + wdth, event.getY() - 20)
895 * TODO: try to modify position region is not obcured by tooltip
903 * set when the current UI interaction has resulted in a change that requires
904 * shading in overviews and structures to be recalculated. this could be
905 * changed to a something more expressive that indicates what actually has
906 * changed, so selective redraws can be applied (ie. only structures, only
909 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
912 * set if av.getSelectionGroup() refers to a group that is defined on the
913 * alignment view, rather than a transient selection
915 // private boolean editingDefinedGroup = false; // TODO: refactor to
916 // avcontroller or viewModel
919 * Sets the status message in alignment panel, showing the sequence number
920 * (index) and id, and residue and residue position if not at a gap, for the
921 * given sequence and column position. Returns the residue position returned
922 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
923 * if at a gapped position.
926 * aligned sequence object
930 * index of sequence in alignment
931 * @return sequence position of residue at column, or adjacent residue if at a
934 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
936 char sequenceChar = sequence.getCharAt(column);
937 int pos = sequence.findPosition(column);
938 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
944 * Builds the status message for the current cursor location and writes it to
945 * the status bar, for example
948 * Sequence 3 ID: FER1_SOLLC
949 * Sequence 5 ID: FER1_PEA Residue: THR (4)
950 * Sequence 5 ID: FER1_PEA Residue: B (3)
951 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
956 * sequence position in the alignment (1..)
957 * @param sequenceChar
958 * the character under the cursor
960 * the sequence residue position (if not over a gap)
962 protected void setStatusMessage(SequenceI sequence, int seqIndex,
963 char sequenceChar, int residuePos)
965 StringBuilder text = new StringBuilder(32);
968 * Sequence number (if known), and sequence name.
970 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
971 text.append("Sequence").append(seqno).append(" ID: ")
972 .append(sequence.getName());
974 String residue = null;
977 * Try to translate the display character to residue name (null for gap).
979 boolean isGapped = Comparison.isGap(sequenceChar);
983 boolean nucleotide = av.getAlignment().isNucleotide();
984 String displayChar = String.valueOf(sequenceChar);
987 residue = ResidueProperties.nucleotideName.get(displayChar);
991 residue = "X".equalsIgnoreCase(displayChar) ? "X"
992 : ("*".equals(displayChar) ? "STOP"
993 : ResidueProperties.aa2Triplet.get(displayChar));
995 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
996 .append(": ").append(residue == null ? displayChar : residue);
998 text.append(" (").append(Integer.toString(residuePos)).append(")");
1000 ap.alignFrame.statusBar.setText(text.toString());
1004 * Set the status bar message to highlight the first matched position in
1009 private void setStatusMessage(SearchResultsI results)
1011 AlignmentI al = this.av.getAlignment();
1012 int sequenceIndex = al.findIndex(results);
1013 if (sequenceIndex == -1)
1017 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1018 for (SearchResultMatchI m : results.getResults())
1020 SequenceI seq = m.getSequence();
1021 if (seq.getDatasetSequence() != null)
1023 seq = seq.getDatasetSequence();
1028 int start = m.getStart();
1029 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1040 public void mouseDragged(MouseEvent evt)
1042 if (mouseWheelPressed)
1044 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1045 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1047 int oldWidth = av.getCharWidth();
1049 // Which is bigger, left-right or up-down?
1050 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1051 .abs(evt.getX() - lastMousePress.getX()))
1054 * on drag up or down, decrement or increment font size
1056 int fontSize = av.font.getSize();
1057 boolean fontChanged = false;
1059 if (evt.getY() < lastMousePress.getY())
1064 else if (evt.getY() > lastMousePress.getY())
1077 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1079 av.setFont(newFont, true);
1080 av.setCharWidth(oldWidth);
1084 ap.av.getCodingComplement().setFont(newFont, true);
1085 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1086 .getSplitViewContainer();
1087 splitFrame.adjustLayout();
1088 splitFrame.repaint();
1095 * on drag left or right, decrement or increment character width
1098 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1100 newWidth = av.getCharWidth() - 1;
1101 av.setCharWidth(newWidth);
1103 else if (evt.getX() > lastMousePress.getX())
1105 newWidth = av.getCharWidth() + 1;
1106 av.setCharWidth(newWidth);
1110 ap.paintAlignment(false, false);
1114 * need to ensure newWidth is set on cdna, regardless of which
1115 * panel the mouse drag happened in; protein will compute its
1116 * character width as 1:1 or 3:1
1118 av.getCodingComplement().setCharWidth(newWidth);
1119 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1120 .getSplitViewContainer();
1121 splitFrame.adjustLayout();
1122 splitFrame.repaint();
1127 FontMetrics fm = getFontMetrics(av.getFont());
1128 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1130 lastMousePress = evt.getPoint();
1137 doMouseDraggedDefineMode(evt);
1141 int res = findColumn(evt);
1148 if ((lastres == -1) || (lastres == res))
1153 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1155 // dragLeft, delete gap
1156 editSequence(false, false, res);
1160 editSequence(true, false, res);
1163 mouseDragging = true;
1164 if ((scrollThread != null) && (scrollThread.isRunning()))
1166 scrollThread.setEvent(evt);
1171 * Edits the sequence to insert or delete one or more gaps, in response to a
1172 * mouse drag or cursor mode command. The number of inserts/deletes may be
1173 * specified with the cursor command, or else depends on the mouse event
1174 * (normally one column, but potentially more for a fast mouse drag).
1176 * Delete gaps is limited to the number of gaps left of the cursor position
1177 * (mouse drag), or at or right of the cursor position (cursor mode).
1179 * In group editing mode (Ctrl or Cmd down), the edit acts on all sequences in
1180 * the current selection group.
1182 * In locked editing mode (with a selection group present), inserts/deletions
1183 * within the selection group are limited to its boundaries (and edits outside
1184 * the group stop at its border).
1187 * true to insert gaps, false to delete gaps
1189 * (unused parameter)
1191 * the column at which to perform the action; the number of columns
1192 * affected depends on <code>this.lastres</code> (cursor position)
1194 synchronized void editSequence(boolean insertGap, boolean editSeq,
1198 int fixedRight = -1;
1199 boolean fixedColumns = false;
1200 SequenceGroup sg = av.getSelectionGroup();
1202 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1204 // No group, but the sequence may represent a group
1205 if (!groupEditing && av.hasHiddenRows())
1207 if (av.isHiddenRepSequence(seq))
1209 sg = av.getRepresentedSequences(seq);
1210 groupEditing = true;
1215 * make a name for the edit action, for
1216 * status bar message and Undo/Redo menu
1218 String label = null;
1221 label = MessageManager.getString("action.edit_group");
1225 label = seq.getName();
1226 if (label.length() > 10)
1228 label = label.substring(0, 10);
1230 label = MessageManager.formatMessage("label.edit_params",
1236 * initialise the edit command if there is not
1237 * already one being extended
1239 if (editCommand == null)
1241 editCommand = new EditCommand(label);
1244 // Are we editing within a selection group?
1245 boolean inSelectionGroup = sg != null
1246 && sg.getSequences(av.getHiddenRepSequences()).contains(seq);
1247 if (groupEditing || inSelectionGroup)
1249 fixedColumns = true;
1251 // sg might be null as the user may only see 1 sequence,
1252 // but the sequence represents a group
1255 if (!av.isHiddenRepSequence(seq))
1260 sg = av.getRepresentedSequences(seq);
1263 fixedLeft = sg.getStartRes();
1264 fixedRight = sg.getEndRes();
1266 if ((startres < fixedLeft && lastres >= fixedLeft)
1267 || (startres >= fixedLeft && lastres < fixedLeft)
1268 || (startres > fixedRight && lastres <= fixedRight)
1269 || (startres <= fixedRight && lastres > fixedRight))
1275 if (fixedLeft > startres)
1277 fixedRight = fixedLeft - 1;
1280 else if (fixedRight < startres)
1282 fixedLeft = fixedRight;
1287 if (av.hasHiddenColumns())
1289 fixedColumns = true;
1290 int y1 = av.getAlignment().getHiddenColumns()
1291 .getNextHiddenBoundary(true, startres);
1292 int y2 = av.getAlignment().getHiddenColumns()
1293 .getNextHiddenBoundary(false, startres);
1295 if ((insertGap && startres > y1 && lastres < y1)
1296 || (!insertGap && startres < y2 && lastres > y2))
1302 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1303 // Selection spans a hidden region
1304 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1312 fixedRight = y2 - 1;
1317 SequenceI[] seqs = new SequenceI[] { seq };
1319 boolean endEditing = false;
1325 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1326 int g, groupSize = vseqs.size();
1327 SequenceI[] groupSeqs = new SequenceI[groupSize];
1328 for (g = 0; g < groupSeqs.length; g++)
1330 groupSeqs[g] = vseqs.get(g);
1336 // If the user has selected the whole sequence, and is dragging to
1337 // the right, we can still extend the alignment and selectionGroup
1338 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1339 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1341 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1342 fixedRight = sg.getEndRes();
1345 // Is it valid with fixed columns??
1346 // Find the next gap before the end
1347 // of the visible region boundary
1348 boolean blank = false;
1349 for (; fixedRight > lastres; fixedRight--)
1353 for (g = 0; g < groupSize; g++)
1355 for (int j = 0; j < startres - lastres; j++)
1358 .isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1373 if (sg.getSize() == av.getAlignment().getHeight())
1375 if ((av.hasHiddenColumns()
1376 && startres < av.getAlignment().getHiddenColumns()
1377 .getNextHiddenBoundary(false, startres)))
1383 int alWidth = av.getAlignment().getWidth();
1384 if (av.hasHiddenRows())
1386 int hwidth = av.getAlignment().getHiddenSequences()
1388 if (hwidth > alWidth)
1393 // We can still insert gaps if the selectionGroup
1394 // contains all the sequences
1395 sg.setEndRes(sg.getEndRes() + startres - lastres);
1396 fixedRight = alWidth + startres - lastres;
1407 else if (!insertGap)
1409 // / Are we able to delete?
1410 // ie are all columns blank?
1412 for (g = 0; g < groupSize; g++)
1414 for (int j = startres; j < lastres; j++)
1416 if (groupSeqs[g].getLength() <= j)
1421 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1423 // Not a gap, block edit not valid
1433 // dragging to the right
1434 if (fixedColumns && fixedRight != -1)
1436 for (int j = lastres; j < startres; j++)
1438 insertGap(j, groupSeqs, fixedRight);
1443 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1444 startres - lastres, false);
1449 // dragging to the left
1450 if (fixedColumns && fixedRight != -1)
1452 for (int j = lastres; j > startres; j--)
1454 deleteChar(startres, groupSeqs, fixedRight);
1459 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1460 lastres - startres, false);
1467 * editing a single sequence
1471 // dragging to the right
1472 if (fixedColumns && fixedRight != -1)
1474 for (int j = lastres; j < startres; j++)
1476 if (!insertGap(j, seqs, fixedRight))
1479 * e.g. cursor mode command asked for
1480 * more inserts than are possible
1489 appendEdit(Action.INSERT_GAP, seqs, lastres, startres - lastres,
1497 // dragging to the left
1498 if (fixedColumns && fixedRight != -1)
1500 for (int j = lastres; j > startres; j--)
1502 if (!Comparison.isGap(seq.getCharAt(startres)))
1507 deleteChar(startres, seqs, fixedRight);
1512 // could be a keyboard edit trying to delete none gaps
1514 for (int m = startres; m < lastres; m++)
1516 if (!Comparison.isGap(seq.getCharAt(m)))
1524 appendEdit(Action.DELETE_GAP, seqs, startres, max, false);
1529 {// insertGap==false AND editSeq==TRUE;
1530 if (fixedColumns && fixedRight != -1)
1532 for (int j = lastres; j < startres; j++)
1534 insertGap(j, seqs, fixedRight);
1539 appendEdit(Action.INSERT_NUC, seqs, lastres,
1540 startres - lastres, false);
1548 * report what actually happened (might be less than
1549 * what was requested)
1551 String msg = getEditStatusMessage(editCommand);
1552 ap.alignFrame.statusBar.setText(msg == null ? " " : msg);
1560 seqCanvas.repaint();
1565 * Constructs an informative status bar message while dragging to insert or
1566 * delete gaps. Answers null if inserts and deletes cancel out.
1568 * @param editCommand
1569 * a command containing the list of individual edits
1572 protected static String getEditStatusMessage(EditCommand editCommand)
1574 if (editCommand == null)
1580 * add any inserts, and subtract any deletes,
1581 * not counting those auto-inserted when doing a 'locked edit'
1582 * (so only counting edits 'under the cursor')
1585 for (Edit cmd : editCommand.getEdits())
1587 if (!cmd.isSystemGenerated())
1589 count += cmd.getAction() == Action.INSERT_GAP ? cmd.getNumber()
1597 * inserts and deletes cancel out
1602 String msgKey = count > 1 ? "label.insert_gaps"
1603 : (count == 1 ? "label.insert_gap"
1604 : (count == -1 ? "label.delete_gap"
1605 : "label.delete_gaps"));
1606 count = Math.abs(count);
1608 return MessageManager.formatMessage(msgKey, String.valueOf(count));
1612 * Inserts one gap at column j, deleting the right-most gapped column up to
1613 * (and including) fixedColumn. Returns true if the edit is successful, false
1614 * if no blank column is available to allow the insertion to be balanced by a
1619 * @param fixedColumn
1622 boolean insertGap(int j, SequenceI[] seq, int fixedColumn)
1624 int blankColumn = fixedColumn;
1625 for (int s = 0; s < seq.length; s++)
1627 // Find the next gap before the end of the visible region boundary
1628 // If lastCol > j, theres a boundary after the gap insertion
1630 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1632 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1634 // Theres a space, so break and insert the gap
1639 if (blankColumn <= j)
1641 blankColumn = fixedColumn;
1647 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1, true);
1649 appendEdit(Action.INSERT_GAP, seq, j, 1, false);
1655 * Helper method to add and perform one edit action
1661 * @param systemGenerated
1662 * true if the edit is a 'balancing' delete (or insert) to match a
1663 * user's insert (or delete) in a locked editing region
1665 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1666 int count, boolean systemGenerated)
1669 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1670 av.getAlignment().getGapCharacter());
1671 edit.setSystemGenerated(systemGenerated);
1673 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1677 * Deletes the character at column j, and inserts a gap at fixedColumn, in
1678 * each of the given sequences. The caller should ensure that all sequences
1679 * are gapped in column j.
1683 * @param fixedColumn
1685 void deleteChar(int j, SequenceI[] seqs, int fixedColumn)
1687 appendEdit(Action.DELETE_GAP, seqs, j, 1, false);
1689 appendEdit(Action.INSERT_GAP, seqs, fixedColumn, 1, true);
1699 public void mouseEntered(MouseEvent e)
1706 if ((scrollThread != null) && (scrollThread.isRunning()))
1708 scrollThread.stopScrolling();
1709 scrollThread = null;
1720 public void mouseExited(MouseEvent e)
1722 if (av.getWrapAlignment())
1727 if (mouseDragging && scrollThread == null)
1729 scrollThread = new ScrollThread();
1734 * Handler for double-click on a position with one or more sequence features.
1735 * Opens the Amend Features dialog to allow feature details to be amended, or
1736 * the feature deleted.
1739 public void mouseClicked(MouseEvent evt)
1741 SequenceGroup sg = null;
1742 SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
1743 if (evt.getClickCount() > 1)
1745 sg = av.getSelectionGroup();
1746 if (sg != null && sg.getSize() == 1
1747 && sg.getEndRes() - sg.getStartRes() < 2)
1749 av.setSelectionGroup(null);
1752 int column = findColumn(evt);
1755 * find features at the position (if not gapped), or straddling
1756 * the position (if at a gap)
1758 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1759 .findFeaturesAtColumn(sequence, column + 1);
1761 if (!features.isEmpty())
1764 * highlight the first feature at the position on the alignment
1766 SearchResultsI highlight = new SearchResults();
1767 highlight.addResult(sequence, features.get(0).getBegin(), features
1769 seqCanvas.highlightSearchResults(highlight, false);
1772 * open the Amend Features dialog; clear highlighting afterwards,
1773 * whether changes were made or not
1775 List<SequenceI> seqs = Collections.singletonList(sequence);
1776 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1778 av.setSearchResults(null); // clear highlighting
1779 seqCanvas.repaint(); // draw new/amended features
1785 public void mouseWheelMoved(MouseWheelEvent e)
1788 double wheelRotation = e.getPreciseWheelRotation();
1789 if (wheelRotation > 0)
1791 if (e.isShiftDown())
1793 av.getRanges().scrollRight(true);
1798 av.getRanges().scrollUp(false);
1801 else if (wheelRotation < 0)
1803 if (e.isShiftDown())
1805 av.getRanges().scrollRight(false);
1809 av.getRanges().scrollUp(true);
1814 * update status bar and tooltip for new position
1815 * (need to synthesize a mouse movement to refresh tooltip)
1818 ToolTipManager.sharedInstance().mouseMoved(e);
1827 public void doMousePressedDefineMode(MouseEvent evt)
1829 final int res = findColumn(evt);
1830 final int seq = findSeq(evt);
1832 updateOverviewAndStructs = false;
1834 startWrapBlock = wrappedBlock;
1836 if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
1838 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1839 MessageManager.getString(
1840 "label.cannot_edit_annotations_in_wrapped_view"),
1841 MessageManager.getString("label.wrapped_view_no_edit"),
1842 JvOptionPane.WARNING_MESSAGE);
1846 if (seq < 0 || res < 0)
1851 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1853 if ((sequence == null) || (res > sequence.getLength()))
1858 stretchGroup = av.getSelectionGroup();
1860 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1862 stretchGroup = av.getAlignment().findGroup(sequence, res);
1863 if (stretchGroup != null)
1865 // only update the current selection if the popup menu has a group to
1867 av.setSelectionGroup(stretchGroup);
1871 if (evt.isPopupTrigger()) // Mac: mousePressed
1878 * defer right-mouse click handling to mouseReleased on Windows
1879 * (where isPopupTrigger() will answer true)
1880 * NB isRightMouseButton is also true for Cmd-click on Mac
1882 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1889 seqCanvas.cursorX = findColumn(evt);
1890 seqCanvas.cursorY = findSeq(evt);
1891 seqCanvas.repaint();
1895 if (stretchGroup == null)
1897 createStretchGroup(res, sequence);
1900 if (stretchGroup != null)
1902 stretchGroup.addPropertyChangeListener(seqCanvas);
1905 seqCanvas.repaint();
1908 private void createStretchGroup(int res, SequenceI sequence)
1910 // Only if left mouse button do we want to change group sizes
1911 // define a new group here
1912 SequenceGroup sg = new SequenceGroup();
1913 sg.setStartRes(res);
1915 sg.addSequence(sequence, false);
1916 av.setSelectionGroup(sg);
1919 if (av.getConservationSelected())
1921 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1925 if (av.getAbovePIDThreshold())
1927 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1930 // TODO: stretchGroup will always be not null. Is this a merge error ?
1931 // or is there a threading issue here?
1932 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1934 // Edit end res position of selected group
1935 changeEndRes = true;
1937 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1939 // Edit end res position of selected group
1940 changeStartRes = true;
1942 stretchGroup.getWidth();
1947 * Build and show a pop-up menu at the right-click mouse position
1953 void showPopupMenu(MouseEvent evt)
1955 final int column = findColumn(evt);
1956 final int seq = findSeq(evt);
1957 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1958 List<SequenceFeature> features = ap.getFeatureRenderer()
1959 .findFeaturesAtColumn(sequence, column + 1);
1961 PopupMenu pop = new PopupMenu(ap, null, features);
1962 pop.show(this, evt.getX(), evt.getY());
1966 * Update the display after mouse up on a selection or group
1969 * mouse released event details
1971 * true if this event is happening after a mouse drag (rather than a
1974 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
1976 if (stretchGroup == null)
1981 stretchGroup.removePropertyChangeListener(seqCanvas);
1983 // always do this - annotation has own state
1984 // but defer colourscheme update until hidden sequences are passed in
1985 boolean vischange = stretchGroup.recalcConservation(true);
1986 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
1988 if (stretchGroup.cs != null)
1990 stretchGroup.cs.alignmentChanged(stretchGroup,
1991 av.getHiddenRepSequences());
1993 ResidueShaderI groupColourScheme = stretchGroup
1994 .getGroupColourScheme();
1995 String name = stretchGroup.getName();
1996 if (stretchGroup.cs.conservationApplied())
1998 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
2000 if (stretchGroup.cs.getThreshold() > 0)
2002 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
2005 PaintRefresher.Refresh(this, av.getSequenceSetId());
2006 // TODO: structure colours only need updating if stretchGroup used to or now
2007 // does contain sequences with structure views
2008 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
2009 updateOverviewAndStructs = false;
2010 changeEndRes = false;
2011 changeStartRes = false;
2012 stretchGroup = null;
2022 public void doMouseDraggedDefineMode(MouseEvent evt)
2024 int res = findColumn(evt);
2025 int y = findSeq(evt);
2027 if (wrappedBlock != startWrapBlock)
2032 if (stretchGroup == null)
2037 if (res >= av.getAlignment().getWidth())
2039 res = av.getAlignment().getWidth() - 1;
2042 if (stretchGroup.getEndRes() == res)
2044 // Edit end res position of selected group
2045 changeEndRes = true;
2047 else if (stretchGroup.getStartRes() == res)
2049 // Edit start res position of selected group
2050 changeStartRes = true;
2053 if (res < av.getRanges().getStartRes())
2055 res = av.getRanges().getStartRes();
2060 if (res > (stretchGroup.getStartRes() - 1))
2062 stretchGroup.setEndRes(res);
2063 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2066 else if (changeStartRes)
2068 if (res < (stretchGroup.getEndRes() + 1))
2070 stretchGroup.setStartRes(res);
2071 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2075 int dragDirection = 0;
2081 else if (y < oldSeq)
2086 while ((y != oldSeq) && (oldSeq > -1)
2087 && (y < av.getAlignment().getHeight()))
2089 // This routine ensures we don't skip any sequences, as the
2090 // selection is quite slow.
2091 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2093 oldSeq += dragDirection;
2100 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2102 if (stretchGroup.getSequences(null).contains(nextSeq))
2104 stretchGroup.deleteSequence(seq, false);
2105 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2111 stretchGroup.addSequence(seq, false);
2114 stretchGroup.addSequence(nextSeq, false);
2115 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2124 mouseDragging = true;
2126 if ((scrollThread != null) && (scrollThread.isRunning()))
2128 scrollThread.setEvent(evt);
2132 * construct a status message showing the range of the selection
2134 StringBuilder status = new StringBuilder(64);
2135 List<SequenceI> seqs = stretchGroup.getSequences();
2136 String name = seqs.get(0).getName();
2137 if (name.length() > 20)
2139 name = name.substring(0, 20);
2141 status.append(name).append(" - ");
2142 name = seqs.get(seqs.size() - 1).getName();
2143 if (name.length() > 20)
2145 name = name.substring(0, 20);
2147 status.append(name).append(" ");
2148 int startRes = stretchGroup.getStartRes();
2149 status.append(" cols ").append(String.valueOf(startRes + 1))
2151 int endRes = stretchGroup.getEndRes();
2152 status.append(String.valueOf(endRes + 1));
2153 status.append(" (").append(String.valueOf(seqs.size())).append(" x ")
2154 .append(String.valueOf(endRes - startRes + 1)).append(")");
2155 ap.alignFrame.setStatus(status.toString());
2158 void scrollCanvas(MouseEvent evt)
2162 if ((scrollThread != null) && (scrollThread.isRunning()))
2164 scrollThread.stopScrolling();
2165 scrollThread = null;
2167 mouseDragging = false;
2171 if (scrollThread == null)
2173 scrollThread = new ScrollThread();
2176 mouseDragging = true;
2177 scrollThread.setEvent(evt);
2182 // this class allows scrolling off the bottom of the visible alignment
2183 class ScrollThread extends Thread
2187 private volatile boolean threadRunning = true;
2189 public ScrollThread()
2194 public void setEvent(MouseEvent e)
2199 public void stopScrolling()
2201 threadRunning = false;
2204 public boolean isRunning()
2206 return threadRunning;
2212 while (threadRunning)
2216 if (mouseDragging && (evt.getY() < 0)
2217 && (av.getRanges().getStartSeq() > 0))
2219 av.getRanges().scrollUp(true);
2222 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2223 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2225 av.getRanges().scrollUp(false);
2228 if (mouseDragging && (evt.getX() < 0))
2230 av.getRanges().scrollRight(false);
2232 else if (mouseDragging && (evt.getX() >= getWidth()))
2234 av.getRanges().scrollRight(true);
2241 } catch (Exception ex)
2249 * modify current selection according to a received message.
2252 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2253 HiddenColumns hidden, SelectionSource source)
2255 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2256 // handles selection messages...
2257 // TODO: extend config options to allow user to control if selections may be
2258 // shared between viewports.
2259 boolean iSentTheSelection = (av == source
2260 || (source instanceof AlignViewport
2261 && ((AlignmentViewport) source).getSequenceSetId()
2262 .equals(av.getSequenceSetId())));
2264 if (iSentTheSelection)
2266 // respond to our own event by updating dependent dialogs
2267 if (ap.getCalculationDialog() != null)
2269 ap.getCalculationDialog().validateCalcTypes();
2275 // process further ?
2276 if (!av.followSelection)
2282 * Ignore the selection if there is one of our own pending.
2284 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2290 * Check for selection in a view of which this one is a dna/protein
2293 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2298 // do we want to thread this ? (contention with seqsel and colsel locks, I
2301 * only copy colsel if there is a real intersection between
2302 * sequence selection and this panel's alignment
2304 boolean repaint = false;
2305 boolean copycolsel = false;
2307 SequenceGroup sgroup = null;
2308 if (seqsel != null && seqsel.getSize() > 0)
2310 if (av.getAlignment() == null)
2312 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2313 + " ViewId=" + av.getViewId()
2314 + " 's alignment is NULL! returning immediately.");
2317 sgroup = seqsel.intersect(av.getAlignment(),
2318 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2319 if ((sgroup != null && sgroup.getSize() > 0))
2324 if (sgroup != null && sgroup.getSize() > 0)
2326 av.setSelectionGroup(sgroup);
2330 av.setSelectionGroup(null);
2332 av.isSelectionGroupChanged(true);
2337 // the current selection is unset or from a previous message
2338 // so import the new colsel.
2339 if (colsel == null || colsel.isEmpty())
2341 if (av.getColumnSelection() != null)
2343 av.getColumnSelection().clear();
2349 // TODO: shift colSel according to the intersecting sequences
2350 if (av.getColumnSelection() == null)
2352 av.setColumnSelection(new ColumnSelection(colsel));
2356 av.getColumnSelection().setElementsFrom(colsel,
2357 av.getAlignment().getHiddenColumns());
2360 av.isColSelChanged(true);
2364 if (copycolsel && av.hasHiddenColumns()
2365 && (av.getAlignment().getHiddenColumns() == null))
2367 System.err.println("Bad things");
2369 if (repaint) // always true!
2371 // probably finessing with multiple redraws here
2372 PaintRefresher.Refresh(this, av.getSequenceSetId());
2373 // ap.paintAlignment(false);
2376 // lastly, update dependent dialogs
2377 if (ap.getCalculationDialog() != null)
2379 ap.getCalculationDialog().validateCalcTypes();
2385 * If this panel is a cdna/protein translation view of the selection source,
2386 * tries to map the source selection to a local one, and returns true. Else
2393 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2394 ColumnSelection colsel, HiddenColumns hidden,
2395 SelectionSource source)
2397 if (!(source instanceof AlignViewportI))
2401 final AlignViewportI sourceAv = (AlignViewportI) source;
2402 if (sourceAv.getCodingComplement() != av
2403 && av.getCodingComplement() != sourceAv)
2409 * Map sequence selection
2411 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2412 av.setSelectionGroup(sg);
2413 av.isSelectionGroupChanged(true);
2416 * Map column selection
2418 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2420 ColumnSelection cs = new ColumnSelection();
2421 HiddenColumns hs = new HiddenColumns();
2422 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2423 av.setColumnSelection(cs);
2424 av.getAlignment().setHiddenColumns(hs);
2426 // lastly, update any dependent dialogs
2427 if (ap.getCalculationDialog() != null)
2429 ap.getCalculationDialog().validateCalcTypes();
2432 PaintRefresher.Refresh(this, av.getSequenceSetId());
2439 * @return null or last search results handled by this panel
2441 public SearchResultsI getLastSearchResults()
2443 return lastSearchResults;