void styleLinkParts() { boolean enabled = (state & DISABLED) == 0; TextStyle linkStyle = new TextStyle (null, enabled ? getLinkForeground() : disabledColor, null); linkStyle.underline = true; for (int i = 0; i < offsets.length; i++) { Point point = offsets [i]; layout.setStyle (linkStyle, point.x, point.y); } }
void styleLinkParts() { boolean enabled = (state & DISABLED) == 0; TextStyle linkStyle = new TextStyle (null, enabled ? getLinkForeground() : disabledColor, null); linkStyle.underline = true; for (int i = 0; i < offsets.length; i++) { Point point = offsets [i]; layout.setStyle (linkStyle, point.x, point.y); } }
void styleLinkParts(boolean enabled) { TextStyle linkStyle = new TextStyle (null, enabled ? internalGetLinkForeground() : disabledColor, null); linkStyle.underline = true; for (int i = 0; i < offsets.length; i++) { Point point = offsets [i]; layout.setStyle (linkStyle, point.x, point.y); } }
void styleLinkParts() { boolean enabled = (state & DISABLED) == 0; TextStyle linkStyle = new TextStyle (null, enabled ? getLinkForeground() : disabledColor, null); linkStyle.underline = true; for (int i = 0; i < offsets.length; i++) { Point point = offsets [i]; layout.setStyle (linkStyle, point.x, point.y); } }
/** * @param layout * @param cell * @param applyColors * @return the text width delta (0 if the text layout contains no other font) */ private int updateTextLayout(TextLayout layout, ViewerCell cell, boolean applyColors) { layout.setStyle(null, 0, Integer.MAX_VALUE); // clear old styles layout.setText(cell.getText()); layout.setFont(cell.getFont()); // set also if null to clear previous usages int originalTextWidth = layout.getBounds().width; // text width without any styles boolean containsOtherFont= false; StyleRange[] styleRanges = cell.getStyleRanges(); if (styleRanges != null) { // user didn't fill styled ranges for (StyleRange styleRange : styleRanges) { StyleRange curr = prepareStyleRange(styleRange, applyColors); layout.setStyle(curr, curr.start, curr.start + curr.length - 1); if (curr.font != null) { containsOtherFont= true; } } } int textWidthDelta = 0; if (containsOtherFont) { textWidthDelta = layout.getBounds().width - originalTextWidth; } return textWidthDelta; }
void drawBullet(Bullet bullet, GC gc, int paintX, int paintY, int index, int lineAscent, int lineDescent) { StyleRange style = bullet.style; GlyphMetrics metrics = style.metrics; Color color = style.foreground; if (color != null) gc.setForeground(color); Font font = style.font; if (font != null) gc.setFont(font); String string = ""; int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER); switch (type) { case ST.BULLET_DOT: string = "\u2022"; break; case ST.BULLET_NUMBER: string = String.valueOf(index + 1); break; case ST.BULLET_LETTER_LOWER: string = String.valueOf((char) (index % 26 + 97)); break; case ST.BULLET_LETTER_UPPER: string = String.valueOf((char) (index % 26 + 65)); break; } if ((bullet.type & ST.BULLET_TEXT) != 0) string += bullet.text; Display display = styledText.getDisplay(); TextLayout layout = new TextLayout(display); layout.setText(string); layout.setAscent(lineAscent); layout.setDescent(lineDescent); style = (StyleRange)style.clone(); style.metrics = null; if (style.font == null) style.font = getFont(style.fontStyle); layout.setStyle(style, 0, string.length()); int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN); layout.draw(gc, x, paintY); layout.dispose(); } int drawLine(int lineIndex, int paintX, int paintY, GC gc, Color widgetBackground, Color widgetForeground) {
void drawBullet(Bullet bullet, GC gc, int paintX, int paintY, int index, int lineAscent, int lineDescent) { StyleRange style = bullet.style; GlyphMetrics metrics = style.metrics; Color color = style.foreground; if (color != null) gc.setForeground(color); Font font = style.font; if (font != null) gc.setFont(font); String string = ""; int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER); switch (type) { case ST.BULLET_DOT: string = "\u2022"; break; case ST.BULLET_NUMBER: string = String.valueOf(index + 1); break; case ST.BULLET_LETTER_LOWER: string = String.valueOf((char) (index % 26 + 97)); break; case ST.BULLET_LETTER_UPPER: string = String.valueOf((char) (index % 26 + 65)); break; } if ((bullet.type & ST.BULLET_TEXT) != 0) string += bullet.text; Display display = styledText.getDisplay(); TextLayout layout = new TextLayout(display); layout.setText(string); layout.setAscent(lineAscent); layout.setDescent(lineDescent); style = (StyleRange)style.clone(); style.metrics = null; if (style.font == null) style.font = getFont(style.fontStyle); layout.setStyle(style, 0, string.length()); int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN); layout.draw(gc, x, paintY); layout.dispose(); } int drawLine(int lineIndex, int paintX, int paintY, GC gc, Color widgetBackground, Color widgetForeground) {
void drawBullet(Bullet bullet, GC gc, int paintX, int paintY, int index, int lineAscent, int lineDescent) { StyleRange style = bullet.style; GlyphMetrics metrics = style.metrics; Color color = style.foreground; if (color != null) gc.setForeground(color); Font font = style.font; if (font != null) gc.setFont(font); String string = ""; int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER); switch (type) { case ST.BULLET_DOT: string = "\u2022"; break; case ST.BULLET_NUMBER: string = String.valueOf(index + 1); break; case ST.BULLET_LETTER_LOWER: string = String.valueOf((char) (index % 26 + 97)); break; case ST.BULLET_LETTER_UPPER: string = String.valueOf((char) (index % 26 + 65)); break; } if ((bullet.type & ST.BULLET_TEXT) != 0) string += bullet.text; Display display = styledText.getDisplay(); TextLayout layout = new TextLayout(display); layout.setText(string); layout.setAscent(lineAscent); layout.setDescent(lineDescent); style = (StyleRange)style.clone(); style.metrics = null; if (style.font == null) style.font = getFont(style.fontStyle); layout.setStyle(style, 0, string.length()); int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN); layout.draw(gc, x, paintY); layout.dispose(); } int drawLine(int lineIndex, int paintX, int paintY, GC gc, Color widgetBackground, Color widgetForeground) {
void drawBullet(Bullet bullet, GC gc, int paintX, int paintY, int index, int lineAscent, int lineDescent) { StyleRange style = bullet.style; GlyphMetrics metrics = style.metrics; Color color = style.foreground; if (color != null) gc.setForeground(color); Font font = style.font; if (font != null) gc.setFont(font); String string = ""; int type = bullet.type & (ST.BULLET_DOT|ST.BULLET_NUMBER|ST.BULLET_LETTER_LOWER|ST.BULLET_LETTER_UPPER); switch (type) { case ST.BULLET_DOT: string = "\u2022"; break; case ST.BULLET_NUMBER: string = String.valueOf(index + 1); break; case ST.BULLET_LETTER_LOWER: string = String.valueOf((char) (index % 26 + 97)); break; case ST.BULLET_LETTER_UPPER: string = String.valueOf((char) (index % 26 + 65)); break; } if ((bullet.type & ST.BULLET_TEXT) != 0) string += bullet.text; Display display = styledText.getDisplay(); TextLayout layout = new TextLayout(display); layout.setText(string); layout.setAscent(lineAscent); layout.setDescent(lineDescent); style = (StyleRange)style.clone(); style.metrics = null; if (style.font == null) style.font = getFont(style.fontStyle); layout.setStyle(style, 0, string.length()); int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN); layout.draw(gc, x, paintY); layout.dispose(); } int drawLine(int lineIndex, int paintX, int paintY, GC gc, Color widgetBackground, Color widgetForeground) {
/** * @param layout * @param cell * @param applyColors * @return the text width delta (0 if the text layout contains no other font) */ private int updateTextLayout(TextLayout layout, ViewerCell cell, boolean applyColors) { layout.setStyle(null, 0, Integer.MAX_VALUE); // clear old styles layout.setText(cell.getText()); layout.setFont(cell.getFont()); // set also if null to clear previous usages int originalTextWidth = layout.getBounds().width; // text width without any styles boolean containsOtherFont= false; StyleRange[] styleRanges = cell.getStyleRanges(); if (styleRanges != null) { // user didn't fill styled ranges for (int i = 0; i < styleRanges.length; i++) { StyleRange curr = prepareStyleRange(styleRanges[i], applyColors); layout.setStyle(curr, curr.start, curr.start + curr.length - 1); if (curr.font != null) { containsOtherFont= true; } } } int textWidthDelta = 0; if (containsOtherFont) { textWidthDelta = layout.getBounds().width - originalTextWidth; } return textWidthDelta; }
private void processColoredLabel(ColoredString richLabel, GC gc, Rectangle textBounds, boolean isSelected, Font font) { String text= richLabel.getString(); fTextLayout.setText(text); fTextLayout.setFont(font); if (!isSelected) { // apply the styled ranges only when element is not selected Display display= (Display) gc.getDevice(); Iterator ranges= richLabel.getRanges(); while (ranges.hasNext()) { ColoredString.StyleRange curr= (ColoredString.StyleRange) ranges.next(); ColoredString.Style style= curr.style; if (style != null) { Color foreground= getColor(style.getForegroundColorName(), display); TextStyle textStyle= new TextStyle(null, foreground, null); fTextLayout.setStyle(textStyle, curr.offset, curr.offset + curr.length - 1); } } } Rectangle bounds= fTextLayout.getBounds(); int x= textBounds.x; int y = textBounds.y + Math.max(0, (textBounds.height - bounds.height) / 2); fTextLayout.draw(gc, x, y); fTextLayout.setText(""); // clear all ranges //$NON-NLS-1$ }
style.metrics = null; if (style.font == null) style.font = getFont(style.fontStyle); layout.setStyle(style, 0, string.length()); int x = paintX + Math.max(0, metrics.width - layout.getBounds().width - BULLET_MARGIN); layout.draw(gc, x, paintY);
layout.setText(" "); layout.setFont(font); layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0); layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1); layout.setStyle(new TextStyle(getFont(SWT.ITALIC), null, null), 2, 2); layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3); FontMetrics metrics = layout.getLineMetrics(0); ascent = metrics.getAscent() + metrics.getLeading();
layout.setText(" "); layout.setFont(font); layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0); layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1); layout.setStyle(new TextStyle(getFont(SWT.ITALIC), null, null), 2, 2); layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3); FontMetrics metrics = layout.getLineMetrics(0); ascent = metrics.getAscent() + metrics.getLeading();
layout.setText(" "); layout.setFont(font); layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0); layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1); layout.setStyle(new TextStyle(getFont(SWT.ITALIC), null, null), 2, 2); layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3); FontMetrics metrics = layout.getLineMetrics(0); ascent = metrics.getAscent() + metrics.getLeading();
layout.setText(" "); layout.setFont(font); layout.setStyle(new TextStyle(getFont(SWT.NORMAL), null, null), 0, 0); layout.setStyle(new TextStyle(getFont(SWT.BOLD), null, null), 1, 1); layout.setStyle(new TextStyle(getFont(SWT.ITALIC), null, null), 2, 2); layout.setStyle(new TextStyle(getFont(SWT.BOLD | SWT.ITALIC), null, null), 3, 3); FontMetrics metrics = layout.getLineMetrics(0); ascent = metrics.getAscent() + metrics.getLeading();
private int updateTextLayout(TableItem item, int index, boolean isSelected) { fSharedLayout.setFont(item.getFont(index)); // XXX: needed to clear the style info, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=226090 fSharedLayout.setText(""); //$NON-NLS-1$ fSharedLayout.setText(item.getText(index)); int originalTextWidth= fSharedLayout.getBounds().width; // text width without any styles StyleRange[] ranges= getStyledRanges(item, index); if (ranges != null) { for (StyleRange range : ranges) { StyleRange curr= range; if (isSelected) { curr= (StyleRange) curr.clone(); curr.foreground= null; curr.background= null; } fSharedLayout.setStyle(curr, curr.start, curr.start + curr.length - 1); } } return fSharedLayout.getBounds().width - originalTextWidth; }
private int updateTextLayout(TableItem item, int index, boolean isSelected) { fSharedLayout.setFont(item.getFont(index)); // XXX: needed to clear the style info, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=226090 fSharedLayout.setText(""); //$NON-NLS-1$ fSharedLayout.setText(item.getText(index)); int originalTextWidth= fSharedLayout.getBounds().width; // text width without any styles StyleRange[] ranges= getStyledRanges(item, index); if (ranges != null) { for (int i= 0; i < ranges.length; i++) { StyleRange curr= ranges[i]; if (isSelected) { curr= (StyleRange) curr.clone(); curr.foreground= null; curr.background= null; } fSharedLayout.setStyle(curr, curr.start, curr.start + curr.length - 1); } } return fSharedLayout.getBounds().width - originalTextWidth; }
boldFont = new Font (display, data.getName (), data.getHeight (), SWT.BOLD); TextStyle style = new TextStyle (boldFont, null, null); layoutText.setStyle (style, 0, string.length ());