X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=d1818049b39a1dfc9dcba4f5a107f7142c479d76;hb=250e53ccab49a91570c00e4f64f565a509db9e68;hp=e5f2be8109d1314d421fd178905b40d01766c830;hpb=a41b74d63832baaf00daac0a176118dc751c3b24;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index e5f2be8..d181804 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -23,7 +23,6 @@ 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; @@ -42,6 +41,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; @@ -54,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, ViewportListenerI +public class ScalePanel extends JPanel + implements MouseMotionListener, MouseListener, ViewportListenerI { protected int offy = 4; @@ -112,7 +112,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.hasHiddenColumns()) { - x = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(x); + x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x); } if (x >= av.getAlignment().getWidth()) @@ -168,17 +168,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.getAlignment().getHiddenColumns().hasHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions()) { item = new JMenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -188,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(); } }); @@ -210,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(); } }); @@ -249,15 +236,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); - // try to be as quick as possible - SequenceI[] iVec = av.getAlignment().getSequencesArray(); - for (int i = 0; i < iVec.length; i++) - { - sg.addSequence(iVec[i], false); - iVec[i] = null; - } - iVec = null; + SequenceGroup sg = new SequenceGroup(av.getAlignment().getSequences()); sg.setStartRes(res); sg.setEndRes(res); @@ -273,7 +252,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, sg.setEndRes(max); } av.setSelectionGroup(sg); - ap.paintAlignment(false); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -288,13 +267,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.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(res); + .visibleToAbsoluteColumn(res); } if (res >= av.getAlignment().getWidth()) @@ -310,7 +291,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } else { - ap.paintAlignment(false); + ap.paintAlignment(false, false); } return; } @@ -329,13 +310,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); + av.isSelectionGroupChanged(true); + av.isColSelChanged(true); av.sendSelection(); } /** * Action on dragging the mouse in the scale panel is to expand or shrink the - * selection group range (including any hidden columns that it spans) + * selection group range (including any hidden columns that it spans). Note + * that the selection is only broadcast at the start of the drag (on + * mousePressed) and at the end (on mouseReleased), to avoid overload + * redrawing of other views. * * @param evt */ @@ -349,7 +335,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, 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); @@ -359,7 +345,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { stretchingGroup = true; cs.stretchGroup(res, sg, min, max); - ap.paintAlignment(false); + ap.paintAlignment(false, false); } } @@ -405,7 +391,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, reveal = av.getAlignment().getHiddenColumns() .getRegionWithEdgeAtRes(res); - res = av.getAlignment().getHiddenColumns().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); ToolTipManager.sharedInstance().registerComponent(this); this.setToolTipText( @@ -422,8 +408,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, @@ -463,7 +458,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { if (hidden.isVisible(sel)) { - sel = hidden.findColumnPosition(sel); + sel = hidden.absoluteToVisibleColumn(sel); } else { @@ -493,20 +488,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, 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, + 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); } } } @@ -552,10 +545,16 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // 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(); } }