Methods Summary |
---|
private java.lang.String | calculateConstraint()
String constraint = null;
LayoutManager lm = dockingSource.getLayout();
if (lm instanceof BorderLayout) {
constraint = (String)((BorderLayout)lm).getConstraints(toolBar);
}
return (constraint != null) ? constraint : constraintBeforeFloating;
|
public boolean | canDock(java.awt.Component c, java.awt.Point p)
return (p != null && getDockingConstraint(c, p) != null);
|
protected javax.swing.event.MouseInputListener | createDockingListener()
getHandler().tb = toolBar;
return getHandler();
|
protected javax.swing.plaf.basic.BasicToolBarUI$DragWindow | createDragWindow(javax.swing.JToolBar toolbar)
Window frame = null;
if(toolBar != null) {
Container p;
for(p = toolBar.getParent() ; p != null && !(p instanceof Window) ;
p = p.getParent());
if(p != null && p instanceof Window)
frame = (Window) p;
}
if(floatingToolBar == null) {
floatingToolBar = createFloatingWindow(toolBar);
}
if (floatingToolBar instanceof Window) frame = (Window) floatingToolBar;
DragWindow dragWindow = new DragWindow(frame);
return dragWindow;
|
protected javax.swing.JFrame | createFloatingFrame(javax.swing.JToolBar toolbar)No longer used, use BasicToolBarUI.createFloatingWindow(JToolBar)
Window window = SwingUtilities.getWindowAncestor(toolbar);
JFrame frame = new JFrame(toolbar.getName(),
(window != null) ? window.getGraphicsConfiguration() : null) {
// Override createRootPane() to automatically resize
// the frame when contents change
protected JRootPane createRootPane() {
JRootPane rootPane = new JRootPane() {
private boolean packing = false;
public void validate() {
super.validate();
if (!packing) {
packing = true;
pack();
packing = false;
}
}
};
rootPane.setOpaque(true);
return rootPane;
}
};
frame.getRootPane().setName("ToolBar.FloatingFrame");
frame.setResizable(false);
WindowListener wl = createFrameListener();
frame.addWindowListener(wl);
return frame;
|
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
class ToolBarDialog extends JDialog {
public ToolBarDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
}
public ToolBarDialog(Dialog owner, String title, boolean modal) {
super(owner, title, modal);
}
// Override createRootPane() to automatically resize
// the frame when contents change
protected JRootPane createRootPane() {
JRootPane rootPane = new JRootPane() {
private boolean packing = false;
public void validate() {
super.validate();
if (!packing) {
packing = true;
pack();
packing = false;
}
}
};
rootPane.setOpaque(true);
return rootPane;
}
}
JDialog dialog;
Window window = SwingUtilities.getWindowAncestor(toolbar);
if (window instanceof Frame) {
dialog = new ToolBarDialog((Frame)window, toolbar.getName(), false);
} else if (window instanceof Dialog) {
dialog = new ToolBarDialog((Dialog)window, toolbar.getName(), false);
} else {
dialog = new ToolBarDialog((Frame)null, toolbar.getName(), false);
}
dialog.getRootPane().setName("ToolBar.FloatingWindow");
dialog.setTitle(toolbar.getName());
dialog.setResizable(false);
WindowListener wl = createFrameListener();
dialog.addWindowListener(wl);
return dialog;
|
protected java.awt.event.WindowListener | createFrameListener()
return new FrameListener();
|
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.
Object border = UIManager.get("ToolBar.nonrolloverBorder");
if (border != null) {
return (Border)border;
}
UIDefaults table = UIManager.getLookAndFeelDefaults();
return new CompoundBorder(new BasicBorders.ButtonBorder(
table.getColor("Button.shadow"),
table.getColor("Button.darkShadow"),
table.getColor("Button.light"),
table.getColor("Button.highlight")),
new BasicBorders.RolloverMarginBorder());
|
private javax.swing.border.Border | createNonRolloverToggleBorder()Creates a non rollover border for Toggle buttons in the toolbar.
UIDefaults table = UIManager.getLookAndFeelDefaults();
return new CompoundBorder(new BasicBorders.RadioButtonBorder(
table.getColor("ToggleButton.shadow"),
table.getColor("ToggleButton.darkShadow"),
table.getColor("ToggleButton.light"),
table.getColor("ToggleButton.highlight")),
new BasicBorders.RolloverMarginBorder());
|
protected java.beans.PropertyChangeListener | createPropertyListener()
return getHandler();
|
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.
Object border = UIManager.get("ToolBar.rolloverBorder");
if (border != null) {
return (Border)border;
}
UIDefaults table = UIManager.getLookAndFeelDefaults();
return new CompoundBorder(new BasicBorders.RolloverButtonBorder(
table.getColor("controlShadow"),
table.getColor("controlDkShadow"),
table.getColor("controlHighlight"),
table.getColor("controlLtHighlight")),
new BasicBorders.RolloverMarginBorder());
|
protected java.awt.event.ContainerListener | createToolBarContListener()
return getHandler();
|
protected java.awt.event.FocusListener | createToolBarFocusListener()
return getHandler();
|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent c)
return new BasicToolBarUI();
|
protected void | dragTo(java.awt.Point position, java.awt.Point origin)
if (toolBar.isFloatable() == true)
{
try
{
if (dragWindow == null)
dragWindow = createDragWindow(toolBar);
Point offset = dragWindow.getOffset();
if (offset == null) {
Dimension size = toolBar.getPreferredSize();
offset = new Point(size.width/2, size.height/2);
dragWindow.setOffset(offset);
}
Point global = new Point(origin.x+ position.x,
origin.y+position.y);
Point dragPoint = new Point(global.x- offset.x,
global.y- offset.y);
if (dockingSource == null)
dockingSource = toolBar.getParent();
constraintBeforeFloating = calculateConstraint();
Point dockingPosition = dockingSource.getLocationOnScreen();
Point comparisonPoint = new Point(global.x-dockingPosition.x,
global.y-dockingPosition.y);
if (canDock(dockingSource, comparisonPoint)) {
dragWindow.setBackground(getDockingColor());
String constraint = getDockingConstraint(dockingSource,
comparisonPoint);
int orientation = mapConstraintToOrientation(constraint);
dragWindow.setOrientation(orientation);
dragWindow.setBorderColor(dockingBorderColor);
} else {
dragWindow.setBackground(getFloatingColor());
dragWindow.setBorderColor(floatingBorderColor);
}
dragWindow.setLocation(dragPoint.x, dragPoint.y);
if (dragWindow.isVisible() == false) {
Dimension size = toolBar.getPreferredSize();
dragWindow.setSize(size.width, size.height);
dragWindow.show();
}
}
catch ( IllegalComponentStateException e )
{
}
}
|
protected void | floatAt(java.awt.Point position, java.awt.Point origin)
if(toolBar.isFloatable() == true)
{
try
{
Point offset = dragWindow.getOffset();
if (offset == null) {
offset = position;
dragWindow.setOffset(offset);
}
Point global = new Point(origin.x+ position.x,
origin.y+position.y);
setFloatingLocation(global.x-offset.x,
global.y-offset.y);
if (dockingSource != null) {
Point dockingPosition = dockingSource.getLocationOnScreen();
Point comparisonPoint = new Point(global.x-dockingPosition.x,
global.y-dockingPosition.y);
if (canDock(dockingSource, comparisonPoint)) {
setFloating(false, comparisonPoint);
} else {
setFloating(true, null);
}
} else {
setFloating(true, null);
}
dragWindow.setOffset(null);
}
catch ( IllegalComponentStateException e )
{
}
}
|
public java.awt.Color | getDockingColor()Gets the color displayed when over a docking area
return dockingColor;
|
private java.lang.String | getDockingConstraint(java.awt.Component c, java.awt.Point p)
if (p == null) return constraintBeforeFloating;
if (c.contains(p)) {
dockingSensitivity = (toolBar.getOrientation() == JToolBar.HORIZONTAL)
? toolBar.getSize().height
: toolBar.getSize().width;
// North (Base distance on height for now!)
if (p.y < dockingSensitivity && !isBlocked(c, BorderLayout.NORTH)) {
return BorderLayout.NORTH;
}
// East (Base distance on height for now!)
if (p.x >= c.getWidth() - dockingSensitivity && !isBlocked(c, BorderLayout.EAST)) {
return BorderLayout.EAST;
}
// West (Base distance on height for now!)
if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
return BorderLayout.WEST;
}
if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
return BorderLayout.SOUTH;
}
}
return null;
|
public java.awt.Color | getFloatingColor()Gets the color displayed when over a floating area
return floatingColor;
|
private javax.swing.plaf.basic.BasicToolBarUI$Handler | getHandler()
if (handler == null) {
handler = new Handler();
}
return handler;
|
javax.swing.InputMap | getInputMap(int condition)
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap)DefaultLookup.get(toolBar, this,
"ToolBar.ancestorInputMap");
}
return null;
|
protected javax.swing.border.Border | getNonRolloverBorder(javax.swing.AbstractButton b)Returns a non-rollover border for the button.
if (b instanceof JToggleButton) {
return nonRolloverToggleBorder;
} else {
return nonRolloverBorder;
}
|
protected javax.swing.border.Border | getRolloverBorder(javax.swing.AbstractButton b)Returns a rollover border for the button.
return rolloverBorder;
|
protected void | installComponents()
|
protected void | installDefaults()
LookAndFeel.installBorder(toolBar,"ToolBar.border");
LookAndFeel.installColorsAndFont(toolBar,
"ToolBar.background",
"ToolBar.foreground",
"ToolBar.font");
// Toolbar specific defaults
if ( dockingColor == null || dockingColor instanceof UIResource )
dockingColor = UIManager.getColor("ToolBar.dockingBackground");
if ( floatingColor == null || floatingColor instanceof UIResource )
floatingColor = UIManager.getColor("ToolBar.floatingBackground");
if ( dockingBorderColor == null ||
dockingBorderColor instanceof UIResource )
dockingBorderColor = UIManager.getColor("ToolBar.dockingForeground");
if ( floatingBorderColor == null ||
floatingBorderColor instanceof UIResource )
floatingBorderColor = UIManager.getColor("ToolBar.floatingForeground");
// ToolBar rollover button borders
Object rolloverProp = toolBar.getClientProperty( IS_ROLLOVER );
if (rolloverProp == null) {
rolloverProp = UIManager.get("ToolBar.isRollover");
}
if ( rolloverProp != null ) {
rolloverBorders = ((Boolean)rolloverProp).booleanValue();
}
if (rolloverBorder == null) {
rolloverBorder = createRolloverBorder();
}
if (nonRolloverBorder == null) {
nonRolloverBorder = createNonRolloverBorder();
}
if (nonRolloverToggleBorder == null) {
nonRolloverToggleBorder = createNonRolloverToggleBorder();
}
setRolloverBorders( isRolloverBorders() );
|
protected void | installKeyboardActions()
InputMap km = getInputMap(JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
SwingUtilities.replaceUIInputMap(toolBar, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
km);
LazyActionMap.installLazyActionMap(toolBar, BasicToolBarUI.class,
"ToolBar.actionMap");
|
protected void | installListeners()
dockingListener = createDockingListener( );
if ( dockingListener != null )
{
toolBar.addMouseMotionListener( dockingListener );
toolBar.addMouseListener( dockingListener );
}
propertyListener = createPropertyListener(); // added in setFloating
if (propertyListener != null) {
toolBar.addPropertyChangeListener(propertyListener);
}
toolBarContListener = createToolBarContListener();
if ( toolBarContListener != null ) {
toolBar.addContainerListener( toolBarContListener );
}
toolBarFocusListener = createToolBarFocusListener();
if ( toolBarFocusListener != null )
{
// Put focus listener on all components in toolbar
Component[] components = toolBar.getComponents();
for ( int i = 0; i < components.length; ++i )
{
components[ i ].addFocusListener( toolBarFocusListener );
}
}
|
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.
// Put non-rollover borders on buttons. These borders reduce the margin.
Component[] components = c.getComponents();
for ( int i = 0; i < components.length; ++i ) {
if ( components[ i ] instanceof JComponent ) {
( (JComponent)components[ i ] ).updateUI();
setBorderToNonRollover( components[ i ] );
}
}
|
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.
// Put back the normal borders on buttons
Component[] components = c.getComponents();
for ( int i = 0; i < components.length; ++i ) {
setBorderToNormal( components[ i ] );
}
|
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.
// Put rollover borders on buttons
Component[] components = c.getComponents();
for ( int i = 0; i < components.length; ++i ) {
if ( components[ i ] instanceof JComponent ) {
( (JComponent)components[ i ] ).updateUI();
setBorderToRollover( components[ i ] );
}
}
|
public void | installUI(javax.swing.JComponent c)
toolBar = (JToolBar) c;
// Set defaults
installDefaults();
installComponents();
installListeners();
installKeyboardActions();
// Initialize instance vars
dockingSensitivity = 0;
floating = false;
floatingX = floatingY = 0;
floatingToolBar = null;
setOrientation( toolBar.getOrientation() );
LookAndFeel.installProperty(c, "opaque", Boolean.TRUE);
if ( c.getClientProperty( FOCUSED_COMP_INDEX ) != null )
{
focusedCompIndex = ( (Integer) ( c.getClientProperty( FOCUSED_COMP_INDEX ) ) ).intValue();
}
|
private boolean | isBlocked(java.awt.Component comp, java.lang.Object constraint)
if (comp instanceof Container) {
Container cont = (Container)comp;
LayoutManager lm = cont.getLayout();
if (lm instanceof BorderLayout) {
BorderLayout blm = (BorderLayout)lm;
Component c = blm.getLayoutComponent(cont, constraint);
return (c != null && c != toolBar);
}
}
return false;
|
public boolean | isFloating()
return floating;
|
public boolean | isRolloverBorders()Returns a flag to determine whether rollover button borders
are enabled.
return rolloverBorders;
|
static void | loadActionMap(javax.swing.plaf.basic.LazyActionMap map)
map.put(new Actions(Actions.NAVIGATE_RIGHT));
map.put(new Actions(Actions.NAVIGATE_LEFT));
map.put(new Actions(Actions.NAVIGATE_UP));
map.put(new Actions(Actions.NAVIGATE_DOWN));
|
private int | mapConstraintToOrientation(java.lang.String constraint)
int orientation = toolBar.getOrientation();
if ( constraint != null )
{
if ( constraint.equals(BorderLayout.EAST) || constraint.equals(BorderLayout.WEST) )
orientation = JToolBar.VERTICAL;
else if ( constraint.equals(BorderLayout.NORTH) || constraint.equals(BorderLayout.SOUTH) )
orientation = JToolBar.HORIZONTAL;
}
return orientation;
|
protected void | navigateFocusedComp(int direction)
int nComp = toolBar.getComponentCount();
int j;
switch ( direction )
{
case EAST:
case SOUTH:
if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
j = focusedCompIndex + 1;
while ( j != focusedCompIndex )
{
if ( j >= nComp ) j = 0;
Component comp = toolBar.getComponentAtIndex( j++ );
if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
{
comp.requestFocus();
break;
}
}
break;
case WEST:
case NORTH:
if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
j = focusedCompIndex - 1;
while ( j != focusedCompIndex )
{
if ( j < 0 ) j = nComp - 1;
Component comp = toolBar.getComponentAtIndex( j-- );
if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )
{
comp.requestFocus();
break;
}
}
break;
default:
break;
}
|
protected void | paintDragWindow(java.awt.Graphics g)Paints the contents of the window used for dragging.
g.setColor(dragWindow.getBackground());
int w = dragWindow.getWidth();
int h = dragWindow.getHeight();
g.fillRect(0, 0, w, h);
g.setColor(dragWindow.getBorderColor());
g.drawRect(0, 0, w - 1, h - 1);
|
protected void | setBorderToNonRollover(java.awt.Component c)Sets the border of the component to have a non-rollover border which
was created by createNonRolloverBorder .
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton)c;
Border border = (Border)borderTable.get(b);
if (border == null || border instanceof UIResource) {
borderTable.put(b, b.getBorder());
}
// Only set the border if its the default border
if (b.getBorder() instanceof UIResource) {
b.setBorder(getNonRolloverBorder(b));
}
rolloverTable.put(b, b.isRolloverEnabled()?
Boolean.TRUE: Boolean.FALSE);
b.setRolloverEnabled(false);
}
|
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.
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton)c;
Border border = (Border)borderTable.remove(b);
b.setBorder(border);
Boolean value = (Boolean)rolloverTable.remove(b);
if (value != null) {
b.setRolloverEnabled(value.booleanValue());
}
}
|
protected void | setBorderToRollover(java.awt.Component c)Sets the border of the component to have a rollover border which
was created by createRolloverBorder .
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton)c;
Border border = (Border)borderTable.get(b);
if (border == null || border instanceof UIResource) {
borderTable.put(b, b.getBorder());
}
// Only set the border if its the default border
if (b.getBorder() instanceof UIResource) {
b.setBorder(getRolloverBorder(b));
}
rolloverTable.put(b, b.isRolloverEnabled()?
Boolean.TRUE: Boolean.FALSE);
b.setRolloverEnabled(true);
}
|
public void | setDockingColor(java.awt.Color c)Sets the color displayed when over a docking area
this.dockingColor = c;
|
public void | setFloating(boolean b, java.awt.Point p)
if (toolBar.isFloatable() == true) {
boolean visible = false;
Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
if (ancestor != null) {
visible = ancestor.isVisible();
}
if (dragWindow != null)
dragWindow.setVisible(false);
this.floating = b;
if (floatingToolBar == null) {
floatingToolBar = createFloatingWindow(toolBar);
}
if (b == true)
{
if (dockingSource == null)
{
dockingSource = toolBar.getParent();
dockingSource.remove(toolBar);
}
constraintBeforeFloating = calculateConstraint();
if ( propertyListener != null )
UIManager.addPropertyChangeListener( propertyListener );
floatingToolBar.getContentPane().add(toolBar,BorderLayout.CENTER);
if (floatingToolBar instanceof Window) {
((Window)floatingToolBar).pack();
((Window)floatingToolBar).setLocation(floatingX, floatingY);
if (visible) {
((Window)floatingToolBar).show();
} else {
ancestor.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
((Window)floatingToolBar).show();
}
});
}
}
} else {
if (floatingToolBar == null)
floatingToolBar = createFloatingWindow(toolBar);
if (floatingToolBar instanceof Window) ((Window)floatingToolBar).setVisible(false);
floatingToolBar.getContentPane().remove(toolBar);
String constraint = getDockingConstraint(dockingSource,
p);
if (constraint == null) {
constraint = BorderLayout.NORTH;
}
int orientation = mapConstraintToOrientation(constraint);
setOrientation(orientation);
if (dockingSource== null)
dockingSource = toolBar.getParent();
if ( propertyListener != null )
UIManager.removePropertyChangeListener( propertyListener );
dockingSource.add(constraint, toolBar);
}
dockingSource.invalidate();
Container dockingSourceParent = dockingSource.getParent();
if (dockingSourceParent != null)
dockingSourceParent.validate();
dockingSource.repaint();
}
|
public void | setFloatingColor(java.awt.Color c)Sets the color displayed when over a floating area
this.floatingColor = c;
|
public void | setFloatingLocation(int x, int y)
floatingX = x;
floatingY = y;
|
public void | setOrientation(int orientation)
toolBar.setOrientation( orientation );
if (dragWindow !=null)
dragWindow.setOrientation(orientation);
|
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.
rolloverBorders = rollover;
if ( rolloverBorders ) {
installRolloverBorders( toolBar );
} else {
installNonRolloverBorders( toolBar );
}
|
protected void | uninstallComponents()
|
protected void | uninstallDefaults()
LookAndFeel.uninstallBorder(toolBar);
dockingColor = null;
floatingColor = null;
dockingBorderColor = null;
floatingBorderColor = null;
installNormalBorders(toolBar);
rolloverBorder = null;
nonRolloverBorder = null;
nonRolloverToggleBorder = null;
|
protected void | uninstallKeyboardActions()
SwingUtilities.replaceUIActionMap(toolBar, null);
SwingUtilities.replaceUIInputMap(toolBar, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
null);
|
protected void | uninstallListeners()
if ( dockingListener != null )
{
toolBar.removeMouseMotionListener(dockingListener);
toolBar.removeMouseListener(dockingListener);
dockingListener = null;
}
if ( propertyListener != null )
{
toolBar.removePropertyChangeListener(propertyListener);
propertyListener = null; // removed in setFloating
}
if ( toolBarContListener != null )
{
toolBar.removeContainerListener( toolBarContListener );
toolBarContListener = null;
}
if ( toolBarFocusListener != null )
{
// Remove focus listener from all components in toolbar
Component[] components = toolBar.getComponents();
for ( int i = 0; i < components.length; ++i )
{
components[ i ].removeFocusListener( toolBarFocusListener );
}
toolBarFocusListener = null;
}
handler = null;
|
public void | uninstallUI(javax.swing.JComponent c)
// Clear defaults
uninstallDefaults();
uninstallComponents();
uninstallListeners();
uninstallKeyboardActions();
// Clear instance vars
if (isFloating() == true)
setFloating(false, null);
floatingToolBar = null;
dragWindow = null;
dockingSource = null;
c.putClientProperty( FOCUSED_COMP_INDEX, new Integer( focusedCompIndex ) );
|