Class Form
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.ui.forms.widgets.Form
-
- All Implemented Interfaces:
Drawable
public class Form extends Composite
Form is a custom control that renders a title and an optional background image above the body composite. It can be used alone when part of parents that are scrolled. If scrolling is required, useScrolledForminstead because it has an instance ofFormand adds scrolling capability.Form can have a title if set. If not set, title area will not be left empty - form body will be resized to fill the entire form. In addition, an optional title image can be set and is rendered to the left of the title (since 3.2).
Form can have a title drop down menu if the menu bar manager is not empty (since 3.3).
Form title can support drag and drop if drag and drop support methods are invoked. When used, additional decoration is rendered behind the title to reinforce the drag and drop ability (since 3.3).
The form supports status messages. These messages can have various severity (error, warning, info or none). If status hyperlink handler is specified, the messages with the specified severity other than none will be rendered as hyperlinks.
Form can have a background image behind the title text. The image is tiled as many times as needed to fill the title area. Alternatively, gradient background can be painted vertically or horizontally.
Form can be put in a 'busy' state. While in this state, title image is replaced with an animation that lasts as long as the 'busy' state is active.
It is possible to create an optional head client control. When created, this control is placed in the form heading as a second row.
Form has a custom layout manager that is wrap-enabled. If a form is placed in a composite whose layout manager implements ILayoutExtension, the body of the form will participate in wrapping as long as its layout manager implements ILayoutExtension as well.
Children of the form should typically be created using FormToolkit to match the appearance and behaviour. When creating children, use the form body as a parent by calling 'getBody()' on the form instance. Example:
FormToolkit toolkit = new FormToolkit(parent.getDisplay()); Form form = toolkit.createForm(parent); form.setText("Sample form"); form.getBody().setLayout(new GridLayout()); toolkit.createButton(form.getBody(), "Checkbox", SWT.CHECK);No layout manager has been set on the body. Clients are required to set the desired layout manager explicitly.
Although the class is not final, it should not be subclassed.
- Since:
- 3.0
- Restriction:
- This class is not intended to be subclassed by clients.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMessageHyperlinkListener(IHyperlinkListener listener)Adds a message hyperlink listener.voidaddTitleDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener)Adds support for dragging items out of the form title area via a user drag-and-drop operation.voidaddTitleDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener)Adds support for dropping items into the form title area via a user drag-and-drop operation.ImagegetBackgroundImage()Returns the optional background image of the form head.intgetBackgroundImageAlignment()Deprecated.due to the underlying widget limitations, background image is either painted at 0,0 and/or tiled.CompositegetBody()Returns the container that occupies the body of the form (the form area below the title).IMessage[]getChildrenMessages()Returns the children messages that the cause of the summary message currently set on the form.CompositegetHead()Returns the container that occupies the head of the form (the form area above the body).ControlgetHeadClient()Returns the optional head client if set.ColorgetHeadColor(String key)Returns the color that is currently use to paint an aspect of the form heading, ornullif not defined.ImagegetImage()Returns the title image that will be rendered to the left of the title.IMenuManagergetMenuManager()Returns the menu manager that is used to manage title area drop-down menu items.StringgetMessage()IMessageManagergetMessageManager()Returns the message manager that will keep track of messages in this form.intgetMessageType()ColorgetSeparatorColor()Deprecated.usegetHeadColor(IFormColors.H_BOTTOM_KEYLINE2)StringgetText()Returns the title text that will be rendered at the top of the form.IToolBarManagergetToolBarManager()Returns the tool bar manager that is used to manage tool items in the form's title area.intgetToolBarVerticalAlignment()Returns the current tool bar alignment (if used).booleanisBackgroundImageClipped()Deprecated.due to the underlying widget limitations, background image is always clipped.booleanisBackgroundImageTiled()Tests if the background image is tiled to cover the entire area of the form heading.booleanisBusy()Tests if the form is in the 'busy' state.booleanisSeparatorVisible()Tests if the form head separator is visible.voidremoveMessageHyperlinkListener(IHyperlinkListener listener)Remove the message hyperlink listener.voidsetBackground(Color bg)Sets the background color of the form.voidsetBackgroundImage(Image backgroundImage)Sets the optional background image to be rendered behind the title starting at the position 0,0.voidsetBackgroundImageAlignment(int backgroundImageAlignment)Deprecated.due to the underlying widget limitations, background image is always tiled and alignment cannot be controlled.voidsetBackgroundImageClipped(boolean backgroundImageClipped)Deprecated.due to the underlying widget limitations, background image is always clipped.voidsetBackgroundImageTiled(boolean backgroundImageTiled)Sets whether the header background image is repeated to cover the entire heading area or not.voidsetBusy(boolean busy)Sets the form's busy state.voidsetFont(Font font)Sets the font of the header text.voidsetForeground(Color fg)Sets the foreground color of the form.voidsetHeadClient(Control headClient)Sets the optional head client.voidsetHeadColor(String key, Color color)Sets the color used to paint an aspect of the form heading.voidsetImage(Image image)Sets the image to be rendered to the left of the title.voidsetLayout(Layout layout)Prevents from changing the custom control layout.voidsetMenu(Menu menu)Passes the menu to the form body.voidsetMessage(String message)Sets the message for this form.voidsetMessage(String newMessage, int newType)Sets the message for this form with an indication of what type of message it is.voidsetMessage(String newMessage, int newType, IMessage[] children)Sets the message for this form with an indication of what type of message it is.voidsetSeparatorColor(Color separatorColor)Deprecated.usesetHeadColor(IFormColors.H_BOTTOM_KEYLINE2, separatorColor)voidsetSeparatorVisible(boolean addSeparator)If set, adds a separator between the head and body.voidsetText(String text)Sets the text to be rendered at the top of the form above the body as a title.voidsetTextBackground(Color[] gradientColors, int[] percents, boolean vertical)Sets the background colors to be painted behind the title text in a gradient.voidsetTitleTextSelectable(boolean selectable)Sets whether ther text in the title region should be selectable.voidsetToolBarVerticalAlignment(int alignment)Sets the tool bar vertical alignment relative to the header.voidupdateToolBar()Updates the local tool bar manager if used.-
Methods 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
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, 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, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setLayoutData, setLocation, setLocation, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.swt.graphics.Drawable
isAutoScalable
-
-
-
-
Constructor Detail
-
Form
public Form(Composite parent, int style)
Creates the form content control as a child of the provided parent.- Parameters:
parent- the parent widget
-
-
Method Detail
-
setMenu
public void setMenu(Menu menu)
Passes the menu to the form body.
-
setLayout
public final void setLayout(Layout layout)
Prevents from changing the custom control layout.
-
getText
public String getText()
Returns the title text that will be rendered at the top of the form.- Returns:
- the title text
-
getImage
public Image getImage()
Returns the title image that will be rendered to the left of the title.- Returns:
- the title image or
nullif not set. - Since:
- 3.2
-
setForeground
public void setForeground(Color fg)
Sets the foreground color of the form. This color will also be used for the body.- Overrides:
setForegroundin classControl- Parameters:
fg- the foreground color
-
setBackground
public void setBackground(Color bg)
Sets the background color of the form. This color will also be used for the body.- Overrides:
setBackgroundin classControl- Parameters:
bg- the background color
-
setFont
public void setFont(Font font)
Sets the font of the header text.
-
setText
public void setText(String text)
Sets the text to be rendered at the top of the form above the body as a title.Note: Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. Mnemonics are not applicable in the case of the form title but need to be taken into account due to the usage of the underlying widget that renders mnemonics in the title area. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.
- Parameters:
text- the title text
-
setTitleTextSelectable
public void setTitleTextSelectable(boolean selectable)
Sets whether ther text in the title region should be selectable.Note: If
drag supportis also enabled, text selection has priority. Dragging still works in the non-text parts of the title area.- Parameters:
selectable- whether the title text should be selectable- Since:
- 3.8
-
setImage
public void setImage(Image image)
Sets the image to be rendered to the left of the title. This image will be temporarily hidden in two cases:- When the form is busy - replaced with a busy animation
- When the form has message set - replaced with the image indicating message severity
- Parameters:
image- the title image ornullto show no image.- Since:
- 3.2
-
setTextBackground
public void setTextBackground(Color[] gradientColors, int[] percents, boolean vertical)
Sets the background colors to be painted behind the title text in a gradient. Note that this method will reset color previously set bysetBackground(Color). This is necessary for the simulated transparency of the heading in all of its children control.- Parameters:
gradientColors- the array of colors that form the gradientpercents- the partition of the overall space between the gradient colorsvertical- oftrue, the gradient will be rendered vertically, iffalsethe orientation will be horizontal.
-
getBackgroundImage
public Image getBackgroundImage()
Returns the optional background image of the form head.- Overrides:
getBackgroundImagein classControl- Returns:
- the background image or
nullif not specified.
-
setBackgroundImage
public void setBackgroundImage(Image backgroundImage)
Sets the optional background image to be rendered behind the title starting at the position 0,0. If the image is smaller than the container in any dimension, it will be tiled. As of version 3.2, this method only supports SWT.BITMAP image types. This is because the rendering is now delegated to SWT which imposes this restriction on background images,- Overrides:
setBackgroundImagein classControl- Parameters:
backgroundImage- the head background image.
-
getToolBarManager
public IToolBarManager getToolBarManager()
Returns the tool bar manager that is used to manage tool items in the form's title area.- Returns:
- form tool bar manager
-
setToolBarVerticalAlignment
public void setToolBarVerticalAlignment(int alignment)
Sets the tool bar vertical alignment relative to the header. Can be useful when there is more free space at the second row (with the head client).- Parameters:
alignment- SWT.TOP or SWT.BOTTOM- Since:
- 3.3
-
getToolBarVerticalAlignment
public int getToolBarVerticalAlignment()
Returns the current tool bar alignment (if used).- Returns:
- SWT.TOP or SWT.BOTTOM
- Since:
- 3.3
-
getMenuManager
public IMenuManager getMenuManager()
Returns the menu manager that is used to manage title area drop-down menu items.- Returns:
- title area drop-down menu manager
- Since:
- 3.3
-
updateToolBar
public void updateToolBar()
Updates the local tool bar manager if used. Does nothing if local tool bar manager has not been created yet.
-
getHead
public Composite getHead()
Returns the container that occupies the head of the form (the form area above the body). Use this container as a parent for the head client.- Returns:
- the head of the form.
- Since:
- 3.2
-
getHeadClient
public Control getHeadClient()
Returns the optional head client if set.- Returns:
- the head client or
nullif not set. - Since:
- 3.2
- See Also:
setHeadClient(Control)
-
setHeadClient
public void setHeadClient(Control headClient)
Sets the optional head client. Head client is placed after the form title. This option causes the tool bar to be placed in the second raw of the header (below the head client).The head client must be a child of the composite returned by
getHead()method.- Parameters:
headClient- the optional child of the head- Since:
- 3.2
-
getBody
public Composite getBody()
Returns the container that occupies the body of the form (the form area below the title). Use this container as a parent for the controls that should be in the form. No layout manager has been set on the form body.- Returns:
- Returns the body of the form.
-
isBackgroundImageTiled
public boolean isBackgroundImageTiled()
Tests if the background image is tiled to cover the entire area of the form heading.- Returns:
trueif heading background image is tiled,falseotherwise.
-
setBackgroundImageTiled
public void setBackgroundImageTiled(boolean backgroundImageTiled)
Sets whether the header background image is repeated to cover the entire heading area or not.- Parameters:
backgroundImageTiled- settrueto tile the image, orfalseto paint the background image only once at 0,0
-
getBackgroundImageAlignment
@Deprecated public int getBackgroundImageAlignment()
Deprecated.due to the underlying widget limitations, background image is either painted at 0,0 and/or tiled.Returns the background image alignment.- Returns:
- SWT.LEFT
-
setBackgroundImageAlignment
@Deprecated public void setBackgroundImageAlignment(int backgroundImageAlignment)
Deprecated.due to the underlying widget limitations, background image is always tiled and alignment cannot be controlled.Sets the background image alignment.- Parameters:
backgroundImageAlignment- The backgroundImageAlignment to set.- Since:
- 3.1
-
isBackgroundImageClipped
@Deprecated public boolean isBackgroundImageClipped()
Deprecated.due to the underlying widget limitations, background image is always clipped.Tests if background image is clipped.- Returns:
- true
- Since:
- 3.1
-
setBackgroundImageClipped
@Deprecated public void setBackgroundImageClipped(boolean backgroundImageClipped)
Deprecated.due to the underlying widget limitations, background image is always clipped.Sets whether the background image is clipped.- Parameters:
backgroundImageClipped- the value to set- Since:
- 3.1
-
isSeparatorVisible
public boolean isSeparatorVisible()
Tests if the form head separator is visible.- Returns:
trueif the head/body separator is visible,falseotherwise- Since:
- 3.2
-
setSeparatorVisible
public void setSeparatorVisible(boolean addSeparator)
If set, adds a separator between the head and body. Since 3.3, the colors that are used to render it areIFormColors.H_BOTTOM_KEYLINE1andIFormColors.H_BOTTOM_KEYLINE2.- Parameters:
addSeparator-trueto make the separator visible,falseotherwise.- Since:
- 3.2
-
getSeparatorColor
@Deprecated public Color getSeparatorColor()
Deprecated.usegetHeadColor(IFormColors.H_BOTTOM_KEYLINE2)Returns the color used to render the optional head separator. If gradient text background is used additional colors from the gradient will be used to render the separator.- Returns:
- separator color or
nullif not set. - Since:
- 3.2
-
setSeparatorColor
@Deprecated public void setSeparatorColor(Color separatorColor)
Deprecated.usesetHeadColor(IFormColors.H_BOTTOM_KEYLINE2, separatorColor)Sets the color to be used to render the optional head separator.- Parameters:
separatorColor- the color to render the head separator ornullto use the default color.- Since:
- 3.2
-
setHeadColor
public void setHeadColor(String key, Color color)
Sets the color used to paint an aspect of the form heading.- Parameters:
key- a valid form heading color key as defined inIFormColors. Relevant keys all start with an H_ prefix.color- the color to use for the provided key- Since:
- 3.3
-
getHeadColor
public Color getHeadColor(String key)
Returns the color that is currently use to paint an aspect of the form heading, ornullif not defined.- Parameters:
key- the color key- Returns:
- the color object or
nullif not set. - Since:
- 3.3
-
setMessage
public void setMessage(String message)
Sets the message for this form. Message text is rendered in the form head when shown.- Parameters:
message- the message, ornullto clear the message- Since:
- 3.2
- See Also:
setMessage(String, int)
-
setMessage
public void setMessage(String newMessage, int newType)
Sets the message for this form with an indication of what type of message it is.The valid message types are one of
NONE,INFORMATION,WARNING, orERRORdefined in IMessageProvider interface.- Parameters:
newMessage- the message, ornullto clear the messagenewType- the message type- Since:
- 3.2
- See Also:
IMessageProvider
-
setMessage
public void setMessage(String newMessage, int newType, IMessage[] children)
Sets the message for this form with an indication of what type of message it is.The valid message types are one of
NONE,INFORMATION,WARNING, orERRORdefined in IMessageProvider interface.In addition to the summary message, this method also sets an array of individual messages.
- Parameters:
newMessage- the message, ornullto clear the messagenewType- the message typechildren- the individual messages that contributed to the overall message- Since:
- 3.3
- See Also:
IMessageProvider
-
addMessageHyperlinkListener
public void addMessageHyperlinkListener(IHyperlinkListener listener)
Adds a message hyperlink listener. If at least one listener is present, messages will be rendered as hyperlinks.- Parameters:
listener-- Since:
- 3.3
- See Also:
removeMessageHyperlinkListener(IHyperlinkListener)
-
removeMessageHyperlinkListener
public void removeMessageHyperlinkListener(IHyperlinkListener listener)
Remove the message hyperlink listener.- Parameters:
listener-- Since:
- 3.3
- See Also:
addMessageHyperlinkListener(IHyperlinkListener)
-
isBusy
public boolean isBusy()
Tests if the form is in the 'busy' state. Busy form displays 'busy' animation in the area of the title image.- Returns:
trueif busy,falseotherwise.- Since:
- 3.2
-
setBusy
public void setBusy(boolean busy)
Sets the form's busy state. Busy form will display 'busy' animation in the area of the title image.- Parameters:
busy- the form's busy state- Since:
- 3.2
-
addTitleDragSupport
public void addTitleDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener)Adds support for dragging items out of the form title area via a user drag-and-drop operation.- Parameters:
operations- a bitwise OR of the supported drag and drop operation types (DROP_COPY,DROP_LINK, andDROP_MOVE)transferTypes- the transfer types that are supported by the drag operationlistener- the callback that will be invoked to set the drag data and to cleanup after the drag and drop operation finishes- Since:
- 3.3
- See Also:
DND
-
addTitleDropSupport
public void addTitleDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener)Adds support for dropping items into the form title area via a user drag-and-drop operation.- Parameters:
operations- a bitwise OR of the supported drag and drop operation types (DROP_COPY,DROP_LINK, andDROP_MOVE)transferTypes- the transfer types that are supported by the drop operationlistener- the callback that will be invoked after the drag and drop operation finishes- Since:
- 3.3
- See Also:
DND
-
getMessage
public String getMessage()
-
getMessageType
public int getMessageType()
-
getChildrenMessages
public IMessage[] getChildrenMessages()
Returns the children messages that the cause of the summary message currently set on the form.- Returns:
- an array of children messages or
nullif not set. - Since:
- 3.3
- See Also:
setMessage(String, int, IMessage[])
-
getMessageManager
public IMessageManager getMessageManager()
Returns the message manager that will keep track of messages in this form.- Returns:
- the message manager instance
- Since:
- org.eclipse.ui.forms 3.4
-
-