X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=5becbc13c85ecc8ae8d28054541d1cd49a5220cb;hb=4f77328104498504339216829abf5ea87e2791ec;hp=57bfa685275457b5d0ac2fb68ae708e3b863a222;hpb=2ca31c294c758a1f7e6c314ff671ddd03f937e60;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 57bfa68..5becbc1 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -42,8 +42,8 @@ import jalview.structure.VamsasSource; import jalview.util.Comparison; import jalview.util.MappingUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; -import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Font; @@ -54,10 +54,8 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.ListIterator; import java.util.Vector; public class SeqPanel extends Panel implements MouseMotionListener, @@ -150,13 +148,13 @@ public class SeqPanel extends Panel implements MouseMotionListener, void setCursorRow() { seqCanvas.cursorY = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorColumn() { seqCanvas.cursorX = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorRowAndColumn() @@ -169,7 +167,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { seqCanvas.cursorX = getKeyboardNo1() - 1; seqCanvas.cursorY = getKeyboardNo2() - 1; - scrollToVisible(); + scrollToVisible(true); } } @@ -178,7 +176,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY); seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1; - scrollToVisible(); + scrollToVisible(true); } void moveCursor(int dx, int dy) @@ -204,10 +202,16 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.cursorX = original; } } - scrollToVisible(); + scrollToVisible(false); } - void scrollToVisible() + /** + * Scroll to make the cursor visible in the viewport. + * + * @param jump + * just jump to the location rather than scrolling + */ + void scrollToVisible(boolean jump) { if (seqCanvas.cursorX < 0) { @@ -228,44 +232,34 @@ public class SeqPanel extends Panel implements MouseMotionListener, } endEditing(); - if (av.getWrapAlignment()) + + boolean repaintNeeded = true; + if (jump) { - av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); + // only need to repaint if the viewport did not move, as otherwise it will + // get a repaint + repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX, + seqCanvas.cursorY); } else { - ViewportRanges ranges = av.getRanges(); - HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - while (seqCanvas.cursorY < ranges.getStartSeq()) - { - ranges.scrollUp(true); - } - while (seqCanvas.cursorY > ranges.getEndSeq()) + if (av.getWrapAlignment()) { - ranges.scrollUp(false); + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); } - while (seqCanvas.cursorX < hidden - .adjustForHiddenColumns(ranges.getStartRes())) + else { - - if (!ranges.scrollRight(false)) - { - break; - } - } - while (seqCanvas.cursorX > hidden - .adjustForHiddenColumns(ranges.getEndRes())) - { - if (!ranges.scrollRight(true)) - { - break; - } + av.getRanges().scrollToVisible(seqCanvas.cursorX, + seqCanvas.cursorY); } } setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); - seqCanvas.repaint(); + if (repaintNeeded) + { + seqCanvas.repaint(); + } } void setSelectionAreaAtCursor(boolean topLeft) @@ -337,7 +331,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, sg.addSequence(sequence, false); av.setSelectionGroup(sg); } - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -419,7 +413,6 @@ public class SeqPanel extends Panel implements MouseMotionListener, * alignment column * @param seq * index of sequence in alignment - * @return position of column in sequence or -1 if at gap */ void setStatusMessage(SequenceI sequence, int column, int seq) { @@ -507,9 +500,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, // For now, ignore the mouseWheel font resizing on Macs // As the Button2_mask always seems to be true - if ((evt.getModifiers() - & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK - && !av.MAC) + if (Platform.isWinMiddleButton(evt)) { mouseWheelPressed = true; return; @@ -530,7 +521,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } int seq = findSeq(evt); - int res = findRes(evt); + int res = findColumn(evt); if (seq < 0 || res < 0) { @@ -566,14 +557,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, av.setSelectionGroup(null); } - int column = findRes(evt); - boolean isGapped = Comparison.isGap(sequence.getCharAt(column)); - List features = findFeaturesAtRes(sequence, - sequence.findPosition(column)); - if (isGapped) - { - removeAdjacentFeatures(features, column + 1, sequence); - } + int column = findColumn(evt); + List features = findFeaturesAtColumn(sequence, + column + 1); if (!features.isEmpty()) { @@ -583,8 +569,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.highlightSearchResults(highlight); seqCanvas.getFeatureRenderer().amendFeatures( Collections.singletonList(sequence), features, false, ap); - - seqCanvas.highlightSearchResults(null); + av.setSearchResults(null); // clear highlighting + seqCanvas.repaint(); // draw new/amended features } } } @@ -610,7 +596,14 @@ public class SeqPanel extends Panel implements MouseMotionListener, int wrappedBlock = -1; - int findRes(MouseEvent evt) + /** + * Returns the aligned sequence position (base 0) at the mouse position, or + * the closest visible one + * + * @param evt + * @return + */ + int findColumn(MouseEvent evt) { int res = 0; int x = evt.getX(); @@ -653,7 +646,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { res = av.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(res); + .visibleToAbsoluteColumn(res); } return res; @@ -714,7 +707,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { int seq = findSeq(evt); - int res = findRes(evt); + int res = findColumn(evt); if (seq < av.getAlignment().getHeight() && res < av.getAlignment().getSequenceAt(seq).getLength()) @@ -786,7 +779,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, @Override public void mouseMoved(MouseEvent evt) { - final int column = findRes(evt); + final int column = findColumn(evt); int seq = findSeq(evt); if (seq >= av.getAlignment().getHeight() || seq < 0 || column < 0) @@ -869,12 +862,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, */ if (av.isShowSequenceFeatures()) { - List allFeatures = findFeaturesAtRes(sequence, - sequence.findPosition(column)); - if (isGapped) - { - removeAdjacentFeatures(allFeatures, column + 1, sequence); - } + List allFeatures = findFeaturesAtColumn(sequence, + column + 1); for (SequenceFeature sf : allFeatures) { tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); @@ -907,63 +896,18 @@ public class SeqPanel extends Panel implements MouseMotionListener, } /** - * Removes from the list of features any that start after, or end before, the - * given column position. This allows us to retain only those features - * adjacent to a gapped position that straddle the position. Contact features - * that 'straddle' the position are also removed, since they are not 'at' the - * position. + * Returns features at the specified aligned column on the given sequence. + * Non-positional features are not included. If the column has a gap, then + * enclosing features are included (but not contact features). * - * @param features - * @param column - * alignment column (1..) * @param sequence + * @param column + * (1..) + * @return */ - protected void removeAdjacentFeatures(List features, - int column, SequenceI sequence) + List findFeaturesAtColumn(SequenceI sequence, int column) { - // TODO should this be an AlignViewController method (shared by gui)? - ListIterator it = features.listIterator(); - while (it.hasNext()) - { - SequenceFeature sf = it.next(); - if (sf.isContactFeature() - || sequence.findIndex(sf.getBegin()) > column - || sequence.findIndex(sf.getEnd()) < column) - { - it.remove(); - } - } - } - - List findFeaturesAtRes(SequenceI sequence, int res) - { - List result = new ArrayList<>(); - SequenceFeature[] features = sequence.getSequenceFeatures(); - if (features != null) - { - for (int i = 0; i < features.length; i++) - { - if (av.getFeaturesDisplayed() == null || !av.getFeaturesDisplayed() - .isVisible(features[i].getType())) - { - continue; - } - - if (features[i].featureGroup != null && !seqCanvas.fr - .checkGroupVisibility(features[i].featureGroup, false)) - { - continue; - } - - if ((features[i].getBegin() <= res) - && (features[i].getEnd() >= res)) - { - result.add(features[i]); - } - } - } - - return result; + return seqCanvas.getFeatureRenderer().findFeaturesAtColumn(sequence, column); } Tooltip tooltip; @@ -1032,7 +976,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, lastMousePress = evt.getPoint(); - ap.paintAlignment(false); + ap.paintAlignment(false, false); ap.annotationPanel.image = null; return; } @@ -1043,7 +987,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, return; } - int res = findRes(evt); + int res = findColumn(evt); if (res < 0) { @@ -1178,9 +1122,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, { fixedColumns = true; int y1 = av.getAlignment().getHiddenColumns() - .getHiddenBoundaryLeft(startres); + .getNextHiddenBoundary(true, startres); int y2 = av.getAlignment().getHiddenColumns() - .getHiddenBoundaryRight(startres); + .getNextHiddenBoundary(false, startres); if ((insertGap && startres > y1 && lastres < y1) || (!insertGap && startres < y2 && lastres > y2)) @@ -1225,7 +1169,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, // Find the next gap before the end // of the visible region boundary boolean blank = false; - for (fixedRight = fixedRight; fixedRight > lastres; fixedRight--) + for (; fixedRight > lastres; fixedRight--) { blank = true; @@ -1252,7 +1196,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (sg.getSize() == av.getAlignment().getHeight()) { if ((av.hasHiddenColumns() && startres < av.getAlignment() - .getHiddenColumns().getHiddenBoundaryRight(startres))) + .getHiddenColumns() + .getNextHiddenBoundary(false, startres))) { endEditing(); return; @@ -1455,7 +1400,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, scrollThread = null; } - int res = findRes(evt); + int column = findColumn(evt); int seq = findSeq(evt); oldSeq = seq; startWrapBlock = wrappedBlock; @@ -1467,16 +1412,16 @@ public class SeqPanel extends Panel implements MouseMotionListener, SequenceI sequence = av.getAlignment().getSequenceAt(seq); - if (sequence == null || res > sequence.getLength()) + if (sequence == null || column > sequence.getLength()) { return; } stretchGroup = av.getSelectionGroup(); - if (stretchGroup == null || !stretchGroup.contains(sequence, res)) + if (stretchGroup == null || !stretchGroup.contains(sequence, column)) { - stretchGroup = av.getAlignment().findGroup(sequence, res); + stretchGroup = av.getAlignment().findGroup(sequence, column); if (stretchGroup != null) { // only update the current selection if the popup menu has a group to @@ -1486,11 +1431,11 @@ public class SeqPanel extends Panel implements MouseMotionListener, } // DETECT RIGHT MOUSE BUTTON IN AWT - if ((evt.getModifiers() - & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) + if ((evt.getModifiersEx() + & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK) { - List allFeatures = findFeaturesAtRes(sequence, - sequence.findPosition(res)); + List allFeatures = findFeaturesAtColumn(sequence, + sequence.findPosition(column + 1)); Vector links = null; for (SequenceFeature sf : allFeatures) @@ -1501,10 +1446,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { links = new Vector<>(); } - for (int j = 0; j < sf.links.size(); j++) - { - links.addElement(sf.links.elementAt(j)); - } + links.addAll(sf.links); } } APopupMenu popup = new APopupMenu(ap, null, links); @@ -1515,7 +1457,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.cursorMode) { - seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorX = findColumn(evt); seqCanvas.cursorY = findSeq(evt); seqCanvas.repaint(); return; @@ -1527,8 +1469,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, { // define a new group here SequenceGroup sg = new SequenceGroup(); - sg.setStartRes(res); - sg.setEndRes(res); + sg.setStartRes(column); + sg.setEndRes(column); sg.addSequence(sequence, false); av.setSelectionGroup(sg); stretchGroup = sg; @@ -1576,7 +1518,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } PaintRefresher.Refresh(ap, av.getSequenceSetId()); - ap.paintAlignment(needOverviewUpdate); + ap.paintAlignment(needOverviewUpdate, needOverviewUpdate); needOverviewUpdate = false; changeEndRes = false; changeStartRes = false; @@ -1586,7 +1528,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, public void doMouseDraggedDefineMode(MouseEvent evt) { - int res = findRes(evt); + int res = findColumn(evt); int y = findSeq(evt); if (wrappedBlock != startWrapBlock)