Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.FontMetrics


  @Override
  public void createControl(Composite parent) {
    Composite composite = ChromiumRemoteTab.createDefaultComposite(parent);
    setControl(composite);

    FontMetrics fontMetrics = PluginUtil.getFontMetrics(composite, null);

    createVerticalSpan(composite, fontMetrics.getHeight());

    Text text = new Text(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);

    text.setText(NLS.bind(Messages.DevToolsProtocolDeprecationTab_MAIN_TEXT, WIP_CONFIGURATION_TYPE.getName()));

    text.setBackground(parent.getBackground());

    {
      GridData gd = new GridData();
      gd.horizontalAlignment = GridData.FILL;
      gd.grabExcessHorizontalSpace = true;
      gd.widthHint = fontMetrics.getAverageCharWidth() * 44;
      text.setLayoutData(gd);
    }

    Button button = new Button(composite, SWT.PUSH);
    button.setText(Messages.DevToolsProtocolDeprecationTab_COPY_LAUNCH_CONFIGURATION);
    button.addSelectionListener(new SelectionListener() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        try {
          performCopying(launchConfiguration);
        } catch (CoreException e) {
          ChromiumDebugPlugin.log(new Exception("Failed to copy launch configuration", e)); //$NON-NLS-1$
        }
      }

      @Override
      public void widgetDefaultSelected(SelectionEvent e) {
      }
    });

    createVerticalSpan(composite, fontMetrics.getHeight());

    Label seeAlso = new Label(composite, SWT.NONE);
    seeAlso.setText(Messages.DevToolsProtocolDeprecationTab_SEE_ALSO);

    createLink(composite, Messages.DevToolsProtocolDeprecationTab_OLD_PROTOCOL,
View Full Code Here


   * @see org.eclipse.ui.forms.internal.widgets.ParagraphSegment#advanceLocator(org.eclipse.swt.graphics.GC, int, org.eclipse.ui.forms.internal.widgets.Locator, java.util.Hashtable)
   */
  public boolean advanceLocator(GC gc, int wHint, Locator locator,
      Hashtable objectTable, boolean computeHeightOnly) {
    if (locator.rowHeight==0) {
      FontMetrics fm = gc.getFontMetrics();
      locator.rowHeight = fm.getHeight();
    }
    if (computeHeightOnly) locator.collectHeights();   
    locator.resetCaret();
    locator.width = locator.x;
    locator.y += locator.rowHeight;
View Full Code Here

   */
  public void layout(GC gc, int width, Locator locator, Hashtable ResourceTable,
      boolean selected) {
    locator.resetCaret();
    if (locator.rowHeight==0) {
      FontMetrics fm = gc.getFontMetrics();
      locator.rowHeight = fm.getHeight();
    }
    locator.y += locator.rowHeight;
    locator.rowHeight = 0;
    locator.rowCounter++;   
  }
View Full Code Here

  public int getFontHeight() {
    if (fontHeight == -1) {
      Font font = getFont();
      GC gc = new GC(getDisplay());
      gc.setFont(font);
      FontMetrics fm = gc.getFontMetrics();
      fontHeight = fm.getHeight();
      gc.dispose();
    }
    return fontHeight;
  }
View Full Code Here

  public int getFontBaselineHeight() {
    if (fontBaselineHeight == -1) {
      Font font = getFont();
      GC gc = new GC(getDisplay());
      gc.setFont(font);
      FontMetrics fm = gc.getFontMetrics();
      fontBaselineHeight = fm.getHeight() - fm.getDescent();
      gc.dispose();
    }
    return fontBaselineHeight;
  }
View Full Code Here

    label.setText("Macro Name:");
    label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));

    macroNameText = new Text(rootControl, SWT.BORDER | SWT.SINGLE);
    macroNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));;
    final FontMetrics macroNameTextFm = new GC(macroNameText).getFontMetrics();
    GridData requestPortGd = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    requestPortGd.widthHint = macroNameTextFm.getAverageCharWidth() * 50;
    macroNameText.setLayoutData(requestPortGd);

    return rootControl;
  }
View Full Code Here

        Control c = getMessageControl();
        if (c == null)
          return 0;
        GC gc = new GC(c.getDisplay());
        gc.setFont(c.getFont());
        FontMetrics fm = gc.getFontMetrics();
        fontBaselineHeight = fm.getHeight() - fm.getDescent();
        gc.dispose();
      }
      return fontBaselineHeight;
    }
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

      if (newColor != null)
        gc.setForeground(newColor);
    }
    oldBg = gc.getBackground();

    FontMetrics fm = gc.getFontMetrics();
    int lineHeight = fm.getHeight();
    int descent = fm.getDescent();

    // paint area rectangles of the segment
    for (int i = 0; i < areaRectangles.size(); i++) {
      AreaRectangle areaRectangle = (AreaRectangle) areaRectangles.get(i);
      Rectangle rect = areaRectangle.rect;
View Full Code Here

      oldFont = gc.getFont();
      Font newFont = (Font) resourceTable.get(fontId);
      if (newFont != null)
        gc.setFont(newFont);
    }
    FontMetrics fm = gc.getFontMetrics();
    int lineHeight = fm.getHeight();
    int descent = fm.getDescent();

    if (!wrapAllowed) {
      layoutWithoutWrapping(gc, width, locator, selected, fm, lineHeight,
          descent);
    } else {
      int lineStart = 0;
      int lastLoc = 0;
      Point lineExtent = new Point(0, 0);
      computeTextFragments(gc);
      int rightEdge = width-locator.marginWidth;
      for (int i = 0; i < textFragments.length; i++) {
        TextFragment fragment = textFragments[i];
        int breakLoc = fragment.index;
        if (breakLoc == 0)
          continue;
        // (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)) && locator.x + lineExtent.x + fragment.length > rightEdge) {
          // overflow
          if ( i != 0 ) {
            int ly = locator.getBaseline(lineHeight - fm.getLeading());
            Rectangle br = new Rectangle(isSelectable()?
                locator.x - 1:locator.x, ly,
                isSelectable()?lineExtent.x + 1:lineExtent.x, lineHeight - descent + 3);
            areaRectangles
            .add(new AreaRectangle(br, lineStart, lastLoc));
          }

          locator.rowHeight = Math.max(locator.rowHeight,
              lineExtent.y);
          locator.resetCaret();
          if (isSelectable())
            locator.x += 1;         
          locator.y += locator.rowHeight;
          locator.rowCounter++;
          locator.rowHeight = 0;
          lineStart = lastLoc;
          lineExtent.x = 0;
          lineExtent.y = 0;
        }
        lastLoc = breakLoc;
        lineExtent.x += fragment.length;
        lineExtent.y = Math.max(lineHeight, lineExtent.y);
      }
      //String lastLine = text.substring(lineStart, lastLoc);
      int ly = locator.getBaseline(lineHeight - fm.getLeading());
      int lastWidth = lineExtent.x;
      if (isSelectable())
        lastWidth += 1;
      Rectangle br = new Rectangle(isSelectable()?locator.x - 1:locator.x, ly,
          isSelectable()?lineExtent.x + 1:lineExtent.x,
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.