com.tensegrity.gui.swt.control
Class SwtToolBar

java.lang.Object
  extended byorg.eclipse.swt.widgets.Widget
      extended byorg.eclipse.swt.widgets.Control
          extended byorg.eclipse.swt.widgets.Scrollable
              extended byorg.eclipse.swt.widgets.Composite
                  extended bycom.tensegrity.gui.swt.control.SwtToolBar
All Implemented Interfaces:
BasicComponent, DocumentListener, org.eclipse.swt.graphics.Drawable, Evaluable, EventListenerTag, GraphPanelListener, ToolBar

public class SwtToolBar
extends org.eclipse.swt.widgets.Composite
implements ToolBar, Evaluable, DocumentListener, GraphPanelListener

This is the SWT implementation of the ToolBar interface.

It is the caller's responsability to set a layout data to this Composite.

Since the SWT recommendation is to NOT subclass ToolBar, this class simply extends Composite and internally manages an instance of ToolBar.

The internal ToolBar instance can be accessed through the getSwtToolBar() method. It is required to use this method when adding ToolItem s to the toolbar.

The addItem(Command, String, Class) and addItem(Command, String, Class, String) methods can be used in order to add ToolItem s to the toolbar.

Use addSeparator() in order to insert separators to the toolbar.

Use the indexOf(String) method in order to retrieve the index of a particular ToolItem.

Note that although this class is a subclass of Composite, it does not make sense to set a layout on it. The setLayout(Layout) method should therefore not be used.

Version:
$Id: SwtToolBar.java,v 1.14 2005/09/15 14:41:14 SebastienGuyon Exp $
Author:
S�bastien Guyon

Nested Class Summary
 class SwtToolBar.SwtToolbarToolTipGenerator
           This is a SwtToolTipGenerator implementation for the SwtToolbar.
 
Field Summary
static java.lang.String TOOLITEM_COMMAND_ID
          Key used to store the command along with each ToolItem added to the ToolBar.
static java.lang.String TOOLITEM_TOOLTIP_ID
          Key used to store the tooltips id along with each ToolItem added to the ToolBar.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
protected SwtToolBar(org.eclipse.swt.widgets.Composite parent, int style, UIManager uiManager)
          
This constructor initializes the internal ToolBar instance with a style style.
protected SwtToolBar(org.eclipse.swt.widgets.Composite parent, int style, UIManager uiManager, int orientation)
           This constructor initializes the internal ToolBar instance with a style style.
  SwtToolBar(org.eclipse.swt.widgets.Composite parent, int style, UIManager uiManager, java.lang.String id)
           This constructor initializes the internal ToolBar instance with a style style.
  SwtToolBar(org.eclipse.swt.widgets.Composite parent, int style, UIManager uiManager, java.lang.String id, int orientation)
           This constructor initializes the internal ToolBar instance with a style style.
 
Method Summary
 void acted(int actID)
          Invoked after each interaction cycle.
 org.eclipse.swt.widgets.ToolItem addItem(Command command, java.lang.String iconurl, java.lang.Class resourceClass)
           This method add a ToolItem to the internal ToolBar.
 org.eclipse.swt.widgets.ToolItem addItem(Command command, java.lang.String iconurl, java.lang.Class resourceClass, java.lang.String tooltipId)
           This method add a ToolItem to the internal ToolBar.
 void addSeparator()
           This method simply adds a separator to the toolbar.
 void addSeparator(int index)
           This method simply adds a separator to the toolbar.
 void applyEvList()
          Refreshes the tooltip string associated to each ToolItem of the internal ToolBar.
 void documentAdded(DocumentEvent documentevent)
          Invoked after a document was added to the mdicomponent.
 void documentModelChanged(DocumentEvent documentevent)
          Invoked after a document's model has changed.
 void documentPreAdd(DocumentEvent documentevent)
          Invoked when a document is about to be added to a mdicomponent.
 void documentPreRemove(DocumentEvent documentevent)
          Invoked when a document is about to be removed from a mdicomponent.
 void documentRemoved(DocumentEvent documentevent)
          Invoked after a document was removed from the mdicomponent.
 void documentSelected(DocumentEvent documentevent)
          Invoked after a document was selected in the mdicomponent.
 void documentUnselected(DocumentEvent documentevent)
          Invoked after a document was unselected in the mdicomponent.
 int getHeight()
          Returns the height of the component in pixels.
 java.lang.String getName()
          A toolbar should provide a human readable name.
 BasicComponent getParentComponent()
          Returns the parent Component of this instance.
 org.eclipse.swt.widgets.ToolBar getSwtToolBar()
          Returns the wrapped ToolBar instance.
 SwtToolTipGenerator getTooltipGenerator()
          Returns the tooltipGenerator.
 int getWidth()
          Returns the width of the component in pixels.
 int indexOf(java.lang.String id)
          Note that the returned value validity is not guaranteed if the toolbar contains more than one ToolItem associated to the same command.
 void installEvList()
          Tells the component to setup its internal state.
 void postAction()
          Invoked when a user interaction has completed on a GraphPanel this instance of GraphPanelListener is registered with.
 void postDropBaseComposite(BaseComposite baseComposite)
          Invoked when a BaseComposite was dragged and dropped onto the GraphPanel this GraphPanelListener.
 void postMouseClick()
          Invoked when a mouse click has completed on a GraphPanel this instance of GraphPanelListener is registered with.
 void preAction()
          Invoked when a user interaction is about to begin on a GraphPanel this instance of GraphPanelListener is registered with.
 void repaint()
          Triggers a repaint.
 void setLayout(org.eclipse.swt.widgets.Layout layout)
           This method is overwritten and throws a runtime exception if used.
 void setTooltipGenerator(SwtToolTipGenerator tooltipGenerator)
          Set the SwtToolTipGenerator.
 void updateStatus()
          This method is used to keep the state of the toolbar up-to-date.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
checkSubclass, computeSize, getChildren, getLayout, getTabList, layout, layout, setFocus, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setCursor, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOOLITEM_TOOLTIP_ID

public static java.lang.String TOOLITEM_TOOLTIP_ID
Key used to store the tooltips id along with each ToolItem added to the ToolBar. See ToolItem.setData().


TOOLITEM_COMMAND_ID

public static java.lang.String TOOLITEM_COMMAND_ID
Key used to store the command along with each ToolItem added to the ToolBar. See ToolItem.setData().

Constructor Detail

SwtToolBar

protected SwtToolBar(org.eclipse.swt.widgets.Composite parent,
                     int style,
                     UIManager uiManager)


This constructor initializes the internal ToolBar instance with a style style. The GridData style of the internal ToolBar is set to GridData.FILL_HORIZONTAL. Do not use this constructor since it does not define the toolbar Id. Subclasses might have a need for it so it is declared as protected.

Parameters:
parent - The toolbar parent container
style - The internal ToolBar style
uiManager - The UIManager used for this toolbar localized strings.

SwtToolBar

public SwtToolBar(org.eclipse.swt.widgets.Composite parent,
                  int style,
                  UIManager uiManager,
                  java.lang.String id)

This constructor initializes the internal ToolBar instance with a style style. The GridData style of the internal ToolBar is set to GridData.FILL_HORIZONTAL.

Parameters:
parent - The toolbar parent container
style - The internal ToolBar style
uiManager - The UIManager used for this toolbar localized strings.
id - Identifier of the GUI resource for the title of this ToolBar

SwtToolBar

protected SwtToolBar(org.eclipse.swt.widgets.Composite parent,
                     int style,
                     UIManager uiManager,
                     int orientation)

This constructor initializes the internal ToolBar instance with a style style. The GridData style of the internal ToolBar is set to orientation. Do not use this constructor since it does not define the toolbar Id. Subclasses might have a need for it so it is declared as protected.

Parameters:
parent - The toolbar parent container
style - The internal ToolBar style
uiManager - The UIManager used for this toolbar localized strings.
orientation - The GridData style of the internal ToolBar. One of SWT.HORIZONTAL or SWT.VERTICAL.

SwtToolBar

public SwtToolBar(org.eclipse.swt.widgets.Composite parent,
                  int style,
                  UIManager uiManager,
                  java.lang.String id,
                  int orientation)

This constructor initializes the internal ToolBar instance with a style style. The GridData style of the internal ToolBar is set to orientation.

Parameters:
parent - The toolbar parent container
style - The internal ToolBar style
uiManager - The UIManager used for this toolbar localized strings.
id - Identifier of the GUI resource for the title of this ToolBar
orientation - The GridData style of the internal ToolBar .One of SWT.HORIZONTAL or SWT.VERTICAL.
Method Detail

setLayout

public void setLayout(org.eclipse.swt.widgets.Layout layout)

This method is overwritten and throws a runtime exception if used. The SwtToolbar internally manages its layout.

See Also:
Composite.setLayout(org.eclipse.swt.widgets.Layout)

addSeparator

public void addSeparator()

This method simply adds a separator to the toolbar.


addSeparator

public void addSeparator(int index)

This method simply adds a separator to the toolbar.

Parameters:
index - the separator position

addItem

public org.eclipse.swt.widgets.ToolItem addItem(Command command,
                                                java.lang.String iconurl,
                                                java.lang.Class resourceClass)

This method add a ToolItem to the internal ToolBar. The passed Command id is used as GUI identifier for the item's tooltip.

Parameters:
command - The command associated with the new ToolItem
iconurl - location of the icon, relative to resourceClass
resourceClass - the reference class used to retrieve the icon
Returns:
the newly created ToolItem

addItem

public org.eclipse.swt.widgets.ToolItem addItem(Command command,
                                                java.lang.String iconurl,
                                                java.lang.Class resourceClass,
                                                java.lang.String tooltipId)

This method add a ToolItem to the internal ToolBar. The passed Command id is used as GUI identifier for the item tooltip.

Parameters:
command - The command associated with the new ToolItem
iconurl - location of the icon, relative to resourceClass
resourceClass - the reference class used to retrieve the icon
tooltipId - GUI identifier for the item's tooltip.
Returns:
the newly created ToolItem

indexOf

public int indexOf(java.lang.String id)
Note that the returned value validity is not guaranteed if the toolbar contains more than one ToolItem associated to the same command.

Specified by:
indexOf in interface ToolBar
Parameters:
id - the id of command.
Returns:
the index of the component or -1 if no such component was found.
See Also:
ToolBar.indexOf(java.lang.String)

updateStatus

public void updateStatus()
Description copied from interface: ToolBar
This method is used to keep the state of the toolbar up-to-date.

Specified by:
updateStatus in interface ToolBar

installEvList

public void installEvList()
Description copied from interface: Evaluable
Tells the component to setup its internal state.

Specified by:
installEvList in interface Evaluable

applyEvList

public void applyEvList()
Refreshes the tooltip string associated to each ToolItem of the internal ToolBar.

Specified by:
applyEvList in interface Evaluable
See Also:
Evaluable.applyEvList()

documentAdded

public void documentAdded(DocumentEvent documentevent)
Description copied from interface: DocumentListener
Invoked after a document was added to the mdicomponent.

Specified by:
documentAdded in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.

documentModelChanged

public void documentModelChanged(DocumentEvent documentevent)
Description copied from interface: DocumentListener
Invoked after a document's model has changed. This means the data behind the document has changed subtantially and needs to be rehashed.

Specified by:
documentModelChanged in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.

documentPreAdd

public void documentPreAdd(DocumentEvent documentevent)
                    throws DocumentEventVetoException
Description copied from interface: DocumentListener
Invoked when a document is about to be added to a mdicomponent. If the implementor throws the declared exception then the documentevent will be veto'd and the corresponding action will not be commence.

Specified by:
documentPreAdd in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.
Throws:
DocumentEventVetoException - indicates that the documentevent is not desired.

documentPreRemove

public void documentPreRemove(DocumentEvent documentevent)
                       throws DocumentEventVetoException
Description copied from interface: DocumentListener
Invoked when a document is about to be removed from a mdicomponent. If the implementor throws the declared exception then the documentevent will be veto'd and the corresponding action will not be commence.

Specified by:
documentPreRemove in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.
Throws:
DocumentEventVetoException - indicates that the documentevent is not desired.

documentRemoved

public void documentRemoved(DocumentEvent documentevent)
Description copied from interface: DocumentListener
Invoked after a document was removed from the mdicomponent.

Specified by:
documentRemoved in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.

documentSelected

public void documentSelected(DocumentEvent documentevent)
Description copied from interface: DocumentListener
Invoked after a document was selected in the mdicomponent.

Specified by:
documentSelected in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.

documentUnselected

public void documentUnselected(DocumentEvent documentevent)
Description copied from interface: DocumentListener
Invoked after a document was unselected in the mdicomponent.

Specified by:
documentUnselected in interface DocumentListener
Parameters:
documentevent - the documentevent structure carrying information.

postDropBaseComposite

public void postDropBaseComposite(BaseComposite baseComposite)
Description copied from interface: GraphPanelListener
Invoked when a BaseComposite was dragged and dropped onto the GraphPanel this GraphPanelListener.

Specified by:
postDropBaseComposite in interface GraphPanelListener
Parameters:
baseComposite - the

preAction

public void preAction()
Description copied from interface: GraphPanelListener
Invoked when a user interaction is about to begin on a GraphPanel this instance of GraphPanelListener is registered with. the GraphPanel this GraphPanelListener.

Specified by:
preAction in interface GraphPanelListener

acted

public void acted(int actID)
Description copied from interface: GraphPanelListener
Invoked after each interaction cycle. This method should be used with care, as the operations that are potentially done in this method affect the perceived and actual performance of interaction.

Specified by:
acted in interface GraphPanelListener
Parameters:
actID - integer id that holds one of the values defined in InteractionConstants that are prefixed with ACT*; The id gives additional info about the type of interaction that actually occured (e.g. whether a composite was manipulated or whether one or many composites were moved.

postAction

public void postAction()
Description copied from interface: GraphPanelListener
Invoked when a user interaction has completed on a GraphPanel this instance of GraphPanelListener is registered with. the GraphPanel this GraphPanelListener.

Specified by:
postAction in interface GraphPanelListener

postMouseClick

public void postMouseClick()
Description copied from interface: GraphPanelListener
Invoked when a mouse click has completed on a GraphPanel this instance of GraphPanelListener is registered with.

Specified by:
postMouseClick in interface GraphPanelListener

getParentComponent

public BasicComponent getParentComponent()
Description copied from interface: BasicComponent
Returns the parent Component of this instance.

Specified by:
getParentComponent in interface BasicComponent
Returns:
the parent component or null if no parent exists.

getName

public java.lang.String getName()
Description copied from interface: ToolBar
A toolbar should provide a human readable name. That allows to identify such a toolbar in a Toolbar menu or allows to give the enclosing frame a title, when such a bar is dragged out of its container.

Specified by:
getName in interface ToolBar
Returns:
the name of the a toolbar.

getHeight

public int getHeight()
Description copied from interface: BasicComponent
Returns the height of the component in pixels.

Specified by:
getHeight in interface BasicComponent
Returns:
the height of the component in pixels.

getWidth

public int getWidth()
Description copied from interface: BasicComponent
Returns the width of the component in pixels.

Specified by:
getWidth in interface BasicComponent
Returns:
the width of the component in pixels.

repaint

public void repaint()
Description copied from interface: BasicComponent
Triggers a repaint.

Specified by:
repaint in interface BasicComponent

getSwtToolBar

public final org.eclipse.swt.widgets.ToolBar getSwtToolBar()
Returns the wrapped ToolBar instance.

Returns:
the wrapped ToolBar instance

getTooltipGenerator

public SwtToolTipGenerator getTooltipGenerator()
Returns the tooltipGenerator.

Returns:
the tooltipGenerator.

setTooltipGenerator

public void setTooltipGenerator(SwtToolTipGenerator tooltipGenerator)
Set the SwtToolTipGenerator. If a SwtToolTipGenerator was already set it is unregistered from the SwtToolTipManager.

Parameters:
tooltipGenerator - The tooltipGenerator to set.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.