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;
}
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;
}
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("");
}
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;
}
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;
}
Aggregations