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