javax.swing.plaf.metal
Class MetalRootPaneUI

java.lang.Object
  extended byjavax.swing.plaf.ComponentUI
      extended byjavax.swing.plaf.RootPaneUI
          extended byjavax.swing.plaf.basic.BasicRootPaneUI
              extended byjavax.swing.plaf.metal.MetalRootPaneUI
All Implemented Interfaces:
EventListener, java.beans.PropertyChangeListener

public class MetalRootPaneUI
extends BasicRootPaneUI

Provides the metal look and feel implementation of RootPaneUI.

MetalRootPaneUI provides support for the windowDecorationStyle property of JRootPane. MetalRootPaneUI does this by way of installing a custom LayoutManager, a private Component to render the appropriate widgets, and a private Border. The LayoutManager is always installed, regardless of the value of the windowDecorationStyle property, but the Border and Component are only installed/added if the windowDecorationStyle is other than JRootPane.NONE.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

Since:
1.4
Author:
Terry Kellerman

Nested Class Summary
private static class MetalRootPaneUI.MetalRootLayout
          A custom layout manager that is responsible for the layout of layeredPane, glassPane, menuBar and titlePane, if one has been installed.
private  class MetalRootPaneUI.MouseInputHandler
          MouseInputHandler is responsible for handling resize/moving of the Window.
 
Nested classes inherited from class javax.swing.plaf.basic.BasicRootPaneUI
 
Field Summary
private static int BORDER_DRAG_THICKNESS
          Region from edges that dragging is active from.
private static String[] borderKeys
          Keys to lookup borders in defaults table.
private static int CORNER_DRAG_WIDTH
          The amount of space (in pixels) that the cursor is changed on.
private static int[] cursorMapping
          Maps from positions to cursor type.
private  Cursor lastCursor
          Cursor used to track the cursor set by the user.
private  LayoutManager layoutManager
          The LayoutManager that is set on the JRootPane.
private  MouseInputListener mouseInputListener
          MouseInputListener that is added to the parent Window the JRootPane is contained in.
private  JRootPane root
          JRootPane providing the look and feel for.
private  LayoutManager savedOldLayout
          LayoutManager of the JRootPane before we replaced it.
private  JComponent titlePane
          JComponent providing window decorations.
private  Window window
          Window the JRootPane is in.
 
Fields inherited from class javax.swing.plaf.basic.BasicRootPaneUI
 
Constructor Summary
MetalRootPaneUI()
           
 
Method Summary
private  LayoutManager createLayoutManager()
          Returns a LayoutManager that will be set on the JRootPane.
private  JComponent createTitlePane(JRootPane root)
          Returns the JComponent to render the window decoration style.
static ComponentUI createUI(JComponent c)
          Creates a UI for a JRootPane.
private  MouseInputListener createWindowMouseInputListener(JRootPane root)
          Returns a MouseListener that will be added to the Window containing the JRootPane.
private  JRootPane getRootPane()
          Returns the JRootPane we're providing the look and feel for.
private  JComponent getTitlePane()
          Returns the JComponent rendering the title pane.
(package private)  void installBorder(JRootPane root)
          Installs the appropriate Border onto the JRootPane.
private  void installClientDecorations(JRootPane root)
          Installs the necessary state onto the JRootPane to render client decorations.
private  void installLayout(JRootPane root)
          Installs the appropriate LayoutManager on the JRootPane to render the window decorations.
 void installUI(JComponent c)
          Invokes supers implementation of installUI to install the necessary state onto the passed in JRootPane to render the metal look and feel implementation of RootPaneUI.
private  void installWindowListeners(JRootPane root, Component parent)
          Installs the necessary Listeners on the parent Window, if there is one.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Invoked when a property changes.
private  void setTitlePane(JRootPane root, JComponent titlePane)
          Sets the window title pane -- the JComponent used to provide a plaf a way to override the native operating system's window title pane with one whose look and feel are controlled by the plaf.
private  void uninstallBorder(JRootPane root)
          Removes any border that may have been installed.
private  void uninstallClientDecorations(JRootPane root)
          Uninstalls any state that installClientDecorations has installed.
private  void uninstallLayout(JRootPane root)
          Uninstalls the previously installed LayoutManager.
 void uninstallUI(JComponent c)
          Invokes supers implementation to uninstall any of its state.
private  void uninstallWindowListeners(JRootPane root)
          Uninstalls the necessary Listeners on the Window the Listeners were last installed on.
 
Methods inherited from class javax.swing.plaf.basic.BasicRootPaneUI
installComponents, installDefaults, installKeyboardActions, installListeners, uninstallComponents, uninstallDefaults, uninstallKeyboardActions, uninstallListeners
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, paint, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

borderKeys

private static final String[] borderKeys
Keys to lookup borders in defaults table.


CORNER_DRAG_WIDTH

private static final int CORNER_DRAG_WIDTH
The amount of space (in pixels) that the cursor is changed on.

See Also:
Constant Field Values

BORDER_DRAG_THICKNESS

private static final int BORDER_DRAG_THICKNESS
Region from edges that dragging is active from.

See Also:
Constant Field Values

window

private Window window
Window the JRootPane is in.


titlePane

private JComponent titlePane
JComponent providing window decorations. This will be null if not providing window decorations.


mouseInputListener

private MouseInputListener mouseInputListener
MouseInputListener that is added to the parent Window the JRootPane is contained in.


layoutManager

private LayoutManager layoutManager
The LayoutManager that is set on the JRootPane.


savedOldLayout

private LayoutManager savedOldLayout
LayoutManager of the JRootPane before we replaced it.


root

private JRootPane root
JRootPane providing the look and feel for.


lastCursor

private Cursor lastCursor
Cursor used to track the cursor set by the user. This is initially Cursor.DEFAULT_CURSOR.


cursorMapping

private static final int[] cursorMapping
Maps from positions to cursor type. Refer to calculateCorner and calculatePosition for details of this.

Constructor Detail

MetalRootPaneUI

public MetalRootPaneUI()
Method Detail

createUI

public static ComponentUI createUI(JComponent c)
Creates a UI for a JRootPane.

Parameters:
c - the JRootPane the RootPaneUI will be created for
Returns:
the RootPaneUI implementation for the passed in JRootPane

installUI

public void installUI(JComponent c)
Invokes supers implementation of installUI to install the necessary state onto the passed in JRootPane to render the metal look and feel implementation of RootPaneUI. If the windowDecorationStyle property of the JRootPane is other than JRootPane.NONE, this will add a custom Component to render the widgets to JRootPane, as well as installing a custom Border and LayoutManager on the JRootPane.

Overrides:
installUI in class BasicRootPaneUI
Parameters:
c - the JRootPane to install state onto

uninstallUI

public void uninstallUI(JComponent c)
Invokes supers implementation to uninstall any of its state. This will also reset the LayoutManager of the JRootPane. If a Component has been added to the JRootPane to render the window decoration style, this method will remove it. Similarly, this will revert the Border and LayoutManager of the JRootPane to what it was before installUI was invoked.

Overrides:
uninstallUI in class BasicRootPaneUI
Parameters:
c - the JRootPane to uninstall state from

installBorder

void installBorder(JRootPane root)
Installs the appropriate Border onto the JRootPane.


uninstallBorder

private void uninstallBorder(JRootPane root)
Removes any border that may have been installed.


installWindowListeners

private void installWindowListeners(JRootPane root,
                                    Component parent)
Installs the necessary Listeners on the parent Window, if there is one.

This takes the parent so that cleanup can be done from removeNotify, at which point the parent hasn't been reset yet.

Parameters:
parent - The parent of the JRootPane

uninstallWindowListeners

private void uninstallWindowListeners(JRootPane root)
Uninstalls the necessary Listeners on the Window the Listeners were last installed on.


installLayout

private void installLayout(JRootPane root)
Installs the appropriate LayoutManager on the JRootPane to render the window decorations.


uninstallLayout

private void uninstallLayout(JRootPane root)
Uninstalls the previously installed LayoutManager.


installClientDecorations

private void installClientDecorations(JRootPane root)
Installs the necessary state onto the JRootPane to render client decorations. This is ONLY invoked if the JRootPane has a decoration style other than JRootPane.NONE.


uninstallClientDecorations

private void uninstallClientDecorations(JRootPane root)
Uninstalls any state that installClientDecorations has installed.

NOTE: This may be called if you haven't installed client decorations yet (ie before installClientDecorations has been invoked).


createTitlePane

private JComponent createTitlePane(JRootPane root)
Returns the JComponent to render the window decoration style.


createWindowMouseInputListener

private MouseInputListener createWindowMouseInputListener(JRootPane root)
Returns a MouseListener that will be added to the Window containing the JRootPane.


createLayoutManager

private LayoutManager createLayoutManager()
Returns a LayoutManager that will be set on the JRootPane.


setTitlePane

private void setTitlePane(JRootPane root,
                          JComponent titlePane)
Sets the window title pane -- the JComponent used to provide a plaf a way to override the native operating system's window title pane with one whose look and feel are controlled by the plaf. The plaf creates and sets this value; the default is null, implying a native operating system window title pane.


getTitlePane

private JComponent getTitlePane()
Returns the JComponent rendering the title pane. If this returns null, it implies there is no need to render window decorations.

Returns:
the current window title pane, or null
See Also:
setTitlePane(javax.swing.JRootPane, javax.swing.JComponent)

getRootPane

private JRootPane getRootPane()
Returns the JRootPane we're providing the look and feel for.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Invoked when a property changes. MetalRootPaneUI is primarily interested in events originating from the JRootPane it has been installed on identifying the property windowDecorationStyle. If the windowDecorationStyle has changed to a value other than JRootPane.NONE, this will add a Component to the JRootPane to render the window decorations, as well as installing a Border on the JRootPane. On the other hand, if the windowDecorationStyle has changed to JRootPane.NONE, this will remove the Component that has been added to the JRootPane as well resetting the Border to what it was before installUI was invoked.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class BasicRootPaneUI
Parameters:
e - A PropertyChangeEvent object describing the event source and the property that has changed.