Example #1
0
 /**
  * Shorten the given text <code>t</code> so that its length doesn't exceed the given width. The
  * default implementation replaces characters in the center of the original string with an
  * ellipsis ("..."). Override if you need a different strategy.
  *
  * @param gc the gc to use for text measurement
  * @param t the text to shorten
  * @param width the width to shorten the text to, in pixels
  * @return the shortened text
  */
 protected String shortenText(GC gc, String t, int width) {
   if (t == null) return null;
   int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
   if (width <= w) return t;
   int l = t.length();
   int max = l / 2;
   int min = 0;
   int mid = (max + min) / 2 - 1;
   if (mid <= 0) return t;
   TextLayout layout = new TextLayout(getDisplay());
   layout.setText(t);
   mid = validateOffset(layout, mid);
   while (min < mid && mid < max) {
     String s1 = t.substring(0, mid);
     String s2 = t.substring(validateOffset(layout, l - mid), l);
     int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
     int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
     if (l1 + w + l2 > width) {
       max = mid;
       mid = validateOffset(layout, (max + min) / 2);
     } else if (l1 + w + l2 < width) {
       min = mid;
       mid = validateOffset(layout, (max + min) / 2);
     } else {
       min = max;
     }
   }
   String result =
       mid == 0
           ? t
           : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l - mid), l);
   layout.dispose();
   return result;
 }
Example #2
0
  /**
   * Draws the rotated text.
   *
   * @param gc the graphics context
   * @param text the text
   * @param x the x coordinate
   * @param y the y coordinate
   * @param angle the angle
   */
  private void drawRotatedText(GC gc, String text, float x, float y, int angle) {

    int textWidth = gc.textExtent(text).x;
    int textHeight = gc.textExtent(text).y;

    // create image to draw text
    Image image = new Image(Display.getCurrent(), textWidth, textHeight);
    GC tmpGc = new GC(image);
    tmpGc.setForeground(getForeground());
    tmpGc.setBackground(gc.getBackground());
    tmpGc.setFont(getFont());
    tmpGc.drawText(text, 0, 0);

    // set transform to rotate
    Transform transform = new Transform(gc.getDevice());
    transform.translate(x, y);
    transform.rotate(360 - angle);
    gc.setTransform(transform);

    // draw the image on the rotated graphics context
    gc.drawImage(image, 0, 0);

    // dispose resources
    tmpGc.dispose();
    transform.dispose();
    image.dispose();
    gc.setTransform(null);
  }
 private static int getLargestActionType(GC gc, IParametricDerivationGraph graph) {
   int max = gc.textExtent("tauw").x; // tau action
   for (IGeneratingFunction f : graph.getGeneratingFunctions())
     max =
         Math.max(
             max,
             gc.textExtent(graph.getSymbolGenerator().getActionLabel(f.getActionId()) + "w").x);
   return max;
 }
Example #4
0
  private void setTitle(String title) {
    int textWidth = titleGC.textExtent(title).x;
    int textHeight = titleGC.textExtent(title).y;

    titleLabel.setText(title);
    titleLabel.setSize(textWidth, textHeight);

    setTitleLocation();
  }
  /**
   * Fills this field editor's basic controls into the given parent.
   *
   * <p>The string field implementation of this <code>FieldEditor</code> framework method
   * contributes the text field. Subclasses may override but must call <code>super.doFillIntoGrid
   * </code>.
   */
  protected void doFillIntoGrid(Composite parent, int numColumns) {
    getLabelControl(parent);

    textField = getTextControl(parent);
    GridData gd = new GridData();
    gd.horizontalSpan = numColumns - 1;
    if (widthInChars != UNLIMITED) {
      GC gc = new GC(textField);
      try {
        Point extent = gc.textExtent("X"); // $NON-NLS-1$
        gd.widthHint = widthInChars * extent.x;
      } finally {
        gc.dispose();
      }
    } else {
      //            System.out.println("fill");
      gd.horizontalAlignment = GridData.FILL_BOTH;
      gd.verticalSpan = 4;
      gd.horizontalSpan = 1;
      gd.grabExcessVerticalSpace = true;
      gd.widthHint = 400;
      gd.heightHint = 60;
      //            gd.grabExcessHorizontalSpace = true;
    }
    textField.setLayoutData(gd);
  }
  /** Reads the next line. The lengths of the line will not exceed the gived maximum width. */
  public String readLine() throws IOException {
    if (fLine == null) {
      String line = fReader.readLine();
      if (line == null) return null;

      int lineLen = fGC.textExtent(line).x;
      if (lineLen < fMaxWidth) {
        return line;
      }
      fLine = line;
      fLineBreakIterator.setText(line);
      fOffset = 0;
    }
    int breakOffset = findNextBreakOffset(fOffset);
    String res;
    if (breakOffset != BreakIterator.DONE) {
      res = fLine.substring(fOffset, breakOffset);
      fOffset = findWordBegin(breakOffset);
      if (fOffset == fLine.length()) {
        fLine = null;
      }
    } else {
      res = fLine.substring(fOffset);
      fLine = null;
    }
    return res;
  }
Example #7
0
  /**
   * ******************************************************************************************
   *
   * <p>Given a line of text and a position, returns the character position within this line.
   *
   * @param text The line of text. Can be looked up through getLine() and getTextForLine()
   * @param mouseX The x coordinate in the line
   * @return The character clicked on (or -1 if none)
   *     ******************************************************************************************
   */
  public int getCharacterPosition(String text, int mouseX) {
    // The only way to compute this I can think of to compute which
    // character was clicked on
    // is to generate each substring in turn and check its length against
    // the point.
    // When we reach the correct length of string we've found the character.
    // This is slow and a bit clumsy, but since it's just on a right-click I
    // think it's ok.
    GC gc = new GC(m_Text);

    // Need to adjust for the scroll bar.
    int scrollX = m_Text.getHorizontalBar().getSelection();
    mouseX = mouseX + scrollX;

    int selectionPoint = -1;
    for (int i = 0; i < text.length(); i++) {
      Point extent = gc.textExtent(text.substring(0, i));
      if (extent.x > mouseX) {
        selectionPoint = (i == 0) ? 0 : i - 1;
        break;
      }
    }

    gc.dispose();

    return selectionPoint;
  }
 public void writeValue(int ex) {
   double x = xyGraph.primaryXAxis.getPositionValue(ex, false);
   int index = (int) x;
   if (index < 0) {
     return;
   }
   Sample sample = (Sample) trace.getDataProvider().getSample(index);
   if (sample != null) {
     double y = sample.getYValue();
     int height = xyGraph.primaryYAxis.getValuePosition(y, false);
     int startX = xyGraph.primaryXAxis.getValuePosition((int) x, false);
     GC gc = new GC(canvas);
     Font font = new Font(null, "Verdana", 10, SWT.BOLD);
     gc.setFont(font);
     String value = FormatUtil.print(y, "#,###");
     Point textSize = gc.textExtent(value);
     gc.drawText(value, startX + (xAxisUnitWidth - textSize.x) / 2, height - 20, true);
     int ground = xyGraph.primaryYAxis.getValuePosition(0, false);
     gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
     gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA));
     gc.drawRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.fillRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.dispose();
     writedValueMode = true;
     lastWritedX = ex;
   }
 }
 public Rectangle buildHighlightRectangle(
     TreeItem item,
     boolean includeChildren,
     GC gc,
     boolean includeHeaderHeight,
     boolean adjustHeight) {
   TreeItem parentItem = item.getParentItem();
   Rectangle bounds = item.getBounds();
   if (parentItem != null) {
     bounds = parentItem.getBounds(0);
   }
   Rectangle itemBounds = item.getBounds();
   int x = bounds.x;
   int width = itemBounds.width + itemBounds.x - bounds.x;
   if (parentItem == null) {
     x = 0;
     width = bounds.width + bounds.x;
   }
   Rectangle highlight = new Rectangle(x, itemBounds.y, width, getTree().getItemHeight());
   // expand for column text
   String columnText = ((ITableLabelProvider) getLabelProvider()).getColumnText(item.getData(), 1);
   if (columnText != null) {
     Point textExtent = gc.textExtent(columnText);
     int textWidth = textExtent.x;
     Rectangle columnBounds = item.getBounds(1);
     highlight.width = (columnBounds.x + textWidth) - highlight.x;
     // increase width to account for space where icon would be
     // later we will need to account for the icons directly (currently
     // there are no icons for the second column)
     highlight.width = highlight.width + 16;
   }
   // expand for children if necessary
   if (includeChildren) {
     TreeItem[] children = item.getItems();
     if (children.length != 0) {
       expandHighlightRectangleForChildren(highlight, children, gc);
     }
   }
   // shrink the rectangle by one pixel so that back to back
   // highlights do not overlap
   if (adjustHeight) {
     int itemSpace = item.getBounds().height - getTree().getItemHeight();
     itemSpace = Math.abs(itemSpace);
     highlight.height = highlight.height - itemSpace;
   }
   if (SWT.getPlatform().equals("gtk") && item.getParentItem() != null) { // $NON-NLS-1$
     // GTK puts expansion handles directly
     // at the location of the parent bounds
     // we use that location to start the box
     // to allow better looking highlights
     // increase the size a bit for linux
     highlight.x = highlight.x - 5;
     highlight.width = highlight.width + 5;
   }
   if (includeHeaderHeight) {
     highlight.y = highlight.y + getTree().getHeaderHeight();
   }
   return highlight;
 }
  protected void drawInformation(GC gc) {
    super.drawInformation(gc);

    String info2 = "SHFIT+×ó  -  Ç°ÒÆ   SHIFT+ÓÒ  -  ºóÒÆ";
    Point ts = gc.textExtent(info2);
    Point size = getSize();
    gc.drawText(info2, size.x / 2 - ts.x / 2, size.y - ts.y * 2 - 5);
  }
 /** {@inheritDoc} */
 @Override
 public void drawTickLabel(
     final GC gc, final SWTMediaPool media, final Double tick, final boolean floating) {
   final Rectangle region = getBounds();
   final int x = getScreenCoord(tick);
   gc.drawLine(x, region.y, x, region.y + TICK_LENGTH);
   final String mark = ticks.format(tick);
   final Point mark_size = gc.textExtent(mark);
   gc.drawString(mark, x - mark_size.x / 2, region.y + TICK_LENGTH, !floating);
 }
 /**
  * This convenience method is used to determine an appropriate width for the column based on the
  * collection of event objects. The returned value is the maximum width (in pixels) of the text
  * the receiver associates with each of the events. The events are provided as Object[] because
  * converting them to {@link UsageDataEventWrapper}[] would be an unnecessary expense.
  *
  * @param gc a {@link GC} loaded with the font used to display the events.
  * @param events an array of {@link UsageDataEventWrapper} instances.
  * @return the width of the widest event
  */
 public int getMaximumWidth(GC gc, Object[] events) {
   int width = 0;
   for (Object event : events) {
     Point extent = gc.textExtent(getText(event));
     int x = extent.x;
     Image image = getImage(event);
     if (image != null) x += image.getBounds().width;
     if (x > width) width = x;
   }
   return width;
 }
 /** @return the height of the title. */
 public int getHeight() {
   Shell shell = new Shell();
   GC gc = new GC(shell);
   gc.setFont(getFont());
   Point point = gc.textExtent(BLANK);
   point.x++;
   int textOrImageHeight = Math.max(point.x, 16);
   gc.dispose();
   shell.dispose();
   return textOrImageHeight + 8;
 }
Example #14
0
  protected String shortenText(GC gc, String t, int width) {
    if (t == null) return null;
    int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
    if (width <= w) return t;
    int p = t.length() - 1;
    if (p <= 0) return t;

    while (0 < p) {
      String s = t.substring(0, p);
      int l = gc.textExtent(s, DRAW_FLAGS).x;

      if (l + w > width) {
        p--;
      } else {
        break;
      }
    }

    if (p == 0) return t;
    return t.substring(0, p) + ELLIPSIS;
  }
Example #15
0
  @Override
  public GC postCalculation(GC toDraw) {
    textScale = (float) canvas.imageDimension.width / (float) canvas.sourceImage.getWidth();

    String text = (int) (textScale * 100) + "%";
    Point textDim = toDraw.textExtent(text);
    toDraw.drawText(
        text,
        canvas.canvasDimension.width - textDim.x - 20,
        canvas.canvasDimension.height - textDim.y - 20);
    return toDraw;
  }
Example #16
0
  /**
   * Draw the X tick.
   *
   * @param gc the graphics context
   */
  private void drawXTick(GC gc) {
    int offset = axis.getTick().getAxisTickMarks().getBounds().x;

    // draw tick labels
    gc.setFont(axis.getTick().getFont());
    int angle = axis.getTick().getTickLabelAngle();
    for (int i = 0; i < tickLabelPositions.size(); i++) {
      if (axis.isValidCategoryAxis() || tickVisibilities.get(i) == true) {
        String text = tickLabels.get(i);
        int textWidth = gc.textExtent(text).x;
        int textHeight = gc.textExtent(text).y;
        if (angle == 0) {
          int x = (int) (tickLabelPositions.get(i) - textWidth / 2d + offset);
          gc.drawText(text, bounds.x + x, bounds.y);
          continue;
        }

        float x, y;
        if (axis.getPosition() == Position.Primary) {
          x =
              (float)
                  (offset
                      + bounds.x
                      + tickLabelPositions.get(i)
                      - textWidth * Math.cos(Math.toRadians(angle))
                      - textHeight / 2d * Math.sin(Math.toRadians(angle)));
          y = (float) (bounds.y + textWidth * Math.sin(Math.toRadians(angle)));
        } else {
          x =
              (float)
                  (offset
                      + bounds.x
                      + tickLabelPositions.get(i)
                      - textHeight / 2d * Math.sin(Math.toRadians(angle)));
          y = (float) (bounds.y + tickLabelMaxLength * Math.sin(Math.toRadians(angle)));
        }
        drawRotatedText(gc, text, x, y, angle);
      }
    }
  }
 @Override
 public Point computeSize(final int wHint, final int hHint, final boolean changed) {
   final GC gc = new GC(this);
   final Point p =
       gc.textExtent(
           MouseLocationManager.LOGICAL_PREFIX
               + COORD_PATTERN
               + MouseLocationManager.SEP
               + MouseLocationManager.SCREEN_PREFIX
               + COORD_PATTERN);
   gc.dispose();
   return p;
 }
  // determine if the license text will fit the allocated space
  private boolean willLicenseTextFit(String licenseText, GC gc) {
    Point splashSize = splash.getSize();
    Point licenseDrawLocation = new Point(290, 290);
    Point requiredSize = gc.textExtent(licenseText);

    int width = splashSize.x - licenseDrawLocation.x;
    int height = splashSize.y - licenseDrawLocation.y;

    boolean fitsVertically = width >= requiredSize.x;
    boolean fitsHorizontally = height >= requiredSize.y;

    return (fitsVertically && fitsHorizontally);
  }
Example #19
0
  /**
   * Draw the Y tick.
   *
   * @param gc the graphics context
   */
  private void drawYTick(GC gc) {
    int margin = Axis.MARGIN + AxisTickMarks.TICK_LENGTH;

    // draw tick labels
    gc.setFont(axis.getTick().getFont());
    int figureHeight = gc.textExtent("dummy").y;
    for (int i = 0; i < tickLabelPositions.size(); i++) {
      if (tickVisibilities.size() == 0 || tickLabels.size() == 0) {
        break;
      }

      if (tickVisibilities.get(i) == true) {
        String text = tickLabels.get(i);
        int x = 0;
        if (tickLabels.get(0).startsWith("-") && !text.startsWith("-")) {
          x += gc.textExtent("-").x;
        }
        int y = (int) (bounds.height - 1 - tickLabelPositions.get(i) - figureHeight / 2.0 - margin);
        gc.drawText(text, bounds.x + x, bounds.y + y);
      }
    }
  }
  @Override
  public final void createContents(Composite parent) {
    // This is a hacked fix to ensure that the label columns on every details
    // page have the same width. SchemaDetails_translatable plus 11 pixels
    // represents the longest label on any field on any details page. This
    // occurs on SchemaStringAttributeDetails and 11 is the size of the
    // horizontal indent that contributes to the label's width.
    GC gc = new GC(parent);
    minLabelWeight = gc.textExtent(PDEUIMessages.SchemaDetails_translatable).x + 11;
    gc.dispose();
    gc = null;

    parent.setLayout(FormLayoutFactory.createDetailsGridLayout(false, 1));
    FormToolkit toolkit = getManagedForm().getToolkit();
    fSection = toolkit.createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    fSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
    fSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));

    GridData gd;
    if (fShowDescription) gd = new GridData(GridData.FILL_BOTH);
    else gd = new GridData(GridData.FILL_HORIZONTAL);
    fSection.setLayoutData(gd);

    // Align the master and details section headers (misalignment caused
    // by section toolbar icons)
    getPage().alignSectionHeaders(fElementSection.getSection(), fSection);

    Composite client = toolkit.createComposite(fSection);
    client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3));

    createDetails(client);

    if (fShowDescription) createDescription(client, toolkit);

    // If the DTD Approximation section was requested, instantiate it and create it's contents
    // on the same parent Composite
    if (fShowDTD) {
      fDtdSection = new SchemaDtdDetailsSection();
      fDtdSection.initialize(getManagedForm());
      fDtdSection.createContents(parent);
    }

    toolkit.paintBordersFor(client);
    fSection.setClient(client);
    markDetailsPart(fSection);

    if (fShowDescription) fDescriptionViewer.createUIListeners();
    hookListeners();
  }
 protected void drawButtons(GC gc) {
   Point size = getSize();
   gc.setBackground(getBackground());
   gc.setForeground(AbstractImageViewer.invert(getBackground()));
   int bx = 1;
   int i;
   for (i = 0; i < buttonTexts.length; i++) {
     Point ts = gc.textExtent(buttonTexts[i]);
     int by = size.y - ts.y - 8;
     int bw = ts.x + 7;
     int bh = ts.y + 6;
     buttonBounds[i] = new Rectangle(bx, by, bw, bh);
     gc.setForeground(AbstractImageViewer.invert(getBackground()));
     gc.drawRectangle(buttonBounds[i]);
     gc.drawText(buttonTexts[i], buttonBounds[i].x + 4, buttonBounds[i].y + 4);
     bx += bw + 2;
   }
 }
  public Point computeSize(int wHint, int hHint, boolean changed) {
    checkWidget();

    int width = 0, height = 0;

    GC gc = new GC(combo);
    Point labelExtent = gc.textExtent("RGB(255,255,255)"); // $NON-NLS-1$
    gc.dispose();

    Point labelSize = combo.computeSize(labelExtent.x, labelExtent.y, changed);
    Point tableSize = colorSelector.getButton().computeSize(wHint, SWT.DEFAULT, changed);
    int borderWidth = getBorderWidth();

    height = Math.max(hHint, Math.max(labelSize.y, tableSize.y) + 2 * borderWidth);
    width = Math.max(wHint, labelSize.x + tableSize.x + 2 * borderWidth);

    return new Point(width, height);
  }
Example #23
0
  /** Draw the item {@inheritDoc} */
  @Override
  public void paintControl(final PaintEvent e) {
    final Display display = getDisplay();
    final GC gc = e.gc;
    final Rectangle bounds = getBounds();

    last_alarm_state = item.getSeverity();
    gc.setBackground(color_provider.getColor(last_alarm_state));
    gc.fillRoundRectangle(0, 0, bounds.width, bounds.height, 10, 10);

    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BORDER));
    gc.drawRoundRectangle(0, 0, bounds.width - 1, bounds.height - 1, 10, 10);

    // Draw Text
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    final String label = item.getName();
    final Point extend = gc.textExtent(label);
    gc.drawString(label, (bounds.width - extend.x) / 2, (bounds.height - extend.y) / 2, true);
  }
 private int findNextBreakOffset(int currOffset) {
   int currWidth = 0;
   int nextOffset = fLineBreakIterator.following(currOffset);
   while (nextOffset != BreakIterator.DONE) {
     String word = fLine.substring(currOffset, nextOffset);
     int wordWidth = fGC.textExtent(word).x;
     int nextWidth = wordWidth + currWidth;
     if (nextWidth > fMaxWidth) {
       if (currWidth > 0) {
         return currOffset;
       }
       return nextOffset;
     }
     currWidth = nextWidth;
     currOffset = nextOffset;
     nextOffset = fLineBreakIterator.next();
   }
   return nextOffset;
 }
Example #25
0
  public void paintControl(PaintEvent e) {

    if (text == null || foreground == null) return;

    GC gc = e.gc;

    Color oldForeground = gc.getForeground(), oldBackground = gc.getBackground();
    Font oldFont = gc.getFont();
    int oldAntiAlias = gc.getTextAntialias();

    gc.setTextAntialias(SWT.ON);

    if (background != null) gc.setBackground(background);
    if (font != null) gc.setFont(font);

    int finalX = x, finalY = y;

    if (useRelativeXY) {
      Point size = shell.getSize();
      Point textExtent = gc.textExtent(text);

      if (x >= 0) finalX = x;
      else {
        finalX = size.x + x;
        finalX -= textExtent.x;
      }

      if (y >= 0) finalY = y;
      else {
        finalY = size.y + y;
        finalY -= textExtent.y;
      }
    }

    gc.setForeground(foreground);
    gc.drawText(text, finalX, finalY, background == null);

    gc.setForeground(oldForeground);
    gc.setBackground(oldBackground);
    gc.setFont(oldFont);
    gc.setTextAntialias(oldAntiAlias);
  }
 @Override
 public Rectangle getInsertionBounds(Control control) {
   // This doesn't take horizontal scrolling into affect.
   // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=204599
   Combo combo = (Combo) control;
   int position = combo.getSelection().y;
   String contents = combo.getText();
   GC gc = new GC(combo);
   gc.setFont(combo.getFont());
   Point extent = gc.textExtent(contents.substring(0, Math.min(position, contents.length())));
   gc.dispose();
   if (COMPUTE_TEXT_USING_CLIENTAREA) {
     return new Rectangle(
         combo.getClientArea().x + extent.x,
         combo.getClientArea().y,
         1,
         combo.getClientArea().height);
   }
   return new Rectangle(extent.x, 0, 1, combo.getSize().y);
 }
Example #27
0
  /**
   * Fills this field editor's basic controls into the given parent.
   *
   * <p>The string field implementation of this <code>FieldEditor</code> framework method
   * contributes the text field. Subclasses may override but must call <code>super.doFillIntoGrid
   * </code>.
   */
  @Override
  protected void doFillIntoGrid(Composite parent, int numColumns) {
    getLabelControl(parent);

    textField = getTextControl(parent);
    GridData gd = new GridData();
    gd.horizontalSpan = numColumns - 1;
    if (widthInChars != UNLIMITED) {
      GC gc = new GC(textField);
      try {
        Point extent = gc.textExtent("X"); // $NON-NLS-1$
        gd.widthHint = widthInChars * extent.x;
      } finally {
        gc.dispose();
      }
    } else {
      gd.horizontalAlignment = GridData.FILL;
      gd.grabExcessHorizontalSpace = true;
    }
    textField.setLayoutData(gd);
  }
Example #28
0
  private void decideShellSize(Shell newShell) {
    GC gc = new GC(newShell);
    Rectangle imgRect = getImage().getBounds();
    Point extent = gc.textExtent(getTitle());
    int titleWidth = imgRect.width + extent.x + 27;

    TextLayout layout = new TextLayout(newShell.getDisplay());
    layout.setWidth(215);
    layout.setText(getTip());

    shellWidth = Math.max(titleWidth, 215 + getLeftMargin() + getRightMargin() + 6);
    shellHeight =
        layout.getBounds().height
            + getTopMargin()
            + getBottomMargin()
            + Math.max(18, extent.y + 6)
            + 13
            + btnDefault.getSize().y;

    gc.dispose();
    layout.dispose();
  }
Example #29
0
  private Point getTotalSize(Image image, String text) {
    Point size = new Point(0, 0);

    if (image != null) {
      Rectangle r = image.getBounds();
      size.x += r.width;
      size.y += r.height;
    }

    GC gc = new GC(this);
    if (text != null && text.length() > 0) {
      Point e = gc.textExtent(text, DRAW_FLAGS);
      size.x += e.x;
      size.y = Math.max(size.y, e.y);
      if (image != null) size.x += GAP;
    } else {
      size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
    }
    gc.dispose();

    return size;
  }
  /** {@inheritDoc} */
  @Override
  public void paint(
      final GC gc,
      final SWTMediaPool media,
      final Font label_font,
      final Font scale_font,
      final Rectangle plot_bounds) {
    super.paint(gc, media);
    final Rectangle region = getBounds();

    final Color old_fg = gc.getForeground();
    gc.setForeground(media.get(getColor()));
    gc.setFont(scale_font);

    // Axis and Tick marks
    gc.drawLine(region.x, region.y, region.x + region.width - 1, region.y);
    computeTicks(gc);

    final double high_value = range.getHigh();
    final int minor_ticks = ticks.getMinorTicks();
    double tick = ticks.getStart();
    double prev = ticks.getPrevious(tick);
    for (
    /**/ ; tick <= high_value && Double.isFinite(tick); tick = ticks.getNext(tick)) {
      // Minor ticks?
      for (int i = 1; i < minor_ticks; ++i) {
        final double minor = prev + ((tick - prev) * i) / minor_ticks;
        final int x = getScreenCoord(minor);
        if (x < region.x) continue;
        gc.drawLine(x, region.y, x, region.y + MINOR_TICK_LENGTH);
      }

      drawTickLabel(gc, media, tick, false);
      if (show_grid) {
        final int x = getScreenCoord(tick);
        //                gc.setLineStyle(SWT.LINE_DOT);
        gc.drawLine(x, plot_bounds.y, x, plot_bounds.y + plot_bounds.height - 1);
        //                gc.setLineStyle(SWT.LINE_SOLID);
      }

      prev = tick;
    }
    // Minor ticks after last major tick?
    if (Double.isFinite(tick))
      for (int i = 1; i < minor_ticks; ++i) {
        final double minor = prev + ((tick - prev) * i) / minor_ticks;
        if (minor > high_value) break;
        final int x = getScreenCoord(minor);
        gc.drawLine(x, region.y, x, region.y + MINOR_TICK_LENGTH);
      }

    // Label: centered at bottom of region
    gc.setFont(label_font);
    final Point label_size = gc.textExtent(getName());
    gc.drawString(
        getName(),
        region.x + (region.width - label_size.x) / 2,
        region.y + region.height - label_size.y - 1,
        false);
    gc.setForeground(old_fg);
  }