Search in sources :

Example 96 with StyleRange

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);
    }
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Iterator(java.util.Iterator) UnboundedFifoBuffer(org.apache.commons.collections.buffer.UnboundedFifoBuffer) ReportMessage(org.talend.designer.runtime.visualization.ReportMessage)

Example 97 with StyleRange

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));
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 98 with StyleRange

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();
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 99 with StyleRange

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();
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Example 100 with StyleRange

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();
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)145 Point (org.eclipse.swt.graphics.Point)52 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)25 Color (org.eclipse.swt.graphics.Color)22 StyledText (org.eclipse.swt.custom.StyledText)13 Font (org.eclipse.swt.graphics.Font)10 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)10 Matcher (java.util.regex.Matcher)9 FontData (org.eclipse.swt.graphics.FontData)8 RGB (org.eclipse.swt.graphics.RGB)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 IOException (java.io.IOException)5 TextPresentation (org.eclipse.jface.text.TextPresentation)5 Image (org.eclipse.swt.graphics.Image)5 Control (org.eclipse.swt.widgets.Control)5 Position (org.eclipse.jface.text.Position)4 TextStyle (org.eclipse.swt.graphics.TextStyle)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3