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.MappedFeatures;
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.seqfeatures.FeatureRendererModel;
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.MouseEvent;
60 import java.awt.event.MouseListener;
61 import java.awt.event.MouseMotionListener;
62 import java.awt.event.MouseWheelEvent;
63 import java.awt.event.MouseWheelListener;
64 import java.util.ArrayList;
65 import java.util.Collections;
66 import java.util.List;
68 import javax.swing.JPanel;
69 import javax.swing.SwingUtilities;
70 import javax.swing.ToolTipManager;
76 * @version $Revision: 1.130 $
78 public class SeqPanel extends JPanel
79 implements MouseListener, MouseMotionListener, MouseWheelListener,
80 SequenceListener, SelectionListener
82 private static final int MAX_TOOLTIP_LENGTH = 300;
84 public SeqCanvas seqCanvas;
86 public AlignmentPanel ap;
89 * last column position for mouseMoved event
91 private int lastMouseColumn;
94 * last sequence offset for mouseMoved event
96 private int lastMouseSeq;
98 protected int lastres;
100 protected int startseq;
102 protected AlignViewport av;
104 ScrollThread scrollThread = null;
106 boolean mouseDragging = false;
108 boolean editingSeqs = false;
110 boolean groupEditing = false;
112 // ////////////////////////////////////////
113 // ///Everything below this is for defining the boundary of the rubberband
114 // ////////////////////////////////////////
117 boolean changeEndSeq = false;
119 boolean changeStartSeq = false;
121 boolean changeEndRes = false;
123 boolean changeStartRes = false;
125 SequenceGroup stretchGroup = null;
127 boolean remove = false;
129 Point lastMousePress;
131 boolean mouseWheelPressed = false;
133 StringBuffer keyboardNo1;
135 StringBuffer keyboardNo2;
137 java.net.URL linkImageURL;
139 private final SequenceAnnotationReport seqARep;
141 StringBuilder tooltipText = new StringBuilder();
145 EditCommand editCommand;
147 StructureSelectionManager ssm;
149 SearchResultsI lastSearchResults;
152 * Creates a new SeqPanel object
157 public SeqPanel(AlignViewport viewport, AlignmentPanel alignPanel)
159 linkImageURL = getClass().getResource("/images/link.gif");
160 seqARep = new SequenceAnnotationReport(linkImageURL.toString());
161 ToolTipManager.sharedInstance().registerComponent(this);
162 ToolTipManager.sharedInstance().setInitialDelay(0);
163 ToolTipManager.sharedInstance().setDismissDelay(10000);
165 setBackground(Color.white);
167 seqCanvas = new SeqCanvas(alignPanel);
168 setLayout(new BorderLayout());
169 add(seqCanvas, BorderLayout.CENTER);
171 this.ap = alignPanel;
173 if (!viewport.isDataset())
175 addMouseMotionListener(this);
176 addMouseListener(this);
177 addMouseWheelListener(this);
178 ssm = viewport.getStructureSelectionManager();
179 ssm.addStructureViewerListener(this);
180 ssm.addSelectionListener(this);
183 lastMouseColumn = -1;
187 int startWrapBlock = -1;
189 int wrappedBlock = -1;
192 * Returns the aligned sequence position (base 0) at the mouse position, or
193 * the closest visible one
198 int findColumn(MouseEvent evt)
203 int startRes = av.getRanges().getStartRes();
204 if (av.getWrapAlignment())
207 int hgap = av.getCharHeight();
208 if (av.getScaleAboveWrapped())
210 hgap += av.getCharHeight();
213 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
214 + hgap + seqCanvas.getAnnotationHeight();
217 y = Math.max(0, y - hgap);
218 x = Math.max(0, x - seqCanvas.getLabelWidthWest());
220 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
226 wrappedBlock = y / cHeight;
227 wrappedBlock += startRes / cwidth;
228 // allow for wrapped view scrolled right (possible from Overview)
229 int startOffset = startRes % cwidth;
230 res = wrappedBlock * cwidth + startOffset
231 + +Math.min(cwidth - 1, x / av.getCharWidth());
235 if (x > seqCanvas.getX() + seqCanvas.getWidth())
237 // make sure we calculate relative to visible alignment, rather than
239 x = seqCanvas.getX() + seqCanvas.getWidth();
241 res = (x / av.getCharWidth()) + startRes;
242 if (res > av.getRanges().getEndRes())
245 res = av.getRanges().getEndRes();
249 if (av.hasHiddenColumns())
251 res = av.getAlignment().getHiddenColumns()
252 .visibleToAbsoluteColumn(res);
259 int findSeq(MouseEvent evt)
264 if (av.getWrapAlignment())
266 int hgap = av.getCharHeight();
267 if (av.getScaleAboveWrapped())
269 hgap += av.getCharHeight();
272 int cHeight = av.getAlignment().getHeight() * av.getCharHeight()
273 + hgap + seqCanvas.getAnnotationHeight();
277 seq = Math.min((y % cHeight) / av.getCharHeight(),
278 av.getAlignment().getHeight() - 1);
283 (y / av.getCharHeight()) + av.getRanges().getStartSeq(),
284 av.getAlignment().getHeight() - 1);
291 * When all of a sequence of edits are complete, put the resulting edit list
292 * on the history stack (undo list), and reset flags for editing in progress.
298 if (editCommand != null && editCommand.getSize() > 0)
300 ap.alignFrame.addHistoryItem(editCommand);
301 av.firePropertyChange("alignment", null,
302 av.getAlignment().getSequences());
307 * Tidy up come what may...
312 groupEditing = false;
321 seqCanvas.cursorY = getKeyboardNo1() - 1;
322 scrollToVisible(true);
325 void setCursorColumn()
327 seqCanvas.cursorX = getKeyboardNo1() - 1;
328 scrollToVisible(true);
331 void setCursorRowAndColumn()
333 if (keyboardNo2 == null)
335 keyboardNo2 = new StringBuffer();
339 seqCanvas.cursorX = getKeyboardNo1() - 1;
340 seqCanvas.cursorY = getKeyboardNo2() - 1;
341 scrollToVisible(true);
345 void setCursorPosition()
347 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
349 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
350 scrollToVisible(true);
353 void moveCursor(int dx, int dy)
355 seqCanvas.cursorX += dx;
356 seqCanvas.cursorY += dy;
358 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
360 if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX))
362 int original = seqCanvas.cursorX - dx;
363 int maxWidth = av.getAlignment().getWidth();
365 if (!hidden.isVisible(seqCanvas.cursorX))
367 int visx = hidden.absoluteToVisibleColumn(seqCanvas.cursorX - dx);
368 int[] region = hidden.getRegionWithEdgeAtRes(visx);
370 if (region != null) // just in case
375 seqCanvas.cursorX = region[1] + 1;
380 seqCanvas.cursorX = region[0] - 1;
383 seqCanvas.cursorX = (seqCanvas.cursorX < 0) ? 0 : seqCanvas.cursorX;
386 if (seqCanvas.cursorX >= maxWidth
387 || !hidden.isVisible(seqCanvas.cursorX))
389 seqCanvas.cursorX = original;
393 scrollToVisible(false);
397 * Scroll to make the cursor visible in the viewport.
400 * just jump to the location rather than scrolling
402 void scrollToVisible(boolean jump)
404 if (seqCanvas.cursorX < 0)
406 seqCanvas.cursorX = 0;
408 else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
410 seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
413 if (seqCanvas.cursorY < 0)
415 seqCanvas.cursorY = 0;
417 else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
419 seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
424 boolean repaintNeeded = true;
427 // only need to repaint if the viewport did not move, as otherwise it will
429 repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX,
434 if (av.getWrapAlignment())
436 // scrollToWrappedVisible expects x-value to have hidden cols subtracted
437 int x = av.getAlignment().getHiddenColumns()
438 .absoluteToVisibleColumn(seqCanvas.cursorX);
439 av.getRanges().scrollToWrappedVisible(x);
443 av.getRanges().scrollToVisible(seqCanvas.cursorX,
448 if (av.getAlignment().getHiddenColumns().isVisible(seqCanvas.cursorX))
450 setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
451 seqCanvas.cursorX, seqCanvas.cursorY);
461 void setSelectionAreaAtCursor(boolean topLeft)
463 SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY);
465 if (av.getSelectionGroup() != null)
467 SequenceGroup sg = av.getSelectionGroup();
468 // Find the top and bottom of this group
469 int min = av.getAlignment().getHeight(), max = 0;
470 for (int i = 0; i < sg.getSize(); i++)
472 int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
487 sg.setStartRes(seqCanvas.cursorX);
488 if (sg.getEndRes() < seqCanvas.cursorX)
490 sg.setEndRes(seqCanvas.cursorX);
493 min = seqCanvas.cursorY;
497 sg.setEndRes(seqCanvas.cursorX);
498 if (sg.getStartRes() > seqCanvas.cursorX)
500 sg.setStartRes(seqCanvas.cursorX);
503 max = seqCanvas.cursorY + 1;
508 // Only the user can do this
509 av.setSelectionGroup(null);
513 // Now add any sequences between min and max
514 sg.getSequences(null).clear();
515 for (int i = min; i < max; i++)
517 sg.addSequence(av.getAlignment().getSequenceAt(i), false);
522 if (av.getSelectionGroup() == null)
524 SequenceGroup sg = new SequenceGroup();
525 sg.setStartRes(seqCanvas.cursorX);
526 sg.setEndRes(seqCanvas.cursorX);
527 sg.addSequence(sequence, false);
528 av.setSelectionGroup(sg);
531 ap.paintAlignment(false, false);
535 void insertGapAtCursor(boolean group)
537 groupEditing = group;
538 startseq = seqCanvas.cursorY;
539 lastres = seqCanvas.cursorX;
540 editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
544 void deleteGapAtCursor(boolean group)
546 groupEditing = group;
547 startseq = seqCanvas.cursorY;
548 lastres = seqCanvas.cursorX + getKeyboardNo1();
549 editSequence(false, false, seqCanvas.cursorX);
553 void insertNucAtCursor(boolean group, String nuc)
555 // TODO not called - delete?
556 groupEditing = group;
557 startseq = seqCanvas.cursorY;
558 lastres = seqCanvas.cursorX;
559 editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
563 void numberPressed(char value)
565 if (keyboardNo1 == null)
567 keyboardNo1 = new StringBuffer();
570 if (keyboardNo2 != null)
572 keyboardNo2.append(value);
576 keyboardNo1.append(value);
584 if (keyboardNo1 != null)
586 int value = Integer.parseInt(keyboardNo1.toString());
590 } catch (Exception x)
601 if (keyboardNo2 != null)
603 int value = Integer.parseInt(keyboardNo2.toString());
607 } catch (Exception x)
621 public void mouseReleased(MouseEvent evt)
623 boolean didDrag = mouseDragging; // did we come here after a drag
624 mouseDragging = false;
625 mouseWheelPressed = false;
627 if (evt.isPopupTrigger()) // Windows: mouseReleased
636 doMouseReleasedDefineMode(evt, didDrag);
650 public void mousePressed(MouseEvent evt)
652 lastMousePress = evt.getPoint();
654 if (SwingUtilities.isMiddleMouseButton(evt))
656 mouseWheelPressed = true;
660 boolean isControlDown = Platform.isControlDown(evt);
661 if (evt.isShiftDown() || isControlDown)
671 doMousePressedDefineMode(evt);
675 int seq = findSeq(evt);
676 int res = findColumn(evt);
678 if (seq < 0 || res < 0)
683 if ((seq < av.getAlignment().getHeight())
684 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
701 public void mouseOverSequence(SequenceI sequence, int index, int pos)
703 String tmp = sequence.hashCode() + " " + index + " " + pos;
705 if (lastMessage == null || !lastMessage.equals(tmp))
707 // System.err.println("mouseOver Sequence: "+tmp);
708 ssm.mouseOverSequence(sequence, index, pos, av);
714 * Highlight the mapped region described by the search results object (unless
715 * unchanged). This supports highlight of protein while mousing over linked
716 * cDNA and vice versa. The status bar is also updated to show the location of
717 * the start of the highlighted region.
720 public String highlightSequence(SearchResultsI results)
722 if (results == null || results.equals(lastSearchResults))
726 lastSearchResults = results;
728 boolean wasScrolled = false;
730 if (av.isFollowHighlight())
732 // don't allow highlight of protein/cDNA to also scroll a complementary
733 // panel,as this sets up a feedback loop (scrolling panel 1 causes moused
734 // over residue to change abruptly, causing highlighted residue in panel 2
735 // to change, causing a scroll in panel 1 etc)
736 ap.setToScrollComplementPanel(false);
737 wasScrolled = ap.scrollToPosition(results, false);
740 seqCanvas.revalidate();
742 ap.setToScrollComplementPanel(true);
745 boolean noFastPaint = wasScrolled && av.getWrapAlignment();
746 if (seqCanvas.highlightSearchResults(results, noFastPaint))
748 setStatusMessage(results);
750 return results.isEmpty() ? null : getHighlightInfo(results);
754 * temporary hack: answers a message suitable to show on structure hover
755 * label. This is normally null. It is a peptide variation description if
757 * <li>results are a single residue in a protein alignment</li>
758 * <li>there is a mapping to a coding sequence (codon)</li>
759 * <li>there are one or more SNP variant features on the codon</li>
761 * in which case the answer is of the format (e.g.) "p.Glu388Asp"
766 private String getHighlightInfo(SearchResultsI results)
769 * ideally, just find mapped CDS (as we don't care about render style here);
770 * for now, go via split frame complement's FeatureRenderer
772 AlignViewportI complement = ap.getAlignViewport().getCodingComplement();
773 if (complement == null)
777 AlignFrame af = Desktop.getAlignFrameFor(complement);
778 FeatureRendererModel fr2 = af.getFeatureRenderer();
780 int j = results.getSize();
781 List<String> infos = new ArrayList<>();
782 for (int i = 0; i < j; i++)
784 SearchResultMatchI match = results.getResults().get(i);
785 int pos = match.getStart();
786 if (pos == match.getEnd())
788 SequenceI seq = match.getSequence();
789 SequenceI ds = seq.getDatasetSequence() == null ? seq
790 : seq.getDatasetSequence();
791 MappedFeatures mf = fr2
792 .findComplementFeaturesAtResidue(ds, pos);
793 List<String> pv = mf.findProteinVariants();
796 if (!infos.contains(s))
808 StringBuilder sb = new StringBuilder();
809 for (String info : infos)
817 return sb.toString();
821 public VamsasSource getVamsasSource()
823 return this.ap == null ? null : this.ap.av;
827 public void updateColours(SequenceI seq, int index)
829 System.out.println("update the seqPanel colours");
834 * Action on mouse movement is to update the status bar to show the current
835 * sequence position, and (if features are shown) to show any features at the
836 * position in a tooltip. Does nothing if the mouse move does not change
842 public void mouseMoved(MouseEvent evt)
846 // This is because MacOSX creates a mouseMoved
847 // If control is down, other platforms will not.
851 final int column = findColumn(evt);
852 final int seq = findSeq(evt);
854 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
859 if (column == lastMouseColumn && seq == lastMouseSeq)
862 * just a pixel move without change of residue
866 lastMouseColumn = column;
869 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
871 if (column >= sequence.getLength())
877 * set status bar message, returning residue position in sequence
879 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
880 final int pos = setStatusMessage(sequence, column, seq);
881 if (ssm != null && !isGapped)
883 mouseOverSequence(sequence, column, pos);
886 tooltipText.setLength(6); // Cuts the buffer back to <html>
888 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
891 for (int g = 0; g < groups.length; g++)
893 if (groups[g].getStartRes() <= column
894 && groups[g].getEndRes() >= column)
896 if (!groups[g].getName().startsWith("JTreeGroup")
897 && !groups[g].getName().startsWith("JGroup"))
899 tooltipText.append(groups[g].getName());
902 if (groups[g].getDescription() != null)
904 tooltipText.append(": " + groups[g].getDescription());
911 * add any features at the position to the tooltip; if over a gap, only
912 * add features that straddle the gap (pos may be the residue before or
915 if (av.isShowSequenceFeatures())
917 List<SequenceFeature> features = ap.getFeatureRenderer()
918 .findFeaturesAtColumn(sequence, column + 1);
919 seqARep.appendFeatures(tooltipText, pos, features,
920 this.ap.getSeqPanel().seqCanvas.fr);
923 * add features in CDS/protein complement at the corresponding
924 * position if configured to do so
926 if (av.isShowComplementFeatures())
928 if (!Comparison.isGap(sequence.getCharAt(column)))
930 AlignViewportI complement = ap.getAlignViewport()
931 .getCodingComplement();
932 AlignFrame af = Desktop.getAlignFrameFor(complement);
933 FeatureRendererModel fr2 = af.getFeatureRenderer();
934 MappedFeatures mf = fr2.findComplementFeaturesAtResidue(sequence,
936 seqARep.appendFeatures(tooltipText, pos, mf.features, fr2);
940 if (tooltipText.length() == 6) // <html>
942 setToolTipText(null);
947 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
949 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
950 tooltipText.append("...");
952 String textString = tooltipText.toString();
953 if (lastTooltip == null || !lastTooltip.equals(textString))
955 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
957 setToolTipText(formattedTooltipText);
958 lastTooltip = textString;
963 private Point lastp = null;
968 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
971 public Point getToolTipLocation(MouseEvent event)
973 int x = event.getX(), w = getWidth();
974 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
977 if (!event.isShiftDown() || p == null)
979 p = (tooltipText != null && tooltipText.length() > 6)
980 ? new Point(event.getX() + wdth, event.getY() - 20)
984 * TODO: try to modify position region is not obcured by tooltip
992 * set when the current UI interaction has resulted in a change that requires
993 * shading in overviews and structures to be recalculated. this could be
994 * changed to a something more expressive that indicates what actually has
995 * changed, so selective redraws can be applied (ie. only structures, only
998 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1001 * set if av.getSelectionGroup() refers to a group that is defined on the
1002 * alignment view, rather than a transient selection
1004 // private boolean editingDefinedGroup = false; // TODO: refactor to
1005 // avcontroller or viewModel
1008 * Sets the status message in alignment panel, showing the sequence number
1009 * (index) and id, and residue and residue position if not at a gap, for the
1010 * given sequence and column position. Returns the residue position returned
1011 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1012 * if at a gapped position.
1015 * aligned sequence object
1019 * index of sequence in alignment
1020 * @return sequence position of residue at column, or adjacent residue if at a
1023 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1025 char sequenceChar = sequence.getCharAt(column);
1026 int pos = sequence.findPosition(column);
1027 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1033 * Builds the status message for the current cursor location and writes it to
1034 * the status bar, for example
1037 * Sequence 3 ID: FER1_SOLLC
1038 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1039 * Sequence 5 ID: FER1_PEA Residue: B (3)
1040 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1045 * sequence position in the alignment (1..)
1046 * @param sequenceChar
1047 * the character under the cursor
1049 * the sequence residue position (if not over a gap)
1051 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1052 char sequenceChar, int residuePos)
1054 StringBuilder text = new StringBuilder(32);
1057 * Sequence number (if known), and sequence name.
1059 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1060 text.append("Sequence").append(seqno).append(" ID: ")
1061 .append(sequence.getName());
1063 String residue = null;
1066 * Try to translate the display character to residue name (null for gap).
1068 boolean isGapped = Comparison.isGap(sequenceChar);
1072 boolean nucleotide = av.getAlignment().isNucleotide();
1073 String displayChar = String.valueOf(sequenceChar);
1076 residue = ResidueProperties.nucleotideName.get(displayChar);
1080 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1081 : ("*".equals(displayChar) ? "STOP"
1082 : ResidueProperties.aa2Triplet.get(displayChar));
1084 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1085 .append(": ").append(residue == null ? displayChar : residue);
1087 text.append(" (").append(Integer.toString(residuePos)).append(")");
1089 ap.alignFrame.statusBar.setText(text.toString());
1093 * Set the status bar message to highlight the first matched position in
1098 private void setStatusMessage(SearchResultsI results)
1100 AlignmentI al = this.av.getAlignment();
1101 int sequenceIndex = al.findIndex(results);
1102 if (sequenceIndex == -1)
1106 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1107 for (SearchResultMatchI m : results.getResults())
1109 SequenceI seq = m.getSequence();
1110 if (seq.getDatasetSequence() != null)
1112 seq = seq.getDatasetSequence();
1117 int start = m.getStart();
1118 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1129 public void mouseDragged(MouseEvent evt)
1131 if (mouseWheelPressed)
1133 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1134 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1136 int oldWidth = av.getCharWidth();
1138 // Which is bigger, left-right or up-down?
1139 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1140 .abs(evt.getX() - lastMousePress.getX()))
1143 * on drag up or down, decrement or increment font size
1145 int fontSize = av.font.getSize();
1146 boolean fontChanged = false;
1148 if (evt.getY() < lastMousePress.getY())
1153 else if (evt.getY() > lastMousePress.getY())
1166 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1168 av.setFont(newFont, true);
1169 av.setCharWidth(oldWidth);
1173 ap.av.getCodingComplement().setFont(newFont, true);
1174 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1175 .getSplitViewContainer();
1176 splitFrame.adjustLayout();
1177 splitFrame.repaint();
1184 * on drag left or right, decrement or increment character width
1187 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1189 newWidth = av.getCharWidth() - 1;
1190 av.setCharWidth(newWidth);
1192 else if (evt.getX() > lastMousePress.getX())
1194 newWidth = av.getCharWidth() + 1;
1195 av.setCharWidth(newWidth);
1199 ap.paintAlignment(false, false);
1203 * need to ensure newWidth is set on cdna, regardless of which
1204 * panel the mouse drag happened in; protein will compute its
1205 * character width as 1:1 or 3:1
1207 av.getCodingComplement().setCharWidth(newWidth);
1208 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1209 .getSplitViewContainer();
1210 splitFrame.adjustLayout();
1211 splitFrame.repaint();
1216 FontMetrics fm = getFontMetrics(av.getFont());
1217 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1219 lastMousePress = evt.getPoint();
1226 doMouseDraggedDefineMode(evt);
1230 int res = findColumn(evt);
1237 if ((lastres == -1) || (lastres == res))
1242 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1244 // dragLeft, delete gap
1245 editSequence(false, false, res);
1249 editSequence(true, false, res);
1252 mouseDragging = true;
1253 if ((scrollThread != null) && (scrollThread.isRunning()))
1255 scrollThread.setEvent(evt);
1259 // TODO: Make it more clever than many booleans
1260 synchronized void editSequence(boolean insertGap, boolean editSeq,
1264 int fixedRight = -1;
1265 boolean fixedColumns = false;
1266 SequenceGroup sg = av.getSelectionGroup();
1268 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1270 // No group, but the sequence may represent a group
1271 if (!groupEditing && av.hasHiddenRows())
1273 if (av.isHiddenRepSequence(seq))
1275 sg = av.getRepresentedSequences(seq);
1276 groupEditing = true;
1280 StringBuilder message = new StringBuilder(64);
1283 message.append("Edit group:");
1284 if (editCommand == null)
1286 editCommand = new EditCommand(
1287 MessageManager.getString("action.edit_group"));
1292 message.append("Edit sequence: " + seq.getName());
1293 String label = seq.getName();
1294 if (label.length() > 10)
1296 label = label.substring(0, 10);
1298 if (editCommand == null)
1300 editCommand = new EditCommand(MessageManager
1301 .formatMessage("label.edit_params", new String[]
1308 message.append(" insert ");
1312 message.append(" delete ");
1315 message.append(Math.abs(startres - lastres) + " gaps.");
1316 ap.alignFrame.statusBar.setText(message.toString());
1318 // Are we editing within a selection group?
1319 if (groupEditing || (sg != null
1320 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1322 fixedColumns = true;
1324 // sg might be null as the user may only see 1 sequence,
1325 // but the sequence represents a group
1328 if (!av.isHiddenRepSequence(seq))
1333 sg = av.getRepresentedSequences(seq);
1336 fixedLeft = sg.getStartRes();
1337 fixedRight = sg.getEndRes();
1339 if ((startres < fixedLeft && lastres >= fixedLeft)
1340 || (startres >= fixedLeft && lastres < fixedLeft)
1341 || (startres > fixedRight && lastres <= fixedRight)
1342 || (startres <= fixedRight && lastres > fixedRight))
1348 if (fixedLeft > startres)
1350 fixedRight = fixedLeft - 1;
1353 else if (fixedRight < startres)
1355 fixedLeft = fixedRight;
1360 if (av.hasHiddenColumns())
1362 fixedColumns = true;
1363 int y1 = av.getAlignment().getHiddenColumns()
1364 .getNextHiddenBoundary(true, startres);
1365 int y2 = av.getAlignment().getHiddenColumns()
1366 .getNextHiddenBoundary(false, startres);
1368 if ((insertGap && startres > y1 && lastres < y1)
1369 || (!insertGap && startres < y2 && lastres > y2))
1375 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1376 // Selection spans a hidden region
1377 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1385 fixedRight = y2 - 1;
1392 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1393 int g, groupSize = vseqs.size();
1394 SequenceI[] groupSeqs = new SequenceI[groupSize];
1395 for (g = 0; g < groupSeqs.length; g++)
1397 groupSeqs[g] = vseqs.get(g);
1403 // If the user has selected the whole sequence, and is dragging to
1404 // the right, we can still extend the alignment and selectionGroup
1405 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1406 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1408 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1409 fixedRight = sg.getEndRes();
1412 // Is it valid with fixed columns??
1413 // Find the next gap before the end
1414 // of the visible region boundary
1415 boolean blank = false;
1416 for (; fixedRight > lastres; fixedRight--)
1420 for (g = 0; g < groupSize; g++)
1422 for (int j = 0; j < startres - lastres; j++)
1424 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1439 if (sg.getSize() == av.getAlignment().getHeight())
1441 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1443 .getNextHiddenBoundary(false, startres)))
1449 int alWidth = av.getAlignment().getWidth();
1450 if (av.hasHiddenRows())
1452 int hwidth = av.getAlignment().getHiddenSequences()
1454 if (hwidth > alWidth)
1459 // We can still insert gaps if the selectionGroup
1460 // contains all the sequences
1461 sg.setEndRes(sg.getEndRes() + startres - lastres);
1462 fixedRight = alWidth + startres - lastres;
1473 else if (!insertGap)
1475 // / Are we able to delete?
1476 // ie are all columns blank?
1478 for (g = 0; g < groupSize; g++)
1480 for (int j = startres; j < lastres; j++)
1482 if (groupSeqs[g].getLength() <= j)
1487 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1489 // Not a gap, block edit not valid
1499 // dragging to the right
1500 if (fixedColumns && fixedRight != -1)
1502 for (int j = lastres; j < startres; j++)
1504 insertChar(j, groupSeqs, fixedRight);
1509 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1510 startres - lastres);
1515 // dragging to the left
1516 if (fixedColumns && fixedRight != -1)
1518 for (int j = lastres; j > startres; j--)
1520 deleteChar(startres, groupSeqs, fixedRight);
1525 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1526 lastres - startres);
1532 // ///Editing a single sequence///////////
1536 // dragging to the right
1537 if (fixedColumns && fixedRight != -1)
1539 for (int j = lastres; j < startres; j++)
1541 insertChar(j, new SequenceI[] { seq }, fixedRight);
1546 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1547 startres - lastres);
1554 // dragging to the left
1555 if (fixedColumns && fixedRight != -1)
1557 for (int j = lastres; j > startres; j--)
1559 if (!Comparison.isGap(seq.getCharAt(startres)))
1564 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1569 // could be a keyboard edit trying to delete none gaps
1571 for (int m = startres; m < lastres; m++)
1573 if (!Comparison.isGap(seq.getCharAt(m)))
1582 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1588 {// insertGap==false AND editSeq==TRUE;
1589 if (fixedColumns && fixedRight != -1)
1591 for (int j = lastres; j < startres; j++)
1593 insertChar(j, new SequenceI[] { seq }, fixedRight);
1598 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1599 startres - lastres);
1606 seqCanvas.repaint();
1609 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1611 int blankColumn = fixedColumn;
1612 for (int s = 0; s < seq.length; s++)
1614 // Find the next gap before the end of the visible region boundary
1615 // If lastCol > j, theres a boundary after the gap insertion
1617 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1619 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1621 // Theres a space, so break and insert the gap
1626 if (blankColumn <= j)
1628 blankColumn = fixedColumn;
1634 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1636 appendEdit(Action.INSERT_GAP, seq, j, 1);
1641 * Helper method to add and perform one edit action.
1648 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1652 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1653 av.getAlignment().getGapCharacter());
1655 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1658 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1661 appendEdit(Action.DELETE_GAP, seq, j, 1);
1663 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1673 public void mouseEntered(MouseEvent e)
1680 if ((scrollThread != null) && (scrollThread.isRunning()))
1682 scrollThread.stopScrolling();
1683 scrollThread = null;
1694 public void mouseExited(MouseEvent e)
1696 if (av.getWrapAlignment())
1701 if (mouseDragging && scrollThread == null)
1703 scrollThread = new ScrollThread();
1708 * Handler for double-click on a position with one or more sequence features.
1709 * Opens the Amend Features dialog to allow feature details to be amended, or
1710 * the feature deleted.
1713 public void mouseClicked(MouseEvent evt)
1715 SequenceGroup sg = null;
1716 SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
1717 if (evt.getClickCount() > 1)
1719 sg = av.getSelectionGroup();
1720 if (sg != null && sg.getSize() == 1
1721 && sg.getEndRes() - sg.getStartRes() < 2)
1723 av.setSelectionGroup(null);
1726 int column = findColumn(evt);
1729 * find features at the position (if not gapped), or straddling
1730 * the position (if at a gap)
1732 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1733 .findFeaturesAtColumn(sequence, column + 1);
1735 if (!features.isEmpty())
1738 * highlight the first feature at the position on the alignment
1740 SearchResultsI highlight = new SearchResults();
1741 highlight.addResult(sequence, features.get(0).getBegin(), features
1743 seqCanvas.highlightSearchResults(highlight, false);
1746 * open the Amend Features dialog; clear highlighting afterwards,
1747 * whether changes were made or not
1749 List<SequenceI> seqs = Collections.singletonList(sequence);
1750 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1752 av.setSearchResults(null); // clear highlighting
1753 seqCanvas.repaint(); // draw new/amended features
1759 public void mouseWheelMoved(MouseWheelEvent e)
1762 double wheelRotation = e.getPreciseWheelRotation();
1763 if (wheelRotation > 0)
1765 if (e.isShiftDown())
1767 av.getRanges().scrollRight(true);
1772 av.getRanges().scrollUp(false);
1775 else if (wheelRotation < 0)
1777 if (e.isShiftDown())
1779 av.getRanges().scrollRight(false);
1783 av.getRanges().scrollUp(true);
1788 * update status bar and tooltip for new position
1789 * (need to synthesize a mouse movement to refresh tooltip)
1792 ToolTipManager.sharedInstance().mouseMoved(e);
1801 public void doMousePressedDefineMode(MouseEvent evt)
1803 final int res = findColumn(evt);
1804 final int seq = findSeq(evt);
1806 updateOverviewAndStructs = false;
1808 startWrapBlock = wrappedBlock;
1810 if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
1812 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1813 MessageManager.getString(
1814 "label.cannot_edit_annotations_in_wrapped_view"),
1815 MessageManager.getString("label.wrapped_view_no_edit"),
1816 JvOptionPane.WARNING_MESSAGE);
1820 if (seq < 0 || res < 0)
1825 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1827 if ((sequence == null) || (res > sequence.getLength()))
1832 stretchGroup = av.getSelectionGroup();
1834 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1836 stretchGroup = av.getAlignment().findGroup(sequence, res);
1837 if (stretchGroup != null)
1839 // only update the current selection if the popup menu has a group to
1841 av.setSelectionGroup(stretchGroup);
1845 if (evt.isPopupTrigger()) // Mac: mousePressed
1852 * defer right-mouse click handling to mouseReleased on Windows
1853 * (where isPopupTrigger() will answer true)
1854 * NB isRightMouseButton is also true for Cmd-click on Mac
1856 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1863 seqCanvas.cursorX = findColumn(evt);
1864 seqCanvas.cursorY = findSeq(evt);
1865 seqCanvas.repaint();
1869 if (stretchGroup == null)
1871 createStretchGroup(res, sequence);
1874 if (stretchGroup != null)
1876 stretchGroup.addPropertyChangeListener(seqCanvas);
1879 seqCanvas.repaint();
1882 private void createStretchGroup(int res, SequenceI sequence)
1884 // Only if left mouse button do we want to change group sizes
1885 // define a new group here
1886 SequenceGroup sg = new SequenceGroup();
1887 sg.setStartRes(res);
1889 sg.addSequence(sequence, false);
1890 av.setSelectionGroup(sg);
1893 if (av.getConservationSelected())
1895 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1899 if (av.getAbovePIDThreshold())
1901 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1904 // TODO: stretchGroup will always be not null. Is this a merge error ?
1905 // or is there a threading issue here?
1906 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1908 // Edit end res position of selected group
1909 changeEndRes = true;
1911 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1913 // Edit end res position of selected group
1914 changeStartRes = true;
1916 stretchGroup.getWidth();
1921 * Build and show a pop-up menu at the right-click mouse position
1927 void showPopupMenu(MouseEvent evt)
1929 final int column = findColumn(evt);
1930 final int seq = findSeq(evt);
1931 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1932 List<SequenceFeature> features = ap.getFeatureRenderer()
1933 .findFeaturesAtColumn(sequence, column + 1);
1935 PopupMenu pop = new PopupMenu(ap, null, features);
1936 pop.show(this, evt.getX(), evt.getY());
1940 * Update the display after mouse up on a selection or group
1943 * mouse released event details
1945 * true if this event is happening after a mouse drag (rather than a
1948 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
1950 if (stretchGroup == null)
1955 stretchGroup.removePropertyChangeListener(seqCanvas);
1957 // always do this - annotation has own state
1958 // but defer colourscheme update until hidden sequences are passed in
1959 boolean vischange = stretchGroup.recalcConservation(true);
1960 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
1962 if (stretchGroup.cs != null)
1964 stretchGroup.cs.alignmentChanged(stretchGroup,
1965 av.getHiddenRepSequences());
1967 ResidueShaderI groupColourScheme = stretchGroup
1968 .getGroupColourScheme();
1969 String name = stretchGroup.getName();
1970 if (stretchGroup.cs.conservationApplied())
1972 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
1974 if (stretchGroup.cs.getThreshold() > 0)
1976 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
1979 PaintRefresher.Refresh(this, av.getSequenceSetId());
1980 // TODO: structure colours only need updating if stretchGroup used to or now
1981 // does contain sequences with structure views
1982 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
1983 updateOverviewAndStructs = false;
1984 changeEndRes = false;
1985 changeStartRes = false;
1986 stretchGroup = null;
1996 public void doMouseDraggedDefineMode(MouseEvent evt)
1998 int res = findColumn(evt);
1999 int y = findSeq(evt);
2001 if (wrappedBlock != startWrapBlock)
2006 if (stretchGroup == null)
2011 if (res >= av.getAlignment().getWidth())
2013 res = av.getAlignment().getWidth() - 1;
2016 if (stretchGroup.getEndRes() == res)
2018 // Edit end res position of selected group
2019 changeEndRes = true;
2021 else if (stretchGroup.getStartRes() == res)
2023 // Edit start res position of selected group
2024 changeStartRes = true;
2027 if (res < av.getRanges().getStartRes())
2029 res = av.getRanges().getStartRes();
2034 if (res > (stretchGroup.getStartRes() - 1))
2036 stretchGroup.setEndRes(res);
2037 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2040 else if (changeStartRes)
2042 if (res < (stretchGroup.getEndRes() + 1))
2044 stretchGroup.setStartRes(res);
2045 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2049 int dragDirection = 0;
2055 else if (y < oldSeq)
2060 while ((y != oldSeq) && (oldSeq > -1)
2061 && (y < av.getAlignment().getHeight()))
2063 // This routine ensures we don't skip any sequences, as the
2064 // selection is quite slow.
2065 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2067 oldSeq += dragDirection;
2074 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2076 if (stretchGroup.getSequences(null).contains(nextSeq))
2078 stretchGroup.deleteSequence(seq, false);
2079 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2085 stretchGroup.addSequence(seq, false);
2088 stretchGroup.addSequence(nextSeq, false);
2089 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2098 mouseDragging = true;
2100 if ((scrollThread != null) && (scrollThread.isRunning()))
2102 scrollThread.setEvent(evt);
2106 void scrollCanvas(MouseEvent evt)
2110 if ((scrollThread != null) && (scrollThread.isRunning()))
2112 scrollThread.stopScrolling();
2113 scrollThread = null;
2115 mouseDragging = false;
2119 if (scrollThread == null)
2121 scrollThread = new ScrollThread();
2124 mouseDragging = true;
2125 scrollThread.setEvent(evt);
2130 // this class allows scrolling off the bottom of the visible alignment
2131 class ScrollThread extends Thread
2135 private volatile boolean threadRunning = true;
2137 public ScrollThread()
2142 public void setEvent(MouseEvent e)
2147 public void stopScrolling()
2149 threadRunning = false;
2152 public boolean isRunning()
2154 return threadRunning;
2160 while (threadRunning)
2164 if (mouseDragging && (evt.getY() < 0)
2165 && (av.getRanges().getStartSeq() > 0))
2167 av.getRanges().scrollUp(true);
2170 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2171 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2173 av.getRanges().scrollUp(false);
2176 if (mouseDragging && (evt.getX() < 0))
2178 av.getRanges().scrollRight(false);
2180 else if (mouseDragging && (evt.getX() >= getWidth()))
2182 av.getRanges().scrollRight(true);
2189 } catch (Exception ex)
2197 * modify current selection according to a received message.
2200 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2201 HiddenColumns hidden, SelectionSource source)
2203 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2204 // handles selection messages...
2205 // TODO: extend config options to allow user to control if selections may be
2206 // shared between viewports.
2207 boolean iSentTheSelection = (av == source
2208 || (source instanceof AlignViewport
2209 && ((AlignmentViewport) source).getSequenceSetId()
2210 .equals(av.getSequenceSetId())));
2212 if (iSentTheSelection)
2214 // respond to our own event by updating dependent dialogs
2215 if (ap.getCalculationDialog() != null)
2217 ap.getCalculationDialog().validateCalcTypes();
2223 // process further ?
2224 if (!av.followSelection)
2230 * Ignore the selection if there is one of our own pending.
2232 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2238 * Check for selection in a view of which this one is a dna/protein
2241 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2246 // do we want to thread this ? (contention with seqsel and colsel locks, I
2249 * only copy colsel if there is a real intersection between
2250 * sequence selection and this panel's alignment
2252 boolean repaint = false;
2253 boolean copycolsel = false;
2255 SequenceGroup sgroup = null;
2256 if (seqsel != null && seqsel.getSize() > 0)
2258 if (av.getAlignment() == null)
2260 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2261 + " ViewId=" + av.getViewId()
2262 + " 's alignment is NULL! returning immediately.");
2265 sgroup = seqsel.intersect(av.getAlignment(),
2266 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2267 if ((sgroup != null && sgroup.getSize() > 0))
2272 if (sgroup != null && sgroup.getSize() > 0)
2274 av.setSelectionGroup(sgroup);
2278 av.setSelectionGroup(null);
2280 av.isSelectionGroupChanged(true);
2285 // the current selection is unset or from a previous message
2286 // so import the new colsel.
2287 if (colsel == null || colsel.isEmpty())
2289 if (av.getColumnSelection() != null)
2291 av.getColumnSelection().clear();
2297 // TODO: shift colSel according to the intersecting sequences
2298 if (av.getColumnSelection() == null)
2300 av.setColumnSelection(new ColumnSelection(colsel));
2304 av.getColumnSelection().setElementsFrom(colsel,
2305 av.getAlignment().getHiddenColumns());
2308 av.isColSelChanged(true);
2312 if (copycolsel && av.hasHiddenColumns()
2313 && (av.getAlignment().getHiddenColumns() == null))
2315 System.err.println("Bad things");
2317 if (repaint) // always true!
2319 // probably finessing with multiple redraws here
2320 PaintRefresher.Refresh(this, av.getSequenceSetId());
2321 // ap.paintAlignment(false);
2324 // lastly, update dependent dialogs
2325 if (ap.getCalculationDialog() != null)
2327 ap.getCalculationDialog().validateCalcTypes();
2333 * If this panel is a cdna/protein translation view of the selection source,
2334 * tries to map the source selection to a local one, and returns true. Else
2341 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2342 ColumnSelection colsel, HiddenColumns hidden,
2343 SelectionSource source)
2345 if (!(source instanceof AlignViewportI))
2349 final AlignViewportI sourceAv = (AlignViewportI) source;
2350 if (sourceAv.getCodingComplement() != av
2351 && av.getCodingComplement() != sourceAv)
2357 * Map sequence selection
2359 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2360 av.setSelectionGroup(sg);
2361 av.isSelectionGroupChanged(true);
2364 * Map column selection
2366 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2368 ColumnSelection cs = new ColumnSelection();
2369 HiddenColumns hs = new HiddenColumns();
2370 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2371 av.setColumnSelection(cs);
2372 av.getAlignment().setHiddenColumns(hs);
2374 // lastly, update any dependent dialogs
2375 if (ap.getCalculationDialog() != null)
2377 ap.getCalculationDialog().validateCalcTypes();
2380 PaintRefresher.Refresh(this, av.getSequenceSetId());
2387 * @return null or last search results handled by this panel
2389 public SearchResultsI getLastSearchResults()
2391 return lastSearchResults;