FileDocCategorySizeDatePackage
MetalRootPaneUI.javaAPI DocJava SE 6 API36444Tue Jun 10 00:26:50 BST 2008javax.swing.plaf.metal

MetalRootPaneUI

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 {@link java.beans.XMLEncoder}.

version
1.23 01/30/06
author
Terry Kellerman
since
1.4

Fields Summary
private static final String[]
borderKeys
Keys to lookup borders in defaults table.
private static final int
CORNER_DRAG_WIDTH
The amount of space (in pixels) that the cursor is changed on.
private static final int
BORDER_DRAG_THICKNESS
Region from edges that dragging is active from.
private Window
window
Window the JRootPane is in.
private JComponent
titlePane
JComponent providing window decorations. This will be null if not providing window decorations.
private MouseInputListener
mouseInputListener
MouseInputListener that is added to the parent Window the JRootPane is contained in.
private LayoutManager
layoutManager
The LayoutManager that is set on the JRootPane.
private LayoutManager
savedOldLayout
LayoutManager of the JRootPane before we replaced it.
private JRootPane
root
JRootPane providing the look and feel for.
private Cursor
lastCursor
Cursor used to track the cursor set by the user. This is initially Cursor.DEFAULT_CURSOR.
private static final int[]
cursorMapping
Maps from positions to cursor type. Refer to calculateCorner and calculatePosition for details of this.
Constructors Summary
Methods Summary
private java.awt.LayoutManagercreateLayoutManager()
Returns a LayoutManager that will be set on the JRootPane.

        return new MetalRootLayout();
    
private javax.swing.event.MouseInputListenercreateMouseInputListener(javax.swing.JRootPane root)
Returns a MouseListener that will be added to the JRootPane and title pane.

        return new MouseInputHandler();
    
private javax.swing.JComponentcreateTitlePane(javax.swing.JRootPane root)
Returns the JComponent to render the window decoration style.

        return new MetalTitlePane(root, this);
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)
Creates a UI for a JRootPane.

param
c the JRootPane the RootPaneUI will be created for
return
the RootPaneUI implementation for the passed in JRootPane


                                  
         
        return new MetalRootPaneUI();
    
private javax.swing.JRootPanegetRootPane()
Returns the JRootPane we're providing the look and feel for.

        return root;
    
private javax.swing.JComponentgetTitlePane()
Returns the JComponent rendering the title pane. If this returns null, it implies there is no need to render window decorations.

return
the current window title pane, or null
see
#setTitlePane

        return titlePane;
    
voidinstallBorder(javax.swing.JRootPane root)
Installs the appropriate Border onto the JRootPane.

        int style = root.getWindowDecorationStyle();

        if (style == JRootPane.NONE) {
            LookAndFeel.uninstallBorder(root);
        }
        else {
            LookAndFeel.installBorder(root, borderKeys[style]);
        }
    
private voidinstallClientDecorationListeners(javax.swing.JRootPane root)
Installs the necessary Listeners for client decorations.

        window = SwingUtilities.getWindowAncestor(root);
        if (window != null) {
            if (mouseInputListener == null) {
                mouseInputListener = createMouseInputListener(root);
            }
            root.addMouseListener(mouseInputListener);
            root.addMouseMotionListener(mouseInputListener);
            titlePane.addMouseListener(mouseInputListener);
            titlePane.addMouseMotionListener(mouseInputListener);
        }
    
private voidinstallClientDecorations(javax.swing.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.

        installBorder(root);

        JComponent titlePane = createTitlePane(root);

        setTitlePane(root, titlePane);
        installClientDecorationListeners(root);
        installLayout(root);
        if (window != null) {
            root.revalidate();
            root.repaint();
        }
    
private voidinstallLayout(javax.swing.JRootPane root)
Installs the appropriate LayoutManager on the JRootPane to render the window decorations.

        if (layoutManager == null) {
            layoutManager = createLayoutManager();
        }
        savedOldLayout = root.getLayout();
        root.setLayout(layoutManager);
    
public voidinstallUI(javax.swing.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.

param
c the JRootPane to install state onto

 
        super.installUI(c);
        root = (JRootPane)c;
        int style = root.getWindowDecorationStyle();
        if (style != JRootPane.NONE) {
            installClientDecorations(root);
        }
    
public voidpropertyChange(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.

param
e A PropertyChangeEvent object describing the event source and the property that has changed.

        super.propertyChange(e);
        
        String propertyName = e.getPropertyName();
        if(propertyName == null) {
            return;
        }
    
        if(propertyName.equals("windowDecorationStyle")) {
            JRootPane root = (JRootPane) e.getSource();
            int style = root.getWindowDecorationStyle();

            // This is potentially more than needs to be done,
            // but it rarely happens and makes the install/uninstall process
            // simpler. MetalTitlePane also assumes it will be recreated if
            // the decoration style changes.
            uninstallClientDecorations(root);
            if (style != JRootPane.NONE) {
                installClientDecorations(root);
            }
        }
        else if (propertyName.equals("ancestor")) {
            uninstallClientDecorationListeners(root);
            if (((JRootPane)e.getSource()).getWindowDecorationStyle() !=
                                           JRootPane.NONE) {
                installClientDecorationListeners(root);
            }
        }
        return;
    
private voidsetTitlePane(javax.swing.JRootPane root, javax.swing.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.

param
content the JComponent to use for the window title pane.

        JLayeredPane layeredPane = root.getLayeredPane();
        JComponent oldTitlePane = getTitlePane();

        if (oldTitlePane != null) {
            oldTitlePane.setVisible(false);
            layeredPane.remove(oldTitlePane);
        }
        if (titlePane != null) {
            layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
            titlePane.setVisible(true);
        }
        this.titlePane = titlePane;
    
private voiduninstallBorder(javax.swing.JRootPane root)
Removes any border that may have been installed.

        LookAndFeel.uninstallBorder(root);
    
private voiduninstallClientDecorationListeners(javax.swing.JRootPane root)
Uninstalls the necessary Listeners for client decorations. This may be invoked without a corresponding installClientDecorationListeners.

        if (window != null) {
            root.removeMouseListener(mouseInputListener);
            root.removeMouseMotionListener(mouseInputListener);
            if (titlePane != null) {
                titlePane.removeMouseListener(mouseInputListener);
                titlePane.removeMouseMotionListener(mouseInputListener);
            }
        }
    
private voiduninstallClientDecorations(javax.swing.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).

        uninstallBorder(root);
        uninstallClientDecorationListeners(root);
        setTitlePane(root, null);
        uninstallLayout(root);
	// We have to revalidate/repaint root if the style is JRootPane.NONE
	// only. When we needs to call revalidate/repaint with other styles
	// the installClientDecorations is always called after this method
	// imediatly and it will cause the revalidate/repaint at the proper
	// time.
        int style = root.getWindowDecorationStyle();
        if (style == JRootPane.NONE) {
	    root.repaint();
	    root.revalidate();
	}
        // Reset the cursor, as we may have changed it to a resize cursor
        if (window != null) {
            window.setCursor(Cursor.getPredefinedCursor
                             (Cursor.DEFAULT_CURSOR));
        }
        window = null;
    
private voiduninstallLayout(javax.swing.JRootPane root)
Uninstalls the previously installed LayoutManager.

        if (savedOldLayout != null) {
            root.setLayout(savedOldLayout);
            savedOldLayout = null;
        }
    
public voiduninstallUI(javax.swing.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.

param
c the JRootPane to uninstall state from

        super.uninstallUI(c);
        uninstallClientDecorations(root);

        layoutManager = null;
        mouseInputListener = null;
        root = null;