Esempio n. 1
0
 /**
  * Paints the bevel image for the specified component with the specified position and size.
  *
  * @param c the component for which this border is being painted
  * @param gr the paint graphics
  * @param x the x position of the painted border
  * @param y the y position of the painted border
  * @param width the width of the painted border
  * @param height the height of the painted border
  */
 public void paintBorder(Component c, Graphics gr, int x, int y, int width, int height) {
   if (image == null) return;
   if (gr.getClipBounds() != null && !gr.getClipBounds().intersects(x, y, width, height)) {
     return;
   }
   paint(c, gr, x, y, width, height, args);
 }
  /**
   * Method which renders the text of the current button.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   * @since 1.4
   */
  @Override
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1);
    boolean borderHasPressedCue = borderHasPressedCue(b);

    /* Draw the Text */
    if (model.isPressed() && model.isArmed() && !borderHasPressedCue) {
      g.setColor(new Color(0xa0000000, true));
      QuaquaUtilities.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset() + 1);
    }

    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground");
      g.setColor((c != null) ? c : b.getForeground());
    }
    QuaquaUtilities.drawStringUnderlineCharAt(
        g,
        text,
        mnemonicIndex,
        textRect.x + getTextShiftOffset(),
        textRect.y + fm.getAscent() + getTextShiftOffset());
  }
Esempio n. 3
0
  protected void paintToImage(Component c, Graphics gr, int width, int height, Object args) {
    // Cast Graphics to Graphics2D
    // Workaround for Java 1.4 and 1.4 on Mac OS X 10.4. We create a new
    // Graphics object instead of just casting the provided one. This is
    // because drawing texture paints appears to confuse the Graphics object.
    Graphics2D g = (Graphics2D) gr.create();

    // Convert image to buffered image (and keep the buffered image).
    image = Images.toBufferedImage(image);
    BufferedImage img = (BufferedImage) image;

    // Set some variables for easy access of insets and image size
    int top = imageInsets.top;
    int left = imageInsets.left;
    int bottom = imageInsets.bottom;
    int right = imageInsets.right;
    int imgWidth = img.getWidth();
    int imgHeight = img.getHeight();

    // Optimisation: Draw image directly if it fits into the component
    if (fillContentArea) {
      if (width == imgWidth && height == imgHeight) {
        g.drawImage(img, 0, 0, c);
        g.dispose();
        return;
      }
    }

    // Optimisation: Remove insets, if image width or image height fits
    if (width == imgWidth) {
      left = imgWidth;
      right = 0;
    }
    if (height == imgHeight) {
      top = imgHeight;
      bottom = 0;
    }

    // Adjust insets if component is too small
    if (width < left + right) {
      left = Math.min(left, width / 2); // Math.max(0, left + (width - left - right) / 2);
      right = width - left;
    }
    if (height < top + bottom) {
      top = Math.min(top, height / 2); // Math.max(0, top + (height - top - bottom) / 2);
      bottom = height - top;
    }

    // Draw the Corners
    if (top > 0 && left > 0) {
      g.drawImage(img, 0, 0, left, top, 0, 0, left, top, c);
    }
    if (top > 0 && right > 0) {
      // g.fillRect(x+width-right, y, x+width, y+top);
      g.drawImage(img, width - right, 0, width, top, imgWidth - right, 0, imgWidth, top, c);
    }
    if (bottom > 0 && left > 0) {
      g.drawImage(img, 0, height - bottom, left, height, 0, imgHeight - bottom, left, imgHeight, c);
    }
    if (bottom > 0 && right > 0) {
      g.drawImage(
          img,
          width - right,
          height - bottom,
          width,
          height,
          imgWidth - right,
          imgHeight - bottom,
          imgWidth,
          imgHeight,
          c);
    }

    // Draw the edges
    BufferedImage subImg = null;
    TexturePaint paint;

    // North
    if (top > 0 && left + right < width) {
      if (imgWidth > right + left) {
        subImg = img.getSubimage(left, 0, imgWidth - right - left, top);
        paint = new TexturePaint(subImg, new Rectangle(left, 0, imgWidth - left - right, top));
        g.setPaint(paint);
        g.fillRect(left, 0, width - left - right, top);
      }
    }
    // South
    if (bottom > 0 && left + right < width) {
      if (imgHeight > bottom && imgWidth > right + left) {
        subImg = img.getSubimage(left, imgHeight - bottom, imgWidth - right - left, bottom);
        paint =
            new TexturePaint(
                subImg, new Rectangle(left, height - bottom, imgWidth - left - right, bottom));
        g.setPaint(paint);
        g.fillRect(left, height - bottom, width - left - right, bottom);
      }
    }
    // West
    if (left > 0 && top + bottom < height) {
      if (imgHeight > top + bottom) {
        subImg = img.getSubimage(0, top, left, imgHeight - top - bottom);
        paint = new TexturePaint(subImg, new Rectangle(0, top, left, imgHeight - top - bottom));
        g.setPaint(paint);
        g.fillRect(0, top, left, height - top - bottom);
      }
    }
    // East
    if (right > 0 && top + bottom < height) {
      if (imgWidth > right && imgHeight > top + bottom) {
        subImg = img.getSubimage(imgWidth - right, top, right, imgHeight - top - bottom);
        paint =
            new TexturePaint(
                subImg, new Rectangle(width - right, top, right, imgHeight - top - bottom));
        g.setPaint(paint);
        g.fillRect(width - right, top, right, height - top - bottom);
      }
    }

    // Fill the center
    if (fillContentArea) {
      if (left + right < imgWidth && top + bottom < imgHeight) {
        subImg = img.getSubimage(left, top, imgWidth - right - left, imgHeight - top - bottom);
        paint =
            new TexturePaint(
                subImg,
                new Rectangle(left, top, imgWidth - right - left, imgHeight - top - bottom));
        g.setPaint(paint);
        g.fillRect(left, top, width - right - left, height - top - bottom);
      }
    }
    g.dispose();
  }