当前位置: 首页>>代码示例>>Java>>正文


Java FontMetrics类代码示例

本文整理汇总了Java中org.eclipse.swt.graphics.FontMetrics的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics类的具体用法?Java FontMetrics怎么用?Java FontMetrics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FontMetrics类属于org.eclipse.swt.graphics包,在下文中一共展示了FontMetrics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupPagingInformation

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Setup some sensible paging information.
 */
public static void setupPagingInformation(ScrolledComposite composite) {
	GC gc = new GC(composite);
	FontMetrics fontMetrics = gc.getFontMetrics();
	gc.dispose();
	int fontHeight = fontMetrics.getHeight();
	int fontWidth = fontMetrics.getAverageCharWidth();
	Rectangle clientArea = composite.getClientArea();
	int lines = clientArea.height / fontHeight;
	int pageHeight = lines * fontHeight;
	int pageWidth = clientArea.width - fontWidth; 
	composite.getVerticalBar().setIncrement(fontHeight);
	composite.getVerticalBar().setPageIncrement(pageHeight);
	composite.getHorizontalBar().setIncrement(fontWidth);
	composite.getHorizontalBar().setPageIncrement(pageWidth);
}
 
开发者ID:AppleCommander,项目名称:AppleCommander,代码行数:19,代码来源:SwtUtil.java

示例2: getSizeHints

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
   * Get the size hints for the receiver. These are used for
   * layout data.
   * @return Point - the preferred x and y coordinates
   */
  public Point getSizeHints() {

      Display display = canvas.getDisplay();

      GC gc = new GC(canvas);
      FontMetrics fm = gc.getFontMetrics();
      int charWidth = fm.getAverageCharWidth();
      int charHeight = fm.getHeight();
      int maxWidth = display.getBounds().width / 2;
      int maxHeight = display.getBounds().height / 6;
      int fontWidth = charWidth * maxCharacterWidth;
      int fontHeight = charHeight * numShowItems;
      if (maxWidth < fontWidth) {
	fontWidth = maxWidth;
}
      if (maxHeight < fontHeight) {
	fontHeight = maxHeight;
}
      gc.dispose();
      return new Point(fontWidth, fontHeight);
  }
 
开发者ID:termsuite,项目名称:termsuite-ui,代码行数:27,代码来源:ProgressCanvasViewer.java

示例3: calculateTextBounds

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Calculates the bounds of the text in the box as measured by the given
 * graphics context and font metrics.
 * 
 * @param gc graphics context from which the measurements are done
 * @return point representing the dimensions of the text's bounds
 */
private Point calculateTextBounds(final GC gc) {
    final SWTGraphics2D g2 = new SWTGraphics2D(gc, Display.getDefault());
    g2.setFont(font);
    final FontMetrics fm = g2.getSWTFontMetrics();
    final Point textBounds = new Point(0, 0);

    boolean firstLine = true;

    final Iterator lineIterator = lines.iterator();
    while (lineIterator.hasNext()) {
        String line = (String) lineIterator.next();
        Point lineBounds = gc.stringExtent(line);
        if (firstLine) {
            textBounds.x = lineBounds.x;
            textBounds.y += fm.getAscent() + fm.getDescent() + fm.getLeading();
            firstLine = false;
        }
        else {
            textBounds.x = Math.max(lineBounds.x, textBounds.x);
            textBounds.y += fm.getHeight();
        }
    }

    return textBounds;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:PSWTText.java

示例4: computeMetrics

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
private void computeMetrics() {
    Control control = getControl();

    if (control == null && Display.getCurrent() != null) {
        control = Display.getCurrent().getActiveShell();
    }

    if (control == null) {
        return;
    }

    /* Compute metrics in pixels */
    final GC gc = new GC(control);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);
}
 
开发者ID:Microsoft,项目名称:team-explorer-everywhere,代码行数:25,代码来源:BasePreferencePage.java

示例5: BaseControl

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
public BaseControl(final Composite parent, final int style) {
    super(parent, style);

    /* Compute metrics in pixels */
    final GC gc = new GC(this);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);

    minimumMessageAreaWidth =
        Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
}
 
开发者ID:Microsoft,项目名称:team-explorer-everywhere,代码行数:20,代码来源:BaseControl.java

示例6: getFontMetrics

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Obtains a {@link FontMetrics} object corresponding to the specified
 * {@link Control}. This method creates and disposes a {@link GC} object to
 * get {@link FontMetrics}.
 *
 * @param control
 *        a {@link Control} to get {@link FontMetrics} for (must not be
 *        <code>null</code>)
 * @return a {@link FontMetrics} object (never <code>null</code>)
 */
public static FontMetrics getFontMetrics(final Control control) {
    Check.notNull(control, "control"); //$NON-NLS-1$

    /*
     * TODO A possible performance enhancement would be to cache the
     * FontMetrics on a Control (control.setData). This would allow multiple
     * calls to this method for the same control to avoid the overhead of
     * creating and disposing a GC each time. We should do this only if
     * profiling indicates a performance problem. If we do this, we should
     * provide an overload of this method that takes a boolean that controls
     * whether the cache is used or not - useful when the client changes the
     * font on a control in between calls, etc.
     */

    final GC gc = new GC(control);
    try {
        gc.setFont(control.getFont());
        return gc.getFontMetrics();
    } finally {
        gc.dispose();
    }
}
 
开发者ID:Microsoft,项目名称:team-explorer-everywhere,代码行数:33,代码来源:ControlSize.java

示例7: computeMetrics

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
private final void computeMetrics() {
    Control control = getControl();

    if (control == null && Display.getCurrent() != null) {
        control = Display.getCurrent().getActiveShell();
    }

    if (control == null) {
        return;
    }

    /* Compute metrics in pixels */
    final GC gc = new GC(control);
    final FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING);
    verticalSpacing = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING);

    spacing = Math.max(horizontalSpacing, verticalSpacing);

    horizontalMargin = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN);
    verticalMargin = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN);

    initializedMetrics = true;
}
 
开发者ID:Microsoft,项目名称:team-explorer-everywhere,代码行数:27,代码来源:BaseWizardPage.java

示例8: createFilesPreviewControl

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
protected void createFilesPreviewControl(Composite parent) {
	Font font = parent.getFont();
	// file preview group
	Composite filePreview = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout();
	layout.numColumns = 1;
	layout.marginWidth = 0;
	filePreview.setLayout(layout);
	filePreview.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
	filePreview.setFont(font);

	// Generated files
	Label label = new Label(filePreview, SWT.NONE);
	label.setText(AngularCLIMessages.NgGenerateBlueprintWizardPage_generated_files);
	label.setFont(font);

	generatedFiles = new Text(filePreview, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL);
	GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
	GC gc = new GC(generatedFiles);
	gc.setFont(font);
	FontMetrics fm = gc.getFontMetrics();
	data.heightHint = 7 * fm.getHeight();
	generatedFiles.setLayoutData(data);
	gc.dispose();
}
 
开发者ID:angelozerr,项目名称:angular-eclipse,代码行数:26,代码来源:NgGenerateBlueprintWizardPage.java

示例9: paint

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Does not paint hidden annotations. Annotations are hidden when they
 * only span one line.
 * 
 * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC,
 *      org.eclipse.swt.widgets.Canvas,
 *      org.eclipse.swt.graphics.Rectangle)
 */
@Override
public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
	/* workaround for BUG85874 */
	/*
	 * only need to check annotations that are expanded because hidden
	 * annotations should never have been given the chance to collapse.
	 */
	if (!isCollapsed()) {
		// working with rectangle, so line height
		FontMetrics metrics = gc.getFontMetrics();
		if (metrics != null) {
			// do not draw annotations that only span one line and
			// mark them as not visible
			if ((rectangle.height / metrics.getHeight()) <= 1) {
				visible = false;
				return;
			}
		}
	}
	visible = true;
	super.paint(gc, canvas, rectangle);
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:31,代码来源:IndentFoldingStrategy.java

示例10: createFilterText

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * @param parent
 *            parent control
 */
private void createFilterText(Composite parent) {
	// Create the widget
	filterText = new Text(parent, SWT.NONE);
	// Set the font
	GC gc = new GC(parent);
	gc.setFont(parent.getFont());
	FontMetrics fontMetrics = gc.getFontMetrics();
	gc.dispose();
	// Create the layout
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1);
	data.horizontalAlignment = GridData.FILL;
	data.verticalAlignment = GridData.CENTER;
	filterText.setLayoutData(data);
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:20,代码来源:AbstractInformationControl.java

示例11: getButtonGridData

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
private GridData getButtonGridData(Button button) {
    GridData gd = new GridData(GridData.FILL_HORIZONTAL
            | GridData.VERTICAL_ALIGN_BEGINNING);
    GC gc = new GC(button);
    gc.setFont(button.getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();
    int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics,
            IDialogConstants.BUTTON_WIDTH);
    gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT,
            true).x);

    gd.heightHint = Dialog
    .convertVerticalDLUsToPixels(fontMetrics, 14 /*IDialogConstants.BUTTON_HEIGHT*/);
    return gd;
}
 
开发者ID:iloveeclipse,项目名称:skin4eclipse,代码行数:17,代码来源:ManageSessionsDialog.java

示例12: getBaselineBias

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Returns the difference between the baseline of the widget and the
 * baseline as specified by the font for <code>gc</code>. When drawing
 * line numbers, the returned bias should be added to obtain text lined up
 * on the correct base line of the text widget.
 *
 * @param gc the <code>GC</code> to get the font metrics from
 * @param widgetLine the widget line
 * @return the baseline bias to use when drawing text that is lined up with
 *         <code>fCachedTextWidget</code>
 * @since 3.2
 */
private int getBaselineBias(GC gc, int widgetLine) {
	/*
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951
	 * widget line height may be more than the font height used for the
	 * line numbers, since font styles (bold, italics...) can have larger
	 * font metrics than the simple font used for the numbers.
	 */
	int offset= fCachedTextWidget.getOffsetAtLine(widgetLine);
	int widgetBaseline= fCachedTextWidget.getBaseline(offset);

	FontMetrics fm= gc.getFontMetrics();
	int fontBaseline= fm.getAscent() + fm.getLeading();
	int baselineBias= widgetBaseline - fontBaseline;
	return Math.max(0, baselineBias);
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:28,代码来源:CommonLineNumberRulerColumn.java

示例13: populateSystemFont

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/** Populates the height and width of the system font. */
private static void populateSystemFont() {
	// create a tiny image to bind our GC to (not that it can't be size 0)
	Image dummyImg = new Image(assertUI(), 1, 1);
	GC gc = new GC(dummyImg);

	FontMetrics metrics = gc.getFontMetrics();
	systemFontHeight = metrics.getHeight();
	systemFontWidth = metrics.getAverageCharWidth();
	if (OS.getNative().isMac()) {
		// add 20% width on Mac
		systemFontWidth = (systemFontWidth * 12) / 10;
	}

	gc.dispose();
	dummyImg.dispose();
}
 
开发者ID:diffplug,项目名称:durian-swt,代码行数:18,代码来源:SwtMisc.java

示例14: createRotatedImageOfString

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Returns a new Image with the given String rotated left (by 90 degrees).
 * The String will be rendered using the provided colors and fonts. The
 * client is responsible for disposing the returned Image. Strings cannot
 * contain newline or tab characters.
 * 
 * @param string
 *            the String to be rendered
 * @param font
 *            the font
 * @param foreground
 *            the text's color
 * @param background
 *            the background color
 * @return an Image which must be disposed
 */
public static Image createRotatedImageOfString(String string, Font font,
		Color foreground, Color background) {
	Display display = Display.getDefault();

	FontMetrics metrics = FigureUtilities.getFontMetrics(font);
	Dimension strSize = FigureUtilities.getStringExtents(string, font);
	Image srcImage = new Image(display, strSize.width, metrics.getAscent());
	GC gc = new GC(srcImage);
	gc.setFont(font);
	gc.setForeground(foreground);
	gc.setBackground(background);
	gc.fillRectangle(srcImage.getBounds());
	gc.drawString(string, 0, 0 - metrics.getLeading());
	Image result = createRotatedImage(srcImage);
	gc.dispose();
	srcImage.dispose();
	return result;
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:35,代码来源:ImageUtilities.java

示例15: setButtonLayoutData

import org.eclipse.swt.graphics.FontMetrics; //导入依赖的package包/类
/**
 * Set the GridData on button to be one that is spaced for the
 * current font.
 * @param button the button the data is being set on.
 */

protected void setButtonLayoutData(Button button) {

    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);

    // Compute and store a font metric
    GC gc = new GC(button);
    gc.setFont(button.getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    int widthHint = org.eclipse.jface.dialogs.Dialog
            .convertVerticalDLUsToPixels(fontMetrics,
                    IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT,
            SWT.DEFAULT, true).x);
    button.setLayoutData(data);
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:24,代码来源:FieldEditor.java


注:本文中的org.eclipse.swt.graphics.FontMetrics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。