/* (non-Javadoc)
  * @see org.eclipse.vtp.desktop.editors.core.theme.ComponentFrame#initializeGraphics(org.eclipse.swt.graphics.GC, java.util.Map)
  */
 public void initializeGraphics(GC gc, Map<String, Object> resourceMap) {
   Font originalFont = gc.getFont();
   Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL);
   gc.setFont(nameFont);
   Point extent = gc.stringExtent(this.getDesignElement().getName());
   if (extent.x > 110) // too long, attempt to wrap text
   {
     extent.x = 0;
     String[] parts = this.getDesignElement().getName().split(" ");
     Point stringExtent = gc.stringExtent(parts[0]);
     int ew = 0;
     ew += stringExtent.x;
     extent.x = stringExtent.x;
     for (int i = 1; i < parts.length; i++) {
       stringExtent = gc.stringExtent(" " + parts[i]);
       if (ew + stringExtent.x > 110) // wrap it
       {
         stringExtent = gc.stringExtent(parts[i]);
         if (extent.x < ew) extent.x = ew;
         ew = stringExtent.x;
         extent.y += 2 + stringExtent.y;
       } else ew += stringExtent.x;
     }
     if (extent.x < ew) extent.x = ew;
   }
   int width = (extent.x + 35);
   int height = (extent.y + 10 + (uiElement.hasConnectors() ? 12 : 0));
   Point centerPoint = uiElement.getCenterPoint();
   upperLeft = new Point(centerPoint.x - (width / 2), centerPoint.y - (height / 2));
   int buffer = width % 2;
   lowerRight = new Point(upperLeft.x + width + buffer, upperLeft.y + height + buffer);
   gc.setFont(originalFont);
   nameFont.dispose();
 }
Esempio n. 2
0
  private void drawTile(GC gc, Rectangle bounds, Tile tile, boolean highlight) {
    if (tile == null || tile.equals(Tile.NONE)) return;

    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int s = Math.min(w, h);
    int n = Math.max(s / 12, 1);
    int x1 = x;
    int x2 = x1 + n;
    int x3 = x + s - n;
    int x4 = x + s;
    int y1 = y;
    int y2 = y1 + n;
    int y3 = y + s - n;
    int y4 = y + s;

    int[] p1 = new int[] {x1, y1, x4, y1, x3, y2, x2, y2, x2, y3, x1, y4};
    int[] p2 = new int[] {x4, y4, x1, y4, x2, y3, x3, y3, x3, y2, x4, y1};

    gc.setBackground(tileFill);
    gc.fillRectangle(x, y, w, h);
    gc.setBackground(highlight ? tileLightHighlight : tileLight);
    gc.fillPolygon(p1);
    gc.setBackground(highlight ? tileDarkHighlight : tileDark);
    gc.fillPolygon(p2);

    if (tile.isWild()) {
      if (!bounds.contains(mousex, mousey)) {
        return;
      }
    }

    Font font = new Font(null, tileFont, s / 2 + 1, SWT.BOLD);
    String string = Character.toString(tile.getLetter()).toUpperCase();
    gc.setFont(font);
    Point extent = gc.stringExtent(string);
    int sx = x + w / 2 - extent.x / 2 - n; // n * 2; //w / 2 - extent.x / 2 - s/8;
    int sy = y + h / 2 - extent.y / 2;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();

    font = new Font(null, tileFont, s / 5, SWT.BOLD);
    string = Integer.toString(game.getTileValues().getValue(tile));
    gc.setFont(font);
    extent = gc.stringExtent(string);
    sx = x + w - n - extent.x - 1;
    sy = y + h - n - extent.y;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();
  }
  /** {@inheritDoc} */
  @Override
  public final int getDesiredPixelSize(
      final Rectangle region, final GC gc, final Font label_font, final Font scale_font) {

    Activator.getLogger().log(Level.FINE, "XAxis layout");
    gc.setFont(label_font);
    final int label_size = gc.getFontMetrics().getHeight();
    gc.setFont(scale_font);
    final int scale_size = gc.getFontMetrics().getHeight();
    // Need room for ticks, tick labels, and axis label
    return TICK_LENGTH + label_size + scale_size;
  }
Esempio n. 4
0
  private void paint(PaintEvent event) {
    GC gc = event.gc;

    // fonts are disposed when calendar is disposed
    Font used = null;
    if (CalendarCombo.OS_CARBON) {
      used = mSettings.getCarbonDrawFont();
      if (used != null) gc.setFont(used);
    } else if (CalendarCombo.OS_WINDOWS) {
      used = mSettings.getWindowsMonthPopupDrawFont();
      if (used != null) gc.setFont(used);
    }

    // double buffering. this could be triple buffering if the platform does
    // it automatically, windows XP does not seem to however
    // basically, we draw all the updates onto an Image in memory, then we
    // transfer the contents thereof onto the canvas.
    // that way there is 0 flicker, which is the desired effect.
    if (mCreated && mEnableDoubleBuffering) {
      try {
        Image buffer = new Image(Display.getDefault(), super.getBounds());
        GC gc2 = new GC(buffer);
        drawOntoGC(gc2);

        // transfer the image buffer onto this canvas
        // just drawImage(buffer, w, h) didn't work, so we do the whole
        // source transfer call
        Rectangle b = getBounds();
        gc.drawImage(buffer, 0, 0, b.width, b.height, 0, 0, b.width, b.height);

        // dispose the buffer, very important or we'll run out of
        // address space for buffered images
        buffer.dispose();
        gc2.dispose();
      } catch (IllegalArgumentException iea) {
        // seems to come here for some reason when we switch phases
        // while the gantt chart is being viewed, I'm not sure why
        // but no time to figure it out for the demo.. so instead of
        // buffering, just draw it onto the GC
        drawOntoGC(gc);
      }
    } else {
      drawOntoGC(gc);
      mCreated = true;
    }

    // don't dispose font, they are disposed when the CalendarCombo are disposed
  }
Esempio n. 5
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);
  }
Esempio n. 6
0
  private void drawCoordinates(IBoard b, GC gc, int xo, int yo, int size, int csize) {
    gc.setBackground(light);
    gc.setForeground(coordinateColor);
    gc.setFont(coordinateFont);

    int xs = size / b.getWidth();
    int ys = size / b.getHeight();
    int pdx = 4 + gc.stringExtent("X").x;
    int pdy = 4;

    for (int y = 0; y < b.getHeight(); y++) {
      String s = Character.toString((char) (y + 'A'));
      int x = 0;
      int px = xo + x * xs - gc.stringExtent(s).x / 2 - pdx;
      int py = yo + y * ys + ys / 2 - gc.stringExtent(s).y / 2;
      gc.drawString(s, px, py, true);
    }

    for (int x = 0; x < b.getWidth(); x++) {
      String s = Integer.toString(x + 1);
      int y = 0;
      int px = xo + x * xs + xs / 2 - gc.stringExtent(s).x / 2;
      int py = yo + y * ys - gc.stringExtent(s).y - pdy;
      gc.drawString(s, px, py, true);
    }
  }
 /**
  * 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 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;
   }
 }
  /*
   * @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);
  }
 /**
  * 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;
 }
Esempio n. 11
0
 void paintCanvas(Event event) {
   canvas.setCursor(null);
   int index = list.getSelectionIndex();
   if (index == -1) return;
   GC gc = event.gc;
   Object object = objects[index];
   if (object instanceof Color) {
     if (((Color) object).isDisposed()) return;
     gc.setBackground((Color) object);
     gc.fillRectangle(canvas.getClientArea());
     return;
   }
   if (object instanceof Cursor) {
     if (((Cursor) object).isDisposed()) return;
     canvas.setCursor((Cursor) object);
     return;
   }
   if (object instanceof Font) {
     if (((Font) object).isDisposed()) return;
     gc.setFont((Font) object);
     FontData[] array = gc.getFont().getFontData();
     StringBuffer sb = new StringBuffer();
     String lf = text.getLineDelimiter();
     for (int i = 0; i < array.length; i++) {
       FontData data = array[i];
       String style = "NORMAL"; // $NON-NLS-1$
       int bits = data.getStyle();
       if (bits != 0) {
         if ((bits & SWT.BOLD) != 0) style = "BOLD "; // $NON-NLS-1$
         if ((bits & SWT.ITALIC) != 0) style += "ITALIC"; // $NON-NLS-1$
       }
       sb.append(data.getName())
           .append(" ")
           .append(data.getHeight()) // $NON-NLS-1$
           .append(" ")
           .append(style)
           .append(lf); // $NON-NLS-1$
     }
     gc.drawString(sb.toString(), 0, 0);
     return;
   }
   // NOTHING TO DRAW FOR GC
   // if (object instanceof GC) {
   // return;
   // }
   if (object instanceof Image) {
     if (((Image) object).isDisposed()) return;
     gc.drawImage((Image) object, 0, 0);
     return;
   }
   if (object instanceof Region) {
     if (((Region) object).isDisposed()) return;
     String string = ((Region) object).getBounds().toString();
     gc.drawString(string, 0, 0);
     return;
   }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Esempio n. 14
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);
  }
Esempio n. 15
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);
  }
Esempio n. 16
0
  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;
      }
    }
  }
Esempio n. 17
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);
  }
Esempio n. 18
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;
 }
 /**
  * Computes the size of the color image displayed on the button.
  *
  * <p>This is an internal method and should not be called by clients.
  *
  * @param window the window to create a GC on for calculation.
  * @return Point The image size
  */
 protected Point computeImageSize(Control window) {
   // Make the image height as high as a corresponding character. This
   // makes sure that the button has the same size as a "normal" text
   // button.
   GC gc = new GC(window);
   Font f = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
   gc.setFont(f);
   int height = gc.getFontMetrics().getHeight();
   gc.dispose();
   Point p = new Point(height * 3 - 6, height);
   return p;
 }
Esempio n. 20
0
  private void drawVersionWarning(GC gc, Display display) {
    gc.setBackground(versionWarningBackgroundColor);
    gc.setForeground(versionWarningForegroundColor);
    gc.fillRectangle(290, 231, 367, 49);
    gc.drawRectangle(290, 231, 367, 49);
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.drawImage(exclamation_image, 304, 243);

    gc.setFont(devWarningFont);
    gc.drawText(
        BaseMessages.getString(PKG, "SplashDialog.DevelopmentWarning"), 335, 241); // $NON-NLS-1$
  }
Esempio n. 21
0
  // @see
  // org.gudy.azureus2.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, org.gudy.azureus2.ui.swt.views.table.TableCellSWT)
  public void cellPaint(GC gc, TableCellSWT cell) {
    VuzeActivitiesEntry entry = (VuzeActivitiesEntry) cell.getDataSource();
    if (entry == null) {
      return;
    }

    TableRow row = cell.getTableRow();
    if (row == null) {
      return;
    }
    String text = (String) row.getData("text");

    if (text != null && text.length() > 0) {
      if (font == null) {
        FontData[] fontData = gc.getFont().getFontData();
        fontData[0].setStyle(SWT.BOLD);
        font = new Font(gc.getDevice(), fontData);
      }
      gc.setFont(font);

      Rectangle bounds = getDrawBounds(cell);

      GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, true, true, SWT.WRAP | SWT.CENTER);

      sp.calculateMetrics();

      if (sp.hasHitUrl()) {
        URLInfo[] hitUrlInfo = sp.getHitUrlInfo();
        for (int i = 0; i < hitUrlInfo.length; i++) {
          URLInfo info = hitUrlInfo[i];
          // handle fake row when showing in column editor

          info.urlUnderline = cell.getTableRow() == null || cell.getTableRow().isSelected();
          if (info.urlUnderline) {
            info.urlColor = null;
          } else {
            info.urlColor = colorLinkNormal;
          }
        }
        int[] mouseOfs = cell.getMouseOffset();
        if (mouseOfs != null) {
          Rectangle realBounds = cell.getBounds();
          URLInfo hitUrl = sp.getHitUrl(mouseOfs[0] + realBounds.x, mouseOfs[1] + realBounds.y);
          if (hitUrl != null) {
            hitUrl.urlColor = colorLinkHover;
          }
        }
      }

      sp.printString();
    }
  }
  /*
   * Oddly enough, this method resizes the columns. In order to figure out how
   * wide to make the columns, we need to use a GC (specifically, the
   * {@link GC#textExtent(String)} method). To avoid creating too many of
   * them, we create one in this method and pass it into the helper method
   * {@link #resizeColumn(GC, UsageDataTableViewerColumn)} which does most of
   * the heavy lifting.
   *
   * This method must be run in the UI Thread.
   */
  void resizeColumns(final Object[] events) {
    if (isDisposed()) return;

    GC gc = new GC(getDisplay());
    gc.setFont(viewer.getTable().getFont());
    resizeColumn(gc, includeColumn, events);
    resizeColumn(gc, whatColumn, events);
    resizeColumn(gc, kindColumn, events);
    resizeColumn(gc, bundleIdColumn, events);
    resizeColumn(gc, bundleVersionColumn, events);
    resizeColumn(gc, descriptionColumn, events);
    resizeColumn(gc, timestampColumn, events);
    gc.dispose();
  }
Esempio n. 23
0
  @Override
  public Point computeSizeConstraints(final int widthInChars, final int heightInChars) {
    final GC gc = new GC(fContentComposite);
    gc.setFont(JFaceResources.getDialogFont());
    final int titleWidth = gc.getFontMetrics().getAverageCharWidth() * widthInChars;
    final int titleHeight = fTitleText.getLineHeight();
    gc.dispose();

    final int infoWidth = LayoutUtil.hintWidth(fInfoText, PREF_DETAIL_PANE_FONT, widthInChars);
    final int infoHeight = fInfoText.getLineHeight() * (heightInChars);

    return new Point(
        Math.max(titleWidth, infoWidth), titleHeight + LayoutUtil.defaultVSpacing() + infoHeight);
  }
Esempio n. 24
0
  public void paintCanvas(GC gc, Point point) {
    if (timeSeries != null) {

      Font old = gc.getFont();
      FontData fd = old.getFontData()[0];
      fd.setHeight(20);
      gc.setFont(new Font(display, fd));
      gc.setForeground(new Color(display, 200, 200, 200));
      Painter.drawText(title, gc, 50, 20, PosHorizontal.LEFT, PosVerical.TOP);
      gc.setFont(old);

      if (point != null) {
        updateRangeOfOutputWindow(point.x, point.y);
      }

      updateDataWindowConversionValues();

      Color color_bluegreen = new Color(display, 190, 240, 190);
      int avg = valueToGraph(dataSum / dataCount);
      gc.setForeground(color_bluegreen);
      gc.drawLine(xStart, avg, xEnd, avg);

      drawGrid(gc);

      drawXYAxis(gc);

      if (compare_timeSeries != null) {

        Color color_red = new Color(display, 240, 0, 0);
        Color color_redgrey = new Color(display, 240, 190, 190);

        drawTimeSeries(gc, compare_timeSeries, color_red, color_redgrey);
      }

      drawTimeSeries(gc, timeSeries, color_black, color_grey);
    }
  }
Esempio n. 25
0
  /**
   * Set the GridData on button to be one that is spaced for the current font.
   *
   * @param button the button the data is being set on.
   */
  protected void setButtonLayoutData(Button button) {

    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);

    // Compute and store a font metric
    GC gc = new GC(button);
    gc.setFont(button.getFont());
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    int widthHint =
        org.eclipse.jface.dialogs.Dialog.convertVerticalDLUsToPixels(
            fontMetrics, IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    button.setLayoutData(data);
  }
Esempio n. 26
0
 /** Sets or clears the caret in the "Example" widget. */
 void setCaret() {
   Caret oldCaret = canvas.getCaret();
   if (caretButton.getSelection()) {
     Caret newCaret = new Caret(canvas, SWT.NONE);
     Font font = canvas.getFont();
     newCaret.setFont(font);
     GC gc = new GC(canvas);
     gc.setFont(font);
     newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
     gc.dispose();
     canvas.setCaret(newCaret);
     canvas.setFocus();
   } else {
     canvas.setCaret(null);
   }
   if (oldCaret != null) oldCaret.dispose();
 }
Esempio n. 27
0
 protected Point calcTextSize() {
   String string = getText();
   if (!hasText()) {
     if ((style & NO_TEXT) != 0) return new Point(0, 0);
     string = "X"; // $NON-NLS-1$
   }
   Point size;
   GC gc = new GC(getControl().getDisplay());
   try {
     gc.setFont(getControl().getFont());
     size = gc.stringExtent(string);
   } finally {
     gc.dispose();
   }
   if (size.x == 0 && hasText()) size.x = 5;
   return size;
 }
 @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);
 }
Esempio n. 29
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);
      }
    }
  }
Esempio n. 30
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);
      }
    }
  }