uic.widgets
Class ToolBarContainer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by uic.widgets.ToolBarContainer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ToolBarContainer
extends JPanel

This ToolBarContainer is a Container that allows a number of Toolbars to be present at a certain side of the screen. The Swing Tutorials describe ways to add only one Toolbar per side of the screen, and its quite hard to actually add a toolbar correctly, this class is suppost to make it easy. The simplest way of using the container is like this:

 JFrame myFrame = new JFrame();
 ToolBarContainer top = new ToolBarContainer(myFrame, SwingConstants.TOP);
 JToolBar fileTools = new JToolBar("File");
     // add some buttons to the fileTools toolbar.
 top.add(fileTools); 
Note that at any time you can still add another toolbar to the container:

 JToolBar projectTools = new JToolBar("Project");
     // add some buttons to the projectTools toolbar.
 top.add(projectTools); 

Known issue: due to the nature of Toolbars in Swing the usage of this container stops a toolbar being able to be 'dragged' from one side of the window to another if you do not use the accompanied UICTheme in your application.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
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.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
ToolBarContainer()
          It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.
ToolBarContainer(int placing)
          It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.
ToolBarContainer(Window parent, int placing)
          It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.
 
Method Summary
 Component add(Component child)
          Overloaded method, look at Container
 Component add(Component child, int index)
          Overloaded method, look at Container
 void add(Component child, Object contraints)
          Overloaded method, look at Container
 boolean canDrop(Point screenCoordinate, boolean paintDropLocation)
          find out if a toolbar at screenCoordinate is 'over' us and the user intends to drop it on us.
protected  JToolBar createToolBar(Component widget, String name)
          rotate and/or wrap the widget in a toolbar (if not a toolbar already)
 Dimension getMinimumSize()
          Make it always 1 pixel width and hight.
 int getPlacing()
          Each ToolBarLayouter is placed on a Window-edge.
 Dimension getPreferredSize()
          Work around bug that borderlayout does not honor minimumSize.
 boolean isHorizontal()
          Shorthand 'orientation' method.
 void paintChildren(Graphics g)
          Draw seperators.
static JToolBar placeToolBarOnWindow(Component widget, Component anyComponent, String name, int placing)
          add a toolbar to a window based on any component that belongs to a certain window.
static JToolBar placeToolBarOnWindow(Component widget, MainWindow window)
          Add a toolbar to the mainwindow
static JToolBar placeToolBarOnWindow(Component widget, MainWindow window, int placing)
          Add a toolbar to the mainwindow
static JToolBar placeToolBarOnWindow(Component widget, MainWindow window, String name)
          Add a toolbar to the mainwindow
static JToolBar placeToolBarOnWindow(Component widget, MainWindow window, String name, int placing)
           
static JToolBar placeToolBarOnWindow(Component widget, Window window)
           
static JToolBar placeToolBarOnWindow(Component widget, Window window, int placing)
           
static JToolBar placeToolBarOnWindow(Component widget, Window window, String name)
           
static JToolBar placeToolBarOnWindow(Component widget, Window window, String name, int placing)
          builder method to put a toolbar on a Window; note that both JFrame and JDialog are Windows.
static JToolBar placeToolBarOnWindow(Component widget, Window window, String name, Point location)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
 

Constructor Detail

ToolBarContainer

public ToolBarContainer()
It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.


ToolBarContainer

public ToolBarContainer(int placing)
It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.

Parameters:
placing - from the box-tyoe SwingConstants (top/bottom etc).

ToolBarContainer

public ToolBarContainer(Window parent,
                        int placing)
It is legal; but not advisable to create a ToolBarContainer by yourself, use the placeToolBarOnWindow factory method instead.

Parameters:
placing - from the box-tyoe SwingConstants (top/bottom etc).
parent - the containing window where the container should be added to.
Method Detail

add

public Component add(Component child)
Overloaded method, look at Container

Overrides:
add in class Container

add

public Component add(Component child,
                     int index)
Overloaded method, look at Container

Overrides:
add in class Container

add

public void add(Component child,
                Object contraints)
Overloaded method, look at Container

Overrides:
add in class Container

isHorizontal

public boolean isHorizontal()
Shorthand 'orientation' method.


getPlacing

public int getPlacing()
Each ToolBarLayouter is placed on a Window-edge.

Returns:
the side of the window from the SwingConstants LEFT/RIGHT/TOP/BOTTOM

createToolBar

protected JToolBar createToolBar(Component widget,
                                 String name)
rotate and/or wrap the widget in a toolbar (if not a toolbar already)


paintChildren

public void paintChildren(Graphics g)
Draw seperators. (overloaded method)

Overrides:
paintChildren in class JComponent

canDrop

public boolean canDrop(Point screenCoordinate,
                       boolean paintDropLocation)
find out if a toolbar at screenCoordinate is 'over' us and the user intends to drop it on us.

Parameters:
screenCoordinate - the point where the users-pointer is
paintDropLocation - if true will give graphical feedback on where exactly the toolbar will be dropped

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Window window,
                                            String name)

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Window window,
                                            int placing)

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Window window)

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            MainWindow window,
                                            String name)
Add a toolbar to the mainwindow

Since:
1.2

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            MainWindow window,
                                            int placing)
Add a toolbar to the mainwindow

Since:
1.2

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            MainWindow window)
Add a toolbar to the mainwindow

Since:
1.2

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            MainWindow window,
                                            String name,
                                            int placing)

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Component anyComponent,
                                            String name,
                                            int placing)
add a toolbar to a window based on any component that belongs to a certain window. For object-orientation purposes it is not always wanted to create and maintain all toolbars in the main-window class. You can have a tab that uses a toolbar, for example. In the constructor of that widget it is not possible to get the Window object for several reasons. The best way to add the toolbar is to call this method with the parent widget (the one that will belong to the same Window when it becomes visible) as the 'anyComponent' argument.

After calling this placeToolBarOnWindow method, your toolbar will automatically be added as soon as the window opens, at the requested location.

Parameters:
widget - the widget you want to place as a toolbar on the window; can be a toolbar but also a simple widget that will then be placed in a toolbar.
anyComponent - any component that belongs to a swing-hierarchy which will have a Window object at the top.
name - of the toolbar.
placing - a direction from the UICToolBar on where the toolbar is to be placed. One of LEFT/RIGHT/TOP/BOTTOM/FLAT/FLOATING/HIDDEN.
Throws:
IllegalArgumentException - when placing is an illegal value.
Since:
2.0

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Window window,
                                            String name,
                                            Point location)

placeToolBarOnWindow

public static JToolBar placeToolBarOnWindow(Component widget,
                                            Window window,
                                            String name,
                                            int placing)
builder method to put a toolbar on a Window; note that both JFrame and JDialog are Windows.

Parameters:
widget - the widget you want to place as a toolbar on the window; can be a toolbar but also a simple widget that will then be placed in a toolbar.
window - the target Window
name - of the toolbar.
placing - a direction from the UICToolBar on where the toolbar is to be placed. One of LEFT/RIGHT/TOP/BOTTOM/FLAT/FLOATING/HIDDEN.
Throws:
IllegalArgumentException - when placing is an illegal value, or window is null.

getMinimumSize

public Dimension getMinimumSize()
Make it always 1 pixel width and hight. Not realy needed when using the UIC Theme, but for others its needed.

Overrides:
getMinimumSize in class JComponent

getPreferredSize

public Dimension getPreferredSize()
Work around bug that borderlayout does not honor minimumSize. Return preferred size that is never smaller then the minimumSize.

Overrides:
getPreferredSize in class JComponent


Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence