From 2267fd4e6dd5e716ba5d89aef9c72c0bd21c6c0b Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 11 May 2017 17:23:37 +0100 Subject: [PATCH] JAL-2491 First port to applet --- src/jalview/appletgui/AlignViewport.java | 3 ++- src/jalview/appletgui/AnnotationPanel.java | 16 +++++++++++- src/jalview/appletgui/IdCanvas.java | 16 +++++++++++- src/jalview/appletgui/IdPanel.java | 4 +-- src/jalview/appletgui/OverviewPanel.java | 15 +++++++++-- src/jalview/appletgui/ScalePanel.java | 12 ++++++++- src/jalview/appletgui/SeqCanvas.java | 39 ++++++++++++++++++++++++++-- src/jalview/appletgui/SeqPanel.java | 24 ++++++++++------- src/jalview/gui/SeqCanvas.java | 4 --- 9 files changed, 110 insertions(+), 23 deletions(-) diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 065c503..13332d3 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -438,8 +438,9 @@ public class AlignViewport extends AlignmentViewport implements int seqOffset = findComplementScrollTarget(sr); if (!sr.isEmpty()) { - complementPanel.setFollowingComplementScroll(true); + complementPanel.setFollowingComplementScroll(false); complementPanel.scrollToCentre(sr, seqOffset); + complementPanel.setFollowingComplementScroll(true); } } diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 0ec7adf..cf7f51e 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -29,6 +29,7 @@ import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.viewmodel.ViewportListenerI; import java.awt.Color; import java.awt.Dimension; @@ -47,10 +48,11 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; public class AnnotationPanel extends Panel implements AwtRenderPanelI, AdjustmentListener, ActionListener, MouseListener, - MouseMotionListener + MouseMotionListener, ViewportListenerI { AlignViewport av; @@ -122,6 +124,7 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, { this.av = av; renderer = new AnnotationRenderer(); + av.getRanges().addPropertyChangeListener(this); } @Override @@ -749,4 +752,15 @@ public class AnnotationPanel extends Panel implements AwtRenderPanelI, return null; } } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + // Respond to viewport range changes (e.g. alignment panel was scrolled) + if (evt.getPropertyName().equals("startres") + || evt.getPropertyName().equals("endres")) + { + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); + } + } } diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index abcbd70..cad5de5 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.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.Color; @@ -28,9 +29,10 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.Panel; +import java.beans.PropertyChangeEvent; import java.util.List; -public class IdCanvas extends Panel +public class IdCanvas extends Panel implements ViewportListenerI { protected AlignViewport av; @@ -55,6 +57,7 @@ public class IdCanvas extends Panel setLayout(null); this.av = av; PaintRefresher.Register(this, av.getSequenceSetId()); + av.getRanges().addPropertyChangeListener(this); } public void drawIdString(Graphics gg, boolean hiddenRows, SequenceI s, @@ -393,4 +396,15 @@ public class IdCanvas extends Panel } return false; } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + // Respond to viewport range changes (e.g. alignment panel was scrolled) + if (evt.getPropertyName().equals("startseq") + || evt.getPropertyName().equals("endseq")) + { + fastPaint((int) evt.getNewValue() - (int) evt.getOldValue()); + } + } } diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index e47c50a..7c67edd 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -401,7 +401,7 @@ public class IdPanel extends Panel implements MouseListener, if (av.getRanges().getStartSeq() > index || av.getRanges().getEndSeq() < index) { - alignPanel.setScrollValues(av.getRanges().getStartRes(), index); + av.getRanges().setStartSeq(index); } } @@ -429,7 +429,7 @@ public class IdPanel extends Panel implements MouseListener, running = true; while (running) { - if (alignPanel.scrollUp(up)) + if (av.getRanges().scrollUp(up)) { // scroll was ok, so add new sequence to selection int seq = av.getRanges().getStartSeq(); diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 3ef2936..786e9c2 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -23,6 +23,7 @@ package jalview.appletgui; import jalview.datamodel.SequenceI; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.viewmodel.OverviewDimensions; +import jalview.viewmodel.ViewportListenerI; import java.awt.Color; import java.awt.Dimension; @@ -35,9 +36,10 @@ import java.awt.event.ComponentEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; public class OverviewPanel extends Panel implements Runnable, - MouseMotionListener, MouseListener + MouseMotionListener, MouseListener, ViewportListenerI { private OverviewDimensions od; @@ -81,6 +83,9 @@ public class OverviewPanel extends Panel implements Runnable, (av.isShowAnnotation() && av.getSequenceConsensusHash() != null)); setSize(new Dimension(od.getWidth(), od.getHeight())); + + av.getRanges().addPropertyChangeListener(this); + addComponentListener(new ComponentAdapter() { @@ -332,7 +337,7 @@ public class OverviewPanel extends Panel implements Runnable, * changed * */ - public void setBoxPosition() + private void setBoxPosition() { od.setBoxPosition(av.getAlignment() .getHiddenSequences(), av.getColumnSelection(), av.getRanges()); @@ -358,4 +363,10 @@ public class OverviewPanel extends Panel implements Runnable, } } + @Override + public void propertyChange(PropertyChangeEvent evt) + { + setBoxPosition(); + } + } diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 15d82a5..a1e4f3d 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -25,6 +25,7 @@ import jalview.datamodel.SequenceGroup; import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; +import jalview.viewmodel.ViewportListenerI; import java.awt.Color; import java.awt.FontMetrics; @@ -38,10 +39,11 @@ 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.List; public class ScalePanel extends Panel implements MouseMotionListener, - MouseListener + MouseListener, ViewportListenerI { protected int offy = 4; @@ -71,6 +73,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, addMouseListener(this); addMouseMotionListener(this); + av.getRanges().addPropertyChangeListener(this); } @Override @@ -462,4 +465,11 @@ public class ScalePanel extends Panel implements MouseMotionListener, } } + @Override + public void propertyChange(PropertyChangeEvent evt) + { + // Respond to viewport change events (e.g. alignment panel was scrolled) + repaint(); + } + } diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 89df11f..b025f32 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.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.Color; @@ -34,8 +35,9 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Image; import java.awt.Panel; +import java.beans.PropertyChangeEvent; -public class SeqCanvas extends Panel +public class SeqCanvas extends Panel implements ViewportListenerI { FeatureRenderer fr; @@ -64,6 +66,8 @@ public class SeqCanvas extends Panel sr = new SequenceRenderer(av); PaintRefresher.Register(this, av.getSequenceSetId()); updateViewport(); + + av.getRanges().addPropertyChangeListener(this); } int avcharHeight = 0, avcharWidth = 0; @@ -431,7 +435,7 @@ public class SeqCanvas extends Panel av.setWrappedWidth(cWidth); - av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth); + av.getRanges().setEndRes(av.getRanges().getStartRes() + cWidth - 1); int endx; int ypos = hgap; @@ -858,4 +862,35 @@ public class SeqCanvas extends Panel repaint(); } + @Override + public void propertyChange(PropertyChangeEvent evt) + { + if (!av.getWrapAlignment()) + { + if (evt.getPropertyName().equals("startres") + || evt.getPropertyName().equals("endres")) + { + // Make sure we're not trying to draw a panel + // larger than the visible window + ViewportRanges vpRanges = av.getRanges(); + int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) + { + scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); + } + else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) + { + scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); + } + fastPaint(scrollX, 0); + } + else if (evt.getPropertyName() == "startseq" + || evt.getPropertyName() == "endseq") + { + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); + } + } + + } + } diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 0e12703..347cceb 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -223,24 +223,24 @@ public class SeqPanel extends Panel implements MouseMotionListener, endEditing(); if (av.getWrapAlignment()) { - ap.scrollToWrappedVisible(seqCanvas.cursorX); + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); } else { ViewportRanges ranges = av.getRanges(); while (seqCanvas.cursorY < ranges.getStartSeq()) { - ap.scrollUp(true); + ranges.scrollUp(true); } while (seqCanvas.cursorY + 1 > ranges.getEndSeq()) { - ap.scrollUp(false); + ranges.scrollUp(false); } while (seqCanvas.cursorX < av.getColumnSelection() .adjustForHiddenColumns(ranges.getStartRes())) { - if (!ap.scrollRight(false)) + if (!ranges.scrollRight(false)) { break; } @@ -248,7 +248,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, while (seqCanvas.cursorX > av.getColumnSelection() .adjustForHiddenColumns(ranges.getEndRes())) { - if (!ap.scrollRight(true)) + if (!ranges.scrollRight(true)) { break; } @@ -740,10 +740,16 @@ public class SeqPanel extends Panel implements MouseMotionListener, { if (av.isFollowHighlight()) { + // don't allow highlight of protein/cDNA to also scroll a complementary + // panel,as this sets up a feedback loop (scrolling panel 1 causes moused + // over residue to change abruptly, causing highlighted residue in panel 2 + // to change, causing a scroll in panel 1 etc) + ap.setFollowingComplementScroll(false); if (ap.scrollToPosition(results, true)) { ap.alignFrame.repaint(); } + ap.setFollowingComplementScroll(true); } setStatusMessage(results); seqCanvas.highlightSearchResults(results); @@ -1751,24 +1757,24 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (mouseDragging && evt.getY() < 0 && av.getRanges().getStartSeq() > 0) { - running = ap.scrollUp(true); + running = av.getRanges().scrollUp(true); } if (mouseDragging && evt.getY() >= getSize().height && av.getAlignment().getHeight() > av.getRanges() .getEndSeq()) { - running = ap.scrollUp(false); + running = av.getRanges().scrollUp(false); } if (mouseDragging && evt.getX() < 0) { - running = ap.scrollRight(false); + running = av.getRanges().scrollRight(false); } else if (mouseDragging && evt.getX() >= getSize().width) { - running = ap.scrollRight(true); + running = av.getRanges().scrollRight(true); } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index abd473d..cd69bdc 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -984,10 +984,6 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { if (av.getWrapAlignment()) { - - } - else - { if (evt.getPropertyName().equals("startres") || evt.getPropertyName().equals("endres")) { -- 1.7.10.2