本文整理汇总了Java中org.eclipse.swt.custom.StyledText.getText方法的典型用法代码示例。如果您正苦于以下问题:Java StyledText.getText方法的具体用法?Java StyledText.getText怎么用?Java StyledText.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.custom.StyledText
的用法示例。
在下文中一共展示了StyledText.getText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateStyleRanges
import org.eclipse.swt.custom.StyledText; //导入方法依赖的package包/类
/**
* From the given Vector of words calculate all StyleRanges using the Color and Font Style that is given.
*
* @param textField Textfield where the text is in
* @param words Words to be highlighted
* @param foreground Color of the text-foreground
* @param background Color of the text-background
* @param fontstyle Fontstyle for the highlighted words
* @param caseSensitive FALSE if the case of the word to highlight should be ignored
* @return Vector A Vector containing all calculated StyleRanges
*/
public static Vector calculateStyleRanges(StyledText textField, Vector words, Color foreground, Color background, int fontstyle, boolean caseSensitive) {
/* Use Vector for the StyleRanges */
Vector styleRanges = new Vector();
/* Text with words to style */
String text = textField.getText();
/* Regard case sensitivity */
if (!caseSensitive)
text = textField.getText().toLowerCase();
/* Foreach word to style */
for (Object word : words) {
int start = 0;
String curWord = (String) word;
/* ToLowerCase if case is regarded */
if (!caseSensitive)
curWord = curWord.toLowerCase();
/* Save current position */
int pos;
/* For each occurance of the word in the text */
while ((pos = text.indexOf(curWord, start)) > -1) {
/* New stylerange for the word */
StyleRange styleRange = new StyleRange();
styleRange.start = pos;
styleRange.length = (curWord.length());
styleRange.fontStyle = fontstyle;
styleRange.foreground = foreground;
styleRange.background = background;
styleRanges.add(styleRange);
/* Goto next words */
start = styleRange.start + styleRange.length;
}
}
return styleRanges;
}