swingwtx.swing
Class JToolBar

java.lang.Object
  extended byswingwt.awt.Component
      extended byswingwt.awt.Container
          extended byswingwtx.swing.JComponent
              extended byswingwtx.swing.JToolBar
All Implemented Interfaces:
ImageObserver, MenuContainer, SwingConstants

public class JToolBar
extends JComponent
implements SwingConstants

This class is now not only fully 'swing-y', but also mirrors correctly to SWT. Also, this class's peer, JToolBar has the option to be contained within a CoolBar. Rob: Unfortunately, this class can never support embedded components the way that Swing does, so we can't use this as the "main" Toolbar implementation. Instead, this allows Swing functionality with actions to the platform toolbar, regular JToolBar will behave like Swing. Daniel: Au cantrare, my pessimistic friend! :) I have done what you say this class can never do. This class really is now fully swing-y and does support placing strange components within itself. The key to the hack is not having the JToolbar class control a ToolBar peer, but a Composite peer. Then we add ToolBar(s) and Composite(s) as needed to give the native look within the CoolBar or without the CoolBar if nessissary. You have to admit, this class has earned the right to be the default implementation. Perhaps we could do a JToolBarNonNative? ;) Rob: Very funny - I'll hack on this a bit and we'll use it as the main implmentation (you win!) Daniel: I made some minor changes to this class, adding the overloaded methods to add(JCheckBox) and add(JRadioButton) so as to enable the corresponding SWT widget functionality in SwingWT.


Nested Class Summary
 class JToolBar.ToolBarUI
          Temparary storage for the ToolBarUI class.
 
Nested classes inherited from class swingwtx.swing.JComponent
JComponent.InternalFrameSelectionListener
 
Field Summary
protected  boolean coolbar
           
protected  org.eclipse.swt.widgets.Composite lastAdd
          Last added component - used to determine when to use ToolBar/Composite
protected  int orientation
           
protected  Container parent
           
protected  org.eclipse.swt.widgets.Composite ppeer
           
protected  boolean rollover
           
protected  java.lang.String titleString
           
 
Fields inherited from class swingwtx.swing.JComponent
accessibleContext, actionMap, ancestorInputMap, border, clientProperties, descendantHasPeer, focusInputMap, internalFrameAdapter, internalFrameParent, opaque, propertyChangeListeners, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, windowInputMap
 
Fields inherited from class swingwt.awt.Container
composite, comps, containerListeners, layout, queuedValidateRequest
 
Fields inherited from class swingwt.awt.Component
actionCommand, actionListeners, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListeners, componentName, consumeAvailableHeight, consumeAvailableWidth, focusable, focusListeners, graphicsConfig, inputMethodListeners, isUserSetFont, keyListeners, layoutModifier, LEFT_ALIGNMENT, LOCK, mouseListeners, mouseMotionListeners, mouseWheelListeners, pBackground, pCursor, pDoubleBuffered, peer, pEnabled, pFont, pForeground, pLayoutData, pLocation, pMaxSize, pMinSize, pPrefSize, pSize, pToolTipText, pVisible, RIGHT_ALIGNMENT, swingWTDefaultActionEventAdapter, swingWTEventAdapter, TOP_ALIGNMENT
 
Fields inherited from interface swingwtx.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 swingwt.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JToolBar()
           
JToolBar(int orientation)
           
JToolBar(java.lang.String titleString)
           
JToolBar(java.lang.String titleString, int orientation)
           
 
Method Summary
 JButton add(Action a)
          What the heck is this method supposed to return? Rob: Create a protected constructor for JButton for this eventuality, and use it to create a wrapper for the ToolItem.
 Component add(Component c)
          We can add a component through this method to the JToolBar and have it go side by side with the ToolItems.
 Component add(JButton b)
          This handy overload will map JButtons to Actions for you - making your buttons look ace :)
 Component add(JCheckBox checkBox)
          map to a SWT.CHECK style ToolItem ..
 Component add(JRadioButton radioButton)
          map to a SWT.RADIO style ToolItem ..
 void addSeparator()
           
 Component getComponentAtIndex(int index)
           
 int getComponentIndex(Component c)
           
 Insets getMargin()
           
 int getOrientation()
           
 JToolBar.ToolBarUI getUI()
           
 void invalidate()
          Overrides normal component invalidation as we are using an SWT layout.
 boolean isBorderPainted()
          I have no clue which platforms support border painting and which don't.
 boolean isFloatable()
           
 boolean isRollover()
           
 void setBorderPainted(boolean b)
          Controlled by the native widget.
 void setFloatable(boolean b)
          I've dropped these.
 void setMargin(Insets insets)
          Sorry, controlled by the native widgets.
 void setOrientation(int orientation)
           
 void setRollover(boolean b)
          WARNING: MacOS X by default doesn't use toolbar rollovers.
 void setSwingWTParent(Container parent)
          Callback for when this JComponent is added to a container.
 void setUI(JToolBar.ToolBarUI ui)
           
 
Methods inherited from class swingwtx.swing.JComponent
add, add, add, add, addPropertyChangeListener, addPropertyChangeListener, checkInternalFrameChild, dispose, getAccessibleContext, getActionMap, getAutoscrolls, getBorder, getClientProperty, getInputMap, getInsets, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isValidateRoot, paint, paintBackground, paintChildren, paintComponent, paintImmediately, paintImmediately, putClientProperty, remove, remove, removePropertyChangeListener, removePropertyChangeListener, repaint, revalidate, scrollRectToVisible, setActionMap, setAutoscrolls, setBorder, setDoubleBuffered, setInputMap, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled
 
Methods inherited from class swingwt.awt.Container
addComponentToLayout, addContainerListener, debug_showContainmentTree, doAdd, doLayout, getComponent, getComponentCount, getComponentOrientation, getComponents, getComposite, getLayout, getMaximumSize, getMinimumSize, getParent, getPreferredSize, minimumSize, preferredSize, processContainerEvent, processEvent, queuedValidate, removeAll, removeComponentFromCache, removeContainerListener, setLayout, setLayoutImpl, validate
 
Methods inherited from class swingwt.awt.Component
add, addActionListener, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, calculatePreferredSize, componentOnlyDispose, computePreferredSize, contains, contains, createImage, createListenerArrayFromVector, createVolatileImage, dispatchEvent, getActionCommand, getAlignmentX, getAlignmentY, getBackground, getBounds, getCursor, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getListeners, getLocation, getLocationOnScreen, getName, getPeer, getPeerSize, getSize, getSize, getSWTPeer, getToolkit, getToolTipText, getTreeLock, getWidth, getX, getY, grabFocus, hasFocus, hasSetFont, hide, imageUpdate, inside, isEnabled, isFocusable, isMinimumSizeSet, isShowing, isVisible, processActionEvent, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, processTraverseEvent, registerActionEvents, registerComponentEvents, registerEvents, registerExtendedModifyEvents, registerFocusEvents, registerKeyEvents, registerModifyEvents, registerMouseEvents, registerPaintEvents, registerTraversalEvents, remove, removeActionListener, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, repaint, repaint, repaint, requestFocus, setActionCommand, setAlignmentX, setAlignmentY, setBackground, setBounds, setBounds, setCachedProperties, setComponentOrientation, setComponentRemoved, setCursor, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setFont, setForeground, setHeight, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setSize, setSize, setToolTipText, setVisible, setWidth, show, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastAdd

protected org.eclipse.swt.widgets.Composite lastAdd
Last added component - used to determine when to use ToolBar/Composite


orientation

protected int orientation

titleString

protected java.lang.String titleString

coolbar

protected boolean coolbar

rollover

protected boolean rollover

parent

protected Container parent

ppeer

protected org.eclipse.swt.widgets.Composite ppeer
Constructor Detail

JToolBar

public JToolBar()

JToolBar

public JToolBar(java.lang.String titleString)

JToolBar

public JToolBar(int orientation)

JToolBar

public JToolBar(java.lang.String titleString,
                int orientation)
Method Detail

getOrientation

public int getOrientation()

setOrientation

public void setOrientation(int orientation)
Parameters:
orientation -

isRollover

public boolean isRollover()

setRollover

public void setRollover(boolean b)
WARNING: MacOS X by default doesn't use toolbar rollovers. For the sake of a consistant LAF, don't use them on that platform.

Parameters:
b -

getComponentAtIndex

public Component getComponentAtIndex(int index)
Parameters:
index -
Returns:

getComponentIndex

public int getComponentIndex(Component c)
Parameters:
c -
Returns:

getMargin

public Insets getMargin()
Returns:
insets The margin of the Composite peer in Insets form.

setMargin

public void setMargin(Insets insets)
Sorry, controlled by the native widgets.

Overrides:
setMargin in class JComponent
Parameters:
insets -

invalidate

public void invalidate()
Overrides normal component invalidation as we are using an SWT layout.

Overrides:
invalidate in class Container

getUI

public JToolBar.ToolBarUI getUI()

setUI

public void setUI(JToolBar.ToolBarUI ui)

setBorderPainted

public void setBorderPainted(boolean b)
Controlled by the native widget. Implemented solely to allow compilation.

Parameters:
b -

isBorderPainted

public boolean isBorderPainted()
I have no clue which platforms support border painting and which don't.

Returns:

isFloatable

public boolean isFloatable()

setFloatable

public void setFloatable(boolean b)
I've dropped these. The toolbar simply can't support it, and the one-coolbar per shell thing is too inflexible. The Swing-y way is to use JCoolBar - even though it isn't a real Swing thing. After all, who uses floatable toolbars???? Daniel: Actually, I use floatable ToolBars and I need this functionality. Since we don't want to put it in JToolBar, we might want to leave the JCoolBar class in place.


addSeparator

public void addSeparator()

setSwingWTParent

public void setSwingWTParent(Container parent)
                      throws java.lang.Exception
Description copied from class: JComponent
Callback for when this JComponent is added to a container.

Overrides:
setSwingWTParent in class JComponent
Throws:
java.lang.Exception

add

public Component add(JButton b)
This handy overload will map JButtons to Actions for you - making your buttons look ace :)


add

public Component add(JCheckBox checkBox)
map to a SWT.CHECK style ToolItem .. but in the meantime lets not break it as a container eh?

Parameters:
checkBox -

add

public Component add(JRadioButton radioButton)
map to a SWT.RADIO style ToolItem .. but in the meantime lets not break it as a container eh?

Parameters:
radioButton -

add

public Component add(Component c)
We can add a component through this method to the JToolBar and have it go side by side with the ToolItems. Rob: Added support for separators

Overrides:
add in class JComponent

add

public JButton add(Action a)
What the heck is this method supposed to return? Rob: Create a protected constructor for JButton for this eventuality, and use it to create a wrapper for the ToolItem. Rob: 9/1/04 Done it :-) Daniel: I made some minor changes to this class and specifically this method to enable rollovers. Hope you aprove! :-)

Parameters:
a -