View | Details | Raw Unified | Return to bug 10581
Collapse All | Expand All

(-)view/SVBorder.java (-508 / +517 lines)
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
}
(-)view/SVTableCellRenderer.java (-107 / +163 lines)
Line 70 Link Here
70
import java.text.*;
Lines 71-76 Link Here
71
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
72
import org.apache.poi.hssf.usermodel.*;
72
import org.apache.poi.hssf.usermodel.HSSFSheet;
73
import org.apache.poi.hssf.usermodel.HSSFRow;
74
import org.apache.poi.hssf.usermodel.HSSFCell;
75
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
76
import org.apache.poi.hssf.usermodel.HSSFFont;
77
--
Line 78 Link Here
78
import org.apache.poi.hssf.util.HSSFColor.WHITE;
74
79
--
Line 90 Link Here
86
  private static final Color black = getAWTColor(new HSSFColor.BLACK());
87
  private static final Color white = getAWTColor(new HSSFColor.WHITE());
88
Line 91 Link Here
90
    protected SVBorder cellBorder = new SVBorder();
91
92
Line 94 Link Here
96
/*    private class CellFormatter {
97
      private Format[] textFormatters;
98
      private Color[] negativeColour;
99
100
      public CellFormatter() {
101
        textFormatters = new Format[0x31];
102
        negativeColour = new Color[0x31];
103
        for (int i=0;i<negativeColour.length;i++)
104
          negativeColour = Color.BLACK;
105
106
        textFormatter[0x01] = new DecimalFormat("0");
107
        textFormatter[0x02] = new DecimalFormat("0.00");
108
        textFormatter[0x03] = new DecimalFormat("#,##0");
109
        textFormatter[0x04] = new DecimalFormat("#,##0.00");
110
        textFormatter[0x05] = new DecimalFormat("($#,##0_);($#,##0)");
111
        textFormatter[0x06] = new DecimalFormat("($#,##0_);[Red]($#,##0)");
112
        textFormatter[0x07] = new DecimalFormat("($#,##0.00);($#,##0.00)");
113
        textFormatter[0x08] = new DecimalFormat("($#,##0.00_);[Red]($#,##0.00)");
114
        textFormatter[0x09] = new DecimalFormat("0%");
115
        textFormatter[0x0A] = new DecimalFormat("0.00%");
116
        textFormatter[0x0B] = new DecimalFormat("0.00E+00");
117
        textFormatter[0x0C] = new SimpleDateFormat("# ?/?");
118
        textFormatter[0x0D] = new SimpleDateFormat("# ??/??");
119
        textFormatter[0x0E] = new SimpleDateFormat("m/d/yy");
120
        textFormatter[0x0F] = new SimpleDateFormat("d-mmm-yy");
121
        textFormatter[0x10] = new SimpleDateFormat("d-mmm");
122
        textFormatter[0x11] = new SimpleDateFormat("mmm-yy");
123
        textFormatter[0x12] = new SimpleDateFormat("h:mm AM/PM");
124
        textFormatter[0x13] = new SimpleDateFormat("h:mm:ss AM/PM");
125
        textFormatter[0x14] = new SimpleDateFormat("h:mm");
126
        textFormatter[0x15] = new SimpleDateFormat("h:mm:ss");
127
        textFormatter[0x16] = new SimpleDateFormat("m/d/yy h:mm");
128
        // 0x17 - 0x24 reserved for international and undocumented 0x25, "(#,##0_);(#,##0)"
129
        //start at 0x26
130
        textFormatter[0x26] = new DecimalFormat("(#,##0_);[Red](#,##0)");
131
        textFormatter[0x27] = new DecimalFormat("(#,##0.00_);(#,##0.00)");
132
        textFormatter[00x28] = new DecimalFormat("(#,##0.00_);[Red](#,##0.00)");
133
        textFormatter[0x29] = new DecimalFormat("_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)");
134
        textFormatter[0x2A] = new DecimalFormat("_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)");
135
        textFormatter[0x2B] = new DecimalFormat("_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)");
136
        textFormatter[0x2C] = new DecimalFormat("_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)");
137
        textFormatter[0x2D] = new SimpleDateFormat("mm:ss");
138
        textFormatter[0x2E] = new SimpleDateFormat("[h]:mm:ss");
139
        textFormatter[0x2F] = new SimpleDateFormat("mm:ss.0");
140
        textFormatter[0x30] = new DecimalFormat("##0.0E+0");
141
      }
142
143
      public String format(short index, Object value) {
144
145
      }
146
147
      public String format(short index, double value) {
148
149
      }
150
    }
151
152
    private static final CellFormatter cellFormatter = new CellFormatter();
153
*/
154
Lines 105-109 Link Here
105
	if (isSelected) {
106
	   setForeground(table.getSelectionForeground());
107
	   setBackground(table.getSelectionBackground());
108
	}
109
Line 115 Link Here
115
Lines 131-132 Link Here
131
          
186
132
          HSSFColor clr = null;
133
--
Lines 134-152 Link Here
134
            clr = (HSSFColor)colors.get(new Integer(s.getFillForegroundColor()));
188
            setBackground(getAWTColor(s.getFillForegroundColor(), white));
135
          }
189
          } else setBackground(white);
136
          if (clr == null) clr = new HSSFColor.WHITE();
190
137
191
          setForeground(getAWTColor(f.getColor(), black));
138
          short[] rgb = clr.getTriplet();
192
139
          Color awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
193
          cellBorder.setBorder(getAWTColor(s.getTopBorderColor(), black),
140
194
                               getAWTColor(s.getRightBorderColor(), black),
141
          setBackground(awtcolor);
195
                               getAWTColor(s.getBottomBorderColor(), black),
142
196
                               getAWTColor(s.getLeftBorderColor(), black),
143
          clr = (HSSFColor)colors.get(new Integer(f.getColor()));
197
                               s.getBorderTop(), s.getBorderRight(),
144
          if (clr == null) clr = new HSSFColor.BLACK();
198
                               s.getBorderBottom(), s.getBorderLeft(),
145
          rgb = clr.getTriplet();
199
                               hasFocus);
146
          awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
200
            setBorder(cellBorder);
147
          setForeground(awtcolor);
201
            isBorderSet=true;
148
202
149
/*          if (s.getBorderBottom() != HSSFCellStyle.BORDER_NONE ||
203
            //Set the value that is rendered for the cell
150
              s.getBorderTop()    != HSSFCellStyle.BORDER_NONE ||
204
            switch (c.getCellType()) {
151
              s.getBorderLeft()   != HSSFCellStyle.BORDER_NONE ||
205
              case HSSFCell.CELL_TYPE_BLANK:
152
              s.getBorderRight()  != HSSFCellStyle.BORDER_NONE) {
206
                setValue("");
153
--
207
              break;
208
              case HSSFCell.CELL_TYPE_BOOLEAN:
209
                if (c.getBooleanCellValue()) {
210
                  setValue("true");
211
                } else {
212
                  setValue("false");
213
                }
214
              break;
215
              case HSSFCell.CELL_TYPE_FORMULA:
216
              case HSSFCell.CELL_TYPE_NUMERIC:
217
                setValue(Double.toString(c.getNumericCellValue()));
218
/*                  short format = s.getDataFormat();
219
                if (format == 40) {
220
                  String formatStr = HSSFDataFormat.getFormat(format);
221
                  System.out.println("Format Str="+formatStr);
222
                  java.text.DecimalFormat frm = new java.text.DecimalFormat(formatStr);
223
                  System.out.println("Formatted value = "+frm.format(c.getNumericCellValue()));
224
                }
Lines 154-217 Link Here
154
              int borderTop = s.getBorderTop();
226
              break;
155
              int borderRight = s.getBorderRight();
227
              case HSSFCell.CELL_TYPE_STRING:
156
              int borderBottom = s.getBorderBottom();
228
                setValue(c.getStringCellValue());
157
              int borderLeft = s.getBorderLeft();
229
              break;
158
              
230
              default:
159
              //OUCH! This could causing rendering performance problems.
231
                setValue("?");
160
              //Need to somehow create once and store
232
            }
161
              SVBorder border = new SVBorder(Color.black, Color.black,
233
            //Set the text alignment of the cell
162
                                           Color.black, Color.black,
234
            switch (s.getAlignment()) {
163
                                           borderTop, borderRight,
235
              case HSSFCellStyle.ALIGN_GENERAL:
164
                                           borderBottom, borderLeft,
236
              case HSSFCellStyle.ALIGN_LEFT:
165
                                           s.getBorderTop() != HSSFCellStyle.BORDER_NONE,
237
              case HSSFCellStyle.ALIGN_JUSTIFY:
166
                                           s.getBorderRight() != HSSFCellStyle.BORDER_NONE,
238
              case HSSFCellStyle.ALIGN_FILL:
167
                                           s.getBorderBottom() != HSSFCellStyle.BORDER_NONE,
239
                setHorizontalAlignment(SwingConstants.LEFT);
168
                                           s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
240
                break;
169
              setBorder(border);
241
              case HSSFCellStyle.ALIGN_CENTER:
170
              isBorderSet=true;
242
              case HSSFCellStyle.ALIGN_CENTER_SELECTION:
171
243
                setHorizontalAlignment(SwingConstants.CENTER);
172
              //Set the value that is rendered for the cell
244
                break;
173
          switch (c.getCellType()) {
245
              case HSSFCellStyle.ALIGN_RIGHT:
174
            case HSSFCell.CELL_TYPE_BLANK:
246
                setHorizontalAlignment(SwingConstants.RIGHT);
175
              setValue("");
247
                break;
176
            break;
248
              default:
177
            case HSSFCell.CELL_TYPE_BOOLEAN:
249
                setHorizontalAlignment(SwingConstants.LEFT);
178
              if (c.getBooleanCellValue()) {
250
                break;
179
                setValue("true");
251
            }
180
              } else {
252
        } else {
181
                setValue("false");
253
          setValue("");
182
              }
254
          setBackground(white);
183
            break;
255
        }
184
            case HSSFCell.CELL_TYPE_FORMULA:
185
            case HSSFCell.CELL_TYPE_NUMERIC:
186
              setValue(""+c.getNumericCellValue());
187
            break;
188
            case HSSFCell.CELL_TYPE_STRING:
189
              setValue(c.getStringCellValue());
190
            break;
191
            default:
192
              setValue("?");
193
          }
194
              //Set the text alignment of the cell
195
              switch (s.getAlignment()) {
196
                case HSSFCellStyle.ALIGN_GENERAL:
197
                case HSSFCellStyle.ALIGN_LEFT:
198
                case HSSFCellStyle.ALIGN_JUSTIFY:
199
                case HSSFCellStyle.ALIGN_FILL:
200
                  setHorizontalAlignment(SwingConstants.LEFT);
201
                  break;
202
                case HSSFCellStyle.ALIGN_CENTER:
203
                case HSSFCellStyle.ALIGN_CENTER_SELECTION:
204
                  setHorizontalAlignment(SwingConstants.CENTER);
205
                  break;
206
                case HSSFCellStyle.ALIGN_RIGHT:
207
                  setHorizontalAlignment(SwingConstants.RIGHT);
208
                  break;
209
                default:
210
                  setHorizontalAlignment(SwingConstants.LEFT);
211
                  break;
212
              }
213
//          }
214
       } else {
215
           setValue("");
216
          setBackground(Color.white);
217
       }
218
--
Line 222 Link Here
222
	        setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
260
              cellBorder.setBorder(black,
223
--
261
                                   black,
262
                                   black,
263
                                   black,
264
                                   HSSFCellStyle.BORDER_NONE,
265
                                   HSSFCellStyle.BORDER_NONE,
266
                                   HSSFCellStyle.BORDER_NONE,
267
                                   HSSFCellStyle.BORDER_NONE,
268
                                   isSelected);
269
              setBorder(cellBorder);
Line 227 Link Here
274
            System.out.println("PING!");
Line 237 Link Here
237
Line 241 Link Here
241
Line 266 Link Here
312
313
    /** This method retrieves the AWT Color representation from the colour hash table
314
     *
315
     */
316
    private final Color getAWTColor(int index, Color deflt) {
317
      HSSFColor clr = (HSSFColor)colors.get(new Integer(index));
318
      if (clr == null) return deflt;
319
      return getAWTColor(clr);
320
    }
321
322
    private static final Color getAWTColor(HSSFColor clr) {
323
      short[] rgb = clr.getTriplet();
324
      return new Color(rgb[0],rgb[1],rgb[2]);
325
    }
326
327

Return to bug 10581