コード例 #1
0
  @Override
  protected void paintBackground(Graphics g, JComponent component) {
    getGlassParameters();
    Graphics2D g2d = (Graphics2D) g.create();

    if (getOrientation().isHorizontal()) {
      paintBackground(
          g2d,
          0,
          0,
          component.getWidth(),
          component.getHeight(),
          getOrientation().isHorizontal(),
          component);
    } else {
      paintBackground(
          g2d,
          0,
          0,
          component.getHeight(),
          component.getWidth(),
          getOrientation().isHorizontal(),
          component);
    }

    g2d.dispose();
  }
コード例 #2
0
  protected void paintBackground(
      Graphics g, int x, int y, int w, int h, boolean horizontal, JComponent component) {
    Graphics2D g2d = (Graphics2D) g.create();
    CEclipseBorder ec = null;
    Insets ins = getOutsideInsets();

    x = ins.left;
    y = ins.top;
    if (getOrientation().isHorizontal()) {
      w -= ins.left + ins.right;
      h -= ins.top + ins.bottom;
    } else {
      w -= ins.top + ins.bottom;
      h -= ins.left + ins.right;
    }

    if (component.getBorder() instanceof CompoundBorder) {
      CompoundBorder cb = (CompoundBorder) component.getBorder();
      CompoundBorder bb = (CompoundBorder) cb.getInsideBorder();

      ec = (CEclipseBorder) bb.getOutsideBorder();
    }

    if (w > 0 && h > 0) {
      if (glassStrip != null) {
        BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics2D gg = im.createGraphics();
        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        gg.setColor(component.getBackground());
        if (ec != null) {
          gg.fill(ec.createShape(0, 0, w, h, ec.getCornerRadius()));

        } else {
          gg.fillRect(0, 0, w, h);
        }

        if (!isSelected()) {
          gg.setComposite(AlphaComposite.SrcIn);
        } else {
          gg.setComposite(AlphaComposite.SrcAtop);
        }

        try {
          glass.Render2Graphics(new Dimension(w, h), gg, glassStrip, true);
        } catch (Exception e) {
          glass.Render2Graphics(new Dimension(w, h), gg, CGlassFactory.VALUE_STEEL, true);
        }

        gg.dispose();

        if (!getOrientation().isHorizontal()) {
          AffineTransform atTrans = AffineTransform.getTranslateInstance(x /* + h */, y + w);
          atTrans.concatenate(COutlineHelper.tRot90CCW);
          g2d.drawImage(im, atTrans, null);
        } else {
          g2d.drawImage(im, x, y, null);
        }
      }

      g2d.dispose();
    }
  }