weka.gui.visualize
Class VisualizePanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byweka.gui.visualize.VisualizePanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
ThresholdVisualizePanel

public class VisualizePanel
extends javax.swing.JPanel

This panel allows the user to visualize a dataset (and if provided) a classifier's/clusterer's predictions in two dimensions. If the user selects a nominal attribute as the colouring attribute then each point is drawn in a colour that corresponds to the discrete value of that attribute for the instance. If the user selects a numeric attribute to colour on, then the points are coloured using a spectrum ranging from blue to red (low values to high). When a classifier's predictions are supplied they are plotted in one of two ways (depending on whether the class is nominal or numeric).
For nominal class: an error made by a classifier is plotted as a square in the colour corresponding to the class it predicted.
For numeric class: predictions are plotted as varying sized x's, where the size of the x is related to the magnitude of the error.

Version:
$Revision: 1.20 $
Author:
Mark Hall (mhall@cs.waikato.ac.nz), Malcolm Ware (mfw4@cs.waikato.ac.nz)
See Also:
Serialized Form

Nested Class Summary
protected  class VisualizePanel.PlotPanel
          Inner class to handle plotting
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
 
Field Summary
private  java.awt.Dimension COMBO_SIZE
          Stop the combos from growing out of control
protected  java.awt.event.ActionListener listener
          An optional listener that we will inform when ComboBox selections change
protected  javax.swing.filechooser.FileFilter m_ArffFilter
          Filter to ensure only arff files are selected
protected  AttributePanel m_attrib
          The panel that displays the attributes , using color to represent another attribute.
protected  javax.swing.JButton m_cancel
          Button for the user to remove all splits.
protected  ClassPanel m_classPanel
          The panel that displays the legend for the colouring attribute
protected  javax.swing.JPanel m_classSurround
          Panel that surrounds the class panel with a titled border
protected  FastVector m_colorList
          The list of the colors used
protected  javax.swing.JComboBox m_ColourCombo
          Lets the user select the attribute to use for colouring
protected  java.awt.Color[] m_DefaultColors
          default colours for colouring discrete class
protected  javax.swing.JFileChooser m_FileChooser
          file chooser for saving instances
protected  javax.swing.JSlider m_Jitter
          The jitter slider
protected  javax.swing.JLabel m_JitterLab
          Label for the jitter slider
protected  LegendPanel m_legendPanel
          The panel that displays legend info if there is more than one plot
protected  Logger m_Log
          the logger
protected  VisualizePanel.PlotPanel m_plot
          The panel that displays the plot
protected  java.lang.String m_plotName
          The name of the plot (not currently displayed, but can be used in the containing Frame or Panel)
protected  javax.swing.JPanel m_plotSurround
          Panel that surrounds the plot panel with a titled border
protected  java.lang.String m_preferredColourDimension
           
protected  java.lang.String m_preferredXDimension
          These hold the names of preferred columns to visualize on---if the user has defined them in the Visualize.props file
protected  java.lang.String m_preferredYDimension
           
protected  javax.swing.JButton m_saveBut
          Button for the user to save the visualized set of instances
protected  javax.swing.JComboBox m_ShapeCombo
          Lets the user select the shape they want to create for instance selection.
protected  boolean m_showAttBars
          Show the attribute bar panel
protected  VisualizePanelListener m_splitListener
          An optional listener that we will inform when the user creates a split to seperate instances.
protected  javax.swing.JButton m_submit
          Button for the user to enter the splits.
protected  javax.swing.JComboBox m_XCombo
          Lets the user select the attribute for the x axis
protected  javax.swing.JComboBox m_YCombo
          Lets the user select the attribute for the y axis
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
VisualizePanel()
          Constructor
VisualizePanel(VisualizePanelListener ls)
          This constructor allows a VisualizePanelListener to be set.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener act)
          Add a listener for this visualize panel
 void addPlot(PlotData2D newPlot)
          Set a new plot to the visualize panel
 int getCIndex()
          Get the index of the attribute selected for coloring
 Instances getInstances()
          Get the master plot's instances
 java.lang.String getName()
          Returns the name associated with this plot. "" is returned if no name is set.
 int getSIndex()
          Get the index of the shape selected for creating splits.
 int getXIndex()
          Get the index of the attribute on the x axis
 int getYIndex()
          Get the index of the attribute on the y axis
static void main(java.lang.String[] args)
          Main method for testing this class
protected  void newColorAttribute(int a, Instances i)
          Sets the Colors in use for a different attrib if it is not a nominal attrib and or does not have more possible values then this will do nothing.
private  void saveVisibleInstances()
          Save the currently visible set of instances to a file
 void setColourIndex(int index)
          Sets the index used for colouring.
 void setInstances(Instances inst)
          Tells the panel to use a new set of instances.
 void setLog(Logger newLog)
          Sets the Logger to receive informational messages
 void setMasterPlot(PlotData2D newPlot)
          Set the master plot for the visualize panel
 void setName(java.lang.String plotName)
          Set a name for this plot
private  void setProperties(java.lang.String relationName)
          Set the properties for the VisualizePanel
 void setShapes(FastVector l)
          This will set the shapes for the instances.
 void setSIndex(int index)
          Set the shape for creating splits.
 void setUpComboBoxes(Instances inst)
           
 void setXIndex(int index)
          Set the index of the attribute for the x axis
 void setYIndex(int index)
          Set the index of the attribute for the y axis
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 
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, 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, 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
 

Field Detail

m_DefaultColors

protected java.awt.Color[] m_DefaultColors
default colours for colouring discrete class


m_XCombo

protected javax.swing.JComboBox m_XCombo
Lets the user select the attribute for the x axis


m_YCombo

protected javax.swing.JComboBox m_YCombo
Lets the user select the attribute for the y axis


m_ColourCombo

protected javax.swing.JComboBox m_ColourCombo
Lets the user select the attribute to use for colouring


m_ShapeCombo

protected javax.swing.JComboBox m_ShapeCombo
Lets the user select the shape they want to create for instance selection.


m_submit

protected javax.swing.JButton m_submit
Button for the user to enter the splits.


m_cancel

protected javax.swing.JButton m_cancel
Button for the user to remove all splits.


m_saveBut

protected javax.swing.JButton m_saveBut
Button for the user to save the visualized set of instances


COMBO_SIZE

private java.awt.Dimension COMBO_SIZE
Stop the combos from growing out of control


m_FileChooser

protected javax.swing.JFileChooser m_FileChooser
file chooser for saving instances


m_ArffFilter

protected javax.swing.filechooser.FileFilter m_ArffFilter
Filter to ensure only arff files are selected


m_JitterLab

protected javax.swing.JLabel m_JitterLab
Label for the jitter slider


m_Jitter

protected javax.swing.JSlider m_Jitter
The jitter slider


m_plot

protected VisualizePanel.PlotPanel m_plot
The panel that displays the plot


m_attrib

protected AttributePanel m_attrib
The panel that displays the attributes , using color to represent another attribute.


m_legendPanel

protected LegendPanel m_legendPanel
The panel that displays legend info if there is more than one plot


m_plotSurround

protected javax.swing.JPanel m_plotSurround
Panel that surrounds the plot panel with a titled border


m_classSurround

protected javax.swing.JPanel m_classSurround
Panel that surrounds the class panel with a titled border


listener

protected java.awt.event.ActionListener listener
An optional listener that we will inform when ComboBox selections change


m_splitListener

protected VisualizePanelListener m_splitListener
An optional listener that we will inform when the user creates a split to seperate instances.


m_plotName

protected java.lang.String m_plotName
The name of the plot (not currently displayed, but can be used in the containing Frame or Panel)


m_classPanel

protected ClassPanel m_classPanel
The panel that displays the legend for the colouring attribute


m_colorList

protected FastVector m_colorList
The list of the colors used


m_preferredXDimension

protected java.lang.String m_preferredXDimension
These hold the names of preferred columns to visualize on---if the user has defined them in the Visualize.props file


m_preferredYDimension

protected java.lang.String m_preferredYDimension

m_preferredColourDimension

protected java.lang.String m_preferredColourDimension

m_showAttBars

protected boolean m_showAttBars
Show the attribute bar panel


m_Log

protected Logger m_Log
the logger

Constructor Detail

VisualizePanel

public VisualizePanel(VisualizePanelListener ls)
This constructor allows a VisualizePanelListener to be set.


VisualizePanel

public VisualizePanel()
Constructor

Method Detail

setLog

public void setLog(Logger newLog)
Sets the Logger to receive informational messages

Parameters:
newLog - the Logger that will now get info messages

setProperties

private void setProperties(java.lang.String relationName)
Set the properties for the VisualizePanel


saveVisibleInstances

private void saveVisibleInstances()
Save the currently visible set of instances to a file


setColourIndex

public void setColourIndex(int index)
Sets the index used for colouring. If this method is called then the supplied index is used and the combo box for selecting colouring attribute is disabled.

Parameters:
index - the index of the attribute to use for colouring

setXIndex

public void setXIndex(int index)
               throws java.lang.Exception
Set the index of the attribute for the x axis

Parameters:
index - the index for the x axis
Throws:
java.lang.Exception - if index is out of range.

getXIndex

public int getXIndex()
Get the index of the attribute on the x axis

Returns:
the index of the attribute on the x axis

setYIndex

public void setYIndex(int index)
               throws java.lang.Exception
Set the index of the attribute for the y axis

Parameters:
index - the index for the y axis
Throws:
java.lang.Exception - if index is out of range.

getYIndex

public int getYIndex()
Get the index of the attribute on the y axis

Returns:
the index of the attribute on the x axis

getCIndex

public int getCIndex()
Get the index of the attribute selected for coloring

Returns:
the index of the attribute on the x axis

getSIndex

public int getSIndex()
Get the index of the shape selected for creating splits.

Returns:
The index of the shape.

setSIndex

public void setSIndex(int index)
               throws java.lang.Exception
Set the shape for creating splits.

Parameters:
index - The index of the shape.
Throws:
java.lang.Exception - if index is out of range.

addActionListener

public void addActionListener(java.awt.event.ActionListener act)
Add a listener for this visualize panel

Parameters:
act - an ActionListener

setName

public void setName(java.lang.String plotName)
Set a name for this plot

Parameters:
plotName - the name for the plot

getName

public java.lang.String getName()
Returns the name associated with this plot. "" is returned if no name is set.

Returns:
the name of the plot

getInstances

public Instances getInstances()
Get the master plot's instances

Returns:
the master plot's instances

newColorAttribute

protected void newColorAttribute(int a,
                                 Instances i)
Sets the Colors in use for a different attrib if it is not a nominal attrib and or does not have more possible values then this will do nothing. otherwise it will add default colors to see that there is a color for the attrib to begin with.

Parameters:
a - The index of the attribute to color.
i - The instances object that contains the attribute.

setShapes

public void setShapes(FastVector l)
This will set the shapes for the instances.

Parameters:
l - A list of the shapes, providing that the objects in the lists are non editable the data will be kept intact.

setInstances

public void setInstances(Instances inst)
Tells the panel to use a new set of instances.

Parameters:
inst - a set of Instances

setUpComboBoxes

public void setUpComboBoxes(Instances inst)

setMasterPlot

public void setMasterPlot(PlotData2D newPlot)
                   throws java.lang.Exception
Set the master plot for the visualize panel

Parameters:
newPlot - the new master plot
Throws:
java.lang.Exception - if the master plot could not be set

addPlot

public void addPlot(PlotData2D newPlot)
             throws java.lang.Exception
Set a new plot to the visualize panel

Parameters:
newPlot - the new plot to add
Throws:
java.lang.Exception - if the plot could not be added

main

public static void main(java.lang.String[] args)
Main method for testing this class