예제 #1
0
  /** @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent) */
  public void paintControl(PaintEvent e) {

    GC gc;
    int offsetX, offsetY;

    if (!doubleBuffering) {
      gc = e.gc;
      gc.setClipping(e.x, e.y, e.width, e.height);
      offsetX = 0;
      offsetY = 0;
    } else {
      if (backBuffer == null) {
        setMaxVisibleArea(e.width, e.height);
      } else {
        Rectangle b = backBuffer.getBounds();
        if (b.width < e.width || b.height < e.height) {
          setMaxVisibleArea(Math.max(e.width, b.width), Math.max(e.height, b.height));
        }
      }
      gc = new GC(backBuffer);
      offsetX = e.x;
      offsetY = e.y;
      gc.setClipping(0, 0, e.width, e.height);
    }

    renderer.paintWorld(gc, offsetX, offsetY);

    if (doubleBuffering) {
      e.gc.drawImage(backBuffer, 0, 0, e.width, e.height, e.x, e.y, e.width, e.height);
      gc.dispose();
    }
  }
예제 #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);
  }
예제 #3
0
 void layout() {
   Rectangle rect = shell.getClientArea();
   // String[] strings = new String[objects.length];
   int width = 0;
   String[] items = list.getItems();
   GC gc = new GC(list);
   for (int i = 0; i < objects.length; i++) {
     width = Math.max(width, gc.stringExtent(items[i]).x);
   }
   gc.dispose();
   Point size1 = start.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size2 = stop.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size3 = check.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size4 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   width = Math.max(size1.x, Math.max(size2.x, Math.max(size3.x, width)));
   width = Math.max(64, Math.max(size4.x, list.computeSize(width, SWT.DEFAULT).x));
   start.setBounds(0, 0, width, size1.y);
   stop.setBounds(0, size1.y, width, size2.y);
   check.setBounds(0, size1.y + size2.y, width, size3.y);
   label.setBounds(0, rect.height - size4.y, width, size4.y);
   int height = size1.y + size2.y + size3.y;
   list.setBounds(0, height, width, rect.height - height - size4.y);
   text.setBounds(width, 0, rect.width - width, rect.height);
   canvas.setBounds(width, 0, rect.width - width, rect.height);
 }
예제 #4
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>.
   */
  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);
  }
예제 #5
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;
  }
 /**
  * Initializes the computation of horizontal and vertical dialog units based on the size of
  * current font.
  *
  * <p>This method must be called before any of the dialog unit based conversion methods are
  * called.
  *
  * @param testControl a control from which to obtain the current font
  */
 private void initializeDialogUnits(Control testControl) {
   // Compute and store a font metric
   GC gc = new GC(testControl);
   gc.setFont(JFaceResources.getDialogFont());
   fFontMetrics = gc.getFontMetrics();
   gc.dispose();
 }
 public void mouseMove(MouseEvent e) {
   if ((e.stateMask & SWT.BUTTON1) == 0) return;
   GC gc = new GC((Canvas) e.widget);
   gc.drawLine(p.x, p.y, e.x, e.y);
   gc.dispose();
   updatePoint(e);
 }
예제 #8
0
  public Point computeSize(int wHint, int hHint, boolean changed) {
    checkWidget();
    int width = 0, height = 0;
    String[] items = list.getItems();
    int textWidth = 0;
    GC gc = new GC(text);
    int spacer = gc.stringExtent(" ").x; // $NON-NLS-1$
    for (int i = 0; i < items.length; i++) {
      textWidth = Math.max(gc.stringExtent(items[i]).x, textWidth);
    }
    gc.dispose();

    Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
    Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
    Point listSize = list.computeSize(wHint, SWT.DEFAULT, changed);
    int borderWidth = getBorderWidth();

    if (icon == null) {
      height = Math.max(hHint, Math.max(textSize.y, arrowSize.y) + 2 * borderWidth);
      width =
          Math.max(
              wHint, Math.max(textWidth + 2 * spacer + arrowSize.x + 2 * borderWidth, listSize.x));
    } else {
      Point iconSize = icon.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed);
      height = Math.max(hHint, Math.max(textSize.y, arrowSize.y) + 2 * borderWidth);
      width =
          Math.max(
              wHint,
              Math.max(
                  textWidth + 2 * spacer + arrowSize.x + iconSize.x + 2 * borderWidth, listSize.x));
    }
    return new Point(width, height);
  }
예제 #9
0
  public void save_Event() {
    FileDialog fd = new FileDialog(ZestDebuggerView.this.getSite().getShell(), SWT.SAVE);
    fd.setText("Save");
    fd.setFilterPath("C:/");
    String[] filterExt = {"*.jpg"};
    fd.setFilterExtensions(filterExt);
    String selected = fd.open();
    System.out.println(selected);

    if (selected != null) {
      GC gc = new GC(viewer.getControl());
      org.eclipse.swt.graphics.Rectangle bounds = viewer.getControl().getBounds();

      Image image = new Image(viewer.getControl().getDisplay(), bounds);
      try {
        gc.copyArea(image, 0, 0);
        ImageLoader imageLoader = new ImageLoader();
        imageLoader.data = new ImageData[] {image.getImageData()};
        imageLoader.save(selected, SWT.IMAGE_JPEG);
        MessageDialog.openInformation(
            ZestDebuggerView.this.getSite().getShell(),
            "Success",
            "The image has been saved successfully");
      } catch (Exception e) {
        e.printStackTrace();
        MessageDialog.openError(
            ZestDebuggerView.this.getSite().getShell(), "Failure", "The image can't be saved");
      } finally {
        image.dispose();
        gc.dispose();
      }
    }
  }
 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;
   }
 }
예제 #11
0
  /**
   * ************************************************************************* Shows a prompt
   * prepared to receive an answer (controlling GUI)
   * ************************************************************************
   */
  private void promptAsControlling() {

    boolean defaultOptionSet = false;

    if (m_promptData.isList()) {
      m_expected = m_promptData.getExpected();
      m_numericInput = false;
      // Set the prompt text
      m_promptText.setText(m_promptData.getText());

      // Adjust the height and visibility of scroll bar depending on
      // the control doing text wrapping or not
      int areaWidth = m_promptText.getClientArea().width;
      GC gc = new GC(m_promptText);
      int textWidth = gc.getFontMetrics().getAverageCharWidth() * m_promptText.getText().length();
      boolean wrapping = textWidth >= areaWidth;
      gc.dispose();
      m_promptText.getVerticalBar().setVisible(wrapping);
      if (wrapping) {
        GridData gd = (GridData) m_promptText.getLayoutData();
        gd.heightHint = 45;
        layout();
      }

      m_promptDisplayType = m_promptData.getPromptDisplayType();
      // Build the option list and show the option composite
      defaultOptionSet =
          updateOptions(
              m_promptData.getOptions(), m_promptData.getExpected(), m_promptData.getDefault());
      if (defaultOptionSet) {
        m_textInput.setValue(m_promptData.getDefault());
      }

    } else {
      // Not a List

      m_expected = null;
      m_promptText.setText(m_promptData.getText());
      m_numericInput = m_promptData.isNumeric();
      if (!m_promptData.getDefault().isEmpty()) {
        m_textInput.setValue(m_promptData.getDefault());
        defaultOptionSet = true;
      }
    }

    setHint();

    if (defaultOptionSet) {
      // If we have a default option preselected, enable the controls
      m_commitButton.setEnabled(true);
      m_resetButton.setEnabled(true);
    } else {
      // Reset the console input

      m_textInput.reset();
    }
    // Set the focus, highlighting
    m_textInput.promptStart();
  }
  void resize() {
    Point size = comp.getSize();
    Image oldBackgroundImage = backgroundImage;
    backgroundImage = new Image(comp.getDisplay(), size.x, size.y);
    GC gc = new GC(backgroundImage);
    comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0);
    Color background = comp.getBackground();
    Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    RGB backgroundRGB = background.getRGB();
    // TODO naive and hard coded, doesn't deal with high contrast, etc.
    Color gradientTop =
        new Color(
            comp.getDisplay(),
            backgroundRGB.red + 12,
            backgroundRGB.green + 10,
            backgroundRGB.blue + 10);
    int h = size.y;
    int curveStart = 0;
    int curve_width = 5;

    int[] curve =
        new int[] {
          0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0,
        };
    int[] line1 = new int[curve.length + 4];
    int index = 0;
    int x = curveStart;
    line1[index++] = x + 1;
    line1[index++] = h;
    for (int i = 0; i < curve.length / 2; i++) {
      line1[index++] = x + curve[2 * i];
      line1[index++] = curve[2 * i + 1];
    }
    line1[index++] = x + curve_width;
    line1[index++] = 0;

    int[] line2 = new int[line1.length];
    index = 0;
    for (int i = 0; i < line1.length / 2; i++) {
      line2[index] = line1[index++] - 1;
      line2[index] = line1[index++];
    }

    // custom gradient
    gc.setForeground(gradientTop);
    gc.setBackground(background);
    gc.drawLine(4, 0, size.x, 0);
    gc.drawLine(3, 1, size.x, 1);
    gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true);
    gc.setForeground(background);
    gc.drawLine(2, size.y - 1, size.x, size.y - 1);
    gradientTop.dispose();

    gc.setForeground(border);
    gc.drawPolyline(line2);
    gc.dispose();
    comp.setBackgroundImage(backgroundImage);
    if (oldBackgroundImage != null) oldBackgroundImage.dispose();
  }
 private void createLabel(Composite parent, final String text, final int N_OF_COLUMNS) {
   Separator label = new Separator(SWT.NONE);
   ((Label) label.getSeparator(parent)).setText(text);
   GC gc = new GC(parent);
   int height = gc.stringExtent(text).y;
   gc.dispose();
   label.doFillIntoGrid(parent, N_OF_COLUMNS, height);
 }
예제 #14
0
 /** @return a white flag that can be used as default. */
 private static Image createDefaultFlag() {
   Image img = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, "png/de.png").createImage();
   GC gc = new GC(img);
   gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
   gc.fillRectangle(img.getBounds());
   gc.dispose();
   return img;
 }
 /**
  * Returns the height hint for this label.
  *
  * @param control the root control of this label
  * @return the height hint for this label
  * @since 3.0
  */
 private int getHeightHint(Composite control) {
   if (fFixedHeight < 0) {
     GC gc = new GC(control);
     gc.setFont(control.getFont());
     fFixedHeight = gc.getFontMetrics().getHeight();
     gc.dispose();
   }
   return fFixedHeight;
 }
  /*
   * @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int)
   */
  public Point computeSizeConstraints(int widthInChars, int heightInChars) {
    GC gc = new GC(fText);
    gc.setFont(fTextFont);
    int width = gc.getFontMetrics().getAverageCharWidth();
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    return new Point(widthInChars * width, heightInChars * height);
  }
예제 #17
0
 /**
  * Creates GridData for the moveup and movedown toolbar buttons.
  *
  * @param control button
  * @return the <code>GridData</code>
  */
 protected GridData makeArrowButtonGridData(Control control) {
   GC gc = new GC(control);
   gc.setFont(control.getFont());
   // fill horizontal to make them all the same size
   GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
   gridData.heightHint = 24;
   gc.dispose();
   return gridData;
 }
예제 #18
0
 /**
  * Creates a new painter for the given text viewer.
  *
  * @param textViewer the text viewer the painter should be attached to
  */
 public WhitespaceCharacterPainter(ITextViewer textViewer) {
   super();
   fTextViewer = textViewer;
   fTextWidget = textViewer.getTextWidget();
   GC gc = new GC(fTextWidget);
   gc.setAdvanced(true);
   fIsAdvancedGraphicsPresent = gc.getAdvanced();
   gc.dispose();
 }
예제 #19
0
 private int getAvarageCharWith(Control control) {
   GC gc = null;
   try {
     gc = new GC(control);
     return gc.getFontMetrics().getAverageCharWidth();
   } finally {
     if (gc != null) gc.dispose();
   }
 }
예제 #20
0
  /**
   * Create an image. The image is added to a cache kept by this provider and is disposed of when
   * this provider is disposed of.
   *
   * @param name the image name.
   * @param rightImage
   * @param leftImage
   * @return the image.
   */
  @Nonnull
  private Image createImage(@Nonnull final String[] names) {
    final StringBuilder builder = new StringBuilder();
    for (final String string : names) {
      builder.append(string);
    }
    final String name = builder.toString();

    if (_imageCache.containsKey(name)) {
      return _imageCache.get(name);
    }

    Image leftImage;
    Image rightImage;
    int width;
    Image dualImage;

    if (names.length == 2) {
      leftImage = loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[0] + ".gif");
      rightImage =
          loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[1] + ".gif");
      width = leftImage.getBounds().width / 3 + 2 + rightImage.getBounds().width;
      dualImage = new Image(leftImage.getDevice(), width, leftImage.getBounds().height);
      final GC gc = new GC(dualImage);
      if (names[1].equals("checked")) {
        gc.drawImage(leftImage, leftImage.getBounds().width / 3 + 2, 0);
        gc.drawImage(rightImage, 2, 0);
      } else {
        gc.drawImage(leftImage, 0, 0);
        gc.drawImage(rightImage, leftImage.getBounds().width / 3 + 2, 0);
      }
      gc.dispose();
    } else {
      leftImage = loadImage(AlarmTreePreference.RES_ICON_PATH.getValue() + "/" + names[0] + ".gif");
      width = leftImage.getBounds().width / 3 + 2 + leftImage.getBounds().width;
      dualImage = new Image(leftImage.getDevice(), width, leftImage.getBounds().height);
      final GC gc = new GC(dualImage);
      gc.drawImage(leftImage, leftImage.getBounds().width / 3 + 2, 0);
      gc.dispose();
    }
    _imageCache.put(name, dualImage);
    return dualImage;
  }
예제 #21
0
  /**
   * Returns the number of pixels corresponding to the given number of horizontal dialog units.
   *
   * <p>Clients may call this framework method, but should not override it.
   *
   * @param control the control being sized
   * @param dlus the number of horizontal dialog units
   * @return the number of pixels
   */
  protected int convertHorizontalDLUsToPixels(Control control, int dlus) {
    GC gc = new GC(control);
    gc.setFont(control.getFont());
    int averageWidth = gc.getFontMetrics().getAverageCharWidth();
    gc.dispose();

    double horizontalDialogUnitSize = averageWidth * 0.25;

    return (int) Math.round(dlus * horizontalDialogUnitSize);
  }
예제 #22
0
  /**
   * Returns the number of pixels corresponding to the given number of vertical dialog units.
   *
   * <p>Clients may call this framework method, but should not override it.
   *
   * @param control the control being sized
   * @param dlus the number of vertical dialog units
   * @return the number of pixels
   */
  protected int convertVerticalDLUsToPixels(Control control, int dlus) {
    GC gc = new GC(control);
    gc.setFont(control.getFont());
    int height = gc.getFontMetrics().getHeight();
    gc.dispose();

    double verticalDialogUnitSize = height * 0.125;

    return (int) Math.round(dlus * verticalDialogUnitSize);
  }
예제 #23
0
  /**
   * This method converts the Graph into an actual image.
   *
   * @param canvas The graph that needs to be converted to an image
   * @return The Image that was generated by the supplied Graph.
   */
  public ImageData getImage(AbstractChartBuilder canvas) {
    GC gc = new GC(canvas);
    Image image = new Image(canvas.getDisplay(), canvas.getSize().x, canvas.getSize().y);
    gc.copyArea(image, 0, 0);
    gc.dispose();

    ImageData data = image.getImageData();
    image.dispose();
    return data;
  }
예제 #24
0
 void setMonthLabelText() {
   String str = getFormattedDate("MMMM", cdt.getCalendarTime()); // $NON-NLS-1$
   GC gc = new GC(getDisplay());
   int width = monthButton.getClientArea().width;
   if (width > 0 && gc.stringExtent(str).x >= width) {
     str = getFormattedDate("MMM", cdt.getCalendarTime()); // $NON-NLS-1$
   }
   gc.dispose();
   monthButton.setText(str);
 }
  private static Image createImage(Display display, int red, int green, int blue) {
    Color color = new Color(display, red, green, blue);
    Image image = new Image(display, 10, 10);
    GC gc = new GC(image);
    gc.setBackground(color);
    gc.fillRectangle(0, 0, 10, 10);
    gc.dispose();

    return image;
  }
예제 #26
0
 /** @return the small {@link Image} that can be used as placeholder for missing image. */
 private static Image getMissingImage() {
   Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
   //
   GC gc = new GC(image);
   gc.setBackground(getColor(SWT.COLOR_RED));
   gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
   gc.dispose();
   //
   return image;
 }
 /**
  * Returns the width hint for this label.
  *
  * @param control the root control of this label
  * @return the width hint for this label
  * @since 2.1
  */
 private int getWidthHint(Composite control) {
   if (fFixedWidth < 0) {
     GC gc = new GC(control);
     gc.setFont(control.getFont());
     fFixedWidth = gc.getFontMetrics().getAverageCharWidth() * fWidthInChars;
     fFixedWidth += INDENT * 2;
     gc.dispose();
   }
   return fFixedWidth;
 }
예제 #28
0
파일: MButton.java 프로젝트: koson/xmind3
  protected void buildCaches() {
    bounds = control.getClientArea();
    bounds.x += MARGIN;
    bounds.y += MARGIN;
    bounds.width -= MARGIN * 2;
    bounds.height -= MARGIN * 2;
    int x1 = bounds.x + BORDER;
    int y1 = bounds.y + BORDER;
    int w1 = bounds.width - BORDER * 2;
    int h1 = bounds.height - BORDER * 2;
    boolean hasArrows = hasArrows();

    if (hasArrows) {
      arrowLoc =
          new Point(
              x1 + w1 + BORDER / 2 - ARROW_WIDTH,
              y1 + (h1 - ARROW_HEIGHT * 2 - ARROWS_SPACING) / 2 - 1);
    }
    contentArea =
        new Rectangle(x1, y1, w1 - (hasArrows ? ARROW_WIDTH + CONTENT_ARROW_SPACING : 0), h1);

    boolean hasImage = hasImage();
    boolean hasText = hasText();
    if (hasImage) {
      if (hasText) {
        Point imgSize = getImageSize();
        imgArea = new Rectangle(x1, y1, imgSize.x, h1);
      } else {
        imgArea = contentArea;
      }
    }

    if (hasText) {
      if (hasImage) {
        int w = imgArea.width + IMAGE_TEXT_SPACING;
        textArea = new Rectangle(imgArea.x + w, y1, contentArea.width - w, h1);
      } else {
        textArea = contentArea;
      }
      int maxTextWidth = textArea.width;
      Point textSize = getTextSize();
      if (textSize.x > maxTextWidth) {
        GC gc = new GC(getControl().getDisplay());
        try {
          gc.setFont(getControl().getFont());
          appliedText =
              getSubString(gc, text, maxTextWidth - gc.stringExtent(ELLIPSIS).x) + ELLIPSIS;
        } finally {
          gc.dispose();
        }
      } else {
        appliedText = text;
      }
    }
  }
예제 #29
0
  /*
   * Create a nice rectangle in the specified color.
   */
  private Image createColorRect(Display display, RGB color) {
    int width = 32;
    int height = 16;

    Image img = new Image(display, width, height);
    GC gc = new GC(img);
    gc.setBackground(new Color(display, color));
    gc.fillRectangle(0, 0, width, height);
    gc.dispose();
    return img;
  }
예제 #30
0
 /** @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;
 }