Class TranslatedSequencePanel

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, SwingConstants, SequenceRenderContext, Changeable

    public class TranslatedSequencePanel
    extends JComponent
    implements SequenceRenderContext, Changeable

    TranslatedSequencePanel is a panel that displays a Sequence. Its features are that it will always draw at low pixel coordinates when using Java2D to render very long sequences and it is quite fast (approximately 8x faster than SequencePanel

    .

    A TranslatedSequencePanel can either display the sequence from left-to-right (HORIZONTAL) or from top-to-bottom (VERTICAL). It has an associated scale which is the number of pixels per symbol and a translation which is the number of Symbols to skip before rendering starts. In order to produce a scrolling effect, the setSymbolTranslation method may be hooked up to an Adjustable such as JScrollBar or to an event listener.

    The exact number of Symbols rendered depends on the width 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, Thomas Down, Jolyon Holdstock
    See Also:
    Serialized Form
    • Field Detail

      • 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 Detail

      • TranslatedSequencePanel

        public TranslatedSequencePanel()
        Creates a new TranslatedSequencePanel with the default settings (direction HORIZONTAL, scale 10.0 pixels per symbol, symbol translation 0, leading border 0.0, trailing border 0.0, 12 point sanserif font).
    • Method Detail

      • getSequence

        public SymbolList getSequence()
        getSequence returns the entire Sequence currently being rendered.
        Returns:
        a Sequence.
      • setSequence

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

        public RangeLocation getRange()
        getRange returns a RangeLocation representing the region of the sequence currently being rendered. This is calculated from the size of the TranslatedSequencePanel, minus its SequenceRenderContext.Borders and its delegate renderer borders (if any), the current rendering translation and the current scale. The value will therefore change when the TranslatedSequencePanel is resized or "scrolled" by changing the translation.
        Specified by:
        getRange in interface SequenceRenderContext
        Returns:
        a RangeLocation.
      • getDirection

        public int getDirection()
        getDirection returns the direction in which this context expects sequences to be rendered - HORIZONTAL or VERTICAL.
        Specified by:
        getDirection in interface SequenceRenderContext
        Returns:
        an int.
      • 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, immediately after any borders, 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, immediately after any borders, 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.
      • getRenderingHints

        public RenderingHints 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.
      • getVisibleSymbolCount

        public int getVisibleSymbolCount()
        getVisibleSymbolCount returns the maximum number of Symbols which can be rendered in the visible area (excluding all borders) of the TranslatedSequencePanel 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.
      • resizeAndValidate

        public void resizeAndValidate()
        resizeAndValidate sets the minimum, preferred and maximum sizes of the component according to the current leading and trailing borders, renderer depth and visible symbol count.
      • 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
      • getChangeSupport

        protected ChangeSupport getChangeSupport​(ChangeType ct)
        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 Sequence to be rendered and the SequenceRenderer are not null.
        Returns:
        a boolean value.