From: kiramt Date: Thu, 11 May 2017 16:24:20 +0000 (+0100) Subject: JAL-2491 First port to applet X-Git-Tag: Release_2_10_2~3^2~64^2~13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ad66d7d56acd4063655df6a845e217683b88523e;p=jalview.git JAL-2491 First port to applet --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 2646ede..3f02c33 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -597,24 +597,22 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, case KeyEvent.VK_PAGE_UP: if (viewport.getWrapAlignment()) { - alignPanel.scrollUp(true); + ranges.scrollUp(true); } else { - alignPanel.setScrollValues(ranges.getStartRes(), - 2 * ranges.getStartSeq() - ranges.getEndSeq()); + ranges.pageUp(); } break; case KeyEvent.VK_PAGE_DOWN: if (viewport.getWrapAlignment()) { - alignPanel.scrollUp(false); + ranges.scrollUp(false); } else { - alignPanel - .setScrollValues(ranges.getStartRes(), ranges.getEndSeq()); + ranges.pageDown(); } break; diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 3ae0394..d7f2d5e 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceI; import jalview.structure.StructureSelectionManager; +import jalview.viewmodel.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; @@ -42,10 +43,11 @@ import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.beans.PropertyChangeEvent; import java.util.List; public class AlignmentPanel extends Panel implements AdjustmentListener, - AlignmentViewPanel + AlignmentViewPanel, ViewportListenerI { public AlignViewport av; @@ -131,7 +133,26 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, @Override public void componentResized(ComponentEvent evt) { - setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); + // reset the viewport ranges when the alignment panel is resized + // in particular, this initialises the end residue value when Jalview + // is initialised + if (av.getWrapAlignment()) + { + int widthInRes = seqPanel.seqCanvas + .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + vpRanges.setViewportWidth(widthInRes); + } + else + { + int widthInRes = seqPanel.seqCanvas.getWidth() + / av.getCharWidth(); + int heightInSeq = seqPanel.seqCanvas.getHeight() + / av.getCharHeight(); + + vpRanges.setViewportWidth(widthInRes); + vpRanges.setViewportHeight(heightInSeq); + } + // setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); if (getSize().height > 0 && annotationPanelHolder.getSize().height > 0) { @@ -164,6 +185,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, } } }); + av.getRanges().addPropertyChangeListener(this); } @Override @@ -230,11 +252,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, annotationPanel.repaint(); validate(); repaint(); - - if (overviewPanel != null) - { - overviewPanel.updateOverviewImage(); - } } public void setIdWidth(int w, int h) @@ -508,28 +525,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, } else { - scrollToWrappedVisible(start); - } - if (redrawOverview && overviewPanel != null) - { - overviewPanel.setBoxPosition(); + vpRanges.scrollToWrappedVisible(start); } + paintAlignment(redrawOverview); return true; } - void scrollToWrappedVisible(int res) - { - int cwidth = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); - if (res <= vpRanges.getStartRes() - || res >= (vpRanges.getStartRes() + cwidth)) - { - vscroll.setValue(res / cwidth); - vpRanges.setStartRes(vscroll.getValue() * cwidth); - } - } - public OverviewPanel getOverviewPanel() { return overviewPanel; @@ -671,126 +673,77 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, int vextent = 0; - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) + public void setScrollValues(int x, int y) { - if (up) + if (av.getWrapAlignment()) { - if (vscroll.getValue() < 1) - { - return false; - } - setScrollValues(hscroll.getValue(), vscroll.getValue() - 1); + setScrollingForWrappedPanel(x); } else { - if (vextent + vscroll.getValue() >= av.getAlignment().getHeight()) - { - return false; - } - setScrollValues(hscroll.getValue(), vscroll.getValue() + 1); - } - repaint(); - return true; - } + int width = av.getAlignment().getWidth(); + int height = av.getAlignment().getHeight(); - public boolean scrollRight(boolean right) - { - if (!right) - { - if (hscroll.getValue() < 1) + if (av.hasHiddenColumns()) { - return false; + width = av.getColumnSelection().findColumnPosition(width); } - setScrollValues(hscroll.getValue() - 1, vscroll.getValue()); - } - else - { - if (hextent + hscroll.getValue() >= av.getAlignment().getWidth()) + if (x < 0) { - return false; + x = 0; } - setScrollValues(hscroll.getValue() + 1, vscroll.getValue()); - } - repaint(); - return true; - } - - public void setScrollValues(int x, int y) - { - int width = av.getAlignment().getWidth(); - int height = av.getAlignment().getHeight(); - - if (av.hasHiddenColumns()) - { - width = av.getColumnSelection().findColumnPosition(width); - } - if (x < 0) - { - x = 0; - } - - - hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth(); - vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight(); - - if (hextent > width) - { - hextent = width; - } + hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth(); + vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight(); - if (vextent > height) - { - vextent = height; - } + if (hextent > width) + { + hextent = width; + } - if ((hextent + x) > width) - { - System.err.println("hextent was " + hextent + " and x was " + x); + if (vextent > height) + { + vextent = height; + } - x = width - hextent; - } + if ((hextent + x) > width) + { + System.err.println("hextent was " + hextent + " and x was " + x); - if ((vextent + y) > height) - { - y = height - vextent; - } + x = width - hextent; + } - if (y < 0) - { - y = 0; - } + if ((vextent + y) > height) + { + y = height - vextent; + } - if (x < 0) - { - System.err.println("x was " + x); - x = 0; - } + if (y < 0) + { + y = 0; + } - vpRanges.setStartSeq(y); - vpRanges.setEndSeq(y + vextent); - vpRanges.setStartRes(x); - vpRanges.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av - .getCharWidth())) - 1); + if (x < 0) + { + System.err.println("x was " + x); + x = 0; + } - hscroll.setValues(x, hextent, 0, width); - vscroll.setValues(y, vextent, 0, height); + hscroll.setValues(x, hextent, 0, width); + vscroll.setValues(y, vextent, 0, height); - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); + sendViewPosition(); } - sendViewPosition(); - } @Override public void adjustmentValueChanged(AdjustmentEvent evt) { int oldX = vpRanges.getStartRes(); + int oldwidth = vpRanges.getViewportWidth(); int oldY = vpRanges.getStartSeq(); + int oldheight = vpRanges.getViewportHeight(); if (evt == null || evt.getSource() == apvscroll) { @@ -804,9 +757,16 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, if (evt == null || evt.getSource() == hscroll) { int x = hscroll.getValue(); - vpRanges.setStartRes(x); - vpRanges.setEndRes(x + seqPanel.seqCanvas.getSize().width - / av.getCharWidth() - 1); + int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth(); + + // if we're scrolling to the position we're already at, stop + // this prevents infinite recursion of events when the scroll/viewport + // ranges values are the same + if ((x == oldX) && (width == oldwidth)) + { + return; + } + vpRanges.setViewportStartAndWidth(x, width); } if (evt == null || evt.getSource() == vscroll) @@ -815,67 +775,84 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, if (av.getWrapAlignment()) { int rowSize = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); - vpRanges.setStartRes(vscroll.getValue() * rowSize); - vpRanges.setEndRes((vscroll.getValue() + 1) * rowSize); + .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + + // if we're scrolling to the position we're already at, stop + // this prevents infinite recursion of events when the scroll/viewport + // ranges values are the same + if ((offy * rowSize == oldX) && (oldwidth == rowSize)) + { + return; + } + else if (offy > -1) + { + vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); + } } else { - vpRanges.setStartSeq(offy); - vpRanges.setEndSeq(offy + seqPanel.seqCanvas.getSize().height - / av.getCharHeight() - 1); - } - } + int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight(); - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); + // if we're scrolling to the position we're already at, stop + // this prevents infinite recursion of events when the scroll/viewport + // ranges values are the same + if ((offy == oldY) && (height == oldheight)) + { + return; + } + vpRanges.setViewportStartAndHeight(offy, height); + } } - int scrollX = vpRanges.getStartRes() - oldX; - int scrollY = vpRanges.getStartSeq() - oldY; + /* if (overviewPanel != null) + { + overviewPanel.setBoxPosition(); + } + int scrollX = vpRanges.getStartRes() - oldX; + int scrollY = vpRanges.getStartSeq() - oldY; + */ if (av.getWrapAlignment() || !fastPaint || av.MAC) { repaint(); } - else - { - // Make sure we're not trying to draw a panel - // larger than the visible window - if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) - { - scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); - } - else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) - { - scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); - } - - idPanel.idCanvas.fastPaint(scrollY); - seqPanel.seqCanvas.fastPaint(scrollX, scrollY); - - scalePanel.repaint(); - if (av.isShowAnnotation()) - { - annotationPanel.fastPaint(vpRanges.getStartRes() - oldX); - } - } + /* else + { + // Make sure we're not trying to draw a panel + // larger than the visible window + if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) + { + scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); + } + else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) + { + scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); + } + + idPanel.idCanvas.fastPaint(scrollY); + seqPanel.seqCanvas.fastPaint(scrollX, scrollY); + + scalePanel.repaint(); + if (av.isShowAnnotation()) + { + annotationPanel.fastPaint(vpRanges.getStartRes() - oldX); + } + }*/ sendViewPosition(); /* * If there is one, scroll the (Protein/cDNA) complementary alignment to * match, unless we are ourselves doing that. */ - if (isFollowingComplementScroll()) - { - setFollowingComplementScroll(false); - } - else - { - AlignmentPanel ap = getComplementPanel(); - av.scrollComplementaryAlignment(ap); - } + /* if (isFollowingComplementScroll()) + { + setFollowingComplementScroll(false); + } + else + { + AlignmentPanel ap = getComplementPanel(); + av.scrollComplementaryAlignment(ap); + }*/ } @@ -927,7 +904,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, * This is like AlignmentI.findIndex(seq) but here we are matching the * dataset sequence not the aligned sequence */ - int sequenceIndex = 0; boolean matched = false; for (SequenceI seq : seqs) { @@ -936,7 +912,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, matched = true; break; } - sequenceIndex++; } if (!matched) { @@ -1003,30 +978,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, idPanel.idCanvas.setSize(d.width, canvasHeight); } - if (av.getWrapAlignment()) - { - int maxwidth = av.getAlignment().getWidth(); - - if (av.hasHiddenColumns()) - { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; - } - - int canvasWidth = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); - - if (canvasWidth > 0) - { - int max = maxwidth / canvasWidth; - vscroll.setMaximum(1 + max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); - } - } - else - { - setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); - } + setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); seqPanel.seqCanvas.repaint(); idPanel.idCanvas.repaint(); @@ -1042,6 +994,36 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, } + /* + * Set vertical scroll bar parameters for wrapped panel + * @param res + * the residue to scroll to + */ + private void setScrollingForWrappedPanel(int res) + { + // get the width of the alignment in residues + int maxwidth = av.getAlignment().getWidth(); + if (av.hasHiddenColumns()) + { + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + } + + // get the width of the canvas in residues + int canvasWidth = seqPanel.seqCanvas + .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); + if (canvasWidth > 0) + { + // position we want to scroll to is number of canvasWidth's to get there + int current = res / canvasWidth; + + // max scroll position: add one because extent is 1 and scrollbar value + // can only be set to at most max - extent + int max = maxwidth / canvasWidth + 1; + vscroll.setUnitIncrement(1); + vscroll.setValues(current, 1, 0, max); + } + } + protected Panel sequenceHolderPanel = new Panel(); protected Scrollbar vscroll = new Scrollbar(); @@ -1187,4 +1169,27 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, return this.followingComplementScroll; } + @Override + /** + * Property change event fired when a change is made to the viewport ranges + * object associated with this alignment panel's viewport + */ + public void propertyChange(PropertyChangeEvent evt) + { + // update this panel's scroll values based on the new viewport ranges values + int x = vpRanges.getStartRes(); + int y = vpRanges.getStartSeq(); + setScrollValues(x, y); + + // now update any complementary alignment (its viewport ranges object + // is different so does not get automatically updated) + if (isFollowingComplementScroll()) + { + setFollowingComplementScroll(false); + av.scrollComplementaryAlignment(getComplementPanel()); + setFollowingComplementScroll(true); + } + + } + }