Source Code Cross Referenced for HSSFCellStyle.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » usermodel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.usermodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:           Licensed to the Apache Software Foundation (ASF) under one or more
003:           contributor license agreements.  See the NOTICE file distributed with
004:           this work for additional information regarding copyright ownership.
005:           The ASF licenses this file to You under the Apache License, Version 2.0
006:           (the "License"); you may not use this file except in compliance with
007:           the License.  You may obtain a copy of the License at
008:
009:               http://www.apache.org/licenses/LICENSE-2.0
010:
011:           Unless required by applicable law or agreed to in writing, software
012:           distributed under the License is distributed on an "AS IS" BASIS,
013:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:           See the License for the specific language governing permissions and
015:           limitations under the License.
016:        ==================================================================== */
017:
018:        package org.apache.poi.hssf.usermodel;
019:
020:        import org.apache.poi.hssf.model.Workbook;
021:        import org.apache.poi.hssf.record.ExtendedFormatRecord;
022:        import org.apache.poi.hssf.record.FormatRecord;
023:        import org.apache.poi.hssf.util.*;
024:
025:        /**
026:         * High level representation of the style of a cell in a sheet of a workbook.
027:         *
028:         * @version 1.0-pre
029:         *
030:         * @author  Andrew C. Oliver (acoliver at apache dot org)
031:         * @author Jason Height (jheight at chariot dot net dot au)
032:         * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle()
033:         * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(short)
034:         * @see org.apache.poi.hssf.usermodel.HSSFCell#setCellStyle(HSSFCellStyle)
035:         */
036:
037:        public class HSSFCellStyle {
038:            private ExtendedFormatRecord format = null;
039:            private short index = 0;
040:
041:            /**
042:             * general (normal) horizontal alignment
043:             */
044:
045:            public final static short ALIGN_GENERAL = 0x0;
046:
047:            /**
048:             * left-justified horizontal alignment
049:             */
050:
051:            public final static short ALIGN_LEFT = 0x1;
052:
053:            /**
054:             * center horizontal alignment
055:             */
056:
057:            public final static short ALIGN_CENTER = 0x2;
058:
059:            /**
060:             * right-justified horizontal alignment
061:             */
062:
063:            public final static short ALIGN_RIGHT = 0x3;
064:
065:            /**
066:             * fill? horizontal alignment
067:             */
068:
069:            public final static short ALIGN_FILL = 0x4;
070:
071:            /**
072:             * justified horizontal alignment
073:             */
074:
075:            public final static short ALIGN_JUSTIFY = 0x5;
076:
077:            /**
078:             * center-selection? horizontal alignment
079:             */
080:
081:            public final static short ALIGN_CENTER_SELECTION = 0x6;
082:
083:            /**
084:             * top-aligned vertical alignment
085:             */
086:
087:            public final static short VERTICAL_TOP = 0x0;
088:
089:            /**
090:             * center-aligned vertical alignment
091:             */
092:
093:            public final static short VERTICAL_CENTER = 0x1;
094:
095:            /**
096:             * bottom-aligned vertical alignment
097:             */
098:
099:            public final static short VERTICAL_BOTTOM = 0x2;
100:
101:            /**
102:             * vertically justified vertical alignment
103:             */
104:
105:            public final static short VERTICAL_JUSTIFY = 0x3;
106:
107:            /**
108:             * No border
109:             */
110:
111:            public final static short BORDER_NONE = 0x0;
112:
113:            /**
114:             * Thin border
115:             */
116:
117:            public final static short BORDER_THIN = 0x1;
118:
119:            /**
120:             * Medium border
121:             */
122:
123:            public final static short BORDER_MEDIUM = 0x2;
124:
125:            /**
126:             * dash border
127:             */
128:
129:            public final static short BORDER_DASHED = 0x3;
130:
131:            /**
132:             * dot border
133:             */
134:
135:            public final static short BORDER_HAIR = 0x4;
136:
137:            /**
138:             * Thick border
139:             */
140:
141:            public final static short BORDER_THICK = 0x5;
142:
143:            /**
144:             * double-line border
145:             */
146:
147:            public final static short BORDER_DOUBLE = 0x6;
148:
149:            /**
150:             * hair-line border
151:             */
152:
153:            public final static short BORDER_DOTTED = 0x7;
154:
155:            /**
156:             * Medium dashed border
157:             */
158:
159:            public final static short BORDER_MEDIUM_DASHED = 0x8;
160:
161:            /**
162:             * dash-dot border
163:             */
164:
165:            public final static short BORDER_DASH_DOT = 0x9;
166:
167:            /**
168:             * medium dash-dot border
169:             */
170:
171:            public final static short BORDER_MEDIUM_DASH_DOT = 0xA;
172:
173:            /**
174:             * dash-dot-dot border
175:             */
176:
177:            public final static short BORDER_DASH_DOT_DOT = 0xB;
178:
179:            /**
180:             * medium dash-dot-dot border
181:             */
182:
183:            public final static short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
184:
185:            /**
186:             * slanted dash-dot border
187:             */
188:
189:            public final static short BORDER_SLANTED_DASH_DOT = 0xD;
190:
191:            /**  No background */
192:            public final static short NO_FILL = 0;
193:            /**  Solidly filled */
194:            public final static short SOLID_FOREGROUND = 1;
195:            /**  Small fine dots */
196:            public final static short FINE_DOTS = 2;
197:            /**  Wide dots */
198:            public final static short ALT_BARS = 3;
199:            /**  Sparse dots */
200:            public final static short SPARSE_DOTS = 4;
201:            /**  Thick horizontal bands */
202:            public final static short THICK_HORZ_BANDS = 5;
203:            /**  Thick vertical bands */
204:            public final static short THICK_VERT_BANDS = 6;
205:            /**  Thick backward facing diagonals */
206:            public final static short THICK_BACKWARD_DIAG = 7;
207:            /**  Thick forward facing diagonals */
208:            public final static short THICK_FORWARD_DIAG = 8;
209:            /**  Large spots */
210:            public final static short BIG_SPOTS = 9;
211:            /**  Brick-like layout */
212:            public final static short BRICKS = 10;
213:            /**  Thin horizontal bands */
214:            public final static short THIN_HORZ_BANDS = 11;
215:            /**  Thin vertical bands */
216:            public final static short THIN_VERT_BANDS = 12;
217:            /**  Thin backward diagonal */
218:            public final static short THIN_BACKWARD_DIAG = 13;
219:            /**  Thin forward diagonal */
220:            public final static short THIN_FORWARD_DIAG = 14;
221:            /**  Squares */
222:            public final static short SQUARES = 15;
223:            /**  Diamonds */
224:            public final static short DIAMONDS = 16;
225:            /**  Less Dots */
226:            public final static short LESS_DOTS = 17;
227:            /**  Least Dots */
228:            public final static short LEAST_DOTS = 18;
229:
230:            /** Creates new HSSFCellStyle why would you want to do this?? */
231:
232:            protected HSSFCellStyle(short index, ExtendedFormatRecord rec) {
233:                this .index = index;
234:                format = rec;
235:            }
236:
237:            /**
238:             * get the index within the HSSFWorkbook (sequence within the collection of ExtnededFormat objects)
239:             * @return unique index number of the underlying record this style represents (probably you don't care
240:             *  unless you're comparing which one is which)
241:             */
242:
243:            public short getIndex() {
244:                return index;
245:            }
246:
247:            /**
248:             * set the data format (must be a valid format)
249:             * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
250:             */
251:
252:            public void setDataFormat(short fmt) {
253:                format.setFormatIndex(fmt);
254:            }
255:
256:            /**
257:             * get the index of the format
258:             * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
259:             */
260:
261:            public short getDataFormat() {
262:                return format.getFormatIndex();
263:            }
264:
265:            /**
266:             * Get the contents of the format string, by looking up
267:             *  the DataFormat against the supplied workbook
268:             * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
269:             */
270:            public String getDataFormatString(Workbook workbook) {
271:                HSSFDataFormat format = new HSSFDataFormat(workbook);
272:
273:                return format.getFormat(getDataFormat());
274:            }
275:
276:            /**
277:             * set the font for this style
278:             * @param font  a font object created or retreived from the HSSFWorkbook object
279:             * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
280:             * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
281:             */
282:
283:            public void setFont(HSSFFont font) {
284:                format.setIndentNotParentFont(true);
285:                short fontindex = font.getIndex();
286:                format.setFontIndex(fontindex);
287:            }
288:
289:            /**
290:             * gets the index of the font for this style
291:             * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
292:             */
293:            public short getFontIndex() {
294:                return format.getFontIndex();
295:            }
296:
297:            /**
298:             * gets the font for this style
299:             * @param parentWorkbook The HSSFWorkbook that this style belongs to
300:             * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIndex()
301:             * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
302:             */
303:            public HSSFFont getFont(HSSFWorkbook parentWorkbook) {
304:                return parentWorkbook.getFontAt(getFontIndex());
305:            }
306:
307:            /**
308:             * set the cell's using this style to be hidden
309:             * @param hidden - whether the cell using this style should be hidden
310:             */
311:
312:            public void setHidden(boolean hidden) {
313:                format.setIndentNotParentCellOptions(true);
314:                format.setHidden(hidden);
315:            }
316:
317:            /**
318:             * get whether the cell's using this style are to be hidden
319:             * @return hidden - whether the cell using this style should be hidden
320:             */
321:
322:            public boolean getHidden() {
323:                return format.isHidden();
324:            }
325:
326:            /**
327:             * set the cell's using this style to be locked
328:             * @param locked - whether the cell using this style should be locked
329:             */
330:
331:            public void setLocked(boolean locked) {
332:                format.setIndentNotParentCellOptions(true);
333:                format.setLocked(locked);
334:            }
335:
336:            /**
337:             * get whether the cell's using this style are to be locked
338:             * @return hidden - whether the cell using this style should be locked
339:             */
340:
341:            public boolean getLocked() {
342:                return format.isLocked();
343:            }
344:
345:            /**
346:             * set the type of horizontal alignment for the cell
347:             * @param align - the type of alignment
348:             * @see #ALIGN_GENERAL
349:             * @see #ALIGN_LEFT
350:             * @see #ALIGN_CENTER
351:             * @see #ALIGN_RIGHT
352:             * @see #ALIGN_FILL
353:             * @see #ALIGN_JUSTIFY
354:             * @see #ALIGN_CENTER_SELECTION
355:             */
356:
357:            public void setAlignment(short align) {
358:                format.setIndentNotParentAlignment(true);
359:                format.setAlignment(align);
360:            }
361:
362:            /**
363:             * get the type of horizontal alignment for the cell
364:             * @return align - the type of alignment
365:             * @see #ALIGN_GENERAL
366:             * @see #ALIGN_LEFT
367:             * @see #ALIGN_CENTER
368:             * @see #ALIGN_RIGHT
369:             * @see #ALIGN_FILL
370:             * @see #ALIGN_JUSTIFY
371:             * @see #ALIGN_CENTER_SELECTION
372:             */
373:
374:            public short getAlignment() {
375:                return format.getAlignment();
376:            }
377:
378:            /**
379:             * get whether this cell is to be part of a merged block of cells
380:             *
381:             * @returns merged or not
382:             */
383:
384:            //    public boolean getMergeCells()
385:            //    {
386:            //        return format.getMergeCells();
387:            //    }
388:            /**
389:             * set whether this cell is to be part of a merged block of cells
390:             *
391:             * @param merge  merged or not
392:             */
393:
394:            //    public void setMergeCells(boolean merge)
395:            //    {
396:            //        format.setMergeCells(merge);
397:            //    }
398:            /**
399:             * set whether the text should be wrapped
400:             * @param wrapped  wrap text or not
401:             */
402:
403:            public void setWrapText(boolean wrapped) {
404:                format.setIndentNotParentAlignment(true);
405:                format.setWrapText(wrapped);
406:            }
407:
408:            /**
409:             * get whether the text should be wrapped
410:             * @return wrap text or not
411:             */
412:
413:            public boolean getWrapText() {
414:                return format.getWrapText();
415:            }
416:
417:            /**
418:             * set the type of vertical alignment for the cell
419:             * @param align the type of alignment
420:             * @see #VERTICAL_TOP
421:             * @see #VERTICAL_CENTER
422:             * @see #VERTICAL_BOTTOM
423:             * @see #VERTICAL_JUSTIFY
424:             */
425:
426:            public void setVerticalAlignment(short align) {
427:                format.setVerticalAlignment(align);
428:            }
429:
430:            /**
431:             * get the type of vertical alignment for the cell
432:             * @return align the type of alignment
433:             * @see #VERTICAL_TOP
434:             * @see #VERTICAL_CENTER
435:             * @see #VERTICAL_BOTTOM
436:             * @see #VERTICAL_JUSTIFY
437:             */
438:
439:            public short getVerticalAlignment() {
440:                return format.getVerticalAlignment();
441:            }
442:
443:            /**
444:             * set the degree of rotation for the text in the cell
445:             * @param rotation degrees (between -90 and 90 degrees)
446:             */
447:
448:            public void setRotation(short rotation) {
449:                if ((rotation < 0) && (rotation >= -90)) {
450:                    //Take care of the funny 4th quadrant issue
451:                    //The 4th quadrant (-1 to -90) is stored as (91 to 180)
452:                    rotation = (short) (90 - rotation);
453:                } else if ((rotation < -90) || (rotation > 90))
454:                    //Do not allow an incorrect rotation to be set
455:                    throw new IllegalArgumentException(
456:                            "The rotation must be between -90 and 90 degrees");
457:                format.setRotation(rotation);
458:            }
459:
460:            /**
461:             * get the degree of rotation for the text in the cell
462:             * @return rotation degrees (between -90 and 90 degrees)
463:             */
464:
465:            public short getRotation() {
466:                short rotation = format.getRotation();
467:                if (rotation > 90)
468:                    //This is actually the 4th quadrant
469:                    rotation = (short) (90 - rotation);
470:                return rotation;
471:            }
472:
473:            /**
474:             * set the number of spaces to indent the text in the cell
475:             * @param indent - number of spaces
476:             */
477:
478:            public void setIndention(short indent) {
479:                format.setIndent(indent);
480:            }
481:
482:            /**
483:             * get the number of spaces to indent the text in the cell
484:             * @return indent - number of spaces
485:             */
486:
487:            public short getIndention() {
488:                return format.getIndent();
489:            }
490:
491:            /**
492:             * set the type of border to use for the left border of the cell
493:             * @param border type
494:             * @see #BORDER_NONE
495:             * @see #BORDER_THIN
496:             * @see #BORDER_MEDIUM
497:             * @see #BORDER_DASHED
498:             * @see #BORDER_DOTTED
499:             * @see #BORDER_THICK
500:             * @see #BORDER_DOUBLE
501:             * @see #BORDER_HAIR
502:             * @see #BORDER_MEDIUM_DASHED
503:             * @see #BORDER_DASH_DOT
504:             * @see #BORDER_MEDIUM_DASH_DOT
505:             * @see #BORDER_DASH_DOT_DOT
506:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
507:             * @see #BORDER_SLANTED_DASH_DOT
508:             */
509:
510:            public void setBorderLeft(short border) {
511:                format.setIndentNotParentBorder(true);
512:                format.setBorderLeft(border);
513:            }
514:
515:            /**
516:             * get the type of border to use for the left border of the cell
517:             * @return border type
518:             * @see #BORDER_NONE
519:             * @see #BORDER_THIN
520:             * @see #BORDER_MEDIUM
521:             * @see #BORDER_DASHED
522:             * @see #BORDER_DOTTED
523:             * @see #BORDER_THICK
524:             * @see #BORDER_DOUBLE
525:             * @see #BORDER_HAIR
526:             * @see #BORDER_MEDIUM_DASHED
527:             * @see #BORDER_DASH_DOT
528:             * @see #BORDER_MEDIUM_DASH_DOT
529:             * @see #BORDER_DASH_DOT_DOT
530:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
531:             * @see #BORDER_SLANTED_DASH_DOT
532:             */
533:
534:            public short getBorderLeft() {
535:                return format.getBorderLeft();
536:            }
537:
538:            /**
539:             * set the type of border to use for the right border of the cell
540:             * @param border type
541:             * @see #BORDER_NONE
542:             * @see #BORDER_THIN
543:             * @see #BORDER_MEDIUM
544:             * @see #BORDER_DASHED
545:             * @see #BORDER_DOTTED
546:             * @see #BORDER_THICK
547:             * @see #BORDER_DOUBLE
548:             * @see #BORDER_HAIR
549:             * @see #BORDER_MEDIUM_DASHED
550:             * @see #BORDER_DASH_DOT
551:             * @see #BORDER_MEDIUM_DASH_DOT
552:             * @see #BORDER_DASH_DOT_DOT
553:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
554:             * @see #BORDER_SLANTED_DASH_DOT
555:             */
556:
557:            public void setBorderRight(short border) {
558:                format.setIndentNotParentBorder(true);
559:                format.setBorderRight(border);
560:            }
561:
562:            /**
563:             * get the type of border to use for the right border of the cell
564:             * @return border type
565:             * @see #BORDER_NONE
566:             * @see #BORDER_THIN
567:             * @see #BORDER_MEDIUM
568:             * @see #BORDER_DASHED
569:             * @see #BORDER_DOTTED
570:             * @see #BORDER_THICK
571:             * @see #BORDER_DOUBLE
572:             * @see #BORDER_HAIR
573:             * @see #BORDER_MEDIUM_DASHED
574:             * @see #BORDER_DASH_DOT
575:             * @see #BORDER_MEDIUM_DASH_DOT
576:             * @see #BORDER_DASH_DOT_DOT
577:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
578:             * @see #BORDER_SLANTED_DASH_DOT
579:             */
580:
581:            public short getBorderRight() {
582:                return format.getBorderRight();
583:            }
584:
585:            /**
586:             * set the type of border to use for the top border of the cell
587:             * @param border type
588:             * @see #BORDER_NONE
589:             * @see #BORDER_THIN
590:             * @see #BORDER_MEDIUM
591:             * @see #BORDER_DASHED
592:             * @see #BORDER_DOTTED
593:             * @see #BORDER_THICK
594:             * @see #BORDER_DOUBLE
595:             * @see #BORDER_HAIR
596:             * @see #BORDER_MEDIUM_DASHED
597:             * @see #BORDER_DASH_DOT
598:             * @see #BORDER_MEDIUM_DASH_DOT
599:             * @see #BORDER_DASH_DOT_DOT
600:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
601:             * @see #BORDER_SLANTED_DASH_DOT
602:             */
603:
604:            public void setBorderTop(short border) {
605:                format.setIndentNotParentBorder(true);
606:                format.setBorderTop(border);
607:            }
608:
609:            /**
610:             * get the type of border to use for the top border of the cell
611:             * @return border type
612:             * @see #BORDER_NONE
613:             * @see #BORDER_THIN
614:             * @see #BORDER_MEDIUM
615:             * @see #BORDER_DASHED
616:             * @see #BORDER_DOTTED
617:             * @see #BORDER_THICK
618:             * @see #BORDER_DOUBLE
619:             * @see #BORDER_HAIR
620:             * @see #BORDER_MEDIUM_DASHED
621:             * @see #BORDER_DASH_DOT
622:             * @see #BORDER_MEDIUM_DASH_DOT
623:             * @see #BORDER_DASH_DOT_DOT
624:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
625:             * @see #BORDER_SLANTED_DASH_DOT
626:             */
627:
628:            public short getBorderTop() {
629:                return format.getBorderTop();
630:            }
631:
632:            /**
633:             * set the type of border to use for the bottom border of the cell
634:             * @param border type
635:             * @see #BORDER_NONE
636:             * @see #BORDER_THIN
637:             * @see #BORDER_MEDIUM
638:             * @see #BORDER_DASHED
639:             * @see #BORDER_DOTTED
640:             * @see #BORDER_THICK
641:             * @see #BORDER_DOUBLE
642:             * @see #BORDER_HAIR
643:             * @see #BORDER_MEDIUM_DASHED
644:             * @see #BORDER_DASH_DOT
645:             * @see #BORDER_MEDIUM_DASH_DOT
646:             * @see #BORDER_DASH_DOT_DOT
647:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
648:             * @see #BORDER_SLANTED_DASH_DOT
649:             */
650:
651:            public void setBorderBottom(short border) {
652:                format.setIndentNotParentBorder(true);
653:                format.setBorderBottom(border);
654:            }
655:
656:            /**
657:             * get the type of border to use for the bottom border of the cell
658:             * @return border type
659:             * @see #BORDER_NONE
660:             * @see #BORDER_THIN
661:             * @see #BORDER_MEDIUM
662:             * @see #BORDER_DASHED
663:             * @see #BORDER_DOTTED
664:             * @see #BORDER_THICK
665:             * @see #BORDER_DOUBLE
666:             * @see #BORDER_HAIR
667:             * @see #BORDER_MEDIUM_DASHED
668:             * @see #BORDER_DASH_DOT
669:             * @see #BORDER_MEDIUM_DASH_DOT
670:             * @see #BORDER_DASH_DOT_DOT
671:             * @see #BORDER_MEDIUM_DASH_DOT_DOT
672:             * @see #BORDER_SLANTED_DASH_DOT
673:             */
674:            public short getBorderBottom() {
675:                return format.getBorderBottom();
676:            }
677:
678:            /**
679:             * set the color to use for the left border
680:             * @param color The index of the color definition
681:             */
682:            public void setLeftBorderColor(short color) {
683:                format.setLeftBorderPaletteIdx(color);
684:            }
685:
686:            /**
687:             * get the color to use for the left border
688:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
689:             * @param color The index of the color definition
690:             */
691:            public short getLeftBorderColor() {
692:                return format.getLeftBorderPaletteIdx();
693:            }
694:
695:            /**
696:             * set the color to use for the right border
697:             * @param color The index of the color definition
698:             */
699:            public void setRightBorderColor(short color) {
700:                format.setRightBorderPaletteIdx(color);
701:            }
702:
703:            /**
704:             * get the color to use for the left border
705:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
706:             * @param color The index of the color definition
707:             */
708:            public short getRightBorderColor() {
709:                return format.getRightBorderPaletteIdx();
710:            }
711:
712:            /**
713:             * set the color to use for the top border
714:             * @param color The index of the color definition
715:             */
716:            public void setTopBorderColor(short color) {
717:                format.setTopBorderPaletteIdx(color);
718:            }
719:
720:            /**
721:             * get the color to use for the top border
722:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
723:             * @param color The index of the color definition
724:             */
725:            public short getTopBorderColor() {
726:                return format.getTopBorderPaletteIdx();
727:            }
728:
729:            /**
730:             * set the color to use for the bottom border
731:             * @param color The index of the color definition
732:             */
733:            public void setBottomBorderColor(short color) {
734:                format.setBottomBorderPaletteIdx(color);
735:            }
736:
737:            /**
738:             * get the color to use for the left border
739:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
740:             * @param color The index of the color definition
741:             */
742:            public short getBottomBorderColor() {
743:                return format.getBottomBorderPaletteIdx();
744:            }
745:
746:            /**
747:             * setting to one fills the cell with the foreground color... No idea about
748:             * other values
749:             *
750:             * @see #NO_FILL
751:             * @see #SOLID_FOREGROUND
752:             * @see #FINE_DOTS
753:             * @see #ALT_BARS
754:             * @see #SPARSE_DOTS
755:             * @see #THICK_HORZ_BANDS
756:             * @see #THICK_VERT_BANDS
757:             * @see #THICK_BACKWARD_DIAG
758:             * @see #THICK_FORWARD_DIAG
759:             * @see #BIG_SPOTS
760:             * @see #BRICKS
761:             * @see #THIN_HORZ_BANDS
762:             * @see #THIN_VERT_BANDS
763:             * @see #THIN_BACKWARD_DIAG
764:             * @see #THIN_FORWARD_DIAG
765:             * @see #SQUARES
766:             * @see #DIAMONDS
767:             *
768:             * @param fp  fill pattern (set to 1 to fill w/foreground color)
769:             */
770:            public void setFillPattern(short fp) {
771:                format.setAdtlFillPattern(fp);
772:            }
773:
774:            /**
775:             * get the fill pattern (??) - set to 1 to fill with foreground color
776:             * @return fill pattern
777:             */
778:
779:            public short getFillPattern() {
780:                return format.getAdtlFillPattern();
781:            }
782:
783:            /**
784:             * Checks if the background and foreground fills are set correctly when one
785:             * or the other is set to the default color.
786:             * <p>Works like the logic table below:</p>
787:             * <p>BACKGROUND   FOREGROUND</p>
788:             * <p>NONE         AUTOMATIC</p>
789:             * <p>0x41         0x40</p>
790:             * <p>NONE         RED/ANYTHING</p>
791:             * <p>0x40         0xSOMETHING</p> 
792:             */
793:            private void checkDefaultBackgroundFills() {
794:                if (format.getFillForeground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) {
795:                    //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt
796:                    //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the
797:                    //background needs to be incremented......
798:                    if (format.getFillBackground() != (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index + 1))
799:                        setFillBackgroundColor((short) (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index + 1));
800:                } else if (format.getFillBackground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index + 1)
801:                    //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!!
802:                    if (format.getFillForeground() != org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index)
803:                        setFillBackgroundColor(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index);
804:            }
805:
806:            /**
807:             * set the background fill color.
808:             * <p>
809:             * For example:
810:             * <pre>
811:             * cs.setFillPattern(HSSFCellStyle.FINE_DOTS );
812:             * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); 
813:             * </pre>
814:             * optionally a Foreground and background fill can be applied:
815:             * <i>Note: Ensure Foreground color is set prior to background</i>
816:             * <pre>
817:             * cs.setFillPattern(HSSFCellStyle.FINE_DOTS );
818:             * cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex());
819:             * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); 
820:             * </pre>
821:             * or, for the special case of SOLID_FILL:
822:             * <pre>
823:             * cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND );
824:             * cs.setFillForegroundColor(new HSSFColor.RED().getIndex());
825:             * </pre>
826:             * It is necessary to set the fill style in order
827:             * for the color to be shown in the cell.
828:             *
829:             * @param bg  color
830:             */
831:
832:            public void setFillBackgroundColor(short bg) {
833:                format.setFillBackground(bg);
834:                checkDefaultBackgroundFills();
835:            }
836:
837:            /**
838:             * get the background fill color
839:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
840:             * @return fill color
841:             */
842:            public short getFillBackgroundColor() {
843:                short result = format.getFillBackground();
844:                //JMH: Do this ridiculous conversion, and let HSSFCellStyle
845:                //internally migrate back and forth
846:                if (result == (HSSFColor.AUTOMATIC.index + 1))
847:                    return HSSFColor.AUTOMATIC.index;
848:                else
849:                    return result;
850:            }
851:
852:            /**
853:             * set the foreground fill color
854:             * <i>Note: Ensure Foreground color is set prior to background color.</i>
855:             * @param bg  color
856:             */
857:            public void setFillForegroundColor(short bg) {
858:                format.setFillForeground(bg);
859:                checkDefaultBackgroundFills();
860:            }
861:
862:            /**
863:             * get the foreground fill color
864:             * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
865:             * @return fill color
866:             */
867:            public short getFillForegroundColor() {
868:                return format.getFillForeground();
869:            }
870:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.