Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.javathis.utilities.ui
Class JTToolBar  view JTToolBar download JTToolBar.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JToolBar
                  extended bycom.javathis.utilities.ui.JTToolBar
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.beans.PropertyChangeListener, java.io.Serializable, javax.swing.SwingConstants

public class JTToolBar
extends javax.swing.JToolBar
implements java.awt.event.MouseListener, java.beans.PropertyChangeListener

A JTToolBar works exactly the same as a javax.swing.JToolBar with additional ability to change it's appearance.

Currently the only supported appearances are normal and flat. Normal is the default and makes it look and act just like a JToolBar. However setting it to flat makes it act more like a Microsoft tool bar.

Flat appearance has shows all the buttons with no borders, and only when the mouse pointer goes over it will it appear to popup. The separators appear as lines instead of spaces between the buttons.

Setting the appearance can be done one of two ways. Either by providing the desired appearance byte with the corresponding constructor, or to the setAppearance(byte) 55 method.

A special feature of a JTToolBar is that when it is set to be floatable and you drag-out the tool bar, it will not let you dock it on a side that already contains a component. (This has been approved as RFE 4664642 with Sun, however still not implemented.)

For drag-out to work correctly it requires a java.awt.BorderLayout for the tool bar's container.

Note: I do not know how this will look or preform on a MAC. If anyone has a MAC, especially one with OS X, please let me know.

Note: This component was created because the javax.swing.JToolBar provided with JDK 1.4.0 is supposed to function as the appearance does by it's rollover methods. However, there are bugs present in the 1.4.0 release that prevent this from working correctly in the Windows LnF. Also separators do not function as they should. Especially when the tool bar is docked on the east or west. Also the separators in the JToolBar are always a bar regardless of the rollover setting. This does not conform existing standards. The separator should only be a bar when the buttons are in a flat appearance other wise they should be a empty space.

A detailed bug report was submitted to Sun, still awaiting it to be reviewed and posted. Once it is posted, a link will be provided here.

Please notify me of non standard behavior of this component in LnF's other than Windows. Since I not well versed in their standards.


Nested Class Summary
 class JTToolBar.BasicJTToolBarUI
           
private  class JTToolBar.JTSeparator
           
private  class JTToolBar.JTToolBarLayout
           
 class JTToolBar.MetalJTToolBarUI
           
 class JTToolBar.WindowsJTToolBarUI
           
 
Nested classes inherited from class javax.swing.JToolBar
javax.swing.JToolBar.AccessibleJToolBar, javax.swing.JToolBar.Separator
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  byte appearance
           
static byte APPEARANCE_FLAT
           
static byte APPEARANCE_NORMAL
           
private static javax.swing.border.Border BUTTON_FLAT_BORDER
           
private static javax.swing.border.Border BUTTON_NORMAL_BORDER
           
private  boolean isDirty
           
private static java.util.ResourceBundle MAIN_RESOURCE_BUNDLE
           
private static java.lang.String uiClassID
           
 
Fields inherited from class javax.swing.JToolBar
 
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 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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTToolBar()
          Creates a new tool bar; orientation defaults to HORIZONTAL, and appeance to APPEARANCE_NORMAL.
JTToolBar(byte appearance)
          Creates a new tool bar with the specified appeance and orientation defaults to HORIZONTAL.
JTToolBar(int orientation)
          Creates a new tool bar with the specified orientation and appeance defaults to APPEARANCE_NORMAL.
JTToolBar(java.lang.String name)
          Creates a new tool bar with the specified name.
JTToolBar(java.lang.String name, byte appearance)
          Creates a new tool bar with a specified name and appearance with orientation defaulting HORIZONTAL.
JTToolBar(java.lang.String name, int orientation)
          Creates a new tool bar with a specified name and orientation with appeance defaulting APPEARANCE_NORMAL.
JTToolBar(java.lang.String name, int orientation, byte appearance)
          Creates a new tool bar with a specified name, orientation, and appearance.
 
Method Summary
protected  void addImpl(java.awt.Component component, java.lang.Object constraints, int index)
          If an javax.swing.AbstractButton is being added, it is modified to handle the current appearance of the tool bar.
 void addSeparator()
          Appends a separator of default size to the end of the tool bar.
 void addSeparator(java.awt.Dimension size)
          Appends a separator of a specified size to the end of the tool bar.
private  boolean canDock(javax.swing.plaf.basic.BasicToolBarUI ui, java.awt.Component component, java.awt.Point point)
           
 byte getAppearance()
          Returns the byte representing the current appearance of the tool bar.
 boolean isRollover()
          Returns true if the appearance is flat.
static void main(java.lang.String[] args)
           
 void mouseClicked(java.awt.event.MouseEvent e)
          This method is called when the mouse is clicked (pressed and released in short succession) on a component.
 void mouseEntered(java.awt.event.MouseEvent e)
          This method is called when the mouse enters a component.
 void mouseExited(java.awt.event.MouseEvent e)
          This method is called when the mouse exits a component.
 void mousePressed(java.awt.event.MouseEvent e)
          This method is called when the mouse is pressed over a component.
 void mouseReleased(java.awt.event.MouseEvent e)
          This method is called when the mouse is released over a component.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Fired after a Bean's property has changed.
 void setAppearance(byte appearance)
          Changes the appearance of the tool bar.
 void setRollover(boolean rollover)
          Deligates to setAppearance(byte) 55 changing appearance to flat if the provided rollover value is true, and normal otherwise.
private  void updateButtons()
          Used to handle all the buttons if the appearance is changed on the fly.
 void updateUI()
          Notification from the UIFactory that the L&F has changed.
private  void updateUIDefaults(javax.swing.LookAndFeel newLnF)
           
 
Methods inherited from class javax.swing.JToolBar
add, createActionChangeListener, createActionComponent, getAccessibleContext, getComponentAtIndex, getComponentIndex, getMargin, getOrientation, getUI, getUIClassID, isBorderPainted, isFloatable, paintBorder, paramString, setBorderPainted, setFloatable, setLayout, setMargin, setOrientation, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, swapComponents, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uiClassID

private static final java.lang.String uiClassID
See Also:
Constant Field Values

MAIN_RESOURCE_BUNDLE

private static final java.util.ResourceBundle MAIN_RESOURCE_BUNDLE

APPEARANCE_FLAT

public static final byte APPEARANCE_FLAT
See Also:
Constant Field Values

APPEARANCE_NORMAL

public static final byte APPEARANCE_NORMAL
See Also:
Constant Field Values

BUTTON_FLAT_BORDER

private static final javax.swing.border.Border BUTTON_FLAT_BORDER

BUTTON_NORMAL_BORDER

private static final javax.swing.border.Border BUTTON_NORMAL_BORDER

isDirty

private boolean isDirty

appearance

private byte appearance
Constructor Detail

JTToolBar

public JTToolBar()
Creates a new tool bar; orientation defaults to HORIZONTAL, and appeance to APPEARANCE_NORMAL.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(int orientation)
Creates a new tool bar with the specified orientation and appeance defaults to APPEARANCE_NORMAL. The orientation must be either HORIZONTAL or VERTICAL.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(byte appearance)
Creates a new tool bar with the specified appeance and orientation defaults to HORIZONTAL. The appeance must be either APPEARANCE_NORMAL or APPEARANCE_FLAT.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(java.lang.String name)
Creates a new tool bar with the specified name. The name is used as the title of the undocked tool bar. The default orientation is HORIZONTAL and appeance is APPEARANCE_NORMAL.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(java.lang.String name,
                 int orientation)
Creates a new tool bar with a specified name and orientation with appeance defaulting APPEARANCE_NORMAL.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(java.lang.String name,
                 byte appearance)
Creates a new tool bar with a specified name and appearance with orientation defaulting HORIZONTAL.

Note: Delegates to the following constructor:

JTToolBar(String, int, byte)


JTToolBar

public JTToolBar(java.lang.String name,
                 int orientation,
                 byte appearance)
Creates a new tool bar with a specified name, orientation, and appearance. All other constructors call this constructor.

Note: If orientation or appearance is an invalid value, an java.lang.IllegalArgumentException will be thrown.

Method Detail

setAppearance

public void setAppearance(byte appearance)
Changes the appearance of the tool bar.

Currently the only supported appearances are normal and flat. Normal is the makes it look and act just like a JToolBar. However setting it to flat makes it show all the buttons with no borders, and only when the mouse pointer goes over it will it appear to popup. The separators appear as lines instead of spaces between the buttons.

Note: If orientation or appearance is an invalid value, an java.lang.IllegalArgumentException will be thrown.


getAppearance

public byte getAppearance()
Returns the byte representing the current appearance of the tool bar.


setRollover

public void setRollover(boolean rollover)
Deligates to setAppearance(byte) 55 changing appearance to flat if the provided rollover value is true, and normal otherwise.


isRollover

public boolean isRollover()
Returns true if the appearance is flat. Overridded to work with the appearance methodology.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
This method is called when the mouse is pressed over a component.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
This method is called when the mouse is released over a component.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
This method is called when the mouse enters a component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
This method is called when the mouse is clicked (pressed and released in short succession) on a component.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Description copied from interface: java.awt.event.MouseListener
This method is called when the mouse exits a component.

Specified by:
mouseExited in interface java.awt.event.MouseListener

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Description copied from interface: java.beans.PropertyChangeListener
Fired after a Bean's property has changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

addSeparator

public void addSeparator()
Appends a separator of default size to the end of the tool bar. The default size is determined by the current look and feel.


addSeparator

public void addSeparator(java.awt.Dimension size)
Appends a separator of a specified size to the end of the tool bar.


updateUI

public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the UIFactory.


addImpl

protected void addImpl(java.awt.Component component,
                       java.lang.Object constraints,
                       int index)
If an javax.swing.AbstractButton is being added, it is modified to handle the current appearance of the tool bar.


updateUIDefaults

private void updateUIDefaults(javax.swing.LookAndFeel newLnF)

canDock

private boolean canDock(javax.swing.plaf.basic.BasicToolBarUI ui,
                        java.awt.Component component,
                        java.awt.Point point)

updateButtons

private void updateButtons()
Used to handle all the buttons if the appearance is changed on the fly.


main

public static void main(java.lang.String[] args)