當前位置: 首頁>>代碼示例>>Java>>正文


Java FontMetrics.getAverageCharWidth方法代碼示例

本文整理匯總了Java中org.eclipse.swt.graphics.FontMetrics.getAverageCharWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java FontMetrics.getAverageCharWidth方法的具體用法?Java FontMetrics.getAverageCharWidth怎麽用?Java FontMetrics.getAverageCharWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.swt.graphics.FontMetrics的用法示例。


在下文中一共展示了FontMetrics.getAverageCharWidth方法的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: 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

示例4: initializePanel

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
@Override
public void initializePanel(Composite parent) {
  final FillLayout rl = new FillLayout();
  parent.setLayout(rl);
  final Text t = new Text(parent, SWT.SINGLE | SWT.ICON_CANCEL | SWT.CANCEL);
  t.setText(startString);

  final int chars = 30;
  final GC gc = new GC(t);
  final FontMetrics fm = gc.getFontMetrics();
  final int width = chars * fm.getAverageCharWidth();
  final int height = fm.getHeight();
  gc.dispose();
  t.setSize(t.computeSize(width, height));
  t.addListener(SWT.DefaultSelection, this);
  t.addListener(SWT.Modify, this);

}
 
開發者ID:JDevlieghere,項目名稱:MAS,代碼行數:19,代碼來源:SwarmDemo.java

示例5: averageCharacterWidth

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
private int averageCharacterWidth(Font font) {
	int width;
    GC gc = new GC(Display.getDefault());
    gc.setFont(font);
    FontMetrics fontMetrics = gc.getFontMetrics();
	width = fontMetrics.getAverageCharWidth();
	gc.dispose();
	return width;
}
 
開發者ID:dakaraphi,項目名稱:eclipse-plugin-commander,代碼行數:10,代碼來源:KaviList.java

示例6: computeSize

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
@Override
public Point computeSize(final Composite composite, final int wHint, final int hHint, final boolean flush) {
    if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
        return new Point(wHint, hHint);
    }

    final Table table = (Table) composite;

    /* Remove ourselves to avoid recursions */
    table.setLayout(null);
    final Point tableSize = table.computeSize(wHint, hHint, flush);
    table.setLayout(this);

    /* Get the font metrics for the table to handle charWidth */
    final FontMetrics fontMetrics = ControlSize.getFontMetrics(composite);

    int minWidth = 0;

    for (int i = 0; i < columnData.length; i++) {
        int persistWidth = -1;

        if (persistenceStore != null && columnData[i].persistenceKey != null) {
            persistWidth = persistenceStore.getColumnWidth(columnData[i].persistenceKey);
        }

        if (persistWidth >= 0) {
            minWidth += persistWidth;
        } else if (columnData[i].width >= 0) {
            minWidth += columnData[i].width;
        } else if (columnData[i].charWidth >= 0) {
            minWidth += columnData[i].charWidth * fontMetrics.getAverageCharWidth();
        }
    }

    if (minWidth > tableSize.x) {
        tableSize.x = minWidth;
    }

    return tableSize;
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:41,代碼來源:PersistentTableLayout.java

示例7: getCharWidth

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
public static int getCharWidth(Drawable control) {
	GC gc = new GC(control);
	FontMetrics fm = gc.getFontMetrics();
	int w = fm.getAverageCharWidth();
	gc.dispose();
	return w;
}
 
開發者ID:OpenSoftwareSolutions,項目名稱:PDFReporter-Studio,代碼行數:8,代碼來源:UIUtil.java

示例8: calculateStringWidth

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
private int calculateStringWidth(Text text, String time) {
	// Compute the base size of the string, then add 5 chars.
	// Note, that if a short date is displayed, the size will be shorter
	// if the "size" changes over time: ex 10 becomes 100 then at that time the
	// string will grow. For Bedrest its worse since month, and day do not have
	// a leading zero.
	GC gc = new GC(text);
	gc.setFont(text.getFont());
	FontMetrics fontMetrics = gc.getFontMetrics();
	int stringWidth = fontMetrics.getAverageCharWidth() * (time.length() + 5);
	gc.dispose();
	return stringWidth;
}
 
開發者ID:nasa,項目名稱:OpenSPIFe,代碼行數:14,代碼來源:NewPlanResourceWizardPage.java

示例9: getLargestSubstringConfinedTo

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * Returns the largest substring of <i>s</i> in Font <i>f</i> that can be
 * confined to the number of pixels in <i>availableWidth<i>.
 * 
 * @param s
 *            the original string
 * @param f
 *            the font
 * @param availableWidth
 *            the available width
 * @return the largest substring that fits in the given width
 */
public int getLargestSubstringConfinedTo(String s, Font f,
		int availableWidth) {
	FontMetrics metrics = FigureUtilities.getFontMetrics(f);
	int min, max;
	float avg = metrics.getAverageCharWidth();
	min = 0;
	max = s.length() + 1;

	// The size of the current guess
	int guess = 0, guessSize = 0;
	while ((max - min) > 1) {
		// Pick a new guess size
		// New guess is the last guess plus the missing width in pixels
		// divided by the average character size in pixels
		guess = guess + (int) ((availableWidth - guessSize) / avg);

		if (guess >= max)
			guess = max - 1;
		if (guess <= min)
			guess = min + 1;

		// Measure the current guess
		guessSize = getTextExtents(s.substring(0, guess), f).width;

		if (guessSize < availableWidth)
			// We did not use the available width
			min = guess;
		else
			// We exceeded the available width
			max = guess;
	}
	return min;
}
 
開發者ID:ghillairet,項目名稱:gef-gwt,代碼行數:46,代碼來源:TextUtilities.java

示例10: fill

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
public void fill(Composite parent) {
	statusLine = parent;

	Label sep = new Label(parent, SWT.SEPARATOR);
	label = new CLabel(statusLine, SWT.SHADOW_NONE);
	label.setText(text);		
	
	if (charWidth == CALC_TRUE_WIDTH) {
		// compute the size of the label to get the width hint for the contribution
		Point preferredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		widthHint = preferredSize.x;
		heightHint = preferredSize.y;
	} else if (widthHint < 0) {
		// Compute the size base on 'charWidth' average char widths
		GC gc = new GC(statusLine);
		gc.setFont(statusLine.getFont());
		FontMetrics fm = gc.getFontMetrics();
		widthHint = fm.getAverageCharWidth() * charWidth;
		heightHint = fm.getHeight();
		gc.dispose();
	}

	StatusLineLayoutData data = new StatusLineLayoutData();
	data.widthHint = widthHint;
	label.setLayoutData(data);

	data = new StatusLineLayoutData();
	data.heightHint = heightHint;
	sep.setLayoutData(data);
}
 
開發者ID:ghillairet,項目名稱:gef-gwt,代碼行數:31,代碼來源:StatusLineContributionItem.java

示例11: convertCharSizeToPixels

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * <p>
 * Converts a width and height specified in characters to dimensions
 * specified in pixels for the specified {@link Control}.
 * </p>
 *
 * <p>
 * If either <code>charWidth</code> or <code>charHeight</code> are equal to
 * {@link SWT#DEFAULT}, the value {@link SWT#DEFAULT} is used for the
 * corresponding pixel value. This can be useful when computing layout data
 * hints, since most layout data objects that supported width or height
 * hints use the value {@link SWT#DEFAULT} to indicate no hint - the default
 * value.
 * </p>
 *
 * <p>
 * The pixel values are returned as a {@link Point} object, with the
 * calculated pixel width as the <code>x</code> value and the pixel height
 * as the <code>y</code> value.
 * </p>
 *
 * @param control
 *        the control to calculate pixel sizes for (must not be
 *        <code>null</code>)
 * @param charWidth
 *        the width, specified in characters, or {@link SWT#DEFAULT}
 * @param charHeight
 *        the height, specified in characters, or {@link SWT#DEFAULT}
 * @return the computed pixel dimensions as a {@link Point} (never
 *         <code>null</code>)
 */
public static Point convertCharSizeToPixels(final Control control, final int charWidth, final int charHeight) {
    int pixelWidth = SWT.DEFAULT;
    int pixelHeight = SWT.DEFAULT;

    if (charWidth != SWT.DEFAULT || charHeight != SWT.DEFAULT) {
        final FontMetrics fontMetrics = getFontMetrics(control);

        if (charWidth != SWT.DEFAULT) {
            pixelWidth = charWidth * fontMetrics.getAverageCharWidth();
        }
        if (charHeight != SWT.DEFAULT) {
            pixelHeight = charHeight * fontMetrics.getHeight();
        }
    }

    return new Point(pixelWidth, pixelHeight);
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:49,代碼來源:ControlSize.java

示例12: createContents

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
@Override
protected Control createContents(Composite parent) {

	Composite c = new Composite(parent, SWT.NONE);
	c.setLayout(new GridLayout(2, true));

	Label serverAddressText = new Label(c, SWT.LEFT);
	serverAddressText.setText("Server Address:");

	serverAddress = new Text(c, SWT.SINGLE | SWT.LEAD | SWT.BORDER);

	int columns = 15;
	GC gc = new GC(serverAddress);
	FontMetrics fm = gc.getFontMetrics();
	int width = columns * fm.getAverageCharWidth();
	int height = fm.getHeight();
	gc.dispose();
	serverAddress.setSize(serverAddress.computeSize(width, height));

	Label serverPoolingText = new Label(c, SWT.LEFT);
	serverPoolingText.setText("Server Pooling:");

	serverPooling = new Button(c, SWT.CHECK);

	Label poolingIntervalText = new Label(c, SWT.LEFT);
	poolingIntervalText.setText("Pooling Interval (ms):");

	poolingInterval = new Text(c, SWT.SINGLE | SWT.LEAD | SWT.BORDER);

	poolingInterval.addListener(SWT.Verify, new Listener() {
		@Override
		public void handleEvent(Event e) {
			String string = e.text;
			char[] chars = new char[string.length()];
			string.getChars(0, chars.length, chars, 0);
			for (int i = 0; i < chars.length; i++) {
				if (!('0' <= chars[i] && chars[i] <= '9')) {
					e.doit = false;
					return;
				}
			}
		}
	});

	columns = 8;
	gc = new GC(poolingInterval);
	fm = gc.getFontMetrics();
	width = columns * fm.getAverageCharWidth();
	height = fm.getHeight();
	gc.dispose();
	poolingInterval.setSize(poolingInterval.computeSize(width, height));

	initializeValues();

	return new Composite(parent, SWT.NULL);
}
 
開發者ID:FTSRG,項目名稱:mondo-collab-framework,代碼行數:57,代碼來源:EMFGitPreferencePage.java

示例13: convertHorizontalDLUsToPixels

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * Returns the number of pixels corresponding to the given number of
 * horizontal dialog units.
 * <p>
 * The required <code>FontMetrics</code> parameter may be created in the
 * following way: <code>
 * 	GC gc = new GC(control);
 *	gc.setFont(control.getFont());
 *	fontMetrics = gc.getFontMetrics();
 *	gc.dispose();
 * </code>
 * </p>
 * 
 * @param fontMetrics
 *            used in performing the conversion
 * @param dlus
 *            the number of horizontal dialog units
 * @return the number of pixels
 * @since 2.0
 */
public static int convertHorizontalDLUsToPixels(FontMetrics fontMetrics,
		int dlus) {
	// round to the nearest pixel
	return (fontMetrics.getAverageCharWidth() * dlus + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2)
			/ HORIZONTAL_DIALOG_UNIT_PER_CHAR;
}
 
開發者ID:ghillairet,項目名稱:gef-gwt,代碼行數:27,代碼來源:Dialog.java

示例14: convertWidthInCharsToPixels

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * Returns the number of pixels corresponding to the width of the given number
 * of characters.
 * <p>
 * The required <code>FontMetrics</code> parameter may be created in the
 * following way: <code>
 *  GC gc = new GC(control);
 *  gc.setFont(control.getFont());
 *  fontMetrics = gc.getFontMetrics();
 *  gc.dispose();
 * </code>
 * </p>
 * 
 * Note: This code was taken from org.eclipse.jface.dialogs.Dialog.
 * 
 * @param fontMetrics used in performing the conversion
 * @param chars the number of characters
 * @return the number of pixels
 */
public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars) {
  return fontMetrics.getAverageCharWidth() * chars;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:23,代碼來源:SWTUtilities.java

示例15: convertHorizontalDLUsToPixels

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * Returns the number of pixels corresponding to the given number of horizontal dialog units.
 * <p>
 * The required <code>FontMetrics</code> parameter may be created in the following way: <code>
 * 	GC gc = new GC(control);
 *	gc.setFont(control.getFont());
 *	fontMetrics = gc.getFontMetrics();
 *	gc.dispose();
 * </code>
 * </p>
 * 
 * @param fontMetrics
 *            used in performing the conversion
 * @param dlus
 *            the number of horizontal dialog units
 * @return the number of pixels
 * @since 2.0
 */
public static int convertHorizontalDLUsToPixels(final FontMetrics fontMetrics, final int dlus) {
	// round to the nearest pixel
	return (fontMetrics.getAverageCharWidth() * dlus + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2)
			/ HORIZONTAL_DIALOG_UNIT_PER_CHAR;
}
 
開發者ID:wolfgang-ch,項目名稱:mytourbook,代碼行數:24,代碼來源:UI.java


注:本文中的org.eclipse.swt.graphics.FontMetrics.getAverageCharWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。