示例#1
0
  /**
   * 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;
  }
示例#2
0
 /**
  * Adds horizontal stretch interval.
  *
  * @param start interval start
  * @param end interval end
  * @param pixel whether fixed interval or not
  */
 public void addHorizontalStretch(final int start, final int end, final boolean pixel) {
   addHorizontalStretch(new NinePatchInterval(start, end, pixel));
 }