X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=87711194a7a9da5b71b9d3c99cb1663f3efb53f7;hb=1e9fada0960dc5f73bfb873c358f0c479864aab7;hp=4e4db23731496b1c0d9b480c7caf4110f33bf1a9;hpb=5e92df41fe4f6fa8b50c3a65000bdb8ddcdc901f;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 4e4db23..8771119 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()) @@ -168,13 +170,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().hasManyHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions()) { item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -184,7 +186,7 @@ public class ScalePanel extends JPanel { av.showAllHiddenColumns(); reveal = null; - ap.paintAlignment(true); + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -208,7 +210,7 @@ public class ScalePanel extends JPanel av.setSelectionGroup(null); } - ap.paintAlignment(true); + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -260,34 +262,31 @@ 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(); + // todo res calculation should be a method on AlignViewport int res = (evt.getX() / 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 +296,7 @@ public class ScalePanel extends JPanel } else { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } return; } @@ -316,7 +315,7 @@ public class ScalePanel extends JPanel } } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -336,7 +335,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 +345,7 @@ public class ScalePanel extends JPanel { stretchingGroup = true; cs.stretchGroup(res, sg, min, max); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -355,16 +354,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 +398,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 +415,8 @@ public class ScalePanel extends JPanel @Override public void paintComponent(Graphics g) { + super.paintComponent(g); + /* * shouldn't get called in wrapped mode as the scale above is * drawn instead by SeqCanvas.drawNorthScale @@ -457,7 +465,7 @@ public class ScalePanel extends JPanel { if (hidden.isVisible(sel)) { - sel = hidden.findColumnPosition(sel); + sel = hidden.absoluteToVisibleColumn(sel); } else { @@ -487,19 +495,18 @@ public class ScalePanel extends JPanel if (av.getShowHiddenMarkers()) { - List positions = hidden.findHiddenRegionPositions(startx, + Iterator it = hidden.getStartRegionIterator(startx, startx + widthx + 1); - for (int pos : positions) + while (it.hasNext()) { - res = pos - startx; + 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); } } } @@ -545,10 +552,16 @@ public class ScalePanel extends JPanel // Here we only want to fastpaint on a scroll, with resize using a normal // paint, so scroll events are identified as changes to the horizontal or // vertical start value. - if (evt.getPropertyName().equals(ViewportRanges.STARTRES)) + if (evt.getPropertyName().equals(ViewportRanges.STARTRES) + || 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(); } }