From: kiramt Date: Tue, 2 May 2017 07:57:38 +0000 (+0100) Subject: JAL-2491 first addition of new event X-Git-Tag: Release_2_10_2~3^2~64^2~28 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6cd58958becb397f90c6609f5f525de04fc98a2b;p=jalview.git JAL-2491 first addition of new event --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 8ade5d6..4863659 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.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; @@ -66,7 +67,8 @@ import javax.swing.SwingUtilities; * @version $Revision: 1.161 $ */ public class AlignmentPanel extends GAlignmentPanel implements - AdjustmentListener, Printable, AlignmentViewPanel + AdjustmentListener, Printable, AlignmentViewPanel, + ViewportListenerI { public AlignViewport av; @@ -154,6 +156,8 @@ public class AlignmentPanel extends GAlignmentPanel implements } }; av.addPropertyChangeListener(propertyChangeListener); + + av.getRanges().addPropertyChangeListener(this); fontChanged(); adjustAnnotationHeight(); updateLayout(); @@ -473,7 +477,7 @@ public class AlignmentPanel extends GAlignmentPanel implements || res >= (vpRanges.getStartRes() + cwidth)) { vscroll.setValue((res / cwidth)); - vpRanges.setStartRes(vscroll.getValue() * cwidth); + // vpRanges.setStartRes(vscroll.getValue() * cwidth); } } @@ -749,9 +753,9 @@ public class AlignmentPanel extends GAlignmentPanel implements * 'do not scroll complement' flag; ensure it is the same for both * operations */ - boolean flag = isDontScrollComplement(); + // boolean flag = isDontScrollComplement(); hscroll.setValues(x, hextent, 0, width); - setDontScrollComplement(flag); + // setDontScrollComplement(flag); vscroll.setValues(y, vextent, 0, height); } @@ -770,8 +774,16 @@ public class AlignmentPanel extends GAlignmentPanel implements if (evt.getSource() == hscroll) { int x = hscroll.getValue(); - vpRanges.setStartRes(x); - vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + if (x == oldX) + { + return; + } + // vpRanges.setStartRes(x); + // vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + // .getCharWidth())) - 1); + vpRanges.setStartEndRes( + x, + (x + (getSeqPanel().seqCanvas.getWidth() / av .getCharWidth())) - 1); } @@ -781,12 +793,18 @@ public class AlignmentPanel extends GAlignmentPanel implements if (av.getWrapAlignment()) { + if (offy == oldX) + { + return; + } if (offy > -1) { int rowSize = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - vpRanges.setStartRes(offy * rowSize); - vpRanges.setEndRes((offy + 1) * rowSize); + vpRanges.setStartEndRes(offy * rowSize, (offy + 1) * rowSize); + // vpRanges.setStartRes(offy * rowSize); + // vpRanges.setEndRes((offy + 1) * rowSize); + } else { @@ -806,62 +824,71 @@ public class AlignmentPanel extends GAlignmentPanel implements } else { - vpRanges.setStartSeq(offy); - vpRanges.setEndSeq(offy - + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) - - 1); + if (offy == oldY) + { + return; + } + // vpRanges.setStartSeq(offy); + // vpRanges.setEndSeq(offy + // + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) + // - 1); + vpRanges.setStartEndSeq( + offy, + offy + + (getSeqPanel().seqCanvas.getHeight() / av + .getCharHeight()) - 1); } } - if (overviewPanel != null) + /*if (overviewPanel != null) { overviewPanel.setBoxPosition(); - } + }*/ - int scrollX = vpRanges.getStartRes() - oldX; - int scrollY = vpRanges.getStartSeq() - oldY; + // int scrollX = vpRanges.getStartRes() - oldX; + // int scrollY = vpRanges.getStartSeq() - oldY; if (av.getWrapAlignment() || !fastPaint) { 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(); - } - - if (scrollX != 0 || scrollY != 0) - { - getIdPanel().getIdCanvas().fastPaint(scrollY); - getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY); - getScalePanel().repaint(); - - if (av.isShowAnnotation() && scrollX != 0) - { - getAnnotationPanel().fastPaint(scrollX); - } - } - } - /* - * If there is one, scroll the (Protein/cDNA) complementary alignment to - * match, unless we are ourselves doing that. - */ - if (isDontScrollComplement()) - { - setDontScrollComplement(false); - } - else - { - av.scrollComplementaryAlignment(); - } + /* 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(); + } + + if (scrollX != 0 || scrollY != 0) + { + getIdPanel().getIdCanvas().fastPaint(scrollY); + getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY); + getScalePanel().repaint(); + + if (av.isShowAnnotation() && scrollX != 0) + { + getAnnotationPanel().fastPaint(scrollX); + } + } + } + /* + * If there is one, scroll the (Protein/cDNA) complementary alignment to + * match, unless we are ourselves doing that. + */ + /* if (isDontScrollComplement()) + { + setDontScrollComplement(false); + } + else + { + av.scrollComplementaryAlignment(); + }*/ } /** @@ -1906,4 +1933,13 @@ public class AlignmentPanel extends GAlignmentPanel implements repaint(); } } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + int x = vpRanges.getStartRes(); + int y = vpRanges.getStartSeq(); + setScrollValues(x, y); + + } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 84f3e6c..8dc168a 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -29,6 +29,7 @@ import jalview.renderer.AwtRenderPanelI; import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MessageManager; +import jalview.viewmodel.ViewportListenerI; import java.awt.AlphaComposite; import java.awt.Color; @@ -49,6 +50,7 @@ import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -69,7 +71,7 @@ import javax.swing.ToolTipManager; */ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, MouseListener, MouseWheelListener, MouseMotionListener, - ActionListener, AdjustmentListener, Scrollable + ActionListener, AdjustmentListener, Scrollable, ViewportListenerI { String HELIX = MessageManager.getString("label.helix"); @@ -155,6 +157,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, // and then set our own listener to consume all mousewheel events ap.annotationScroller.addMouseWheelListener(this); renderer = new AnnotationRenderer(); + + av.getRanges().addPropertyChangeListener(this); } public AnnotationPanel(AlignViewport av) @@ -1156,4 +1160,15 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, renderer.dispose(); } } + + @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/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index aad0776..fe58c67 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.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; @@ -31,6 +32,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JPanel; @@ -41,7 +43,7 @@ import javax.swing.JPanel; * @author $author$ * @version $Revision$ */ -public class IdCanvas extends JPanel +public class IdCanvas extends JPanel implements ViewportListenerI { protected AlignViewport av; @@ -80,6 +82,7 @@ public class IdCanvas extends JPanel setLayout(new BorderLayout()); this.av = av; PaintRefresher.Register(this, av.getSequenceSetId()); + av.getRanges().addPropertyChangeListener(this); } /** @@ -515,4 +518,15 @@ public class IdCanvas extends JPanel { this.idfont = idfont; } + + @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/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index c19f005..970d5e6 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -4463,7 +4463,7 @@ public class Jalview2XML af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view .isShowUnconserved() : false); af.viewport.getRanges().setStartRes(view.getStartRes()); - af.viewport.getRanges().setStartSeq(view.getStartSeq()); + // startSeq set in af.alignPanel.updateLayout below 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 6235cbe..10eee30 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -368,7 +368,7 @@ public class Jalview2XML_V1 af.setBounds(view.getXpos(), view.getYpos(), view.getWidth(), view.getHeight()); af.viewport.getRanges().setStartRes(view.getStartRes()); - af.viewport.getRanges().setStartSeq(view.getStartSeq()); + // startSeq set in af.alignPanel.updateLayout below af.viewport.setShowAnnotation(view.getShowAnnotation()); af.viewport.setAbovePIDThreshold(view.getPidSelected()); af.viewport.setColourText(view.getShowColourText()); diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index c530fdc..3bd7388 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -24,6 +24,7 @@ import jalview.datamodel.SequenceI; import jalview.renderer.AnnotationRenderer; import jalview.renderer.seqfeatures.FeatureColourFinder; import jalview.viewmodel.OverviewDimensions; +import jalview.viewmodel.ViewportListenerI; import java.awt.Color; import java.awt.Dimension; @@ -34,6 +35,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import javax.swing.JPanel; @@ -44,7 +46,8 @@ import javax.swing.JPanel; * @author $author$ * @version $Revision$ */ -public class OverviewPanel extends JPanel implements Runnable +public class OverviewPanel extends JPanel implements Runnable, + ViewportListenerI { private static final Color TRANS_GREY = new Color(100, 100, 100, 25); @@ -94,6 +97,8 @@ public class OverviewPanel extends JPanel implements Runnable (av.isShowAnnotation() && av .getAlignmentConservationAnnotation() != null)); + av.getRanges().addPropertyChangeListener(this); + addComponentListener(new ComponentAdapter() { @Override @@ -357,4 +362,10 @@ public class OverviewPanel extends JPanel implements Runnable g.setColor(Color.red); od.drawBox(g); } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + setBoxPosition(); + } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index de21be6..5b8002f 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -27,6 +27,7 @@ import jalview.renderer.ScaleRenderer; import jalview.renderer.ScaleRenderer.ScaleMark; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.viewmodel.ViewportListenerI; import java.awt.Color; import java.awt.FontMetrics; @@ -38,6 +39,7 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JMenuItem; @@ -51,7 +53,7 @@ import javax.swing.ToolTipManager; * supports a range of mouse operations to select, hide or reveal columns. */ public class ScalePanel extends JPanel implements MouseMotionListener, - MouseListener + MouseListener, ViewportListenerI { protected int offy = 4; @@ -90,6 +92,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, addMouseListener(this); addMouseMotionListener(this); + + av.getRanges().addPropertyChangeListener(this); } /** @@ -542,4 +546,11 @@ public class ScalePanel extends JPanel 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/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 64e5fdc..7b8dd92 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.ViewportListenerI; import jalview.viewmodel.ViewportRanges; import java.awt.BasicStroke; @@ -37,6 +38,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeEvent; import java.util.List; import javax.swing.JComponent; @@ -47,7 +49,7 @@ import javax.swing.JComponent; * @author $author$ * @version $Revision$ */ -public class SeqCanvas extends JComponent +public class SeqCanvas extends JComponent implements ViewportListenerI { final FeatureRenderer fr; @@ -88,6 +90,8 @@ public class SeqCanvas extends JComponent setLayout(new BorderLayout()); PaintRefresher.Register(this, av.getSequenceSetId()); setBackground(Color.white); + + av.getRanges().addPropertyChangeListener(this); } public SequenceRenderer getSequenceRenderer() @@ -975,4 +979,33 @@ public class SeqCanvas extends JComponent repaint(); } + + @Override + public void propertyChange(PropertyChangeEvent evt) + { + + 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/viewmodel/ViewportListenerI.java b/src/jalview/viewmodel/ViewportListenerI.java new file mode 100644 index 0000000..555089e --- /dev/null +++ b/src/jalview/viewmodel/ViewportListenerI.java @@ -0,0 +1,8 @@ +package jalview.viewmodel; + +import java.beans.PropertyChangeListener; + +public interface ViewportListenerI extends PropertyChangeListener +{ + +} diff --git a/src/jalview/viewmodel/ViewportProperties.java b/src/jalview/viewmodel/ViewportProperties.java index 246806e..a78a1c0 100644 --- a/src/jalview/viewmodel/ViewportProperties.java +++ b/src/jalview/viewmodel/ViewportProperties.java @@ -20,7 +20,21 @@ */ package jalview.viewmodel; +import java.beans.PropertyChangeSupport; + public abstract class ViewportProperties { + protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + + public void addPropertyChangeListener(ViewportListenerI listener) + { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(ViewportListenerI listener) + { + changeSupport.removePropertyChangeListener(listener); + } } diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index c91d2d9..bbdaa9e 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -79,7 +79,7 @@ public class ViewportRanges extends ViewportProperties } /** - * Set first residue visible in the viewport + * Set first residue visible in the viewport, and retain the current width. * * @param res * residue position @@ -94,7 +94,18 @@ public class ViewportRanges extends ViewportProperties { res = 0; } + + int oldres = this.startRes; this.startRes = res; + // changeSupport.firePropertyChange("startres", oldres, res); + } + + public void setStartEndRes(int startres, int endres) + { + int oldres = this.startRes; + setStartRes(startres); + setEndRes(endres); + changeSupport.firePropertyChange("startres", oldres, startres); } /** @@ -113,7 +124,10 @@ public class ViewportRanges extends ViewportProperties { res = 0; } + int oldres = this.endRes; this.endRes = res; + + // changeSupport.firePropertyChange("endres", oldres, res); } /** @@ -132,7 +146,18 @@ public class ViewportRanges extends ViewportProperties { seq = 0; } + + int oldseq = this.startSeq; this.startSeq = seq; + // changeSupport.firePropertyChange("startseq", oldseq, seq); + } + + public void setStartEndSeq(int startseq, int endseq) + { + int oldseq = this.startSeq; + setStartSeq(startseq); + setEndSeq(endseq); + changeSupport.firePropertyChange("startseq", oldseq, startseq); } /** @@ -151,7 +176,10 @@ public class ViewportRanges extends ViewportProperties { seq = 0; } + int oldseq = this.endSeq; this.endSeq = seq; + + // changeSupport.firePropertyChange("endseq", oldseq, seq); } /**