Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.ui.forms.widgets
Class FormText  view FormText download FormText.java

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 byorg.eclipse.swt.widgets.Canvas
                      extended byorg.eclipse.ui.forms.widgets.FormText
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public final class FormText
extends org.eclipse.swt.widgets.Canvas

This class is a read-only text control that is capable of rendering wrapped text. Text can be rendered as-is or by parsing the formatting XML tags. Independently, words that start with http:// can be converted into hyperlinks on the fly.

When configured to use formatting XML, the control requires the root element form to be used. 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:

None of the elements can nest. For example, you cannot have b inside a span . This was done to keep everything simple and transparent.

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.

You should be careful not to ask the control to render large quantities of text. It does not have advanced support for dirty regions and will repaint fully each time. Instead, combine the control in a composite with other controls and let SWT take care of the dirty regions.

Although the class is not marked final,

Since:
3.0

Nested Class Summary
private  class FormText.FormTextLayout
           
 
Field Summary
private  org.eclipse.jface.action.Action copyShortcutAction
           
private  org.eclipse.ui.internal.forms.widgets.HyperlinkSegment entered
           
private  boolean hasFocus
           
private  java.util.Vector listeners
           
private  boolean loading
           
private  java.lang.String loadingText
           
 int marginHeight
          Value of hte horizontal margin (default is 1).
 int marginWidth
          Value of the horizontal margin (default is 0).
private  org.eclipse.ui.internal.forms.widgets.FormTextModel model
           
private  boolean mouseDown
           
private  org.eclipse.jface.action.Action openAction
           
private  boolean paragraphsSeparated
           
private  java.util.Hashtable resourceTable
           
static java.lang.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).
 
Fields inherited from class org.eclipse.swt.widgets.Canvas
 
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
 
Fields inherited from class org.eclipse.swt.widgets.Scrollable
 
Fields inherited from class org.eclipse.swt.widgets.Control
 
Fields inherited from class org.eclipse.swt.widgets.Widget
handle
 
Constructor Summary
FormText(org.eclipse.swt.widgets.Composite parent, int style)
          Contructs a new form text widget in the provided parent and using the styles.
 
Method Summary
private  void activateLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link, int stateMask)
           
private  void activateSelectedLink()
           
 void addHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener listener)
          Adds a listener that will handle hyperlink events.
private  boolean advance(boolean next)
           
 org.eclipse.swt.graphics.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).
protected  void contextMenuAboutToShow(org.eclipse.jface.action.IMenuManager manager)
          Context menu is about to show - override to add actions to the menu manager.
private  void contributeLinkActions(org.eclipse.jface.action.IMenuManager manager, org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link)
           
private  void copyShortcut(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link)
           
private  void ensureBoldFontPresent(org.eclipse.swt.graphics.Font regularFont)
           
private  void ensureVisible(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment segment)
           
private  void enterLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link, int stateMask)
           
private  void exitLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link, int stateMask)
           
private  java.lang.String getAcessibleText()
           
 boolean getFocus()
          Test for focus.
 org.eclipse.ui.forms.HyperlinkSettings getHyperlinkSettings()
          Returns the hyperlink settings that are in effect for this control.
 java.lang.String getLoadingText()
          Returns the text that will be shown in the control while the real content is loading.
private  int getParagraphSpacing(int lineHeight)
           
 boolean getParagraphsSeparated()
          Tests if there is some inter-paragraph spacing.
private  void handleDrag(org.eclipse.swt.events.MouseEvent e)
           
private  void handleFocusChange()
           
private  void handleMouseClick(org.eclipse.swt.events.MouseEvent e, boolean down)
           
private  void handleMouseHover(org.eclipse.swt.events.MouseEvent e)
           
private  void handleMouseMove(org.eclipse.swt.events.MouseEvent e)
           
private  void initAccessible()
           
 boolean isLoading()
          Test if the widget is currently processing the text it is about to render.
 boolean isWhitespaceNormalized()
          Tests whether whitespace inside paragraph and list item is normalized.
private  void makeActions()
           
private  void paint(org.eclipse.swt.events.PaintEvent e)
           
private  void paintFocusTransfer(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment oldLink, org.eclipse.ui.internal.forms.widgets.HyperlinkSegment newLink)
           
private  void paintLinkHover(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link, boolean hover)
           
 void removeHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener listener)
          Removes the hyperlink listener.
 void setColor(java.lang.String key, org.eclipse.swt.graphics.Color color)
          Registers the color referenced by the provided key.
 void setContents(java.io.InputStream is, boolean expandURLs)
          Sets the contents of the stream.
 boolean setFocus()
          Sets the focus to the first hyperlink, or the widget itself if there are no hyperlinks.
 void setFont(org.eclipse.swt.graphics.Font font)
          Sets the font to use to render the default text (text that does not have special font property assigned).
 void setFont(java.lang.String key, org.eclipse.swt.graphics.Font font)
          Registers the font referenced by the provided key.
 void setHyperlinkSettings(org.eclipse.ui.forms.HyperlinkSettings settings)
          Sets the hyperlink settings to be used for this control.
 void setImage(java.lang.String key, org.eclipse.swt.graphics.Image image)
          Registers the image referenced by the provided key.
 void setLoadingText(java.lang.String loadingText)
          Sets the text that will be shown in the control while the real content is loading.
 void setParagraphsSeparated(boolean value)
          If paragraphs are separated, spacing will be added between them.
 void setText(java.lang.String text, boolean parseTags, boolean expandURLs)
          Sets the provided text.
 void setWhitespaceNormalized(boolean value)
          Controls whether whitespace inside paragraph and list items is normalized.
 
Methods inherited from class org.eclipse.swt.widgets.Canvas
getCaret, scroll, setCaret
 
Methods inherited from class org.eclipse.swt.widgets.Composite
checkSubclass, getChildren, getLayout, getTabList, layout, layout, setLayout, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getBorderWidth, 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, 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, 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

URL_HANDLER_ID

public static final java.lang.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). Value is "urlHandler".

See Also:
Constant Field Values

marginWidth

public int marginWidth
Value of the horizontal margin (default is 0).


marginHeight

public int marginHeight
Value of hte horizontal margin (default is 1).


hasFocus

private boolean hasFocus

paragraphsSeparated

private boolean paragraphsSeparated

model

private org.eclipse.ui.internal.forms.widgets.FormTextModel model

listeners

private java.util.Vector listeners

resourceTable

private java.util.Hashtable resourceTable

entered

private org.eclipse.ui.internal.forms.widgets.HyperlinkSegment entered

mouseDown

private boolean mouseDown

openAction

private org.eclipse.jface.action.Action openAction

copyShortcutAction

private org.eclipse.jface.action.Action copyShortcutAction

loading

private boolean loading

loadingText

private java.lang.String loadingText
Constructor Detail

FormText

public FormText(org.eclipse.swt.widgets.Composite parent,
                int style)
Contructs a new form text widget in the provided parent and using the styles.

Method Detail

getFocus

public boolean getFocus()
Test for focus.


isLoading

public boolean isLoading()
Test if the widget is currently processing the text it is about to render.


getLoadingText

public java.lang.String getLoadingText()
Returns the text that will be shown in the control while the real content is loading.


setLoadingText

public void setLoadingText(java.lang.String loadingText)
Sets the text that will be shown in the control while the real content is loading. This is significant when content to render is loaded from the input stream that was created from a remote URL, and the time to load the entire content is nontrivial.


setParagraphsSeparated

public void setParagraphsSeparated(boolean value)
If paragraphs are separated, spacing will be added between them. Otherwise, new paragraphs will simply start on a new line with no spacing.


getParagraphsSeparated

public boolean getParagraphsSeparated()
Tests if there is some inter-paragraph spacing.


setImage

public void setImage(java.lang.String key,
                     org.eclipse.swt.graphics.Image image)
Registers the image referenced by the provided key.

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.


setColor

public void setColor(java.lang.String key,
                     org.eclipse.swt.graphics.Color color)
Registers the color referenced by the provided key.

For span tags, an object of a type Color must be registered using the key equivalent to the value of the color attribute.


setFont

public void setFont(java.lang.String key,
                    org.eclipse.swt.graphics.Font font)
Registers the font referenced by the provided key.

For span tags, an object of a type Font must be registered using the key equivalent to the value of the font attribute.


setFont

public void setFont(org.eclipse.swt.graphics.Font font)
Sets the font to use to render the default text (text that does not have special font property assigned). Bold font will be constructed from this font.


setText

public void setText(java.lang.String text,
                    boolean parseTags,
                    boolean expandURLs)
Sets the provided text. Text can be rendered as-is, or by parsing the formatting tags. Optionally, sections of text starting with http:// will be converted to hyperlinks.


setContents

public void setContents(java.io.InputStream is,
                        boolean expandURLs)
Sets the contents of the stream. Optionally, URLs in untagged text can be converted into hyperlinks. The caller is responsible for closing the stream.


setWhitespaceNormalized

public void setWhitespaceNormalized(boolean value)
Controls whether whitespace inside paragraph and list items is normalized.

If normalized:

  • all white space characters will be condensed into at most one when between words.
  • new line characters will be ignored and replaced with one white space character
  • white space characters after the opening tags and before the closing tags will be trimmed

isWhitespaceNormalized

public boolean isWhitespaceNormalized()
Tests whether whitespace inside paragraph and list item is normalized.


setFocus

public boolean setFocus()
Sets the focus to the first hyperlink, or the widget itself if there are no hyperlinks.


getHyperlinkSettings

public org.eclipse.ui.forms.HyperlinkSettings getHyperlinkSettings()
Returns the hyperlink settings that are in effect for this control.


setHyperlinkSettings

public void setHyperlinkSettings(org.eclipse.ui.forms.HyperlinkSettings settings)
Sets the hyperlink settings to be used for this control. Settings will affect things like hyperlink color, rendering style, cursor etc.


addHyperlinkListener

public void addHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener listener)
Adds a listener that will handle hyperlink events.


removeHyperlinkListener

public void removeHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener listener)
Removes the hyperlink listener.


contextMenuAboutToShow

protected void contextMenuAboutToShow(org.eclipse.jface.action.IMenuManager manager)
Context menu is about to show - override to add actions to the menu manager. Subclasses are required to call 'super' when overriding.


makeActions

private void makeActions()

getAcessibleText

private java.lang.String getAcessibleText()

initAccessible

private void initAccessible()

handleMouseClick

private void handleMouseClick(org.eclipse.swt.events.MouseEvent e,
                              boolean down)

handleMouseHover

private void handleMouseHover(org.eclipse.swt.events.MouseEvent e)

handleMouseMove

private void handleMouseMove(org.eclipse.swt.events.MouseEvent e)

advance

private boolean advance(boolean next)

handleFocusChange

private void handleFocusChange()

enterLink

private void enterLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link,
                       int stateMask)

exitLink

private void exitLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link,
                      int stateMask)

paintLinkHover

private void paintLinkHover(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link,
                            boolean hover)

activateSelectedLink

private void activateSelectedLink()

activateLink

private void activateLink(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link,
                          int stateMask)

ensureBoldFontPresent

private void ensureBoldFontPresent(org.eclipse.swt.graphics.Font regularFont)

paint

private void paint(org.eclipse.swt.events.PaintEvent e)

getParagraphSpacing

private int getParagraphSpacing(int lineHeight)

paintFocusTransfer

private void paintFocusTransfer(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment oldLink,
                                org.eclipse.ui.internal.forms.widgets.HyperlinkSegment newLink)

contributeLinkActions

private void contributeLinkActions(org.eclipse.jface.action.IMenuManager manager,
                                   org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link)

copyShortcut

private void copyShortcut(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment link)

ensureVisible

private void ensureVisible(org.eclipse.ui.internal.forms.widgets.HyperlinkSegment segment)

handleDrag

private void handleDrag(org.eclipse.swt.events.MouseEvent e)

computeSize

public org.eclipse.swt.graphics.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).