java类org.eclipse.swt.graphics.FontMetrics的实例源码

SwtUtil.java 文件源码 项目:AppleCommander 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SwtUtil.java 文件源码 项目:applecommander 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}
ProgressCanvasViewer.java 文件源码 项目:termsuite-ui 阅读 49 收藏 0 点赞 0 评论 0
/**
   * 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);
  }
PSWTText.java 文件源码 项目:PhET 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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;
}
BasePreferencePage.java 文件源码 项目:team-explorer-everywhere 阅读 26 收藏 0 点赞 0 评论 0
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);
}
BaseControl.java 文件源码 项目:team-explorer-everywhere 阅读 26 收藏 0 点赞 0 评论 0
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);
}
ControlSize.java 文件源码 项目:team-explorer-everywhere 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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();
    }
}
BaseWizardPage.java 文件源码 项目:team-explorer-everywhere 阅读 27 收藏 0 点赞 0 评论 0
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;
}
NgGenerateBlueprintWizardPage.java 文件源码 项目:angular-eclipse 阅读 26 收藏 0 点赞 0 评论 0
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();
}
IndentFoldingStrategy.java 文件源码 项目:typescript.java 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AbstractInformationControl.java 文件源码 项目:typescript.java 阅读 31 收藏 0 点赞 0 评论 0
/**
 * @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);
}
PSWTText.java 文件源码 项目:piccolo2d.java 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ManageSessionsDialog.java 文件源码 项目:skin4eclipse 阅读 28 收藏 0 点赞 0 评论 0
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;
}
CommonLineNumberRulerColumn.java 文件源码 项目:APICloud-Studio 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SwtMisc.java 文件源码 项目:durian-swt 阅读 30 收藏 0 点赞 0 评论 0
/** 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();
}
ImageUtilities.java 文件源码 项目:gef-gwt 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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;
}
FieldEditor.java 文件源码 项目:gef-gwt 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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);
}
LayoutConstants.java 文件源码 项目:gef-gwt 阅读 24 收藏 0 点赞 0 评论 0
private static void initializeConstants() {
    if (dialogMargins != null) {
        return;
    }

    GC gc = new GC(Display.getCurrent());
    gc.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics = gc.getFontMetrics();

    dialogMargins = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_MARGIN),
            Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_MARGIN));

    dialogSpacing = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING),
            Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.VERTICAL_SPACING));

    minButtonSize  = new Point(Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH), 0);

    gc.dispose();
}
SwarmDemo.java 文件源码 项目:MAS 阅读 26 收藏 0 点赞 0 评论 0
@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);

}
DesignerRepresentation.java 文件源码 项目:birt 阅读 28 收藏 0 点赞 0 评论 0
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( );
    }
}
SelectionButtonDialogField.java 文件源码 项目:birt 阅读 22 收藏 0 点赞 0 评论 0
public Control[] doFillIntoGrid( Composite parent, int nColumns )
{
    assertEnoughColumns( nColumns );

    Button button = getSelectionButton( parent );
    GridData gd = new GridData( );
    gd.horizontalSpan = nColumns;
    gd.horizontalAlignment = GridData.FILL;
    if ( fButtonStyle == SWT.PUSH )
    {
        GC gc = new GC( button.getFont( ).getDevice( ) );
        gc.setFont( button.getFont( ) );
        FontMetrics fFontMetrics = gc.getFontMetrics( );
        gc.dispose( );
        int widthHint = Dialog.convertHorizontalDLUsToPixels( fFontMetrics,
                IDialogConstants.BUTTON_WIDTH );
        gd.widthHint = Math.max( widthHint,
                button.computeSize( SWT.DEFAULT, SWT.DEFAULT, true ).x );
    }

    button.setLayoutData( gd );

    return new Control[]{
        button
    };
}
TestProgressBar.java 文件源码 项目:n4js 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Paint.
 */
protected void onPaint(GC gc) {
    final Rectangle b = getBounds();

    final TestStatus status = counter != null ? counter.getAggregatedStatus() : null;
    if (status != null) {

        final int total = Math.max(expectedTotal, counter.getTotal()); // this is our 100% value
        final int value = counter.getTotal(); // current value
        final int totalPx = b.width;
        final int valuePx = Math.round(totalPx * (((float) value) / ((float) total)));

        gc.setBackground(getColorForStatus(status));
        gc.fillRectangle(0, 0, valuePx, b.height);

        gc.setBackground(getBackground());
        gc.fillRectangle(0 + valuePx, 0, b.width - valuePx, b.height);
    } else {
        // clear
        gc.setBackground(getBackground());
        gc.fillRectangle(b);
    }

    if (counter != null) {
        final FontMetrics fm = gc.getFontMetrics();
        gc.setForeground(getForeground());
        final int pending = expectedTotal > 0 ? expectedTotal - counter.getTotal() : -1;
        gc.drawString(counter.toString(true, pending, SWT.RIGHT),
                4, b.height / 2 - fm.getHeight() / 2 - fm.getDescent(), true);
    }
}
KaviList.java 文件源码 项目:eclipse-plugin-commander 阅读 30 收藏 0 点赞 0 评论 0
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;
}
EdgeDefaultSection.java 文件源码 项目:gw4e.project 阅读 28 收藏 0 点赞 0 评论 0
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();
    }
}
VertexDefaultSection.java 文件源码 项目:gw4e.project 阅读 31 收藏 0 点赞 0 评论 0
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();
    }
}
GraphDefaultSection.java 文件源码 项目:gw4e.project 阅读 29 收藏 0 点赞 0 评论 0
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();
    }
}
HydrographInstallationDialog.java 文件源码 项目:Hydrograph 阅读 32 收藏 0 点赞 0 评论 0
public void update(String currentPageId) {
    if (composite == null || composite.isDisposed())
        return;
    GC metricsGC = new GC(composite);
    FontMetrics metrics = metricsGC.getFontMetrics();
    metricsGC.dispose();
    List buttons = (List) buttonMap.get(currentPageId);
    Control[] children = composite.getChildren();

    int visibleChildren = 0;
    Button closeButton = getButton(IDialogConstants.CLOSE_ID);

    for (int i = 0; i < children.length; i++) {
        Control control = children[i];
        if (closeButton == control)
            closeButton.dispose();
        else {
            control.setVisible(false);
            setButtonLayoutData(metrics, control, false);
        }
    }
    if (buttons != null) {
        for (int i = 0; i < buttons.size(); i++) {
            Button button = (Button) buttons.get(i);
            button.setVisible(true);
            setButtonLayoutData(metrics, button, true);
            GridData data = (GridData) button.getLayoutData();
            data.exclude = false;
            visibleChildren++;
        }
    }

    GridLayout compositeLayout = (GridLayout) composite.getLayout();
    compositeLayout.numColumns = visibleChildren;
    composite.layout(true);
}
HydrographInstallationDialog.java 文件源码 项目:Hydrograph 阅读 28 收藏 0 点赞 0 评论 0
protected void setButtonLayoutData(FontMetrics metrics, Control button,
        boolean visible) {
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    int widthHint = Dialog.convertHorizontalDLUsToPixels(metrics,
            IDialogConstants.BUTTON_WIDTH);
    Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    data.widthHint = Math.max(widthHint, minSize.x);
    data.exclude = !visible;
    button.setLayoutData(data);
}
GUI.java 文件源码 项目:albaum 阅读 35 收藏 0 点赞 0 评论 0
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();
    }
}
PSWTText.java 文件源码 项目:PhET 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}


问题


面经


文章

微信
公众号

扫码关注公众号