本文整理汇总了Java中org.eclipse.swt.graphics.GC.stringExtent方法的典型用法代码示例。如果您正苦于以下问题:Java GC.stringExtent方法的具体用法?Java GC.stringExtent怎么用?Java GC.stringExtent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.GC
的用法示例。
在下文中一共展示了GC.stringExtent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawString
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
public static void drawString(GC gc, String str, float x, float y, float width, float height, int bgAlpha) {
if (str == null)
return;
org.eclipse.swt.graphics.Point size = gc.stringExtent(str);
int posX = Math.round(x + width / 2 - size.x / 2);
int posY = Math.round(y + height / 2 - size.y / 2);
if (bgAlpha >= 255) {
gc.drawString(str, posX, posY);
} else {
gc.drawString(str, posX, posY, true);
if (bgAlpha > 0) {
gc.setAlpha(bgAlpha);
gc.fillRectangle(posX, posY, size.x, size.y);
gc.setAlpha(255);
}
}
}
示例2: drawTemporaryLabels
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/**
* draw temporary labels for external nodes (and save their bounds for later)
*/
private List<Rectangle> drawTemporaryLabels(GC gc) {
final List<Rectangle> nodesExternalBounds = new ArrayList<>();
final Rectangle clip = GraphUtils.getClip(gc);
float px = clip.x + clip.width;
float py = clip.y + clip.height;
for (String currNE : endNodesExternal) {
final org.eclipse.swt.graphics.Point size = gc.stringExtent(currNE);
py -= size.y + 4;
final float rx = px - (size.x + 4);
final Rectangle b = new Rectangle(rx, py, size.x, size.y);
nodesExternalBounds.add(b);
// TODO string extent will be computed twice :(
GraphUtils.drawString(gc, currNE, b.x + b.width / 2, b.y + b.height / 2);
}
return nodesExternalBounds;
}
示例3: drawLabel
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/** Draws the label between jumping control flow elements. */
void drawLabel(GC gc, Point p) {
label = "";
for (ControlFlowType cfType : cfTypes) {
switch (cfType) {
case Break:
case Continue:
case Return:
case Throw:
case LoopEnter:
case LoopReenter:
case LoopInfinite:
if (!label.isEmpty())
label += "|";
label += cfType.name();
break;
default:
}
}
org.eclipse.swt.graphics.Point size = gc.stringExtent(label);
float x = p.x - size.x / 2;
float y = p.y - size.y / 2;
GraphUtils.drawString(gc, label, x, y);
}
示例4: computeColumnWidths
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/**
* Pre-compute column widths for the file tab.
* These can and are over-ridden by user sizing.
*/
protected void computeColumnWidths(int format) {
List headers = disks[0].getFileColumnHeaders(format);
int[] headerWidths = new int[headers.size()];
GC gc = new GC(shell);
for (int i=0; i<headers.size(); i++) {
FileColumnHeader header = (FileColumnHeader) headers.get(i);
if (header.getTitle().length() >= header.getMaximumWidth()) {
headerWidths[i] = gc.stringExtent(header.getTitle()).x +
2 * gc.stringExtent(textBundle.get("WidestCharacter")).x; //$NON-NLS-1$
} else {
headerWidths[i] = gc.stringExtent(
textBundle.get("WidestCharacter")).x //$NON-NLS-1$
* header.getMaximumWidth();
}
}
gc.dispose();
gc = null;
columnWidths.put(new Integer(format), headerWidths);
}
示例5: computeSizeOfTextAndImages
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
private Point computeSizeOfTextAndImages() {
int width = 0, height = 0;
final boolean textISNotEmpty = getText() != null && !getText().equals("");
if (textISNotEmpty) {
final GC gc = new GC(this.parentBreadcrumb);
gc.setFont(this.parentBreadcrumb.getFont());
final Point extent = gc.stringExtent(getText());
gc.dispose();
width += extent.x;
height = extent.y;
}
final Point imageSize = computeMaxWidthAndHeightForImages(getImage(),
this.selectionImage, this.disabledImage);
if (imageSize.x != -1) {
width += imageSize.x;
height = Math.max(imageSize.y, height);
if (textISNotEmpty) {
width += MARGIN * 2;
}
}
width += MARGIN;
return new Point(width, height);
}
示例6: trim
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/**
* Change size of receiving Node to its preferred size.
*/
public void trim(GC gc) {
if (title != null) {
final org.eclipse.swt.graphics.Point size = gc.stringExtent(title);
this.width = size.x + BORDER * 2;
this.height = size.y + BORDER * 2;
} else {
this.width = DEFAULT_WIDTH;
this.height = DEFAULT_HEIGHT;
}
}
示例7: getCachedStringExtent
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
private static synchronized Point getCachedStringExtent(GC gc, String text) {
if (m_LastGCFromExtend != gc) {
m_StringExtentCache.clear();
m_LastGCFromExtend = gc;
}
Point p = m_StringExtentCache.get(text);
if (p == null) {
if (text == null)
return new Point(0, 0);
p = gc.stringExtent(text);
m_StringExtentCache.put(text, p);
}
return new Point(p.x, p.y);
}
示例8: getOptimalWidth
import org.eclipse.swt.graphics.GC; //导入方法依赖的package包/类
/**
* Returns the optimal width of the given cell (used by column resizing)
*
* @param col
* @param row
* @param content
* @param fixed
* @return int
*/
public int getOptimalWidth(GC gc, int col, int row, Object content,
boolean fixed) {
return gc.stringExtent(content.toString()).x + 8;
}