use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.
the class RuntimeGraphcsComposite method displayReportField.
public void displayReportField() {
if (reportField != null && !reportField.isDisposed()) {
if (messageManager == null) {
return;
}
UnboundedFifoBuffer messages = messageManager.getMessages();
Iterator iterator = messages.iterator();
StringBuilder content = new StringBuilder();
StyleRange[] styleRanges = new StyleRange[messages.size()];
int i = 0;
while (iterator.hasNext()) {
ReportMessage message = (ReportMessage) iterator.next();
content.append(message.getContent());
styleRanges[i++] = message.getType();
}
reportField.setText(content.toString());
reportField.setStyleRanges(styleRanges);
// reportField.setForeground(new Color(Display.getDefault(), 255, 0, 0));
reportField.setTopIndex(Integer.MAX_VALUE);
}
}
use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.
the class ReportMessageManager method setWarningMessage.
public synchronized void setWarningMessage(String content, Color foreground, Color background) {
int oldLength = getMessagesLength();
StyleRange styleRange = new StyleRange(oldLength, content.length(), foreground, background);
messages.add(new ReportMessage(styleRange, content));
}
use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.
the class LoginDialogV2 method setWarnMessage.
public void setWarnMessage(String warnMsg, List<StyleRange> styleRange) {
StyleRange[] styleRanges = null;
if (styleRange != null && !styleRange.isEmpty()) {
styleRanges = styleRange.toArray(new StyleRange[0]);
} else {
StyleRange range = new StyleRange();
range.font = errorFont;
range.foreground = WHITE_COLOR;
range.start = 0;
range.length = warnMsg.length();
styleRanges = new StyleRange[] { range };
}
errorTextLabel.setText(warnMsg);
errorTextLabel.setStyleRanges(styleRanges);
errorTextLabel.setToolTipText(warnMsg);
adjustErrorMessageAreaSize();
errorMessageArea.setBackground(YELLOW_COLOR);
brandingArea.layout();
brandingArea.update();
}
use of org.eclipse.swt.custom.StyleRange in project tdi-studio-se by Talend.
the class LoginDialogV2 method setErrorMessage.
public void setErrorMessage(String errMsg, List<StyleRange> styleRange) {
StyleRange[] styleRanges = null;
if (styleRange != null && !styleRange.isEmpty()) {
styleRanges = styleRange.toArray(new StyleRange[0]);
} else {
StyleRange range = new StyleRange();
range.font = errorFont;
range.foreground = WHITE_COLOR;
range.start = 0;
range.length = errMsg.length();
styleRanges = new StyleRange[] { range };
}
errorTextLabel.setText(errMsg);
errorTextLabel.setStyleRanges(styleRanges);
errorTextLabel.setToolTipText(errMsg);
adjustErrorMessageAreaSize();
errorMessageArea.setBackground(RED_COLOR);
brandingArea.layout();
brandingArea.update();
}
use of org.eclipse.swt.custom.StyleRange in project eclipse.platform.swt by eclipse.
the class StyledTextTab method createStyledTextStyleGroup.
/**
* Creates the "StyledText Style" group.
*/
void createStyledTextStyleGroup() {
styledTextStyleGroup = new Group(controlGroup, SWT.NONE);
styledTextStyleGroup.setText(ControlExample.getResourceString("StyledText_Styles"));
styledTextStyleGroup.setLayout(new GridLayout(6, false));
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
data.horizontalSpan = 2;
styledTextStyleGroup.setLayoutData(data);
/* Get images */
boldImage = createBitmapImage(display, "bold");
italicImage = createBitmapImage(display, "italic");
redImage = createBitmapImage(display, "red");
yellowImage = createBitmapImage(display, "yellow");
underlineImage = createBitmapImage(display, "underline");
strikeoutImage = createBitmapImage(display, "strikeout");
/* Create controls to modify the StyledText */
Label label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("StyledText_Style_Instructions"));
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
resetButton = new Button(styledTextStyleGroup, SWT.PUSH);
resetButton.setText(ControlExample.getResourceString("Clear"));
resetButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false, 2, 1));
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Bold"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
boldButton = new Button(styledTextStyleGroup, SWT.PUSH);
boldButton.setImage(boldImage);
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Underline"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
underlineButton = new Button(styledTextStyleGroup, SWT.PUSH);
underlineButton.setImage(underlineImage);
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Foreground_Style"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
redButton = new Button(styledTextStyleGroup, SWT.PUSH);
redButton.setImage(redImage);
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Italic"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
italicButton = new Button(styledTextStyleGroup, SWT.PUSH);
italicButton.setImage(italicImage);
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Strikeout"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
strikeoutButton = new Button(styledTextStyleGroup, SWT.PUSH);
strikeoutButton.setImage(strikeoutImage);
label = new Label(styledTextStyleGroup, SWT.NONE);
label.setText(ControlExample.getResourceString("Background_Style"));
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
yellowButton = new Button(styledTextStyleGroup, SWT.PUSH);
yellowButton.setImage(yellowImage);
SelectionListener styleListener = widgetSelectedAdapter(e -> {
Point sel = styledText.getSelectionRange();
if ((sel == null) || (sel.y == 0))
return;
StyleRange style;
for (int i = sel.x; i < sel.x + sel.y; i++) {
StyleRange range = styledText.getStyleRangeAtOffset(i);
if (range != null && e.widget != resetButton) {
style = (StyleRange) range.clone();
style.start = i;
style.length = 1;
} else {
style = new StyleRange(i, 1, null, null, SWT.NORMAL);
}
if (e.widget == boldButton) {
style.fontStyle ^= SWT.BOLD;
} else if (e.widget == italicButton) {
style.fontStyle ^= SWT.ITALIC;
} else if (e.widget == underlineButton) {
style.underline = !style.underline;
} else if (e.widget == strikeoutButton) {
style.strikeout = !style.strikeout;
}
styledText.setStyleRange(style);
}
styledText.setSelectionRange(sel.x + sel.y, 0);
});
SelectionListener colorListener = widgetSelectedAdapter(e -> {
Point sel = styledText.getSelectionRange();
if ((sel == null) || (sel.y == 0))
return;
Color fg = null, bg = null;
if (e.widget == redButton) {
fg = display.getSystemColor(SWT.COLOR_RED);
} else if (e.widget == yellowButton) {
bg = display.getSystemColor(SWT.COLOR_YELLOW);
}
StyleRange style;
for (int i = sel.x; i < sel.x + sel.y; i++) {
StyleRange range = styledText.getStyleRangeAtOffset(i);
if (range != null) {
style = (StyleRange) range.clone();
style.start = i;
style.length = 1;
if (fg != null)
style.foreground = style.foreground != null ? null : fg;
if (bg != null)
style.background = style.background != null ? null : bg;
} else {
style = new StyleRange(i, 1, fg, bg, SWT.NORMAL);
}
styledText.setStyleRange(style);
}
styledText.setSelectionRange(sel.x + sel.y, 0);
});
resetButton.addSelectionListener(styleListener);
boldButton.addSelectionListener(styleListener);
italicButton.addSelectionListener(styleListener);
underlineButton.addSelectionListener(styleListener);
strikeoutButton.addSelectionListener(styleListener);
redButton.addSelectionListener(colorListener);
yellowButton.addSelectionListener(colorListener);
yellowButton.addDisposeListener(e -> {
boldImage.dispose();
italicImage.dispose();
redImage.dispose();
yellowImage.dispose();
underlineImage.dispose();
strikeoutImage.dispose();
});
}
Aggregations