org.eclipse.swt.graphics.GC.stringExtent()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.eclipse.swt.graphics.GC.stringExtent()方法的一些代码示例,展示了GC.stringExtent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GC.stringExtent()方法的具体详情如下:
包路径:org.eclipse.swt.graphics.GC
类名称:GC
方法名:stringExtent

GC.stringExtent介绍

[英]Returns the extent of the given string. No tab expansion or carriage return processing will be performed.

The extent of a string is the width and height of the rectangular area it would cover if drawn in a particular font (in this case, the current font in the receiver).
[中]返回给定字符串的范围。不执行制表符扩展或回车处理。
字符串的范围是以特定字体绘制时将覆盖的矩形区域的宽度和高度(在本例中为接收器中的当前字体)。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

void layout() {
 Composite parent = canvas.getParent();
 Rectangle rect = parent.getClientArea();
 int width = 0;
 String[] items = list.getItems();
 GC gc = new GC( list );
 for ( int i = 0; i < objects.length; i++ ) {
  width = Math.max( width, gc.stringExtent( items[i] ).x );
 }
 gc.dispose();
 Point size1 = start.computeSize( SWT.DEFAULT, SWT.DEFAULT );
 Point size2 = stop.computeSize( SWT.DEFAULT, SWT.DEFAULT );
 Point size3 = check.computeSize( SWT.DEFAULT, SWT.DEFAULT );
 Point size4 = label.computeSize( SWT.DEFAULT, SWT.DEFAULT );
 width = Math.max( size1.x, Math.max( size2.x, Math.max( size3.x, width ) ) );
 width = Math.max( 64, Math.max( size4.x, list.computeSize( width, SWT.DEFAULT ).x ) );
 start.setBounds( 0, 0, width, size1.y );
 stop.setBounds( 0, size1.y, width, size2.y );
 check.setBounds( 0, size1.y + size2.y, width, size3.y );
 label.setBounds( 0, rect.height - size4.y, width, size4.y );
 int height = size1.y + size2.y + size3.y;
 list.setBounds( 0, height, width, rect.height - height - size4.y );
 text.setBounds( width, 0, rect.width - width, rect.height );
 canvas.setBounds( width, 0, rect.width - width, rect.height );
}

代码示例来源:origin: org.microemu/microemu-javase-swt

public int stringWidth(String string) 
{
  return gc.stringExtent(string).x;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.aix.ppc

int getPreferredWidth (GC gc) {
  int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
  if (image != null) {
    width += ExpandItem.TEXT_INSET + imageWidth;
  }
  if (text.length() > 0) {
    width += gc.stringExtent (text).x;
  }
  return width;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.s390x

int getPreferredWidth (GC gc) {
  int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
  if (image != null) {
    width += ExpandItem.TEXT_INSET + imageWidth;
  }
  if (text.length() > 0) {
    width += gc.stringExtent (text).x;
  }
  return width;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.ppc

int getPreferredWidth (GC gc) {
  int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
  if (image != null) {
    width += ExpandItem.TEXT_INSET + imageWidth;
  }
  if (text.length() > 0) {
    width += gc.stringExtent (text).x;
  }
  return width;
}

代码示例来源:origin: org.eclipse.swt.cocoa.macosx/x86_64

int getPreferredWidth (GC gc) {
  int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
  if (image != null) {
    width += ExpandItem.TEXT_INSET + imageWidth;
  }
  if (text.length() > 0) {
    width += gc.stringExtent (text).x;
  }
  return width;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.workbench.texteditor

private int computeMinimumContextColumnWidth(GC gc) {
  int width= gc.stringExtent(TemplatesMessages.TemplatePreferencePage_column_context).x;
  Iterator<TemplateContextType> iter= getContextTypeRegistry().contextTypes();
  while (iter.hasNext()) {
    TemplateContextType contextType= iter.next();
    width= Math.max(width, gc.stringExtent(contextType.getName()).x);
  }
  return width;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench.texteditor

private int computeMinimumContextColumnWidth(GC gc) {
  int width= gc.stringExtent(TemplatesMessages.TemplatePreferencePage_column_context).x;
  Iterator<TemplateContextType> iter= getContextTypeRegistry().contextTypes();
  while (iter.hasNext()) {
    TemplateContextType contextType= iter.next();
    width= Math.max(width, gc.stringExtent(contextType.getName()).x);
  }
  return width;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.examples

@Override
  public Point computeSize(int wHint, int hHint, boolean changed) {
    GC gc = new GC(this);
    Point point = gc.stringExtent(buttonText);
    gc.dispose();
    point.x += MARGIN;
    point.y += MARGIN;
    return point;
  }
};

代码示例来源:origin: BiglySoftware/BiglyBT

private int calcWidth(Date date, String format, String prefix ) {
  GC gc = new GC(Display.getDefault());
  gc.setFont(FontUtils.getAnyFontBold(gc));
  SimpleDateFormat temp = new SimpleDateFormat(format);
  String date_str = temp.format(date);
  if ( prefix != null ){
    date_str = prefix + date_str;
  }
  Point newSize = gc.stringExtent(date_str);
  gc.dispose();
  return newSize.x;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private void createLabel(Composite parent, final String text, final int N_OF_COLUMNS) {
  Separator label= new Separator(SWT.NONE);
  ((Label) label.getSeparator(parent)).setText(text);
  GC gc= new GC(parent);
  int height= gc.stringExtent(text).y;
  gc.dispose();
  label.doFillIntoGrid(parent, N_OF_COLUMNS, height);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private void createLabel(Composite parent, final String text, final int N_OF_COLUMNS) {
  Separator label= new Separator(SWT.NONE);
  ((Label) label.getSeparator(parent)).setText(text);
  GC gc= new GC(parent);
  int height= gc.stringExtent(text).y;
  gc.dispose();
  label.doFillIntoGrid(parent, N_OF_COLUMNS, height);
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private void createLabel(Composite parent, final String text, final int N_OF_COLUMNS) {
  Separator label= new Separator(SWT.NONE);
  ((Label) label.getSeparator(parent)).setText(text);
  GC gc= new GC(parent);
  int height= gc.stringExtent(text).y;
  gc.dispose();
  label.doFillIntoGrid(parent, N_OF_COLUMNS, height);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private int computeWidth(Control control, String name) {
  if (name == null)
    return 0;
  GC gc= new GC(control);
  try {
    gc.setFont(JFaceResources.getDialogFont());
    return gc.stringExtent(name).x + 10;
  } finally {
    gc.dispose();
  }
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private int computeWidth(Control control, String name) {
  if (name == null)
    return 0;
  GC gc= new GC(control);
  try {
    gc.setFont(JFaceResources.getDialogFont());
    return gc.stringExtent(name).x + 10;
  } finally {
    gc.dispose();
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private int computeWidth(Control control, String name) {
  if (name == null)
    return 0;
  GC gc= new GC(control);
  try {
    gc.setFont(JFaceResources.getDialogFont());
    return gc.stringExtent(name).x + 10;
  } finally {
    gc.dispose();
  }
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.xhtmlrenderer/core-renderer

public int getWidth(FontContext context, FSFont font, String string) {
  GC gc = ((SWTFontContext) context).getGC();
  Font previous = gc.getFont();
  gc.setFont(((SWTFSFont) font).getSWTFont());
  int width = gc.stringExtent(string).x;
  gc.setFont(previous);
  return width;
}

代码示例来源:origin: org.eclipse/org.eclipse.ui.workbench.texteditor

private Caret createOverwriteCaret(StyledText styledText) {
  Caret caret= new Caret(styledText, SWT.NULL);
  GC gc= new GC(styledText);
  // XXX this overwrite box is not proportional-font aware
  // take 'a' as a medium sized character
  Point charSize= gc.stringExtent("a"); //$NON-NLS-1$
  
  // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
  caret.setSize(charSize.x, styledText.getLineHeight());
  caret.setFont(styledText.getFont());
  
  gc.dispose();
  return caret;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.workbench.texteditor

private Caret createOverwriteCaret(StyledText styledText) {
  Caret caret= new Caret(styledText, SWT.NULL);
  GC gc= new GC(styledText);
  // XXX: this overwrite box is not proportional-font aware
  // take 'a' as a medium sized character
  Point charSize= gc.stringExtent("a"); //$NON-NLS-1$
  // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
  caret.setSize(charSize.x, styledText.getLineHeight());
  caret.setFont(styledText.getFont());
  gc.dispose();
  return caret;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench.texteditor

private Caret createOverwriteCaret(StyledText styledText) {
  Caret caret= new Caret(styledText, SWT.NULL);
  GC gc= new GC(styledText);
  // XXX: this overwrite box is not proportional-font aware
  // take 'a' as a medium sized character
  Point charSize= gc.stringExtent("a"); //$NON-NLS-1$
  // XXX: Filed request to get a caret with auto-height: https://bugs.eclipse.org/bugs/show_bug.cgi?id=118612
  caret.setSize(charSize.x, styledText.getLineHeight());
  caret.setFont(styledText.getFont());
  gc.dispose();
  return caret;
}

相关文章

微信公众号

最新文章

更多

GC类方法