weka.gui
Class CostMatrixEditor

java.lang.Object
  extended byweka.gui.CostMatrixEditor
All Implemented Interfaces:
java.beans.PropertyEditor

public class CostMatrixEditor
extends java.lang.Object
implements java.beans.PropertyEditor

Class for editing CostMatrix objects. Brings up a custom editing panel with which the user can edit the matrix interactively, as well as save load cost matrices from files.

Version:
$Revision: 1.7 $
Author:
Richard Kirkby (rkirkby@cs.waikato.ac.nz)

Nested Class Summary
private  class CostMatrixEditor.CostMatrixTableModel
          This class wraps around the cost matrix presenting it as a TableModel so that it can be displayed and edited in a JTable.
private  class CostMatrixEditor.CustomEditor
          This class presents a GUI for editing the cost matrix, and saving and loading from files.
 
Field Summary
private  CostMatrixEditor.CustomEditor m_customEditor
          An instance of the custom editor
private  javax.swing.JFileChooser m_fileChooser
          The file chooser for the user to select cost files to save and load
private  CostMatrix m_matrix
          The cost matrix being edited
private  java.beans.PropertyChangeSupport m_propSupport
          A helper class for notifying listeners
 
Constructor Summary
CostMatrixEditor()
          Constructs a new CostMatrixEditor.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds an object to the list of those that wish to be informed when the cost matrix changes.
 java.lang.String getAsText()
          Some objects can be represented as text, but a cost matrix cannot.
 java.awt.Component getCustomEditor()
          Gets a GUI component with which the user can edit the cost matrix.
 java.lang.String getJavaInitializationString()
          Returns the Java code that generates an object the same as the one being edited.
 java.lang.String[] getTags()
          Some objects can return tags, but a cost matrix cannot.
 java.lang.Object getValue()
          Gets the cost matrix that is being edited.
 boolean isPaintable()
          Indicates whether the object can be represented graphically.
 void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box)
          Paints a graphical representation of the object.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes an object from the list of those that wish to be informed when the cost matrix changes.
 void setAsText(java.lang.String text)
          Some objects can be represented as text, but a cost matrix cannot.
 void setValue(java.lang.Object value)
          Sets the value of the CostMatrix to be edited.
 boolean supportsCustomEditor()
          Indicates whether the cost matrix can be edited in a GUI, which it can.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_matrix

private CostMatrix m_matrix
The cost matrix being edited


m_propSupport

private java.beans.PropertyChangeSupport m_propSupport
A helper class for notifying listeners


m_customEditor

private CostMatrixEditor.CustomEditor m_customEditor
An instance of the custom editor


m_fileChooser

private javax.swing.JFileChooser m_fileChooser
The file chooser for the user to select cost files to save and load

Constructor Detail

CostMatrixEditor

public CostMatrixEditor()
Constructs a new CostMatrixEditor.

Method Detail

setValue

public void setValue(java.lang.Object value)
Sets the value of the CostMatrix to be edited.

Specified by:
setValue in interface java.beans.PropertyEditor
Parameters:
value - a CostMatrix object to be edited

getValue

public java.lang.Object getValue()
Gets the cost matrix that is being edited.

Specified by:
getValue in interface java.beans.PropertyEditor
Returns:
the edited CostMatrix object

isPaintable

public boolean isPaintable()
Indicates whether the object can be represented graphically. In this case it can.

Specified by:
isPaintable in interface java.beans.PropertyEditor
Returns:
true

paintValue

public void paintValue(java.awt.Graphics gfx,
                       java.awt.Rectangle box)
Paints a graphical representation of the object. For the cost matrix it prints out the text "X x X matrix", where X is the size of the matrix.

Specified by:
paintValue in interface java.beans.PropertyEditor
Parameters:
gfx - the graphics context to draw the representation to
box - the bounds within which the representation should fit.

getJavaInitializationString

public java.lang.String getJavaInitializationString()
Returns the Java code that generates an object the same as the one being edited. Unfortunately this can't be done in a single line of code, so the code returned will only build a default cost matrix of the same size.

Specified by:
getJavaInitializationString in interface java.beans.PropertyEditor
Returns:
the initialization string

getAsText

public java.lang.String getAsText()
Some objects can be represented as text, but a cost matrix cannot.

Specified by:
getAsText in interface java.beans.PropertyEditor
Returns:
null

setAsText

public void setAsText(java.lang.String text)
Some objects can be represented as text, but a cost matrix cannot.

Specified by:
setAsText in interface java.beans.PropertyEditor
Parameters:
text - ignored
Throws:
always - throws an IllegalArgumentException

getTags

public java.lang.String[] getTags()
Some objects can return tags, but a cost matrix cannot.

Specified by:
getTags in interface java.beans.PropertyEditor
Returns:
null

getCustomEditor

public java.awt.Component getCustomEditor()
Gets a GUI component with which the user can edit the cost matrix.

Specified by:
getCustomEditor in interface java.beans.PropertyEditor
Returns:
an editor GUI component

supportsCustomEditor

public boolean supportsCustomEditor()
Indicates whether the cost matrix can be edited in a GUI, which it can.

Specified by:
supportsCustomEditor in interface java.beans.PropertyEditor
Returns:
true

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds an object to the list of those that wish to be informed when the cost matrix changes.

Specified by:
addPropertyChangeListener in interface java.beans.PropertyEditor
Parameters:
listener - a new listener to add to the list

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes an object from the list of those that wish to be informed when the cost matrix changes.

Specified by:
removePropertyChangeListener in interface java.beans.PropertyEditor
Parameters:
listener - the listener to remove from the list