|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
weka.gui.treevisualizer.TreeVisualizer
Class for displaying a Node structure in Swing.
To work this class simply create an instance of it.
Assign it to a window or other such object.
Resize it to the desired size.
When using the Displayer hold the left mouse button to drag the tree around.
Click the left mouse button with ctrl to shrink the size of the tree by half.
Click and drag with the left mouse button and shift to draw a box, when the left mouse button is released the contents of the box will be magnified to fill the screen.
Click the right mouse button to bring up a menu.
Most options are self explanatory.
Select Auto Scale to set the tree to it's optimal display size.
Nested Class Summary | |
private class |
TreeVisualizer.EdgeInfo
Internal Class for containing display information about an Edge. |
private class |
TreeVisualizer.NodeInfo
Internal Class for containing display information about a Node. |
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 javax.swing.JMenuItem |
m_accept
An option on the win menu. |
private javax.swing.JMenuItem |
m_addChildren
An add children to Node choice, This is only available if the tree display has a treedisplay listerner added to it. |
private javax.swing.JMenuItem |
m_autoScale
An option on the win_menu |
private javax.swing.JRadioButton |
m_caseSen
|
private javax.swing.JMenuItem |
m_classifyChild
Use this to have J48 classify this node. |
private boolean |
m_clickAvailable
A variable used to determine for the clicked method if any other mouse state has already taken place. |
private java.awt.Font |
m_currentFont
The font used to display the tree. |
private TreeVisualizer.EdgeInfo[] |
m_edges
An array with the Edges sorted into it and display information about the Edges. |
private javax.swing.JMenuItem |
m_fitToScreen
An option on the win_menu |
private int |
m_focusNode
The subscript for the currently selected node (this is an internal thing, so the user is unaware of this). |
private java.awt.FontMetrics |
m_fontSize
The size information for the current font. |
private javax.swing.Timer |
m_frameLimiter
A timer to keep the frame rate constant. |
private int |
m_highlightNode
The Node the user is currently focused on , this is similar to focus node except that it is used by other classes rather than this one. |
private TreeDisplayListener |
m_listener
|
private int |
m_mouseState
Describes the action the user is performing. |
private java.awt.Dimension |
m_newMousePos
A variable used to tag the most current point of a user action. |
private javax.swing.JPopupMenu |
m_nodeMenu
A right or middle click popup menu for nodes. |
private TreeVisualizer.NodeInfo[] |
m_nodes
An array with the Nodes sorted into it and display information about the Nodes. |
private int |
m_numLevels
The number of levels in the tree. |
private int |
m_numNodes
The number of Nodes in the tree. |
private java.awt.Dimension |
m_nViewPos
A variable used to remember the desired view pos. |
private java.awt.Dimension |
m_nViewSize
A variable used to remember the desired tree size. |
private java.awt.Dimension |
m_oldMousePos
A variable used to tag the start pos of a user action. |
private NodePlace |
m_placer
The placement algorithm for the Node structure. |
private javax.swing.JMenuItem |
m_remChildren
Similar to add children but now it removes children. |
private int |
m_scaling
The number of frames left to calculate. |
private javax.swing.JTextField |
m_searchString
|
private javax.swing.JDialog |
m_searchWin
|
private javax.swing.JMenu |
m_selectFont
A ub group on the win_menu |
private javax.swing.ButtonGroup |
m_selectFontGroup
A grouping for the font choices |
private javax.swing.JMenuItem |
m_sendInstances
Use this to dump the instances from this node to the vis panel. |
private javax.swing.JRadioButtonMenuItem |
m_size1
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size10
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size12
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size14
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size16
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size18
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size2
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size20
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size22
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size24
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size4
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size6
A font choice. |
private javax.swing.JRadioButtonMenuItem |
m_size8
A font choice. |
private javax.swing.JMenuItem |
m_topN
An option on the win_menu |
private Node |
m_topNode
The top Node. |
private java.awt.Dimension |
m_viewPos
The postion of the view relative to the tree. |
private java.awt.Dimension |
m_viewSize
The size of the tree in pixels. |
private javax.swing.JMenuItem |
m_visualise
A visualize choice for the node, may not be available. |
private javax.swing.JPopupMenu |
m_winMenu
A right (or middle) click popup menu. |
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 | |
TreeVisualizer(TreeDisplayListener tdl,
Node n,
NodePlace p)
Constructs Displayer with the specified Node as the top of the tree, and uses the NodePlacer to place the Nodes. |
|
TreeVisualizer(TreeDisplayListener tdl,
java.lang.String dot,
NodePlace p)
Constructs Displayer to display a tree provided in a dot format. |
Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent e)
Performs the action associated with the ActionEvent. |
private void |
animateScaling(java.awt.Dimension n_pos,
java.awt.Dimension n_size,
int frames)
This will increment the size and position of the tree towards the desired size and position a little (depending on the value of frames) everytime it is called. |
private void |
arrayFill(Node t,
TreeVisualizer.NodeInfo[] l,
TreeVisualizer.EdgeInfo[] k)
This will fill two arrays with the Nodes and Edges from the tree into a particular order. |
private void |
autoScale()
This Calculates the minimum size of the tree which will prevent any text overlapping and make it readable, and then set the size of the tree to this. |
private void |
calcScreenCoords(int n)
Converts the internal coordinates of the node found from n and converts them to the actual screen coordinates. |
private void |
changeFontSize(int s)
This will change the font size for displaying the tree to the one specified. |
private void |
drawLine(int e,
java.awt.Graphics g)
Determines the attributes of the edge and draws it. |
private void |
drawNode(int n,
java.awt.Graphics g)
Determines the attributes of the node and draws it. |
private void |
drawText(int x1,
int y1,
int s,
boolean e_or_n,
java.awt.Graphics g)
Draws the text for either an Edge or a Node. |
void |
fitToScreen()
Fits the tree to the current screen size. |
private void |
getScreenFit(java.awt.Dimension np,
java.awt.Dimension ns)
Calculates the dimensions needed to fit the entire tree into view. |
void |
itemStateChanged(java.awt.event.ItemEvent e)
Performs the action associated with the ItemEvent. |
static void |
main(java.lang.String[] args)
Main method for testing this class. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Does nothing. |
void |
mouseDragged(java.awt.event.MouseEvent e)
Performs intermediate updates to what the user wishes to do. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Does nothing. |
void |
mouseExited(java.awt.event.MouseEvent e)
Does nothing. |
private boolean |
mouseInBounds(java.awt.event.MouseEvent e)
Checks to see if the coordinates of the mouse lie on this JPanel. |
void |
mouseMoved(java.awt.event.MouseEvent e)
Does nothing. |
void |
mousePressed(java.awt.event.MouseEvent e)
Determines what action the user wants to perform. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Performs the final stages of what the user wants to perform. |
void |
paintComponent(java.awt.Graphics g)
Updates the screen contents. |
private void |
painter(java.awt.Graphics g)
Draws the tree to the graphics context |
void |
setHighlight(java.lang.String id)
Set the highlight for the node with the given id |
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, 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, 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 |
Field Detail |
private NodePlace m_placer
private Node m_topNode
private java.awt.Dimension m_viewPos
private java.awt.Dimension m_viewSize
private java.awt.Font m_currentFont
private java.awt.FontMetrics m_fontSize
private int m_numNodes
private int m_numLevels
private TreeVisualizer.NodeInfo[] m_nodes
private TreeVisualizer.EdgeInfo[] m_edges
private javax.swing.Timer m_frameLimiter
private int m_mouseState
private java.awt.Dimension m_oldMousePos
private java.awt.Dimension m_newMousePos
private boolean m_clickAvailable
private java.awt.Dimension m_nViewPos
private java.awt.Dimension m_nViewSize
private int m_scaling
private javax.swing.JPopupMenu m_winMenu
private javax.swing.JMenuItem m_topN
private javax.swing.JMenuItem m_fitToScreen
private javax.swing.JMenuItem m_autoScale
private javax.swing.JMenu m_selectFont
private javax.swing.ButtonGroup m_selectFontGroup
private javax.swing.JRadioButtonMenuItem m_size24
private javax.swing.JRadioButtonMenuItem m_size22
private javax.swing.JRadioButtonMenuItem m_size20
private javax.swing.JRadioButtonMenuItem m_size18
private javax.swing.JRadioButtonMenuItem m_size16
private javax.swing.JRadioButtonMenuItem m_size14
private javax.swing.JRadioButtonMenuItem m_size12
private javax.swing.JRadioButtonMenuItem m_size10
private javax.swing.JRadioButtonMenuItem m_size8
private javax.swing.JRadioButtonMenuItem m_size6
private javax.swing.JRadioButtonMenuItem m_size4
private javax.swing.JRadioButtonMenuItem m_size2
private javax.swing.JRadioButtonMenuItem m_size1
private javax.swing.JMenuItem m_accept
private javax.swing.JPopupMenu m_nodeMenu
private javax.swing.JMenuItem m_visualise
private javax.swing.JMenuItem m_addChildren
private javax.swing.JMenuItem m_remChildren
private javax.swing.JMenuItem m_classifyChild
private javax.swing.JMenuItem m_sendInstances
private int m_focusNode
private int m_highlightNode
private TreeDisplayListener m_listener
private javax.swing.JTextField m_searchString
private javax.swing.JDialog m_searchWin
private javax.swing.JRadioButton m_caseSen
Constructor Detail |
public TreeVisualizer(TreeDisplayListener tdl, java.lang.String dot, NodePlace p)
tdl
- listenerdot
- string containing the dot representation of the tree to
displayp
- the algorithm to be used to position the nodes.public TreeVisualizer(TreeDisplayListener tdl, Node n, NodePlace p)
tdl
- listener.n
- the top Node of the tree to be displayed.p
- the algorithm to be used to position the nodes.Method Detail |
public void fitToScreen()
private void getScreenFit(java.awt.Dimension np, java.awt.Dimension ns)
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
e
- the action event.public void itemStateChanged(java.awt.event.ItemEvent e)
itemStateChanged
in interface java.awt.event.ItemListener
e
- the item event.public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
e
- the mouse event.public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
e
- the mouse event.public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
e
- the mouse event.private boolean mouseInBounds(java.awt.event.MouseEvent e)
e
- the mouse event.
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
e
- the mouse event.public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
e
- the mouse event.public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
e
- the mouse event.public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
e
- the mouse event.public void setHighlight(java.lang.String id)
id
- the id of the node to set the highlight forpublic void paintComponent(java.awt.Graphics g)
g
- the drawing surface.private void painter(java.awt.Graphics g)
g
- the drawing surface.private void drawNode(int n, java.awt.Graphics g)
n
- A subscript identifying the node in nodes arrayg
- The drawing surfaceprivate void drawLine(int e, java.awt.Graphics g)
e
- A subscript identifying the edge in edges array.g
- The drawing surface.private void drawText(int x1, int y1, int s, boolean e_or_n, java.awt.Graphics g)
x1
- the left side of the text area.y1
- the top of the text area.s
- A subscript identifying either a Node or Edge.e_or_n
- Distinguishes whether it is a node or edge.g
- The drawing surface.private void calcScreenCoords(int n)
n
- A subscript identifying the Node.private void autoScale()
private void animateScaling(java.awt.Dimension n_pos, java.awt.Dimension n_size, int frames)
n_pos
- The final position of the tree wanted.n_size
- The final size of the tree wanted.frames
- The number of frames that shall occur before the final
size and pos is reached.private void changeFontSize(int s)
s
- The new pointsize of the font.private void arrayFill(Node t, TreeVisualizer.NodeInfo[] l, TreeVisualizer.EdgeInfo[] k)
t
- The top Node of the tree.l
- An array that has already been allocated, to be filled.k
- An array that has already been allocated, to be filled.public static void main(java.lang.String[] args)
args
- first argument should be the name of a file that contains
a tree discription in dot format.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |