Class TreeMap<N>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
de.engehausen.treemap.swing.TreeMap<N>
- Type Parameters:
N- the type of node the backing weighted tree model uses.
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
Tree map UI widget. It displays information represented in a
IWeightedTreeModel
as a tree map and supports navigation inside of the model.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BuildControlprotected booleanIndicates whether the mouse cursor should be changed toCursor.WAIT_CURSORduring recalculation.protected IColorProvider<N, Color> protected Nprotected GraphicsConfigurationprotected BufferedImageprotected ILabelProvider<N> protected ITreeMapLayout<N> protected List<ISelectionChangeListener<N>> protected ITreeModel<N> protected ITreeModel<IRectangle<N>> protected IRectangleRenderer<N, Graphics2D, Color> protected IRectangle<N> Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSelectionChangeListener(ISelectionChangeListener<N> aListener) Adds the given listener for selection change events.protected voiddrawBusy(Graphics2D gr) Called when the tree map is busy during rendering.protected IRectangle<N> findRectangle(int x, int y) Find the smallest rectangle in the model containing the given coordinates.Returns the color provider the tree map uses.Returns the model currently being used by the tree map.Returns the currently active label provider of this tree map.Returns the rectangle renderer used by the tree map.Deprecated.voidprotected BufferedImagerebuildImage(int width, int height, ITreeModel<IRectangle<N>> rects) Rebuilds the image buffer used for rendering the tree map quickly.protected voidRecalculates the rectangle tree model and internal image in a separated thread.voidrefresh()Force a refresh of the paint buffer; this may be needed if the colors provided by theIColorProviderhave changed.voidremoveSelectionChangeListener(ISelectionChangeListener<N> aListener) Removes the given change event listener.protected voidrender(Graphics2D g, ITreeModel<IRectangle<N>> rects) Renders the rectangles of the tree map.protected voidrender(Graphics2D g, ITreeModel<IRectangle<N>> rects, IRectangle<N> rect) protected booleanselectRectangle(int x, int y) Try to select a rectangle at the given coordinates (which are relative to the widget).voidsetColorProvider(IColorProvider<N, Color> aProvider) Sets the color provider the tree map will use during rendering.voidsetLabelProvider(ILabelProvider<N> aProvider) Sets the label provider the tree map will use during rendering.voidsetRectangleRenderer(IRectangleRenderer<N, Graphics2D, Color> aRenderer) Sets the rectangle renderer the tree map will use.voidsetTreeMapLayout(ITreeMapLayout<N> aLayout) Sets the layout for the tree map.<T extends Number>
voidsetTreeModel(IGenericWeightedTreeModel<N, T> aModel) Sets the model to use in this tree map.voidsetTreeModel(IWeightedTreeModel<N> aModel) Sets the model to use in this tree map.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods 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, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
model
-
layout
-
rectangles
-
selected
-
currentRoot
-
image
-
buildControl
-
renderer
-
labelProvider
-
colorProvider
-
listeners
-
gc
-
changeCursorOnRecalculate
protected boolean changeCursorOnRecalculateIndicates whether the mouse cursor should be changed toCursor.WAIT_CURSORduring recalculation.
-
-
Constructor Details
-
TreeMap
public TreeMap()Create the tree map (supporting navigation). -
TreeMap
public TreeMap(boolean supportNavigation) Creates the tree map.- Parameters:
supportNavigation-trueif navigation through left/right mouse clicks is supported,falseotherwise.
-
TreeMap
public TreeMap(boolean supportNavigation, boolean changeCursorOnRecalculate) Creates the tree map.- Parameters:
supportNavigation-trueif navigation through left/right mouse clicks is supported,falseotherwise.changeCursorOnRecalculate- indicates whether the mouse cursor should be changed toCursor.WAIT_CURSORduring recalculation.
-
-
Method Details
-
setRectangleRenderer
Sets the rectangle renderer the tree map will use. If no renderer is set, a default will be used.- Parameters:
aRenderer- the rectangle renderer, must not benull.
-
getRectangleRenderer
Returns the rectangle renderer used by the tree map.- Returns:
- the rectangle renderer used by the tree map.
-
setLabelProvider
Sets the label provider the tree map will use during rendering. If no provider is set no labels are displayed.- Parameters:
aProvider- the label provider; may benull.
-
getLabelProvider
Returns the currently active label provider of this tree map.- Returns:
- the currently active label provider of this tree map.
-
setColorProvider
Sets the color provider the tree map will use during rendering. If no provider is set a default will be used.- Parameters:
aProvider- the color provider; may benull.
-
getColorProvider
Returns the color provider the tree map uses.- Returns:
- the color provider the tree map uses.
-
refresh
public void refresh()Force a refresh of the paint buffer; this may be needed if the colors provided by theIColorProviderhave changed. This does not recompute the rectangles. -
setTreeModel
Sets the model to use in this tree map.- Parameters:
aModel- the model to use; must not benull.
-
setTreeModel
Sets the model to use in this tree map.- Type Parameters:
T- the number type of the weights- Parameters:
aModel- the model to use; must not benull.
-
getTreeModel
Deprecated.usegetCurrentTreeModel()instead Returns the model currently being used by the tree map.- Returns:
- the model currently being used by the tree map, may be
null.
-
getCurrentTreeModel
Returns the model currently being used by the tree map.- Returns:
- the model currently being used by the tree map, may be
null.
-
addSelectionChangeListener
Adds the given listener for selection change events.- Parameters:
aListener- the listener to add, must not benulland must not already have been added.
-
removeSelectionChangeListener
Removes the given change event listener.- Parameters:
aListener- the listener to remove
-
setTreeMapLayout
Sets the layout for the tree map. If this method is not called, a default squarified layout with maximum nesting level two is used- Parameters:
aLayout- the layout to use, must not benull
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
drawBusy
Called when the tree map is busy during rendering.- Parameters:
gr- the graphics object used for rendering.
-
render
Renders the rectangles of the tree map.- Parameters:
g- the graphics to draw onrects- the rectangles to render
-
render
-
selectRectangle
protected boolean selectRectangle(int x, int y) Try to select a rectangle at the given coordinates (which are relative to the widget).- Parameters:
x- x coordinatey- y coordinate- Returns:
trueif the selection changed,falseotherwise.
-
findRectangle
Find the smallest rectangle in the model containing the given coordinates.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- a rectangle of the current rectangle tree, or
nullif no rectangle can be found.
-
recalculate
protected void recalculate()Recalculates the rectangle tree model and internal image in a separated thread. -
rebuildImage
Rebuilds the image buffer used for rendering the tree map quickly.- Parameters:
width- the new widthheight- the new heightrects- the rectangle model to use for rendering into the buffer- Returns:
- the render result.
-
getCurrentTreeModel()instead Returns the model currently being used by the tree map.