public Shape getShape(float xMin, float yMin, float xMax, float yMax) { final float w = xMax - xMin; final float h = yMax - yMin; final float arcSize = Math.min(w, h) / 4f; rect.setRoundRect(xMin, yMin, w, h, arcSize, arcSize); return rect; } }
public void paintComponent(Graphics g) { insets = super.getInsets(insets); final Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final float x = insets.left; final float y = insets.top; final float w = getEffectiveWidth() - insets.right - insets.left; final float h = HEIGHT; bkRect.setRoundRect(x, y, w, h, CORNER_RADIUS, CORNER_RADIUS); g2d.setColor(BK_COLOR); g2d.fill(bkRect); if (indet) { final float nw = (INDET_BAR_WIDTH * 2.0 > w) ? (w * 0.2f) : INDET_BAR_WIDTH; final float nx = (float) (x + (w - nw) * indetPositionFunc(indetPosition)); fgRect.setRoundRect(nx, y, nw, h, CORNER_RADIUS, CORNER_RADIUS); g2d.setColor(INDET_FG_COLOR); } else { fgRect.setRoundRect(x, y, w * progress, h, CORNER_RADIUS, CORNER_RADIUS); g2d.setColor(FG_COLOR); } g2d.fill(fgRect); }
@Override public Canvas strokeRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareStroke(gfx); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); gfx.draw(roundRect); isDirty = true; return this; }
/** * Creates a path representing the rounded rectangle provided. * * @param x left of rectangle * @param y top of rectangle * @param width width of rectangle * @param height height of rectangle * @param arcWidth width of the arc at the corners * @param arcHeight height of arc at the corners * @return created rounded rectangle */ public static PSWTPath createRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight); final PSWTPath result = new PSWTPath(TEMP_ROUNDRECTANGLE); result.setPaint(Color.white); return result; }
/** * Resets the path to a rectangle with the dimensions and position provided. * * @param x left of the rectangle * @param y top of te rectangle * @param width width of the rectangle * @param height height of the rectangle * @param arcWidth width of arc in the corners of the rectangle * @param arcHeight height of arc in the corners of the rectangle */ public void setPathToRoundRectangle(final float x, final float y, final float width, final float height, final float arcWidth, final float arcHeight) { TEMP_ROUNDRECTANGLE.setRoundRect(x, y, width, height, arcWidth, arcHeight); setShape(TEMP_ROUNDRECTANGLE); }
@Override public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, boolean fill) { ROUND_RECT.setRoundRect(x, y, width, height, arcWidth, arcHeight); if (fill) { fill(ROUND_RECT, true); } else { draw(ROUND_RECT); } }
@Override public Canvas strokeRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareStroke(g2d); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); g2d.draw(roundRect); isDirty = true; return this; }
@Override public Canvas strokeRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareStroke(g2d); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); g2d.draw(roundRect); isDirty = true; return this; }
@Override public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, boolean fill) { ROUND_RECT.setRoundRect(x, y, width, height, arcWidth, arcHeight); if (fill) { fill(ROUND_RECT, true); } else { draw(ROUND_RECT); } }
@Override public Canvas fillRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareFill(gfx); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); gfx.fill(roundRect); isDirty = true; return this; }
@Override public Canvas fillRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareFill(g2d); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); g2d.fill(roundRect); isDirty = true; return this; }
@Override public Canvas strokeRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareStroke(gfx); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); gfx.draw(roundRect); isDirty = true; return this; }
@Override public Canvas fillRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareFill(g2d); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); g2d.fill(roundRect); isDirty = true; return this; }
@Override public Canvas fillRoundRect(float x, float y, float width, float height, float radius) { currentState().prepareFill(gfx); roundRect.setRoundRect(x, y, width, height, radius*2, radius*2); gfx.fill(roundRect); isDirty = true; return this; }