Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.FontMetrics


        Display display = new Display();
        Shell shell = new Shell(display);
        Label label = new Label(shell, SWT.BORDER);

        GC gc = new GC(label);
        FontMetrics fm = gc.getFontMetrics();

        int height = fm.getHeight();
        label.setSize(label.computeSize(labelWidth, height));

        useOptimiser = true;
        expensiveMethodCallCounter = 0;
        String textUsingOptimiser = getAvailableTextToDisplay(gc,
View Full Code Here


     */
    public static int getButtonWidth( Control control )
    {
        GC gc = new GC( control );
        gc.setFont( JFaceResources.getDialogFont() );
        FontMetrics fontMetrics = gc.getFontMetrics();
        gc.dispose();

        int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
        return width;
    }
View Full Code Here

     */
    public static int getButtonWidth( Control control )
    {
        GC gc = new GC( control );
        gc.setFont( JFaceResources.getDialogFont() );
        FontMetrics fontMetrics = gc.getFontMetrics();
        gc.dispose();

        int width = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
        return width;
    }
View Full Code Here

          if (image != null)
            e.gc.drawImage(image, 5, 5);
          else {
            String[] strings = (String[]) c.getData("STRINGS");
            if (strings != null) {
              FontMetrics metrics = e.gc.getFontMetrics();
              int height = metrics.getHeight();
              int y = 5;
              for (int i = 0; i < strings.length; i++) {
                e.gc.drawString(strings[i], 5, y);
                y += height + 5;
              }
View Full Code Here

     */
    public static Button createButton( Composite parent, String text, int span )
    {
        GC gc = new GC( parent );
        gc.setFont( JFaceResources.getDialogFont() );
        FontMetrics fontMetrics = gc.getFontMetrics();
        gc.dispose();

        Button button = new Button( parent, SWT.PUSH );
        GridData gd = new GridData();
        gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
View Full Code Here

        Point point = progressBar.getSize();
        Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
        e.gc.setFont(font);
        e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
       
        FontMetrics fontMetrics = e.gc.getFontMetrics();
        int stringWidth = fontMetrics.getAverageCharWidth() * string.length();
        int stringHeight = fontMetrics.getHeight();
       
        e.gc.drawString(string, (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
        font.dispose();
      }
    });
View Full Code Here

                    Font font = new Font(display, labelFontData);
                    parent.setFont(font);

                    GC gc = new GC(display);
                    gc.setFont(font);
                    FontMetrics fontMetrics = gc.getFontMetrics();
                    averageCharWidth = fontMetrics.getAverageCharWidth();
                    height = fontMetrics.getHeight();
                    gc.dispose();
                } catch (Throwable e) {
                    //ignore
                }
                return super.createDialogArea(parent);
View Full Code Here

            Paragraph[] paragraphs = model.getParagraphs();
            GC gc = new GC(SapphireFormText.this);
            gc.setFont(getFont());
            Locator loc = new Locator();
            int width = wHint != SWT.DEFAULT ? wHint : 0;
            FontMetrics fm = gc.getFontMetrics();
            int lineHeight = fm.getHeight();
            boolean selectableInTheLastRow = false;
            for (int i = 0; i < paragraphs.length; i++) {
                Paragraph p = paragraphs[i];
                if (i > 0 && getParagraphsSeparated()
                        && p.getAddVerticalSpace())
View Full Code Here

            gc.setBackground(getBackground());

            Locator loc = new Locator();
            loc.marginWidth = marginWidth;
            loc.y = marginHeight;
            FontMetrics fm = gc.getFontMetrics();
            int lineHeight = fm.getHeight();

            Paragraph[] paragraphs = model.getParagraphs();
            IHyperlinkSegment selectedLink = getSelectedLink();
            for (int i = 0; i < paragraphs.length; i++) {
                Paragraph p = paragraphs[i];
View Full Code Here

            oldFont = gc.getFont();
            Font newFont = (Font) objectTable.get(fontId);
            if (newFont != null)
                gc.setFont(newFont);
        }
        FontMetrics fm = gc.getFontMetrics();
        int lineHeight = fm.getHeight();
        boolean newLine = false;

        if (wHint == SWT.DEFAULT || !wrapAllowed) {
            Point extent = gc.textExtent(text);
            int totalExtent = locator.x+extent.x;
            if (isSelectable())
                totalExtent+=1;

            if (wHint != SWT.DEFAULT && totalExtent + locator.marginWidth > wHint) {
                // new line
                locator.resetCaret();
                locator.y += locator.rowHeight;
                if (computeHeightOnly)
                    locator.collectHeights();
                locator.rowHeight = 0;
                locator.leading = 0;
                newLine = true;
            }
            int width = extent.x;
            if (isSelectable())
                width += 1;
            locator.x += width;
            locator.width = locator.x;
            locator.rowHeight = Math.max(locator.rowHeight, extent.y);
            locator.leading = Math.max(locator.leading, fm.getLeading());
            return newLine;
        }

        computeTextFragments(gc);

        int width = 0;
        Point lineExtent = new Point(0, 0);

        for (int i = 0; i < textFragments.length; i++) {
            TextFragment textFragment = textFragments[i];
            int currentExtent = locator.x + lineExtent.x;
           
            if (isSelectable())
                currentExtent += 1;

            // i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0) means:
            // only wrap on the first fragment if we are not at the start of a line
            if ((i != 0 || locator.x > locator.getStartX() + (isSelectable() ? 1 : 0)) && currentExtent + textFragment.length > wHint) {
                // overflow
                int lineWidth = currentExtent;
                locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
                locator.leading = Math.max(locator.leading, fm.getLeading());
                if (computeHeightOnly)
                    locator.collectHeights();
                locator.x = locator.indent;
                locator.y += locator.rowHeight;
                locator.rowHeight = 0;
                locator.leading = 0;
                lineExtent.x = 0;
                lineExtent.y = 0;
                width = Math.max(width, lineWidth);
                newLine = true;
            }
            lineExtent.x += textFragment.length;
            lineExtent.y = Math.max(lineHeight, lineExtent.y);
            width = Math.max (width, locator.x + lineExtent.x);
        }
        int lineWidth = lineExtent.x;
        if (isSelectable())
            lineWidth += 1;
        locator.x += lineWidth;
        locator.width = width;
        locator.rowHeight = Math.max(locator.rowHeight, lineExtent.y);
        locator.leading = Math.max(locator.leading, fm.getLeading());
        if (oldFont != null) {
            gc.setFont(oldFont);
        }
        return newLine;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.FontMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.