本文整理汇总了Java中org.eclipse.swt.graphics.TextLayout.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.dispose方法的具体用法?Java TextLayout.dispose怎么用?Java TextLayout.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.TextLayout
的用法示例。
在下文中一共展示了TextLayout.dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shortenText
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
public static String shortenText(final GC gc, String text, final int width, final String ellipses) {
if (gc.textExtent(text, 0).x <= width) {
return text;
}
final int ellipseWidth = gc.textExtent(ellipses, 0).x;
final int length = text.length();
final TextLayout layout = new TextLayout(gc.getDevice());
layout.setText(text);
int end = layout.getPreviousOffset(length, SWT.MOVEMENT_CLUSTER);
while (end > 0) {
text = text.substring(0, end);
final int l = gc.textExtent(text, 0).x;
if (l + ellipseWidth <= width) {
break;
}
end = layout.getPreviousOffset(end, SWT.MOVEMENT_CLUSTER);
}
layout.dispose();
return end == 0 ? text.substring(0, 1) : text + ellipses;
}
示例2: getPreferredHeight
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
if (innerTagFactory == null) {
innerTagFactory = new XliffInnerTagFactory(placeHolderBuilder);
}
innerTagFactory.reset();
TextLayout layout = getCellTextLayout(cell);
int counts = layout.getLineCount();
int contentHeight = 0;
for (int i = 0; i < counts; i++) {
contentHeight += layout.getLineBounds(i).height;
}
layout.dispose();
contentHeight += Math.max(counts - 1, 0) * SEGMENT_LINE_SPACING;
contentHeight += 4;// 加上编辑模式下,StyledTextCellEditor的边框
contentHeight += topPadding;
contentHeight += bottomPadding;
return contentHeight;
}
示例3: drawTextLayout
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* @see Graphics#drawTextLayout(TextLayout, int, int, int, int, Color,
* Color)
*/
public void drawTextLayout(TextLayout layout, int x, int y,
int selectionStart, int selectionEnd, Color selectionForeground,
Color selectionBackground) {
TextLayout scaled = zoomTextLayout(layout);
if (scaled == null) {
return;
}
try {
graphics.drawTextLayout(scaled,
(int) Math.floor(x * zoom + fractionalX),
(int) Math.floor(y * zoom + fractionalY), selectionStart,
selectionEnd, selectionBackground, selectionForeground);
} finally {
scaled.dispose();
}
}
示例4: drawBlankString
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
protected void drawBlankString( Graphics g, String s )
{
TextLayout tl = new TextLayout( Display.getCurrent( ) );
// bidi_hcg: Apply text direction
tl.setOrientation( this.rtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT );
tl.setText( s );
Rectangle rc = tl.getBounds( );
int left = ( getClientArea( ).width - rc.width ) / 2;
int top = ( getClientArea( ).height - rc.height ) / 2;
g.drawText( s, getClientArea( ).x + left, getClientArea( ).y + top );
tl.dispose();
}
示例5: getPaintObjectListener
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* Convenience method
*
* @param inWidget
* {@link StyledText}
* @return {@link PaintObjectListener}
*/
public static PaintObjectListener getPaintObjectListener(
final StyledText inWidget) {
return new PaintObjectListener() {
@Override
public void paintObject(final PaintObjectEvent inEvent) {
final Display lDisplay = inEvent.display;
final StyleRange lStyle = inEvent.style;
final int lPosition = inEvent.x + lStyle.metrics.width
- BULLET_WIDTH + 2;
Font lFont = lStyle.font;
if (lFont == null)
lFont = inWidget.getFont();
final TextLayout lLayout = new TextLayout(lDisplay);
lLayout.setAscent(inEvent.ascent);
lLayout.setDescent(inEvent.descent);
lLayout.setFont(lFont);
lLayout.setText(String.format("%s.", inEvent.bulletIndex + 1)); //$NON-NLS-1$
lLayout.draw(inEvent.gc, lPosition, inEvent.y);
lLayout.dispose();
}
};
}
示例6: updateImage
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
protected void updateImage() {
Rectangle bounds = getBounds();
if (bounds.width <= 0 || bounds.height <= 0)
return;
TextLayout layout = new TextLayout(Display.getDefault());
//layout.setFont(getFont());
layout.setText(getText());
for (StyleRange styleRange : ranges) {
//styleRange.background = ColorConstants.white;
layout.setStyle(styleRange, styleRange.start, styleRange.start
+ styleRange.length);
}
if (image != null && !image.isDisposed()) {
image.dispose();
}
image = new Image(Display.getDefault(), bounds.width, bounds.height);
GC gc = new GC(image);
gc.setBackground(ColorConstants.red);
layout.draw(gc, 0, 0);
image.getImageData().transparentPixel = image.getImageData().palette
.getPixel(ColorConstants.white.getRGB());
layout.dispose();
gc.dispose();
}
示例7: shortenText
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* Shorten the given text <code>t</code> so that its length doesn't exceed
* the given width. The default implementation replaces characters in the
* center of the original string with an ellipsis ("...").
* Override if you need a different strategy.
*
* @param gc the gc to use for text measurement
* @param t the text to shorten
* @param width the width to shorten the text to, in pixels
* @return the shortened text
* Note, this code was copied from
* org.eclipse.swt.custom.CLabel.shortenText()
*/
protected String shortenText(GC gc, String t, int width) {
if (t == null) return null;
int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
if (width<=w) return t;
int l = t.length();
int max = l/2;
int min = 0;
int mid = (max+min)/2 - 1;
if (mid <= 0) return t;
TextLayout layout = new TextLayout (getDisplay());
layout.setText(t);
mid = validateOffset(layout, mid);
while (min < mid && mid < max) {
String s1 = t.substring(0, mid);
String s2 = t.substring(validateOffset(layout, l-mid), l);
int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
if (l1+w+l2 > width) {
max = mid;
mid = validateOffset(layout, (max+min)/2);
} else if (l1+w+l2 < width) {
min = mid;
mid = validateOffset(layout, (max+min)/2);
} else {
min = max;
}
}
String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l-mid), l);
layout.dispose();
return result;
}
示例8: paintCell
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
super.paintCell(cell, gc, bounds, configRegistry);
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
TextLayout layout = getCellTextLayout(cell);
Rectangle rectangle = cell.getBounds();
layout.draw(gc, rectangle.x + leftPadding, rectangle.y + topPadding);
layout.dispose();
}
示例9: getPreferredHeight
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
@Override
public int getPreferredHeight(LayerCell cell, GC gc, IConfigRegistry configRegistry) {
TextLayout layout = getCellTextLayout(cell);
int contentHeight = layout.getBounds().height;
layout.dispose();
tuv = null;
contentHeight += topPadding;
contentHeight += bottomPadding;
contentHeight += 4;// 加上编辑模式下,StyledTextCellEditor的边框
return contentHeight;
}
示例10: shortenText
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
*
*
* @param gc
* @param t
* @param width
* @return
*/
protected String shortenText(GC gc, String t, int width) {
if (t == null) return null;
int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
if (width <= w) return t;
int l = t.length();
int max = l / 2;
int min = 0;
int mid = (max + min) / 2 - 1;
if (mid <= 0) return t;
TextLayout layout = new TextLayout(getDisplay());
layout.setText(t);
mid = validateOffset(layout, mid);
while (min < mid && mid < max) {
String s1 = t.substring(0, mid);
String s2 = t.substring(validateOffset(layout, l - mid), l);
int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
if (l1 + w + l2 > width) {
max = mid;
mid = validateOffset(layout, (max + min) / 2);
} else if (l1 + w + l2 < width) {
min = mid;
mid = validateOffset(layout, (max + min) / 2);
} else {
min = max;
}
}
String result = mid == 0 ? t : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l - mid), l);
layout.dispose();
return result;
}
示例11: shortenTextCenter
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
private String shortenTextCenter(final GC gc, final String text, final int width) {
if (text == null) {
return null;
}
final int ellipseWidth = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
if (width <= ellipseWidth) {
return ELLIPSIS;
}
else if ((gc.textExtent(text, DRAW_FLAGS)).x <= width) {
return text;
}
final int l = text.length();
int max = l / 2;
int min = 0;
int mid = (max + min) / 2 - 1;
if (mid <= 0) {
return ELLIPSIS;
}
final TextLayout layout = new TextLayout(getDisplay());
layout.setText(text);
mid = calculateOffset(layout, mid);
while (min < mid && mid < max) {
final String s1 = text.substring(0, mid);
final String s2 = text.substring(calculateOffset(layout, l - mid), l);
final int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
final int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
if (l1 + ellipseWidth + l2 > width) {
max = mid;
mid = calculateOffset(layout, (max + min) / 2);
}
else if (l1 + ellipseWidth + l2 < width) {
min = mid;
mid = calculateOffset(layout, (max + min) / 2);
}
else {
min = max;
}
}
final String result = mid == 0 ? ELLIPSIS : text.substring(0, mid)
+ ELLIPSIS
+ text.substring(calculateOffset(layout, l - mid), l);
layout.dispose();
return result;
}
示例12: createMessageArea
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
@Override
protected Control createMessageArea(Composite parent) {
initializeDialogUnits(parent);
Composite messageComposite= new Composite(parent, SWT.NONE);
messageComposite.setFont(parent.getFont());
GridLayout layout= new GridLayout();
layout.numColumns= 1;
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
messageComposite.setLayout(layout);
messageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Label explain= new Label(messageComposite, SWT.WRAP);
explain.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
explain.setText(FixMessages.CleanUpPostSaveListener_SlowCleanUpWarningDialog_explain);
final BulletListBlock cleanUpListBlock= new BulletListBlock(messageComposite, SWT.NONE);
GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true);
cleanUpListBlock.setLayoutData(gridData);
cleanUpListBlock.setText(fCleanUpNames);
TextLayout textLayout= new TextLayout(messageComposite.getDisplay());
textLayout.setText(fCleanUpNames);
int lineCount= textLayout.getLineCount();
if (lineCount < 5)
gridData.heightHint= textLayout.getLineBounds(0).height * 6;
textLayout.dispose();
Link link= new Link(messageComposite, SWT.NONE);
link.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
link.setText(FixMessages.CleanUpPostSaveListener_SlowCleanUpDialog_link);
link.addSelectionListener(new SelectionAdapter() {
/*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(getShell(), SaveParticipantPreferencePage.PREFERENCE_PAGE_ID, null, null).open();
}
});
return messageComposite;
}
示例13: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + insideMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells
// in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() +
// bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
示例14: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + 3;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
示例15: computeSize
import org.eclipse.swt.graphics.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}