javax.swing.plaf.metal
Class MetalTitlePane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.plaf.metal.MetalTitlePane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

class MetalTitlePane
extends JComponent

Class that manages a JLF awt.Window-descendant class's title bar.

This class assumes it will be created with a particular window decoration style, and that if the style changes, a new one will be created.

Since:
1.4
Author:
Terry Kellerman

Nested Class Summary
private  class MetalTitlePane.CloseAction
          Actions used to close the Window.
private  class MetalTitlePane.IconifyAction
          Actions used to iconfiy the Frame.
private  class MetalTitlePane.MaximizeAction
          Actions used to restore the Frame.
private  class MetalTitlePane.PropertyChangeHandler
          PropertyChangeListener installed on the Window.
private  class MetalTitlePane.RestoreAction
          Actions used to restore the Frame.
private  class MetalTitlePane.SystemMenuBar
          Class responsible for drawing the system menu.
private  class MetalTitlePane.TitlePaneLayout
          This inner class is marked "public" due to a compiler bug.
private  class MetalTitlePane.WindowHandler
          WindowListener installed on the Window, updates the state as necessary.
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  Color activeBackground
           
private  MetalBumps activeBumps
           
private  Color activeBumpsHighlight
           
private  Color activeBumpsShadow
           
private  Color activeForeground
           
private  Color activeShadow
           
private  int buttonsWidth
          Room remaining in title for bumps.
private  Action closeAction
          Action used to close the Window.
private  JButton closeButton
          Button used to maximize or restore the Frame.
private static Border handyEmptyBorder
           
private  Action iconifyAction
          Action used to iconify the Frame.
private  JButton iconifyButton
          Button used to maximize or restore the Frame.
private static int IMAGE_HEIGHT
           
private static int IMAGE_WIDTH
           
private  Color inactiveBackground
           
private  MetalBumps inactiveBumps
           
private  Color inactiveForeground
           
private  Color inactiveShadow
           
private  Action maximizeAction
          Action to restore the Frame size.
private  Icon maximizeIcon
          Icon used for toggleButton when window is normal size.
private  JMenuBar menuBar
          JMenuBar, typically renders the system menu items.
private  Icon minimizeIcon
          Icon used for toggleButton when window is maximized.
private  java.beans.PropertyChangeListener propertyChangeListener
          PropertyChangeListener added to the JRootPane.
private  Action restoreAction
          Action to restore the Frame size.
private  JRootPane rootPane
          JRootPane rendering for.
private  MetalRootPaneUI rootPaneUI
          MetalRootPaneUI that created us.
private  int state
          Buffered Frame.state property.
private  JButton toggleButton
          Button used to maximize or restore the Frame.
private  Window window
          Window we're currently in.
private  WindowListener windowListener
          Listens for changes in the state of the Window listener to update the state of the widgets.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MetalTitlePane(JRootPane root, MetalRootPaneUI ui)
           
 
Method Summary
private  void addMenuItems(JMenu menu)
          Adds the necessary JMenuItems to the passed in menu.
 void addNotify()
          Notifies this component that it now has a parent component.
private  String clippedText(String text, FontMetrics fm, int availTextWidth)
          Convenience method to clip the passed in text to the specified size.
private  void close()
          Closes the Window.
private  void createActions()
          Create the Actions that get associated with the buttons and menu items.
private  void createButtons()
          Creates the Buttons that will be placed on the TitlePane.
private  LayoutManager createLayout()
          Returns the LayoutManager that should be installed on the MetalTitlePane.
private  JMenu createMenu()
          Returns the JMenu displaying the appropriate menu items for manipulating the Frame.
protected  JMenuBar createMenuBar()
          Returns the JMenuBar displaying the appropriate system menu items.
private  JButton createTitleButton()
          Returns a JButton appropriate for placement on the TitlePane.
private  WindowListener createWindowListener()
          Returns the WindowListener to add to the Window.
private  java.beans.PropertyChangeListener createWindowPropertyChangeListener()
          Returns the PropertyChangeListener to install on the Window.
private  void determineColors()
          Determines the Colors to draw with.
private  Frame getFrame()
          Returns the Frame rendering in.
 JRootPane getRootPane()
          Returns the JRootPane this was created for.
private  String getTitle()
          Returns the String to display as the title.
private  Window getWindow()
          Returns the Window the JRootPane is contained in.
private  int getWindowDecorationStyle()
          Returns the decoration style of the JRootPane.
private  void iconify()
          Iconifies the Frame.
private  void installDefaults()
          Installs the fonts and necessary properties on the MetalTitlePane.
private  void installListeners()
          Installs the necessary listeners.
private  void installSubcomponents()
          Adds any sub-Components contained in the MetalTitlePane.
private  void maximize()
          Maximizes the Frame.
 void paintComponent(Graphics g)
          Renders the TitlePane.
 void removeNotify()
          Notifies this component that it no longer has a parent component.
private  void restore()
          Restores the Frame size.
private  void setActive(boolean isActive)
          Updates state dependant upon the Window's active state.
private  void setState(int state)
          Sets the state of the Window.
private  void setState(int state, boolean updateRegardless)
          Sets the state of the window.
private  void uninstall()
          Uninstalls the necessary state.
private  void uninstallDefaults()
          Uninstalls any previously installed UI values.
private  void uninstallListeners()
          Uninstalls the necessary listeners.
private  void updateToggleButton(Action action, Icon icon)
          Updates the toggle button to contain the Icon icon, and Action action.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handyEmptyBorder

private static final Border handyEmptyBorder

IMAGE_HEIGHT

private static final int IMAGE_HEIGHT
See Also:
Constant Field Values

IMAGE_WIDTH

private static final int IMAGE_WIDTH
See Also:
Constant Field Values

propertyChangeListener

private java.beans.PropertyChangeListener propertyChangeListener
PropertyChangeListener added to the JRootPane.


menuBar

private JMenuBar menuBar
JMenuBar, typically renders the system menu items.


closeAction

private Action closeAction
Action used to close the Window.


iconifyAction

private Action iconifyAction
Action used to iconify the Frame.


restoreAction

private Action restoreAction
Action to restore the Frame size.


maximizeAction

private Action maximizeAction
Action to restore the Frame size.


toggleButton

private JButton toggleButton
Button used to maximize or restore the Frame.


iconifyButton

private JButton iconifyButton
Button used to maximize or restore the Frame.


closeButton

private JButton closeButton
Button used to maximize or restore the Frame.


maximizeIcon

private Icon maximizeIcon
Icon used for toggleButton when window is normal size.


minimizeIcon

private Icon minimizeIcon
Icon used for toggleButton when window is maximized.


windowListener

private WindowListener windowListener
Listens for changes in the state of the Window listener to update the state of the widgets.


window

private Window window
Window we're currently in.


rootPane

private JRootPane rootPane
JRootPane rendering for.


buttonsWidth

private int buttonsWidth
Room remaining in title for bumps.


state

private int state
Buffered Frame.state property. As state isn't bound, this is kept to determine when to avoid updating widgets.


rootPaneUI

private MetalRootPaneUI rootPaneUI
MetalRootPaneUI that created us.


inactiveBackground

private Color inactiveBackground

inactiveForeground

private Color inactiveForeground

inactiveShadow

private Color inactiveShadow

activeBumpsHighlight

private Color activeBumpsHighlight

activeBumpsShadow

private Color activeBumpsShadow

activeBackground

private Color activeBackground

activeForeground

private Color activeForeground

activeShadow

private Color activeShadow

activeBumps

private MetalBumps activeBumps

inactiveBumps

private MetalBumps inactiveBumps
Constructor Detail

MetalTitlePane

public MetalTitlePane(JRootPane root,
                      MetalRootPaneUI ui)
Method Detail

uninstall

private void uninstall()
Uninstalls the necessary state.


installListeners

private void installListeners()
Installs the necessary listeners.


uninstallListeners

private void uninstallListeners()
Uninstalls the necessary listeners.


createWindowListener

private WindowListener createWindowListener()
Returns the WindowListener to add to the Window.


createWindowPropertyChangeListener

private java.beans.PropertyChangeListener createWindowPropertyChangeListener()
Returns the PropertyChangeListener to install on the Window.


getRootPane

public JRootPane getRootPane()
Returns the JRootPane this was created for.

Overrides:
getRootPane in class JComponent
Returns:
the JRootPane that contains this component, or null if no JRootPane is found

getWindowDecorationStyle

private int getWindowDecorationStyle()
Returns the decoration style of the JRootPane.


addNotify

public void addNotify()
Description copied from class: JComponent
Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners.

Overrides:
addNotify in class JComponent
See Also:
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

removeNotify

public void removeNotify()
Description copied from class: JComponent
Notifies this component that it no longer has a parent component. When this method is invoked, any KeyboardActions set up in the the chain of parent components are removed.

Overrides:
removeNotify in class JComponent
See Also:
JComponent.registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

installSubcomponents

private void installSubcomponents()
Adds any sub-Components contained in the MetalTitlePane.


determineColors

private void determineColors()
Determines the Colors to draw with.


installDefaults

private void installDefaults()
Installs the fonts and necessary properties on the MetalTitlePane.


uninstallDefaults

private void uninstallDefaults()
Uninstalls any previously installed UI values.


createMenuBar

protected JMenuBar createMenuBar()
Returns the JMenuBar displaying the appropriate system menu items.


close

private void close()
Closes the Window.


iconify

private void iconify()
Iconifies the Frame.


maximize

private void maximize()
Maximizes the Frame.


restore

private void restore()
Restores the Frame size.


createActions

private void createActions()
Create the Actions that get associated with the buttons and menu items.


createMenu

private JMenu createMenu()
Returns the JMenu displaying the appropriate menu items for manipulating the Frame.


addMenuItems

private void addMenuItems(JMenu menu)
Adds the necessary JMenuItems to the passed in menu.


createTitleButton

private JButton createTitleButton()
Returns a JButton appropriate for placement on the TitlePane.


createButtons

private void createButtons()
Creates the Buttons that will be placed on the TitlePane.


createLayout

private LayoutManager createLayout()
Returns the LayoutManager that should be installed on the MetalTitlePane.


setActive

private void setActive(boolean isActive)
Updates state dependant upon the Window's active state.


setState

private void setState(int state)
Sets the state of the Window.


setState

private void setState(int state,
                      boolean updateRegardless)
Sets the state of the window. If updateRegardless is true and the state has not changed, this will update anyway.


updateToggleButton

private void updateToggleButton(Action action,
                                Icon icon)
Updates the toggle button to contain the Icon icon, and Action action.


getFrame

private Frame getFrame()
Returns the Frame rendering in. This will return null if the JRootPane is not contained in a Frame.


getWindow

private Window getWindow()
Returns the Window the JRootPane is contained in. This will return null if there is no parent ancestor of the JRootPane.


getTitle

private String getTitle()
Returns the String to display as the title.


paintComponent

public void paintComponent(Graphics g)
Renders the TitlePane.

Overrides:
paintComponent in class JComponent
Parameters:
g - the Graphics object to protect
See Also:
JComponent.paint(java.awt.Graphics), ComponentUI

clippedText

private String clippedText(String text,
                           FontMetrics fm,
                           int availTextWidth)
Convenience method to clip the passed in text to the specified size.