本文整理汇总了Java中org.eclipse.swt.custom.StyledText.setStyleRanges方法的典型用法代码示例。如果您正苦于以下问题:Java StyledText.setStyleRanges方法的具体用法?Java StyledText.setStyleRanges怎么用?Java StyledText.setStyleRanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.custom.StyledText
的用法示例。
在下文中一共展示了StyledText.setStyleRanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: highlightText
import org.eclipse.swt.custom.StyledText; //导入方法依赖的package包/类
/**
* Set the given StyleRanges from the Vector to the StyledText
*
* @param textField Textfield where the text is in
* @param styleRanges Vector containing StyleRanges
*/
public static void highlightText(StyledText textField, Vector styleRanges) {
StyleRange styleRangesArray[] = new StyleRange[styleRanges.size()];
for (int a = 0; a < styleRanges.size(); a++)
styleRangesArray[a] = (StyleRange) styleRanges.get(a);
textField.setStyleRanges(styleRangesArray);
}
示例2: toStyledText
import org.eclipse.swt.custom.StyledText; //导入方法依赖的package包/类
/**
* Creates and returns with a new {@link StyledText styled text} instance hooked up to the given parent composite.
*
* @param parent
* the parent of the styled text control.
* @param style
* style bits for the new text control.
* @return a new styled text control initialized from the descriptor.
*/
default StyledText toStyledText(final Composite parent, final int style) {
final StyledText text = new StyledText(parent, READ_ONLY | style);
text.setText(getText());
text.setStyleRanges(getRanges());
text.setFont(getFont());
text.setEditable(false);
text.setEnabled(false);
final AtomicReference<Color> colorRef = new AtomicReference<>();
final IPreferenceStore prefStore = EditorsUI.getPreferenceStore();
if (null == prefStore
|| prefStore.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
colorRef.set(getDefault().getSystemColor(COLOR_LIST_BACKGROUND));
} else {
RGB rgb = null;
if (prefStore.contains(PREFERENCE_COLOR_BACKGROUND)) {
if (prefStore.isDefault(PREFERENCE_COLOR_BACKGROUND)) {
rgb = getDefaultColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
} else {
rgb = getColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
}
if (rgb != null) {
colorRef.set(new Color(text.getDisplay(), rgb));
}
}
}
if (null != colorRef.get()) {
text.setBackground(colorRef.get());
text.addDisposeListener(e -> {
if (!colorRef.get().isDisposed()) {
colorRef.get().dispose();
}
});
}
text.pack();
return text;
}
示例3: createCustomAreaWithLink
import org.eclipse.swt.custom.StyledText; //导入方法依赖的package包/类
/**
* Creates a control with some message and with link to the Binaries preference page.
*
* @param parent
* the parent composite.
* @param dialog
* the container dialog that has to be closed.
* @param binary
* the binary with the illegal state.
*
* @return a control with error message and link that can be reused in dialogs.
*/
public static Control createCustomAreaWithLink(final Composite parent, final Dialog dialog, final Binary binary) {
final String binaryLabel = binary.getLabel();
final String prefix = "The requested operation cannot be performed due to invalid '" + binaryLabel
+ "' settings. Check your '" + binaryLabel
+ "' configuration and preferences under the corresponding ";
final String link = "preference page";
final String suffix = ".";
final String text = prefix + link + suffix;
final Composite control = new Composite(parent, NONE);
control.setLayout(GridLayoutFactory.fillDefaults().create());
final GridData gridData = GridDataFactory.fillDefaults().align(LEFT, TOP).grab(true, true).create();
control.setLayoutData(gridData);
final StyleRange style = new StyleRange();
style.underline = true;
style.underlineStyle = UNDERLINE_LINK;
final StyledText styledText = new StyledText(control, MULTI | READ_ONLY | WRAP);
styledText.setWordWrap(true);
styledText.setJustify(true);
styledText.setText(text);
final GridData textGridData = GridDataFactory.fillDefaults().align(FILL, FILL).grab(true, true).create();
textGridData.widthHint = TEXT_WIDTH_HINT;
textGridData.heightHint = TEXT_HEIGHT_HINT;
styledText.setLayoutData(textGridData);
styledText.setEditable(false);
styledText.setBackground(UIUtils.getSystemColor(COLOR_WIDGET_BACKGROUND));
final int[] ranges = { text.indexOf(link), link.length() };
final StyleRange[] styles = { style };
styledText.setStyleRanges(ranges, styles);
styledText.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(final MouseEvent event) {
try {
final int offset = styledText.getOffsetAtLocation(new Point(event.x, event.y));
final StyleRange actualStyle = styledText.getStyleRangeAtOffset(offset);
if (null != actualStyle && actualStyle.underline
&& UNDERLINE_LINK == actualStyle.underlineStyle) {
dialog.close();
final PreferenceDialog preferenceDialog = createPreferenceDialogOn(
UIUtils.getShell(),
BinariesPreferencePage.ID,
FILTER_IDS,
null);
if (null != preferenceDialog) {
preferenceDialog.open();
}
}
} catch (final IllegalArgumentException e) {
// We are not over the actual text.
}
}
});
return control;
}