本文整理匯總了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;
}