Class ExpandableComposite
- All Implemented Interfaces:
Drawable
- Direct Known Subclasses:
Section
The widget can be instantiated as-is, or subclassed to modify some aspects of it. *
Since 3.1, left/right arrow keys can be used to control the expansion state. If several expandable composites are created in the same parent, up/down arrow keys can be used to traverse between them. Expandable text accepts mnemonics and mnemonic activation will toggle the expansion state.
While expandable composite recognize that different styles can be used to
render the title bar, and even defines the constants for these styles
(TITLE_BAR and SHORT_TITLE_BAR the actual painting
is done in the subclasses.
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIf this style is used, the client origin will be vertically aligned with the title text.intVertical spacing between the title area and the composite client control (default is 3).static final intIf this style is used, computed size of the composite will take the client width into consideration only in the expanded state.intVertical spacing between the title area and the description control (default is 0).static final intIf this style is used, the control will be created in the expanded state.static final intIf this style is used, the title text will be rendered as a hyperlink that can individually accept focus.protected intDeprecated.this variable was left as protected by mistake.static final intBy default, text client is right-aligned.intHeight of the margin that will be added around the control (default is 0).intWidth of the margin that will be added around the control (default is 0).static final intIf this style is used, title will not be rendered.static final intBy default, a focus box is painted around the title when it receives focus.static final intIf this style is used, a short version of the title bar decoration will be painted behind the text.protected ControlThe text label for the title.static final intIf this style is used, title bar decoration will be painted behind the text.intHorizontal margin around the inside of the title bar area when TITLE_BAR or SHORT_TITLE_BAR style is used.protected ToggleHyperlinkThe toggle widget used to expand the composite.static final intIf this style is used, a tree node with either + or - signs will be used to render the expansion toggle.static final intIf this style is used, a twistie will be used to render the expansion toggle.protected intDeprecated.this variable was left as protected by mistake.Fields inherited from class org.eclipse.swt.widgets.Widget
nativeZoom -
Constructor Summary
ConstructorsConstructorDescriptionExpandableComposite(Composite parent, int style) Creates an expandable composite using a TWISTIE toggle.ExpandableComposite(Composite parent, int style, int expansionStyle) Creates the expandable composite in the provided parent. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpansionListener(IExpansionListener listener) Adds the listener that will be notified when the expansion state changes.computeSize(int wHint, int hHint, boolean changed) Computes the size of the expandable composite.booleanForces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.Returns the current expandable client.protected ControlReturns description control that will be placed under the title if present.intReturns the bitwise-ORed style bits for the expansion control.protected ControlReturns the separator control that will be placed between the title and the description if present.getText()Returns the title string.Returns the text client control.intReturns the difference in height between the text and the text client (if set).Returns the title bar foreground when TITLE_BAR style is used.protected booleanTests if this expandable composite renders a title bar around the text.protected voidinternalSetExpanded(boolean expanded) Performs the expansion state change for the expandable control.booleanTests the expanded state of the composite.protected booleanReturns true if the composite is fixed i.e. cannot be expanded or collapsed.protected voidIf TITLE_BAR or SHORT_TITLE_BAR style is used, title bar decoration will be painted behind the text in this method.voidremoveExpansionListener(IExpansionListener listener) Removes the expansion listener.voidSets the active color of the toggle control (when the mouse enters the toggle area).voidsetBackground(Color bg) Sets the background of all the custom controls in the expandable.voidSets the client of this expandable composite.voidsetEnabled(boolean enabled) Enables the receiver if the argument istrue, and disables it otherwise.voidsetExpanded(boolean expanded) Changes expanded state.voidsetExpanded(boolean expanded, boolean fireExpanding) Changes expanded state.voidSets the fonts of all the custom controls in the expandable.voidsetForeground(Color fg) Sets the foreground of all the custom controls in the expandable.final voidPrevents assignment of the layout manager - expandable composite uses its own layout.voidOverrides 'super' to pass the menu to the text label.voidSets the title of the expandable composite.voidsetTextClient(Control textClient) Sets the text client control.voidsetTitleBarForeground(Color color) Sets the color of the title bar foreground when TITLE_BAR style is used.voidSets the color of the toggle control.voidsetToolTipText(String string) Sets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown.Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setIMEMethods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayoutDeferred, setTabList, toStringMethods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar, setScrollbarsModeMethods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, 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, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setLayoutData, setLocation, setLocation, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, updateMethods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, addTypedListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setDataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.swt.graphics.Drawable
isAutoScalable
-
Field Details
-
TWISTIE
public static final int TWISTIEIf this style is used, a twistie will be used to render the expansion toggle.- See Also:
-
TREE_NODE
public static final int TREE_NODEIf this style is used, a tree node with either + or - signs will be used to render the expansion toggle.- See Also:
-
FOCUS_TITLE
public static final int FOCUS_TITLEIf this style is used, the title text will be rendered as a hyperlink that can individually accept focus. Otherwise, it will still act like a hyperlink, but only the toggle control will accept focus.- See Also:
-
CLIENT_INDENT
public static final int CLIENT_INDENTIf this style is used, the client origin will be vertically aligned with the title text. Otherwise, it will start at x = 0.- See Also:
-
COMPACT
public static final int COMPACTIf this style is used, computed size of the composite will take the client width into consideration only in the expanded state. Otherwise, client width will always be taken into account.- See Also:
-
EXPANDED
public static final int EXPANDEDIf this style is used, the control will be created in the expanded state. This state can later be changed programmatically or by the user if TWISTIE or TREE_NODE style is used.- See Also:
-
TITLE_BAR
public static final int TITLE_BARIf this style is used, title bar decoration will be painted behind the text.- See Also:
-
SHORT_TITLE_BAR
public static final int SHORT_TITLE_BARIf this style is used, a short version of the title bar decoration will be painted behind the text. This style is useful when a more discrete option is needed for the title bar.- Since:
- 3.1
- See Also:
-
NO_TITLE
public static final int NO_TITLEIf this style is used, title will not be rendered.- See Also:
-
LEFT_TEXT_CLIENT_ALIGNMENT
public static final int LEFT_TEXT_CLIENT_ALIGNMENTBy default, text client is right-aligned. If this style is used, it will be positioned after the text control and vertically centered with it.- See Also:
-
NO_TITLE_FOCUS_BOX
public static final int NO_TITLE_FOCUS_BOXBy default, a focus box is painted around the title when it receives focus. If this style is used, the focus box will not be painted. This style does not apply when FOCUS_TITLE is used.- Since:
- 3.5
- See Also:
-
marginWidth
public int marginWidthWidth of the margin that will be added around the control (default is 0). -
marginHeight
public int marginHeightHeight of the margin that will be added around the control (default is 0). -
clientVerticalSpacing
public int clientVerticalSpacingVertical spacing between the title area and the composite client control (default is 3). -
descriptionVerticalSpacing
public int descriptionVerticalSpacingVertical spacing between the title area and the description control (default is 0). The description control is normally placed at the new line as defined in the font used to render it. This value will be added to it.- Since:
- 3.3
-
titleBarTextMarginWidth
public int titleBarTextMarginWidthHorizontal margin around the inside of the title bar area when TITLE_BAR or SHORT_TITLE_BAR style is used. This variable is not used otherwise.- Since:
- 3.3
-
toggle
The toggle widget used to expand the composite. -
textLabel
The text label for the title. -
VGAP
Deprecated.this variable was left as protected by mistake. It will be turned into static and hidden in the future versions. Do not use them and do not change its value. -
GAP
Deprecated.this variable was left as protected by mistake. It will be turned into static and hidden in the future versions. Do not use it and do not change its value.
-
-
Constructor Details
-
ExpandableComposite
Creates an expandable composite using a TWISTIE toggle.- Parameters:
parent- the parent compositestyle- SWT style bits
-
ExpandableComposite
Creates the expandable composite in the provided parent.- Parameters:
parent- the parentstyle- the control style (as expected by SWT subclass)expansionStyle- the style of the expansion widget (TREE_NODE, TWISTIE, CLIENT_INDENT, COMPACT, FOCUS_TITLE, LEFT_TEXT_CLIENT_ALIGNMENT, NO_TITLE)
-
-
Method Details
-
forceFocus
public boolean forceFocus()Description copied from class:ControlForces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.- Overrides:
forceFocusin classControl- Returns:
trueif the control got focus, andfalseif it was unable to.- See Also:
-
setMenu
Overrides 'super' to pass the menu to the text label. -
setLayout
Prevents assignment of the layout manager - expandable composite uses its own layout. -
setBackground
Sets the background of all the custom controls in the expandable.- Overrides:
setBackgroundin classControl- Parameters:
bg- the new color (or null)
-
setForeground
Sets the foreground of all the custom controls in the expandable.- Overrides:
setForegroundin classControl- Parameters:
fg- the new color (or null)
-
setToggleColor
Sets the color of the toggle control.- Parameters:
c- the color object
-
setActiveToggleColor
Sets the active color of the toggle control (when the mouse enters the toggle area).- Parameters:
c- the active color object
-
setFont
Sets the fonts of all the custom controls in the expandable. -
setEnabled
public void setEnabled(boolean enabled) Description copied from class:ControlEnables the receiver if the argument istrue, and disables it otherwise. A disabled control is typically not selectable from the user interface and draws with an inactive or "grayed" look.- Overrides:
setEnabledin classControl- Parameters:
enabled- the new enabled state
-
setClient
Sets the client of this expandable composite. The client must not be null and must be a direct child of this container.- Parameters:
client- the client that will be expanded or collapsed
-
getClient
Returns the current expandable client.- Returns:
- the client control
-
setText
Sets the title of the expandable composite. The title will act as a hyperlink and activating it will toggle the client between expanded and collapsed state.- Parameters:
title- the new title string- See Also:
-
setToolTipText
Description copied from class:ControlSets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown. For a control that has a default tool tip, such as the Tree control on Windows, setting the tool tip text to an empty string replaces the default, causing no tool tip text to be shown.The mnemonic indicator (character '&') is not displayed in a tool tip. To display a single '&' in the tool tip, the character '&' can be escaped by doubling it in the string.
NOTE: This operation is a hint and behavior is platform specific, on Windows for CJK-style mnemonics of the form " (&C)" at the end of the tooltip text are not shown in tooltip.
- Overrides:
setToolTipTextin classControl- Parameters:
string- the new tool tip text (or null)
-
getText
Returns the title string.- Returns:
- the title string
- See Also:
-
isExpanded
public boolean isExpanded()Tests the expanded state of the composite.- Returns:
- true if expanded, false if collapsed.
-
getExpansionStyle
public int getExpansionStyle()Returns the bitwise-ORed style bits for the expansion control.- Returns:
- the bitwise-ORed style bits for the expansion control
-
setExpanded
public void setExpanded(boolean expanded) Changes expanded state. Equivalent tosetExpanded(expanded, false).- Parameters:
expanded- the new expanded state- See Also:
-
setExpanded
public void setExpanded(boolean expanded, boolean fireExpanding) Changes expanded state.- Parameters:
expanded- the new expanded statefireExpanding- if true, listeners will be notified- Since:
- 3.13
-
internalSetExpanded
protected void internalSetExpanded(boolean expanded) Performs the expansion state change for the expandable control.- Parameters:
expanded- the expansion state
-
addExpansionListener
Adds the listener that will be notified when the expansion state changes.- Parameters:
listener- the listener to add
-
removeExpansionListener
Removes the expansion listener.- Parameters:
listener- the listener to remove
-
onPaint
If TITLE_BAR or SHORT_TITLE_BAR style is used, title bar decoration will be painted behind the text in this method. The default implementation does nothing - subclasses are responsible for rendering the title area.- Parameters:
e- the paint event
-
getDescriptionControl
Returns description control that will be placed under the title if present.- Returns:
- the description control or null if not used.
-
getSeparatorControl
Returns the separator control that will be placed between the title and the description if present.- Returns:
- the separator control or null if not used.
-
computeSize
Computes the size of the expandable composite.- Overrides:
computeSizein classControl- Parameters:
wHint- the width hint (can beSWT.DEFAULT)hHint- the height hint (can beSWT.DEFAULT)changed-trueif the control's contents have changed, andfalseotherwise- Returns:
- the preferred size of the control.
- See Also:
-
isFixedStyle
protected boolean isFixedStyle()Returns true if the composite is fixed i.e. cannot be expanded or collapsed. Fixed control will still contain the title, separator and description (if present) as well as the client, but will be in the permanent expanded state and the toggle affordance will not be shown.- Returns:
- true if the control is fixed in the expanded state, false if it can be collapsed.
-
getTextClient
Returns the text client control.- Returns:
- Returns the text client control if specified, or
nullif not.
-
setTextClient
Sets the text client control. Text client is a control that is a child of the expandable composite and is placed to the right of the text. It can be used to place small image hyperlinks. If more than one control is needed, use Composite to hold them. Care should be taken that the height of the control is comparable to the height of the text.- Parameters:
textClient- the textClient to set ornullif not needed any more.
-
getTextClientHeightDifference
public int getTextClientHeightDifference()Returns the difference in height between the text and the text client (if set). This difference can cause vertical alignment problems when two expandable composites are placed side by side, one with and one without the text client. Use this method obtain the value to add to eitherdescriptionVerticalSpacing(if you have description) orclientVerticalSpacingto correct the alignment of the expandable without the text client.- Returns:
- the difference in height between the text and the text client or 0 if no corrective action is needed.
- Since:
- 3.3
-
hasTitleBar
protected boolean hasTitleBar()Tests if this expandable composite renders a title bar around the text.- Returns:
trueforTITLE_BARorSHORT_TITLE_BARstyles,falseotherwise.
-
setTitleBarForeground
Sets the color of the title bar foreground when TITLE_BAR style is used.- Parameters:
color- the title bar foreground
-
getTitleBarForeground
Returns the title bar foreground when TITLE_BAR style is used.- Returns:
- the title bar foreground
-