X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=6abee0882b7b8a31e230e64735c5c5ff549b4b1e;hb=2d2b6828b010b374731bb3de3945440977b77a66;hp=de21be6225003849c996f0743dae32d4674568cd;hpb=97b26ba418dec7a6e926378205d25470bf098633;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index de21be6..6abee08 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -21,12 +21,15 @@ package jalview.gui; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; 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; @@ -38,6 +41,8 @@ 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.Iterator; import java.util.List; import javax.swing.JMenuItem; @@ -50,8 +55,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; @@ -90,6 +95,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, addMouseListener(this); addMouseMotionListener(this); + + av.getRanges().addPropertyChangeListener(this); } /** @@ -106,7 +113,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - x = av.getColumnSelection().adjustForHiddenColumns(x); + x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x); } if (x >= av.getAlignment().getWidth()) @@ -162,17 +169,13 @@ 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(); } }); pop.add(item); - if (av.getColumnSelection().hasHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions()) { item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -182,11 +185,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(); } }); @@ -204,18 +203,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(); } }); @@ -267,7 +261,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, sg.setEndRes(max); } av.setSelectionGroup(sg); - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -282,12 +276,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { mouseDragging = false; - int res = (evt.getX() / av.getCharWidth()) + int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates + + int res = (xCords / av.getCharWidth()) + av.getRanges().getStartRes(); if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .visibleToAbsoluteColumn(res); } if (res >= av.getAlignment().getWidth()) @@ -303,7 +300,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } else { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } return; } @@ -322,7 +319,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -337,11 +334,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { mouseDragging = true; ColumnSelection cs = av.getColumnSelection(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); res = Math.max(0, res); - res = cs.adjustForHiddenColumns(res); + res = hidden.visibleToAbsoluteColumn(res); res = Math.min(res, av.getAlignment().getWidth() - 1); min = Math.min(res, min); max = Math.max(res, max); @@ -351,7 +349,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { stretchingGroup = true; cs.stretchGroup(res, sg, min, max); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -394,23 +392,15 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int res = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); - res = av.getColumnSelection().adjustForHiddenColumns(res); + reveal = av.getAlignment().getHiddenColumns() + .getRegionWithEdgeAtRes(res); - if (av.getColumnSelection().getHiddenColumns() != null) - { - for (int[] region : av.getColumnSelection().getHiddenColumns()) - { - 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; - } - } - } + res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); + + ToolTipManager.sharedInstance().registerComponent(this); + this.setToolTipText( + MessageManager.getString("label.reveal_hidden_columns")); + repaint(); } /** @@ -422,8 +412,17 @@ public class ScalePanel extends JPanel implements MouseMotionListener, @Override public void paintComponent(Graphics g) { - drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(), - getWidth(), getHeight()); + super.paintComponent(g); + + /* + * 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, @@ -446,7 +445,9 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); - int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + int avCharWidth = av.getCharWidth(); + int avCharHeight = av.getCharHeight(); if (cs != null) { @@ -459,9 +460,9 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - if (cs.isVisible(sel)) + if (hidden.isVisible(sel)) { - sel = cs.findColumnPosition(sel); + sel = hidden.absoluteToVisibleColumn(sel); } else { @@ -488,24 +489,21 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // draw any hidden column markers gg.setColor(Color.blue); int res; - if (av.getShowHiddenMarkers() - && av.getColumnSelection().getHiddenColumns() != null) + + if (av.getShowHiddenMarkers()) { - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() - .size(); i++) + Iterator it = hidden.getStartRegionIterator(startx, + startx + widthx + 1); + while (it.hasNext()) { - res = av.getColumnSelection().findHiddenRegionPosition(i) - - startx; + res = it.next() - startx; - if (res < 0 || res > widthx) - { - continue; - } - - gg.fillPolygon(new int[] { - -1 + res * avCharWidth - avCharHeight / 4, + 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 }, new int[] + { y, y, y + 2 * yOf }, 3); } } } @@ -542,4 +540,26 @@ 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 + + // 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(); + } + } + }