X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=798c833735b18a6358ffc642fbae0feebe61ce21;hb=0a849b60d2a0419da55f9a3a05b3fe2ed9a576bf;hp=bc59f912bbde73d3eb4fcf860e2f28fa8551e60e;hpb=d1707d4c26db76cfeb640f0dbeb3e3427fd40eb7;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index bc59f91..798c833 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -28,6 +28,8 @@ import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; import java.awt.Color; import java.awt.FontMetrics; @@ -39,6 +41,7 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JMenuItem; @@ -51,8 +54,8 @@ import javax.swing.ToolTipManager; * The panel containing the sequence ruler (when not in wrapped mode), and * supports a range of mouse operations to select, hide or reveal columns. */ -public class ScalePanel extends JPanel implements MouseMotionListener, - MouseListener +public class ScalePanel extends JPanel + implements MouseMotionListener, MouseListener, ViewportListenerI { protected int offy = 4; @@ -91,6 +94,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, addMouseListener(this); addMouseMotionListener(this); + + av.getRanges().addPropertyChangeListener(this); } /** @@ -163,11 +168,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { av.showColumn(reveal[0]); reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -183,11 +184,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { av.showAllHiddenColumns(); reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -205,18 +202,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener, public void actionPerformed(ActionEvent e) { av.hideColumns(res, res); - if (av.getSelectionGroup() != null - && av.getSelectionGroup().getSize() == av.getAlignment() - .getHeight()) + if (av.getSelectionGroup() != null && av.getSelectionGroup() + .getSize() == av.getAlignment().getHeight()) { av.setSelectionGroup(null); } - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -268,7 +260,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, sg.setEndRes(max); } av.setSelectionGroup(sg); - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -305,7 +297,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } else { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } return; } @@ -324,7 +316,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -354,7 +346,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { stretchingGroup = true; cs.stretchGroup(res, sg, min, max); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -397,24 +389,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); + reveal = av.getAlignment().getHiddenColumns() + .getRegionWithEdgeAtRes(res); + res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); - if (av.getAlignment().getHiddenColumns().getListOfCols() != null) - { - for (int[] region : av.getAlignment().getHiddenColumns() - .getListOfCols()) - { - if (res + 1 == region[0] || res - 1 == region[1]) - { - reveal = region; - ToolTipManager.sharedInstance().registerComponent(this); - this.setToolTipText(MessageManager - .getString("label.reveal_hidden_columns")); - repaint(); - return; - } - } - } + ToolTipManager.sharedInstance().registerComponent(this); + this.setToolTipText( + MessageManager.getString("label.reveal_hidden_columns")); + repaint(); } /** @@ -426,8 +409,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener, @Override public void paintComponent(Graphics g) { - drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(), - getWidth(), getHeight()); + /* + * shouldn't get called in wrapped mode as the scale above is + * drawn instead by SeqCanvas.drawNorthScale + */ + if (!av.getWrapAlignment()) + { + drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(), + getWidth(), getHeight()); + } } // scalewidth will normally be screenwidth, @@ -495,23 +485,25 @@ public class ScalePanel extends JPanel implements MouseMotionListener, gg.setColor(Color.blue); int res; - if (av.getShowHiddenMarkers() && hidden.getListOfCols() != null) + if (av.getShowHiddenMarkers()) { - for (int i = 0; i < hidden.getListOfCols() - .size(); i++) + List positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = hidden.findHiddenRegionPosition(i) - - startx; + res = pos - startx; if (res < 0 || res > widthx) { continue; } - 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); + 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); } } } @@ -548,4 +540,22 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } + @Override + public void propertyChange(PropertyChangeEvent evt) + { + // Respond to viewport change events (e.g. alignment panel was scrolled) + // Both scrolling and resizing change viewport ranges: scrolling changes + // both start and end points, but resize only changes end values. + // 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) + || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ) + || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) + { + // scroll event, repaint panel + repaint(); + } + } + }