X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FScalePanel.java;h=d3f4a699a35405f86f6138c0335491d50a2fccca;hb=4f77328104498504339216829abf5ea87e2791ec;hp=9106385a549c4b7898295d7cf5585c082f85ba55;hpb=ea710b87c966bf443b6526236ae38a38edf06b3b;p=jalview.git diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 9106385..d3f4a69 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -21,8 +21,13 @@ package jalview.appletgui; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; import java.awt.Color; import java.awt.FontMetrics; @@ -36,9 +41,12 @@ import java.awt.event.InputEvent; 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; -public class ScalePanel extends Panel implements MouseMotionListener, - MouseListener +public class ScalePanel extends Panel + implements MouseMotionListener, MouseListener, ViewportListenerI { protected int offy = 4; @@ -68,17 +76,18 @@ public class ScalePanel extends Panel implements MouseMotionListener, addMouseListener(this); addMouseMotionListener(this); + av.getRanges().addPropertyChangeListener(this); } @Override public void mousePressed(MouseEvent evt) { - int x = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int x = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes(); final int res; if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(x); + res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x); } else { @@ -87,7 +96,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, min = res; max = res; - if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) + if ((evt.getModifiersEx() + & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK) { rightMouseButtonPressed(evt, res); } @@ -132,7 +142,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, sg.setStartRes(min); sg.setEndRes(max); } - ap.paintAlignment(true); + ap.paintAlignment(false, false); av.sendSelection(); } @@ -158,17 +168,13 @@ public class ScalePanel extends Panel 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().hasManyHiddenColumns()) + if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions()) { item = new MenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() @@ -178,11 +184,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, { av.showAllHiddenColumns(); reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.paintAlignment(true, true); av.sendSelection(); } }); @@ -201,18 +203,13 @@ public class ScalePanel extends Panel 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(); } }); @@ -227,7 +224,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, { mouseDragging = false; - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); if (res > av.getAlignment().getWidth()) { @@ -236,12 +234,13 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (av.hasHiddenColumns()) { - res = av.getColumnSelection().adjustForHiddenColumns(res); + res = av.getAlignment().getHiddenColumns() + .visibleToAbsoluteColumn(res); } if (!stretchingGroup) { - ap.paintAlignment(false); + ap.paintAlignment(false, false); return; } @@ -258,77 +257,36 @@ public class ScalePanel extends Panel implements MouseMotionListener, } stretchingGroup = false; - ap.paintAlignment(false); + ap.paintAlignment(false, false); 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) + * + * @param evt + */ @Override public void mouseDragged(MouseEvent evt) { mouseDragging = true; + ColumnSelection cs = av.getColumnSelection(); - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - if (res < 0) - { - res = 0; - } - - if (av.hasHiddenColumns()) - { - res = av.getColumnSelection().adjustForHiddenColumns(res); - } - - if (res > av.getAlignment().getWidth()) - { - res = av.getAlignment().getWidth() - 1; - } - - if (res < min) - { - min = res; - } - - if (res > max) - { - max = res; - } + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); + res = Math.max(0, res); + res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); + res = Math.min(res, av.getAlignment().getWidth() - 1); + min = Math.min(res, min); + max = Math.max(res, max); SequenceGroup sg = av.getSelectionGroup(); - if (sg != null) { stretchingGroup = true; - - if (!av.getColumnSelection().contains(res)) - { - av.getColumnSelection().addElement(res); - } - - if (res > sg.getStartRes()) - { - sg.setEndRes(res); - } - if (res < sg.getStartRes()) - { - sg.setStartRes(res); - } - - int col; - for (int i = min; i <= max; i++) - { - col = av.getColumnSelection().adjustForHiddenColumns(i); - - if ((col < sg.getStartRes()) || (col > sg.getEndRes())) - { - av.getColumnSelection().removeElement(col); - } - else - { - av.getColumnSelection().addElement(col); - } - } - - ap.paintAlignment(false); + cs.stretchGroup(res, sg, min, max); + ap.paintAlignment(false, false); } } @@ -364,19 +322,11 @@ public class ScalePanel extends Panel implements MouseMotionListener, return; } - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); - res = av.getColumnSelection().adjustForHiddenColumns(res); - - reveal = null; - for (int[] region : av.getColumnSelection().getHiddenColumns()) - { - if (res + 1 == region[0] || res - 1 == region[1]) - { - reveal = region; - break; - } - } + reveal = av.getAlignment().getHiddenColumns() + .getRegionWithEdgeAtRes(res); repaint(); } @@ -390,8 +340,15 @@ public class ScalePanel extends Panel implements MouseMotionListener, @Override public void paint(Graphics g) { - drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width, - getSize().height); + /* + * 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(), + getSize().width, getSize().height); + } } // scalewidth will normally be screenwidth, @@ -406,63 +363,70 @@ public class ScalePanel extends Panel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); - gg.setColor(new Color(220, 0, 0)); - int avcharWidth = av.getCharWidth(), avcharHeight = av.getCharHeight(); - for (int sel : cs.getSelected()) + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + int avCharWidth = av.getCharWidth(); + int avcharHeight = av.getCharHeight(); + if (cs != null) { - // TODO: JAL-2001 - provide a fast method to list visible selected in a - // given range - if (av.hasHiddenColumns()) + gg.setColor(new Color(220, 0, 0)); + boolean hasHiddenColumns = hidden.hasHiddenColumns(); + for (int sel : cs.getSelected()) { - sel = av.getColumnSelection().findColumnPosition(sel); - } + // TODO: JAL-2001 - provide a fast method to list visible selected in a + // given range + if (hasHiddenColumns) + { + if (hidden.isVisible(sel)) + { + sel = hidden.absoluteToVisibleColumn(sel); + } + else + { + continue; + } + } - if ((sel >= startx) && (sel <= endx)) - { - gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth, - getSize().height); + if ((sel >= startx) && (sel <= endx)) + { + gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth, + getSize().height); + } } } // Draw the scale numbers gg.setColor(Color.black); - int scalestartx = (startx / 10) * 10; - - FontMetrics fm = gg.getFontMetrics(av.getFont()); - int y = avcharHeight - fm.getDescent(); - - if ((scalestartx % 10) == 0) - { - scalestartx += 5; - } - - String string; int maxX = 0; + List marks = new ScaleRenderer().calculateMarks(av, startx, + endx); - for (int i = scalestartx; i < endx; i += 5) + FontMetrics fm = gg.getFontMetrics(av.getFont()); + int y = avcharHeight; + int yOf = fm.getDescent(); + y -= yOf; + for (ScaleMark mark : marks) { - if ((i % 10) == 0) + boolean major = mark.major; + int mpos = mark.column; // (i - startx - 1) + String mstring = mark.text; + if (mstring != null) { - string = String.valueOf(av.getColumnSelection() - .adjustForHiddenColumns(i)); - if ((i - startx - 1) * avcharWidth > maxX) + if (mpos * avCharWidth > maxX) { - gg.drawString(string, (i - startx - 1) * avcharWidth, y); - maxX = (i - startx + 1) * avcharWidth + fm.stringWidth(string); + gg.drawString(mstring, mpos * avCharWidth, y); + maxX = (mpos + 2) * avCharWidth + fm.stringWidth(mstring); } - - gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), - y + 2, - ((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y - + (fm.getDescent() * 2)); - + } + if (major) + { + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + 2, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); } else { - gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y - + fm.getDescent(), ((i - startx - 1) * avcharWidth) - + (avcharWidth / 2), y + (fm.getDescent() * 2)); + gg.drawLine((mpos * avCharWidth) + (avCharWidth / 2), y + yOf, + (mpos * avCharWidth) + (avCharWidth / 2), y + (yOf * 2)); } } @@ -472,33 +436,39 @@ public class ScalePanel extends Panel implements MouseMotionListener, int res; if (av.getShowHiddenMarkers()) { - for (int i = 0; i < av.getColumnSelection().getHiddenColumns() - .size(); i++) + int widthx = 1 + endx - startx; + Iterator it = hidden.getStartRegionIterator(startx, + startx + widthx + 1); + while (it.hasNext()) { + res = it.next() - startx; - res = av.getColumnSelection().findHiddenRegionPosition(i) - - startx; - - if (res < 0 || res > endx - scalestartx) - { - continue; - } - - gg.fillPolygon(new int[] { res * avcharWidth - avcharHeight / 4, - res * avcharWidth + avcharHeight / 4, res * avcharWidth }, - new int[] { y - avcharHeight / 2, y - avcharHeight / 2, - y + 8 }, 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); } } - - if (reveal != null && reveal[0] > startx && reveal[0] < endx) - { - gg.drawString(MessageManager.getString("label.reveal_columns"), - reveal[0] * avcharWidth, 0); - } } + } + @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(); + } } }