org.peace_tools.views
Class ClusterSummaryView

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.ClusterSummaryView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible, WorkspaceListener

public class ClusterSummaryView
extends javax.swing.JPanel
implements WorkspaceListener, java.lang.Runnable

View to display a graph of clusters to provide a summary view.

See Also:
Serialized Form

Nested Class Summary
private  class ClusterSummaryView.TickLine
          A simple component to draw vertical or horizontal ticks.
 
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  java.awt.Rectangle area
          The area in the graph pane where the actual graph is drawn.
private  javax.swing.JSlider[] axisScale
          The x and y axis scale controllers.
private  int borderSize
          Empty white space around the core graph to make things look good.
private  javax.swing.JToggleButton classify
          A toggle button which when checked (or depressed) indicates that the bars must also include the classification information for each cluster displayed in the graph.
private  ClusterFile clusterFile
          The set of clusters that we are working with.
private  ESTList estList
          The set of ESTs that the clusters correspond to.
private  javax.swing.JPanel graph
          The panel that is used to draw the cluster graph.
private  javax.swing.JToggleButton logScale
          A toggle button which when checked (or depressed) indicates that the y-axis must be drawn on a logarithmic scale rather than on a linear scale.
private  float LogStartValue
          A convenience constant to set the smallest y-axis value when the data is displayed on a log scale.
private  MainFrame mainFrame
          Convenient reference to the main frame class that logically owns this component.
private  int maxClusterSize
          The largest cluster in the set of clusters that we are working with.
private static long serialVersionUID
          Generated serialization UID (merely to keep the compiler happy)
private  int TickFontSize
          This is a constant that provides the maximum font size we would like to use for the ticks on the graph.
private  javax.swing.JToolBar toolbar
          The tool bar that contains some commonly used tools with the summary view and for modifying the graph size / info.
private  javax.swing.JLabel yLabel
          The main y-axis label is drawn separately so that it can be rotated and drawn vertically in the paintGraph() method.
 
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
ClusterSummaryView(MainFrame frame, ClusterFile clusterFile, ESTList estList, MSTClusterData wsEntry)
          The default constructor.
 
Method Summary
private  void addXAxisLabels(java.awt.Rectangle area)
          Helper method to create X-axis labels.
private  void addYAxisLabels(java.awt.Rectangle area)
          Helper method to create Y-axis labels.
private  void checkAndClassify()
          Helper method to check and launch classification from another thread.
private  void createGraph()
          Helper method to configure and setup the graph panel to draw the actual cluster graph.
private  java.awt.Dimension createLabels(float startValue, int endValue, int tickPixelSpacing, int axisLength, boolean xAxis, java.awt.Rectangle area, java.util.ArrayList<javax.swing.JLabel> labelList)
          Helper method to create the axis labels.
private  javax.swing.JSlider createSlider(int size)
          Helper method to create a slider with suitable scale.
private  void createTicks(java.util.ArrayList<javax.swing.JLabel> labelList, boolean xAxis)
          Helper method to create little tick lines on x or y axis.
private  void drawClassificationBars(java.awt.Graphics g, java.awt.Rectangle barArea, ClusterNode cluster)
          Draw clustering classification information in the graph.
private  void drawGraph(java.awt.Graphics g)
          Top-level method to draw the cluster graph.
private  int getStartX(int clIndex)
          Helper method to translate a cluster Index to an absolute x-coordinate.
private  void resizeGraph()
          Helper method to resize/scale the graph.
 void run()
          Perform classification from a separate thread.
private  void setupAxisLabels()
          Helper method to setup x and y axis labels used to draw axis information.
private  void setupToolBar()
          Helper method to configure and setup various tools in the tool bar.
private  int toClusterIndex(int x)
          Helper method to convert an x-coordinate in the graph to a cluster index.
 void workspaceChanged(WorkspaceEvent event)
          Intercept and update graph if classifiers change.
 
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, paintComponent, 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

TickFontSize

private final int TickFontSize
This is a constant that provides the maximum font size we would like to use for the ticks on the graph.

See Also:
Constant Field Values

axisScale

private javax.swing.JSlider[] axisScale
The x and y axis scale controllers. The following array holds two sliders that can be used to control the scale of the x-axis and y-axis in the graph. The sliders are created in the setupToolBar() method. The sliders are set such that the scale of the graph cannot be set to a value which reduces the dimension of the graph below 100x100.


yLabel

private javax.swing.JLabel yLabel
The main y-axis label is drawn separately so that it can be rotated and drawn vertically in the paintGraph() method. Consequently, it is maintained as a separate instance variable (unlike other labels).


area

private java.awt.Rectangle area
The area in the graph pane where the actual graph is drawn. This area is set by the various method to ensure that the graph drawn does not interfere with the axis and borders etc.


borderSize

private int borderSize
Empty white space around the core graph to make things look good.


graph

private javax.swing.JPanel graph
The panel that is used to draw the cluster graph. The panel is created in the setupGraph() method. The paintComponent call-back is intercepted by this component to draw the graph.


toolbar

private final javax.swing.JToolBar toolbar
The tool bar that contains some commonly used tools with the summary view and for modifying the graph size / info.


logScale

private javax.swing.JToggleButton logScale
A toggle button which when checked (or depressed) indicates that the y-axis must be drawn on a logarithmic scale rather than on a linear scale.


classify

private javax.swing.JToggleButton classify
A toggle button which when checked (or depressed) indicates that the bars must also include the classification information for each cluster displayed in the graph.


maxClusterSize

private final int maxClusterSize
The largest cluster in the set of clusters that we are working with. This information is set once and reused to draw the graphs.


clusterFile

private final ClusterFile clusterFile
The set of clusters that we are working with. The cluster data is set when this class is instantiated.


estList

private final ESTList estList
The set of ESTs that the clusters correspond to. This data is actually used only for classification.


LogStartValue

private final float LogStartValue
A convenience constant to set the smallest y-axis value when the data is displayed on a log scale.

See Also:
Constant Field Values

mainFrame

private final MainFrame mainFrame
Convenient reference to the main frame class that logically owns this component. This value is set in the constructor and is never changed.


serialVersionUID

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

See Also:
Constant Field Values
Constructor Detail

ClusterSummaryView

public ClusterSummaryView(MainFrame frame,
                          ClusterFile clusterFile,
                          ESTList estList,
                          MSTClusterData wsEntry)
The default constructor. The default constructor creates the various controls that are part of the summary view. In addition, it also sets up the summary graph with default view and seize.

Parameters:
frame - The main frame that logically owns this view. This reference is used to launch the classifier dialog.
clusterFile - The data model to be used to display the clusters from a given cluster file.
estList - The set of ESTs that contain information about each EST in the clusters.
wsEntry - The workspace entry corresponding to the clustering file that is being displayed by this view.
Method Detail

setupToolBar

private void setupToolBar()
Helper method to configure and setup various tools in the tool bar. This method was introduced to streamline the code better and cut down the code clutter in the constructor.


createSlider

private javax.swing.JSlider createSlider(int size)
Helper method to create a slider with suitable scale. This method is used to create a suitable slider to set size for both x and y axis scaling. This method ensures the scale of the axis cannot be below a value that will make the axis smaller than 100 pixels. Note that JSlider takes only integer values. So the scales are translated to multiplied by 100. That is rather than setting scale to 0.08 we set scale to 8.

Parameters:
size - The default/normal size of the axis.
Returns:
A JSlider with suitable scale and default value set.

drawGraph

private void drawGraph(java.awt.Graphics g)
Top-level method to draw the cluster graph. This method is the top-level method to draw the cluster graph associated with this object. This method is invoked from the graph JPanel as the paintComponent() call back is intercepted and forwarded to this method as setup in the setupGraph() method. This method draws the graph by suitably delegating the appropriate tasks to various helper methods.

Parameters:
g - The graphics object to be used to draw the graph.

drawClassificationBars

private void drawClassificationBars(java.awt.Graphics g,
                                    java.awt.Rectangle barArea,
                                    ClusterNode cluster)
Draw clustering classification information in the graph. This method is invoked from the drawGraph() method to draw the classification information in the bar using the coloring scheme setup by the user. This method uses the EST classification information and divides the bar area into percentages to reflect the groups of ESTs.

Parameters:
g - The graphics object to be used to draw the bars.
barArea - The area of the bar to be filled to reflect the percentages of cluster classification information.
cluster - The cluster whose classification information is to be displayed as percentages.

getStartX

private int getStartX(int clIndex)
Helper method to translate a cluster Index to an absolute x-coordinate. This is a helper method that can be used to translate a given cluster index to an absolute x-coordinate value within the graph pane.

Parameters:
clIndex - The index of the cluster to be translated.
Returns:
The starting x-coordinate of the cluster bar in the cluster graph.

toClusterIndex

private int toClusterIndex(int x)
Helper method to convert an x-coordinate in the graph to a cluster index.

Parameters:
x - The x-coordinate to be translated to a cluster id.
Returns:
The index of the cluster that logically contains the given x-coordinate. If the x-coordinate is not contained by any cluster then this method returns -1.

createGraph

private void createGraph()
Helper method to configure and setup the graph panel to draw the actual cluster graph. The graph is displayed in the middle of the panel. This method was introduced to streamline the code better and cut down the code clutter in the constructor.


resizeGraph

private void resizeGraph()
Helper method to resize/scale the graph. This method is called initially or whenever the user changes the scale of the graph. This method uses the x and y axis scale factors to suitably scale the graph size and relayout the graph.


setupAxisLabels

private void setupAxisLabels()
Helper method to setup x and y axis labels used to draw axis information. This helper method is invoked whenever the size of the graph is changed (by the user via tool bar buttons). This method computes the labels to be displayed in the graph and then positions them within the graph pane.

Note: The graph (a JPanel) does not have a layout manager. Therefore the x and y locations of the labels are completely under our control.


addXAxisLabels

private void addXAxisLabels(java.awt.Rectangle area)
Helper method to create X-axis labels. This is a helper method that is invoked from the setupAxisLabels() method to setup the labels on the x-axis. This method was introduced to streamline the code a bit better.

Note: This method must be called only after the addYAxisLabels(Rectangle) method has been called. This is needed to ensure that the area of the graph has been suitably updated.

Parameters:
area - The area of the graph to be used for creating the labels.

addYAxisLabels

private void addYAxisLabels(java.awt.Rectangle area)
Helper method to create Y-axis labels. This is a helper method that is invoked from the setupAxisLabels() method to setup the labels on the y-axis. This method was introduced to streamline the code a bit better.

Note: This method must be called before the addXAxisLabels(Rectangle) method. This method sets up the graph area appropriately for the addXAxisLabels(Rectangle) method.

Parameters:
area - The area of the graph to be used for creating the labels.

createTicks

private void createTicks(java.util.ArrayList<javax.swing.JLabel> labelList,
                         boolean xAxis)
Helper method to create little tick lines on x or y axis. This is a helper method that is used create small tick lines on the x-axis or the y-axis.

Parameters:
labelList - The labels to be used to determine the location of the ticks.
xAxis - If this parameter is true, then the ticks are for the x-axis. Otherwise the ticks are to be created for the y-axis.

createLabels

private java.awt.Dimension createLabels(float startValue,
                                        int endValue,
                                        int tickPixelSpacing,
                                        int axisLength,
                                        boolean xAxis,
                                        java.awt.Rectangle area,
                                        java.util.ArrayList<javax.swing.JLabel> labelList)
Helper method to create the axis labels. This helper method is used to add labels on both the x and the y axes. This method performs some initial math to ensure that the labels are reasonably well spaced out.

Parameters:
startValue - The starting value for the axis.
endValue - The ending value for the axis.
tickPixelSpacing - The pixels between ticks.
axisLength - The net length of the axis.
xAxis - If this is true, then the labels are for the x-axis. Otherwise labels are to be created for the y-axis.
area - The net area of the graph.
labelList - An array list to which the labels created are added. This list can be null (then labels are not added to the list).
Returns:
The dimension of the largest (or longest) label created. This value is typically used to right-justify labels on the y-axis.

checkAndClassify

private void checkAndClassify()
Helper method to check and launch classification from another thread. This method is a utility method that is invoked from a couple of different listener call back methods to check and classifiy the data as necessary.


run

public void run()
Perform classification from a separate thread. This is a helper method that is invoked from a separate thread to perform classification of EST data and subsequently cluster information.

Specified by:
run in interface java.lang.Runnable

workspaceChanged

public void workspaceChanged(WorkspaceEvent event)
Intercept and update graph if classifiers change. This method intercepts notifications from the work space and if the classifier list in the work space changes and the classification option is enabled in this graph, then this method reclassifies the ESTs and redisplays the graph with classifier information.

Specified by:
workspaceChanged in interface WorkspaceListener
Parameters:
event - The event that contains the information regarding the change that has occured to the workspace.