From: kiramt Date: Thu, 16 Mar 2017 17:30:14 +0000 (+0000) Subject: JAL-2388 Applied ViewportRanges to code X-Git-Tag: Release_2_10_2~3^2~92^2~33 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=97b26ba418dec7a6e926378205d25470bf098633;p=jalview.git JAL-2388 Applied ViewportRanges to code --- diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index c6312ab..bd43c60 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -47,11 +47,13 @@ import java.util.Map; public interface AlignViewportI extends ViewStyleI { - ViewportRanges getRanges(); - - int getEndRes(); - - int getStartRes(); + /** + * Get the ranges object containing details of the start and end sequences and + * residues + * + * @return + */ + public ViewportRanges getRanges(); /** * calculate the height for visible annotation, revalidating bounds where @@ -461,8 +463,4 @@ public interface AlignViewportI extends ViewStyleI * @return search results or null */ SearchResultsI getSearchResults(); - - int getStartSeq(); - - int getEndSeq(); } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index dc622f5..e51131b 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -75,6 +75,7 @@ import jalview.structures.models.AAStructureBindingModel; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Canvas; @@ -420,6 +421,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, @Override public void keyPressed(KeyEvent evt) { + ViewportRanges ranges = viewport.getRanges(); + if (viewport.cursorMode && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt @@ -571,8 +574,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, new String[] { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) { - alignPanel.seqPanel.seqCanvas.cursorX = viewport.getStartRes(); - alignPanel.seqPanel.seqCanvas.cursorY = viewport.getStartSeq(); + alignPanel.seqPanel.seqCanvas.cursorX = ranges.getStartRes(); + alignPanel.seqPanel.seqCanvas.cursorY = ranges.getStartSeq(); } break; @@ -598,8 +601,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } else { - alignPanel.setScrollValues(viewport.getStartRes(), - 2 * viewport.getStartSeq() - viewport.getEndSeq()); + alignPanel.setScrollValues(ranges.getStartRes(), + 2 * ranges.getStartSeq() - ranges.getEndSeq()); } break; @@ -610,8 +613,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } else { - alignPanel.setScrollValues(viewport.getStartRes(), - viewport.getEndSeq()); + alignPanel + .setScrollValues(ranges.getStartRes(), ranges.getEndSeq()); } break; @@ -2063,7 +2066,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, seqs, 0, viewport.getAlignment().getWidth(), viewport.getAlignment())); - viewport.setEndSeq(viewport.getAlignment().getHeight()); + viewport.getRanges().setEndSeq(viewport.getAlignment().getHeight()); viewport.getAlignment().getWidth(); viewport.firePropertyChange("alignment", null, viewport.getAlignment() .getSequences()); @@ -2299,6 +2302,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, void trimAlignment(boolean trimLeft) { + AlignmentI al = viewport.getAlignment(); + ViewportRanges ranges = viewport.getRanges(); ColumnSelection colSel = viewport.getColumnSelection(); int column; @@ -2321,20 +2326,20 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } else { - seqs = viewport.getAlignment().getSequencesArray(); + seqs = al.getSequencesArray(); } TrimRegionCommand trimRegion; if (trimLeft) { trimRegion = new TrimRegionCommand("Remove Left", true, seqs, - column, viewport.getAlignment()); - viewport.setStartRes(0); + column, al); + ranges.setStartRes(0); } else { trimRegion = new TrimRegionCommand("Remove Right", false, seqs, - column, viewport.getAlignment()); + column, al); } statusBar.setText(MessageManager.formatMessage( @@ -2343,23 +2348,25 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, .toString() })); addHistoryItem(trimRegion); - for (SequenceGroup sg : viewport.getAlignment().getGroups()) + for (SequenceGroup sg : al.getGroups()) { if ((trimLeft && !sg.adjustForRemoveLeft(column)) || (!trimLeft && !sg.adjustForRemoveRight(column))) { - viewport.getAlignment().deleteGroup(sg); + al.deleteGroup(sg); } } - viewport.firePropertyChange("alignment", null, viewport - .getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, al.getSequences()); } } public void removeGappedColumnMenuItem_actionPerformed() { - int start = 0, end = viewport.getAlignment().getWidth() - 1; + AlignmentI al = viewport.getAlignment(); + ViewportRanges ranges = viewport.getRanges(); + int start = 0; + int end = ranges.getAbsoluteAlignmentWidth() - 1; SequenceI[] seqs; if (viewport.getSelectionGroup() != null) @@ -2387,22 +2394,24 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // This is to maintain viewport position on first residue // of first sequence - SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(viewport.getStartRes()); + SequenceI seq = al.getSequenceAt(0); + int startRes = seq.findPosition(ranges.getStartRes()); // ShiftList shifts; // viewport.getAlignment().removeGaps(shifts=new ShiftList()); // edit.alColumnChanges=shifts.getInverse(); // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); - viewport.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + ranges.setStartRes(seq.findIndex(startRes) - 1); + viewport.firePropertyChange("alignment", null, al.getSequences()); } public void removeAllGapsMenuItem_actionPerformed() { - int start = 0, end = viewport.getAlignment().getWidth() - 1; + AlignmentI al = viewport.getAlignment(); + ViewportRanges ranges = viewport.getRanges(); + int start = 0; + int end = ranges.getAbsoluteAlignmentWidth() - 1; SequenceI[] seqs; if (viewport.getSelectionGroup() != null) @@ -2419,16 +2428,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // This is to maintain viewport position on first residue // of first sequence - SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(viewport.getStartRes()); + SequenceI seq = al.getSequenceAt(0); + int startRes = seq.findPosition(ranges.getStartRes()); addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end, - viewport.getAlignment())); + al)); - viewport.setStartRes(seq.findIndex(startRes) - 1); + ranges.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + viewport.firePropertyChange("alignment", null, al.getSequences()); } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 30817d5..065c503 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -297,7 +297,7 @@ public class AlignViewport extends AlignmentViewport implements public void resetSeqLimits(int height) { - setEndSeq(height / getCharHeight()); + ranges.setEndSeq(height / getCharHeight()); } public void setCurrentTree(NJTree tree) diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index e864337..3ae0394 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.ViewportRanges; import java.awt.BorderLayout; import java.awt.Color; @@ -65,6 +66,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, AnnotationLabels alabels; + ViewportRanges vpRanges; + // this value is set false when selection area being dragged boolean fastPaint = true; @@ -73,6 +76,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, { alignFrame = null; av = null; + vpRanges = null; seqPanel = null; seqPanelHolder = null; sequenceHolderPanel = null; @@ -96,6 +100,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, alignFrame = af; this.av = av; + vpRanges = av.getRanges(); seqPanel = new SeqPanel(av, this); idPanel = new IdPanel(av, this); scalePanel = new ScalePanel(av, this); @@ -126,7 +131,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, @Override public void componentResized(ComponentEvent evt) { - setScrollValues(av.getStartRes(), av.getStartSeq()); + setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); if (getSize().height > 0 && annotationPanelHolder.getSize().height > 0) { @@ -383,7 +388,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, */ if (centre) { - int offset = (av.getEndRes() - av.getStartRes() + 1) / 2 - 1; + int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1; start = Math.max(start - offset, 0); end = Math.min(end + offset, seq.getEnd() - 1); } @@ -468,33 +473,34 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, // setScrollValues(start, seqIndex); // } // logic copied from jalview.gui.AlignmentPanel: - if ((startv = av.getStartRes()) >= start) + if ((startv = vpRanges.getStartRes()) >= start) { /* * Scroll left to make start of search results visible */ setScrollValues(start - 1, seqIndex); } - else if ((endv = av.getEndRes()) <= end) + else if ((endv = vpRanges.getEndRes()) <= end) { /* * Scroll right to make end of search results visible */ setScrollValues(startv + 1 + end - endv, seqIndex); } - else if ((starts = av.getStartSeq()) > seqIndex) + else if ((starts = vpRanges.getStartSeq()) > seqIndex) { /* * Scroll up to make start of search results visible */ - setScrollValues(av.getStartRes(), seqIndex); + setScrollValues(vpRanges.getStartRes(), seqIndex); } - else if ((ends = av.getEndSeq()) <= seqIndex) + else if ((ends = vpRanges.getEndSeq()) <= seqIndex) { /* * Scroll down to make end of search results visible */ - setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); + setScrollValues(vpRanges.getStartRes(), starts + seqIndex - ends + + 1); } /* * Else results are already visible - no need to scroll @@ -516,10 +522,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, { int cwidth = seqPanel.seqCanvas .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); - if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth)) + if (res <= vpRanges.getStartRes() + || res >= (vpRanges.getStartRes() + cwidth)) { vscroll.setValue(res / cwidth); - av.setStartRes(vscroll.getValue() * cwidth); + vpRanges.setStartRes(vscroll.getValue() * cwidth); } } @@ -632,8 +639,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, public void setWrapAlignment(boolean wrap) { - av.setStartSeq(0); - av.setStartRes(0); + vpRanges.setStartSeq(0); + vpRanges.setStartRes(0); scalePanelHolder.setVisible(!wrap); hscroll.setVisible(!wrap); @@ -762,10 +769,10 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, x = 0; } - av.setStartSeq(y); - av.setEndSeq(y + vextent); - av.setStartRes(x); - av.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av + vpRanges.setStartSeq(y); + vpRanges.setEndSeq(y + vextent); + vpRanges.setStartRes(x); + vpRanges.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av .getCharWidth())) - 1); hscroll.setValues(x, hextent, 0, width); @@ -782,8 +789,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, @Override public void adjustmentValueChanged(AdjustmentEvent evt) { - int oldX = av.getStartRes(); - int oldY = av.getStartSeq(); + int oldX = vpRanges.getStartRes(); + int oldY = vpRanges.getStartSeq(); if (evt == null || evt.getSource() == apvscroll) { @@ -797,8 +804,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, if (evt == null || evt.getSource() == hscroll) { int x = hscroll.getValue(); - av.setStartRes(x); - av.setEndRes(x + seqPanel.seqCanvas.getSize().width + vpRanges.setStartRes(x); + vpRanges.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() - 1); } @@ -809,13 +816,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, { int rowSize = seqPanel.seqCanvas .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width); - av.setStartRes(vscroll.getValue() * rowSize); - av.setEndRes((vscroll.getValue() + 1) * rowSize); + vpRanges.setStartRes(vscroll.getValue() * rowSize); + vpRanges.setEndRes((vscroll.getValue() + 1) * rowSize); } else { - av.setStartSeq(offy); - av.setEndSeq(offy + seqPanel.seqCanvas.getSize().height + vpRanges.setStartSeq(offy); + vpRanges.setEndSeq(offy + seqPanel.seqCanvas.getSize().height / av.getCharHeight() - 1); } } @@ -825,8 +832,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, overviewPanel.setBoxPosition(); } - int scrollX = av.getStartRes() - oldX; - int scrollY = av.getStartSeq() - oldY; + int scrollX = vpRanges.getStartRes() - oldX; + int scrollY = vpRanges.getStartSeq() - oldY; if (av.getWrapAlignment() || !fastPaint || av.MAC) { @@ -836,13 +843,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, { // Make sure we're not trying to draw a panel // larger than the visible window - if (scrollX > av.getEndRes() - av.getStartRes()) + if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) { - scrollX = av.getEndRes() - av.getStartRes(); + scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); } - else if (scrollX < av.getStartRes() - av.getEndRes()) + else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) { - scrollX = av.getStartRes() - av.getEndRes(); + scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); } idPanel.idCanvas.fastPaint(scrollY); @@ -851,7 +858,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, scalePanel.repaint(); if (av.isShowAnnotation()) { - annotationPanel.fastPaint(av.getStartRes() - oldX); + annotationPanel.fastPaint(vpRanges.getStartRes() - oldX); } } sendViewPosition(); @@ -948,8 +955,9 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, private void sendViewPosition() { StructureSelectionManager.getStructureSelectionManager(av.applet) - .sendViewPosition(this, av.getStartRes(), av.getEndRes(), - av.getStartSeq(), av.getEndSeq()); + .sendViewPosition(this, vpRanges.getStartRes(), + vpRanges.getEndRes(), vpRanges.getStartSeq(), + vpRanges.getEndSeq()); } /** @@ -1017,7 +1025,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, } else { - setScrollValues(av.getStartRes(), av.getStartSeq()); + setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); } seqPanel.seqCanvas.repaint(); diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index b28ccc7..ad74b25 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -339,7 +339,8 @@ public class AnnotationLabels extends Panel implements ActionListener, av.calcPanelHeight()); f.height += dif; ap.seqPanelHolder.setPreferredSize(f); - ap.setScrollValues(av.getStartRes(), av.getStartSeq()); + ap.setScrollValues(av.getRanges().getStartRes(), av.getRanges() + .getStartSeq()); ap.validate(); // ap.paintAlignment(true); ap.addNotify(); diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 8b1bb26..0ec7adf 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -462,7 +462,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, } } - int column = evt.getX() / av.getCharWidth() + av.getStartRes(); + int column = evt.getX() / av.getCharWidth() + + av.getRanges().getStartRes(); if (av.hasHiddenColumns()) { @@ -618,7 +619,8 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, gg.setColor(Color.white); gg.fillRect(0, 0, getSize().width, getSize().height); - drawComponent(gg, av.getStartRes(), av.getEndRes() + 1); + drawComponent(gg, av.getRanges().getStartRes(), av.getRanges() + .getEndRes() + 1); g.drawImage(image, 0, 0, this); } @@ -635,7 +637,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.getCharWidth(), 0); - int sr = av.getStartRes(), er = av.getEndRes() + 1, transX = 0; + int sr = av.getRanges().getStartRes(), er = av.getRanges().getEndRes() + 1, transX = 0; if (horizontal > 0) // scrollbar pulled right, image to the left { diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index 18281d9..abcbd70 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -21,6 +21,7 @@ package jalview.appletgui; import jalview.datamodel.SequenceI; +import jalview.viewmodel.ViewportRanges; import java.awt.Color; import java.awt.Font; @@ -103,17 +104,20 @@ public class IdCanvas extends Panel return; } + ViewportRanges ranges = av.getRanges(); + gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.getCharHeight()); - int ss = av.getStartSeq(), es = av.getEndSeq(), transY = 0; + int ss = ranges.getStartSeq(), es = ranges.getEndSeq(), transY = 0; if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.getStartSeq()) // ie scrolling too fast, more than a page at a + if (ss < ranges.getStartSeq()) // ie scrolling too fast, more than a page + // at a // time { - ss = av.getStartSeq(); + ss = ranges.getStartSeq(); } else { @@ -123,9 +127,9 @@ public class IdCanvas extends Panel else if (vertical < 0) { es = ss - vertical; - if (es > av.getEndSeq()) + if (es > ranges.getEndSeq()) { - es = av.getEndSeq(); + es = ranges.getEndSeq(); } } @@ -181,7 +185,7 @@ public class IdCanvas extends Panel gg.setFont(italic); gg.fillRect(0, 0, getSize().width, getSize().height); - drawIds(av.getStartSeq(), av.getEndSeq()); + drawIds(av.getRanges().getStartSeq(), av.getRanges().getEndSeq()); g.drawImage(image, 0, 0, this); } @@ -234,9 +238,10 @@ public class IdCanvas extends Panel int cHeight = alheight * avcharHeight + hgap + annotationHeight; - int rowSize = av.getEndRes() - av.getStartRes(); + int rowSize = av.getRanges().getEndRes() + - av.getRanges().getStartRes(); // Draw the rest of the panels - for (int ypos = hgap, row = av.getStartRes(); (ypos <= getSize().height) + for (int ypos = hgap, row = av.getRanges().getStartRes(); (ypos <= getSize().height) && (row < maxwidth); ypos += cHeight, row += rowSize) { for (int i = starty; i < alheight; i++) diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index b03a638..e47c50a 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -253,13 +253,13 @@ public class IdPanel extends Panel implements MouseListener, return; } - if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0) + if (mouseDragging && e.getY() < 0 && av.getRanges().getStartSeq() > 0) { scrollThread = new ScrollThread(true); } if (mouseDragging && e.getY() >= getSize().height - && av.getAlignment().getHeight() > av.getEndSeq()) + && av.getAlignment().getHeight() > av.getRanges().getEndSeq()) { scrollThread = new ScrollThread(false); } @@ -398,9 +398,10 @@ public class IdPanel extends Panel implements MouseListener, int index = av.getAlignment().findIndex(list.get(0)); // do we need to scroll the panel? - if (av.getStartSeq() > index || av.getEndSeq() < index) + if (av.getRanges().getStartSeq() > index + || av.getRanges().getEndSeq() < index) { - alignPanel.setScrollValues(av.getStartRes(), index); + alignPanel.setScrollValues(av.getRanges().getStartRes(), index); } } @@ -431,10 +432,10 @@ public class IdPanel extends Panel implements MouseListener, if (alignPanel.scrollUp(up)) { // scroll was ok, so add new sequence to selection - int seq = av.getStartSeq(); + int seq = av.getRanges().getStartSeq(); if (!up) { - seq = av.getEndSeq(); + seq = av.getRanges().getEndSeq(); } if (seq < lastid) diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index ed07b63..15d82a5 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -76,7 +76,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, @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()) @@ -229,7 +229,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()) { @@ -276,7 +277,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, mouseDragging = true; ColumnSelection cs = av.getColumnSelection(); - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); res = Math.max(0, res); res = cs.adjustForHiddenColumns(res); res = Math.min(res, av.getAlignment().getWidth() - 1); @@ -324,7 +326,8 @@ 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); @@ -350,7 +353,8 @@ public class ScalePanel extends Panel implements MouseMotionListener, @Override public void paint(Graphics g) { - drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width, + drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(), + getSize().width, getSize().height); } diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index cd5aa74..b28b800 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -27,6 +27,7 @@ import jalview.datamodel.SequenceI; import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import java.awt.Color; import java.awt.FontMetrics; @@ -211,17 +212,19 @@ public class SeqCanvas extends Panel return; } + ViewportRanges ranges = av.getRanges(); + updateViewport(); // Its possible on certain browsers that the call to fastpaint // is faster than it can paint, so this check here catches // this possibility - if (lastsr + horizontal != av.getStartRes()) + if (lastsr + horizontal != ranges.getStartRes()) { - horizontal = av.getStartRes() - lastsr; + horizontal = ranges.getStartRes() - lastsr; } - lastsr = av.getStartRes(); + lastsr = ranges.getStartRes(); fastPaint = true; gg.copyArea(horizontal * avcharWidth, vertical * avcharHeight, imgWidth @@ -229,7 +232,8 @@ public class SeqCanvas extends Panel imgHeight - vertical * avcharHeight, -horizontal * avcharWidth, -vertical * avcharHeight); - int sr = av.getStartRes(), er = av.getEndRes(), ss = av.getStartSeq(), es = av + int sr = ranges.getStartRes(), er = ranges.getEndRes(), ss = ranges + .getStartSeq(), es = ranges .getEndSeq(), transX = 0, transY = 0; if (horizontal > 0) // scrollbar pulled right, image to the left @@ -245,10 +249,11 @@ public class SeqCanvas extends Panel else if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.getStartSeq()) // ie scrolling too fast, more than a page at a + if (ss < ranges.getStartSeq()) // ie scrolling too fast, more than a page + // at a // time { - ss = av.getStartSeq(); + ss = ranges.getStartSeq(); } else { @@ -258,9 +263,9 @@ public class SeqCanvas extends Panel else if (vertical < 0) { es = ss - vertical; - if (es > av.getEndSeq()) + if (es > ranges.getEndSeq()) { - es = av.getEndSeq(); + es = ranges.getEndSeq(); } } @@ -331,14 +336,16 @@ public class SeqCanvas extends Panel gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); + ViewportRanges ranges = av.getRanges(); + if (av.getWrapAlignment()) { - drawWrappedPanel(gg, imgWidth, imgHeight, av.getStartRes()); + drawWrappedPanel(gg, imgWidth, imgHeight, ranges.getStartRes()); } else { - drawPanel(gg, av.getStartRes(), av.getEndRes(), av.getStartSeq(), - av.getEndSeq(), 0); + drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(), + ranges.getStartSeq(), ranges.getEndSeq(), 0); } g.drawImage(img, 0, 0, this); @@ -424,7 +431,7 @@ public class SeqCanvas extends Panel av.setWrappedWidth(cWidth); - av.setEndRes(av.getStartRes() + cWidth); + av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth); int endx; int ypos = hgap; diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 946fc2a..0e12703 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -41,6 +41,7 @@ import jalview.structure.VamsasSource; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Font; @@ -226,16 +227,17 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - while (seqCanvas.cursorY < av.getStartSeq()) + ViewportRanges ranges = av.getRanges(); + while (seqCanvas.cursorY < ranges.getStartSeq()) { ap.scrollUp(true); } - while (seqCanvas.cursorY + 1 > av.getEndSeq()) + while (seqCanvas.cursorY + 1 > ranges.getEndSeq()) { ap.scrollUp(false); } while (seqCanvas.cursorX < av.getColumnSelection() - .adjustForHiddenColumns(av.getStartRes())) + .adjustForHiddenColumns(ranges.getStartRes())) { if (!ap.scrollRight(false)) @@ -244,7 +246,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } while (seqCanvas.cursorX > av.getColumnSelection() - .adjustForHiddenColumns(av.getEndRes())) + .adjustForHiddenColumns(ranges.getEndRes())) { if (!ap.scrollRight(true)) { @@ -624,14 +626,14 @@ public class SeqPanel extends Panel implements MouseMotionListener, } wrappedBlock = y / cHeight; - wrappedBlock += av.getStartRes() / cwidth; + wrappedBlock += av.getRanges().getStartRes() / cwidth; res = wrappedBlock * cwidth + x / av.getCharWidth(); } else { - res = (x / av.getCharWidth()) + av.getStartRes(); + res = (x / av.getCharWidth()) + av.getRanges().getStartRes(); } if (av.hasHiddenColumns()) @@ -681,7 +683,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(), av + seq = Math.min((y / av.getCharHeight()) + + av.getRanges().getStartSeq(), + av .getAlignment().getHeight() - 1); if (seq < 0) { @@ -1643,8 +1647,10 @@ public class SeqPanel extends Panel implements MouseMotionListener, oldSeq = -1; } - if (res > av.getEndRes() || res < av.getStartRes() - || y < av.getStartSeq() || y > av.getEndSeq()) + if (res > av.getRanges().getEndRes() + || res < av.getRanges().getStartRes() + || y < av.getRanges().getStartSeq() + || y > av.getRanges().getEndSeq()) { mouseExited(evt); } @@ -1742,13 +1748,15 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (evt != null) { - if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0) + if (mouseDragging && evt.getY() < 0 + && av.getRanges().getStartSeq() > 0) { running = ap.scrollUp(true); } if (mouseDragging && evt.getY() >= getSize().height - && av.getAlignment().getHeight() > av.getEndSeq()) + && av.getAlignment().getHeight() > av.getRanges() + .getEndSeq()) { running = ap.scrollUp(false); } @@ -1890,8 +1898,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, public void scrollTo(int row, int column) { - row = row < 0 ? ap.av.getStartSeq() : row; - column = column < 0 ? ap.av.getStartRes() : column; + row = row < 0 ? ap.av.getRanges().getStartSeq() : row; + column = column < 0 ? ap.av.getRanges().getStartRes() : column; ap.scrollTo(column, column, row, true, true); } @@ -1903,8 +1911,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, public void scrollToRow(int row) { - row = row < 0 ? ap.av.getStartSeq() : row; - ap.scrollTo(ap.av.getStartRes(), ap.av.getStartRes(), row, true, true); + row = row < 0 ? ap.av.getRanges().getStartSeq() : row; + ap.scrollTo(ap.av.getRanges().getStartRes(), ap.av.getRanges() + .getStartRes(), row, true, true); } /** @@ -1915,8 +1924,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, public void scrollToColumn(int column) { - column = column < 0 ? ap.av.getStartRes() : column; - ap.scrollTo(column, column, ap.av.getStartSeq(), true, true); + column = column < 0 ? ap.av.getRanges().getStartRes() : column; + ap.scrollTo(column, column, ap.av.getRanges().getStartSeq(), true, true); } /** diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 75d3677..ab1ac0e 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -86,6 +86,7 @@ import jalview.schemes.ResidueProperties; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; import jalview.ws.DBRefFetcher.FetchFinishedListenerI; import jalview.ws.jws1.Discoverer; @@ -160,6 +161,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignViewport viewport; + ViewportRanges vpRanges; + public AlignViewControllerI avc; List alignPanels = new ArrayList(); @@ -331,6 +334,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, progressBar = new ProgressBar(this.statusPanel, this.statusBar); } + vpRanges = viewport.getRanges(); avc = new jalview.controller.AlignViewController(this, viewport, alignPanel); if (viewport.getAlignmentConservationAnnotation() == null) @@ -640,9 +644,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new String[] { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) { - alignPanel.getSeqPanel().seqCanvas.cursorX = viewport + alignPanel.getSeqPanel().seqCanvas.cursorX = vpRanges .getStartRes(); - alignPanel.getSeqPanel().seqCanvas.cursorY = viewport + alignPanel.getSeqPanel().seqCanvas.cursorY = vpRanges .getStartSeq(); } alignPanel.getSeqPanel().seqCanvas.repaint(); @@ -681,8 +685,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.setScrollValues(viewport.getStartRes(), - 2 * viewport.getStartSeq() - viewport.getEndSeq()); + alignPanel.setScrollValues(vpRanges.getStartRes(), + 2 * vpRanges.getStartSeq() - vpRanges.getEndSeq()); } break; case KeyEvent.VK_PAGE_DOWN: @@ -692,8 +696,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.setScrollValues(viewport.getStartRes(), - viewport.getEndSeq()); + alignPanel.setScrollValues(vpRanges.getStartRes(), + vpRanges.getEndSeq()); } break; } @@ -2143,7 +2147,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // propagate alignment changed. - viewport.setEndSeq(alignment.getHeight()); + vpRanges.setEndSeq(alignment.getHeight()); if (annotationAdded) { // Duplicate sequence annotation in all views. @@ -2547,7 +2551,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { trimRegion = new TrimRegionCommand("Remove Left", true, seqs, column, viewport.getAlignment()); - viewport.setStartRes(0); + vpRanges.setStartRes(0); } else { @@ -2614,13 +2618,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(viewport.getStartRes()); + int startRes = seq.findPosition(vpRanges.getStartRes()); // ShiftList shifts; // viewport.getAlignment().removeGaps(shifts=new ShiftList()); // edit.alColumnChanges=shifts.getInverse(); // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); - viewport.setStartRes(seq.findIndex(startRes) - 1); + vpRanges.setStartRes(seq.findIndex(startRes) - 1); viewport.firePropertyChange("alignment", null, viewport.getAlignment() .getSequences()); @@ -2653,12 +2657,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(viewport.getStartRes()); + int startRes = seq.findPosition(vpRanges.getStartRes()); addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end, viewport.getAlignment())); - viewport.setStartRes(seq.findIndex(startRes) - 1); + vpRanges.setStartRes(seq.findIndex(startRes) - 1); viewport.firePropertyChange("alignment", null, viewport.getAlignment() .getSequences()); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 11321eb..602e3a1 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -852,7 +852,7 @@ public class AlignViewport extends AlignmentViewport implements } } - setEndSeq(getAlignment().getHeight()); + ranges.setEndSeq(getAlignment().getHeight()); firePropertyChange("alignment", null, getAlignment().getSequences()); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 631638f..ac137b9 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -35,6 +35,7 @@ import jalview.schemes.ResidueProperties; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Color; @@ -69,6 +70,8 @@ public class AlignmentPanel extends GAlignmentPanel implements { public AlignViewport av; + ViewportRanges vpRanges; + OverviewPanel overviewPanel; private SeqPanel seqPanel; @@ -113,6 +116,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { alignFrame = af; this.av = av; + vpRanges = av.getRanges(); setSeqPanel(new SeqPanel(av, this)); setIdPanel(new IdPanel(av, this)); @@ -377,7 +381,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ if (centre) { - int offset = (av.getEndRes() - av.getStartRes() + 1) / 2 - 1; + int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1; start = Math.max(start - offset, 0); end = end + offset - 1; } @@ -413,7 +417,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // + av.getStartSeq() + ", ends=" + av.getEndSeq()); if (!av.getWrapAlignment()) { - if ((startv = av.getStartRes()) >= start) + if ((startv = vpRanges.getStartRes()) >= start) { /* * Scroll left to make start of search results visible @@ -421,7 +425,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // setScrollValues(start - 1, seqIndex); // plus one residue setScrollValues(start, seqIndex); } - else if ((endv = av.getEndRes()) <= end) + else if ((endv = vpRanges.getEndRes()) <= end) { /* * Scroll right to make end of search results visible @@ -429,19 +433,20 @@ public class AlignmentPanel extends GAlignmentPanel implements // setScrollValues(startv + 1 + end - endv, seqIndex); // plus one setScrollValues(startv + end - endv, seqIndex); } - else if ((starts = av.getStartSeq()) > seqIndex) + else if ((starts = vpRanges.getStartSeq()) > seqIndex) { /* * Scroll up to make start of search results visible */ - setScrollValues(av.getStartRes(), seqIndex); + setScrollValues(vpRanges.getStartRes(), seqIndex); } - else if ((ends = av.getEndSeq()) <= seqIndex) + else if ((ends = vpRanges.getEndSeq()) <= seqIndex) { /* * Scroll down to make end of search results visible */ - setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); + setScrollValues(vpRanges.getStartRes(), starts + seqIndex - ends + + 1); } /* * Else results are already visible - no need to scroll @@ -464,10 +469,11 @@ public class AlignmentPanel extends GAlignmentPanel implements { int cwidth = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth)) + if (res < vpRanges.getStartRes() + || res >= (vpRanges.getStartRes() + cwidth)) { vscroll.setValue((res / cwidth)); - av.setStartRes(vscroll.getValue() * cwidth); + vpRanges.setStartRes(vscroll.getValue() * cwidth); } } @@ -591,7 +597,7 @@ public class AlignmentPanel extends GAlignmentPanel implements fontChanged(); setAnnotationVisible(av.isShowAnnotation()); boolean wrap = av.getWrapAlignment(); - av.setStartSeq(0); + vpRanges.setStartSeq(0); scalePanelHolder.setVisible(!wrap); hscroll.setVisible(!wrap); idwidthAdjuster.setVisible(!wrap); @@ -735,7 +741,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } // update endRes after x has (possibly) been adjusted - av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av .getCharWidth())) - 1); /* @@ -758,14 +764,14 @@ public class AlignmentPanel extends GAlignmentPanel implements @Override public void adjustmentValueChanged(AdjustmentEvent evt) { - int oldX = av.getStartRes(); - int oldY = av.getStartSeq(); + int oldX = vpRanges.getStartRes(); + int oldY = vpRanges.getStartSeq(); if (evt.getSource() == hscroll) { int x = hscroll.getValue(); - av.setStartRes(x); - av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + vpRanges.setStartRes(x); + vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av .getCharWidth())) - 1); } @@ -779,8 +785,8 @@ public class AlignmentPanel extends GAlignmentPanel implements { int rowSize = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - av.setStartRes(offy * rowSize); - av.setEndRes((offy + 1) * rowSize); + vpRanges.setStartRes(offy * rowSize); + vpRanges.setEndRes((offy + 1) * rowSize); } else { @@ -792,15 +798,16 @@ public class AlignmentPanel extends GAlignmentPanel implements @Override public void run() { - setScrollValues(av.getStartRes(), av.getStartSeq()); + setScrollValues(vpRanges.getStartRes(), + vpRanges.getStartSeq()); } }); } } else { - av.setStartSeq(offy); - av.setEndSeq(offy + vpRanges.setStartSeq(offy); + vpRanges.setEndSeq(offy + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) - 1); } @@ -811,8 +818,8 @@ public class AlignmentPanel extends GAlignmentPanel implements overviewPanel.setBoxPosition(); } - int scrollX = av.getStartRes() - oldX; - int scrollY = av.getStartSeq() - oldY; + int scrollX = vpRanges.getStartRes() - oldX; + int scrollY = vpRanges.getStartSeq() - oldY; if (av.getWrapAlignment() || !fastPaint) { @@ -822,13 +829,13 @@ public class AlignmentPanel extends GAlignmentPanel implements { // Make sure we're not trying to draw a panel // larger than the visible window - if (scrollX > av.getEndRes() - av.getStartRes()) + if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) { - scrollX = av.getEndRes() - av.getStartRes(); + scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); } - else if (scrollX < av.getStartRes() - av.getEndRes()) + else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) { - scrollX = av.getStartRes() - av.getEndRes(); + scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); } if (scrollX != 0 || scrollY != 0) @@ -928,7 +935,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } else { - setScrollValues(av.getStartRes(), av.getStartSeq()); + setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index c619dc1..84f3e6c 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -707,7 +707,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } - int column = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int column = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); if (av.hasHiddenColumns()) { @@ -904,7 +905,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } } - imgWidth = (av.getEndRes() - av.getStartRes() + 1) * av.getCharWidth(); + imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes() + 1) + * av.getCharWidth(); if (imgWidth < 1) { return; @@ -945,7 +947,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, imageFresh = true; } - drawComponent(gg, av.getStartRes(), av.getEndRes() + 1); + drawComponent(gg, av.getRanges().getStartRes(), av.getRanges() + .getEndRes() + 1); imageFresh = false; g.drawImage(image, 0, 0, this); } @@ -975,8 +978,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.getCharWidth(), 0); long mtime = System.currentTimeMillis(); - int sr = av.getStartRes(); - int er = av.getEndRes() + 1; + int sr = av.getRanges().getStartRes(); + int er = av.getRanges().getEndRes() + 1; int transX = 0; if (horizontal > 0) // scrollbar pulled right, image to the left diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 11bb14b..aad0776 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.datamodel.SequenceI; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Color; @@ -158,20 +159,22 @@ public class IdCanvas extends JPanel return; } + ViewportRanges ranges = av.getRanges(); + gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.getCharHeight()); - int ss = av.getStartSeq(); - int es = av.getEndSeq(); + int ss = ranges.getStartSeq(); + int es = ranges.getEndSeq(); int transY = 0; if (vertical > 0) // scroll down { ss = es - vertical; - if (ss < av.getStartSeq()) + if (ss < ranges.getStartSeq()) { // ie scrolling too fast, more than a page at a time - ss = av.getStartSeq(); + ss = ranges.getStartSeq(); } else { @@ -182,9 +185,9 @@ public class IdCanvas extends JPanel { es = ss - vertical; - if (es > av.getEndSeq()) + if (es > ranges.getEndSeq()) { - es = av.getEndSeq(); + es = ranges.getEndSeq(); } } @@ -240,7 +243,7 @@ public class IdCanvas extends JPanel gg.setColor(Color.white); gg.fillRect(0, 0, getWidth(), imgHeight); - drawIds(av.getStartSeq(), av.getEndSeq()); + drawIds(av.getRanges().getStartSeq(), av.getRanges().getEndSeq()); g.drawImage(image, 0, 0, this); } @@ -314,10 +317,11 @@ public class IdCanvas extends JPanel int cHeight = alheight * av.getCharHeight() + hgap + annotationHeight; - int rowSize = av.getEndRes() - av.getStartRes(); + int rowSize = av.getRanges().getEndRes() + - av.getRanges().getStartRes(); // Draw the rest of the panels - for (int ypos = hgap, row = av.getStartRes(); (ypos <= getHeight()) + for (int ypos = hgap, row = av.getRanges().getStartRes(); (ypos <= getHeight()) && (row < maxwidth); ypos += cHeight, row += rowSize) { for (int i = starty; i < alheight; i++) diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 6ae19f0..2074900 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -242,13 +242,14 @@ public class IdPanel extends JPanel implements MouseListener, return; } - if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0)) + if (mouseDragging && (e.getY() < 0) + && (av.getRanges().getStartSeq() > 0)) { scrollThread = new ScrollThread(true); } if (mouseDragging && (e.getY() >= getHeight()) - && (av.getAlignment().getHeight() > av.getEndSeq())) + && (av.getAlignment().getHeight() > av.getRanges().getEndSeq())) { scrollThread = new ScrollThread(false); } @@ -442,9 +443,10 @@ public class IdPanel extends JPanel implements MouseListener, int index = av.getAlignment().findIndex(list.get(0)); // do we need to scroll the panel? - if ((av.getStartSeq() > index) || (av.getEndSeq() < index)) + if ((av.getRanges().getStartSeq() > index) + || (av.getRanges().getEndSeq() < index)) { - alignPanel.setScrollValues(av.getStartRes(), index); + alignPanel.setScrollValues(av.getRanges().getStartRes(), index); } } @@ -486,11 +488,11 @@ public class IdPanel extends JPanel implements MouseListener, if (alignPanel.scrollUp(up)) { // scroll was ok, so add new sequence to selection - int seq = av.getStartSeq(); + int seq = av.getRanges().getStartSeq(); if (!up) { - seq = av.getEndSeq(); + seq = av.getRanges().getEndSeq(); } if (seq < lastid) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 55d29d5..e8b832d 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -87,6 +87,7 @@ import jalview.util.Platform; import jalview.util.StringUtils; import jalview.util.jarInputStreamProvider; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import jalview.viewmodel.seqfeatures.FeatureRendererSettings; import jalview.viewmodel.seqfeatures.FeaturesDisplayed; import jalview.ws.jws2.Jws2Discoverer; @@ -755,6 +756,7 @@ public class Jalview2XML List userColours = new ArrayList(); AlignViewport av = ap.av; + ViewportRanges vpRanges = av.getRanges(); JalviewModel object = new JalviewModel(); object.setVamsasModel(new jalview.schemabinding.version2.VamsasModel()); @@ -1270,8 +1272,8 @@ public class Jalview2XML view.setWidth(size.width); view.setHeight(size.height); - view.setStartRes(av.getStartRes()); - view.setStartSeq(av.getStartSeq()); + view.setStartRes(vpRanges.getStartRes()); + view.setStartSeq(vpRanges.getStartSeq()); if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme) { @@ -4448,8 +4450,8 @@ public class Jalview2XML af.viewport.setThresholdTextColour(view.getTextColThreshold()); af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view .isShowUnconserved() : false); - af.viewport.setStartRes(view.getStartRes()); - af.viewport.setStartSeq(view.getStartSeq()); + af.viewport.getRanges().setStartRes(view.getStartRes()); + af.viewport.getRanges().setStartSeq(view.getStartSeq()); af.alignPanel.updateLayout(); ColourSchemeI cs = null; // apply colourschemes diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index e751a2c..6235cbe 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -367,8 +367,8 @@ public class Jalview2XML_V1 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), view.getHeight()); - af.viewport.setStartRes(view.getStartRes()); - af.viewport.setStartSeq(view.getStartSeq()); + af.viewport.getRanges().setStartRes(view.getStartRes()); + af.viewport.getRanges().setStartSeq(view.getStartSeq()); af.viewport.setShowAnnotation(view.getShowAnnotation()); af.viewport.setAbovePIDThreshold(view.getPidSelected()); af.viewport.setColourText(view.getShowColourText()); diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 8961f21..de21be6 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -101,7 +101,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, @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()) @@ -282,7 +282,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { mouseDragging = false; - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); if (av.hasHiddenColumns()) { @@ -337,7 +338,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, mouseDragging = true; ColumnSelection cs = av.getColumnSelection(); - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); res = Math.max(0, res); res = cs.adjustForHiddenColumns(res); res = Math.min(res, av.getAlignment().getWidth() - 1); @@ -389,7 +391,8 @@ public class ScalePanel extends JPanel 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); @@ -419,7 +422,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, @Override public void paintComponent(Graphics g) { - drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight()); + drawScale(g, av.getRanges().getStartRes(), av.getRanges().getEndRes(), + getWidth(), getHeight()); } // scalewidth will normally be screenwidth, diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 226e0df..0593e24 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -26,6 +26,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; +import jalview.viewmodel.ViewportRanges; import java.awt.BasicStroke; import java.awt.BorderLayout; @@ -279,10 +280,11 @@ public class SeqCanvas extends JComponent gg.copyArea(horizontal * charWidth, vertical * charHeight, imgWidth, imgHeight, -horizontal * charWidth, -vertical * charHeight); - int sr = av.getStartRes(); - int er = av.getEndRes(); - int ss = av.getStartSeq(); - int es = av.getEndSeq(); + ViewportRanges ranges = av.getRanges(); + int sr = ranges.getStartRes(); + int er = ranges.getEndRes(); + int ss = ranges.getStartSeq(); + int es = ranges.getEndSeq(); int transX = 0; int transY = 0; @@ -300,9 +302,9 @@ public class SeqCanvas extends JComponent { ss = es - vertical; - if (ss < av.getStartSeq()) + if (ss < ranges.getStartSeq()) { // ie scrolling too fast, more than a page at a time - ss = av.getStartSeq(); + ss = ranges.getStartSeq(); } else { @@ -313,9 +315,9 @@ public class SeqCanvas extends JComponent { es = ss - vertical; - if (es > av.getEndSeq()) + if (es > ranges.getEndSeq()) { - es = av.getEndSeq(); + es = ranges.getEndSeq(); } } @@ -395,14 +397,15 @@ public class SeqCanvas extends JComponent gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); + ViewportRanges ranges = av.getRanges(); if (av.getWrapAlignment()) { - drawWrappedPanel(gg, getWidth(), getHeight(), av.getStartRes()); + drawWrappedPanel(gg, getWidth(), getHeight(), ranges.getStartRes()); } else { - drawPanel(gg, av.getStartRes(), av.getEndRes(), av.getStartSeq(), - av.getEndSeq(), 0); + drawPanel(gg, ranges.getStartRes(), ranges.getEndRes(), + ranges.getStartSeq(), ranges.getEndSeq(), 0); } g.drawImage(lcimg, 0, 0, this); @@ -504,7 +507,7 @@ public class SeqCanvas extends JComponent av.setWrappedWidth(cWidth); - av.setEndRes(av.getStartRes() + cWidth); + av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth); int endx; int ypos = hgap; diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 16415cc..db7aa36 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -209,7 +209,7 @@ public class SeqPanel extends JPanel implements MouseListener, } wrappedBlock = y / cHeight; - wrappedBlock += av.getStartRes() / cwidth; + wrappedBlock += av.getRanges().getStartRes() / cwidth; res = wrappedBlock * cwidth + x / av.getCharWidth(); @@ -222,11 +222,11 @@ public class SeqPanel extends JPanel implements MouseListener, // right-hand gutter x = seqCanvas.getX() + seqCanvas.getWidth(); } - res = (x / av.getCharWidth()) + av.getStartRes(); - if (res > av.getEndRes()) + res = (x / av.getCharWidth()) + av.getRanges().getStartRes(); + if (res > av.getRanges().getEndRes()) { // moused off right - res = av.getEndRes(); + res = av.getRanges().getEndRes(); } } @@ -262,7 +262,9 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(), av + seq = Math.min((y / av.getCharHeight()) + + av.getRanges().getStartSeq(), + av .getAlignment().getHeight() - 1); } @@ -385,18 +387,18 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - while (seqCanvas.cursorY < av.getStartSeq()) + while (seqCanvas.cursorY < av.getRanges().getStartSeq()) { ap.scrollUp(true); } - while (seqCanvas.cursorY + 1 > av.getEndSeq()) + while (seqCanvas.cursorY + 1 > av.getRanges().getEndSeq()) { ap.scrollUp(false); } if (!av.getWrapAlignment()) { while (seqCanvas.cursorX < av.getColumnSelection() - .adjustForHiddenColumns(av.getStartRes())) + .adjustForHiddenColumns(av.getRanges().getStartRes())) { if (!ap.scrollRight(false)) { @@ -404,7 +406,7 @@ public class SeqPanel extends JPanel implements MouseListener, } } while (seqCanvas.cursorX > av.getColumnSelection() - .adjustForHiddenColumns(av.getEndRes())) + .adjustForHiddenColumns(av.getRanges().getEndRes())) { if (!ap.scrollRight(true)) { @@ -1772,9 +1774,9 @@ public class SeqPanel extends JPanel implements MouseListener, changeStartRes = true; } - if (res < av.getStartRes()) + if (res < av.getRanges().getStartRes()) { - res = av.getStartRes(); + res = av.getRanges().getStartRes(); } if (changeEndRes) @@ -1908,13 +1910,15 @@ public class SeqPanel extends JPanel implements MouseListener, { if (evt != null) { - if (mouseDragging && (evt.getY() < 0) && (av.getStartSeq() > 0)) + if (mouseDragging && (evt.getY() < 0) + && (av.getRanges().getStartSeq() > 0)) { running = ap.scrollUp(true); } if (mouseDragging && (evt.getY() >= getHeight()) - && (av.getAlignment().getHeight() > av.getEndSeq())) + && (av.getAlignment().getHeight() > av.getRanges() + .getEndSeq())) { running = ap.scrollUp(false); } diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 6f84a2e..3a27c7d 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -307,7 +307,7 @@ public class AnnotationRenderer public void updateFromAlignViewport(AlignViewportI av) { charWidth = av.getCharWidth(); - endRes = av.getEndRes(); + endRes = av.getRanges().getEndRes(); charHeight = av.getCharHeight(); hasHiddenColumns = av.hasHiddenColumns(); validCharWidth = av.isValidCharWidth(); diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 1f91935..5f84a5d 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1287,14 +1287,6 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private boolean followHighlight = true; - /*private int startRes; - - private int endRes; - - private int startSeq; - - private int endSeq;*/ - /** * Property change listener for changes in alignment * @@ -2652,50 +2644,6 @@ public abstract class AlignmentViewport implements AlignViewportI, return ranges; } - @Override - public int getStartRes() - { - return ranges.getStartRes(); - } - - @Override - public int getEndRes() - { - return ranges.getEndRes(); - } - - @Override - public int getStartSeq() - { - return ranges.getStartSeq(); - } - - public void setStartRes(int res) - { - ranges.setStartRes(res); - } - - public void setStartSeq(int seq) - { - ranges.setStartSeq(seq); - } - - public void setEndRes(int res) - { - ranges.setEndRes(res); - } - - public void setEndSeq(int seq) - { - ranges.setEndSeq(seq); - } - - @Override - public int getEndSeq() - { - return ranges.getEndSeq(); - } - /** * Helper method to populate the SearchResults with the location in the * complementary alignment to scroll to, in order to match this one. @@ -2733,7 +2681,8 @@ public abstract class AlignmentViewport implements AlignViewportI, * locate 'middle' column (true middle if an odd number visible, left of * middle if an even number visible) */ - int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2; + int middleColumn = ranges.getStartRes() + + (ranges.getEndRes() - ranges.getStartRes()) / 2; final HiddenSequences hiddenSequences = getAlignment() .getHiddenSequences(); @@ -2743,7 +2692,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ int lastSeq = alignment.getHeight() - 1; List seqMappings = null; - for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) + for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++) { sequence = getAlignment().getSequenceAt(seqNo); if (hiddenSequences != null && hiddenSequences.isHidden(sequence)) diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 5c8cdb6..c91d2d9 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -25,7 +25,9 @@ import jalview.datamodel.AlignmentI; /** * Embryonic class which: Supplies and updates viewport properties relating to * position such as: start and end residues and sequences; ideally will serve - * hidden columns/rows too + * hidden columns/rows too. Intention also to support calculations for + * positioning, scrolling etc. such as finding the middle of the viewport, + * checking for scrolls off screen */ public class ViewportRanges extends ViewportProperties { diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index 676a4b6..4d3dd2f 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -617,8 +617,8 @@ public class DasSequenceFeatureFetcher } af.getFeatureRenderer().featuresAdded(); - int start = af.getViewport().getStartSeq(); - int end = af.getViewport().getEndSeq(); + int start = af.getViewport().getRanges().getStartSeq(); + int end = af.getViewport().getRanges().getEndSeq(); int index; for (index = start; index < end; index++) { diff --git a/test/jalview/gui/AlignmentPanelTest.java b/test/jalview/gui/AlignmentPanelTest.java index f3b6876..c580a88 100644 --- a/test/jalview/gui/AlignmentPanelTest.java +++ b/test/jalview/gui/AlignmentPanelTest.java @@ -28,6 +28,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import jalview.viewmodel.ViewportRanges; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -164,27 +165,29 @@ public class AlignmentPanelTest @Test(groups = "Functional") public void TestSetScrollValues() { - int oldres = af.getViewport().getEndRes(); + ViewportRanges ranges = af.getViewport().getRanges(); + + int oldres = ranges.getEndRes(); af.alignPanel.setScrollValues(-1, 5); // setting -ve x value does not change residue - assertEquals(af.getViewport().getEndRes(), oldres); + assertEquals(ranges.getEndRes(), oldres); af.alignPanel.setScrollValues(0, 5); // setting 0 as x value does not change residue - assertEquals(af.getViewport().getEndRes(), oldres); + assertEquals(ranges.getEndRes(), oldres); af.alignPanel.setScrollValues(5, 5); // setting x value to 5 extends endRes by 5 residues - assertEquals(af.getViewport().getEndRes(), oldres + 5); + assertEquals(ranges.getEndRes(), oldres + 5); // scroll to position after hidden columns sets endres to oldres (width) + // position int scrollpos = 60; af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(af.getViewport().getEndRes(), oldres + scrollpos); + assertEquals(ranges.getEndRes(), oldres + scrollpos); // scroll to position within hidden columns, still sets endres to oldres + // position @@ -194,14 +197,14 @@ public class AlignmentPanelTest af.getViewport().showAllHiddenColumns(); af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(af.getViewport().getEndRes(), oldres + scrollpos); + assertEquals(ranges.getEndRes(), oldres + scrollpos); // scroll to position within distance of the end of the alignment // endRes should be set to width of alignment - 1 scrollpos = 130; af.getViewport().showAllHiddenColumns(); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(af.getViewport().getEndRes(), af.getViewport() + assertEquals(ranges.getEndRes(), af.getViewport() .getAlignment().getWidth() - 1); // now hide some columns, and scroll to position within @@ -210,7 +213,7 @@ public class AlignmentPanelTest // columns af.getViewport().hideColumns(30, 50); af.alignPanel.setScrollValues(scrollpos, 5); - assertEquals(af.getViewport().getEndRes(), af.getViewport() + assertEquals(ranges.getEndRes(), af.getViewport() .getAlignment().getWidth() - 1 - 21); // 21 is the number of hidden // columns }