Exemple #1
0
  /**
   * A border with rounded corners and a shadow
   *
   * @author Poul Henriksen
   */
  private static class RoundedShadowBorder extends AbstractBorder {
    private Insets insets;
    private ImageIcon topLeftCorner = Config.getImageAsIcon("image.border.topleft");
    private ImageIcon topRightCorner = Config.getImageAsIcon("image.border.topright");
    private ImageIcon bottomLeftCorner = Config.getImageAsIcon("image.border.bottomleft");
    private ImageIcon bottomRightCorner = Config.getImageAsIcon("image.border.bottomright");
    private Color shadowColor = new Color(145, 145, 145);
    private Color backgroundColor = Color.white;
    private Color borderColor = Color.black;
    private int backgroundThickness = 5; // extra space around the frame

    public RoundedShadowBorder() {
      insets = new Insets(0, 0, 0, 0);
      insets.bottom = bottomLeftCorner.getIconHeight() + backgroundThickness;
      insets.top = topLeftCorner.getIconHeight() + backgroundThickness;
      insets.left = topLeftCorner.getIconHeight() + backgroundThickness;
      insets.right = topRightCorner.getIconHeight() + backgroundThickness;
    }

    /**
     * Reinitializes the insets parameter with this Border's current Insets.
     *
     * @param c the component for which this border insets value applies
     * @param insets the object to be reinitialized
     * @return the <code>insets</code> object
     */
    public Insets getBorderInsets(Component c, Insets insets) {
      insets.bottom = this.insets.bottom;
      insets.top = this.insets.top;
      insets.left = this.insets.left;
      insets.right = this.insets.right;
      return insets;
    }

    /**
     * Returns a new <code>Insets</code> instance.
     *
     * @param c the component for which this border insets value applies
     * @return the new <code>Insets</code> object
     */
    public Insets getBorderInsets(Component c) {
      return (Insets) insets.clone();
    }

    /** Returns false. */
    public boolean isBorderOpaque() {
      return false;
    }

    /** Paints the border */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      x += backgroundThickness;
      y += backgroundThickness;
      height -= 2 * backgroundThickness;
      width -= 2 * backgroundThickness;
      // Top
      g.setColor(backgroundColor);
      g.drawLine(x, y, x + width, y);
      g.drawLine(x, y + 1, x + width, y + 1);
      g.drawLine(x, y + 2, x + width, y + 2);
      g.setColor(borderColor);
      g.drawLine(x, y + 3, x + width, y + 3);

      // Bottom
      g.setColor(borderColor);
      g.drawLine(x, y + height - 4, x + width, y + height - 4);
      g.setColor(shadowColor);
      g.drawLine(x, y + height - 3, x + width, y + height - 3);
      g.drawLine(x, y + height - 2, x + width, y + height - 2);

      // Left
      g.setColor(backgroundColor);
      g.drawLine(x, y, x, y + height);
      g.drawLine(x + 1, y, x + 1, y + height);
      g.drawLine(x + 2, y, x + 2, y + height);
      g.setColor(borderColor);
      g.drawLine(x + 3, y, x + 3, y + height);

      // Right
      g.setColor(borderColor);
      g.drawLine(x + width - 4, y, x + width - 4, y + height);
      g.setColor(shadowColor);
      g.drawLine(x + width - 3, y, x + width - 3, y + height);
      g.drawLine(x + width - 2, y, x + width - 2, y + height);

      // Background around the border
      g.setColor(backgroundColor);
      for (int i = 0; i < backgroundThickness + 1; i++) {
        g.drawRect(x - i, y - i, width - 1 + 2 * i, height - 1 + 2 * i);
      }

      // Corners
      height += backgroundThickness;
      width += backgroundThickness;
      topLeftCorner.paintIcon(c, g, x, y);
      topRightCorner.paintIcon(c, g, x + width - insets.right, y);
      bottomLeftCorner.paintIcon(c, g, x, y + height - insets.bottom);
      bottomRightCorner.paintIcon(c, g, x + width - insets.right, y + height - insets.bottom);
    }
  }
Exemple #2
0
  /**
   * Get the icon for most BlueJ frames.
   *
   * @return an icon to be used as the frame icon for most BlueJ windows
   */
  public static Image getIconImage() {
    if (iconImage == null) iconImage = Config.getImageAsIcon("image.icon").getImage();

    return iconImage;
  }