dsto.dfc.swt.text
Class StyledTextLinkOTron

java.lang.Object
  extended by dsto.dfc.swt.text.StyledTextLinkOTron
All Implemented Interfaces:
Disposable, EventListener, org.eclipse.swt.custom.LineStyleListener, org.eclipse.swt.internal.SWTEventListener, org.eclipse.swt.widgets.Listener

public class StyledTextLinkOTron
extends Object
implements org.eclipse.swt.custom.LineStyleListener, org.eclipse.swt.widgets.Listener, Disposable

Adds automatic clickable links to URL's in a styled text widget.

Note: the link colour is extracted from JFaceColors.getHyperlinkText(org.eclipse.swt.widgets.Display) which may not be set. To set manually use:

   JFaceResources.getColorRegistry ().put
     (JFacePreferences.HYPERLINK_COLOR,
      display.getSystemColor (SWT.COLOR_BLUE).getRGB ());
 
See /plugins/org.eclipse.rcp.source... /org.eclipse.ui.workbench.../org/eclipse/ui/internal/dialogs/ProductInfoDialog.java for an another example of doing this, including keyboard traversal.

Author:
Matthew Phillips

Constructor Summary
StyledTextLinkOTron(org.eclipse.swt.custom.StyledText textField)
          Create a new instance.
 
Method Summary
 void addListener(int event, org.eclipse.swt.widgets.Listener listener)
          Add a SWT.Selection listener to listen for URL clicks (URL in Event.text).
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 void handleEvent(org.eclipse.swt.widgets.Event e)
           
 void lineGetStyle(org.eclipse.swt.custom.LineStyleEvent e)
          Called by text field to get style for a line.
 boolean openInBrowser()
           
 void openInBrowser(boolean newValue)
          Set to true to automatically open links in the system browser (default true).
 void removeListener(int event, org.eclipse.swt.widgets.Listener listener)
           
protected  List<UrlScanner.UrlRange> scanForUrls(String text, int offset)
           
 UrlScanner.UrlRange urlRangeAt(org.eclipse.swt.widgets.Event e)
          Find the URL range at a given mouse event.
 UrlScanner.UrlRange urlRangeAt(int offset)
          Find the URL range for a given offset into the text.
 Set validSchemes()
          The set of valid URL schemes that are recognised as links.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyledTextLinkOTron

public StyledTextLinkOTron(org.eclipse.swt.custom.StyledText textField)
Create a new instance.

Method Detail

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable

openInBrowser

public void openInBrowser(boolean newValue)
Set to true to automatically open links in the system browser (default true).


openInBrowser

public boolean openInBrowser()

addListener

public void addListener(int event,
                        org.eclipse.swt.widgets.Listener listener)
Add a SWT.Selection listener to listen for URL clicks (URL in Event.text). Can veto/ok open in browser with Event.doit.


removeListener

public void removeListener(int event,
                           org.eclipse.swt.widgets.Listener listener)

validSchemes

public Set validSchemes()
The set of valid URL schemes that are recognised as links. Can add "*" to this to allow any vaguely URL-looking link. Default is {"http", "ftp", "mailto"}.


handleEvent

public void handleEvent(org.eclipse.swt.widgets.Event e)
Specified by:
handleEvent in interface org.eclipse.swt.widgets.Listener

urlRangeAt

public UrlScanner.UrlRange urlRangeAt(org.eclipse.swt.widgets.Event e)
Find the URL range at a given mouse event.


urlRangeAt

public UrlScanner.UrlRange urlRangeAt(int offset)
Find the URL range for a given offset into the text.


lineGetStyle

public void lineGetStyle(org.eclipse.swt.custom.LineStyleEvent e)
Called by text field to get style for a line.

Specified by:
lineGetStyle in interface org.eclipse.swt.custom.LineStyleListener

scanForUrls

protected List<UrlScanner.UrlRange> scanForUrls(String text,
                                                int offset)


Copyright © 2008 Commonwealth of Australia