1 package org.simantics.spreadsheet.ui;
\r
3 import java.awt.Graphics;
\r
4 import java.awt.Insets;
\r
5 import java.awt.Component;
\r
6 import java.awt.Color;
\r
8 import javax.swing.Icon;
\r
9 import javax.swing.border.EmptyBorder;
\r
11 import org.simantics.ui.colors.Colors;
\r
13 public class SheetBorder extends EmptyBorder
\r
15 private static final long serialVersionUID = 1L;
\r
16 protected boolean bottomColor;
\r
17 protected boolean rightColor;
\r
19 final Color NONE = Colors.awt(Colors.rgb(0.9,0.9,0.9));
\r
24 * Creates a matte border with the specified insets and color.
\r
25 * @param top the top inset of the border
\r
26 * @param left the left inset of the border
\r
27 * @param bottom the bottom inset of the border
\r
28 * @param right the right inset of the border
\r
29 * @param matteColor the color rendered for the border
\r
31 public SheetBorder(int top, int left, int bottom, int right, boolean bottomColor, boolean rightColor) {
\r
32 super(top, left, bottom, right);
\r
33 this.bottomColor = bottomColor;
\r
34 this.rightColor = rightColor;
\r
38 * Paints the matte border.
\r
40 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
\r
42 Insets insets = getBorderInsets(c);
\r
43 Color oldColor = g.getColor();
\r
46 boolean same = bottomColor == rightColor;
\r
50 g.setColor(bottomColor ? Color.BLACK : NONE);
\r
51 g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
\r
52 g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
\r
56 // Not the same color - paint black on top
\r
59 // Black bottom - no right
\r
61 g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
\r
62 g.setColor(Color.BLACK);
\r
63 g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
\r
65 // Black right - no bottom
\r
67 g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
\r
68 g.setColor(Color.BLACK);
\r
69 g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
\r
74 g.translate(-x, -y);
\r
75 g.setColor(oldColor);
\r
80 * Reinitialize the insets parameter with this Border's current Insets.
\r
81 * @param c the component for which this border insets value applies
\r
82 * @param insets the object to be reinitialized
\r
85 public Insets getBorderInsets(Component c, Insets insets) {
\r
86 return computeInsets(insets);
\r
90 * Returns the insets of the border.
\r
93 public Insets getBorderInsets() {
\r
94 return computeInsets(new Insets(0,0,0,0));
\r
97 /* should be protected once api changes area allowed */
\r
98 private Insets computeInsets(Insets insets) {
\r
101 insets.right = right;
\r
102 insets.bottom = bottom;
\r
107 * Returns the color used for tiling the border or null
\r
108 * if a tile icon is being used.
\r
111 public Color getMatteColor() {
\r
116 * Returns the icon used for tiling the border or null
\r
117 * if a solid color is being used.
\r
120 public Icon getTileIcon() {
\r
125 * Returns whether or not the border is opaque.
\r
127 public boolean isBorderOpaque() {
\r
128 // If a tileIcon is set, then it may contain transparent bits
\r