public class FormText extends Canvas
When configured to use formatting XML, the control requires the root element
form
to be used and requires any ampersand (&) characters in the text to
be replaced by the entity &. The following tags can be children of the
form
element:
Text in paragraphs and list items will be wrapped according to the width of the control. The following tags can appear as children of either p or li elements:
Image
set using 'setImage' method. Vertical
position of image relative to surrounding text is optionally controlled by
the attribute align that can have values top, middle
and bottomtrue
to make the control fill the entire width of the text.
Form text is not responsible for creating or disposing controls, it only
places them relative to the surrounding text. Similar to img,
vertical position of the control can be set using the align
attribute. In addition, width and height attributes can
be used to force the dimensions of the control. If not used,
the preferred control size will be used.
None of the elements can nest. For example, you cannot have b inside a span . This was done to keep everything simple and transparent. Since 3.1, an exception to this rule has been added to support nesting images and text inside the hyperlink tag (a). Image enclosed in the hyperlink tag acts as a hyperlink, can be clicked on and can accept and render selection focus. When both text and image is enclosed, selection and rendering will affect both as a single hyperlink.
Since 3.1, it is possible to select text. Text selection can be programmatically accessed and also copied to clipboard. Non-textual objects (images, controls etc.) in the selection range are ignored.
Care should be taken when using this control. Form text is not an HTML browser and should not be treated as such. If you need complex formatting capabilities, use Browser widget. If you need editing capabilities and font/color styles of text segments is all you need, use StyleText widget. Finally, if all you need is to wrap text, use SWT Label widget and create it with SWT.WRAP style.
FormToolkit
,
TableWrapLayout
Modifier and Type | Field and Description |
---|---|
int |
marginHeight
Value of tue vertical margin (default is 1).
|
int |
marginWidth
Value of the horizontal margin (default is 0).
|
static String |
URL_HANDLER_ID
The object ID to be used when registering action to handle URL hyperlinks
(those that should result in opening the web browser).
|
Constructor and Description |
---|
FormText(Composite parent,
int style)
Contructs a new form text widget in the provided parent and using the
styles.
|
Modifier and Type | Method and Description |
---|---|
void |
addHyperlinkListener(IHyperlinkListener listener)
Adds a listener that will handle hyperlink events.
|
void |
addSelectionListener(SelectionListener listener)
Adds a selection listener.
|
boolean |
canCopy()
Tests if the text is selected and can be copied into the clipboard.
|
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Overrides the method by fully trusting the layout manager (computed width
or height may be larger than the provider width or height hints).
|
void |
copy()
Copies the selected text into the clipboard.
|
boolean |
getFocus()
Test for focus.
|
HyperlinkSettings |
getHyperlinkSettings()
Returns the hyperlink settings that are in effect for this control.
|
String |
getLoadingText()
Deprecated.
loading text is not used since 3.1
|
boolean |
getParagraphsSeparated()
Tests if there is some inter-paragraph spacing.
|
Object |
getSelectedLinkHref()
Returns the reference of the hyperlink that currently has keyboard focus,
or
null if there are no hyperlinks in the receiver or no
hyperlink has focus at the moment. |
String |
getSelectedLinkText()
Returns the text of the hyperlink that currently has keyboard focus, or
null if there are no hyperlinks in the receiver or no
hyperlink has focus at the moment. |
String |
getSelectionText()
Returns the selected text.
|
boolean |
isLoading()
Deprecated.
not used any more - returns
false |
boolean |
isWhitespaceNormalized()
Tests whether whitespace inside paragraph and list item is normalized.
|
void |
removeHyperlinkListener(IHyperlinkListener listener)
Removes the hyperlink listener.
|
void |
removeSelectionListener(SelectionListener listener)
Removes the specified selection listener.
|
void |
setColor(String key,
Color color)
Registers the color referenced by the provided key.
|
void |
setContents(InputStream is,
boolean expandURLs)
Sets the contents of the stream.
|
void |
setControl(String key,
Control control)
Registers the control referenced by the provided key.
|
void |
setEnabled(boolean enabled)
Enables the receiver if the argument is
true ,
and disables it otherwise. |
boolean |
setFocus()
Causes the receiver to have the keyboard focus,
such that all keyboard events will be delivered to it.
|
void |
setFont(Font font)
Sets the font to use to render the default text (text that does not have
special font property assigned).
|
void |
setFont(String key,
Font font)
Registers the font referenced by the provided key.
|
void |
setHyperlinkSettings(HyperlinkSettings settings)
Sets the hyperlink settings to be used for this control.
|
void |
setImage(String key,
Image image)
Registers the image referenced by the provided key.
|
void |
setLoadingText(String loadingText)
Deprecated.
use setText(loadingText, false, false);
|
void |
setMenu(Menu menu)
Disposes the internal menu if created and sets the menu provided as a
parameter.
|
void |
setParagraphsSeparated(boolean value)
If paragraphs are separated, spacing will be added between them.
|
void |
setText(String text,
boolean parseTags,
boolean expandURLs)
Sets the provided text.
|
void |
setWhitespaceNormalized(boolean value)
Controls whether whitespace inside paragraph and list items is
normalized.
|
drawBackground, getCaret, getIME, scroll, setCaret, setIME
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, 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, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setForeground, setLayoutData, setLocation, setLocation, 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, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
public static final String URL_HANDLER_ID
public int marginWidth
public int marginHeight
public FormText(Composite parent, int style)
The only valid style bit for FormText
is SWT.NO_FOCUS
.
This will cause the widget to always refuse focus.
parent
- form text parent controlstyle
- the widget stylepublic boolean getFocus()
public boolean isLoading()
false
public String getLoadingText()
public void setLoadingText(String loadingText)
loadingText
- loading text messagepublic void setParagraphsSeparated(boolean value)
value
- true if paragraphs are separated, false
otherwise.public boolean getParagraphsSeparated()
public void setImage(String key, Image image)
For img tags, an object of a type Image must be registered using the key equivalent to the value of the href attribute used in the tag.
key
- unique key that matches the value of the href
attribute.image
- an object of a type Image .public void setColor(String key, Color color)
For span tags, an object of a type Color must be registered using the key equivalent to the value of the color attribute.
key
- unique key that matches the value of the color
attribute.color
- an object of the type Color or null
if the key needs to be cleared.public void setFont(String key, Font font)
For span tags, an object of a type Font must be registered using the key equivalent to the value of the font attribute.
key
- unique key that matches the value of the font
attribute.font
- an object of the type Font or null
if the key needs to be cleared.public void setControl(String key, Control control)
For control tags, an object of a type Control must be registered using the key equivalent to the value of the control attribute.
key
- unique key that matches the value of the control
attribute.control
- an object of the type Control or null
if the existing control at the specified key needs to be
removed.public void setFont(Font font)
public void setText(String text, boolean parseTags, boolean expandURLs)
text
- the text to renderparseTags
- if true , formatting tags will be parsed.
Otherwise, text will be rendered as-is.expandURLs
- if true , URLs found in the untagged text will be
converted into hyperlinks.public void setContents(InputStream is, boolean expandURLs)
is
- stream to renderexpandURLs
- if true , URLs found in untagged text will be
converted into hyperlinks.public void setWhitespaceNormalized(boolean value)
setText
or
setContents
.
If normalized:
value
- true
if whitespace is normalized,
false
otherwise.public boolean isWhitespaceNormalized()
true
if whitespace is normalized,
false
otherwise.setWhitespaceNormalized(boolean)
public void setMenu(Menu menu)
public HyperlinkSettings getHyperlinkSettings()
public void setHyperlinkSettings(HyperlinkSettings settings)
settings
- hyperlink settings for this controlpublic void addHyperlinkListener(IHyperlinkListener listener)
listener
- the listener to addpublic void removeHyperlinkListener(IHyperlinkListener listener)
listener
- the listener to removepublic void addSelectionListener(SelectionListener listener)
widgetDefaultSelected
is not called for FormText.
listener
- the listenerSWTException
- IllegalArgumentException
- public void removeSelectionListener(SelectionListener listener)
listener
- the listenerSWTException
- IllegalArgumentException
- public String getSelectionText()
SWTException
- public boolean canCopy()
true
if the selected text can be copied into the
clipboard, false
otherwise.public void copy()
public Object getSelectedLinkHref()
null
if there are no hyperlinks in the receiver or no
hyperlink has focus at the moment.null
if none
selected.public String getSelectedLinkText()
null
if there are no hyperlinks in the receiver or no
hyperlink has focus at the moment.null
if none
selected.public Point computeSize(int wHint, int hHint, boolean changed)
computeSize
in class Composite
wHint
- the width hint (can be SWT.DEFAULT
)hHint
- the height hint (can be SWT.DEFAULT
)changed
- true
if the control's contents have changed, and false
otherwiseComposite.computeSize(int, int, boolean)
public void setEnabled(boolean enabled)
Control
true
,
and disables it otherwise. A disabled control is typically
not selectable from the user interface and draws with an
inactive or "grayed" look.setEnabled
in class Control
enabled
- the new enabled statepublic boolean setFocus()
Control
setFocus
in class Composite
true
if the control got focus, and false
if it was unable to.Control.forceFocus()
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.