## org.biojava.bio.gui.sequence
Class TranslatedSequencePanel

    java.lang.Object
      java.awt.Component
          java.awt.Container
              javax.swing.JComponent
                  org.biojava.bio.gui.sequence.TranslatedSequencePanel

All Implemented Interfaces:
  Changeable, java.awt.image.ImageObserver, java.awt.MenuContainer, SequenceRenderContext, java.io.Serializable, javax.swing.SwingConstants

public class TranslatedSequencePanel
extends javax.swing.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 `Symbol`s 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 `Symbol`s rendered depends on the width of the panel and the scale. Resizing the panel will cause the number of `Symbol`s 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
See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class javax.swing.JComponent
`javax.swing.JComponent.AccessibleJComponent`

Nested classes inherited from class java.awt.Container
`java.awt.Container.AccessibleAWTContainer`

Nested classes inherited from class java.awt.Component
`java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy`

Nested classes inherited from class org.biojava.bio.gui.sequence.SequenceRenderContext
`SequenceRenderContext.Border`

Field Summary
`static ChangeType` `RENDERER` Constant `RENDERER` is a `ChangeType` which indicates a change to the renderer, requiring a layout update.
`static ChangeType` `TRANSLATION` Constant `TRANSLATION` is a `ChangeType` which indicates a change to the translation, requiring a paint update.

Fields inherited from class javax.swing.JComponent
`accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

Fields inherited from class java.awt.Component
`BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

Fields inherited from interface org.biojava.bio.gui.sequence.SequenceRenderContext
`LAYOUT, REPAINT`

Fields inherited from interface javax.swing.SwingConstants
`BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST`

Fields inherited from interface java.awt.image.ImageObserver
`ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

Constructor Summary
`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 Summary
`void` `addChangeListener(ChangeListener cl)` `addChangeListener` adds a listener for all types of change.
`void` `addChangeListener(ChangeListener cl, ChangeType ct)` `addChangeListener` adds a listener for specific types of change.
`void` `addSequenceViewerListener(SequenceViewerListener svl)` `addSequenceViewerListener` adds a listener for mouse click `SequenceViewerEvent`s.
`void` `addSequenceViewerMotionListener(SequenceViewerMotionListener svml)` `addSequenceViewerMotionListener` adds a listener for mouse motion `SequenceViewerEvent`s.
`protected ChangeSupport` `getChangeSupport(ChangeType ct)` `getChangeSupport` lazily instantiates a helper for change listeners.
`int` `getDirection()` `getDirection` returns the direction in which this context expects sequences to be rendered - HORIZONTAL or VERTICAL.
`FeatureHolder` `getFeatures()` `getFeatures` returns all of the `Feature`s belonging to the currently rendered `Sequence`.
`SequenceRenderContext.Border` `getLeadingBorder()` `getLeadingBorder` returns the leading border.
`RangeLocation` `getRange()` `getRange` returns a `RangeLocation` representing the region of the sequence currently being rendered.
`SequenceRenderer` `getRenderer()` `getRenderer` returns the current `SequenceRenderer`.
`java.awt.RenderingHints` `getRenderingHints()` `getRenderingHints` returns the `RenderingHints` currently being used by the `Graphics2D` instances of delegate renderers.
`double` `getScale()` `getScale` returns the scale in pixels per `Symbol`.
`Sequence` `getSequence()` `getSequence` returns the entire `Sequence` currently being rendered.
`SymbolList` `getSymbols()` `getSymbols` returns all of the `Symbol`s belonging to the currently rendered `Sequence`.
`int` `getSymbolTranslation()` `getSymbolTranslation` returns the current translation in `Symbol`s which will be applied when rendering.
`SequenceRenderContext.Border` `getTrailingBorder()` `getTrailingBorder` returns the trailing border.
`int` `getVisibleSymbolCount()` `getVisibleSymbolCount` returns the maximum number of `Symbol`s which can be rendered in the visible area (excluding all borders) of the `TranslatedSequencePanel` at the current scale.
`int` `graphicsToSequence(double graphicsPos)` `graphicsToSequence` converts a graphical position to a sequence index.
`int` `graphicsToSequence(java.awt.Point point)` `graphicsToSequence` converts a graphical position to a sequence index.
`protected boolean` `hasListeners()` `hasListeners` returns true if there are active listeners for BioJava events.
`protected boolean` `isActive()` `isActive` returns true if both the `Sequence` to be rendered and the `SequenceRenderer` are not null.
`boolean` `isUnchanging(ChangeType ct)` A particular ChangeType can never be raised by this Changeable.
`void` `paintComponent(java.awt.Graphics g)` `paintComponent` paints this component.
`void` `removeChangeListener(ChangeListener cl)` `removeChangeListener` removes a listener.
`void` `removeChangeListener(ChangeListener cl, ChangeType ct)` `removeChangeListener` removes a listener.
`void` `removeSequenceViewerListener(SequenceViewerListener svl)` `removeSequenceViewerListener` removes a listener for mouse click `SequenceViewerEvent`s.
`void` `removeSequenceViewerMotionListener(SequenceViewerMotionListener svml)` `addSequenceViewerMotionListener` removes a listener for mouse motion `SequenceViewerEvent`s.
`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.
`double` `sequenceToGraphics(int sequencePos)` `sequenceToGraphics` converts a sequence index to a graphical position.
`void` `setDirection(int direction)` `setDirection` sets the direction in which this context will render sequences - HORIZONTAL or VERTICAL.
`void` `setRenderer(SequenceRenderer renderer)` `setRenderer` sets the current `SequenceRenderer`.
`void` `setRenderingHints(java.awt.RenderingHints hints)` `setRenderingHints` sets the `RenderingHints` which will be used by the `Graphics2D` instances of delegate renderers.
`void` `setScale(double scale)` `setScale` sets the scale in pixels per `Symbol`.
`void` `setSequence(Sequence sequence)` `setSequence` sets the `Sequence` to be rendered.
`void` `setSymbolTranslation(int translation)` `setSymbolTranslation` sets the translation in `Symbol`s which will be applied when rendering.

Methods inherited from class javax.swing.JComponent

`addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI`

Methods inherited from class java.awt.Container

`add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree`

Methods inherited from class java.awt.Component

`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.biojava.bio.gui.sequence.SequenceRenderContext
`getFont`

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 Sequence 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`.

### getSymbols

    public SymbolList getSymbols()

  `getSymbols` returns all of the `Symbol`s belonging to the currently rendered `Sequence`.

  Specified by:
    `getSymbols` in interface `SequenceRenderContext`
  Returns:
    a `SymbolList`.

### getFeatures

    public FeatureHolder getFeatures()

  `getFeatures` returns all of the `Feature`s belonging to the currently rendered `Sequence`.

  Specified by:
    `getFeatures` in interface `SequenceRenderContext`
  Returns:
    a `FeatureHolder`.

### 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.Border`s 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`.

### setDirection

    public void setDirection(int direction)
                      throws java.lang.IllegalArgumentException

  `setDirection` sets the direction in which this context will render sequences - HORIZONTAL or VERTICAL.

  Parameters:
    `direction` - an `int`.
  Throws:
    `java.lang.IllegalArgumentException` - if an error occurs.

### 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 `Symbol`s 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 java.lang.IndexOutOfBoundsException

  `setSymbolTranslation` sets the translation in `Symbol`s 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:
    `java.lang.IndexOutOfBoundsException` - if the translation is greater than the sequence length.

### getLeadingBorder

    public SequenceRenderContext.Border getLeadingBorder()

  `getLeadingBorder` returns the leading border.

  Specified by:
    `getLeadingBorder` in interface `SequenceRenderContext`
  Returns:
    a `SequenceRenderContext.Border`.

### getTrailingBorder

    public SequenceRenderContext.Border getTrailingBorder()

  `getTrailingBorder` returns the trailing border.

  Specified by:
    `getTrailingBorder` in interface `SequenceRenderContext`
  Returns:
    a `SequenceRenderContext.Border`.

### getRenderer

    public SequenceRenderer getRenderer()

  `getRenderer` returns the current `SequenceRenderer`.

  Returns:
    a `SequenceRenderer`.

### setRenderer

    public void setRenderer(SequenceRenderer renderer)
                     throws ChangeVetoException

  `setRenderer` sets the current `SequenceRenderer`.

  Returns:
    a `SequenceRenderer`.
  Throws:
    `ChangeVetoException`

### getRenderingHints

    public java.awt.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(java.awt.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`.

### 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(java.awt.Point point)

  `graphicsToSequence` converts a graphical position to a sequence index.

  Specified by:
    `graphicsToSequence` in interface `SequenceRenderContext`
  Parameters:
    `point` - a point representing the position
  Returns:
    an `int`.

### getVisibleSymbolCount

    public int getVisibleSymbolCount()

  `getVisibleSymbolCount` returns the maximum number of `Symbol`s 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 `Symbol`s rendered will be less.

  Returns:
    an `int`.

### paintComponent

    public void paintComponent(java.awt.Graphics g)

  `paintComponent` paints this component.

  Parameters:
    `g` - a `Graphics` object.

### 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.

### addChangeListener

    public void addChangeListener(ChangeListener cl)

  `addChangeListener` adds a listener for all types of change.

  Specified by:
    `addChangeListener` in interface `Changeable`
  Parameters:
    `cl` - a `ChangeListener`.

### addChangeListener

    public void addChangeListener(ChangeListener cl,
                                  ChangeType ct)

  `addChangeListener` adds a listener for specific types of change.

  Specified by:
    `addChangeListener` in interface `Changeable`
  Parameters:
    `cl` - a `ChangeListener`.
    `ct` - a `ChangeType`.

### removeChangeListener

    public void removeChangeListener(ChangeListener cl)

  `removeChangeListener` removes a listener.

  Specified by:
    `removeChangeListener` in interface `Changeable`
  Parameters:
    `cl` - a `ChangeListener`.

### removeChangeListener

    public void removeChangeListener(ChangeListener cl,
                                     ChangeType ct)

  `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

    public void addSequenceViewerListener(SequenceViewerListener svl)

  `addSequenceViewerListener` adds a listener for mouse click `SequenceViewerEvent`s.

  Parameters:
    `svl` - a `SequenceViewerListener`.

### removeSequenceViewerListener

    public void removeSequenceViewerListener(SequenceViewerListener svl)

  `removeSequenceViewerListener` removes a listener for mouse click `SequenceViewerEvent`s.

  Parameters:
    `svl` - a `SequenceViewerListener`.

### addSequenceViewerMotionListener

    public void addSequenceViewerMotionListener(SequenceViewerMotionListener svml)

  `addSequenceViewerMotionListener` adds a listener for mouse motion `SequenceViewerEvent`s.

  Parameters:
    `svml` - a `SequenceViewerMotionListener`.

### removeSequenceViewerMotionListener

    public void removeSequenceViewerMotionListener(SequenceViewerMotionListener svml)

  `addSequenceViewerMotionListener` removes a listener for mouse motion `SequenceViewerEvent`s.

  Parameters:
    `svml` - a `SequenceViewerMotionListener`.

### 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.