org.eclipse.swtbot.swt.finder.widgets
Class SWTBotStyledText

java.lang.Object
  extended by org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot<StyledText>
      extended by org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText

public class SWTBotStyledText
extends AbstractSWTBot<StyledText>

Version:
$Id$
Author:
Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>

Field Summary
 
Fields inherited from class org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot
description, display, log, widget
 
Constructor Summary
SWTBotStyledText(StyledText styledText)
          Constructs a new instance of this object.
SWTBotStyledText(StyledText styledText, SelfDescribing description)
          Constructs a new instance of this object.
 
Method Summary
 Position cursorPosition()
          Gets the current position of the cursor.
 Bullet getBulletOnCurrentLine()
          Gets the bullet on the current line.
 Bullet getBulletOnLine(int line)
          Gets the bullet on the given line.
 RGB getLineBackground(int line)
          Gets the color of the background on the specified line.
 int getLineCount()
          Gets the number of lines in the StyledText.
 List<String> getLines()
          Gets all the lines in the editor.
 String getSelection()
          Gets the current selection text.
 StyleRange getStyle(int line, int column)
          Gets the style for the given line.
 StyleRange[] getStyles(int line, int column, int length)
          Gets the style information.
 int getTabs()
          Gets the tab width of the StyledText measured in characters.
 String getTextOnCurrentLine()
          Gets the text on the current line.
 String getTextOnLine(int line)
          Gets the text on the line.
 boolean hasBulletOnCurrentLine()
          Checks if this has a bullet on the current line.
 boolean hasBulletOnLine(int line)
          Gets if this has a bullet on the specific line.
 void insertText(int line, int column, String text)
          Inserts text at the given location.
 void insertText(String text)
          Inserts text at the end.
 void navigateTo(int line, int column)
          Sets the caret at the specified location.
 void navigateTo(Position position)
          Sets the caret at the specified location.
 void notifyKeyboardEvent(int modificationKeys, char c)
          Deprecated. use AbstractSWTBot.pressShortcut(int, char) instead. This api will be removed.
 void notifyKeyboardEvent(int modificationKeys, char c, int keyCode)
          Deprecated. use AbstractSWTBot.pressShortcut(int, int, char) instead. This api will be removed.
protected  int offset(int line, int column)
          Gets the offset.
 void selectCurrentLine()
          Selects the text on the current line.
 void selectLine(int line)
          Selects the text on the specified line.
 void selectRange(int line, int column, int length)
          Selects the range.
 void setText(String text)
          Sets the text into the styled text.
 void typeText(int line, int column, String text)
          Types the text at the given location.
 void typeText(String text)
          Types the text.
 void typeText(String text, int interval)
          Types the text.
 
Methods inherited from class org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot
absoluteLocation, assertEnabled, asyncExec, backgroundColor, click, click, clickXY, contextMenu, contextMenu, createEvent, createMouseEvent, createSelectionEvent, doubleClickXY, foregroundColor, getId, getText, getToolTipText, hasStyle, isActive, isEnabled, isEnabledInternal, isVisible, keyboard, notify, notify, notify, pressShortcut, pressShortcut, pressShortcut, rightClick, rightClick, setFocus, sleep, syncExec, syncExec, syncExec, syncExec, syncExec, syncExec, syncExec, syncExec, toString, traverse, waitForEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SWTBotStyledText

public SWTBotStyledText(StyledText styledText)
                 throws WidgetNotFoundException
Constructs a new instance of this object.

Parameters:
styledText - the widget.
Throws:
WidgetNotFoundException - if the widget is null or widget has been disposed.
Since:
2.0

SWTBotStyledText

public SWTBotStyledText(StyledText styledText,
                        SelfDescribing description)
                 throws WidgetNotFoundException
Constructs a new instance of this object.

Parameters:
styledText - the widget.
description - the description of the widget, this will be reported by AbstractSWTBot.toString()
Throws:
WidgetNotFoundException - if the widget is null or widget has been disposed.
Since:
2.0
Method Detail

setText

public void setText(String text)
Sets the text into the styled text.

Parameters:
text - the text to set.

notifyKeyboardEvent

@Deprecated
public void notifyKeyboardEvent(int modificationKeys,
                                           char c)
Deprecated. use AbstractSWTBot.pressShortcut(int, char) instead. This api will be removed.

Notifies of the keyboard event.

FIXME need some work for CTRL|SHIFT + 1 the 1 is to be sent as '!' in this case.

Parameters:
modificationKeys - the modification keys.
c - the character.
See Also:
Event.character, Event.stateMask

notifyKeyboardEvent

@Deprecated
public void notifyKeyboardEvent(int modificationKeys,
                                           char c,
                                           int keyCode)
Deprecated. use AbstractSWTBot.pressShortcut(int, int, char) instead. This api will be removed.

Notifies of keyboard event.

Parameters:
modificationKeys - the modification key.
c - the character.
keyCode - any special keys (function keys, arrow or navigation keys etc.)
See Also:
Event.keyCode, Event.character, Event.stateMask

navigateTo

public void navigateTo(int line,
                       int column)
Sets the caret at the specified location.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.

navigateTo

public void navigateTo(Position position)
Sets the caret at the specified location.

Parameters:
position - the position of the caret.

cursorPosition

public Position cursorPosition()
Gets the current position of the cursor. The returned position will contain a 0-based line and column.

Returns:
the position of the cursor in the styled text.

typeText

public void typeText(int line,
                     int column,
                     String text)
Types the text at the given location.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
text - the text to be typed at the specified location
Since:
1.0

insertText

public void insertText(int line,
                       int column,
                       String text)
Inserts text at the given location.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
text - the text to be inserted at the specified location

insertText

public void insertText(String text)
Inserts text at the end.

FIXME handle line endings

Parameters:
text - the text to be inserted at the location of the caret.

typeText

public void typeText(String text)
Types the text.

FIXME handle line endings

Parameters:
text - the text to be typed at the location of the caret.
Since:
1.0

typeText

public void typeText(String text,
                     int interval)
Types the text.

FIXME handle line endings

Parameters:
text - the text to be typed at the location of the caret.
interval - the interval between consecutive key strokes.
Since:
1.0

getStyle

public StyleRange getStyle(int line,
                           int column)
Gets the style for the given line.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
Returns:
the StyleRange at the specified location

offset

protected int offset(int line,
                     int column)
Gets the offset.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
Returns:
the character offset at the specified location in the styledtext.
See Also:
StyledTextContent.getOffsetAtLine(int)

selectRange

public void selectRange(int line,
                        int column,
                        int length)
Selects the range.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
length - the length of the selection.

getSelection

public String getSelection()
Gets the current selection text.

Returns:
the selection in the styled text

getStyles

public StyleRange[] getStyles(int line,
                              int column,
                              int length)
Gets the style information.

Parameters:
line - the line number, 0 based.
column - the column number, 0 based.
length - the length.
Returns:
the styles in the specified range.
See Also:
StyledText.getStyleRanges(int, int)

getTextOnCurrentLine

public String getTextOnCurrentLine()
Gets the text on the current line.

Returns:
the text on the current line, without the line delimiters.
See Also:
getTextOnLine(int)

getTextOnLine

public String getTextOnLine(int line)
Gets the text on the line.

TODO: throw exception if the line is out of range.

Parameters:
line - the line number, 0 based.
Returns:
the text on the given line number, without the line delimiters.

hasBulletOnCurrentLine

public boolean hasBulletOnCurrentLine()
Checks if this has a bullet on the current line.

Returns:
true if the styledText has a bullet on the given line, false otherwise.
See Also:
StyledText.getLineBullet(int)

hasBulletOnLine

public boolean hasBulletOnLine(int line)
Gets if this has a bullet on the specific line.

Parameters:
line - the line number, 0 based.
Returns:
true if the styledText has a bullet on the given line, false otherwise.
See Also:
StyledText.getLineBullet(int)

getBulletOnCurrentLine

public Bullet getBulletOnCurrentLine()
Gets the bullet on the current line.

Returns:
the bullet on the current line.
See Also:
StyledText.getLineBullet(int)

getBulletOnLine

public Bullet getBulletOnLine(int line)
Gets the bullet on the given line.

Parameters:
line - the line number, 0 based.
Returns:
the bullet on the given line.
See Also:
StyledText.getLineBullet(int)

selectLine

public void selectLine(int line)
Selects the text on the specified line.

Parameters:
line - the line number, 0 based.
Since:
1.1

selectCurrentLine

public void selectCurrentLine()
Selects the text on the current line.

Since:
1.1

getLineBackground

public RGB getLineBackground(int line)
Gets the color of the background on the specified line.

Parameters:
line - the line number, 0 based.
Returns:
the RGB of the line background color of the specified line.
Since:
1.3

getLineCount

public int getLineCount()
Gets the number of lines in the StyledText.

Returns:
the number of lines in the StyledText.

getLines

public List<String> getLines()
Gets all the lines in the editor.

Returns:
the lines in the editor.

getTabs

public int getTabs()
Gets the tab width of the StyledText measured in characters.

Returns:
the tab width of the StyledText measured in characters.