X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=6912a020f8f1ceb1063f3398a9e68f163cd6199a;hb=2d8dfad8a0aa6a6febfc0c3bc0379de0b46e0cfc;hp=6b2f9c901722dd16c7249064dcf4e82d05f6ed2a;hpb=53507580ea0d347514d4f5e092a4d3d815609b9e;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 6b2f9c9..6912a02 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -35,6 +35,7 @@ import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Point; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -42,6 +43,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; +import java.util.Iterator; import java.util.List; import javax.swing.JMenuItem; @@ -112,7 +114,7 @@ public class ScalePanel extends JPanel if (av.hasHiddenColumns()) { - x = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(x); + x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x); } if (x >= av.getAlignment().getWidth()) @@ -130,8 +132,9 @@ public class ScalePanel extends JPanel if (evt.isPopupTrigger()) // Mac: mousePressed { rightMouseButtonPressed(evt, res); + return; } - else if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac()) + if (Platform.isWinRightButton(evt)) { /* * defer right-mouse click handling to mouse up on Windows @@ -140,10 +143,7 @@ public class ScalePanel extends JPanel */ return; } - else - { - leftMouseButtonPressed(evt, res); - } + leftMouseButtonPressed(evt, res); } /** @@ -168,13 +168,13 @@ public class ScalePanel extends JPanel { av.showColumn(reveal[0]); reveal = null; - ap.paintAlignment(true); + ap.paintAlignment(true, true); av.sendSelection(); } }); pop.add(item); - if (av.getAlignment().getHiddenColumns().hasHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions()) { item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -184,7 +184,7 @@ public class ScalePanel extends JPanel { av.showAllHiddenColumns(); reveal = null; - ap.paintAlignment(true); + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -208,7 +208,7 @@ public class ScalePanel extends JPanel av.setSelectionGroup(null); } - ap.paintAlignment(true); + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -260,34 +260,34 @@ public class ScalePanel extends JPanel sg.setEndRes(max); } av.setSelectionGroup(sg); - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } /** - * DOCUMENT ME! + * Action on mouseUp is to set the limit of the current selection group (if + * there is one) and broadcast the selection * * @param evt - * DOCUMENT ME! */ @Override public void mouseReleased(MouseEvent evt) { mouseDragging = false; + ap.getSeqPanel().stopScrolling(); - int res = (evt.getX() / av.getCharWidth()) + // todo res calculation should be a method on AlignViewport + int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates + + int res = (xCords / av.getCharWidth()) + av.getRanges().getStartRes(); if (av.hasHiddenColumns()) { res = av.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(res); - } - - if (res >= av.getAlignment().getWidth()) - { - res = av.getAlignment().getWidth() - 1; + .visibleToAbsoluteColumn(res); } + res = Math.min(res, av.getAlignment().getWidth() - 1); if (!stretchingGroup) { @@ -297,7 +297,7 @@ public class ScalePanel extends JPanel } else { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } return; } @@ -316,7 +316,7 @@ public class ScalePanel extends JPanel } } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -336,7 +336,7 @@ public class ScalePanel extends JPanel int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); res = Math.max(0, res); - res = hidden.adjustForHiddenColumns(res); + res = hidden.visibleToAbsoluteColumn(res); res = Math.min(res, av.getAlignment().getWidth() - 1); min = Math.min(res, min); max = Math.max(res, max); @@ -346,7 +346,7 @@ public class ScalePanel extends JPanel { stretchingGroup = true; cs.stretchGroup(res, sg, min, max); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -355,16 +355,23 @@ public class ScalePanel extends JPanel { if (mouseDragging) { - ap.getSeqPanel().scrollCanvas(null); + mouseDragging = false; + ap.getSeqPanel().stopScrolling(); } } + /** + * Action on leaving the panel bounds with mouse drag in progress is to start + * scrolling the alignment in the direction of the mouse. To restrict + * scrolling to left-right (not up-down), the y-value of the mouse position is + * replaced with zero. + */ @Override public void mouseExited(MouseEvent evt) { if (mouseDragging) { - ap.getSeqPanel().scrollCanvas(evt); + ap.getSeqPanel().startScrolling(new Point(evt.getX(), 0)); } } @@ -392,7 +399,7 @@ public class ScalePanel extends JPanel reveal = av.getAlignment().getHiddenColumns() .getRegionWithEdgeAtRes(res); - res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); ToolTipManager.sharedInstance().registerComponent(this); this.setToolTipText( @@ -409,6 +416,8 @@ public class ScalePanel extends JPanel @Override public void paintComponent(Graphics g) { + //super.paintComponent(g); // BH 2019 + /* * shouldn't get called in wrapped mode as the scale above is * drawn instead by SeqCanvas.drawNorthScale @@ -457,7 +466,7 @@ public class ScalePanel extends JPanel { if (hidden.isVisible(sel)) { - sel = hidden.findColumnPosition(sel); + sel = hidden.absoluteToVisibleColumn(sel); } else { @@ -487,23 +496,18 @@ public class ScalePanel extends JPanel if (av.getShowHiddenMarkers()) { - List positions = hidden.findHiddenRegionPositions(); - for (int pos : positions) + Iterator it = hidden.getStartRegionIterator(startx, + startx + widthx + 1); + while (it.hasNext()) { - res = pos - startx; - - if (res < 0 || res > widthx) - { - continue; - } + res = it.next() - startx; gg.fillPolygon( new int[] - { -1 + res * avCharWidth - avCharHeight / 4, - -1 + res * avCharWidth + avCharHeight / 4, - -1 + res * avCharWidth }, - new int[] - { y, y, y + 2 * yOf }, 3); + { -1 + res * avCharWidth - avCharHeight / 4, + -1 + res * avCharWidth + avCharHeight / 4, + -1 + res * avCharWidth }, new int[] + { y, y, y + 2 * yOf }, 3); } } } @@ -550,10 +554,15 @@ public class ScalePanel extends JPanel // paint, so scroll events are identified as changes to the horizontal or // vertical start value. if (evt.getPropertyName().equals(ViewportRanges.STARTRES) - || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) + || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ) + || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) { // scroll event, repaint panel - repaint(); + + // Call repaint on alignment panel so that repaints from other alignment + // panel components can be aggregated. Otherwise performance of the overview + // window and others may be adversely affected. + av.getAlignPanel().repaint(); } }