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);
795 List<String> pv = mf.findProteinVariants();
798 if (!infos.contains(s))
811 StringBuilder sb = new StringBuilder();
812 for (String info : infos)
820 return sb.toString();
824 public VamsasSource getVamsasSource()
826 return this.ap == null ? null : this.ap.av;
830 public void updateColours(SequenceI seq, int index)
832 System.out.println("update the seqPanel colours");
837 * Action on mouse movement is to update the status bar to show the current
838 * sequence position, and (if features are shown) to show any features at the
839 * position in a tooltip. Does nothing if the mouse move does not change
845 public void mouseMoved(MouseEvent evt)
849 // This is because MacOSX creates a mouseMoved
850 // If control is down, other platforms will not.
854 final int column = findColumn(evt);
855 final int seq = findSeq(evt);
857 if (column < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
862 if (column == lastMouseColumn && seq == lastMouseSeq)
865 * just a pixel move without change of residue
869 lastMouseColumn = column;
872 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
874 if (column >= sequence.getLength())
880 * set status bar message, returning residue position in sequence
882 boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
883 final int pos = setStatusMessage(sequence, column, seq);
884 if (ssm != null && !isGapped)
886 mouseOverSequence(sequence, column, pos);
889 tooltipText.setLength(6); // Cuts the buffer back to <html>
891 SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
894 for (int g = 0; g < groups.length; g++)
896 if (groups[g].getStartRes() <= column
897 && groups[g].getEndRes() >= column)
899 if (!groups[g].getName().startsWith("JTreeGroup")
900 && !groups[g].getName().startsWith("JGroup"))
902 tooltipText.append(groups[g].getName());
905 if (groups[g].getDescription() != null)
907 tooltipText.append(": " + groups[g].getDescription());
914 * add any features at the position to the tooltip; if over a gap, only
915 * add features that straddle the gap (pos may be the residue before or
918 if (av.isShowSequenceFeatures())
920 List<SequenceFeature> features = ap.getFeatureRenderer()
921 .findFeaturesAtColumn(sequence, column + 1);
922 seqARep.appendFeatures(tooltipText, pos, features,
923 this.ap.getSeqPanel().seqCanvas.fr);
926 * add features in CDS/protein complement at the corresponding
927 * position if configured to do so
929 if (av.isShowComplementFeatures())
931 if (!Comparison.isGap(sequence.getCharAt(column)))
933 AlignViewportI complement = ap.getAlignViewport()
934 .getCodingComplement();
935 AlignFrame af = Desktop.getAlignFrameFor(complement);
936 FeatureRendererModel fr2 = af.getFeatureRenderer();
937 MappedFeatures mf = fr2.findComplementFeaturesAtResidue(sequence,
941 seqARep.appendFeatures(tooltipText, pos, mf.features, fr2);
946 if (tooltipText.length() == 6) // <html>
948 setToolTipText(null);
953 if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant
955 tooltipText.setLength(MAX_TOOLTIP_LENGTH);
956 tooltipText.append("...");
958 String textString = tooltipText.toString();
959 if (lastTooltip == null || !lastTooltip.equals(textString))
961 String formattedTooltipText = JvSwingUtils.wrapTooltip(true,
963 setToolTipText(formattedTooltipText);
964 lastTooltip = textString;
969 private Point lastp = null;
974 * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
977 public Point getToolTipLocation(MouseEvent event)
979 int x = event.getX(), w = getWidth();
980 int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
983 if (!event.isShiftDown() || p == null)
985 p = (tooltipText != null && tooltipText.length() > 6)
986 ? new Point(event.getX() + wdth, event.getY() - 20)
990 * TODO: try to modify position region is not obcured by tooltip
998 * set when the current UI interaction has resulted in a change that requires
999 * shading in overviews and structures to be recalculated. this could be
1000 * changed to a something more expressive that indicates what actually has
1001 * changed, so selective redraws can be applied (ie. only structures, only
1004 private boolean updateOverviewAndStructs = false; // TODO: refactor to avcontroller
1007 * set if av.getSelectionGroup() refers to a group that is defined on the
1008 * alignment view, rather than a transient selection
1010 // private boolean editingDefinedGroup = false; // TODO: refactor to
1011 // avcontroller or viewModel
1014 * Sets the status message in alignment panel, showing the sequence number
1015 * (index) and id, and residue and residue position if not at a gap, for the
1016 * given sequence and column position. Returns the residue position returned
1017 * by Sequence.findPosition. Note this may be for the nearest adjacent residue
1018 * if at a gapped position.
1021 * aligned sequence object
1025 * index of sequence in alignment
1026 * @return sequence position of residue at column, or adjacent residue if at a
1029 int setStatusMessage(SequenceI sequence, final int column, int seqIndex)
1031 char sequenceChar = sequence.getCharAt(column);
1032 int pos = sequence.findPosition(column);
1033 setStatusMessage(sequence, seqIndex, sequenceChar, pos);
1039 * Builds the status message for the current cursor location and writes it to
1040 * the status bar, for example
1043 * Sequence 3 ID: FER1_SOLLC
1044 * Sequence 5 ID: FER1_PEA Residue: THR (4)
1045 * Sequence 5 ID: FER1_PEA Residue: B (3)
1046 * Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
1051 * sequence position in the alignment (1..)
1052 * @param sequenceChar
1053 * the character under the cursor
1055 * the sequence residue position (if not over a gap)
1057 protected void setStatusMessage(SequenceI sequence, int seqIndex,
1058 char sequenceChar, int residuePos)
1060 StringBuilder text = new StringBuilder(32);
1063 * Sequence number (if known), and sequence name.
1065 String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
1066 text.append("Sequence").append(seqno).append(" ID: ")
1067 .append(sequence.getName());
1069 String residue = null;
1072 * Try to translate the display character to residue name (null for gap).
1074 boolean isGapped = Comparison.isGap(sequenceChar);
1078 boolean nucleotide = av.getAlignment().isNucleotide();
1079 String displayChar = String.valueOf(sequenceChar);
1082 residue = ResidueProperties.nucleotideName.get(displayChar);
1086 residue = "X".equalsIgnoreCase(displayChar) ? "X"
1087 : ("*".equals(displayChar) ? "STOP"
1088 : ResidueProperties.aa2Triplet.get(displayChar));
1090 text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
1091 .append(": ").append(residue == null ? displayChar : residue);
1093 text.append(" (").append(Integer.toString(residuePos)).append(")");
1095 ap.alignFrame.statusBar.setText(text.toString());
1099 * Set the status bar message to highlight the first matched position in
1104 private void setStatusMessage(SearchResultsI results)
1106 AlignmentI al = this.av.getAlignment();
1107 int sequenceIndex = al.findIndex(results);
1108 if (sequenceIndex == -1)
1112 SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
1113 for (SearchResultMatchI m : results.getResults())
1115 SequenceI seq = m.getSequence();
1116 if (seq.getDatasetSequence() != null)
1118 seq = seq.getDatasetSequence();
1123 int start = m.getStart();
1124 setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
1135 public void mouseDragged(MouseEvent evt)
1137 if (mouseWheelPressed)
1139 boolean inSplitFrame = ap.av.getCodingComplement() != null;
1140 boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
1142 int oldWidth = av.getCharWidth();
1144 // Which is bigger, left-right or up-down?
1145 if (Math.abs(evt.getY() - lastMousePress.getY()) > Math
1146 .abs(evt.getX() - lastMousePress.getX()))
1149 * on drag up or down, decrement or increment font size
1151 int fontSize = av.font.getSize();
1152 boolean fontChanged = false;
1154 if (evt.getY() < lastMousePress.getY())
1159 else if (evt.getY() > lastMousePress.getY())
1172 Font newFont = new Font(av.font.getName(), av.font.getStyle(),
1174 av.setFont(newFont, true);
1175 av.setCharWidth(oldWidth);
1179 ap.av.getCodingComplement().setFont(newFont, true);
1180 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1181 .getSplitViewContainer();
1182 splitFrame.adjustLayout();
1183 splitFrame.repaint();
1190 * on drag left or right, decrement or increment character width
1193 if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
1195 newWidth = av.getCharWidth() - 1;
1196 av.setCharWidth(newWidth);
1198 else if (evt.getX() > lastMousePress.getX())
1200 newWidth = av.getCharWidth() + 1;
1201 av.setCharWidth(newWidth);
1205 ap.paintAlignment(false, false);
1209 * need to ensure newWidth is set on cdna, regardless of which
1210 * panel the mouse drag happened in; protein will compute its
1211 * character width as 1:1 or 3:1
1213 av.getCodingComplement().setCharWidth(newWidth);
1214 SplitFrame splitFrame = (SplitFrame) ap.alignFrame
1215 .getSplitViewContainer();
1216 splitFrame.adjustLayout();
1217 splitFrame.repaint();
1222 FontMetrics fm = getFontMetrics(av.getFont());
1223 av.validCharWidth = fm.charWidth('M') <= av.getCharWidth();
1225 lastMousePress = evt.getPoint();
1232 doMouseDraggedDefineMode(evt);
1236 int res = findColumn(evt);
1243 if ((lastres == -1) || (lastres == res))
1248 if ((res < av.getAlignment().getWidth()) && (res < lastres))
1250 // dragLeft, delete gap
1251 editSequence(false, false, res);
1255 editSequence(true, false, res);
1258 mouseDragging = true;
1259 if ((scrollThread != null) && (scrollThread.isRunning()))
1261 scrollThread.setEvent(evt);
1265 // TODO: Make it more clever than many booleans
1266 synchronized void editSequence(boolean insertGap, boolean editSeq,
1270 int fixedRight = -1;
1271 boolean fixedColumns = false;
1272 SequenceGroup sg = av.getSelectionGroup();
1274 SequenceI seq = av.getAlignment().getSequenceAt(startseq);
1276 // No group, but the sequence may represent a group
1277 if (!groupEditing && av.hasHiddenRows())
1279 if (av.isHiddenRepSequence(seq))
1281 sg = av.getRepresentedSequences(seq);
1282 groupEditing = true;
1286 StringBuilder message = new StringBuilder(64);
1289 message.append("Edit group:");
1290 if (editCommand == null)
1292 editCommand = new EditCommand(
1293 MessageManager.getString("action.edit_group"));
1298 message.append("Edit sequence: " + seq.getName());
1299 String label = seq.getName();
1300 if (label.length() > 10)
1302 label = label.substring(0, 10);
1304 if (editCommand == null)
1306 editCommand = new EditCommand(MessageManager
1307 .formatMessage("label.edit_params", new String[]
1314 message.append(" insert ");
1318 message.append(" delete ");
1321 message.append(Math.abs(startres - lastres) + " gaps.");
1322 ap.alignFrame.statusBar.setText(message.toString());
1324 // Are we editing within a selection group?
1325 if (groupEditing || (sg != null
1326 && sg.getSequences(av.getHiddenRepSequences()).contains(seq)))
1328 fixedColumns = true;
1330 // sg might be null as the user may only see 1 sequence,
1331 // but the sequence represents a group
1334 if (!av.isHiddenRepSequence(seq))
1339 sg = av.getRepresentedSequences(seq);
1342 fixedLeft = sg.getStartRes();
1343 fixedRight = sg.getEndRes();
1345 if ((startres < fixedLeft && lastres >= fixedLeft)
1346 || (startres >= fixedLeft && lastres < fixedLeft)
1347 || (startres > fixedRight && lastres <= fixedRight)
1348 || (startres <= fixedRight && lastres > fixedRight))
1354 if (fixedLeft > startres)
1356 fixedRight = fixedLeft - 1;
1359 else if (fixedRight < startres)
1361 fixedLeft = fixedRight;
1366 if (av.hasHiddenColumns())
1368 fixedColumns = true;
1369 int y1 = av.getAlignment().getHiddenColumns()
1370 .getNextHiddenBoundary(true, startres);
1371 int y2 = av.getAlignment().getHiddenColumns()
1372 .getNextHiddenBoundary(false, startres);
1374 if ((insertGap && startres > y1 && lastres < y1)
1375 || (!insertGap && startres < y2 && lastres > y2))
1381 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1382 // Selection spans a hidden region
1383 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1391 fixedRight = y2 - 1;
1398 List<SequenceI> vseqs = sg.getSequences(av.getHiddenRepSequences());
1399 int g, groupSize = vseqs.size();
1400 SequenceI[] groupSeqs = new SequenceI[groupSize];
1401 for (g = 0; g < groupSeqs.length; g++)
1403 groupSeqs[g] = vseqs.get(g);
1409 // If the user has selected the whole sequence, and is dragging to
1410 // the right, we can still extend the alignment and selectionGroup
1411 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1412 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1414 sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1415 fixedRight = sg.getEndRes();
1418 // Is it valid with fixed columns??
1419 // Find the next gap before the end
1420 // of the visible region boundary
1421 boolean blank = false;
1422 for (; fixedRight > lastres; fixedRight--)
1426 for (g = 0; g < groupSize; g++)
1428 for (int j = 0; j < startres - lastres; j++)
1430 if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j)))
1445 if (sg.getSize() == av.getAlignment().getHeight())
1447 if ((av.hasHiddenColumns() && startres < av.getAlignment()
1449 .getNextHiddenBoundary(false, startres)))
1455 int alWidth = av.getAlignment().getWidth();
1456 if (av.hasHiddenRows())
1458 int hwidth = av.getAlignment().getHiddenSequences()
1460 if (hwidth > alWidth)
1465 // We can still insert gaps if the selectionGroup
1466 // contains all the sequences
1467 sg.setEndRes(sg.getEndRes() + startres - lastres);
1468 fixedRight = alWidth + startres - lastres;
1479 else if (!insertGap)
1481 // / Are we able to delete?
1482 // ie are all columns blank?
1484 for (g = 0; g < groupSize; g++)
1486 for (int j = startres; j < lastres; j++)
1488 if (groupSeqs[g].getLength() <= j)
1493 if (!Comparison.isGap(groupSeqs[g].getCharAt(j)))
1495 // Not a gap, block edit not valid
1505 // dragging to the right
1506 if (fixedColumns && fixedRight != -1)
1508 for (int j = lastres; j < startres; j++)
1510 insertChar(j, groupSeqs, fixedRight);
1515 appendEdit(Action.INSERT_GAP, groupSeqs, startres,
1516 startres - lastres);
1521 // dragging to the left
1522 if (fixedColumns && fixedRight != -1)
1524 for (int j = lastres; j > startres; j--)
1526 deleteChar(startres, groupSeqs, fixedRight);
1531 appendEdit(Action.DELETE_GAP, groupSeqs, startres,
1532 lastres - startres);
1538 // ///Editing a single sequence///////////
1542 // dragging to the right
1543 if (fixedColumns && fixedRight != -1)
1545 for (int j = lastres; j < startres; j++)
1547 insertChar(j, new SequenceI[] { seq }, fixedRight);
1552 appendEdit(Action.INSERT_GAP, new SequenceI[] { seq }, lastres,
1553 startres - lastres);
1560 // dragging to the left
1561 if (fixedColumns && fixedRight != -1)
1563 for (int j = lastres; j > startres; j--)
1565 if (!Comparison.isGap(seq.getCharAt(startres)))
1570 deleteChar(startres, new SequenceI[] { seq }, fixedRight);
1575 // could be a keyboard edit trying to delete none gaps
1577 for (int m = startres; m < lastres; m++)
1579 if (!Comparison.isGap(seq.getCharAt(m)))
1588 appendEdit(Action.DELETE_GAP, new SequenceI[] { seq },
1594 {// insertGap==false AND editSeq==TRUE;
1595 if (fixedColumns && fixedRight != -1)
1597 for (int j = lastres; j < startres; j++)
1599 insertChar(j, new SequenceI[] { seq }, fixedRight);
1604 appendEdit(Action.INSERT_NUC, new SequenceI[] { seq }, lastres,
1605 startres - lastres);
1612 seqCanvas.repaint();
1615 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1617 int blankColumn = fixedColumn;
1618 for (int s = 0; s < seq.length; s++)
1620 // Find the next gap before the end of the visible region boundary
1621 // If lastCol > j, theres a boundary after the gap insertion
1623 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1625 if (Comparison.isGap(seq[s].getCharAt(blankColumn)))
1627 // Theres a space, so break and insert the gap
1632 if (blankColumn <= j)
1634 blankColumn = fixedColumn;
1640 appendEdit(Action.DELETE_GAP, seq, blankColumn, 1);
1642 appendEdit(Action.INSERT_GAP, seq, j, 1);
1647 * Helper method to add and perform one edit action.
1654 protected void appendEdit(Action action, SequenceI[] seq, int pos,
1658 final Edit edit = new EditCommand().new Edit(action, seq, pos, count,
1659 av.getAlignment().getGapCharacter());
1661 editCommand.appendEdit(edit, av.getAlignment(), true, null);
1664 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1667 appendEdit(Action.DELETE_GAP, seq, j, 1);
1669 appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1);
1679 public void mouseEntered(MouseEvent e)
1686 if ((scrollThread != null) && (scrollThread.isRunning()))
1688 scrollThread.stopScrolling();
1689 scrollThread = null;
1700 public void mouseExited(MouseEvent e)
1702 if (av.getWrapAlignment())
1707 if (mouseDragging && scrollThread == null)
1709 scrollThread = new ScrollThread();
1714 * Handler for double-click on a position with one or more sequence features.
1715 * Opens the Amend Features dialog to allow feature details to be amended, or
1716 * the feature deleted.
1719 public void mouseClicked(MouseEvent evt)
1721 SequenceGroup sg = null;
1722 SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
1723 if (evt.getClickCount() > 1)
1725 sg = av.getSelectionGroup();
1726 if (sg != null && sg.getSize() == 1
1727 && sg.getEndRes() - sg.getStartRes() < 2)
1729 av.setSelectionGroup(null);
1732 int column = findColumn(evt);
1735 * find features at the position (if not gapped), or straddling
1736 * the position (if at a gap)
1738 List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
1739 .findFeaturesAtColumn(sequence, column + 1);
1741 if (!features.isEmpty())
1744 * highlight the first feature at the position on the alignment
1746 SearchResultsI highlight = new SearchResults();
1747 highlight.addResult(sequence, features.get(0).getBegin(), features
1749 seqCanvas.highlightSearchResults(highlight, false);
1752 * open the Amend Features dialog; clear highlighting afterwards,
1753 * whether changes were made or not
1755 List<SequenceI> seqs = Collections.singletonList(sequence);
1756 seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, false,
1758 av.setSearchResults(null); // clear highlighting
1759 seqCanvas.repaint(); // draw new/amended features
1765 public void mouseWheelMoved(MouseWheelEvent e)
1768 double wheelRotation = e.getPreciseWheelRotation();
1769 if (wheelRotation > 0)
1771 if (e.isShiftDown())
1773 av.getRanges().scrollRight(true);
1778 av.getRanges().scrollUp(false);
1781 else if (wheelRotation < 0)
1783 if (e.isShiftDown())
1785 av.getRanges().scrollRight(false);
1789 av.getRanges().scrollUp(true);
1794 * update status bar and tooltip for new position
1795 * (need to synthesize a mouse movement to refresh tooltip)
1798 ToolTipManager.sharedInstance().mouseMoved(e);
1807 public void doMousePressedDefineMode(MouseEvent evt)
1809 final int res = findColumn(evt);
1810 final int seq = findSeq(evt);
1812 updateOverviewAndStructs = false;
1814 startWrapBlock = wrappedBlock;
1816 if (av.getWrapAlignment() && seq > av.getAlignment().getHeight())
1818 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1819 MessageManager.getString(
1820 "label.cannot_edit_annotations_in_wrapped_view"),
1821 MessageManager.getString("label.wrapped_view_no_edit"),
1822 JvOptionPane.WARNING_MESSAGE);
1826 if (seq < 0 || res < 0)
1831 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1833 if ((sequence == null) || (res > sequence.getLength()))
1838 stretchGroup = av.getSelectionGroup();
1840 if (stretchGroup == null || !stretchGroup.contains(sequence, res))
1842 stretchGroup = av.getAlignment().findGroup(sequence, res);
1843 if (stretchGroup != null)
1845 // only update the current selection if the popup menu has a group to
1847 av.setSelectionGroup(stretchGroup);
1851 if (evt.isPopupTrigger()) // Mac: mousePressed
1858 * defer right-mouse click handling to mouseReleased on Windows
1859 * (where isPopupTrigger() will answer true)
1860 * NB isRightMouseButton is also true for Cmd-click on Mac
1862 if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
1869 seqCanvas.cursorX = findColumn(evt);
1870 seqCanvas.cursorY = findSeq(evt);
1871 seqCanvas.repaint();
1875 if (stretchGroup == null)
1877 createStretchGroup(res, sequence);
1880 if (stretchGroup != null)
1882 stretchGroup.addPropertyChangeListener(seqCanvas);
1885 seqCanvas.repaint();
1888 private void createStretchGroup(int res, SequenceI sequence)
1890 // Only if left mouse button do we want to change group sizes
1891 // define a new group here
1892 SequenceGroup sg = new SequenceGroup();
1893 sg.setStartRes(res);
1895 sg.addSequence(sequence, false);
1896 av.setSelectionGroup(sg);
1899 if (av.getConservationSelected())
1901 SliderPanel.setConservationSlider(ap, av.getResidueShading(),
1905 if (av.getAbovePIDThreshold())
1907 SliderPanel.setPIDSliderSource(ap, av.getResidueShading(),
1910 // TODO: stretchGroup will always be not null. Is this a merge error ?
1911 // or is there a threading issue here?
1912 if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
1914 // Edit end res position of selected group
1915 changeEndRes = true;
1917 else if ((stretchGroup != null) && (stretchGroup.getStartRes() == res))
1919 // Edit end res position of selected group
1920 changeStartRes = true;
1922 stretchGroup.getWidth();
1927 * Build and show a pop-up menu at the right-click mouse position
1933 void showPopupMenu(MouseEvent evt)
1935 final int column = findColumn(evt);
1936 final int seq = findSeq(evt);
1937 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1938 List<SequenceFeature> features = ap.getFeatureRenderer()
1939 .findFeaturesAtColumn(sequence, column + 1);
1941 PopupMenu pop = new PopupMenu(ap, null, features);
1942 pop.show(this, evt.getX(), evt.getY());
1946 * Update the display after mouse up on a selection or group
1949 * mouse released event details
1951 * true if this event is happening after a mouse drag (rather than a
1954 public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
1956 if (stretchGroup == null)
1961 stretchGroup.removePropertyChangeListener(seqCanvas);
1963 // always do this - annotation has own state
1964 // but defer colourscheme update until hidden sequences are passed in
1965 boolean vischange = stretchGroup.recalcConservation(true);
1966 updateOverviewAndStructs |= vischange && av.isSelectionDefinedGroup()
1968 if (stretchGroup.cs != null)
1970 stretchGroup.cs.alignmentChanged(stretchGroup,
1971 av.getHiddenRepSequences());
1973 ResidueShaderI groupColourScheme = stretchGroup
1974 .getGroupColourScheme();
1975 String name = stretchGroup.getName();
1976 if (stretchGroup.cs.conservationApplied())
1978 SliderPanel.setConservationSlider(ap, groupColourScheme, name);
1980 if (stretchGroup.cs.getThreshold() > 0)
1982 SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
1985 PaintRefresher.Refresh(this, av.getSequenceSetId());
1986 // TODO: structure colours only need updating if stretchGroup used to or now
1987 // does contain sequences with structure views
1988 ap.paintAlignment(updateOverviewAndStructs, updateOverviewAndStructs);
1989 updateOverviewAndStructs = false;
1990 changeEndRes = false;
1991 changeStartRes = false;
1992 stretchGroup = null;
2002 public void doMouseDraggedDefineMode(MouseEvent evt)
2004 int res = findColumn(evt);
2005 int y = findSeq(evt);
2007 if (wrappedBlock != startWrapBlock)
2012 if (stretchGroup == null)
2017 if (res >= av.getAlignment().getWidth())
2019 res = av.getAlignment().getWidth() - 1;
2022 if (stretchGroup.getEndRes() == res)
2024 // Edit end res position of selected group
2025 changeEndRes = true;
2027 else if (stretchGroup.getStartRes() == res)
2029 // Edit start res position of selected group
2030 changeStartRes = true;
2033 if (res < av.getRanges().getStartRes())
2035 res = av.getRanges().getStartRes();
2040 if (res > (stretchGroup.getStartRes() - 1))
2042 stretchGroup.setEndRes(res);
2043 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2046 else if (changeStartRes)
2048 if (res < (stretchGroup.getEndRes() + 1))
2050 stretchGroup.setStartRes(res);
2051 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2055 int dragDirection = 0;
2061 else if (y < oldSeq)
2066 while ((y != oldSeq) && (oldSeq > -1)
2067 && (y < av.getAlignment().getHeight()))
2069 // This routine ensures we don't skip any sequences, as the
2070 // selection is quite slow.
2071 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2073 oldSeq += dragDirection;
2080 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
2082 if (stretchGroup.getSequences(null).contains(nextSeq))
2084 stretchGroup.deleteSequence(seq, false);
2085 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2091 stretchGroup.addSequence(seq, false);
2094 stretchGroup.addSequence(nextSeq, false);
2095 updateOverviewAndStructs |= av.isSelectionDefinedGroup();
2104 mouseDragging = true;
2106 if ((scrollThread != null) && (scrollThread.isRunning()))
2108 scrollThread.setEvent(evt);
2112 void scrollCanvas(MouseEvent evt)
2116 if ((scrollThread != null) && (scrollThread.isRunning()))
2118 scrollThread.stopScrolling();
2119 scrollThread = null;
2121 mouseDragging = false;
2125 if (scrollThread == null)
2127 scrollThread = new ScrollThread();
2130 mouseDragging = true;
2131 scrollThread.setEvent(evt);
2136 // this class allows scrolling off the bottom of the visible alignment
2137 class ScrollThread extends Thread
2141 private volatile boolean threadRunning = true;
2143 public ScrollThread()
2148 public void setEvent(MouseEvent e)
2153 public void stopScrolling()
2155 threadRunning = false;
2158 public boolean isRunning()
2160 return threadRunning;
2166 while (threadRunning)
2170 if (mouseDragging && (evt.getY() < 0)
2171 && (av.getRanges().getStartSeq() > 0))
2173 av.getRanges().scrollUp(true);
2176 if (mouseDragging && (evt.getY() >= getHeight()) && (av
2177 .getAlignment().getHeight() > av.getRanges().getEndSeq()))
2179 av.getRanges().scrollUp(false);
2182 if (mouseDragging && (evt.getX() < 0))
2184 av.getRanges().scrollRight(false);
2186 else if (mouseDragging && (evt.getX() >= getWidth()))
2188 av.getRanges().scrollRight(true);
2195 } catch (Exception ex)
2203 * modify current selection according to a received message.
2206 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
2207 HiddenColumns hidden, SelectionSource source)
2209 // TODO: fix this hack - source of messages is align viewport, but SeqPanel
2210 // handles selection messages...
2211 // TODO: extend config options to allow user to control if selections may be
2212 // shared between viewports.
2213 boolean iSentTheSelection = (av == source
2214 || (source instanceof AlignViewport
2215 && ((AlignmentViewport) source).getSequenceSetId()
2216 .equals(av.getSequenceSetId())));
2218 if (iSentTheSelection)
2220 // respond to our own event by updating dependent dialogs
2221 if (ap.getCalculationDialog() != null)
2223 ap.getCalculationDialog().validateCalcTypes();
2229 // process further ?
2230 if (!av.followSelection)
2236 * Ignore the selection if there is one of our own pending.
2238 if (av.isSelectionGroupChanged(false) || av.isColSelChanged(false))
2244 * Check for selection in a view of which this one is a dna/protein
2247 if (selectionFromTranslation(seqsel, colsel, hidden, source))
2252 // do we want to thread this ? (contention with seqsel and colsel locks, I
2255 * only copy colsel if there is a real intersection between
2256 * sequence selection and this panel's alignment
2258 boolean repaint = false;
2259 boolean copycolsel = false;
2261 SequenceGroup sgroup = null;
2262 if (seqsel != null && seqsel.getSize() > 0)
2264 if (av.getAlignment() == null)
2266 Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId()
2267 + " ViewId=" + av.getViewId()
2268 + " 's alignment is NULL! returning immediately.");
2271 sgroup = seqsel.intersect(av.getAlignment(),
2272 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
2273 if ((sgroup != null && sgroup.getSize() > 0))
2278 if (sgroup != null && sgroup.getSize() > 0)
2280 av.setSelectionGroup(sgroup);
2284 av.setSelectionGroup(null);
2286 av.isSelectionGroupChanged(true);
2291 // the current selection is unset or from a previous message
2292 // so import the new colsel.
2293 if (colsel == null || colsel.isEmpty())
2295 if (av.getColumnSelection() != null)
2297 av.getColumnSelection().clear();
2303 // TODO: shift colSel according to the intersecting sequences
2304 if (av.getColumnSelection() == null)
2306 av.setColumnSelection(new ColumnSelection(colsel));
2310 av.getColumnSelection().setElementsFrom(colsel,
2311 av.getAlignment().getHiddenColumns());
2314 av.isColSelChanged(true);
2318 if (copycolsel && av.hasHiddenColumns()
2319 && (av.getAlignment().getHiddenColumns() == null))
2321 System.err.println("Bad things");
2323 if (repaint) // always true!
2325 // probably finessing with multiple redraws here
2326 PaintRefresher.Refresh(this, av.getSequenceSetId());
2327 // ap.paintAlignment(false);
2330 // lastly, update dependent dialogs
2331 if (ap.getCalculationDialog() != null)
2333 ap.getCalculationDialog().validateCalcTypes();
2339 * If this panel is a cdna/protein translation view of the selection source,
2340 * tries to map the source selection to a local one, and returns true. Else
2347 protected boolean selectionFromTranslation(SequenceGroup seqsel,
2348 ColumnSelection colsel, HiddenColumns hidden,
2349 SelectionSource source)
2351 if (!(source instanceof AlignViewportI))
2355 final AlignViewportI sourceAv = (AlignViewportI) source;
2356 if (sourceAv.getCodingComplement() != av
2357 && av.getCodingComplement() != sourceAv)
2363 * Map sequence selection
2365 SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av);
2366 av.setSelectionGroup(sg);
2367 av.isSelectionGroupChanged(true);
2370 * Map column selection
2372 // ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv,
2374 ColumnSelection cs = new ColumnSelection();
2375 HiddenColumns hs = new HiddenColumns();
2376 MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs);
2377 av.setColumnSelection(cs);
2378 av.getAlignment().setHiddenColumns(hs);
2380 // lastly, update any dependent dialogs
2381 if (ap.getCalculationDialog() != null)
2383 ap.getCalculationDialog().validateCalcTypes();
2386 PaintRefresher.Refresh(this, av.getSequenceSetId());
2393 * @return null or last search results handled by this panel
2395 public SearchResultsI getLastSearchResults()
2397 return lastSearchResults;