Class TreeMap<N>

Type Parameters:
N - the type of node the backing weighted tree model uses.
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class TreeMap<N> extends JPanel
Tree map UI widget. It displays information represented in a IWeightedTreeModel as a tree map and supports navigation inside of the model.
See Also:
  • Field Details

  • Constructor Details

    • TreeMap

      public TreeMap()
      Create the tree map (supporting navigation).
    • TreeMap

      public TreeMap(boolean supportNavigation)
      Creates the tree map.
      Parameters:
      supportNavigation - true if navigation through left/right mouse clicks is supported, false otherwise.
    • TreeMap

      public TreeMap(boolean supportNavigation, boolean changeCursorOnRecalculate)
      Creates the tree map.
      Parameters:
      supportNavigation - true if navigation through left/right mouse clicks is supported, false otherwise.
      changeCursorOnRecalculate - indicates whether the mouse cursor should be changed to Cursor.WAIT_CURSOR during recalculation.
  • Method Details

    • setRectangleRenderer

      public void setRectangleRenderer(IRectangleRenderer<N,Graphics2D,Color> aRenderer)
      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 be null.
    • getRectangleRenderer

      public IRectangleRenderer<N,Graphics2D,Color> getRectangleRenderer()
      Returns the rectangle renderer used by the tree map.
      Returns:
      the rectangle renderer used by the tree map.
    • setLabelProvider

      public void setLabelProvider(ILabelProvider<N> aProvider)
      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 be null.
    • getLabelProvider

      public ILabelProvider<N> getLabelProvider()
      Returns the currently active label provider of this tree map.
      Returns:
      the currently active label provider of this tree map.
    • setColorProvider

      public void setColorProvider(IColorProvider<N,Color> aProvider)
      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 be null.
    • getColorProvider

      public IColorProvider<N,Color> 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 the IColorProvider have changed. This does not recompute the rectangles.
    • setTreeModel

      public void setTreeModel(IWeightedTreeModel<N> aModel)
      Sets the model to use in this tree map.
      Parameters:
      aModel - the model to use; must not be null.
    • setTreeModel

      public <T extends Number> void setTreeModel(IGenericWeightedTreeModel<N,T> aModel)
      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 be null.
    • getTreeModel

      public IWeightedTreeModel<N> getTreeModel()
      Deprecated.
      use getCurrentTreeModel() 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

      public ITreeModel<N> 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

      public void addSelectionChangeListener(ISelectionChangeListener<N> aListener)
      Adds the given listener for selection change events.
      Parameters:
      aListener - the listener to add, must not be null and must not already have been added.
    • removeSelectionChangeListener

      public void removeSelectionChangeListener(ISelectionChangeListener<N> aListener)
      Removes the given change event listener.
      Parameters:
      aListener - the listener to remove
    • setTreeMapLayout

      public void setTreeMapLayout(ITreeMapLayout<N> aLayout)
      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 be null
    • paintComponent

      public void paintComponent(Graphics gr)
      Overrides:
      paintComponent in class JComponent
    • drawBusy

      protected void drawBusy(Graphics2D gr)
      Called when the tree map is busy during rendering.
      Parameters:
      gr - the graphics object used for rendering.
    • render

      protected void render(Graphics2D g, ITreeModel<IRectangle<N>> rects)
      Renders the rectangles of the tree map.
      Parameters:
      g - the graphics to draw on
      rects - the rectangles to render
    • render

      protected void render(Graphics2D g, ITreeModel<IRectangle<N>> rects, IRectangle<N> rect)
    • 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 coordinate
      y - y coordinate
      Returns:
      true if the selection changed, false otherwise.
    • findRectangle

      protected IRectangle<N> findRectangle(int x, int y)
      Find the smallest rectangle in the model containing the given coordinates.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      a rectangle of the current rectangle tree, or null if no rectangle can be found.
    • recalculate

      protected void recalculate()
      Recalculates the rectangle tree model and internal image in a separated thread.
    • rebuildImage

      protected BufferedImage rebuildImage(int width, int height, ITreeModel<IRectangle<N>> rects)
      Rebuilds the image buffer used for rendering the tree map quickly.
      Parameters:
      width - the new width
      height - the new height
      rects - the rectangle model to use for rendering into the buffer
      Returns:
      the render result.