@Override protected void fillShape(Graphics graphics) { Rectangle a = start(graphics); try { graphics.fillRoundRectangle(a, 20, 20); } finally { stop(graphics); } }
@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); }
@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); } }