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.bin.Jalview;
26 import jalview.commands.EditCommand;
27 import jalview.commands.EditCommand.Action;
28 import jalview.commands.EditCommand.Edit;
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;
52 import jalview.viewmodel.ViewportRanges;
54 import java.awt.BorderLayout;
55 import java.awt.Color;
57 import java.awt.FontMetrics;
58 import java.awt.Point;
59 import java.awt.event.ActionEvent;
60 import java.awt.event.ActionListener;
61 import java.awt.event.MouseEvent;
62 import java.awt.event.MouseListener;
63 import java.awt.event.MouseMotionListener;
64 import java.awt.event.MouseWheelEvent;
65 import java.awt.event.MouseWheelListener;
66 import java.util.Collections;
67 import java.util.List;
69 import javax.swing.JLabel;
70 import javax.swing.JPanel;
71 import javax.swing.JToolTip;
72 import javax.swing.SwingUtilities;
73 import javax.swing.Timer;
74 import javax.swing.ToolTipManager;
80 * @version $Revision: 1.130 $
82 public class SeqPanel extends JPanel
83 implements MouseListener, MouseMotionListener, MouseWheelListener,
84 SequenceListener, SelectionListener
86 private static final int MAX_TOOLTIP_LENGTH = 300;
88 public SeqCanvas seqCanvas;
90 public AlignmentPanel ap;
93 * last column position for mouseMoved event
95 private int lastMouseColumn;
98 * last sequence offset for mouseMoved event
100 private int lastMouseSeq;
102 protected int lastres;
104 protected int startseq;
106 protected AlignViewport av;
108 ScrollThread scrollThread = null;
110 boolean mouseDragging = false;
112 boolean editingSeqs = false;
114 boolean groupEditing = false;
116 // ////////////////////////////////////////
117 // ///Everything below this is for defining the boundary of the rubberband
118 // ////////////////////////////////////////
121 boolean changeEndSeq = false;
123 boolean changeStartSeq = false;
125 boolean changeEndRes = false;
127 boolean changeStartRes = false;
129 SequenceGroup stretchGroup = null;
131 boolean remove = false;
133 Point lastMousePress;
135 boolean mouseWheelPressed = false;
137 StringBuffer keyboardNo1;
139 StringBuffer keyboardNo2;
141 java.net.URL linkImageURL;
143 private final SequenceAnnotationReport seqARep;
145 StringBuilder tooltipText = new StringBuilder();
149 EditCommand editCommand;
151 StructureSelectionManager ssm;
153 SearchResultsI lastSearchResults;
156 * Creates a new SeqPanel object
161 public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
163 linkImageURL = getClass().getResource("/images/link.gif");
164 seqARep = new SequenceAnnotationReport(linkImageURL.toString());
165 ToolTipManager.sharedInstance().registerComponent(this);
166 ToolTipManager.sharedInstance().setInitialDelay(0);
167 ToolTipManager.sharedInstance().setDismissDelay(10000);
171 setBackground(Color.white);
173 seqCanvas = new SeqCanvas(alignPanel);
174 setLayout(new BorderLayout());
175 add(seqCanvas, BorderLayout.CENTER);
177 this.ap = alignPanel;
179 if (!viewport.isDataset())
181 addMouseMotionListener(this);
182 addMouseListener(this);
183 addMouseWheelListener(this);
184 ssm = viewport.getStructureSelectionManager();
185 ssm.addStructureViewerListener(this);
186 ssm.addSelectionListener(this);
189 lastMouseColumn = -1;
193 int startWrapBlock = -1;
195 int wrappedBlock = -1;
198 * Returns the aligned sequence position (base 0) at the mouse position, or
199 * the closest visible one
204 int findColumn(MouseEvent evt)
209 int startRes = av.getRanges().getStartRes();
210 if (av.getWrapAlignment())
213 int hgap = av.getCharHeight();
214 if (av.getScaleAboveWrapped())
216 hgap += av.getCharHeight();
219 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
220 + hgap + seqCanvas.getAnnotationHeight();
223 y = Math.max(0, y - hgap);
224 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
226 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
232 wrappedBlock = y / cHeight;
233 wrappedBlock += startRes / cwidth;
234 // allow for wrapped view scrolled right (possible from Overview)
235 int startOffset = startRes % cwidth;
236 res = wrappedBlock * cwidth + startOffset
237 + +Math.min(cwidth - 1, x / av.getCharWidth());
241 if (x > seqCanvas.getX() + seqCanvas.getWidth())
243 // make sure we calculate relative to visible alignment, rather than
245 x = seqCanvas.getX() + seqCanvas.getWidth();
247 res = (x / av.getCharWidth()) + startRes;
248 if (res > av.getRanges().getEndRes())
251 res = av.getRanges().getEndRes();
255 if (av.hasHiddenColumns())
257 res = av.getAlignment().getHiddenColumns()
258 .visibleToAbsoluteColumn(res);
265 int findSeq(MouseEvent evt)
270 if (av.getWrapAlignment())
272 int hgap = av.getCharHeight();
273 if (av.getScaleAboveWrapped())
275 hgap += av.getCharHeight();
278 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
279 + hgap + seqCanvas.getAnnotationHeight();
283 seq = Math.min((y % cHeight) / av.getCharHeight(),
284 av.getAlignment().getHeight() - 1);
289 (y / av.getCharHeight()) + av.getRanges().getStartSeq(),
290 av.getAlignment().getHeight() - 1);
297 * When all of a sequence of edits are complete, put the resulting edit list
298 * on the history stack (undo list), and reset flags for editing in progress.
304 if (editCommand != null && editCommand.getSize() > 0)
306 ap.alignFrame.addHistoryItem(editCommand);
307 av.firePropertyChange("alignment", null,
308 av.getAlignment().getSequences());
313 * Tidy up come what may...
318 groupEditing = false;
327 seqCanvas.cursorY = getKeyboardNo1() - 1;
328 scrollToVisible(true);
331 void setCursorColumn()
333 seqCanvas.cursorX = getKeyboardNo1() - 1;
334 scrollToVisible(true);
337 void setCursorRowAndColumn()
339 if (keyboardNo2 == null)
341 keyboardNo2 = new StringBuffer();
345 seqCanvas.cursorX = getKeyboardNo1() - 1;
346 seqCanvas.cursorY = getKeyboardNo2() - 1;
347 scrollToVisible(true);
351 void setCursorPosition()
353 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
355 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
356 scrollToVisible(true);
359 void moveCursor(int dx, int dy)
361 seqCanvas.cursorX += dx;
362 seqCanvas.cursorY += dy;
364 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
366 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
368 int original = seqCanvas.cursorX - dx;
369 int maxWidth = av.getAlignment().getWidth();
371 if (!hidden.isVisible(seqCanvas.cursorX))
373 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
374 int[] region = hidden.getRegionWithEdgeAtRes(visx);
376 if (region != null) // just in case
381 seqCanvas.cursorX = region[1] + 1;
386 seqCanvas.cursorX = region[0] - 1;
389 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
392 if (seqCanvas.cursorX >= maxWidth
393 || !hidden.isVisible(seqCanvas.cursorX))
395 seqCanvas.cursorX = original;
399 scrollToVisible(false);
403 * Scroll to make the cursor visible in the viewport.
406 * just jump to the location rather than scrolling
408 void scrollToVisible(boolean jump)
410 if (seqCanvas.cursorX < 0)
412 seqCanvas.cursorX = 0;
414 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
416 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
419 if (seqCanvas.cursorY < 0)
421 seqCanvas.cursorY = 0;
423 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
425 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
430 boolean repaintNeeded = true;
433 // only need to repaint if the viewport did not move, as otherwise it will
435 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
440 if (av.getWrapAlignment())
442 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
443 int x = av.getAlignment().getHiddenColumns()
444 .absoluteToVisibleColumn(seqCanvas.cursorX);
445 av.getRanges().scrollToWrappedVisible(x);
449 av.getRanges().scrollToVisible(seqCanvas.cursorX,
454 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
456 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
457 seqCanvas.cursorX, seqCanvas.cursorY);
467 void setSelectionAreaAtCursor(boolean topLeft)
469 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
471 if (av.getSelectionGroup() != null)
473 SequenceGroup sg = av.getSelectionGroup();
474 // Find the top and bottom of this group
475 int min = av.getAlignment().getHeight(), max = 0;
476 for (int i = 0; i < sg.getSize(); i++)
478 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
493 sg.setStartRes(seqCanvas.cursorX);
494 if (sg.getEndRes() < seqCanvas.cursorX)
496 sg.setEndRes(seqCanvas.cursorX);
499 min = seqCanvas.cursorY;
503 sg.setEndRes(seqCanvas.cursorX);
504 if (sg.getStartRes() > seqCanvas.cursorX)
506 sg.setStartRes(seqCanvas.cursorX);
509 max = seqCanvas.cursorY + 1;
514 // Only the user can do this
515 av.setSelectionGroup(null);
519 // Now add any sequences between min and max
520 sg.getSequences(null).clear();
521 for (int i = min; i < max; i++)
523 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
528 if (av.getSelectionGroup() == null)
530 SequenceGroup sg = new SequenceGroup();
531 sg.setStartRes(seqCanvas.cursorX);
532 sg.setEndRes(seqCanvas.cursorX);
533 sg.addSequence(sequence, false);
534 av.setSelectionGroup(sg);
537 ap.paintAlignment(false, false);
541 void insertGapAtCursor(boolean group)
543 groupEditing = group;
544 startseq = seqCanvas.cursorY;
545 lastres = seqCanvas.cursorX;
546 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
550 void deleteGapAtCursor(boolean group)
552 groupEditing = group;
553 startseq = seqCanvas.cursorY;
554 lastres = seqCanvas.cursorX + getKeyboardNo1();
555 editSequence(false, false, seqCanvas.cursorX);
559 void insertNucAtCursor(boolean group, String nuc)
561 // TODO not called - delete?
562 groupEditing = group;
563 startseq = seqCanvas.cursorY;
564 lastres = seqCanvas.cursorX;
565 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
569 void numberPressed(char value)
571 if (keyboardNo1 == null)
573 keyboardNo1 = new StringBuffer();
576 if (keyboardNo2 != null)
578 keyboardNo2.append(value);
582 keyboardNo1.append(value);
590 if (keyboardNo1 != null)
592 int value = Integer.parseInt(keyboardNo1.toString());
596 } catch (Exception x)
607 if (keyboardNo2 != null)
609 int value = Integer.parseInt(keyboardNo2.toString());
613 } catch (Exception x)
627 public void mouseReleased(MouseEvent evt)
629 boolean didDrag = mouseDragging; // did we come here after a drag
630 mouseDragging = false;
631 mouseWheelPressed = false;
633 if (evt.isPopupTrigger()) // Windows: mouseReleased
646 doMouseReleasedDefineMode(evt, didDrag);
657 public void mousePressed(MouseEvent evt)
659 lastMousePress = evt.getPoint();
661 if (SwingUtilities.isMiddleMouseButton(evt))
663 mouseWheelPressed = true;
667 boolean isControlDown = Platform.isControlDown(evt);
668 if (evt.isShiftDown() || isControlDown)
678 doMousePressedDefineMode(evt);
682 int seq = findSeq(evt);
683 int res = findColumn(evt);
685 if (seq < 0 || res < 0)
690 if ((seq < av.getAlignment().getHeight())
691 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
707 private String formattedTooltipText;
710 public void mouseOverSequence(SequenceI sequence, int index, int pos)
712 String tmp = sequence.hashCode() + " " + index + " " + pos;
714 if (lastMessage == null || !lastMessage.equals(tmp))
716 // System.err.println("mouseOver Sequence: "+tmp);
717 ssm.mouseOverSequence(sequence, index, pos, av);
723 * Highlight the mapped region described by the search results object (unless
724 * unchanged). This supports highlight of protein while mousing over linked
725 * cDNA and vice versa. The status bar is also updated to show the location of
726 * the start of the highlighted region.
729 public void highlightSequence(SearchResultsI results)
731 if (results == null || results.equals(lastSearchResults))
735 lastSearchResults = results;
737 boolean wasScrolled = false;
739 if (av.isFollowHighlight())
741 // don't allow highlight of protein/cDNA to also scroll a complementary
742 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
743 // over residue to change abruptly, causing highlighted residue in panel 2
744 // to change, causing a scroll in panel 1 etc)
745 ap.setToScrollComplementPanel(false);
746 wasScrolled = ap.scrollToPosition(results, false);
749 seqCanvas.revalidate();
751 ap.setToScrollComplementPanel(true);
754 boolean fastPaint = !(wasScrolled && av.getWrapAlignment());
755 if (seqCanvas.highlightSearchResults(results, fastPaint))
757 setStatusMessage(results);
762 public VamsasSource getVamsasSource()
764 return this.ap == null ? null : this.ap.av;
768 public void updateColours(SequenceI seq, int index)
770 System.out.println("update the seqPanel colours");
775 * Action on mouse movement is to update the status bar to show the current
776 * sequence position, and (if features are shown) to show any features at the
777 * position in a tooltip. Does nothing if the mouse move does not change
783 public void mouseMoved(MouseEvent evt)
787 // This is because MacOSX creates a mouseMoved
788 // If control is down, other platforms will not.
792 final int column = findColumn(evt);
793 final int seq = findSeq(evt);
795 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
800 if (column == lastMouseColumn && seq == lastMouseSeq)
803 * just a pixel move without change of residue
807 lastMouseColumn = column;
810 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
812 if (column >= sequence.getLength())
818 * set status bar message, returning residue position in sequence
820 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
821 final int pos = setStatusMessage(sequence, column, seq);
822 if (ssm != null && !isGapped)
824 mouseOverSequence(sequence, column, pos);
827 tooltipText.setLength(6); // Cuts the buffer back to <html>
829 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
832 for (int g = 0; g < groups.length; g++)
834 if (groups[g].getStartRes() <= column
835 && groups[g].getEndRes() >= column)
837 if (!groups[g].getName().startsWith("JTreeGroup")
838 && !groups[g].getName().startsWith("JGroup"))
840 tooltipText.append(groups[g].getName());
843 if (groups[g].getDescription() != null)
845 tooltipText.append(": " + groups[g].getDescription());
852 * add any features at the position to the tooltip; if over a gap, only
853 * add features that straddle the gap (pos may be the residue before or
856 if (av.isShowSequenceFeatures())
858 List<SequenceFeature> features = ap.getFeatureRenderer()
859 .findFeaturesAtColumn(sequence, column + 1);
860 seqARep.appendFeatures(tooltipText, pos, features,
861 this.ap.getSeqPanel().seqCanvas.fr);
863 if (tooltipText.length() == 6) // <html>
865 setToolTipText(null);
870 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
872 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
873 tooltipText.append("...");
875 String textString = tooltipText.toString();
876 if (lastTooltip == null || !lastTooltip.equals(textString))
878 formattedTooltipText = JvSwingUtils.wrapTooltip(true,
880 setToolTipText(formattedTooltipText);
882 lastTooltip = textString;
888 private Point lastp = null;
890 private JToolTip tempTip = new JLabel().createToolTip();
895 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
898 public Point getToolTipLocation(MouseEvent event)
902 if (tooltipText == null || tooltipText.length() == 6)
905 if (lastp != null && event.isShiftDown())
909 int x = event.getX();
910 int y = event.getY();
913 tempTip.setTipText(formattedTooltipText);
914 int tipWidth = (int) tempTip.getPreferredSize().getWidth();
916 // was x += (w - x < 200) ? -(w / 2) : 5;
917 x = (x + tipWidth < w ? x + 10 : w - tipWidth);
918 p = new Point(x, y + 20); // BH 2018 was - 20?
920 * TODO: try to modify position region is not obcured by tooltip
931 * set when the current UI interaction has resulted in a change that requires
932 * shading in overviews and structures to be recalculated. this could be
933 * changed to a something more expressive that indicates what actually has
934 * changed, so selective redraws can be applied (ie. only structures, only
937 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
940 * set if av.getSelectionGroup() refers to a group that is defined on the
941 * alignment view, rather than a transient selection
943 // private boolean editingDefinedGroup = false; // TODO: refactor to
944 // avcontroller or viewModel
947 * Sets the status message in alignment panel, showing the sequence number
948 * (index) and id, and residue and residue position if not at a gap, for the
949 * given sequence and column position. Returns the residue position returned
950 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
951 * if at a gapped position.
954 * aligned sequence object
958 * index of sequence in alignment
959 * @return sequence position of residue at column, or adjacent residue if at a
962 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
964 char sequenceChar = sequence.getCharAt(column);
965 int pos = sequence.findPosition(column);
966 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
972 * Builds the status message for the current cursor location and writes it to
973 * the status bar, for example
976 * Sequence 3 ID: FER1_SOLLC
977 * Sequence 5 ID: FER1_PEA Residue: THR (4)
978 * Sequence 5 ID: FER1_PEA Residue: B (3)
979 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
984 * sequence position in the alignment (1..)
985 * @param sequenceChar
986 * the character under the cursor
988 * the sequence residue position (if not over a gap)
990 protected void setStatusMessage(SequenceI sequence, int seqIndex,
991 char sequenceChar, int residuePos)
993 StringBuilder text = new StringBuilder(32);
996 * Sequence number (if known), and sequence name.
998 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
999 text.append("Sequence").append(seqno).append(" ID: ")
1000 .append(sequence.getName());
1002 String residue = null;
1005 * Try to translate the display character to residue name (null for gap).
1007 boolean isGapped = Comparison.isGap(sequenceChar);
1011 boolean nucleotide = av.getAlignment().isNucleotide();
1012 String displayChar = String.valueOf(sequenceChar);
1015 residue = ResidueProperties.nucleotideName.get(displayChar);
1019 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1020 : ("*".equals(displayChar) ? "STOP"
1021 : ResidueProperties.aa2Triplet.get(displayChar));
1023 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1024 .append(": ").append(residue == null ? displayChar : residue);
1026 text.append(" (").append(Integer.toString(residuePos)).append(")");
1028 ap.alignFrame.setStatus(text.toString());
1032 * Set the status bar message to highlight the first matched position in
1037 private void setStatusMessage(SearchResultsI results)
1039 AlignmentI al = this.av.getAlignment();
1040 int sequenceIndex = al.findIndex(results);
1041 if (sequenceIndex == -1)
1045 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1046 for (SearchResultMatchI m : results.getResults())
1048 SequenceI seq = m.getSequence();
1049 if (seq.getDatasetSequence() != null)
1051 seq = seq.getDatasetSequence();
1056 int start = m.getStart();
1057 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1068 public void mouseDragged(MouseEvent evt)
1070 if (mouseWheelPressed)
1072 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1073 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1075 int oldWidth = av.getCharWidth();
1077 // Which is bigger, left-right or up-down?
1078 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1079 .abs(evt.getX() - lastMousePress.getX()))
1082 * on drag up or down, decrement or increment font size
1084 int fontSize = av.font.getSize();
1085 boolean fontChanged = false;
1087 if (evt.getY() < lastMousePress.getY())
1092 else if (evt.getY() > lastMousePress.getY())
1105 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1107 av.setFont(newFont, true);
1108 av.setCharWidth(oldWidth);
1112 ap.av.getCodingComplement().setFont(newFont, true);
1113 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1114 .getSplitViewContainer();
1115 splitFrame.adjustLayout();
1116 splitFrame.repaint();
1123 * on drag left or right, decrement or increment character width
1126 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1128 newWidth = av.getCharWidth() - 1;
1129 av.setCharWidth(newWidth);
1131 else if (evt.getX() > lastMousePress.getX())
1133 newWidth = av.getCharWidth() + 1;
1134 av.setCharWidth(newWidth);
1138 ap.paintAlignment(false, false);
1142 * need to ensure newWidth is set on cdna, regardless of which
1143 * panel the mouse drag happened in; protein will compute its
1144 * character width as 1:1 or 3:1
1146 av.getCodingComplement().setCharWidth(newWidth);
1147 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1148 .getSplitViewContainer();
1149 splitFrame.adjustLayout();
1150 splitFrame.repaint();
1155 FontMetrics fm = getFontMetrics(av.getFont());
1156 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1158 lastMousePress = evt.getPoint();
1165 doMouseDraggedDefineMode(evt);
1169 int res = findColumn(evt);
1176 if ((lastres == -1) || (lastres == res))
1181 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1183 // dragLeft, delete gap
1184 editSequence(false, false, res);
1188 editSequence(true, false, res);
1191 mouseDragging = true;
1192 if (scrollThread != null)
1194 scrollThread.setMousePosition(evt.getPoint());
1198 // TODO: Make it more clever than many booleans
1199 synchronized void editSequence(boolean insertGap, boolean editSeq,
1203 int fixedRight = -1;
1204 boolean fixedColumns = false;
1205 SequenceGroup sg = av.getSelectionGroup();
1207 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1209 // No group, but the sequence may represent a group
1210 if (!groupEditing && av.hasHiddenRows())
1212 if (av.isHiddenRepSequence(seq))
1214 sg = av.getRepresentedSequences(seq);
1215 groupEditing = true;
1219 StringBuilder message = new StringBuilder(64);
1222 message.append("Edit group:");
1223 if (editCommand == null)
1225 editCommand = new EditCommand(
1226 MessageManager.getString("action.edit_group"));
1231 message.append("Edit sequence: " + seq.getName());
1232 String label = seq.getName();
1233 if (label.length() > 10)
1235 label = label.substring(0, 10);
1237 if (editCommand == null)
1239 editCommand = new EditCommand(MessageManager
1240 .formatMessage("label.edit_params", new String[]
1247 message.append(" insert ");
1251 message.append(" delete ");
1254 message.append(Math.abs(startres - lastres) + " gaps.");
1255 ap.alignFrame.setStatus(message.toString());
1257 // Are we editing within a selection group?
1258 if (groupEditing || (sg != null
1259 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1261 fixedColumns = true;
1263 // sg might be null as the user may only see 1 sequence,
1264 // but the sequence represents a group
1267 if (!av.isHiddenRepSequence(seq))
1272 sg = av.getRepresentedSequences(seq);
1275 fixedLeft = sg.getStartRes();
1276 fixedRight = sg.getEndRes();
1278 if ((startres < fixedLeft && lastres >= fixedLeft)
1279 || (startres >= fixedLeft && lastres < fixedLeft)
1280 || (startres > fixedRight && lastres <= fixedRight)
1281 || (startres <= fixedRight && lastres > fixedRight))
1287 if (fixedLeft > startres)
1289 fixedRight = fixedLeft - 1;
1292 else if (fixedRight < startres)
1294 fixedLeft = fixedRight;
1299 if (av.hasHiddenColumns())
1301 fixedColumns = true;
1302 int y1 = av.getAlignment().getHiddenColumns()
1303 .getNextHiddenBoundary(true, startres);
1304 int y2 = av.getAlignment().getHiddenColumns()
1305 .getNextHiddenBoundary(false, startres);
1307 if ((insertGap && startres > y1 && lastres < y1)
1308 || (!insertGap && startres < y2 && lastres > y2))
1314 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1315 // Selection spans a hidden region
1316 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1324 fixedRight = y2 - 1;
1331 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1332 int g, groupSize = vseqs.size();
1333 SequenceI[] groupSeqs = new SequenceI[groupSize];
1334 for (g = 0; g < groupSeqs.length; g++)
1336 groupSeqs[g] = vseqs.get(g);
1342 // If the user has selected the whole sequence, and is dragging to
1343 // the right, we can still extend the alignment and selectionGroup
1344 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1345 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1347 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1348 fixedRight = sg.getEndRes();
1351 // Is it valid with fixed columns??
1352 // Find the next gap before the end
1353 // of the visible region boundary
1354 boolean blank = false;
1355 for (; fixedRight > lastres; fixedRight--)
1359 for (g = 0; g < groupSize; g++)
1361 for (int j = 0; j < startres - lastres; j++)
1363 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1378 if (sg.getSize() == av.getAlignment().getHeight())
1380 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1382 .getNextHiddenBoundary(false, startres)))
1388 int alWidth = av.getAlignment().getWidth();
1389 if (av.hasHiddenRows())
1391 int hwidth = av.getAlignment().getHiddenSequences()
1393 if (hwidth > alWidth)
1398 // We can still insert gaps if the selectionGroup
1399 // contains all the sequences
1400 sg.setEndRes(sg.getEndRes() + startres - lastres);
1401 fixedRight = alWidth + startres - lastres;
1412 else if (!insertGap)
1414 // / Are we able to delete?
1415 // ie are all columns blank?
1417 for (g = 0; g < groupSize; g++)
1419 for (int j = startres; j < lastres; j++)
1421 if (groupSeqs[g].getLength() <= j)
1426 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1428 // Not a gap, block edit not valid
1438 // dragging to the right
1439 if (fixedColumns && fixedRight != -1)
1441 for (int j = lastres; j < startres; j++)
1443 insertChar(j, groupSeqs, fixedRight);
1448 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1449 startres - lastres);
1454 // dragging to the left
1455 if (fixedColumns && fixedRight != -1)
1457 for (int j = lastres; j > startres; j--)
1459 deleteChar(startres, groupSeqs, fixedRight);
1464 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1465 lastres - startres);
1471 // ///Editing a single sequence///////////
1475 // dragging to the right
1476 if (fixedColumns && fixedRight != -1)
1478 for (int j = lastres; j < startres; j++)
1480 insertChar(j, new SequenceI[] { seq }, fixedRight);
1485 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1486 startres - lastres);
1493 // dragging to the left
1494 if (fixedColumns && fixedRight != -1)
1496 for (int j = lastres; j > startres; j--)
1498 if (!Comparison.isGap(seq.getCharAt(startres)))
1503 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1508 // could be a keyboard edit trying to delete none gaps
1510 for (int m = startres; m < lastres; m++)
1512 if (!Comparison.isGap(seq.getCharAt(m)))
1521 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1527 {// insertGap==false AND editSeq==TRUE;
1528 if (fixedColumns && fixedRight != -1)
1530 for (int j = lastres; j < startres; j++)
1532 insertChar(j, new SequenceI[] { seq }, fixedRight);
1537 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1538 startres - lastres);
1545 seqCanvas.repaint();
1548 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1550 int blankColumn = fixedColumn;
1551 for (int s = 0; s < seq.length; s++)
1553 // Find the next gap before the end of the visible region boundary
1554 // If lastCol > j, theres a boundary after the gap insertion
1556 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1558 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1560 // Theres a space, so break and insert the gap
1565 if (blankColumn <= j)
1567 blankColumn = fixedColumn;
1573 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1575 appendEdit(Action.INSERT_GAP, seq, j, 1);
1580 * Helper method to add and perform one edit action.
1587 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1591 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1592 av.getAlignment().getGapCharacter());
1594 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1597 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1600 appendEdit(Action.DELETE_GAP, seq, j, 1);
1602 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1606 * On reentering the panel, stops any scrolling that was started on dragging
1612 public void mouseEntered(MouseEvent e)
1622 * On leaving the panel, if the mouse is being dragged, starts a thread to
1623 * scroll it until the mouse is released (in unwrapped mode only)
1628 public void mouseExited(MouseEvent e)
1632 startScrolling(e.getPoint());
1637 * Handler for double-click on a position with one or more sequence features.
1638 * Opens the Amend Features dialog to allow feature details to be amended, or
1639 * the feature deleted.
1642 public void mouseClicked(MouseEvent evt)
1644 SequenceGroup sg = null;
1645 SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
1646 if (evt.getClickCount() > 1)
1648 sg = av.getSelectionGroup();
1649 if (sg != null && sg.getSize() == 1
1650 && sg.getEndRes() - sg.getStartRes() < 2)
1652 av.setSelectionGroup(null);
1655 int column = findColumn(evt);
1658 * find features at the position (if not gapped), or straddling
1659 * the position (if at a gap)
1661 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1662 .findFeaturesAtColumn(sequence, column + 1);
1664 if (!features.isEmpty())
1667 * highlight the first feature at the position on the alignment
1669 SearchResultsI highlight = new SearchResults();
1670 highlight.addResult(sequence, features.get(0).getBegin(), features
1672 seqCanvas.highlightSearchResults(highlight, true);
1675 * open the Amend Features dialog
1677 new FeatureEditor(ap, Collections.singletonList(sequence), features,
1678 false).showDialog();
1684 public void mouseWheelMoved(MouseWheelEvent e)
1687 double wheelRotation = e.getPreciseWheelRotation();
1688 if (wheelRotation > 0)
1690 if (e.isShiftDown())
1692 av.getRanges().scrollRight(true);
1697 av.getRanges().scrollUp(false);
1700 else if (wheelRotation < 0)
1702 if (e.isShiftDown())
1704 av.getRanges().scrollRight(false);
1708 av.getRanges().scrollUp(true);
1713 * update status bar and tooltip for new position
1714 * (need to synthesize a mouse movement to refresh tooltip)
1717 ToolTipManager.sharedInstance().mouseMoved(e);
1726 public void doMousePressedDefineMode(MouseEvent evt)
1728 final int res = findColumn(evt);
1729 final int seq = findSeq(evt);
1731 updateOverviewAndStructs = false;
1733 startWrapBlock = wrappedBlock;
1735 if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
1737 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1738 MessageManager.getString(
1739 "label.cannot_edit_annotations_in_wrapped_view"),
1740 MessageManager.getString("label.wrapped_view_no_edit"),
1741 JvOptionPane.WARNING_MESSAGE);
1745 if (seq < 0 || res < 0)
1750 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1752 if ((sequence == null) || (res > sequence.getLength()))
1757 stretchGroup = av.getSelectionGroup();
1759 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1761 stretchGroup = av.getAlignment().findGroup(sequence, res);
1762 if (stretchGroup != null)
1764 // only update the current selection if the popup menu has a group to
1766 av.setSelectionGroup(stretchGroup);
1770 if (evt.isPopupTrigger()) // Mac: mousePressed
1777 * defer right-mouse click handling to mouseReleased on Windows
1778 * (where isPopupTrigger() will answer true)
1779 * NB isRightMouseButton is also true for Cmd-click on Mac
1781 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1788 seqCanvas.cursorX = findColumn(evt);
1789 seqCanvas.cursorY = findSeq(evt);
1790 seqCanvas.repaint();
1794 if (stretchGroup == null)
1796 createStretchGroup(res, sequence);
1799 if (stretchGroup != null)
1801 stretchGroup.addPropertyChangeListener(seqCanvas);
1804 seqCanvas.repaint();
1807 private void createStretchGroup(int res, SequenceI sequence)
1809 // Only if left mouse button do we want to change group sizes
1810 // define a new group here
1811 SequenceGroup sg = new SequenceGroup();
1812 sg.setStartRes(res);
1814 sg.addSequence(sequence, false);
1815 av.setSelectionGroup(sg);
1818 if (av.getConservationSelected())
1820 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1824 if (av.getAbovePIDThreshold())
1826 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1829 // TODO: stretchGroup will always be not null. Is this a merge error ?
1830 // or is there a threading issue here?
1831 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1833 // Edit end res position of selected group
1834 changeEndRes = true;
1836 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1838 // Edit end res position of selected group
1839 changeStartRes = true;
1841 stretchGroup.getWidth();
1846 * Build and show a pop-up menu at the right-click mouse position
1852 void showPopupMenu(MouseEvent evt)
1854 final int column = findColumn(evt);
1855 final int seq = findSeq(evt);
1856 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1857 List<SequenceFeature> features = ap.getFeatureRenderer()
1858 .findFeaturesAtColumn(sequence, column + 1);
1860 PopupMenu pop = new PopupMenu(ap, null, features);
1861 pop.show(this, evt.getX(), evt.getY());
1865 * Update the display after mouse up on a selection or group
1868 * mouse released event details
1870 * true if this event is happening after a mouse drag (rather than a
1873 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
1875 if (stretchGroup == null)
1880 stretchGroup.removePropertyChangeListener(seqCanvas);
1882 // always do this - annotation has own state
1883 // but defer colourscheme update until hidden sequences are passed in
1884 boolean vischange = stretchGroup.recalcConservation(true);
1885 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
1887 if (stretchGroup.cs != null)
1889 stretchGroup.cs.alignmentChanged(stretchGroup,
1890 av.getHiddenRepSequences());
1892 ResidueShaderI groupColourScheme = stretchGroup
1893 .getGroupColourScheme();
1894 String name = stretchGroup.getName();
1895 if (stretchGroup.cs.conservationApplied())
1897 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
1899 if (stretchGroup.cs.getThreshold() > 0)
1901 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
1904 PaintRefresher.Refresh(this, av.getSequenceSetId());
1905 // TODO: structure colours only need updating if stretchGroup used to or now
1906 // does contain sequences with structure views
1907 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
1908 updateOverviewAndStructs = false;
1909 changeEndRes = false;
1910 changeStartRes = false;
1911 stretchGroup = null;
1921 public void doMouseDraggedDefineMode(MouseEvent evt)
1923 int res = findColumn(evt);
1924 int y = findSeq(evt);
1926 if (wrappedBlock != startWrapBlock)
1931 if (stretchGroup == null)
1936 res = Math.min(res, av.getAlignment().getWidth()-1);
1938 if (stretchGroup.getEndRes() == res)
1940 // Edit end res position of selected group
1941 changeEndRes = true;
1943 else if (stretchGroup.getStartRes() == res)
1945 // Edit start res position of selected group
1946 changeStartRes = true;
1949 if (res < av.getRanges().getStartRes())
1951 res = av.getRanges().getStartRes();
1956 if (res > (stretchGroup.getStartRes() - 1))
1958 stretchGroup.setEndRes(res);
1959 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
1962 else if (changeStartRes)
1964 if (res < (stretchGroup.getEndRes() + 1))
1966 stretchGroup.setStartRes(res);
1967 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
1971 int dragDirection = 0;
1977 else if (y < oldSeq)
1982 while ((y != oldSeq) && (oldSeq > -1)
1983 && (y < av.getAlignment().getHeight()))
1985 // This routine ensures we don't skip any sequences, as the
1986 // selection is quite slow.
1987 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1989 oldSeq += dragDirection;
1996 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1998 if (stretchGroup.getSequences(null).contains(nextSeq))
2000 stretchGroup.deleteSequence(seq, false);
2001 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2007 stretchGroup.addSequence(seq, false);
2010 stretchGroup.addSequence(nextSeq, false);
2011 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2020 mouseDragging = true;
2022 if (scrollThread != null)
2024 scrollThread.setMousePosition(evt.getPoint());
2029 * Stops the scroll thread if it is running
2031 void stopScrolling()
2033 if (scrollThread != null)
2035 scrollThread.stopScrolling();
2036 scrollThread = null;
2038 mouseDragging = false;
2042 * Starts a thread to scroll the alignment, towards a given mouse position
2043 * outside the panel bounds, unless the alignment is in wrapped mode
2047 void startScrolling(Point mousePos)
2050 * set this.mouseDragging in case this was called from
2051 * a drag in ScalePanel or AnnotationPanel
2053 mouseDragging = true;
2054 if (!av.getWrapAlignment() && scrollThread == null)
2056 scrollThread = new ScrollThread();
2057 scrollThread.setMousePosition(mousePos);
2058 if (!Jalview.isJS())
2061 * Java - run in a new thread
2063 scrollThread.start();
2068 * Javascript - run every 20ms until scrolling stopped
2069 * or reaches the limit of scrollable alignment
2071 // java.util.Timer version:
2072 // Timer t = new Timer("ScrollThreadTimer", true);
2073 // TimerTask task = new TimerTask()
2076 // public void run()
2078 // if (!scrollThread.scrollOnce())
2084 // t.schedule(task, 20, 20);
2085 Timer t = new Timer(20, new ActionListener()
2088 public void actionPerformed(ActionEvent e)
2090 if (scrollThread != null)
2092 // if (!scrollOnce() {t.stop();}) gives compiler error :-(
2093 scrollThread.scrollOnce();
2097 t.addActionListener(new ActionListener()
2100 public void actionPerformed(ActionEvent e)
2102 if (scrollThread == null)
2104 // finished and nulled itself
2115 * Performs scrolling of the visible alignment left, right, up or down, until
2116 * scrolling is stopped by calling stopScrolling, mouse drag is ended, or the
2117 * limit of the alignment is reached
2119 class ScrollThread extends Thread
2121 private Point mousePos;
2123 private volatile boolean keepRunning = true;
2128 public ScrollThread()
2130 setName("SeqPanel$ScrollThread");
2134 * Sets the position of the mouse that determines the direction of the
2135 * scroll to perform. If this is called as the mouse moves, scrolling should
2136 * respond accordingly. For example, if the mouse is dragged right, scroll
2137 * right should start; if the drag continues down, scroll down should also
2142 public void setMousePosition(Point p)
2148 * Sets a flag that will cause the thread to exit
2150 public void stopScrolling()
2152 keepRunning = false;
2156 * Scrolls the alignment left or right, and/or up or down, depending on the
2157 * last notified mouse position, until the limit of the alignment is
2158 * reached, or a flag is set to stop the scroll
2165 if (mousePos != null)
2167 keepRunning = scrollOnce();
2172 } catch (Exception ex)
2176 SeqPanel.this.scrollThread = null;
2182 * <li>one row up, if the mouse is above the panel</li>
2183 * <li>one row down, if the mouse is below the panel</li>
2184 * <li>one column left, if the mouse is left of the panel</li>
2185 * <li>one column right, if the mouse is right of the panel</li>
2187 * Answers true if a scroll was performed, false if not - meaning either
2188 * that the mouse position is within the panel, or the edge of the alignment
2191 boolean scrollOnce()
2194 * quit after mouseUp ensures interrupt in JalviewJS
2201 boolean scrolled = false;
2202 ViewportRanges ranges = SeqPanel.this.av.getRanges();
2209 // mouse is above this panel - try scroll up
2210 scrolled = ranges.scrollUp(true);
2212 else if (mousePos.y >= getHeight())
2214 // mouse is below this panel - try scroll down
2215 scrolled = ranges.scrollUp(false);
2219 * scroll left or right
2223 scrolled |= ranges.scrollRight(false);
2225 else if (mousePos.x >= getWidth())
2227 scrolled |= ranges.scrollRight(true);
2234 * modify current selection according to a received message.
2237 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2238 HiddenColumns hidden, SelectionSource source)
2240 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2241 // handles selection messages...
2242 // TODO: extend config options to allow user to control if selections may be
2243 // shared between viewports.
2244 boolean iSentTheSelection = (av == source
2245 || (source instanceof AlignViewport
2246 && ((AlignmentViewport) source).getSequenceSetId()
2247 .equals(av.getSequenceSetId())));
2249 if (iSentTheSelection)
2251 // respond to our own event by updating dependent dialogs
2252 if (ap.getCalculationDialog() != null)
2254 ap.getCalculationDialog().validateCalcTypes();
2260 // process further ?
2261 if (!av.followSelection)
2267 * Ignore the selection if there is one of our own pending.
2269 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2275 * Check for selection in a view of which this one is a dna/protein
2278 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2283 // do we want to thread this ? (contention with seqsel and colsel locks, I
2286 * only copy colsel if there is a real intersection between
2287 * sequence selection and this panel's alignment
2289 boolean repaint = false;
2290 boolean copycolsel = false;
2292 SequenceGroup sgroup = null;
2293 if (seqsel != null && seqsel.getSize() > 0)
2295 if (av.getAlignment() == null)
2297 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2298 + " ViewId=" + av.getViewId()
2299 + " 's alignment is NULL! returning immediately.");
2302 sgroup = seqsel.intersect(av.getAlignment(),
2303 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2304 if ((sgroup != null && sgroup.getSize() > 0))
2309 if (sgroup != null && sgroup.getSize() > 0)
2311 av.setSelectionGroup(sgroup);
2315 av.setSelectionGroup(null);
2317 av.isSelectionGroupChanged(true);
2322 // the current selection is unset or from a previous message
2323 // so import the new colsel.
2324 if (colsel == null || colsel.isEmpty())
2326 if (av.getColumnSelection() != null)
2328 av.getColumnSelection().clear();
2334 // TODO: shift colSel according to the intersecting sequences
2335 if (av.getColumnSelection() == null)
2337 av.setColumnSelection(new ColumnSelection(colsel));
2341 av.getColumnSelection().setElementsFrom(colsel,
2342 av.getAlignment().getHiddenColumns());
2345 av.isColSelChanged(true);
2349 if (copycolsel && av.hasHiddenColumns()
2350 && (av.getAlignment().getHiddenColumns() == null))
2352 System.err.println("Bad things");
2354 if (repaint) // always true!
2356 // probably finessing with multiple redraws here
2357 PaintRefresher.Refresh(this, av.getSequenceSetId());
2358 // ap.paintAlignment(false);
2361 // lastly, update dependent dialogs
2362 if (ap.getCalculationDialog() != null)
2364 ap.getCalculationDialog().validateCalcTypes();
2370 * If this panel is a cdna/protein translation view of the selection source,
2371 * tries to map the source selection to a local one, and returns true. Else
2378 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2379 ColumnSelection colsel, HiddenColumns hidden,
2380 SelectionSource source)
2382 if (!(source instanceof AlignViewportI))
2386 final AlignViewportI sourceAv = (AlignViewportI) source;
2387 if (sourceAv.getCodingComplement() != av
2388 && av.getCodingComplement() != sourceAv)
2394 * Map sequence selection
2396 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2397 av.setSelectionGroup(sg);
2398 av.isSelectionGroupChanged(true);
2401 * Map column selection
2403 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2405 ColumnSelection cs = new ColumnSelection();
2406 HiddenColumns hs = new HiddenColumns();
2407 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2408 av.setColumnSelection(cs);
2409 av.getAlignment().setHiddenColumns(hs);
2411 // lastly, update any dependent dialogs
2412 if (ap.getCalculationDialog() != null)
2414 ap.getCalculationDialog().validateCalcTypes();
2417 PaintRefresher.Refresh(this, av.getSequenceSetId());
2424 * @return null or last search results handled by this panel
2426 public SearchResultsI getLastSearchResults()
2428 return lastSearchResults;