org.peace_tools.views.overlap
Class OverlapPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.peace_tools.views.overlap.OverlapPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

 class OverlapPanel
extends javax.swing.JPanel

The overlap panel that displays the actual overlap image.

This panel performs the core task of drawing the various fragments illustrating the overlap. The fragments are drawn row-by-row using the data from a given (specified in the constructor) OverlapModel object. The size and location of the rectangles for each fragment depend on the current scaling factors set for this component (via call to setScale() method). The scaling factors also control the preferred size reported by this panel. The color map maintained by this class is used to color the fragments based on their cluster ID.

NoteThis class is meant to be instantiated and used only by the OverlapView class. Consequently it has been made package private.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  ClusterColorMapper colorMapper
          Helper to look-up color for a given cluster ID.
private  double colScale
          The scale to be applies when rendering a single column.
private  java.awt.Font font
          The font being used by this panel to render information for each fragment.
private  OverlapModel overlapModel
          The OverlapModel that provides the necessary information for rendering the core information required by this panel.
private  int renderInfo
          Variable to indicate the information about a fragment that should be rendered.
private  double rowScale
          The scale to be applies when rendering a single row.
private static long serialVersionUID
          Generated serialization UID (merely to keep the compiler happy)
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
OverlapPanel(OverlapModel overlapModel, ClusterColorMapper colorMapper, double rowScale, double colScale)
          The only constructor.
 
Method Summary
private  java.awt.Font computeFont(java.awt.Graphics g)
          Compute the font that will fit letters within each fragment rectangle.
 double getColScale()
          Obtain the current column scaling factor being used.
 int getRenderInfo()
          Obtain the type of information being rendered for each fragment.
 double getRowScale()
          Obtain the current row scaling factor being used.
private  void paint(java.awt.Graphics main, int row, ESTEntry fragment)
          Helper method to paint a given fragment using a given graphics handle.
 void paintComponent(java.awt.Graphics g)
          Override the default paint method for this panel to render fragments.
 void setRenderInfo(int renderInfo)
          Set the type of information to be rendered for each fragment.
 void setScale(double rowScale, double colScale)
          Method to set the current scales used by this component.
private  java.awt.Rectangle toModelCoordinates(java.awt.Rectangle pixelBounds)
          Helper method to translate graphics coordinates to model coordinates.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rowScale

private double rowScale
The scale to be applies when rendering a single row. This value represents the maximum height of each row. Once the row height is above 3 at least one blank line is allocated for each row to clearly delineate one row from the other. This value is initialized in the constructor and can be changed via a call to the setScale() method in this class. Typically this value is in integral units without any fractions. However, it is maintained as a double to accommodate non-integral scales in the future. However, this value should never be set to zero.


colScale

private double colScale
The scale to be applies when rendering a single column. This value represents the maximum width of each column. This value is initialized in the constructor and can be changed via a call to the setScale() method in this class. Typically this value is in integral units when columns occupy more than 1 pixel. If a column occupies fewer than one pixel then this value is a fractional value. This value should never be set to zero.


overlapModel

private final OverlapModel overlapModel
The OverlapModel that provides the necessary information for rendering the core information required by this panel. This instance variable is initialized by the constructor and is never changed during the life time of this object.


colorMapper

private final ClusterColorMapper colorMapper
Helper to look-up color for a given cluster ID. This interface is used when rendering fragments. The color mapper is used to look up the colors set for a given cluster, given its cluster ID. The cluster colors are set and updated indirectly by the OverlapView class.


renderInfo

private int renderInfo
Variable to indicate the information about a fragment that should be rendered. The value of this instance variable is either 0, 1, 2, or 3. These values are interpreted as follows:
  1. Do not render any details (just draws a rectangle).
  2. Show nucleotide sequence information.
  3. Show FASTA identifier/header information.
  4. Show debugging information.


font

private java.awt.Font font
The font being used by this panel to render information for each fragment. This font is computed based on the scale set for this panel. The font is computed (in the computeFont(Graphics) method) such that the characters fit within the scales specified for this object. Each time the scale is changed the font is reset to null (in the setScale(double, double) method) to fore computing a new font.


serialVersionUID

private static final long serialVersionUID
Generated serialization UID (merely to keep the compiler happy)

See Also:
Constant Field Values
Constructor Detail

OverlapPanel

public OverlapPanel(OverlapModel overlapModel,
                    ClusterColorMapper colorMapper,
                    double rowScale,
                    double colScale)
The only constructor.

Parameters:
overlapModel - The overlap model from where the data for rendering the fragments is obtained.
colorMapper - The helper object to be used to determine the color for rendering fragments belonging to various clusters.
rowScale - The initial scale for the rows that determines the pixel size of each row.
colScale - The initial scale for columns that determines the pixel size of each column.
Method Detail

setRenderInfo

public void setRenderInfo(int renderInfo)
Set the type of information to be rendered for each fragment. The valid values that can passed to this method are: 0, 1, 2, or 3. These values are interpreted as follows:
  1. Do not render any details (just draws a rectangle).
  2. Show nucleotide sequence information.
  3. Show FASTA identifier/header information.
  4. Show debugging information.

Parameters:
renderInfo - A simple integer code indicating the type of information to be rendered by this panel. See list above for details.

getRenderInfo

public int getRenderInfo()
Obtain the type of information being rendered for each fragment.

Returns:
Returns a simple integer code indicating the type of information being rendered by this panel. The value values returned by this method are 0, 1, 2, or 3 and they are to be interpreted as follows:
  1. Not rendering any details (just draws a rectangle).
  2. Showing nucleotide sequence information.
  3. Showing FASTA identifier/header information.
  4. Showing debugging information.

getRowScale

public double getRowScale()
Obtain the current row scaling factor being used.

Returns:
The current row scaling factor being used. This value is integral values.

getColScale

public double getColScale()
Obtain the current column scaling factor being used.

Returns:
The current column scaling factor being used. This value can be fractional values that may have to be normalized to display or work within the GUI for sliders.

toModelCoordinates

private java.awt.Rectangle toModelCoordinates(java.awt.Rectangle pixelBounds)
Helper method to translate graphics coordinates to model coordinates. This method is a helper method that is used when painting fragments. This method is used to translate the graphics coordinates (in pixel values) to model coordinates (rows and columns in the OverlapModel). This method uses the rowScale and colScale values (set via call to setScale(double, double) method) to perform the translation.

Parameters:
pixelBounds - The graphical coordinates (in pixel values) to be translated.
Returns:
A Rectangle object containing the graphical coordinates translated to model coordinates.

paintComponent

public void paintComponent(java.awt.Graphics g)
Override the default paint method for this panel to render fragments. This method overrides the default paint method in the parent class to render fragments using the following approach:
  1. The clip bounds of the graphics object is translated to model coordinates using the toModelCoordinates method.
  2. For each row to be rendered, this method obtains the list of fragments in each row and checks to see if the fragment is to be rendered.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphics component to be used for rendering the fragments.

paint

private void paint(java.awt.Graphics main,
                   int row,
                   ESTEntry fragment)
Helper method to paint a given fragment using a given graphics handle. This method operates as follows:
  1. It computes the bounds of the fragment in terms of pixel coordinates given the fragments row, starting column, fragment sequence length, and the rowScale.
  2. Using the cluster color set for the fragment's cluster, it draws a rectangle of the appropriate size.
  3. It then renders the nucleotide sequence or FASTA identifier information depending on the configuration.

Parameters:
main - The graphics handle to be used for rendering the given fragment.
row - The logical model row where the fragment is to be rendered.
fragment - The fragment to be rendered.

computeFont

private java.awt.Font computeFont(java.awt.Graphics g)
Compute the font that will fit letters within each fragment rectangle. This method is invoked from the paintComponent(Graphics) method whenever the font instance variable is null. This method uses the supplied Graphics object to compute the largest mono-spaced font that will fit within the allocated space for a fragment.

Parameters:
g - The graphics handle to be used for computing the font sizes.
Returns:
The font object to be used for rendering characters within the boundaries of each fragment.

setScale

public void setScale(double rowScale,
                     double colScale)
Method to set the current scales used by this component.

This method must be used to set the scales to be used for painting rows and columns in this panel. The scales also determine the overall size of this component.

Note: The containing component my repaint itself to ensure that changes in bounds are correctly refreshed on screen.

Parameters:
rowScale - The scale that determines the number of pixels occupied by each row. This value cannot be zero. However, no checks are performed on the scale. Consequently, the behavior of this component with a zero scale is undefined.
colScale - The scale that determines the number of pixels occupied by each row. This value cannot be zero. However, no checks are performed on the scale. Consequently, the behavior of this component with a zero scale is undefined.