Example #1
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);
    }
  }
Example #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();
  }
Example #3
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;
   }
 }
  /**
   * Create a background image that shows the scale and channels as requested
   *
   * @return
   */
  private Image CreateBackgroundImage(int numHorizontalLines, int numVerticalLines) {
    // * Image i = new Image(device, boundsRectangle);
    // * GC gc = new GC(i);
    // * gc.drawRectangle(0, 0, 50, 50);
    // * gc.dispose();
    Rectangle rect = getBounds();
    if ((rect.width == 0) || (rect.height == 0)) return null;
    Image TheImage = new Image(getDisplay(), rect);
    GC gc = new GC(TheImage);
    gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
    int step = (getSize().y - 20) / (numHorizontalLines - 1);
    int width = getSize().x;
    int height = getSize().y;
    gc.fillRectangle(0, 0, width, getSize().y);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_CYAN));
    int Value =
        myLowRangeValue
            + (int) (10.0 * (float) (myhighValue - myLowRangeValue) / (float) rect.height);
    int RangeStep =
        (int)
            ((float) (rect.height - 20)
                / (float) (numHorizontalLines - 1)
                * (float) (myhighValue - myLowRangeValue)
                / (float) rect.height);
    for (int i = 0; i < numHorizontalLines; i++) {
      gc.drawLine(0, 10 + (step * i), width, 10 + (step * i));
      gc.drawString(
          Integer.toString(Value + RangeStep * (numHorizontalLines - (i + 1))),
          10,
          10 + (step * i));
    }
    step = (getSize().x - 20) / (numVerticalLines - 1);
    for (int i = 0; i < numVerticalLines; i++) {
      gc.drawLine(10 + (step * i), 0, 10 + (step * i), height);
    }
    step = (int) Math.round(gc.getFont().getFontData()[0].height * 1.5);
    if (ShowLabels) {
      for (int i = 0; i < chan.length; i++) {
        gc.setForeground(chan[i].fg);
        gc.drawString(chan[i].name, 50, 10 + (step * i));
      }
    }
    gc.setForeground(chan[0].fg);
    gc.drawString(myStatus, 200, 10);

    // gc.drawString(string, x, y)
    gc.dispose();
    return TheImage;
  }
  /**
   * paint progress bar
   *
   * @param paintEvent paint event
   */
  private void paint(PaintEvent paintEvent) {
    GC gc;
    Rectangle bounds;
    int x, y, w, h;

    gc = paintEvent.gc;
    bounds = getBounds();
    x = 0;
    y = 0;
    w = bounds.width;
    h = bounds.height;

    // shadow
    gc.setForeground(colorNormalShadow);
    gc.drawRectangle(x + 0, y + 0, w - 2, h - 2);

    gc.setForeground(colorHighlightShadow);
    gc.drawLine(x + 1, y + 1, x + w - 3, y + 1);
    gc.drawLine(x + 1, y + 2, x + 1, y + h - 3);
    gc.drawLine(x + 0, y + h - 1, x + w - 1, y + h - 1);
    gc.drawLine(x + w - 1, y + 0, x + w - 1, y + h - 2);

    // draw bar
    gc.setBackground(colorBar);
    gc.fillRectangle(x + 2, y + 2, w - 4, h - 4);
    gc.setBackground(colorBarSet);
    gc.fillRectangle(x + 2, y + 2, (int) ((double) (w - 4) * value), h - 4);

    // draw percentage text
    gc.setForeground(colorBlack);
    gc.drawString(text, (w - textSize.x) / 2, (h - textSize.y) / 2, true);
  }
Example #6
0
 void drawItem(GC gc, boolean drawFocus) {
   int headerHeight = parent.getBandHeight();
   Display display = getDisplay();
   gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
   gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
   gc.fillGradientRectangle(x, y, width, headerHeight, true);
   if (expanded) {
     gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
     gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1);
     gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
     gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
   }
   int drawX = x;
   if (image != null) {
     drawX += ExpandItem.TEXT_INSET;
     if (imageHeight > headerHeight) {
       gc.drawImage(image, drawX, y + headerHeight - imageHeight);
     } else {
       gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2);
     }
     drawX += imageWidth;
   }
   if (text.length() > 0) {
     drawX += ExpandItem.TEXT_INSET;
     Point size = gc.stringExtent(text);
     gc.setForeground(parent.getForeground());
     gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true);
   }
   int chevronSize = ExpandItem.CHEVRON_SIZE;
   drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
   if (drawFocus) {
     gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2);
   }
 }
 /** {@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);
 }
Example #8
0
    private void paintControl(Event e) {
      Color oldForeground = e.gc.getForeground();
      Color oldBackground = e.gc.getBackground();

      Point size = getSize();
      Rectangle r = new Rectangle(0, 0, size.x, size.y);

      renderer.drawRectangle(rootItem, item, e.gc, r);

      String text = item.getName();
      String info = getInfo();

      GC gc = e.gc;
      gc.setForeground(Colors.getTextColor(gc.getBackground()));
      gc.drawString(text, 2, 2, true);
      Point extent = gc.stringExtent(text);
      gc.drawString(info, 2, extent.y + 1, true);

      e.gc.setForeground(oldForeground);
      e.gc.setBackground(oldBackground);
    }
  /**
   * Draw string at widget offset.
   *
   * @param gc
   * @param offset the widget offset
   * @param s the string to be drawn
   * @param fg the foreground color
   */
  private void draw(GC gc, int offset, String s, Color fg) {
    // Compute baseline delta (see
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640)
    int baseline = fTextWidget.getBaseline(offset);
    FontMetrics fontMetrics = gc.getFontMetrics();
    int fontBaseline = fontMetrics.getAscent() + fontMetrics.getLeading();
    int baslineDelta = baseline - fontBaseline;

    Point pos = fTextWidget.getLocationAtOffset(offset);
    gc.setForeground(fg);
    gc.drawString(s, pos.x, pos.y + baslineDelta, true);
  }
  @Override
  protected void paintLine(int line, int y, int lineheight, GC gc, Display display) {
    int widgetLine = JFaceTextUtil.modelLineToWidgetLine(getParentRuler().getTextViewer(), line);

    // get the corresponding line number and background color for this column
    String text = "";
    Color bgColor = null;
    if (line < indexedLineNumbersList.size()) {
      bgColor = linesToColorMapping.get(line);
      List<IndexedLineNumber> curLine = indexedLineNumbersList.get(line);
      for (IndexedLineNumber lineNumber : curLine) {
        if (lineNumber.getColumnIndex() == columnIndex) {
          text = createDisplayString(lineNumber.getNumber());
        }
      }
    }

    // get line indentation
    int[] indentations = null;
    try {
      indentations = getIndentations();
    } catch (Exception e) {
      LOGGER.error("Could not get unified column line indentation!", e);
    }

    // calculate proper positioning and draw number
    if (indentations != null) {
      int indentation = indentations[text.length()];
      int baselineBias = getBaselineBias(gc, widgetLine);
      if (bgColor != null) {
        gc.setBackground(bgColor);
        gc.drawString(text, indentation, y + baselineBias, false);
      } else {
        gc.drawString(text, indentation, y + baselineBias, true);
      }
    }
  }
Example #11
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 final void draw(final GC gc, final int offset, final int length) {
    if (gc != null) {
      Point left = mTextWidget.getLocationAtOffset(offset);
      Point right = mTextWidget.getLocationAtOffset(offset + length);
      Color color = mMismatch ? mMismatchColor : mColor;

      if (mBox) {
        gc.setForeground(color);
        int x = left.x;
        int y = left.y;
        int w = right.x - left.x - 1;
        int h = gc.getFontMetrics().getHeight();
        gc.drawRectangle(x, y, w, h);
      } else {
        gc.setForeground(mDefaultColor);
        gc.setBackground(color);
        gc.drawString(mTextWidget.getTextRange(offset, 1), left.x, left.y, false);
      }
    } else {
      mTextWidget.redrawRange(offset, length, true);
    }
  }
Example #13
0
  protected void buildBars() {
    long now = TimeUtil.getCurrentTime();
    if ((now - lastDrawTime) < REFRESH_INTERVAL || area == null) {
      return;
    }
    if (onGoing) return;
    onGoing = true;
    int width = area.width > 100 ? area.width : 100;
    int height = area.height > 50 ? area.height : 50;
    Image img = new Image(null, width, height);
    GC gc = new GC(img);
    try {
      lastDrawTime = now;
      double maxValue = 0;
      ArrayList<EqData> list = new ArrayList<EqData>();
      synchronized (valueSet) {
        for (EqData e : valueSet) {
          if (objSelMgr.isUnselectedObject(e.objHash)) {
            continue;
          }
          double max = ChartUtil.getEqMaxValue(e.asd.act1 + e.asd.act2 + e.asd.act3);
          if (max > maxValue) {
            maxValue = max;
          }
          list.add(e);
        }
      }
      size = list.size();
      if (size < 1) {
        datas = new EqData[0];
        return;
      }
      datas = list.toArray(new EqData[size]);
      unitHeight = (height - AXIS_PADDING) / size;

      if (unitHeight < MINIMUM_UNIT_HEIGHT) {
        unitHeight = MINIMUM_UNIT_HEIGHT;
      }

      // draw horizontal line
      gc.setForeground(XLogViewPainter.color_grid_narrow);
      gc.setLineStyle(SWT.LINE_DOT);
      for (int i = AXIS_PADDING + unitHeight; i <= height - unitHeight; i = i + unitHeight) {
        gc.drawLine(0, i, width, i);
      }

      // draw axis line
      gc.setForeground(black);
      gc.setLineStyle(SWT.LINE_SOLID);
      int verticalLineX = 6;
      gc.drawLine(verticalLineX, AXIS_PADDING, verticalLineX, height);
      gc.drawLine(verticalLineX, AXIS_PADDING, width, AXIS_PADDING);

      int groundWidth = area.width - verticalLineX;
      int barSpace = width - verticalLineX - (3 * BAR_WIDTH);
      int imgHeight = unitHeight - (BAR_PADDING_HEIGHT * 2);
      int mod = (int) (TimeUtil.getCurrentTime() % CYCLE_INTERVAL);
      for (int i = 0; i < datas.length; i++) {
        // draw objName
        String objName = datas[i].displayName;
        gc.setForeground(dark_gary);
        gc.setFont(verdana10Italic);
        int strWidth = gc.stringExtent(objName).x;
        while (groundWidth <= (strWidth + 5)) {
          objName = objName.substring(1);
          strWidth = gc.stringExtent(objName).x;
        }
        int x1 = width - strWidth - 5;
        int y1 =
            AXIS_PADDING + (unitHeight * i) + ((unitHeight - (gc.stringExtent(objName).y + 2)));
        gc.drawString(objName, x1, y1, true);
        if (datas[i].isAlive == false) {
          gc.setForeground(dark_gary);
          gc.setLineWidth(2);
          gc.drawLine(
              x1 - 1,
              y1 + (gc.stringExtent(objName).y / 2),
              x1 + gc.stringExtent(objName).x + 1,
              y1 + (gc.stringExtent(objName).y / 2));
        }
        gc.setLineWidth(1);
        ActiveSpeedData asd = datas[i].asd;
        long total = asd.act1 + asd.act2 + asd.act3;
        double reach = barSpace * (total / maxValue);
        int barX = verticalLineX + 1;
        if (total > 0) {
          try {
            // distribute bars to 3 types
            int noOfBars = (int) reach / BAR_WIDTH;
            int noOfAct1 = (int) (noOfBars * ((double) asd.act1 / total));
            int noOfAct2 = (int) (noOfBars * ((double) asd.act2 / total));
            int noOfAct3 = (int) (noOfBars * ((double) asd.act3 / total));
            int sediments = noOfBars - (noOfAct1 + noOfAct2 + noOfAct3);
            while (sediments > 0) {
              if (asd.act3 > 0) {
                noOfAct3++;
                sediments--;
              }
              if (sediments > 0 && asd.act2 > 0) {
                noOfAct2++;
                sediments--;
              }
              if (sediments > 0 && asd.act1 > 0) {
                noOfAct1++;
                sediments--;
              }
            }
            int barY = AXIS_PADDING + ((unitHeight * i) + BAR_PADDING_HEIGHT);
            Color lastColor = null;

            for (int j = 0; j < noOfAct3; j++) {
              // draw red bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac3,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac3;
            }
            for (int j = 0; j < noOfAct2; j++) {
              // draw yellow bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac2,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac2;
            }
            for (int j = 0; j < noOfAct1; j++) {
              // draw blue bar
              drawNemo(
                  gc,
                  ColorUtil.getInstance().ac1,
                  barX + 1,
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
              barX += BAR_WIDTH;
              lastColor = ColorUtil.getInstance().ac1;
            }

            // draw tong-tong bar
            if (lastColor != null) {
              drawNemo(
                  gc,
                  lastColor,
                  barX + 1 + (int) calculateReach(mod, BAR_WIDTH * 0.7d),
                  barY + 1,
                  BAR_WIDTH - 2,
                  imgHeight - 2);
            }
          } catch (Throwable th) {
            th.printStackTrace();
          }
        }

        // draw count text
        if (datas[i].isAlive) {
          gc.setFont(verdana10Bold);
          gc.setForeground(black);
          String v = Long.toString(total);
          gc.drawString(
              v,
              barX + (BAR_WIDTH * 2),
              AXIS_PADDING + (unitHeight * i) + ((unitHeight - gc.stringExtent(v).y) / 2),
              true);
        }
      }

      // draw scale text
      gc.setForeground(black);
      gc.setFont(verdana7);
      int max = (int) maxValue;
      String v = Integer.toString(max);
      String v2 = Integer.toString(max / 2);
      gc.drawString(v, width - gc.stringExtent(v).x - 2, 2, true);
      gc.drawString(
          v2, verticalLineX + ((width - verticalLineX) / 2) - gc.stringExtent(v2).x, 2, true);
      gc.drawString("0", verticalLineX, 2, true);
    } catch (Throwable th) {
      th.printStackTrace();
    } finally {
      gc.dispose();
      Image old = ibuffer;
      ibuffer = img;
      if (old != null) {
        old.dispose();
      }
      onGoing = false;
    }
  }
Example #14
0
  protected void paint(GC gc, Display display) {
    if (bounds == null) buildCaches();

    gc.setAntialias(SWT.ON);
    gc.setTextAntialias(SWT.ON);

    int x, y, w, h;
    boolean focused = getControl().isFocusControl() || isForceFocus();
    boolean hasBackgroundAndBorder = pressed || hovered || focused;
    if (hasBackgroundAndBorder) {
      // draw control background
      gc.setBackground(getBorderBackground(display));
      gc.fillRoundRectangle(
          bounds.x, bounds.y, bounds.width, bounds.height, CORNER_SIZE, CORNER_SIZE);
    }

    if (focused) {
      // draw focused content background
      x = contentArea.x - FOCUS_BORDER;
      y = contentArea.y - FOCUS_BORDER;
      w = contentArea.width + FOCUS_BORDER * 2;
      h = contentArea.height + FOCUS_BORDER * 2;
      gc.setBackground(getRealTextBackground(display));
      gc.fillRoundRectangle(x, y, w, h, FOCUS_CORNER_SIZE, FOCUS_CORNER_SIZE);
    }

    boolean hasImage = hasImage();
    boolean hasText = hasText();
    if (hasImage) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(imgArea)) {
        // draw image
        Point imgSize = getImageSize();
        x = imgArea.x + (imgArea.width - imgSize.x) / 2;
        y = imgArea.y + (imgArea.height - imgSize.y) / 2;
        gc.setClipping(imgArea);
        gc.drawImage(image, x, y);
        gc.setClipping(clipping);
      }
    }
    if (hasText) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(textArea)) {
        // draw text
        String text = getAppliedText();
        gc.setFont(getControl().getFont());
        Point ext = gc.stringExtent(text);
        //                    if (hasImage) {
        x = textArea.x;
        //                    } else {
        //                        x = textArea.x + (textArea.width - ext.x) / 2;
        //                    }
        y = textArea.y + (textArea.height - ext.y) / 2;
        gc.setClipping(textArea);
        gc.setForeground(getRealTextForeground(display));
        gc.drawString(text, x, y, true);
        gc.setClipping(clipping);
      }
    }

    // draw arrows
    if (hasArrows() && arrowLoc != null) {
      gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
      x = arrowLoc.x + ARROW_WIDTH / 2;
      y = arrowLoc.y;
      int x1 = arrowLoc.x - 1;
      int y1 = arrowLoc.y + ARROW_HEIGHT + 1;
      int x2 = arrowLoc.x + ARROW_WIDTH;
      gc.fillPolygon(new int[] {x, y, x1, y1, x2, y1});

      y += ARROW_HEIGHT * 2 + ARROWS_SPACING + 1;
      x1 = arrowLoc.x;
      y1 += ARROWS_SPACING;
      gc.fillPolygon(new int[] {x, y, x2, y1, x1 - 1, y1});
    }

    // draw border
    if (focused) {
      x = bounds.x;
      y = bounds.y;
      w = bounds.width;
      h = bounds.height;
      if (DRAWS_FOCUS) {
        gc.drawFocus(x - MARGIN + 1, y - MARGIN + 1, w + MARGIN * 2 - 2, h + MARGIN * 2 - 2);
      } else {
        gc.setForeground(getBorderForeground(display, focused));
        gc.drawRoundRectangle(x, y, w, h, CORNER_SIZE, CORNER_SIZE);
      }
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.mantis.MantisComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "rust.selection.color", 82, 140, 55);
    Color elementBlue = getColor(gc, resourceMap, "rust.element.color", 207, 234, 195);
    Color elementGradBlue = getColor(gc, resourceMap, "rust.element.color.gradient", 161, 211, 137);
    Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);
    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;
    int mainBodyHeight = height - (uiElement.hasConnectors() ? 12 : 0);

    if (uiElement.hasConnectors()) {
      // draw inspector tray
      gc.setBackground(elementBlue);
      gc.fillRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);

      // draw inspector tray border
      if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
        gc.setForeground(selectedColor);
      }
      gc.drawRoundRectangle(upperLeft.x, upperLeft.y + 3, width - 1, height - 3, 20, 20);
    }

    // draw main body
    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);
    gc.setBackground(elementGradBlue);
    gc.fillRoundRectangle(
        upperLeft.x + 1,
        upperLeft.y + (mainBodyHeight / 2) - 1,
        lowerRight.x - upperLeft.x - 2,
        (mainBodyHeight / 2) + (mainBodyHeight % 2),
        20,
        20);
    //		gc.setForeground(elementBlue);
    //		gc.fillGradientRectangle(upperLeft.x + 2,
    //			upperLeft.y
    //			+ (mainBodyHeight / 3),
    //			lowerRight.x - upperLeft.x - 4,
    //			((mainBodyHeight / 3) * 2) - 5,
    //			true);
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw main body border
    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, mainBodyHeight - 1, 20, 20);

    gc.setForeground(foreground);
    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 19, lowerRight.y - 8, lowerRight.x - 5, lowerRight.y - 8);
      //			gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 10, lowerRight.y - 3, lowerRight.x - 5, lowerRight.y - 8);
    }

    // draw icon
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(
          icon,
          upperLeft.x + 5,
          upperLeft.y + (((mainBodyHeight - 16) / 2) + ((mainBodyHeight - 16) % 2)));
    }

    // draw element name
    int curX = upperLeft.x + 25;
    int curY = upperLeft.y + 5;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 2 + stringExtent.y;
        curX = upperLeft.x + 25;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }

    // draw decorator icons
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }

    // resource cleanup
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    nameFont.dispose();
  }
Example #16
0
  private void drawDates(GC gc) {
    int y = mTopDateSpacer;
    int spacer = 2;

    Calendar temp = Calendar.getInstance(mLocale);
    temp.setTime(mStart.getTime());

    temp.add(Calendar.MONTH, -3);

    if (!CalendarCombo.OS_CARBON) {
      gc.setFont(mSettings.getWindowsMonthPopupDrawFont());
    } else gc.setFont(mSettings.getCarbonDrawFont());

    gc.setForeground(ColorCache.getBlack());

    mMonthEntries.clear();

    // gc.setBackground(ColorCache.getWhite());
    // gc.fillRectangle(bounds);

    for (int i = 0; i < mMonthsToShow; i++) {
      int mo = temp.get(Calendar.MONTH);
      String toDraw = mMonths[mo] + " " + temp.get(Calendar.YEAR);
      Point p = gc.stringExtent(toDraw);

      // center the text in the available space
      int rest = mInnerWidth - p.x;
      rest /= 2;

      Rectangle rect = new Rectangle(0, y - 1, mBounds.width, p.y + 1);

      if (mHoverEntry != null) {
        // draw hover entry
        if (mHoverEntry.getRect().equals(rect)) {
          gc.setBackground(ColorCache.getBlack());
          gc.fillRectangle(mHoverEntry.getRect());
          gc.setBackground(ColorCache.getWhite());
          gc.setForeground(ColorCache.getWhite());
          // lastHoverRect = hoverEntry.getRect();
          mSelectedMonth = mHoverEntry.getCalendar();
        }
      } else {
        // draw today
        if (i == 3) {
          gc.setBackground(ColorCache.getBlack());
          gc.fillRectangle(rect);
          gc.setBackground(ColorCache.getWhite());
          gc.setForeground(ColorCache.getWhite());
        }
      }

      gc.drawString(toDraw, rest, y, true);
      gc.setForeground(ColorCache.getBlack());

      MonthEntry me = new MonthEntry(temp);
      me.setRect(rect);
      me.setyPos(y);
      me.setText(toDraw);
      mMonthEntries.add(me);

      temp.add(Calendar.MONTH, 1);
      y += p.y + spacer;
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.vtp.desktop.editors.themes.attraction.AttractionComponentFrame#renderFrame(org.eclipse.swt.graphics.GC, int, int, java.util.Map)
   */
  public void renderFrame(GC gc, int renderingPhase, int options, Map<String, Object> resourceMap) {
    Font originalFont = gc.getFont();
    Color foreground = gc.getForeground();
    Color background = gc.getBackground();
    Color selectedColor = getColor(gc, resourceMap, "attraction.selection.color", 0, 0, 255);
    Color elementBlue = getColor(gc, resourceMap, "attraction.element.color", 201, 229, 255);
    Color elementGradBlue =
        getColor(gc, resourceMap, "attraction.element.color.gradient", 153, 206, 255);
    Font nameFont = getFont(gc, resourceMap, "attraction.element.font", "Arial", 10, SWT.NORMAL);
    gc.setFont(nameFont);

    if (upperLeft == null) {
      initializeGraphics(gc, resourceMap);
    }
    int width = lowerRight.x - upperLeft.x;
    int height = lowerRight.y - upperLeft.y;

    gc.setBackground(elementBlue);
    gc.fillRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_PRINTING) == 0) {
      gc.setBackground(elementGradBlue);
      gc.fillRoundRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 2),
          lowerRight.x - upperLeft.x,
          ((lowerRight.y - upperLeft.y) / 2),
          12,
          12);
      gc.setForeground(elementBlue);
      gc.fillGradientRectangle(
          upperLeft.x,
          upperLeft.y + ((lowerRight.y - upperLeft.y) / 3),
          lowerRight.x - upperLeft.x,
          (((lowerRight.y - upperLeft.y) / 3) * 2) - 5,
          true);
    }
    gc.setForeground(foreground);
    gc.setBackground(background);

    // draw connector hot spot
    if (uiElement.hasConnectors()) {
      gc.drawLine(lowerRight.x - 17, lowerRight.y - 10, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 15, lowerRight.x - 3, lowerRight.y - 10);
      gc.drawLine(lowerRight.x - 8, lowerRight.y - 5, lowerRight.x - 3, lowerRight.y - 10);
    }

    if (selected && (options & Theme.RENDER_FLAG_NO_SELECTION) == 0) {
      gc.setForeground(selectedColor);
    }
    gc.drawRoundRectangle(upperLeft.x, upperLeft.y, width - 1, height - 1, 12, 12);
    if ((options & Theme.RENDER_FLAG_NO_ICONS) == 0) {
      gc.drawImage(icon, upperLeft.x + 10, upperLeft.y + 12);
    }
    int curX = upperLeft.x + 30;
    int curY = upperLeft.y + 15;
    String[] parts = this.getDesignElement().getName().split(" ");
    Point stringExtent = gc.stringExtent(parts[0]);
    int ew = stringExtent.x;
    gc.drawString(parts[0], curX, curY, true);
    curX += stringExtent.x;
    for (int i = 1; i < parts.length; i++) {
      stringExtent = gc.stringExtent(" " + parts[i]);
      boolean wrapped = false;
      if (ew + stringExtent.x > 110) // wrap it
      {
        stringExtent = gc.stringExtent(parts[i]);
        ew = stringExtent.x;
        curY += 3 + stringExtent.y;
        curX = upperLeft.x + 30;
        wrapped = true;
      } else ew += stringExtent.x;
      gc.drawString((wrapped ? "" : " ") + parts[i], curX, curY, true);
      curX += stringExtent.x;
    }
    if (selected) {
      gc.setForeground(foreground);
    }
    gc.setFont(originalFont);
    if ((options & Theme.RENDER_FLAG_NO_MARKERS) == 0) {
      if (uiElement.hasErrors())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_ERROR"),
            lowerRight.x - 17,
            upperLeft.y);
      else if (uiElement.hasWarnings())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault()
                .getImageRegistry()
                .get("ICON_WARNING"),
            lowerRight.x - 16,
            upperLeft.y);
      else if (uiElement.hasTodo())
        gc.drawImage(
            org.eclipse.vtp.desktop.core.Activator.getDefault().getImageRegistry().get("ICON_TASK"),
            lowerRight.x - 18,
            upperLeft.y + 2);
    }
  }
Example #18
0
  private void drawPlayerStats(GC gc, Rectangle bounds, IPlayer player, int align) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    int p = w / 32;

    Color fillColor = null;
    Color handleColor = null;
    Color scoreColor = null;
    Color clockColor = null;

    if (game.getGameState() == GameState.ENDED) {
      if (player == game.getWinner()) {
        fillColor = new Color(null, 0, 164, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      } else {
        fillColor = new Color(null, 164, 0, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      }
    } else {
      if (player == game.getCurrentPlayer()) {
        fillColor = new Color(null, 0, 0, 192);
        handleColor = new Color(null, 205, 205, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 215, 215, 215);
      } else {
        fillColor = new Color(null, 153, 153, 153);
        handleColor = new Color(null, 0, 0, 128);
        scoreColor = new Color(null, 0, 0, 0);
        clockColor = new Color(null, 0, 0, 0);
      }
    }

    // fill
    gc.setBackground(fillColor);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);

    // draw handle
    int n = h / 4;
    Font font = new Font(null, "Arial", n, SWT.BOLD);
    String s = player.getName();
    gc.setFont(font);
    gc.setForeground(handleColor);
    Point extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y, true);
    }
    font.dispose();

    // save width
    int i = extent.x + p;

    // draw clock
    font = new Font(null, "Courier New", n, SWT.BOLD);
    s = player.getClock().toString();
    gc.setFont(font);
    gc.setForeground(clockColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y + h - extent.y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y + h - extent.y, true);
    }
    font.dispose();

    // draw score
    font = new Font(null, "Arial", h / 2, SWT.BOLD);
    s = Integer.toString(player.getScore());
    gc.setFont(font);
    gc.setForeground(scoreColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + i + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    } else {
      gc.drawString(s, x + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    }
    font.dispose();

    fillColor.dispose();
    handleColor.dispose();
    scoreColor.dispose();
    clockColor.dispose();
  }
  /** {@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);
  }
 void paint(Event event) {
   if (row == null) return;
   int columnIndex = column == null ? 0 : table.indexOf(column);
   GC gc = event.gc;
   gc.setBackground(getBackground());
   gc.setForeground(getForeground());
   gc.fillRectangle(event.x, event.y, event.width, event.height);
   int x = 0;
   Point size = getSize();
   Image image = row.getImage(columnIndex);
   if (image != null) {
     Rectangle imageSize = image.getBounds();
     int imageY = (size.y - imageSize.height) / 2;
     gc.drawImage(image, x, imageY);
     x += imageSize.width;
   }
   String text = row.getText(columnIndex);
   if (text.length() > 0) {
     Rectangle bounds = row.getBounds(columnIndex);
     Point extent = gc.stringExtent(text);
     // Temporary code - need a better way to determine table trim
     String platform = SWT.getPlatform();
     if ("win32".equals(platform)) { // $NON-NLS-1$
       if (table.getColumnCount() == 0 || columnIndex == 0) {
         x += 2;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 6;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 6;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2;
             break;
         }
       }
     } else {
       if (table.getColumnCount() == 0) {
         x += 5;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 5;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 2;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2 + 2;
             break;
         }
       }
     }
     int textY = (size.y - extent.y) / 2;
     gc.drawString(text, x, textY);
   }
   if (isFocusControl()) {
     Display display = getDisplay();
     gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
     gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
     gc.drawFocus(0, 0, size.x, size.y);
   }
 }