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