public class CollapsibleButtons
extends org.eclipse.swt.widgets.Composite
implements org.eclipse.swt.events.MouseListener, org.eclipse.swt.events.MouseMoveListener, org.eclipse.swt.events.MouseTrackListener
Website
If you want more info or more documentation, please visit: http://www.hexapixel.com
Description
ButtonComposite is a Widget that displays a vertical row of buttons similar
to the way that Microsoft® shows buttons in the bottom left of the
Microsoft Outlook 2005, and 2007 editions. The button bar is a collapsible
bar that contains an image, text, and an associated toolbar at the very
bottom where buttons that are currently "collapsed" are shown. There is also
a menu which is activated by clicking a small arrow icon on the toolbar that
will allow you to do actions that are similar to the actions you can do with
the mouse.
The bar is resized by dragging the handle-bar which is at the very top. When the mouse is clicked on the handlebar and dragged either up or down, buttons will be shown and hidden accordingly. The button bar also has a feature where - if there's no space to show the actively shown buttons due to progam window size, buttons will automatically collapse to conserve space, and then automatically expand back to the original number of visible buttons when the program window is returned to a size where they can be shown.
Where to put it
It is important to point out that due to the nature of the ButtonComposite,
it is important to put it inside a layout that will allow it to
expand/collapse with the widgets that are around it - as whenever a button is
shown/hidden, the actual physical size of the widget changes, which should
cause surrounding widgets to take up either more or less space. I personally
recommend putting the ButtonBar inside either a ViewForm, SashForm.
If you still wish to put it on a plain composite, I suggest doing it the following way:
// outer layer wrapper
Composite bcWrapper = new Composite(parentComposite, SWT.None);
GridLayout gl = new GridLayout(1, true);
gl.marginBottom = 0;
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.marginHeight = 0;
inner.setLayout(gl);
CollapsibleButtons cButtons = new CollapsibleButtons(bcWrapper, SWT.NONE);
// will ensure the composite takes up the appropriate amount of space and gets aligned correctly, we align it at the end as that is where it should live
cButtons.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_END));
cButtons.addButton(...);
Customizing
As many people wish to customize the widget beyond the capabilities it
already has, there are a few ways you may basically take control over as much
or little as you please. First, there are three interfaces that are of
importance (apart from the IButtonListener), one is the IButtonPainter, the
IColorManager and the ISettings. Let's start with the IColorManager.
IColorManager
If you don't specify a color manager, the DefaultColorManager will be used.
The color manager's job is to return colors to the method that is painting
the button when the button is drawn, when you move over a button, when you
select a button, and when you hover over a selected button. The colors that
are returned from the ColorManager will determine everything as far as looks
go.
IButtonPainter
Then there's the IButtonPainter. The IButtonPainter lets you take over 3
methods, which are how A. The background colors of the button are painted. B.
How the text is drawn, and C. How the image is painted. As this is basically
100% of how a button is drawn, you can control every aspect of the button
look and feel. By default, if no IButtonPainter is assigned, the
DefaultButtonPainter will be used. The IButtonPainter's paintBackground(...)
method is also used to draw all aspects of the tool bar. That way, the
toolbar automatically gets the same colors etc like the normal buttons.
ISettings
To control a lot of the features, such as, whether to show the toolbar or
not, whether you want certain size buttons, painted borders, and so on, you
can create a class that implements ISettings and set it as the Settings
manager when you create a ButtonComposite. If you don't specify one,
DefaultSettings will be used.
Each button is esentially a composite inside a custom layout, and the toolbar is a composite by itself.
If a toolbar is not wanted, you may control its visibility by implementing ISettings
Double Buffering
It is also important to note that the widget uses custom double buffering as
neither Windows XP's or SWT's DOUBLE_BUFFER flag do the job well enough. To
do a proper double buffer, the widget is first drawn into a cached Graphics
object that is then copied onto the actual graphics object. This reduces
flickering and other odd widget behavior. If you intend to run the widget on
either Linux or Macintosh (which both know how to double buffer in the OS),
you may turn it off.
Modifier and Type | Class and Description |
---|---|
(package private) class |
CollapsibleButtons.VerticalLayout |
Constructor and Description |
---|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style)
Creates a new ButtonComposite.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
IColorManager colorManager)
Creates a new ButtonComposite.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
ILanguageSettings language)
Creates a new ButtonComposite with a given language manager.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
int theme)
Creates a new ButtonComposite.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
int theme,
IColorManager colorManager)
Creates a new ButtonComposite.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
int theme,
IColorManager colorManager,
ISettings settings,
ILanguageSettings language)
Creates a new ButtonComposite.
|
CollapsibleButtons(org.eclipse.swt.widgets.Composite parent,
int style,
ISettings settings,
ILanguageSettings language)
Creates a new ButtonComposite with a given settings and language manager.
|
Modifier and Type | Method and Description |
---|---|
CustomButton |
addButton(java.lang.String name,
java.lang.String toolTip,
org.eclipse.swt.graphics.Image bigImage,
org.eclipse.swt.graphics.Image toolbarImage)
Adds a button to the composite.
|
void |
addButtonListener(IButtonListener listener)
Adds a new IButtonListener listener that will report clicks and other
events.
|
void |
addMenuListener(IMenuListener listener)
Adds a menu listener that is notified before and after the menu popup is shown.
|
void |
deselectAll()
Deselects all buttons
|
void |
forceLayoutUpdate()
Should you ever need to force a re-layout of the composite, this is the
method to call.
|
IColorManager |
getColorManager()
Returns the active color manager.
|
java.util.List<CustomButton> |
getItems()
Returns the list of all buttons.
|
ILanguageSettings |
getLanguageSettings()
Returns the current Language settings manager.
|
(package private) java.util.List<IMenuListener> |
getMenuListeners() |
int |
getNumVisibleButtons()
Returns the number of currently visible buttons.
|
CustomButton |
getSelection()
Returns the current selection, or null if none.
|
ISettings |
getSettings()
Returns the current Settings manager.
|
org.eclipse.swt.graphics.Point |
getSize() |
ToolbarComposite |
getToolbarComposite()
Returns the toolbar composite.
|
void |
hideButton(CustomButton button)
Hides the given button (and adds it to the toolbar).
|
void |
hideNextButton()
Hides the next button furthest down in the list.
|
boolean |
isVisible(CustomButton button)
If a button is permanently hidden or permanently shown.
|
int |
itemCount()
Returns the number of buttons in the list.
|
void |
mouseDoubleClick(org.eclipse.swt.events.MouseEvent event) |
void |
mouseDown(org.eclipse.swt.events.MouseEvent event) |
void |
mouseEnter(org.eclipse.swt.events.MouseEvent event) |
void |
mouseExit(org.eclipse.swt.events.MouseEvent event) |
void |
mouseHover(org.eclipse.swt.events.MouseEvent event) |
void |
mouseMove(org.eclipse.swt.events.MouseEvent event) |
void |
mouseUp(org.eclipse.swt.events.MouseEvent event) |
void |
permanentlyHideButton(CustomButton button)
Hides the button from the list and the toolbar.
|
void |
permanentlyShowButton(CustomButton button)
Un-hides a button that has been hidden from toolbar and ButtonComposite
view.
|
(package private) void |
remove(CustomButton cb,
boolean callDispose) |
void |
removeAllButtons()
Removes all buttons.
|
void |
removeButton(CustomButton cb)
Same method that is called when
CustomButton.dispose() is called. |
void |
removeButtonListener(IButtonListener listener)
Removes an IButtonListener
|
void |
removeMenuListener(IMenuListener listener)
Removes a menu listener.
|
void |
selectItem(CustomButton button)
Selects a specific CustomButton.
|
void |
selectItemAndLoad(CustomButton button)
Flags a button as selected and pretends it got clicked.
|
void |
showButton(CustomButton button)
Shows the given button (and removes it from the toolbar).
|
void |
showNextButton()
Shows the next button from the list of buttons that are currently hidden.
|
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
mouseDoubleClickAdapter, mouseDownAdapter, mouseUpAdapter
public CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style)
parent
- Parent compositestyle
- Composite style, SWT.NO_BACKGROUND will be appended to the
style.public CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, ILanguageSettings language)
parent
- Parent compositestyle
- stylelanguage
- Language managerpublic CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, ISettings settings, ILanguageSettings language)
parent
- Parent compositestyle
- stylesettings
- Settings managerlanguage
- Language managerpublic CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, int theme)
parent
- Parent compositestyle
- Composite style, SWT.NO_BACKGROUND will be appended to the
styletheme
- IColorManager.STYLE_public CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, IColorManager colorManager)
parent
- Parent compositestyle
- Composite style, SWT.NO_BACKGROUND will be appended to the
stylecolorManager
- IColorManager implementation. Set to null to use the
defaultpublic CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, int theme, IColorManager colorManager)
parent
- Parent compositestyle
- Composite style, SWT.NO_BACKGROUND will be appended to the
styletheme
- IColorManager.STYLE_colorManager
- IColorManager implementation. Set to null to use the
defaultpublic CollapsibleButtons(org.eclipse.swt.widgets.Composite parent, int style, int theme, IColorManager colorManager, ISettings settings, ILanguageSettings language)
parent
- Parent compositestyle
- Composite style, SWT.NO_BACKGROUND will be appended to the
styletheme
- IColorManager.STYLE_colorManager
- IColorManager implementation. Set to null to use the
defaultsettings
- ISettings implementation. Set to null to use the defaultlanguage
- ILanguage implementations. Set to null to use the
default.public void addButtonListener(IButtonListener listener)
listener
- IButtonListenerpublic void removeButtonListener(IButtonListener listener)
listener
- IButtonListenerpublic void mouseMove(org.eclipse.swt.events.MouseEvent event)
mouseMove
in interface org.eclipse.swt.events.MouseMoveListener
public int getNumVisibleButtons()
public void permanentlyHideButton(CustomButton button)
button
- Button to hidepublic void permanentlyShowButton(CustomButton button)
button
- Button to showpublic void hideButton(CustomButton button)
button
- Button to hidepublic void showButton(CustomButton button)
button
- Button to showpublic boolean isVisible(CustomButton button)
button
- CustomButton to checkpublic void hideNextButton()
public void forceLayoutUpdate()
public void showNextButton()
public CustomButton addButton(java.lang.String name, java.lang.String toolTip, org.eclipse.swt.graphics.Image bigImage, org.eclipse.swt.graphics.Image toolbarImage)
name
- Text that should be displayed on button. May be null.toolTip
- Tooltip that is displayed when mouse moves over both
button and tool bar icon. Recommended null.bigImage
- Image displayed on the button. Ideally 24x24 pixels
transparent PNG image.toolbarImage
- Image displayed on the toolbar and on any menu items.
Ideally 16x16 pixels transparent GIF image.public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent event)
mouseDoubleClick
in interface org.eclipse.swt.events.MouseListener
public void mouseDown(org.eclipse.swt.events.MouseEvent event)
mouseDown
in interface org.eclipse.swt.events.MouseListener
public void mouseUp(org.eclipse.swt.events.MouseEvent event)
mouseUp
in interface org.eclipse.swt.events.MouseListener
public org.eclipse.swt.graphics.Point getSize()
getSize
in class org.eclipse.swt.widgets.Control
public void mouseEnter(org.eclipse.swt.events.MouseEvent event)
mouseEnter
in interface org.eclipse.swt.events.MouseTrackListener
public void mouseExit(org.eclipse.swt.events.MouseEvent event)
mouseExit
in interface org.eclipse.swt.events.MouseTrackListener
public void mouseHover(org.eclipse.swt.events.MouseEvent event)
mouseHover
in interface org.eclipse.swt.events.MouseTrackListener
public void selectItemAndLoad(CustomButton button)
button
- Button to select and clickpublic void selectItem(CustomButton button)
button
- CustomButton to selectpublic void deselectAll()
public java.util.List<CustomButton> getItems()
public CustomButton getSelection()
public int itemCount()
public IColorManager getColorManager()
public ISettings getSettings()
public ILanguageSettings getLanguageSettings()
public ToolbarComposite getToolbarComposite()
public void addMenuListener(IMenuListener listener)
listener
- Listener to addpublic void removeMenuListener(IMenuListener listener)
listener
- Listener to removepublic void removeAllButtons()
public void removeButton(CustomButton cb)
CustomButton.dispose()
is called.cb
- CustomButton to removevoid remove(CustomButton cb, boolean callDispose)
java.util.List<IMenuListener> getMenuListeners()