Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.FontMetrics


     */
    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


  private InputData currentInput = null;

  private LiveEditDiffViewer(Composite parent, Configuration configuration) {
    colors = new Colors(parent.getDisplay());

    FontMetrics defaultFontMetrics = PluginUtil.getFontMetrics(parent, null);

    Composite composite = new Composite(parent, SWT.NONE);
    {
      composite.setLayoutData(new GridData(GridData.FILL_BOTH));
      GridLayout topLayout = new GridLayout();
      topLayout.numColumns = 1;
      composite.setLayout(topLayout);
    }

    Composite labelPairComposite = new Composite(composite, SWT.NONE);
    {
      labelPairComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      FillLayout fillLayout = new FillLayout();
      fillLayout.type = SWT.HORIZONTAL;
      fillLayout.spacing = 5;
      labelPairComposite.setLayout(fillLayout);
    }
    Label labelLeft = new Label(labelPairComposite, SWT.NONE);
    Label labelRight = new Label(labelPairComposite, SWT.NONE);

    Composite fourCells = new Composite(composite, SWT.NONE);
    {
      GridData gd = new GridData(GridData.FILL_BOTH);
      gd.heightHint = defaultFontMetrics.getHeight() * 30;
      gd.widthHint = defaultFontMetrics.getAverageCharWidth() * 85;
      fourCells.setLayoutData(gd);
      FillLayout fillLayout = new FillLayout();
      fillLayout.type = SWT.VERTICAL;
      fillLayout.spacing = 5;
      fourCells.setLayout(fillLayout);
    }

    Composite treePairComposite = new Composite(fourCells, SWT.NONE);
    {
      FillLayout fillLayout = new FillLayout();
      fillLayout.type = SWT.HORIZONTAL;
      fillLayout.spacing = 5;
      treePairComposite.setLayout(fillLayout);
    }

    linkMonitor = new TreeLinkMonitor();

    TreeViewer treeViewerLeft = new TreeViewer(treePairComposite);
    TreeViewer treeViewerRight = new TreeViewer(treePairComposite);

    Composite sourcePairComposite = new Composite(fourCells, SWT.NONE);
    {
      FillLayout fillLayout = new FillLayout();
      fillLayout.type = SWT.HORIZONTAL;
      fillLayout.spacing = 5;
      sourcePairComposite.setLayout(fillLayout);
    }
    SourceViewer sourceViewerLeft =
        new SourceViewer(sourcePairComposite, null, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sourceViewerLeft.getTextWidget().setEditable(false);
    SourceViewer sourceViewerRight =
        new SourceViewer(sourcePairComposite, null, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sourceViewerRight.getTextWidget().setEditable(false);

    {
      functionStatusText = new Text(composite, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
      Display display = composite.getDisplay();
      functionStatusText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

      GridData gd = new GridData(GridData.FILL_BOTH);
      gd.minimumHeight = defaultFontMetrics.getHeight() * 3;
      gd.heightHint = gd.minimumHeight;
      gd.grabExcessHorizontalSpace = true;
      gd.horizontalAlignment = GridData.FILL;
      functionStatusText.setLayoutData(gd);
    }
View Full Code Here

   */
  private static float[] deriveRotationAnchorOffsets(final GC g2,
      final String text, final TextAnchor anchor) {

    final float[] result = new float[2];
    final FontMetrics fm = g2.getFontMetrics();
    final Rectangle bounds = TextUtilities.getTextBounds(text, g2);
    final float ascent = fm.getAscent();
    final float halfAscent = ascent / 2.0f;
    final float descent = fm.getDescent();
    final float leading = fm.getLeading();
    float xAdj = 0.0f;
    float yAdj = 0.0f;

    if ((anchor == TextAnchor.TOP_LEFT)
        || (anchor == TextAnchor.CENTER_LEFT)
        || (anchor == TextAnchor.BOTTOM_LEFT)
        || (anchor == TextAnchor.BASELINE_LEFT)
        || (anchor == TextAnchor.HALF_ASCENT_LEFT)) {

      xAdj = 0.0f;

    } else if ((anchor == TextAnchor.TOP_CENTER)
        || (anchor == TextAnchor.CENTER)
        || (anchor == TextAnchor.BOTTOM_CENTER)
        || (anchor == TextAnchor.BASELINE_CENTER)
        || (anchor == TextAnchor.HALF_ASCENT_CENTER)) {

      xAdj = bounds.width / 2.0f;

    } else if ((anchor == TextAnchor.TOP_RIGHT)
        || (anchor == TextAnchor.CENTER_RIGHT)
        || (anchor == TextAnchor.BOTTOM_RIGHT)
        || (anchor == TextAnchor.BASELINE_RIGHT)
        || (anchor == TextAnchor.HALF_ASCENT_RIGHT)) {

      xAdj = bounds.width;

    }

    if ((anchor == TextAnchor.TOP_LEFT)
        || (anchor == TextAnchor.TOP_CENTER)
        || (anchor == TextAnchor.TOP_RIGHT)) {

      yAdj = descent + leading - bounds.height;

    } else if ((anchor == TextAnchor.CENTER_LEFT)
        || (anchor == TextAnchor.CENTER)
        || (anchor == TextAnchor.CENTER_RIGHT)) {

      yAdj = descent + leading - (float) (bounds.height / 2.0);

    } else if ((anchor == TextAnchor.HALF_ASCENT_LEFT)
        || (anchor == TextAnchor.HALF_ASCENT_CENTER)
        || (anchor == TextAnchor.HALF_ASCENT_RIGHT)) {

      yAdj = -halfAscent;

    } else if ((anchor == TextAnchor.BASELINE_LEFT)
        || (anchor == TextAnchor.BASELINE_CENTER)
        || (anchor == TextAnchor.BASELINE_RIGHT)) {

      yAdj = 0.0f;

    } else if ((anchor == TextAnchor.BOTTOM_LEFT)
        || (anchor == TextAnchor.BOTTOM_CENTER)
        || (anchor == TextAnchor.BOTTOM_RIGHT)) {

      yAdj = fm.getDescent() + fm.getLeading();

    }
    result[0] = xAdj;
    result[1] = yAdj;
    return result;
View Full Code Here

  private static float[] deriveTextBoundsAnchorOffsets(final GC g2,
      final String text, final TextAnchor anchor,
      final Rectangle textBounds) {

    final float[] result = new float[2];
    final FontMetrics fm = g2.getFontMetrics();
    final Rectangle bounds = TextUtilities.getTextBounds(text, g2);
    final float ascent = fm.getAscent();
    final float halfAscent = ascent / 2.0f;
    final float leading = fm.getLeading();

    float xAdj = 0.0f;
    float yAdj = 0.0f;

    // Horizontal adjustment
View Full Code Here

   * @return the offset.
   */
  public float calculateBaselineOffset(final GC g2, final TextAnchor anchor) {
    float result = 0.0f;
    g2.setFont(this.font);
    final FontMetrics fm = g2.getFontMetrics();
    if ((anchor == TextAnchor.TOP_LEFT)
        || (anchor == TextAnchor.TOP_CENTER)
        || (anchor == TextAnchor.TOP_RIGHT)) {
      result = fm.getAscent();
    } else if ((anchor == TextAnchor.BOTTOM_LEFT)
        || (anchor == TextAnchor.BOTTOM_CENTER)
        || (anchor == TextAnchor.BOTTOM_RIGHT)) {
      result = -fm.getDescent() - fm.getLeading();
    }
    return result;
  }
View Full Code Here

      int availableWidth, float avg, int wrapping) {
    if (string.length() == 0) {
      return 0;
    }

    FontMetrics metrics = getFontMetrics(font);
    BreakIterator breakItr = BreakIterator.getLineInstance();
    breakItr.setText(string);
    int MIN, min, max;
    if (avg == 0.0) {
      avg = metrics.getAverageCharWidth();
    }

    int firstBreak = breakItr.next();

    int winNL = string.indexOf("\r\n"); //$NON-NLS-1$
View Full Code Here

    // while (frag.length > 0 &&
    // Character.isElementContentWhitespace(s.charAt(frag.length - 1)))
    // frag.length--;
    frag.setTextData(s.substring(0, frag._length));
    Dimension d = getStringExtents2(s.substring(0, frag._length), f);
    FontMetrics fm = getFontMetrics(f);
    frag.setHeight(fm.getHeight());
    frag.setAscent(fm.getAscent() + fm.getLeading());
    if (frag._length > 0
        && Character.isWhitespace(s.charAt(frag._length - 1))) {
      frag._isLastCharWhitespace = true;
    } else {
      frag._isLastCharWhitespace = false;
View Full Code Here

        + ELLIPSIS);
    return subStringText;
  }

  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;
View Full Code Here

       * 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) {
            fIsVisible = false;
            return;
          }
        }
      }
View Full Code Here

   */
  private int convertWidthInCharsToPixels(Control testControl, int chars) {
    // Compute and store a font metric
    GC gc = new GC(testControl);
    gc.setFont(JFaceResources.getDialogFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    // test for failure to initialize for backward compatibility
    if (fontMetrics == null)
      return 0;
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.