org.jhotdraw.gui.plaf.palette
Class PaletteToolBarUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.ToolBarUI
          extended by org.jhotdraw.gui.plaf.palette.PaletteToolBarUI
All Implemented Interfaces:
javax.swing.SwingConstants

public class PaletteToolBarUI
extends javax.swing.plaf.ToolBarUI
implements javax.swing.SwingConstants

ToolBarUI for palette components.

This UI differs from BasicToolBarUI, in that the component holding the toolbar is supposed to use BoxLayout instead of BorderLayout. This allows to have multiple toolbars in the same component. The toolbars can be reorderd in the component, but they are not allowed to float in their own floating window.

The JToolBar starts dragging only, if the drag starts over the insets of its border.

Author:
Werner Randelshofer  @version $Id: PaletteToolBarUI.java 527 2009-06-07 14:28:19Z rawcoder $

Nested Class Summary
private static class PaletteToolBarUI.Actions
           
 class PaletteToolBarUI.DockingListener
          This class should be treated as a "protected" inner class.
protected  class PaletteToolBarUI.DragWindow
           
protected  class PaletteToolBarUI.FrameListener
           
private  class PaletteToolBarUI.Handler
           
protected  class PaletteToolBarUI.PropertyListener
           
protected  class PaletteToolBarUI.ToolBarContListener
           
protected  class PaletteToolBarUI.ToolBarFocusListener
           
 
Field Summary
private  java.util.HashMap<javax.swing.AbstractButton,javax.swing.border.Border> borderTable
           
protected  java.lang.Integer constraintBeforeFloating
           
protected  java.awt.Color dockingBorderColor
           
protected  java.awt.Color dockingColor
           
protected  javax.swing.event.MouseInputListener dockingListener
           
private  int dockingSensitivity
           
private  java.awt.Container dockingSource
           
protected  javax.swing.KeyStroke downKey
          Deprecated. As of Java 2 platform v1.3.
protected  PaletteToolBarUI.DragWindow dragWindow
           
private  boolean floating
           
protected  java.awt.Color floatingBorderColor
           
protected  java.awt.Color floatingColor
           
private  javax.swing.JFrame floatingFrame
           
private  javax.swing.RootPaneContainer floatingToolBar
           
private  int floatingX
           
private  int floatingY
           
private static java.lang.String FOCUSED_COMP_INDEX
           
protected  int focusedCompIndex
           
private  PaletteToolBarUI.Handler handler
           
(package private) static java.lang.String IS_DIVIDER_DRAWN
           
private static java.lang.String IS_ROLLOVER
           
private static boolean isFloatingAllowed
           
protected  javax.swing.KeyStroke leftKey
          Deprecated. As of Java 2 platform v1.3.
private static javax.swing.border.Border nonRolloverBorder
           
private static javax.swing.border.Border nonRolloverToggleBorder
           
protected  java.beans.PropertyChangeListener propertyListener
           
protected  javax.swing.KeyStroke rightKey
          Deprecated. As of Java 2 platform v1.3.
private static javax.swing.border.Border rolloverBorder
           
private  boolean rolloverBorders
           
private  java.util.Hashtable<javax.swing.AbstractButton,java.lang.Boolean> rolloverTable
           
protected  javax.swing.JToolBar toolBar
           
static java.lang.String TOOLBAR_ICON_PROPERTY
           
static java.lang.String TOOLBAR_INSETS_OVERRIDE_PROPERTY
           
static java.lang.String TOOLBAR_TEXT_ICON_GAP_PROPERTY
           
protected  java.awt.event.ContainerListener toolBarContListener
           
protected  java.awt.event.FocusListener toolBarFocusListener
           
protected  javax.swing.KeyStroke upKey
          Deprecated. As of Java 2 platform v1.3.
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
PaletteToolBarUI()
           
 
Method Summary
private  java.lang.Integer calculateConstraint()
           
 boolean canDock(java.awt.Component c, java.awt.Point p)
           
protected  javax.swing.event.MouseInputListener createDockingListener()
           
protected  PaletteToolBarUI.DragWindow createDragWindow(javax.swing.JToolBar toolbar)
           
protected  javax.swing.JFrame createFloatingFrame(javax.swing.JToolBar toolbar)
          No longer used, use PaletteToolBarUI.createFloatingWindow(JToolBar)
protected  javax.swing.RootPaneContainer createFloatingWindow(javax.swing.JToolBar toolbar)
          Creates a window which contains the toolbar after it has been dragged out from its container
protected  java.awt.event.WindowListener createFrameListener()
           
protected  javax.swing.border.Border createNonRolloverBorder()
          Creates the non rollover border for toolbar components.
private  javax.swing.border.Border createNonRolloverToggleBorder()
          Creates a non rollover border for Toggle buttons in the toolbar.
protected  java.beans.PropertyChangeListener createPropertyListener()
           
protected  javax.swing.border.Border createRolloverBorder()
          Creates a rollover border for toolbar components.
protected  java.awt.event.ContainerListener createToolBarContListener()
           
protected  java.awt.event.FocusListener createToolBarFocusListener()
           
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
           
protected  void dragTo(java.awt.Point position, java.awt.Point origin)
           
protected  void floatAt(java.awt.Point position, java.awt.Point origin)
           
 java.awt.Color getDockingColor()
          Gets the color displayed when over a docking area
private  java.lang.Integer getDockingConstraint(java.awt.Component c, java.awt.Point p)
           
 java.awt.Color getFloatingColor()
          Gets the color displayed when over a floating area
private  PaletteToolBarUI.Handler getHandler()
           
(package private)  javax.swing.InputMap getInputMap(int condition)
           
private  javax.swing.border.Border getRolloverBorder(javax.swing.AbstractButton b)
           
protected  void installComponents()
           
protected  void installDefaults()
           
protected  void installKeyboardActions()
           
protected  void installListeners()
           
protected  void installNonRolloverBorders(javax.swing.JComponent c)
          Installs non-rollover borders on all the child components of the JComponent.
protected  void installNormalBorders(javax.swing.JComponent c)
          Installs normal borders on all the child components of the JComponent.
protected  void installRolloverBorders(javax.swing.JComponent c)
          Installs rollover borders on all the child components of the JComponent.
 void installUI(javax.swing.JComponent c)
           
private  boolean isBlocked(java.awt.Component comp, java.lang.Object constraint)
           
 boolean isFloating()
           
 boolean isRolloverBorders()
          Returns a flag to determine whether rollover button borders are enabled.
(package private) static void loadActionMap(PaletteLazyActionMap map)
           
private  int mapConstraintToOrientation(java.lang.Object constraint)
           
protected  void navigateFocusedComp(int direction)
           
protected  void paintDragWindow(java.awt.Graphics g)
          Paints the contents of the window used for dragging.
protected  void setBorderToNonRollover(java.awt.Component c)
          Sets the border of the component to have a non-rollover border which was created by createNonRolloverBorder.
protected  void setBorderToNormal(java.awt.Component c)
          Sets the border of the component to have a normal border.
protected  void setBorderToRollover(java.awt.Component c)
          Sets the border of the component to have a rollover border which was created by createRolloverBorder.
 void setDockingColor(java.awt.Color c)
          Sets the color displayed when over a docking area
 void setFloating(boolean b, java.awt.Point p)
           
 void setFloatingColor(java.awt.Color c)
          Sets the color displayed when over a floating area
 void setFloatingLocation(int x, int y)
           
 void setOrientation(int orientation)
           
 void setRolloverBorders(boolean rollover)
          Sets the flag for enabling rollover borders on the toolbar and it will also install the apropriate border depending on the state of the flag.
protected  void uninstallComponents()
           
protected  void uninstallDefaults()
           
protected  void uninstallKeyboardActions()
           
protected  void uninstallListeners()
           
 void uninstallUI(javax.swing.JComponent c)
           
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, 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

isFloatingAllowed

private static final boolean isFloatingAllowed
See Also:
Constant Field Values

toolBar

protected javax.swing.JToolBar toolBar

floating

private boolean floating

floatingX

private int floatingX

floatingY

private int floatingY

floatingFrame

private javax.swing.JFrame floatingFrame

floatingToolBar

private javax.swing.RootPaneContainer floatingToolBar

dragWindow

protected PaletteToolBarUI.DragWindow dragWindow

dockingSource

private java.awt.Container dockingSource

dockingSensitivity

private int dockingSensitivity

focusedCompIndex

protected int focusedCompIndex

dockingColor

protected java.awt.Color dockingColor

floatingColor

protected java.awt.Color floatingColor

dockingBorderColor

protected java.awt.Color dockingBorderColor

floatingBorderColor

protected java.awt.Color floatingBorderColor

dockingListener

protected javax.swing.event.MouseInputListener dockingListener

propertyListener

protected java.beans.PropertyChangeListener propertyListener

toolBarContListener

protected java.awt.event.ContainerListener toolBarContListener

toolBarFocusListener

protected java.awt.event.FocusListener toolBarFocusListener

handler

private PaletteToolBarUI.Handler handler

constraintBeforeFloating

protected java.lang.Integer constraintBeforeFloating

IS_ROLLOVER

private static java.lang.String IS_ROLLOVER

IS_DIVIDER_DRAWN

static java.lang.String IS_DIVIDER_DRAWN

TOOLBAR_ICON_PROPERTY

public static final java.lang.String TOOLBAR_ICON_PROPERTY
See Also:
Constant Field Values

TOOLBAR_TEXT_ICON_GAP_PROPERTY

public static final java.lang.String TOOLBAR_TEXT_ICON_GAP_PROPERTY
See Also:
Constant Field Values

TOOLBAR_INSETS_OVERRIDE_PROPERTY

public static final java.lang.String TOOLBAR_INSETS_OVERRIDE_PROPERTY
See Also:
Constant Field Values

rolloverBorder

private static javax.swing.border.Border rolloverBorder

nonRolloverBorder

private static javax.swing.border.Border nonRolloverBorder

nonRolloverToggleBorder

private static javax.swing.border.Border nonRolloverToggleBorder

rolloverBorders

private boolean rolloverBorders

borderTable

private java.util.HashMap<javax.swing.AbstractButton,javax.swing.border.Border> borderTable

rolloverTable

private java.util.Hashtable<javax.swing.AbstractButton,java.lang.Boolean> rolloverTable

upKey

@Deprecated
protected javax.swing.KeyStroke upKey
Deprecated. As of Java 2 platform v1.3.
As of Java 2 platform v1.3 this previously undocumented field is no longer used. Key bindings are now defined by the LookAndFeel, please refer to the key bindings specification for further details.


downKey

@Deprecated
protected javax.swing.KeyStroke downKey
Deprecated. As of Java 2 platform v1.3.
As of Java 2 platform v1.3 this previously undocumented field is no longer used. Key bindings are now defined by the LookAndFeel, please refer to the key bindings specification for further details.


leftKey

@Deprecated
protected javax.swing.KeyStroke leftKey
Deprecated. As of Java 2 platform v1.3.
As of Java 2 platform v1.3 this previously undocumented field is no longer used. Key bindings are now defined by the LookAndFeel, please refer to the key bindings specification for further details.


rightKey

@Deprecated
protected javax.swing.KeyStroke rightKey
Deprecated. As of Java 2 platform v1.3.
As of Java 2 platform v1.3 this previously undocumented field is no longer used. Key bindings are now defined by the LookAndFeel, please refer to the key bindings specification for further details.


FOCUSED_COMP_INDEX

private static java.lang.String FOCUSED_COMP_INDEX
Constructor Detail

PaletteToolBarUI

public PaletteToolBarUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)

installUI

public void installUI(javax.swing.JComponent c)
Overrides:
installUI in class javax.swing.plaf.ComponentUI

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Overrides:
uninstallUI in class javax.swing.plaf.ComponentUI

installDefaults

protected void installDefaults()

uninstallDefaults

protected void uninstallDefaults()

installComponents

protected void installComponents()

uninstallComponents

protected void uninstallComponents()

installListeners

protected void installListeners()

uninstallListeners

protected void uninstallListeners()

installKeyboardActions

protected void installKeyboardActions()

getInputMap

javax.swing.InputMap getInputMap(int condition)

loadActionMap

static void loadActionMap(PaletteLazyActionMap map)

uninstallKeyboardActions

protected void uninstallKeyboardActions()

navigateFocusedComp

protected void navigateFocusedComp(int direction)

createRolloverBorder

protected javax.swing.border.Border createRolloverBorder()
Creates a rollover border for toolbar components. The rollover border will be installed if rollover borders are enabled.

Override this method to provide an alternate rollover border.

Since:
1.4

createNonRolloverBorder

protected javax.swing.border.Border createNonRolloverBorder()
Creates the non rollover border for toolbar components. This border will be installed as the border for components added to the toolbar if rollover borders are not enabled.

Override this method to provide an alternate rollover border.

Since:
1.4

createNonRolloverToggleBorder

private javax.swing.border.Border createNonRolloverToggleBorder()
Creates a non rollover border for Toggle buttons in the toolbar.


createFloatingFrame

protected javax.swing.JFrame createFloatingFrame(javax.swing.JToolBar toolbar)
No longer used, use PaletteToolBarUI.createFloatingWindow(JToolBar)

See Also:
createFloatingWindow(javax.swing.JToolBar)

createFloatingWindow

protected javax.swing.RootPaneContainer createFloatingWindow(javax.swing.JToolBar toolbar)
Creates a window which contains the toolbar after it has been dragged out from its container

Returns:
a RootPaneContainer object, containing the toolbar.

createDragWindow

protected PaletteToolBarUI.DragWindow createDragWindow(javax.swing.JToolBar toolbar)

isRolloverBorders

public boolean isRolloverBorders()
Returns a flag to determine whether rollover button borders are enabled.

Returns:
true if rollover borders are enabled; false otherwise
Since:
1.4
See Also:
setRolloverBorders(boolean)

setRolloverBorders

public void setRolloverBorders(boolean rollover)
Sets the flag for enabling rollover borders on the toolbar and it will also install the apropriate border depending on the state of the flag.

Parameters:
rollover - if true, rollover borders are installed. Otherwise non-rollover borders are installed
Since:
1.4
See Also:
isRolloverBorders()

installRolloverBorders

protected void installRolloverBorders(javax.swing.JComponent c)
Installs rollover borders on all the child components of the JComponent.

This is a convenience method to call setBorderToRollover for each child component.

Parameters:
c - container which holds the child components (usally a JToolBar)
Since:
1.4
See Also:
setBorderToRollover(java.awt.Component)

installNonRolloverBorders

protected void installNonRolloverBorders(javax.swing.JComponent c)
Installs non-rollover borders on all the child components of the JComponent. A non-rollover border is the border that is installed on the child component while it is in the toolbar.

This is a convenience method to call setBorderToNonRollover for each child component.

Parameters:
c - container which holds the child components (usally a JToolBar)
Since:
1.4
See Also:
setBorderToNonRollover(java.awt.Component)

installNormalBorders

protected void installNormalBorders(javax.swing.JComponent c)
Installs normal borders on all the child components of the JComponent. A normal border is the original border that was installed on the child component before it was added to the toolbar.

This is a convenience method to call setBorderNormal for each child component.

Parameters:
c - container which holds the child components (usally a JToolBar)
Since:
1.4
See Also:
setBorderToNonRollover(java.awt.Component)

setBorderToRollover

protected void setBorderToRollover(java.awt.Component c)
Sets the border of the component to have a rollover border which was created by createRolloverBorder.

Parameters:
c - component which will have a rollover border installed
Since:
1.4
See Also:
createRolloverBorder()

getRolloverBorder

private javax.swing.border.Border getRolloverBorder(javax.swing.AbstractButton b)

setBorderToNonRollover

protected void setBorderToNonRollover(java.awt.Component c)
Sets the border of the component to have a non-rollover border which was created by createNonRolloverBorder.

Parameters:
c - component which will have a non-rollover border installed
Since:
1.4
See Also:
createNonRolloverBorder()

setBorderToNormal

protected void setBorderToNormal(java.awt.Component c)
Sets the border of the component to have a normal border. A normal border is the original border that was installed on the child component before it was added to the toolbar.

Parameters:
c - component which will have a normal border re-installed
Since:
1.4
See Also:
createNonRolloverBorder()

setFloatingLocation

public void setFloatingLocation(int x,
                                int y)

isFloating

public boolean isFloating()

setFloating

public void setFloating(boolean b,
                        java.awt.Point p)

mapConstraintToOrientation

private int mapConstraintToOrientation(java.lang.Object constraint)

setOrientation

public void setOrientation(int orientation)

getDockingColor

public java.awt.Color getDockingColor()
Gets the color displayed when over a docking area


setDockingColor

public void setDockingColor(java.awt.Color c)
Sets the color displayed when over a docking area


getFloatingColor

public java.awt.Color getFloatingColor()
Gets the color displayed when over a floating area


setFloatingColor

public void setFloatingColor(java.awt.Color c)
Sets the color displayed when over a floating area


isBlocked

private boolean isBlocked(java.awt.Component comp,
                          java.lang.Object constraint)

canDock

public boolean canDock(java.awt.Component c,
                       java.awt.Point p)

calculateConstraint

private java.lang.Integer calculateConstraint()

getDockingConstraint

private java.lang.Integer getDockingConstraint(java.awt.Component c,
                                               java.awt.Point p)

dragTo

protected void dragTo(java.awt.Point position,
                      java.awt.Point origin)

floatAt

protected void floatAt(java.awt.Point position,
                       java.awt.Point origin)

getHandler

private PaletteToolBarUI.Handler getHandler()

createToolBarContListener

protected java.awt.event.ContainerListener createToolBarContListener()

createToolBarFocusListener

protected java.awt.event.FocusListener createToolBarFocusListener()

createPropertyListener

protected java.beans.PropertyChangeListener createPropertyListener()

createDockingListener

protected javax.swing.event.MouseInputListener createDockingListener()

createFrameListener

protected java.awt.event.WindowListener createFrameListener()

paintDragWindow

protected void paintDragWindow(java.awt.Graphics g)
Paints the contents of the window used for dragging.

Parameters:
g - Graphics to paint to.
Throws:
java.lang.NullPointerException - is g is null
Since:
1.5