Lines 1-507
Link Here
|
1 |
package org.apache.poi.hssf.contrib.view; |
1 |
package org.apache.poi.hssf.contrib.view; |
2 |
|
2 |
|
3 |
import java.awt.Graphics; |
3 |
import java.awt.*; |
4 |
import java.awt.Insets; |
4 |
|
5 |
import java.awt.Rectangle; |
5 |
import javax.swing.border.AbstractBorder; |
6 |
import java.awt.Color; |
6 |
|
7 |
import java.awt.Component; |
7 |
import org.apache.poi.hssf.usermodel.HSSFCellStyle; |
8 |
|
8 |
|
9 |
import javax.swing.border.AbstractBorder; |
9 |
/** |
10 |
|
10 |
* This is an attempt to implement Excel style borders for the SuckyViewer |
11 |
import org.apache.poi.hssf.usermodel.HSSFCellStyle; |
11 |
* |
12 |
|
12 |
*/ |
13 |
/** |
13 |
public class SVBorder extends AbstractBorder { |
14 |
* This is an attempt to implement Excel style borders for the SuckyViewer |
14 |
private Color northColor = null; |
15 |
* |
15 |
private Color eastColor = null; |
16 |
*/ |
16 |
private Color southColor = null; |
17 |
public class SVBorder extends AbstractBorder { |
17 |
private Color westColor = null; |
18 |
Color northColor = null; |
18 |
private int northBorderType = HSSFCellStyle.BORDER_NONE; |
19 |
Color eastColor = null; |
19 |
private int eastBorderType =HSSFCellStyle.BORDER_NONE; |
20 |
Color southColor = null; |
20 |
private int southBorderType = HSSFCellStyle.BORDER_NONE; |
21 |
Color westColor = null; |
21 |
private int westBorderType = HSSFCellStyle.BORDER_NONE; |
22 |
int northBorderType; |
22 |
private boolean northBorder=false; |
23 |
int eastBorderType; |
23 |
private boolean eastBorder=false; |
24 |
int southBorderType; |
24 |
private boolean southBorder=false; |
25 |
int westBorderType; |
25 |
private boolean westBorder=false; |
26 |
boolean northBorder=false; |
26 |
private boolean selected = false; |
27 |
boolean eastBorder=false; |
27 |
|
28 |
boolean southBorder=false; |
28 |
public void setBorder(Color northColor, Color eastColor, |
29 |
boolean westBorder=false; |
29 |
Color southColor, Color westColor, |
30 |
|
30 |
int northBorderType, int eastBorderType, |
31 |
public SVBorder(Color northColor, Color eastColor, |
31 |
int southBorderType, int westBorderType, |
32 |
Color southColor, Color westColor, |
32 |
boolean selected) { |
33 |
int northBorderType, int eastBorderType, |
33 |
this.eastColor = eastColor; |
34 |
int southBorderType, int westBorderType, |
34 |
this.southColor = southColor; |
35 |
boolean northBorder, boolean eastBorder, |
35 |
this.westColor = westColor; |
36 |
boolean southBorder, boolean westBorder) { |
36 |
this.northBorderType = northBorderType; |
37 |
this.northColor = northColor; |
37 |
this.eastBorderType = eastBorderType; |
38 |
this.eastColor = eastColor; |
38 |
this.southBorderType = southBorderType; |
39 |
this.southColor = southColor; |
39 |
this.westBorderType = westBorderType; |
40 |
this.westColor = westColor; |
40 |
this.northBorder=northBorderType != HSSFCellStyle.BORDER_NONE; |
41 |
this.northBorderType = northBorderType; |
41 |
this.eastBorder=eastBorderType != HSSFCellStyle.BORDER_NONE; |
42 |
this.eastBorderType = eastBorderType; |
42 |
this.southBorder=southBorderType != HSSFCellStyle.BORDER_NONE; |
43 |
this.southBorderType = southBorderType; |
43 |
this.westBorder=westBorderType != HSSFCellStyle.BORDER_NONE; |
44 |
this.westBorderType = westBorderType; |
44 |
this.selected = selected; |
45 |
this.northBorder=northBorder; |
45 |
} |
46 |
this.eastBorder=eastBorder; |
46 |
|
47 |
this.southBorder=southBorder; |
47 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, |
48 |
this.westBorder=westBorder; |
48 |
int height) { |
49 |
} |
49 |
Color oldColor = g.getColor(); |
50 |
|
50 |
|
51 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, |
51 |
|
52 |
int height) { |
52 |
paintSelectedBorder(g, x, y, width, height); |
53 |
Color oldColor = g.getColor(); |
53 |
paintNormalBorders(g, x, y, width, height); |
54 |
int i; |
54 |
paintDottedBorders(g, x, y, width, height); |
55 |
|
55 |
paintDashedBorders(g, x, y, width, height); |
56 |
// System.err.println("northBorder="+northBorderType); |
56 |
paintDoubleBorders(g, x, y, width, height); |
57 |
paintNormalBorders(g, x, y, width, height); |
57 |
paintDashDotDotBorders(g, x, y, width, height); |
58 |
paintDottedBorders(g, x, y, width, height); |
58 |
|
59 |
paintDashedBorders(g, x, y, width, height); |
59 |
|
60 |
paintDoubleBorders(g, x, y, width, height); |
60 |
g.setColor(oldColor); |
61 |
paintDashDotDotBorders(g, x, y, width, height); |
61 |
} |
62 |
|
62 |
|
63 |
|
63 |
private void paintSelectedBorder(Graphics g, int x, int y, int width, |
64 |
g.setColor(oldColor); |
64 |
int height) { |
65 |
} |
65 |
if (selected) { |
66 |
|
66 |
//Need to setup thickness of 2 |
67 |
private void paintNormalBorders(Graphics g, int x, int y, int width, |
67 |
g.setColor(Color.black); |
68 |
int height) { |
68 |
//paint the border |
69 |
|
69 |
g.drawRect(x,y,width-1,height-1); |
70 |
if (northBorder && |
70 |
|
71 |
((northBorderType == HSSFCellStyle.BORDER_THIN) || |
71 |
//paint the filled rectangle at the bottom left hand position |
72 |
(northBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
72 |
g.fillRect(x+width-5, y+height-5, 5, 5); |
73 |
(northBorderType == HSSFCellStyle.BORDER_THICK) |
73 |
} |
74 |
) |
74 |
} |
75 |
) { |
75 |
|
76 |
|
76 |
|
77 |
int thickness = getThickness(northBorderType); |
77 |
private void paintNormalBorders(Graphics g, int x, int y, int width, |
78 |
|
78 |
int height) { |
79 |
g.setColor(northColor); |
79 |
|
80 |
|
80 |
if (northBorder && |
81 |
for (int k=0; k < thickness; k++) { |
81 |
((northBorderType == HSSFCellStyle.BORDER_THIN) || |
82 |
g.drawLine(x,y+k,width,y+k); |
82 |
(northBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
83 |
} |
83 |
(northBorderType == HSSFCellStyle.BORDER_THICK) |
84 |
} |
84 |
) |
85 |
|
85 |
) { |
86 |
if (eastBorder && |
86 |
|
87 |
((eastBorderType == HSSFCellStyle.BORDER_THIN) || |
87 |
int thickness = getThickness(northBorderType); |
88 |
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
88 |
|
89 |
(eastBorderType == HSSFCellStyle.BORDER_THICK) |
89 |
g.setColor(northColor); |
90 |
) |
90 |
|
91 |
) { |
91 |
for (int k=0; k < thickness; k++) { |
92 |
|
92 |
g.drawLine(x,y+k,width,y+k); |
93 |
int thickness = getThickness(eastBorderType); |
93 |
} |
94 |
|
94 |
} |
95 |
g.setColor(eastColor); |
95 |
|
96 |
|
96 |
if (eastBorder && |
97 |
for (int k=0; k < thickness; k++) { |
97 |
((eastBorderType == HSSFCellStyle.BORDER_THIN) || |
98 |
g.drawLine(width-k,y,width-k,height); |
98 |
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
99 |
} |
99 |
(eastBorderType == HSSFCellStyle.BORDER_THICK) |
100 |
} |
100 |
) |
101 |
|
101 |
) { |
102 |
if (southBorder && |
102 |
|
103 |
((southBorderType == HSSFCellStyle.BORDER_THIN) || |
103 |
int thickness = getThickness(eastBorderType); |
104 |
(southBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
104 |
|
105 |
(southBorderType == HSSFCellStyle.BORDER_THICK) |
105 |
g.setColor(eastColor); |
106 |
) |
106 |
|
107 |
) { |
107 |
for (int k=0; k < thickness; k++) { |
108 |
|
108 |
g.drawLine(width-k,y,width-k,height); |
109 |
int thickness = getThickness(southBorderType); |
109 |
} |
110 |
|
110 |
} |
111 |
g.setColor(southColor); |
111 |
|
112 |
for (int k=0; k < thickness; k++) { |
112 |
if (southBorder && |
113 |
g.drawLine(x,height - k,width,height - k); |
113 |
((southBorderType == HSSFCellStyle.BORDER_THIN) || |
114 |
} |
114 |
(southBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
115 |
} |
115 |
(southBorderType == HSSFCellStyle.BORDER_THICK) |
116 |
|
116 |
) |
117 |
if (westBorder && |
117 |
) { |
118 |
((westBorderType == HSSFCellStyle.BORDER_THIN) || |
118 |
|
119 |
(westBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
119 |
int thickness = getThickness(southBorderType); |
120 |
(westBorderType == HSSFCellStyle.BORDER_THICK) |
120 |
|
121 |
) |
121 |
g.setColor(southColor); |
122 |
) { |
122 |
for (int k=0; k < thickness; k++) { |
123 |
|
123 |
g.drawLine(x,height - k,width,height - k); |
124 |
int thickness = getThickness(westBorderType); |
124 |
} |
125 |
|
125 |
} |
126 |
g.setColor(westColor); |
126 |
|
127 |
|
127 |
if (westBorder && |
128 |
for (int k=0; k < thickness; k++) { |
128 |
((westBorderType == HSSFCellStyle.BORDER_THIN) || |
129 |
g.drawLine(x+k,y,x+k,height); |
129 |
(westBorderType == HSSFCellStyle.BORDER_MEDIUM) || |
130 |
} |
130 |
(westBorderType == HSSFCellStyle.BORDER_THICK) |
131 |
} |
131 |
) |
132 |
} |
132 |
) { |
133 |
|
133 |
|
134 |
private void paintDottedBorders(Graphics g, int x, int y, int width, |
134 |
int thickness = getThickness(westBorderType); |
135 |
int height) { |
135 |
|
136 |
if (northBorder && |
136 |
g.setColor(westColor); |
137 |
northBorderType == HSSFCellStyle.BORDER_DOTTED) { |
137 |
|
138 |
int thickness = getThickness(northBorderType); |
138 |
for (int k=0; k < thickness; k++) { |
139 |
|
139 |
g.drawLine(x+k,y,x+k,height); |
140 |
g.setColor(northColor); |
140 |
} |
141 |
|
141 |
} |
142 |
for (int k=0; k < thickness; k++) { |
142 |
} |
143 |
for (int xc = x; xc < width; xc=xc+2) { |
143 |
|
144 |
g.drawLine(xc,y+k,xc,y+k); |
144 |
private void paintDottedBorders(Graphics g, int x, int y, int width, |
145 |
} |
145 |
int height) { |
146 |
} |
146 |
if (northBorder && |
147 |
} |
147 |
northBorderType == HSSFCellStyle.BORDER_DOTTED) { |
148 |
|
148 |
int thickness = getThickness(northBorderType); |
149 |
if (eastBorder && |
149 |
|
150 |
eastBorderType == HSSFCellStyle.BORDER_DOTTED |
150 |
g.setColor(northColor); |
151 |
) { |
151 |
|
152 |
|
152 |
for (int k=0; k < thickness; k++) { |
153 |
int thickness = getThickness(eastBorderType); |
153 |
for (int xc = x; xc < width; xc=xc+2) { |
154 |
thickness++; //need for dotted borders to show up east |
154 |
g.drawLine(xc,y+k,xc,y+k); |
155 |
|
155 |
} |
156 |
g.setColor(eastColor); |
156 |
} |
157 |
|
157 |
} |
158 |
for (int k=0; k < thickness; k++) { |
158 |
|
159 |
for (int yc=y;yc < height; yc=yc+2) { |
159 |
if (eastBorder && |
160 |
g.drawLine(width-k,yc,width-k,yc); |
160 |
eastBorderType == HSSFCellStyle.BORDER_DOTTED |
161 |
} |
161 |
) { |
162 |
} |
162 |
|
163 |
} |
163 |
int thickness = getThickness(eastBorderType); |
164 |
|
164 |
thickness++; //need for dotted borders to show up east |
165 |
if (southBorder && |
165 |
|
166 |
southBorderType == HSSFCellStyle.BORDER_DOTTED |
166 |
g.setColor(eastColor); |
167 |
) { |
167 |
|
168 |
|
168 |
for (int k=0; k < thickness; k++) { |
169 |
int thickness = getThickness(southBorderType); |
169 |
for (int yc=y;yc < height; yc=yc+2) { |
170 |
thickness++; |
170 |
g.drawLine(width-k,yc,width-k,yc); |
171 |
g.setColor(southColor); |
171 |
} |
172 |
for (int k=0; k < thickness; k++) { |
172 |
} |
173 |
for (int xc = x; xc < width; xc=xc+2) { |
173 |
} |
174 |
g.drawLine(xc,height-k,xc,height-k); |
174 |
|
175 |
} |
175 |
if (southBorder && |
176 |
} |
176 |
southBorderType == HSSFCellStyle.BORDER_DOTTED |
177 |
} |
177 |
) { |
178 |
|
178 |
|
179 |
if (westBorder && |
179 |
int thickness = getThickness(southBorderType); |
180 |
westBorderType == HSSFCellStyle.BORDER_DOTTED |
180 |
thickness++; |
181 |
) { |
181 |
g.setColor(southColor); |
182 |
|
182 |
for (int k=0; k < thickness; k++) { |
183 |
int thickness = getThickness(westBorderType); |
183 |
for (int xc = x; xc < width; xc=xc+2) { |
184 |
// thickness++; |
184 |
g.drawLine(xc,height-k,xc,height-k); |
185 |
|
185 |
} |
186 |
g.setColor(westColor); |
186 |
} |
187 |
|
187 |
} |
188 |
for (int k=0; k < thickness; k++) { |
188 |
|
189 |
for (int yc=y;yc < height; yc=yc+2) { |
189 |
if (westBorder && |
190 |
g.drawLine(x+k,yc,x+k,yc); |
190 |
westBorderType == HSSFCellStyle.BORDER_DOTTED |
191 |
} |
191 |
) { |
192 |
} |
192 |
|
193 |
} |
193 |
int thickness = getThickness(westBorderType); |
194 |
} |
194 |
// thickness++; |
195 |
|
195 |
|
196 |
|
196 |
g.setColor(westColor); |
197 |
private void paintDashedBorders(Graphics g, int x, int y, int width, |
197 |
|
198 |
int height) { |
198 |
for (int k=0; k < thickness; k++) { |
199 |
if (northBorder && |
199 |
for (int yc=y;yc < height; yc=yc+2) { |
200 |
((northBorderType == HSSFCellStyle.BORDER_DASHED) || |
200 |
g.drawLine(x+k,yc,x+k,yc); |
201 |
(northBorderType == HSSFCellStyle.BORDER_HAIR)) |
201 |
} |
202 |
) { |
202 |
} |
203 |
int thickness = getThickness(northBorderType); |
203 |
} |
204 |
|
204 |
} |
205 |
int dashlength = 1; |
205 |
|
206 |
|
206 |
|
207 |
if (northBorderType == HSSFCellStyle.BORDER_DASHED) |
207 |
private void paintDashedBorders(Graphics g, int x, int y, int width, |
208 |
dashlength = 2; |
208 |
int height) { |
209 |
|
209 |
if (northBorder && |
210 |
g.setColor(northColor); |
210 |
((northBorderType == HSSFCellStyle.BORDER_DASHED) || |
211 |
|
211 |
(northBorderType == HSSFCellStyle.BORDER_HAIR)) |
212 |
for (int k=0; k < thickness; k++) { |
212 |
) { |
213 |
for (int xc = x; xc < width; xc=xc+5) { |
213 |
int thickness = getThickness(northBorderType); |
214 |
g.drawLine(xc,y+k,xc+dashlength,y+k); |
214 |
|
215 |
} |
215 |
int dashlength = 1; |
216 |
} |
216 |
|
217 |
} |
217 |
if (northBorderType == HSSFCellStyle.BORDER_DASHED) |
218 |
|
218 |
dashlength = 2; |
219 |
if (eastBorder && |
219 |
|
220 |
((eastBorderType == HSSFCellStyle.BORDER_DASHED) || |
220 |
g.setColor(northColor); |
221 |
(eastBorderType == HSSFCellStyle.BORDER_HAIR)) |
221 |
|
222 |
) { |
222 |
for (int k=0; k < thickness; k++) { |
223 |
|
223 |
for (int xc = x; xc < width; xc=xc+5) { |
224 |
int thickness = getThickness(eastBorderType); |
224 |
g.drawLine(xc,y+k,xc+dashlength,y+k); |
225 |
thickness++; //need for dotted borders to show up east |
225 |
} |
226 |
|
226 |
} |
227 |
|
227 |
} |
228 |
int dashlength = 1; |
228 |
|
229 |
|
229 |
if (eastBorder && |
230 |
if (eastBorderType == HSSFCellStyle.BORDER_DASHED) |
230 |
((eastBorderType == HSSFCellStyle.BORDER_DASHED) || |
231 |
dashlength = 2; |
231 |
(eastBorderType == HSSFCellStyle.BORDER_HAIR)) |
232 |
|
232 |
) { |
233 |
g.setColor(eastColor); |
233 |
|
234 |
|
234 |
int thickness = getThickness(eastBorderType); |
235 |
for (int k=0; k < thickness; k++) { |
235 |
thickness++; //need for dotted borders to show up east |
236 |
for (int yc=y;yc < height; yc=yc+5) { |
236 |
|
237 |
g.drawLine(width-k,yc,width-k,yc+dashlength); |
237 |
|
238 |
} |
238 |
int dashlength = 1; |
239 |
} |
239 |
|
240 |
} |
240 |
if (eastBorderType == HSSFCellStyle.BORDER_DASHED) |
241 |
|
241 |
dashlength = 2; |
242 |
if (southBorder && |
242 |
|
243 |
((southBorderType == HSSFCellStyle.BORDER_DASHED) || |
243 |
g.setColor(eastColor); |
244 |
(southBorderType == HSSFCellStyle.BORDER_HAIR)) |
244 |
|
245 |
) { |
245 |
for (int k=0; k < thickness; k++) { |
246 |
|
246 |
for (int yc=y;yc < height; yc=yc+5) { |
247 |
int thickness = getThickness(southBorderType); |
247 |
g.drawLine(width-k,yc,width-k,yc+dashlength); |
248 |
thickness++; |
248 |
} |
249 |
|
249 |
} |
250 |
int dashlength = 1; |
250 |
} |
251 |
|
251 |
|
252 |
if (southBorderType == HSSFCellStyle.BORDER_DASHED) |
252 |
if (southBorder && |
253 |
dashlength = 2; |
253 |
((southBorderType == HSSFCellStyle.BORDER_DASHED) || |
254 |
|
254 |
(southBorderType == HSSFCellStyle.BORDER_HAIR)) |
255 |
g.setColor(southColor); |
255 |
) { |
256 |
for (int k=0; k < thickness; k++) { |
256 |
|
257 |
for (int xc = x; xc < width; xc=xc+5) { |
257 |
int thickness = getThickness(southBorderType); |
258 |
g.drawLine(xc,height-k,xc+dashlength,height-k); |
258 |
thickness++; |
259 |
} |
259 |
|
260 |
} |
260 |
int dashlength = 1; |
261 |
} |
261 |
|
262 |
|
262 |
if (southBorderType == HSSFCellStyle.BORDER_DASHED) |
263 |
if (westBorder && |
263 |
dashlength = 2; |
264 |
((westBorderType == HSSFCellStyle.BORDER_DASHED) || |
264 |
|
265 |
(westBorderType == HSSFCellStyle.BORDER_HAIR)) |
265 |
g.setColor(southColor); |
266 |
) { |
266 |
for (int k=0; k < thickness; k++) { |
267 |
|
267 |
for (int xc = x; xc < width; xc=xc+5) { |
268 |
int thickness = getThickness(westBorderType); |
268 |
g.drawLine(xc,height-k,xc+dashlength,height-k); |
269 |
// thickness++; |
269 |
} |
270 |
|
270 |
} |
271 |
int dashlength = 1; |
271 |
} |
272 |
|
272 |
|
273 |
if (westBorderType == HSSFCellStyle.BORDER_DASHED) |
273 |
if (westBorder && |
274 |
dashlength = 2; |
274 |
((westBorderType == HSSFCellStyle.BORDER_DASHED) || |
275 |
|
275 |
(westBorderType == HSSFCellStyle.BORDER_HAIR)) |
276 |
g.setColor(westColor); |
276 |
) { |
277 |
|
277 |
|
278 |
for (int k=0; k < thickness; k++) { |
278 |
int thickness = getThickness(westBorderType); |
279 |
for (int yc=y;yc < height; yc=yc+5) { |
279 |
// thickness++; |
280 |
g.drawLine(x+k,yc,x+k,yc+dashlength); |
280 |
|
281 |
} |
281 |
int dashlength = 1; |
282 |
} |
282 |
|
283 |
} |
283 |
if (westBorderType == HSSFCellStyle.BORDER_DASHED) |
284 |
} |
284 |
dashlength = 2; |
285 |
|
285 |
|
286 |
|
286 |
g.setColor(westColor); |
287 |
private void paintDoubleBorders(Graphics g, int x, int y, int width, |
287 |
|
288 |
int height) { |
288 |
for (int k=0; k < thickness; k++) { |
289 |
if (northBorder && |
289 |
for (int yc=y;yc < height; yc=yc+5) { |
290 |
northBorderType == HSSFCellStyle.BORDER_DOUBLE) { |
290 |
g.drawLine(x+k,yc,x+k,yc+dashlength); |
291 |
|
291 |
} |
292 |
g.setColor(northColor); |
292 |
} |
293 |
|
293 |
} |
294 |
int leftx=x; |
294 |
} |
295 |
int rightx=width; |
295 |
|
296 |
|
296 |
|
297 |
// if there are borders on the west or east then |
297 |
private void paintDoubleBorders(Graphics g, int x, int y, int width, |
298 |
// the second line shouldn't cross them |
298 |
int height) { |
299 |
if (westBorder) |
299 |
if (northBorder && |
300 |
leftx = x+3; |
300 |
northBorderType == HSSFCellStyle.BORDER_DOUBLE) { |
301 |
|
301 |
|
302 |
if (eastBorder) |
302 |
g.setColor(northColor); |
303 |
rightx = width-3; |
303 |
|
304 |
|
304 |
int leftx=x; |
305 |
g.drawLine(x,y,width,y); |
305 |
int rightx=width; |
306 |
g.drawLine(leftx,y+2,rightx,y+2); |
306 |
|
307 |
} |
307 |
// if there are borders on the west or east then |
308 |
|
308 |
// the second line shouldn't cross them |
309 |
if (eastBorder && |
309 |
if (westBorder) |
310 |
eastBorderType == HSSFCellStyle.BORDER_DOUBLE |
310 |
leftx = x+3; |
311 |
) { |
311 |
|
312 |
|
312 |
if (eastBorder) |
313 |
int thickness = getThickness(eastBorderType); |
313 |
rightx = width-3; |
314 |
thickness++; //need for dotted borders to show up east |
314 |
|
315 |
|
315 |
g.drawLine(x,y,width,y); |
316 |
g.setColor(eastColor); |
316 |
g.drawLine(leftx,y+2,rightx,y+2); |
317 |
|
317 |
} |
318 |
int topy=y; |
318 |
|
319 |
int bottomy=height; |
319 |
if (eastBorder && |
320 |
|
320 |
eastBorderType == HSSFCellStyle.BORDER_DOUBLE |
321 |
if (northBorder) |
321 |
) { |
322 |
topy=y+3; |
322 |
|
323 |
|
323 |
int thickness = getThickness(eastBorderType); |
324 |
if (southBorder) |
324 |
thickness++; //need for dotted borders to show up east |
325 |
bottomy=height-3; |
325 |
|
326 |
|
326 |
g.setColor(eastColor); |
327 |
g.drawLine(width-1,y,width-1,height); |
327 |
|
328 |
g.drawLine(width-3,topy,width-3,bottomy); |
328 |
int topy=y; |
329 |
} |
329 |
int bottomy=height; |
330 |
|
330 |
|
331 |
if (southBorder && |
331 |
if (northBorder) |
332 |
southBorderType == HSSFCellStyle.BORDER_DOUBLE |
332 |
topy=y+3; |
333 |
) { |
333 |
|
334 |
|
334 |
if (southBorder) |
335 |
g.setColor(southColor); |
335 |
bottomy=height-3; |
336 |
|
336 |
|
337 |
int leftx=y; |
337 |
g.drawLine(width-1,y,width-1,height); |
338 |
int rightx=width; |
338 |
g.drawLine(width-3,topy,width-3,bottomy); |
339 |
|
339 |
} |
340 |
if (westBorder) |
340 |
|
341 |
leftx=x+3; |
341 |
if (southBorder && |
342 |
|
342 |
southBorderType == HSSFCellStyle.BORDER_DOUBLE |
343 |
if (eastBorder) |
343 |
) { |
344 |
rightx=width-3; |
344 |
|
345 |
|
345 |
g.setColor(southColor); |
346 |
|
346 |
|
347 |
g.drawLine(x,height - 1,width,height - 1); |
347 |
int leftx=y; |
348 |
g.drawLine(leftx,height - 3,rightx,height - 3); |
348 |
int rightx=width; |
349 |
} |
349 |
|
350 |
|
350 |
if (westBorder) |
351 |
if (westBorder && |
351 |
leftx=x+3; |
352 |
westBorderType == HSSFCellStyle.BORDER_DOUBLE |
352 |
|
353 |
) { |
353 |
if (eastBorder) |
354 |
|
354 |
rightx=width-3; |
355 |
int thickness = getThickness(westBorderType); |
355 |
|
356 |
// thickness++; |
356 |
|
357 |
|
357 |
g.drawLine(x,height - 1,width,height - 1); |
358 |
g.setColor(westColor); |
358 |
g.drawLine(leftx,height - 3,rightx,height - 3); |
359 |
|
359 |
} |
360 |
int topy=y; |
360 |
|
361 |
int bottomy=height-3; |
361 |
if (westBorder && |
362 |
|
362 |
westBorderType == HSSFCellStyle.BORDER_DOUBLE |
363 |
if (northBorder) |
363 |
) { |
364 |
topy=y+2; |
364 |
|
365 |
|
365 |
int thickness = getThickness(westBorderType); |
366 |
if (southBorder) |
366 |
// thickness++; |
367 |
bottomy=height-3; |
367 |
|
368 |
|
368 |
g.setColor(westColor); |
369 |
g.drawLine(x,y,x,height); |
369 |
|
370 |
g.drawLine(x+2,topy,x+2,bottomy); |
370 |
int topy=y; |
371 |
} |
371 |
int bottomy=height-3; |
372 |
} |
372 |
|
373 |
|
373 |
if (northBorder) |
374 |
|
374 |
topy=y+2; |
375 |
private void paintDashDotDotBorders(Graphics g, int x, int y, int width, |
375 |
|
376 |
int height) { |
376 |
if (southBorder) |
377 |
if (northBorder && |
377 |
bottomy=height-3; |
378 |
((northBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
378 |
|
379 |
(northBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
379 |
g.drawLine(x,y,x,height); |
380 |
) { |
380 |
g.drawLine(x+2,topy,x+2,bottomy); |
381 |
int thickness = getThickness(northBorderType); |
381 |
} |
382 |
|
382 |
} |
383 |
g.setColor(northColor); |
383 |
|
384 |
for (int l=x; l < width;) { |
384 |
|
385 |
l=l+drawDashDotDot(g, l, y, thickness, true, true); |
385 |
private void paintDashDotDotBorders(Graphics g, int x, int y, int width, |
386 |
} |
386 |
int height) { |
387 |
|
387 |
if (northBorder && |
388 |
} |
388 |
((northBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
389 |
|
389 |
(northBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
390 |
if (eastBorder && |
390 |
) { |
391 |
((eastBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
391 |
int thickness = getThickness(northBorderType); |
392 |
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
392 |
|
393 |
) { |
393 |
g.setColor(northColor); |
394 |
|
394 |
for (int l=x; l < width;) { |
395 |
int thickness = getThickness(eastBorderType); |
395 |
l=l+drawDashDotDot(g, l, y, thickness, true, true); |
396 |
|
396 |
} |
397 |
g.setColor(eastColor); |
397 |
|
398 |
|
398 |
} |
399 |
for (int l=y;l < height;) { |
399 |
|
400 |
//System.err.println("drawing east"); |
400 |
if (eastBorder && |
401 |
l=l+drawDashDotDot(g,width-1,l,thickness,false,false); |
401 |
((eastBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
402 |
} |
402 |
(eastBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
403 |
} |
403 |
) { |
404 |
|
404 |
|
405 |
if (southBorder && |
405 |
int thickness = getThickness(eastBorderType); |
406 |
((southBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
406 |
|
407 |
(southBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
407 |
g.setColor(eastColor); |
408 |
) { |
408 |
|
409 |
|
409 |
for (int l=y;l < height;) { |
410 |
int thickness = getThickness(southBorderType); |
410 |
//System.err.println("drawing east"); |
411 |
|
411 |
l=l+drawDashDotDot(g,width-1,l,thickness,false,false); |
412 |
g.setColor(southColor); |
412 |
} |
413 |
|
413 |
} |
414 |
for (int l=x; l < width;) { |
414 |
|
415 |
//System.err.println("drawing south"); |
415 |
if (southBorder && |
416 |
l=l+drawDashDotDot(g, l, height-1, thickness, true, false); |
416 |
((southBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
417 |
} |
417 |
(southBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
418 |
} |
418 |
) { |
419 |
|
419 |
|
420 |
if (westBorder && |
420 |
int thickness = getThickness(southBorderType); |
421 |
((westBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
421 |
|
422 |
(westBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
422 |
g.setColor(southColor); |
423 |
) { |
423 |
|
424 |
|
424 |
for (int l=x; l < width;) { |
425 |
int thickness = getThickness(westBorderType); |
425 |
//System.err.println("drawing south"); |
426 |
|
426 |
l=l+drawDashDotDot(g, l, height-1, thickness, true, false); |
427 |
g.setColor(westColor); |
427 |
} |
428 |
|
428 |
} |
429 |
for (int l=y;l < height;) { |
429 |
|
430 |
//System.err.println("drawing west"); |
430 |
if (westBorder && |
431 |
l=l+drawDashDotDot(g,x,l,thickness,false,true); |
431 |
((westBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || |
432 |
} |
432 |
(westBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) |
433 |
|
433 |
) { |
434 |
} |
434 |
|
435 |
} |
435 |
int thickness = getThickness(westBorderType); |
436 |
|
436 |
|
437 |
/** |
437 |
g.setColor(westColor); |
438 |
* Draws one dash dot dot horizontally or vertically with thickness drawn |
438 |
|
439 |
* incrementally to either the right or left. |
439 |
for (int l=y;l < height;) { |
440 |
* |
440 |
//System.err.println("drawing west"); |
441 |
* @param g graphics object for drawing with |
441 |
l=l+drawDashDotDot(g,x,l,thickness,false,true); |
442 |
* @param x the x origin of the line |
442 |
} |
443 |
* @param y the y origin of the line |
443 |
|
444 |
* @param thickness the thickness of the line |
444 |
} |
445 |
* @param horizontal or vertical (true for horizontal) |
445 |
} |
446 |
* @param right/bottom or left/top thickness (true for right or top), |
446 |
|
447 |
* if true then the x or y origin will be incremented to provide |
447 |
/** |
448 |
* thickness, if false, they'll be decremented. For vertical |
448 |
* Draws one dash dot dot horizontally or vertically with thickness drawn |
449 |
* borders, x is incremented or decremented, for horizontal its y. |
449 |
* incrementally to either the right or left. |
450 |
* Just set to true for north and west, and false for east and |
450 |
* |
451 |
* south. |
451 |
* @param g graphics object for drawing with |
452 |
* @returns length - returns the length of the line. |
452 |
* @param x the x origin of the line |
453 |
*/ |
453 |
* @param y the y origin of the line |
454 |
private int drawDashDotDot(Graphics g,int x, int y, int thickness, |
454 |
* @param thickness the thickness of the line |
455 |
boolean horizontal, |
455 |
* @param horizontal or vertical (true for horizontal) |
456 |
boolean rightBottom) { |
456 |
* @param right/bottom or left/top thickness (true for right or top), |
457 |
|
457 |
* if true then the x or y origin will be incremented to provide |
458 |
for (int t=0; t < thickness; t++) { |
458 |
* thickness, if false, they'll be decremented. For vertical |
459 |
if (!rightBottom) { |
459 |
* borders, x is incremented or decremented, for horizontal its y. |
460 |
t = 0 - t; //add negative thickness so we go the other way |
460 |
* Just set to true for north and west, and false for east and |
461 |
//then we'll decrement instead of increment. |
461 |
* south. |
462 |
} |
462 |
* @returns length - returns the length of the line. |
463 |
if (horizontal) { |
463 |
*/ |
464 |
g.drawLine(x,y+t,x+5,y+t); |
464 |
private int drawDashDotDot(Graphics g,int x, int y, int thickness, |
465 |
g.drawLine(x+8,y+t,x+10,y+t); |
465 |
boolean horizontal, |
466 |
g.drawLine(x+13,y+t,x+15,y+t); |
466 |
boolean rightBottom) { |
467 |
} else { |
467 |
|
468 |
g.drawLine(x+t,y,x+t,y+5); |
468 |
for (int t=0; t < thickness; t++) { |
469 |
g.drawLine(x+t,y+8,x+t,y+10); |
469 |
if (!rightBottom) { |
470 |
g.drawLine(x+t,y+13,x+t,y+15); |
470 |
t = 0 - t; //add negative thickness so we go the other way |
471 |
} |
471 |
//then we'll decrement instead of increment. |
472 |
} |
472 |
} |
473 |
return 18; |
473 |
if (horizontal) { |
474 |
} |
474 |
g.drawLine(x,y+t,x+5,y+t); |
475 |
|
475 |
g.drawLine(x+8,y+t,x+10,y+t); |
476 |
private int getThickness(int thickness) { |
476 |
g.drawLine(x+13,y+t,x+15,y+t); |
477 |
int retval=1; |
477 |
} else { |
478 |
switch (thickness) { |
478 |
g.drawLine(x+t,y,x+t,y+5); |
479 |
case HSSFCellStyle.BORDER_THIN: |
479 |
g.drawLine(x+t,y+8,x+t,y+10); |
480 |
retval=2; |
480 |
g.drawLine(x+t,y+13,x+t,y+15); |
481 |
break; |
481 |
} |
482 |
case HSSFCellStyle.BORDER_MEDIUM: |
482 |
} |
483 |
retval=3; |
483 |
return 18; |
484 |
break; |
484 |
} |
485 |
case HSSFCellStyle.BORDER_THICK: |
485 |
|
486 |
retval=4; |
486 |
private int getThickness(int thickness) { |
487 |
break; |
487 |
int retval=1; |
488 |
case HSSFCellStyle.BORDER_DASHED: |
488 |
switch (thickness) { |
489 |
retval=1; |
489 |
case HSSFCellStyle.BORDER_THIN: |
490 |
break; |
490 |
retval=2; |
491 |
case HSSFCellStyle.BORDER_DASH_DOT_DOT: |
491 |
break; |
492 |
retval=1; |
492 |
case HSSFCellStyle.BORDER_MEDIUM: |
493 |
break; |
493 |
retval=3; |
494 |
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: |
494 |
break; |
495 |
retval=3; |
495 |
case HSSFCellStyle.BORDER_THICK: |
496 |
break; |
496 |
retval=4; |
497 |
case HSSFCellStyle.BORDER_HAIR: |
497 |
break; |
498 |
retval=1; |
498 |
case HSSFCellStyle.BORDER_DASHED: |
499 |
break; |
499 |
retval=1; |
500 |
default: |
500 |
break; |
501 |
retval=1; |
501 |
case HSSFCellStyle.BORDER_DASH_DOT_DOT: |
502 |
} |
502 |
retval=1; |
503 |
return retval; |
503 |
break; |
504 |
} |
504 |
case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: |
505 |
|
505 |
retval=3; |
506 |
|
506 |
break; |
507 |
} |
507 |
case HSSFCellStyle.BORDER_HAIR: |
508 |
-- |
508 |
retval=1; |
|
|
509 |
break; |
510 |
default: |
511 |
retval=1; |
512 |
} |
513 |
return retval; |
514 |
} |
515 |
|
516 |
|
517 |
} |