1 package org.simantics.spreadsheet.ui;
4 import java.awt.Component;
5 import java.awt.Graphics;
6 import java.awt.Insets;
8 import javax.swing.border.AbstractBorder;
9 import javax.swing.border.Border;
11 public class TableBorder extends AbstractBorder {
13 private static final long serialVersionUID = -2732591061826521471L;
14 private static Border blackLine;
15 private static Border grayLine;
17 protected int thickness;
18 protected Color lineColor;
19 protected boolean roundedCorners;
21 final public static TableBorder BORDER = new TableBorder(DefaultLookup.BORDER, 0);
23 /** Convenience method for getting the Color.black LineBorder of thickness 1.
25 public static Border createBlackLineBorder() {
26 if (blackLine == null) {
27 blackLine = new TableBorder(Color.black, 1);
32 /** Convenience method for getting the Color.gray LineBorder of thickness 1.
34 public static Border createGrayLineBorder() {
35 if (grayLine == null) {
36 grayLine = new TableBorder(Color.gray, 1);
42 * Creates a line border with the specified color and a
44 * @param color the color for the border
46 public TableBorder(Color color) {
47 this(color, 1, false);
51 * Creates a line border with the specified color and thickness.
52 * @param color the color of the border
53 * @param thickness the thickness of the border
55 public TableBorder(Color color, int thickness) {
56 this(color, thickness, false);
60 * Creates a line border with the specified color, thickness,
62 * @param color the color of the border
63 * @param thickness the thickness of the border
64 * @param roundedCorners whether or not border corners should be round
67 public TableBorder(Color color, int thickness, boolean roundedCorners) {
69 this.thickness = thickness;
70 this.roundedCorners = roundedCorners;
74 * Paints the border for the specified component with the
75 * specified position and size.
76 * @param c the component for which this border is being painted
77 * @param g the paint graphics
78 * @param x the x position of the painted border
79 * @param y the y position of the painted border
80 * @param width the width of the painted border
81 * @param height the height of the painted border
83 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
85 Color oldColor = g.getColor();
88 /// PENDING(klobad) How/should do we support Roundtangles?
89 g.setColor(lineColor);
90 g.drawLine(1, height-1, 1 + width-1, height-1);
91 g.drawLine(width-1, 0, width-1, height-1);
92 // for(i = 0; i < thickness; i++) {
93 // if(!roundedCorners)
94 // g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1);
96 // g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
103 * Returns the insets of the border.
104 * @param c the component for which this border insets value applies
106 public Insets getBorderInsets(Component c) {
107 return new Insets(thickness, thickness, thickness, thickness);
111 * Reinitialize the insets parameter with this Border's current Insets.
112 * @param c the component for which this border insets value applies
113 * @param insets the object to be reinitialized
115 public Insets getBorderInsets(Component c, Insets insets) {
116 insets.left = insets.top = insets.right = insets.bottom = thickness;
121 * Returns the color of the border.
123 public Color getLineColor() {
128 * Returns the thickness of the border.
130 public int getThickness() {
135 * Returns whether this border will be drawn with rounded corners.
138 public boolean getRoundedCorners() {
139 return roundedCorners;
143 * Returns whether or not the border is opaque.
145 public boolean isBorderOpaque() {
146 return !roundedCorners;