]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/TableBorder.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / TableBorder.java
1 package org.simantics.spreadsheet.ui;
2
3 import java.awt.Color;
4 import java.awt.Component;
5 import java.awt.Graphics;
6 import java.awt.Insets;
7
8 import javax.swing.border.AbstractBorder;
9 import javax.swing.border.Border;
10
11 public class TableBorder extends AbstractBorder {
12
13         private static final long serialVersionUID = -2732591061826521471L;
14         private static Border blackLine;
15         private static Border grayLine;
16
17         protected int thickness;
18         protected Color lineColor;
19         protected boolean roundedCorners;
20
21         final public static TableBorder BORDER = new TableBorder(DefaultLookup.BORDER, 0);
22
23         /** Convenience method for getting the Color.black LineBorder of thickness 1.
24          */
25         public static Border createBlackLineBorder() {
26                 if (blackLine == null) {
27                         blackLine = new TableBorder(Color.black, 1);
28                 }
29                 return blackLine;
30         }
31
32         /** Convenience method for getting the Color.gray LineBorder of thickness 1.
33          */
34         public static Border createGrayLineBorder() {
35                 if (grayLine == null) {
36                         grayLine = new TableBorder(Color.gray, 1);
37                 }
38                 return grayLine;
39         }
40
41         /** 
42          * Creates a line border with the specified color and a 
43          * thickness = 1.
44          * @param color the color for the border
45          */
46         public TableBorder(Color color) {
47                 this(color, 1, false);
48         }
49
50         /**
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
54          */
55         public TableBorder(Color color, int thickness)  {
56                 this(color, thickness, false);
57         }
58
59         /**
60          * Creates a line border with the specified color, thickness,
61          * and corner shape.
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
65          * @since 1.3
66          */
67         public TableBorder(Color color, int thickness, boolean roundedCorners)  {
68                 lineColor = color;
69                 this.thickness = thickness;
70                 this.roundedCorners = roundedCorners;
71         }
72
73         /**
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
82          */
83         public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
84
85                 Color oldColor = g.getColor();
86                 int i;
87
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);
95                 //                              else
96                 //                                      g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness);
97                 //                      }
98                 g.setColor(oldColor);
99
100         }
101
102         /**
103          * Returns the insets of the border.
104          * @param c the component for which this border insets value applies
105          */
106         public Insets getBorderInsets(Component c)       {
107                 return new Insets(thickness, thickness, thickness, thickness);
108         }
109
110         /** 
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
114          */
115         public Insets getBorderInsets(Component c, Insets insets) {
116                 insets.left = insets.top = insets.right = insets.bottom = thickness;
117                 return insets;
118         }
119
120         /**
121          * Returns the color of the border.
122          */
123         public Color getLineColor()     {
124                 return lineColor;
125         }
126
127         /**
128          * Returns the thickness of the border.
129          */
130         public int getThickness()       {
131                 return thickness;
132         }
133
134         /**
135          * Returns whether this border will be drawn with rounded corners.
136          * @since 1.3
137          */
138         public boolean getRoundedCorners() {
139                 return roundedCorners;
140         }
141
142         /**
143          * Returns whether or not the border is opaque.
144          */
145         public boolean isBorderOpaque() { 
146                 return !roundedCorners; 
147         }
148
149 }