Search in sources :

Example 31 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project archi by archimatetool.

the class XYScaledGraphics method zoomTextLayout.

private TextLayout zoomTextLayout(TextLayout layout) {
    TextLayout zoomed = new TextLayout(Display.getCurrent());
    zoomed.setText(layout.getText());
    int zoomWidth = -1;
    if (layout.getWidth() != -1) {
        zoomWidth = ((int) (layout.getWidth() * xZoom));
    }
    if (zoomWidth < -1 || zoomWidth == 0) {
        return null;
    }
    zoomed.setFont(zoomFont2(layout.getFont()));
    zoomed.setAlignment(layout.getAlignment());
    zoomed.setAscent(layout.getAscent());
    zoomed.setDescent(layout.getDescent());
    zoomed.setOrientation(layout.getOrientation());
    zoomed.setSegments(layout.getSegments());
    zoomed.setSpacing(layout.getSpacing());
    zoomed.setTabs(layout.getTabs());
    zoomed.setWidth(zoomWidth);
    int length = layout.getText().length();
    if (length > 0) {
        int start = 0, offset = 1;
        TextStyle style = null, lastStyle = layout.getStyle(0);
        for (; offset <= length; offset++) {
            if (offset != length && (style = layout.getStyle(offset)) == lastStyle) {
                continue;
            }
            int end = offset - 1;
            if (lastStyle != null) {
                TextStyle zoomedStyle = new TextStyle(zoomFont2(lastStyle.font), lastStyle.foreground, lastStyle.background);
                zoomed.setStyle(zoomedStyle, start, end);
            }
            lastStyle = style;
            start = offset;
        }
    }
    return zoomed;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Point(org.eclipse.draw2d.geometry.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 32 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project archi by archimatetool.

the class ScaledGraphics method zoomTextLayout.

private TextLayout zoomTextLayout(TextLayout layout) {
    TextLayout zoomed = new TextLayout(Display.getCurrent());
    zoomed.setText(layout.getText());
    int zoomWidth = -1;
    if (layout.getWidth() != -1)
        zoomWidth = ((int) (layout.getWidth() * zoom));
    if (zoomWidth < -1 || zoomWidth == 0)
        return null;
    zoomed.setFont(zoomFont(layout.getFont()));
    zoomed.setAlignment(layout.getAlignment());
    zoomed.setAscent(layout.getAscent());
    zoomed.setDescent(layout.getDescent());
    zoomed.setOrientation(layout.getOrientation());
    zoomed.setSegments(layout.getSegments());
    zoomed.setSpacing(layout.getSpacing());
    zoomed.setTabs(layout.getTabs());
    zoomed.setWidth(zoomWidth);
    int length = layout.getText().length();
    // navigate through text
    if (length > 0) {
        int start = 0, offset = 1;
        TextStyle style = null, lastStyle = layout.getStyle(0);
        for (; offset <= length; offset++) {
            if (offset != length && (style = layout.getStyle(offset)) == lastStyle)
                continue;
            int end = offset - 1;
            if (lastStyle != null) {
                TextStyle zoomedStyle = new TextStyle(zoomFont(lastStyle.font), lastStyle.foreground, lastStyle.background);
                zoomedStyle.metrics = lastStyle.metrics;
                zoomedStyle.rise = lastStyle.rise;
                zoomedStyle.strikeout = lastStyle.strikeout;
                zoomedStyle.strikeoutColor = lastStyle.strikeoutColor;
                zoomedStyle.underline = lastStyle.underline;
                zoomedStyle.underlineColor = lastStyle.underlineColor;
                zoomedStyle.underlineStyle = lastStyle.underlineStyle;
                zoomed.setStyle(zoomedStyle, start, end);
            }
            lastStyle = style;
            start = offset;
        }
    }
    return zoomed;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Point(org.eclipse.draw2d.geometry.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 33 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project xtext-eclipse by eclipse.

the class XbaseInformationControl method createTextLayout.

/**
 * Creates and initializes the text layout used to compute the size hint.
 *
 * @since 3.2
 */
private void createTextLayout() {
    fTextLayout = new TextLayout(fSashForm.getDisplay());
    // Initialize fonts
    String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName;
    Font font = JFaceResources.getFont(symbolicFontName);
    fTextLayout.setFont(font);
    fTextLayout.setWidth(-1);
    font = JFaceResources.getFontRegistry().getBold(symbolicFontName);
    fBoldStyle = new TextStyle(font, null, null);
    // Compute and set tab width
    // $NON-NLS-1$
    fTextLayout.setText("    ");
    int tabWidth = fTextLayout.getBounds().width;
    fTextLayout.setTabs(new int[] { tabWidth });
    // $NON-NLS-1$
    fTextLayout.setText("");
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout)

Example 34 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project pmd-eclipse-plugin by pmd.

the class ASTPainterHelper method layoutFor.

public TextLayout layoutFor(TreeItem item) {
    Object data = item.getData();
    if (data instanceof Comment) {
        return layoutFor((Comment) data);
    }
    if (data instanceof JavadocElement) {
        return layoutFor((JavadocElement) data);
    }
    AbstractNode node = (AbstractNode) data;
    String label = node.toString();
    TextStyle extraStyle = imageStyle;
    String extra = NodeImageDeriver.derivedTextFor(node);
    if (extra != null) {
        extraStyle = derivedStyle;
    } else {
        extra = textFor(node);
    }
    textLayout.setText(label + (extra == null ? "" : " " + extra));
    int labelLength = label.length();
    textLayout.setStyle(labelStyle, 0, labelLength);
    if (extra != null) {
        textLayout.setStyle(extraStyle, labelLength, labelLength + extra.length() + 1);
    }
    return textLayout;
}
Also used : Comment(net.sourceforge.pmd.lang.java.ast.Comment) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) TextStyle(org.eclipse.swt.graphics.TextStyle) JavadocElement(net.sourceforge.pmd.lang.java.ast.JavadocElement)

Example 35 with TextStyle

use of org.eclipse.swt.graphics.TextStyle in project jbosstools-openshift by jbosstools.

the class OpenShiftExplorerLabelProvider method getStyledText.

private StyledString getStyledText(NewProjectLinkNode node, int limit) {
    StyledString value = new StyledString();
    value.append(node.toString(), new StyledString.Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            textStyle.underline = true;
            textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
        }
    });
    return value;
}
Also used : TextStyle(org.eclipse.swt.graphics.TextStyle) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

TextStyle (org.eclipse.swt.graphics.TextStyle)35 Point (org.eclipse.swt.graphics.Point)14 TextLayout (org.eclipse.swt.graphics.TextLayout)14 Color (org.eclipse.swt.graphics.Color)9 Font (org.eclipse.swt.graphics.Font)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Matcher (java.util.regex.Matcher)6 StyleRange (org.eclipse.swt.custom.StyleRange)6 ArrayList (java.util.ArrayList)5 Styler (org.eclipse.jface.viewers.StyledString.Styler)5 IToken (org.eclipse.jface.text.rules.IToken)4 StyledString (org.eclipse.jface.viewers.StyledString)4 RGB (org.eclipse.swt.graphics.RGB)4 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)3 List (java.util.List)2 Point (org.eclipse.draw2d.geometry.Point)2 Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 ITokenScanner (org.eclipse.jface.text.rules.ITokenScanner)2 GridItem (org.eclipse.nebula.widgets.grid.GridItem)2