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