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


Java FontMetrics.getHeight方法代碼示例

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


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

示例5: 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

示例6: 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

示例7: 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

示例8: showNullChart

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
private void showNullChart( Dimension dSize )
{
    // Display error message for null chart. This behavior is consistent
    // with invalid table.
    String MSG = Messages.getString( "DesignerRepresentation.msg.InvalidChart" ); //$NON-NLS-1$
    logger.log( ILogger.ERROR,
            Messages.getString( "DesignerRepresentation.log.UnableToFind" ) ); //$NON-NLS-1$

    Device dv = Display.getCurrent( );
    Font font = FontManager.getFont( "Dialog", 10, SWT.ITALIC ); //$NON-NLS-1$
    gc.setFont( font );
    FontMetrics fm = gc.getFontMetrics( );
    gc.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
    gc.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
    gc.fillRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
    gc.drawRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
    String[] texts = splitOnBreaks( MSG, font, dSize.width - 10 );
    int y = 5;
    for ( String text : texts )
    {
        gc.drawText( text, 5, y );
        y += fm.getHeight( );
    }
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:25,代碼來源:DesignerRepresentation.java

示例9: setHeight

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
private void setHeight(FormData fd, Control control, int rowcount) {
    GC gc = new GC(control);
    try {
        gc.setFont(control.getFont());
        FontMetrics fm = gc.getFontMetrics();
        fd.height = rowcount * fm.getHeight();
    } finally {
        gc.dispose();
    }
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:11,代碼來源:EdgeDefaultSection.java

示例10: getReaderSize

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
private int getReaderSize(final KeyText r) {
    final GC gc = new GC(r);
    try
    {
        gc.setFont(r.getFont());
        final FontMetrics fm = gc.getFontMetrics();
        return READER_ROWS * fm.getHeight();
    }
    finally {
        gc.dispose();
    }
}
 
開發者ID:moforw,項目名稱:albaum,代碼行數:13,代碼來源:GUI.java

示例11: paintAsText

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
/**
 * Paints this object normally (show it's text). Note that the entire text
 * gets rendered so that it's upper left corner appears at the origin of
 * this local object.
 * 
 * @param ppc The graphics context to paint into.
 */
public void paintAsText(final PPaintContext ppc) {
    final SWTGraphics2D sg2 = (SWTGraphics2D) ppc.getGraphics();

    if (!transparent) {
        if (getPaint() == null) {
            sg2.setBackground(Color.WHITE);
        }
        else {
            sg2.setBackground((Color) getPaint());
        }

        sg2.fillRect(0, 0, (int) getWidth(), (int) getHeight());
    }

    sg2.translate(padding, padding);

    sg2.setColor(penColor);
    sg2.setFont(font);

    String line;
    double y = 0;

    final FontMetrics fontMetrics = sg2.getSWTFontMetrics();

    final Iterator lineIterator = lines.iterator();
    while (lineIterator.hasNext()) {
        line = (String) lineIterator.next();
        if (line.length() != 0) {
            sg2.drawString(line, 0, y, true);
        }

        y += fontMetrics.getHeight();
    }

    sg2.translate(-padding, -padding);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:44,代碼來源:PSWTText.java

示例12: TextHeight

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
public static int TextHeight(final Text control, final int width) {
    final GC gc = new GC(control);
    final FontMetrics fm = gc.getFontMetrics();
    gc.dispose();

    if (control.getText() == null) {
        return SWT.DEFAULT;
    }

    return (fm.getHeight()
        * (int) Math.ceil((((fm.getAverageCharWidth() * 1.0) * control.getText().length()) / width) + 0.25)) + 2;
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:13,代碼來源:FormHelper.java

示例13: getCharHeight

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

示例14: paintFigure

import org.eclipse.swt.graphics.FontMetrics; //導入方法依賴的package包/類
@Override
protected void paintFigure(Graphics g) {
    super.paintFigure(g);
    FontMetrics fm = FigureUtilities.getFontMetrics(getFont());
    int h = fm.getHeight();
    int y = h;
    boolean first = true;
    String symbolicFontName = getFont().toString();
    Font boldFont = FontUtils.FONT_REGISTRY_INSTANCE.getBold(symbolicFontName);
    for (DateFormat format : dateFormats) {
        try {
            g.pushState();
            if (first) {
                g.setFont(boldFont);
                first = false;
            }
            String id = DateFormatRegistry.INSTANCE.getDateFormatID(format);
            if (id==null) id = "";
            g.drawText(id, 5, y);
            
            if (cursorTime != null) {
                String date = format.format(cursorTime);
                int width = FigureUtilities.getTextWidth(date, getFont()) + 5;
                g.drawText(date, bounds.width - width, y);
            }
            
            y += h;
        } finally {
            g.popState();
        }
    }
    //boldFont.dispose();
}
 
開發者ID:nasa,項目名稱:OpenSPIFe,代碼行數:34,代碼來源:ScaleHeaderFigure.java

示例15: 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


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