Class PairwiseSequencePanel

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.biojava.bio.gui.sequence.PairwiseSequencePanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, SwingConstants, PairwiseRenderContext, SequenceRenderContext, Changeable

A PairwiseSequencePanel is a panel that displays a pair of sequences; one sequence (the primary) may be either left-to-right (HORIZONTAL) or from top-to-bottom (VERTICAL). The other sequence (secondary) will then occupy the remaining direction. It has an associated scale which is the number of pixels per symbol and applies to both sequences. The leading and trailing borders apply to the primary sequence only.

The primary purpose of this component is to provide a means for representing graphically comparisons between two sequences. This could be anything from traditional dotplots (or variants created with lines) to a more complex layered plot involving superimposed renderers.

Each sequence has a translation which is the number of Symbols to skip before rendering starts. In order to produce a scrolling effect, the setSymbolTranslation or setSecondarySymbolTranslation method may be hooked up to an Adjustable such as JScrollBar or to an event listener.

The exact number of Symbols rendered in each sequence depends on the dimensions of the panel and the scale. Resizing the panel will cause the number of Symbols rendered to change accordingly.

The panel will fill its background to the Color defined by the setBackground() method provided that it has been defined as opaque using setOpaque().

The change event handling code is based on the original panel and other BioJava components by Matthew and Thomas.

Since:
1.2
Author:
Keith James, Matthew Pocock
See Also:
  • Field Details

    • RENDERER

      public static final ChangeType RENDERER
      Constant RENDERER is a ChangeType which indicates a change to the renderer, requiring a layout update.
    • TRANSLATION

      public static final ChangeType TRANSLATION
      Constant TRANSLATION is a ChangeType which indicates a change to the translation, requiring a paint update.
  • Constructor Details

    • PairwiseSequencePanel

      Creates a new PairwiseSequencePanel with the default settings (primary sequence direction HORIZONTAL, scale 10.0 pixels per symbol, symbol translation 0, secondary symbol translation 0, leading border 0.0, trailing border 0.0, 12 point sanserif font).
  • Method Details

    • getSequence

      getSequence returns the entire Sequence currently being rendered.
      Returns:
      a Sequence.
    • setSequence

      public void setSequence(Sequence sequence)
      setSequence sets the Sequence to be rendered.
      Parameters:
      sequence - a Sequence.
    • getSecondarySequence

      getSecondarySequence returns the entire secondary Sequence currently being rendered.
      Returns:
      a Sequence.
    • setSecondarySequence

      public void setSecondarySequence(Sequence sequence)
      setSecondarySequence sets the secondary Sequence to be rendered.
      Parameters:
      sequence - a Sequence.
    • getSymbols

      getSymbols returns all of the Symbols belonging to the currently rendered Sequence.
      Specified by:
      getSymbols in interface SequenceRenderContext
      Returns:
      a SymbolList.
    • getSecondarySymbols

      getSecondarySymbols returns all of the Symbols belonging to the currently rendered secondary Sequence.
      Specified by:
      getSecondarySymbols in interface PairwiseRenderContext
      Returns:
      a SymbolList.
    • getFeatures

      getFeatures returns all of the Features belonging to the currently rendered Sequence.
      Specified by:
      getFeatures in interface SequenceRenderContext
      Returns:
      a FeatureHolder.
    • getSecondaryFeatures

      getSecondaryFeatures returns all of the Features belonging to the currently rendered secondary Sequence.
      Specified by:
      getSecondaryFeatures in interface PairwiseRenderContext
      Returns:
      a FeatureHolder.
    • getRange

      getRange returns a RangeLocation representing the region of the sequence currently being rendered. This is calculated from the size of the PairwiseSequencePanel, the current rendering translation and the current scale. The value will therefore change when the PairwiseSequencePanel is resized or "scrolled" by changing the translation.
      Specified by:
      getRange in interface SequenceRenderContext
      Returns:
      a RangeLocation.
    • getSecondaryRange

      getSecondaryRange returns a RangeLocation representing the region of the secondary sequence currently being rendered. This is calculated from the size of the PairwiseSequencePanel, the current rendering translation and the current scale. The value will therefore change when the PairwiseSequencePanel is resized or "scrolled" by changing the translation.
      Specified by:
      getSecondaryRange in interface PairwiseRenderContext
      Returns:
      a RangeLocation.
    • getDirection

      public int getDirection()
      getDirection returns the direction in which this context expects the sequence to be rendered - HORIZONTAL or VERTICAL.
      Specified by:
      getDirection in interface SequenceRenderContext
      Returns:
      an int.
    • setDirection

      public void setDirection(int direction) throws IllegalArgumentException
      setDirection sets the direction in which this context will render the sequence - HORIZONTAL or VERTICAL.
      Parameters:
      direction - an int.
      Throws:
      IllegalArgumentException - if an invalid direction is used.
    • getSecondaryDirection

      public int getSecondaryDirection()
      getSecondaryDirection returns the direction in which this context expects the secondary sequence to be rendered - HORIZONTAL or VERTICAL.
      Specified by:
      getSecondaryDirection in interface PairwiseRenderContext
      Returns:
      an int.
    • getScale

      public double getScale()
      getScale returns the scale in pixels per Symbol.
      Specified by:
      getScale in interface SequenceRenderContext
      Returns:
      a double.
    • setScale

      public void setScale(double scale)
      setScale sets the scale in pixels per Symbol.
      Parameters:
      scale - a double.
    • getSymbolTranslation

      public int getSymbolTranslation()
      getSymbolTranslation returns the current translation in Symbols which will be applied when rendering. The sequence will be rendered starting at this translation. Values may be from 0 to the length of the rendered sequence.
      Returns:
      an int.
    • setSymbolTranslation

      public void setSymbolTranslation(int translation) throws IndexOutOfBoundsException
      setSymbolTranslation sets the translation in Symbols which will be applied when rendering. The sequence will be rendered starting at that translation. Values may be from 0 to the length of the rendered sequence.
      Parameters:
      translation - an int.
      Throws:
      IndexOutOfBoundsException - if the translation is greater than the sequence length.
    • getSecondarySymbolTranslation

      getSecondarySymbolTranslation returns the current translation in Symbols which will be applied when rendering. The secondary sequence will be rendered starting at this translation. Values may be from 0 to the length of the rendered sequence.
      Returns:
      an int.
    • setSecondarySymbolTranslation

      public void setSecondarySymbolTranslation(int translation) throws IndexOutOfBoundsException
      setSecondarySymbolTranslation sets the translation in Symbols which will be applied when rendering. The secondary sequence will be rendered starting at that translation. Values may be from 0 to the length of the rendered sequence.
      Parameters:
      translation - an int.
      Throws:
      IndexOutOfBoundsException - if the translation is greater than the sequence length.
    • getLeadingBorder

      getLeadingBorder returns the leading border of the primary sequence.
      Specified by:
      getLeadingBorder in interface SequenceRenderContext
      Returns:
      a SequenceRenderContext.Border.
    • getTrailingBorder

      getTrailingBorder returns the trailing border of the primary sequence.
      Specified by:
      getTrailingBorder in interface SequenceRenderContext
      Returns:
      a SequenceRenderContext.Border.
    • getRenderer

      getRenderer returns the current PairwiseSequenceRenderer.
      Returns:
      a PairwiseSequenceRenderer.
    • setRenderer

      setRenderer sets the current PairwiseSequenceRenderer.
      Throws:
      ChangeVetoException
    • getRenderingHints

      getRenderingHints returns the RenderingHints currently being used by the Graphics2D instances of delegate renderers. If none is set, the constructor creates one with a null Map.
      Returns:
      a RenderingHints.
    • setRenderingHints

      public void setRenderingHints(RenderingHints hints)
      setRenderingHints sets the RenderingHints which will be used by the Graphics2D instances of delegate renderers.
      Parameters:
      hints - a RenderingHints.
    • sequenceToGraphics

      public double sequenceToGraphics(int sequencePos)
      sequenceToGraphics converts a sequence index to a graphical position.
      Specified by:
      sequenceToGraphics in interface SequenceRenderContext
      Parameters:
      sequencePos - an int.
      Returns:
      a double.
    • secondarySequenceToGraphics

      public double secondarySequenceToGraphics(int sequencePos)
      secondarySequenceToGraphics converts a sequence index to a graphical position.
      Specified by:
      secondarySequenceToGraphics in interface PairwiseRenderContext
      Parameters:
      sequencePos - an int.
      Returns:
      a double.
    • graphicsToSequence

      public int graphicsToSequence(double graphicsPos)
      graphicsToSequence converts a graphical position to a sequence index.
      Specified by:
      graphicsToSequence in interface SequenceRenderContext
      Parameters:
      graphicsPos - a double.
      Returns:
      an int.
    • graphicsToSequence

      public int graphicsToSequence(Point2D point)
      graphicsToSequence converts a graphical position to a sequence index.
      Specified by:
      graphicsToSequence in interface SequenceRenderContext
      Parameters:
      point - a graphic position.
      Returns:
      an int.
    • graphicsToSecondarySequence

      public int graphicsToSecondarySequence(double graphicsPos)
      graphicsToSecondarySequence converts a graphical position to a secondary sequence index.
      Specified by:
      graphicsToSecondarySequence in interface PairwiseRenderContext
      Parameters:
      graphicsPos - a double.
      Returns:
      an int.
    • graphicsToSecondarySequence

      public int graphicsToSecondarySequence(Point point)
      graphicsToSecondarySequence converts a graphical position to a secondary sequence index.
      Specified by:
      graphicsToSecondarySequence in interface PairwiseRenderContext
      Parameters:
      point - a Point.
      Returns:
      an int.
    • getVisibleSymbolCount

      public int getVisibleSymbolCount()
      getVisibleSymbolCount returns the maximum number of Symbols which can be rendered in the visible area (excluding all borders) of the PairwiseSequencePanel at the current scale. Note that if the translation is greater than 0, the actual number of Symbols rendered will be less.
      Returns:
      an int.
    • getVisibleSecondarySymbolCount

      getVisibleSecondarySymbolCount returns the maximum number of secondary Symbols which can be rendered in the visible area (excluding all borders) of the PairwiseSequencePanel at the current scale. Note that if the translation is greater than 0, the actual number of Symbols rendered will be less.
      Returns:
      an int.
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • resizeAndValidate

      public void resizeAndValidate()
      resizeAndValidate sets the minimum, preferred and maximum sizes of the component according to the current visible symbol count.
    • addChangeListener

      addChangeListener adds a listener for all types of change.
      Specified by:
      addChangeListener in interface Changeable
      Parameters:
      cl - a ChangeListener.
    • addChangeListener

      addChangeListener adds a listener for specific types of change.
      Specified by:
      addChangeListener in interface Changeable
      Parameters:
      cl - a ChangeListener.
      ct - a ChangeType.
    • removeChangeListener

      removeChangeListener removes a listener.
      Specified by:
      removeChangeListener in interface Changeable
      Parameters:
      cl - a ChangeListener.
    • removeChangeListener

      removeChangeListener removes a listener.
      Specified by:
      removeChangeListener in interface Changeable
      Parameters:
      cl - a ChangeListener.
      ct - a ChangeType.
    • isUnchanging

      public boolean isUnchanging(ChangeType ct)
      Description copied from interface: Changeable

      A particular ChangeType can never be raised by this Changeable.

      If this returns true, then it is guaranteed that change events of this type (and all child types) can never under any circumstances be fired by this Changeable instance. If it returns false, that does not mean that this type of event will or even can be raised, but that it is worth registering listeners incase.

      Specified by:
      isUnchanging in interface Changeable
      Parameters:
      ct - the ChangeType to check
      Returns:
      true if ChangeEvents of this type are guaranteed to never be fired
    • addSequenceViewerListener

      addSequenceViewerListener adds a listener for mouse click SequenceViewerEvents.
      Parameters:
      svl - a SequenceViewerListener.
    • removeSequenceViewerListener

      removeSequenceViewerListener removes a listener for mouse click SequenceViewerEvents.
      Parameters:
      svl - a SequenceViewerListener.
    • addSequenceViewerMotionListener

      addSequenceViewerMotionListener adds a listener for mouse motion SequenceViewerEvents.
      Parameters:
      svml - a SequenceViewerMotionListener.
    • removeSequenceViewerMotionListener

      addSequenceViewerMotionListener removes a listener for mouse motion SequenceViewerEvents.
      Parameters:
      svml - a SequenceViewerMotionListener.
    • getChangeSupport

      getChangeSupport lazily instantiates a helper for change listeners.
      Parameters:
      ct - a ChangeType.
      Returns:
      a ChangeSupport object.
    • hasListeners

      protected boolean hasListeners()
      hasListeners returns true if there are active listeners for BioJava events.
      Returns:
      a boolean value.
    • isActive

      protected boolean isActive()
      isActive returns true if both the Sequences to be rendered and the PairwiseHomologyRenderer are not null.
      Returns:
      a boolean value.