/** * sets the round height of the rectangle * @param roundHeight a new round height */ public void setRoundHeight(int roundHeight) { int oldRoundHeight = getRoundHeight(); this.roundHeight = roundHeight; setDirty(true); firePropertyChange("roundHeight",oldRoundHeight,roundHeight); }
/** * sets the round width of the rectangle * @param roundWidth a new round width */ public void setRoundWidth(int roundWidth) { int oldRoundWidth = getRoundWidth(); this.roundWidth = roundWidth; setDirty(true); firePropertyChange("roundWidth",oldRoundWidth,roundWidth); }
/** * sets if the rectangle should be rounded * @param rounded if the rectangle should be rounded */ public void setRounded(boolean rounded) { boolean oldRounded = isRounded(); this.rounded = rounded; setDirty(true); firePropertyChange("rounded",oldRounded,rounded); }
private void drawBackground(Graphics2D g, Shape shape, int width, int height) { Paint p = getFillPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.fill(shape); if(getAreaEffects() != null) { for(AreaEffect ef : getAreaEffects()) { ef.apply(g, shape, width, height); } } }
private void drawBorder(Graphics2D g, Shape shape, int width, int height) { Paint p = getBorderPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.setStroke(new BasicStroke(getBorderWidth())); // shrink the border by 1 px if(shape instanceof Rectangle2D) { Rectangle2D rect = (Rectangle2D) shape; g.draw(new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1)); } else if(shape instanceof RoundRectangle2D) { RoundRectangle2D rect = (RoundRectangle2D) shape; g.draw(new RoundRectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1, rect.getArcWidth(), rect.getArcHeight())); } else { g.draw(shape); } }
protected RectangularShape calculateShape(int width, int height) { Insets insets = getInsets(); int x = insets.left; int y = insets.top; // use the position calcs from the super class Rectangle bounds = calculateLayout(this.width, this.height, width, height); if(this.width != -1 && !isFillHorizontal()) { width = this.width; x = bounds.x; } if(this.height != -1 && !isFillVertical()) { height = this.height; y = bounds.y; } if(isFillHorizontal()) { width = width - insets.left - insets.right; } if(isFillVertical()) { height = height - insets.top - insets.bottom; } RectangularShape shape = new Rectangle2D.Double(x, y, width, height); if(rounded) { shape = new RoundRectangle2D.Double(x, y, width, height, roundWidth, roundHeight); } return shape; }
@Override protected void doPaint(Graphics2D g, Object component, int width, int height) { Shape shape = provideShape(g, component, width, height); switch (getStyle()) { case BOTH: drawBackground(g,shape,width,height); drawBorder(g,shape,width,height); break; case FILLED: drawBackground(g,shape,width,height); break; case OUTLINE: drawBorder(g,shape,width,height); break; } // background // border // leave the clip to support masking other painters ShapeUtils.mergeClip(g,shape); /* Area area = new Area(g.getClip()); area.intersect(new Area(shape));//new Rectangle(0,0,width,height))); g.setClip(area);*/ //g.setClip(shape); }
protected void doPaint(Graphics2D g, T component, int width, int height) { RectangularShape shape = calculateShape(width, height); switch (getStyle()) { case BOTH: drawBackground(g,shape,width,height); drawBorder(g,shape,width,height); break; case FILLED: drawBackground(g,shape,width,height); break; case OUTLINE: drawBorder(g,shape,width,height); break; case NONE: break; } // background // border // leave the clip to support masking other painters GraphicsUtilities.mergeClip(g,shape); /* Area area = new Area(g.getClip()); area.intersect(new Area(shape));//new Rectangle(0,0,width,height))); g.setClip(area);*/ //g.setClip(shape); }
assertThat(rp.getRoundHeight(), is(0)); assertThat(rp.getRoundWidth(), is(0)); assertThat(rp.isRounded(), is(false));
@Override protected Shape provideShape(Graphics2D g, Object comp, int width, int height) { return calculateShape(width,height); } }
private void drawBackground(Graphics2D g, Shape shape, int width, int height) { Paint p = getFillPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.fill(shape); if(getAreaEffects() != null) { for(AreaEffect ef : getAreaEffects()) { ef.apply(g, shape, width, height); } } }
private void drawBorder(Graphics2D g, Shape shape, int width, int height) { Paint p = getBorderPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.setStroke(new BasicStroke(getBorderWidth())); // shrink the border by 1 px if(shape instanceof Rectangle2D) { Rectangle2D rect = (Rectangle2D) shape; g.draw(new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1)); } else if(shape instanceof RoundRectangle2D) { RoundRectangle2D rect = (RoundRectangle2D) shape; g.draw(new RoundRectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1, rect.getArcWidth(), rect.getArcHeight())); } else { g.draw(shape); } }
protected RectangularShape calculateShape(int width, int height) { Insets insets = getInsets(); int x = insets.left; int y = insets.top; // use the position calcs from the super class Rectangle bounds = calculateLayout(this.width, this.height, width, height); if(this.width != -1 && !isFillHorizontal()) { width = this.width; x = bounds.x; } if(this.height != -1 && !isFillVertical()) { height = this.height; y = bounds.y; } if(isFillHorizontal()) { width = width - insets.left - insets.right; } if(isFillVertical()) { height = height - insets.top - insets.bottom; } RectangularShape shape = new Rectangle2D.Double(x, y, width, height); if(rounded) { shape = new RoundRectangle2D.Double(x, y, width, height, roundWidth, roundHeight); } return shape; }
@Override protected void doPaint(Graphics2D g, Object component, int width, int height) { Shape shape = provideShape(g, component, width, height); switch (getStyle()) { case BOTH: drawBackground(g,shape,width,height); drawBorder(g,shape,width,height); break; case FILLED: drawBackground(g,shape,width,height); break; case OUTLINE: drawBorder(g,shape,width,height); break; } // background // border // leave the clip to support masking other painters ShapeUtils.mergeClip(g,shape); /* Area area = new Area(g.getClip()); area.intersect(new Area(shape));//new Rectangle(0,0,width,height))); g.setClip(area);*/ //g.setClip(shape); }
@Override protected Shape provideShape(Graphics2D g, Object comp, int width, int height) { return calculateShape(width,height); } }
private void drawBackground(Graphics2D g, Shape shape, int width, int height) { Paint p = getFillPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.fill(shape); if(getAreaEffects() != null) { for(AreaEffect ef : getAreaEffects()) { ef.apply(g, shape, width, height); } } }
private void drawBorder(Graphics2D g, Shape shape, int width, int height) { Paint p = getBorderPaint(); if(isPaintStretched()) { p = calculateSnappedPaint(p, width, height); } g.setPaint(p); g.setStroke(new BasicStroke(getBorderWidth())); // shrink the border by 1 px if(shape instanceof Rectangle2D) { Rectangle2D rect = (Rectangle2D) shape; g.draw(new Rectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1)); } else if(shape instanceof RoundRectangle2D) { RoundRectangle2D rect = (RoundRectangle2D) shape; g.draw(new RoundRectangle2D.Double(rect.getX(), rect.getY(), rect.getWidth()-1, rect.getHeight()-1, rect.getArcWidth(), rect.getArcHeight())); } else { g.draw(shape); } }
protected RectangularShape calculateShape(int width, int height) { Insets insets = getInsets(); int x = insets.left; int y = insets.top; // use the position calcs from the super class Rectangle bounds = calculateLayout(this.width, this.height, width, height); if(this.width != -1 && !isFillHorizontal()) { width = this.width; x = bounds.x; } if(this.height != -1 && !isFillVertical()) { height = this.height; y = bounds.y; } if(isFillHorizontal()) { width = width - insets.left - insets.right; } if(isFillVertical()) { height = height - insets.top - insets.bottom; } RectangularShape shape = new Rectangle2D.Double(x, y, width, height); if(rounded) { shape = new RoundRectangle2D.Double(x, y, width, height, roundWidth, roundHeight); } return shape; }
/** * sets the round height of the rectangle * @param roundHeight a new round height */ public void setRoundHeight(int roundHeight) { int oldRoundHeight = getRoundHeight(); this.roundHeight = roundHeight; setDirty(true); firePropertyChange("roundHeight",oldRoundHeight,roundHeight); }
/** * sets the round width of the rectangle * @param roundWidth a new round width */ public void setRoundWidth(int roundWidth) { int oldRoundWidth = getRoundWidth(); this.roundWidth = roundWidth; setDirty(true); firePropertyChange("roundWidth",oldRoundWidth,roundWidth); }