Module java.desktop

Class MetalTreeUI



  • public class MetalTreeUI
    extends BasicTreeUI
    The metal look and feel implementation of TreeUI.

    MetalTreeUI allows for configuring how to visually render the spacing and delineation between nodes. The following hints are supported:

    Descriptions of supported hints: Angled, Horizontal, and None
    Angled A line is drawn connecting the child to the parent. For handling of the root node refer to JTree.setRootVisible(boolean) and JTree.setShowsRootHandles(boolean).
    Horizontal A horizontal line is drawn dividing the children of the root node.
    None Do not draw any visual indication between nodes.

    As it is typically impractical to obtain the TreeUI from the JTree and cast to an instance of MetalTreeUI you enable this property via the client property JTree.lineStyle. For example, to switch to Horizontal style you would do: tree.putClientProperty("JTree.lineStyle", "Horizontal");

    The default is Angled.

    • Constructor Detail

      • MetalTreeUI

        public MetalTreeUI​()
        Constructs the MetalTreeUI.
    • Method Detail

      • createUI

        public static ComponentUI createUI​(JComponent x)
        Constructs the MetalTreeUI.
        Parameters:
        x - a component
        Returns:
        the instance of the MetalTreeUI
      • getHorizontalLegBuffer

        protected int getHorizontalLegBuffer​()
        Description copied from class: BasicTreeUI
        The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default. This method makes the leg end before that.
        Overrides:
        getHorizontalLegBuffer in class BasicTreeUI
        Returns:
        the horizontal leg buffer
      • installUI

        public void installUI​(JComponent c)
        Description copied from class: ComponentUI
        Configures the specified component appropriately for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:
        1. Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
        2. Install a LayoutManager on the component if necessary.
        3. Create/add any required sub-components to the component.
        4. Create/install event listeners on the component.
        5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
        6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
        7. Initialize any appropriate instance data.
        Overrides:
        installUI in class BasicTreeUI
        Parameters:
        c - the component where this UI delegate is being installed
        See Also:
        ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()
      • uninstallUI

        public void uninstallUI​(JComponent c)
        Description copied from class: ComponentUI
        Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:
        1. Remove any UI-set borders from the component.
        2. Remove any UI-set layout managers on the component.
        3. Remove any UI-added sub-components from the component.
        4. Remove any UI-added event/property listeners from the component.
        5. Remove any UI-installed keyboard UI from the component.
        6. Nullify any allocated instance data objects to allow for GC.
        Overrides:
        uninstallUI in class BasicTreeUI
        Parameters:
        c - the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        See Also:
        ComponentUI.installUI(javax.swing.JComponent), JComponent.updateUI()
      • decodeLineStyle

        protected void decodeLineStyle​(Object lineStyleFlag)
        Converts between the string passed into the client property and the internal representation (currently and int)
        Parameters:
        lineStyleFlag - a flag
      • isLocationInExpandControl

        protected boolean isLocationInExpandControl​(int row,
                                                    int rowLevel,
                                                    int mouseX,
                                                    int mouseY)
        Returns true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.
        Parameters:
        row - a row
        rowLevel - a row level
        mouseX - X coordinate
        mouseY - Y coordinate
        Returns:
        true if a point with X coordinate mouseX and Y coordinate mouseY is in expanded control.
      • paint

        public void paint​(Graphics g,
                          JComponent c)
        Description copied from class: ComponentUI
        Paints the specified component appropriately for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.
        Overrides:
        paint in class BasicTreeUI
        Parameters:
        g - the Graphics context in which to paint
        c - the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        See Also:
        ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
      • paintHorizontalSeparators

        protected void paintHorizontalSeparators​(Graphics g,
                                                 JComponent c)
        Paints the horizontal separators.
        Parameters:
        g - an instance of Graphics
        c - a component
      • paintVerticalPartOfLeg

        protected void paintVerticalPartOfLeg​(Graphics g,
                                              Rectangle clipBounds,
                                              Insets insets,
                                              TreePath path)
        Description copied from class: BasicTreeUI
        Paints the vertical part of the leg. The receiver should NOT modify clipBounds, insets.
        Overrides:
        paintVerticalPartOfLeg in class BasicTreeUI
        Parameters:
        g - a graphics context
        clipBounds - a clipped rectangle
        insets - insets
        path - a tree path
      • paintHorizontalPartOfLeg

        protected void paintHorizontalPartOfLeg​(Graphics g,
                                                Rectangle clipBounds,
                                                Insets insets,
                                                Rectangle bounds,
                                                TreePath path,
                                                int row,
                                                boolean isExpanded,
                                                boolean hasBeenExpanded,
                                                boolean isLeaf)
        Description copied from class: BasicTreeUI
        Paints the horizontal part of the leg. The receiver should NOT modify clipBounds, or insets.

        NOTE: parentRow can be -1 if the root is not visible.

        Overrides:
        paintHorizontalPartOfLeg in class BasicTreeUI
        Parameters:
        g - a graphics context
        clipBounds - a clipped rectangle
        insets - insets
        bounds - a bounding rectangle
        path - a tree path
        row - a row
        isExpanded - true if the path is expanded
        hasBeenExpanded - true if the path has been expanded
        isLeaf - true if the path is leaf