/** * Returns inner shade nine-patch icon. * * @param shadeWidth shade width * @param round corners round * @param shadeOpacity shade opacity * @return inner shade nine-patch icon */ public static NinePatchIcon createInnerShadeIcon( final int shadeWidth, final int round, final float shadeOpacity) { // Calculating width for temprorary image final int inner = Math.max(shadeWidth, round); int width = shadeWidth * 2 + inner * 2; // Creating template image final BufferedImage bi = new BufferedImage(width, width, BufferedImage.TYPE_INT_ARGB); final Graphics2D ig = bi.createGraphics(); GraphicsUtils.setupAntialias(ig); final Area area = new Area(new Rectangle(0, 0, width, width)); area.exclusiveOr( new Area( new RoundRectangle2D.Double( shadeWidth, shadeWidth, width - shadeWidth * 2, width - shadeWidth * 2, round * 2, round * 2))); ig.setPaint(Color.BLACK); ig.fill(area); ig.dispose(); // Creating shade image final ShadowFilter sf = new ShadowFilter(shadeWidth, 0, 0, shadeOpacity); final BufferedImage shade = sf.filter(bi, null); // Clipping shade image final Graphics2D g2d = shade.createGraphics(); GraphicsUtils.setupAntialias(g2d); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN)); g2d.setPaint(FlatLafStyleConstants.transparent); g2d.fill(area); g2d.dispose(); final BufferedImage croppedShade = shade.getSubimage(shadeWidth, shadeWidth, width - shadeWidth * 2, width - shadeWidth * 2); width = croppedShade.getWidth(); // Creating nine-patch icon final NinePatchIcon ninePatchIcon = NinePatchIcon.create(croppedShade); ninePatchIcon.addHorizontalStretch(0, inner, true); ninePatchIcon.addHorizontalStretch(inner + 1, width - inner - 1, false); ninePatchIcon.addHorizontalStretch(width - inner, width, true); ninePatchIcon.addVerticalStretch(0, inner, true); ninePatchIcon.addVerticalStretch(inner + 1, width - inner - 1, false); ninePatchIcon.addVerticalStretch(width - inner, width, true); ninePatchIcon.setMargin(shadeWidth); return ninePatchIcon; }
/** * Returns rotated by 180 degrees NinePatchIcon. This method also modifies patches information * properly. * * @param icon NinePatchIcon to rotate * @return rotated by 180 degrees NinePatchIcon */ public static NinePatchIcon rotateIcon180(final NinePatchIcon icon) { final BufferedImage rawImage = ImageUtils.rotateImage180(icon.getRawImage()); final NinePatchIcon rotated = NinePatchIcon.create(rawImage); // Rotating stretch information rotated.setHorizontalStretch(CollectionUtils.copy(icon.getHorizontalStretch())); rotated.setVerticalStretch(CollectionUtils.copy(icon.getVerticalStretch())); // Rotating margin final Insets om = icon.getMargin(); rotated.setMargin(om.bottom, om.right, om.top, om.left); return rotated; }
/** * Sets content margin. * * @param spacing sides margin */ public void setMargin(final int spacing) { setMargin(spacing, spacing, spacing, spacing); }
/** * Sets content margin. * * @param top top margin * @param left left margin * @param bottom bottom margin * @param right right margin */ public void setMargin(final int top, final int left, final int bottom, final int right) { setMargin(new Insets(top, left, bottom, right)); }