Exemplo n.º 1
0
    protected void paintFigure(Graphics graphics) {
      int alpha = 0x60;
      graphics.setAntialias(SWT.ON);
      if (control != null && !control.isDisposed() && control.isEnabled()) {
        graphics.setAlpha(0xff);
      } else {
        graphics.setAlpha(0x90);
      }
      Rectangle r = getBounds();
      Path shape = new Path(Display.getCurrent());
      float corner = Math.max(2, (vertical ? r.width : r.height) / 2);
      SWTUtils.addRoundedRectangle(shape, r.x, r.y, r.width - 1, r.height - 1, corner);

      Pattern pattern =
          new Pattern(
              Display.getCurrent(), //
              r.x,
              r.y, //
              vertical ? r.right() - 1 : r.x, //
              vertical ? r.y : r.bottom() - 1, //
              ColorConstants.gray,
              alpha, //
              ColorConstants.lightGray,
              alpha);
      graphics.setBackgroundPattern(pattern);
      graphics.fillPath(shape);
      graphics.setBackgroundPattern(null);
      pattern.dispose();

      graphics.setAlpha(alpha);
      graphics.setForegroundColor(ColorConstants.gray);
      graphics.drawPath(shape);
      shape.dispose();
    }
Exemplo n.º 2
0
    @Override
    protected void paintClientArea(Graphics graphics) {
      if (support3d == null) support3d = GraphicsUtil.testPatternSupported(graphics);
      Rectangle clientArea = getClientArea();
      Rectangle square =
          new Rectangle(
              clientArea.x,
              clientArea.y + clientArea.height / 2 - BOX_SIZE / 2,
              BOX_SIZE,
              BOX_SIZE);
      graphics.pushState();
      if (support3d)
        graphics.setBackgroundPattern(
            GraphicsUtil.createScaledPattern(
                graphics,
                Display.getCurrent(),
                square.x,
                square.y + 1,
                square.x,
                square.y + square.height,
                ColorConstants.white,
                graphics.getBackgroundColor()));
      graphics.fillRoundRectangle(square, 4, 4);
      graphics.setForegroundColor(CustomMediaFactory.getInstance().getColor(130, 130, 130));
      graphics.drawRoundRectangle(square, 4, 4);

      if (boolValue) {
        graphics.translate(square.x, square.y);
        graphics.setLineWidth(3);
        graphics.setForegroundColor(selectedColor);

        graphics.drawPolyline(
            new int[] {
              3,
              (int) (BOX_SIZE * 0.45),
              (int) (BOX_SIZE * 0.45),
              BOX_SIZE * 3 / 4 - 1,
              BOX_SIZE - 2,
              3
            });
      }
      graphics.popState();
      Dimension textSize = FigureUtilities.getTextExtents(text, graphics.getFont());

      if (!isEnabled()) {
        graphics.translate(1, 1);
        graphics.setForegroundColor(ColorConstants.buttonLightest);
        graphics.drawText(text, square.getRight().getTranslated(GAP, -textSize.height / 2));
        graphics.translate(-1, -1);
        graphics.setForegroundColor(ColorConstants.buttonDarker);
      }
      graphics.drawText(text, square.getRight().getTranslated(GAP, -textSize.height / 2));

      super.paintClientArea(graphics);
    }
Exemplo n.º 3
0
    @Override
    protected void fillShape(Graphics graphics) {
      graphics.setAntialias(SWT.ON);
      Pattern pattern = null;
      graphics.setBackgroundColor(GRAY_COLOR);
      boolean support3D = GraphicsUtil.testPatternSupported(graphics);
      if (effect3D && support3D) {
        // add this to eliminate the repaint bug on Mac
        graphics.fillOval(new Rectangle());

        pattern =
            new Pattern(
                Display.getCurrent(),
                bounds.x,
                bounds.y,
                bounds.x + bounds.width,
                bounds.y + bounds.height,
                WHITE_COLOR,
                BORDER_COLOR);
        graphics.setBackgroundPattern(pattern);
      }
      super.fillShape(graphics);
      if (effect3D && support3D) pattern.dispose();
    }
Exemplo n.º 4
0
    @Override
    protected void fillShape(Graphics graphics) {

      int fill_corner = DEFAULT_CORNER;
      // If this is more close to 1/2, more light the tank will be.
      double intersectFactor = 11d / 20d;
      if (bounds.width < 2 * DEFAULT_CORNER) intersectFactor = 12d / 20d;
      int rectWidth = (int) (bounds.width * intersectFactor);
      if (fill_corner > (2 * rectWidth - (bounds.width - 2 * getLineWidth())))
        fill_corner = 2 * rectWidth - bounds.width;

      corner.height = fill_corner;
      corner.width = fill_corner;
      graphics.setAntialias(SWT.ON);
      int valuePosition = ((LinearScale) scale).getValuePosition(getCoercedValue(), false);
      if (support3d == null) support3d = GraphicsUtil.testPatternSupported(graphics);

      if (effect3D && support3d) {
        graphics.setBackgroundColor(WHITE_COLOR);
        super.fillShape(graphics);
        // fill background
        Rectangle leftRectangle = new Rectangle(bounds.x, bounds.y, rectWidth, bounds.height);
        Pattern leftGradientPattern =
            GraphicsUtil.createScaledPattern(
                graphics,
                Display.getCurrent(),
                leftRectangle.x,
                leftRectangle.y,
                leftRectangle.x + leftRectangle.width + 2,
                leftRectangle.y,
                fillBackgroundColor,
                255,
                WHITE_COLOR,
                0);
        graphics.setBackgroundPattern(leftGradientPattern);
        graphics.fillRoundRectangle(leftRectangle, corner.width, corner.height);
        Rectangle rightRectangle =
            new Rectangle(bounds.x + bounds.width - rectWidth, bounds.y, rectWidth, bounds.height);
        Pattern rightGradientPattern =
            GraphicsUtil.createScaledPattern(
                graphics,
                Display.getCurrent(),
                rightRectangle.x - 2,
                rightRectangle.y,
                rightRectangle.x + rightRectangle.width,
                rightRectangle.y,
                WHITE_COLOR,
                0,
                fillBackgroundColor,
                255);
        graphics.setBackgroundPattern(rightGradientPattern);
        graphics.fillRoundRectangle(rightRectangle, corner.width, corner.height);
        leftGradientPattern.dispose();
        rightGradientPattern.dispose();

        // fill value
        graphics.setBackgroundColor(WHITE_COLOR);
        int fillHeight = bounds.height - (valuePosition - bounds.y) - getLineWidth();
        if (fillHeight > 0) {
          graphics.fillRoundRectangle(
              new Rectangle(bounds.x, valuePosition, bounds.width, fillHeight),
              fill_corner,
              fill_corner);
          leftRectangle = new Rectangle(bounds.x, valuePosition, rectWidth, fillHeight);
          leftGradientPattern =
              GraphicsUtil.createScaledPattern(
                  graphics,
                  Display.getCurrent(),
                  leftRectangle.x,
                  leftRectangle.y,
                  leftRectangle.x + leftRectangle.width + 2,
                  leftRectangle.y,
                  fillColor,
                  255,
                  WHITE_COLOR,
                  0);
          graphics.setBackgroundPattern(leftGradientPattern);
          graphics.fillRoundRectangle(leftRectangle, fill_corner, fill_corner);

          rightRectangle =
              new Rectangle(
                  bounds.x + bounds.width - rectWidth, valuePosition, rectWidth, fillHeight);
          rightGradientPattern =
              GraphicsUtil.createScaledPattern(
                  graphics,
                  Display.getCurrent(),
                  rightRectangle.x - 2,
                  rightRectangle.y,
                  rightRectangle.x + rightRectangle.width,
                  rightRectangle.y,
                  WHITE_COLOR,
                  0,
                  fillColor,
                  255);
          graphics.setBackgroundPattern(rightGradientPattern);
          graphics.fillRoundRectangle(rightRectangle, fill_corner, fill_corner);

          leftGradientPattern.dispose();
          rightGradientPattern.dispose();
        }
        graphics.setForegroundColor(EFFECT3D_OUTLINE_COLOR);

      } else {
        graphics.setBackgroundColor(fillBackgroundColor);
        super.fillShape(graphics);
        graphics.setBackgroundColor(fillColor);
        graphics.fillRoundRectangle(
            new Rectangle(
                bounds.x + lineWidth,
                valuePosition,
                bounds.width - 2 * lineWidth,
                bounds.height - (valuePosition - bounds.y)),
            fill_corner,
            fill_corner);
        //        graphics.setForegroundColor(outlineColor);
      }
    }
Exemplo n.º 5
0
  @Override
  protected void paintClientArea(Graphics graphics) {
    graphics.setAntialias(SWT.ON);
    Rectangle area = getClientArea();
    area.width = Math.min(area.width, area.height);
    area.height = area.width;
    Pattern pattern = null;
    graphics.pushState();
    graphics.setBackgroundColor(GRAY_COLOR);
    boolean support3D = GraphicsUtil.testPatternSupported(graphics);
    if (effect3D && support3D) {
      // add this to eliminate the repaint bug on Mac
      graphics.fillOval(new Rectangle());
      pattern =
          new Pattern(
              Display.getCurrent(),
              area.x,
              area.y,
              area.x + area.width,
              area.y + area.height,
              BORDER_COLOR,
              WHITE_COLOR);
      graphics.setBackgroundPattern(pattern);
    }
    graphics.fillOval(area);
    graphics.popState();

    if (effect3D && support3D) {
      pattern.dispose();
      area.shrink(BORDER_WIDTH, BORDER_WIDTH);
    } else area.shrink(1, 1);

    graphics.fillOval(area);

    super.paintClientArea(graphics);

    // glossy effect
    if (effect3D && support3D) {
      graphics.pushState();
      graphics.setAntialias(SWT.ON);
      final double R = area.width / 2.0d;
      final double UD_FILL_PART = 9.5d / 10d;
      final double UP_DOWN_RATIO = 1d / 2d;
      final double LR_FILL_PART = 8.5d / 10d;
      final double UP_ANGLE = 0d * Math.PI / 180d;
      final double DOWN_ANGLE = 35d * Math.PI / 180d;
      // add this to eliminate the repaint bug on Mac

      graphics.fillOval(new Rectangle());

      Pattern glossyPattern =
          new Pattern(
              Display.getCurrent(),
              area.x + area.width / 2,
              (float) (area.y + area.height / 2 - R * UD_FILL_PART),
              area.x + area.width / 2,
              (float) (area.y + area.height / 2 + R * UP_DOWN_RATIO),
              WHITE_COLOR,
              90,
              WHITE_COLOR,
              0);
      graphics.setBackgroundPattern(glossyPattern);
      Rectangle rectangle =
          new Rectangle(
              (int) (area.x + area.width / 2 - R * LR_FILL_PART * Math.cos(UP_ANGLE)),
              (int) (area.y + area.height / 2 - R * UD_FILL_PART),
              (int) (2 * R * LR_FILL_PART * Math.cos(UP_ANGLE)),
              (int) (R * UD_FILL_PART + R * UP_DOWN_RATIO));
      graphics.fillOval(rectangle);
      glossyPattern.dispose();

      glossyPattern =
          new Pattern(
              Display.getCurrent(),
              area.x + area.width / 2,
              (float) (area.y + area.height / 2 + R * UP_DOWN_RATIO - 1),
              area.x + area.width / 2,
              (float) (area.y + area.height / 2 + R * UD_FILL_PART + 1),
              WHITE_COLOR,
              0,
              WHITE_COLOR,
              40);
      graphics.setBackgroundPattern(glossyPattern);
      rectangle =
          new Rectangle(
              (int) (area.x + area.width / 2 - R * LR_FILL_PART * Math.sin(DOWN_ANGLE)),
              (int) Math.ceil(area.y + area.height / 2 + R * UP_DOWN_RATIO),
              (int) (2 * R * LR_FILL_PART * Math.sin(DOWN_ANGLE)),
              (int) Math.ceil(R * UD_FILL_PART - R * UP_DOWN_RATIO));
      graphics.fillOval(rectangle);
      glossyPattern.dispose();
      graphics.popState();
    }
  }
Exemplo n.º 6
0
  @Override
  protected void paintClientArea(Graphics graphics) {
    updateThresholdPosition();
    graphics.setAntialias(SWT.ON);
    graphics.setLineWidth(rampWidth);
    graphics.pushState();
    int overlap = 0;
    Pattern pattern = null;
    boolean support3D = GraphicsUtil.testPatternSupported(graphics);
    // draw lolo part
    if (lolo.visible) {
      graphics.setBackgroundColor(lolo.color);
      graphics.fillArc(bounds, lolo.absolutePosition, min.relativePosition - lolo.relativePosition);
    }
    // draw lo part
    if (lo.visible) {
      if (support3D && gradient && lolo.visible) {
        try {
          pattern =
              new Pattern(
                  Display.getCurrent(),
                  lolo.leftPoint.x,
                  lolo.leftPoint.y,
                  lo.rightPoint.x,
                  lo.rightPoint.y,
                  lolo.color,
                  lo.color);
          graphics.setBackgroundPattern(pattern);
          overlap = OVERLAP_DEGREE / 2;
        } catch (Exception e) {
          support3D = false;
          pattern.dispose();
          graphics.setBackgroundColor(lo.color);
          overlap = 0;
        }
      } else {
        graphics.setBackgroundColor(lo.color);
        overlap = 0;
      }

      if (lolo.visible)
        graphics.fillArc(
            bounds, lo.absolutePosition, lolo.relativePosition - lo.relativePosition + overlap);
      else
        graphics.fillArc(bounds, lo.absolutePosition, min.relativePosition - lo.relativePosition);
      if (gradient && lolo.visible && support3D) pattern.dispose();
    }

    // draw left normal part
    // get the left marker
    boolean leftMarkerVisible = false;
    ThresholdMarker leftMarker = null;
    if (lo.visible) {
      leftMarkerVisible = true;
      leftMarker = lo;
    } else if (lolo.visible) {
      leftMarkerVisible = true;
      leftMarker = lolo;
    } else leftMarkerVisible = false;

    if (gradient && leftMarkerVisible && support3D) {
      pattern =
          new Pattern(
              Display.getCurrent(),
              leftMarker.leftPoint.x,
              leftMarker.leftPoint.y,
              normal.rightPoint.x,
              normal.rightPoint.y,
              leftMarker.color,
              normal.color);
      graphics.setBackgroundPattern(pattern);
      overlap = OVERLAP_DEGREE / 2;
    } else {
      graphics.setBackgroundColor(normal.color);
      overlap = 0;
    }

    if (leftMarkerVisible)
      graphics.fillArc(
          bounds,
          normal.absolutePosition,
          leftMarker.relativePosition - normal.relativePosition + overlap);
    else
      graphics.fillArc(
          bounds, normal.absolutePosition, min.relativePosition - normal.relativePosition);

    if (gradient && leftMarkerVisible && support3D) pattern.dispose();

    // draw right normal part
    // get the right marker
    boolean rightMarkerVisible = false;
    ThresholdMarker rightMarker = null;
    if (hi.visible) {
      rightMarkerVisible = true;
      rightMarker = hi;
    } else if (hihi.visible) {
      rightMarkerVisible = true;
      rightMarker = hihi;
    } else rightMarkerVisible = false;

    if (gradient && rightMarkerVisible && support3D) {
      pattern =
          new Pattern(
              Display.getCurrent(),
              rightMarker.rightPoint.x,
              rightMarker.rightPoint.y,
              normal.leftPoint.x,
              normal.leftPoint.y,
              rightMarker.color,
              normal.color);
      graphics.setBackgroundPattern(pattern);
      overlap = OVERLAP_DEGREE / 2;
    } else {
      graphics.setBackgroundColor(normal.color);
      overlap = 0;
    }

    if (rightMarkerVisible)
      graphics.fillArc(
          bounds,
          rightMarker.absolutePosition,
          normal.relativePosition - rightMarker.relativePosition + overlap + 1);
    else
      graphics.fillArc(
          bounds, max.absolutePosition, normal.relativePosition - max.relativePosition + 1);

    if (gradient && rightMarkerVisible && support3D) pattern.dispose();

    // draw hi part
    if (hi.visible) {
      if (hihi.visible) {
        rightMarkerVisible = true;
        rightMarker = hihi;
      } else rightMarkerVisible = false;

      if (gradient && rightMarkerVisible && support3D) {
        pattern =
            new Pattern(
                Display.getCurrent(),
                rightMarker.rightPoint.x,
                rightMarker.rightPoint.y,
                hi.leftPoint.x,
                hi.leftPoint.y,
                rightMarker.color,
                hi.color);
        graphics.setBackgroundPattern(pattern);
        overlap = OVERLAP_DEGREE / 2;
      } else {
        graphics.setBackgroundColor(hi.color);
        overlap = 0;
      }

      if (rightMarkerVisible)
        graphics.fillArc(
            bounds,
            rightMarker.absolutePosition,
            hi.relativePosition - rightMarker.relativePosition + overlap);
      else
        graphics.fillArc(bounds, max.absolutePosition, hi.relativePosition - max.relativePosition);

      if (gradient && rightMarkerVisible && support3D) pattern.dispose();
    }

    // draw hihi part
    if (hihi.visible) {
      if (gradient && support3D) overlap = OVERLAP_DEGREE / 2;
      else overlap = 0;
      graphics.setBackgroundColor(hihi.color);
      graphics.fillArc(
          bounds, max.absolutePosition, hihi.relativePosition - max.relativePosition + overlap);
    }

    graphics.popState();
    graphics.fillOval(
        bounds.x + rampWidth,
        bounds.y + rampWidth,
        bounds.width - 2 * rampWidth,
        bounds.height - 2 * rampWidth);

    super.paintClientArea(graphics);
  }