Source Code Cross Referenced for EPFont.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » elementprocessor » impl » poi » hssf » elements » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements 
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.cocoon.components.elementprocessor.impl.poi.hssf.elements;
019:
020:        import org.apache.cocoon.components.elementprocessor.types.Attribute;
021:        import org.apache.cocoon.components.elementprocessor.ElementProcessor;
022:
023:        import org.apache.cocoon.components.elementprocessor.types.BooleanConverter;
024:        import org.apache.cocoon.components.elementprocessor.types.BooleanResult;
025:        import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
026:        import org.apache.cocoon.components.elementprocessor.types.NumericResult;
027:        import org.apache.cocoon.components.elementprocessor.types.Validator;
028:
029:        import org.apache.poi.hssf.usermodel.HSSFCellStyle;
030:        import org.apache.poi.hssf.usermodel.HSSFFont;
031:        import org.apache.poi.hssf.util.HSSFColor;
032:
033:        import java.io.IOException;
034:        import java.util.Hashtable;
035:
036:        /**
037:         * No-op implementation of ElementProcessor to handle the "Font" tag
038:         *
039:         * This element has five attributes and also holds the name of the
040:         * font as element content.
041:         *
042:         * This element is not used in HSSFSerializer 1.0
043:         *
044:         * @author Marc Johnson (marc_johnson27591@hotmail.com)
045:         * @author Andrew C. Oliver (acoliver2@users.sourceforge.net)
046:         * @version CVS $Id: EPFont.java 433543 2006-08-22 06:22:54Z crossley $
047:         */
048:        public class EPFont extends BaseElementProcessor {
049:            private NumericResult _unit;
050:            private BooleanResult _bold;
051:            private BooleanResult _italic;
052:            private NumericResult _underline;
053:            private BooleanResult _strike_through;
054:            private String _font;
055:            private HSSFFont hssfFont;
056:            private static final String _unit_attribute = "Unit";
057:            private static final String _bold_attribute = "Bold";
058:            private static final String _italic_attribute = "Italic";
059:            private static final String _underline_attribute = "Underline";
060:            private static final String _strike_through_attribute = "StrikeThrough";
061:            private static final Validator _underline_type_validator = new Validator() {
062:                public IOException validate(final Number number) {
063:                    return UnderlineType.isValid(number.intValue()) ? null
064:                            : new IOException("\"" + number
065:                                    + "\" is not a legal value");
066:                }
067:            };
068:
069:            /**
070:             * constructor
071:             */
072:            public EPFont() {
073:                super (null);
074:                _unit = null;
075:                _bold = null;
076:                _italic = null;
077:                _underline = null;
078:                _strike_through = null;
079:                _font = null;
080:            }
081:
082:            /**
083:             * Override of Initialize() implementation
084:             * @param attributes the array of Attribute instances; may be empty, will
085:             *                  never be null
086:             * @param parent the parent ElementProcessor; may be null
087:             * @exception IOException if anything is wrong
088:             */
089:            public void initialize(final Attribute[] attributes,
090:                    final ElementProcessor parent) throws IOException {
091:                super .initialize(attributes, parent);
092:                EPStyle pstyle = (EPStyle) parent;
093:                if (pstyle.isValid()) {
094:                    Hashtable colorhash = pstyle.getColorHash();
095:                    HSSFColor color = null;
096:
097:                    HSSFCellStyle style = pstyle.getStyle();
098:                    //style.setFillForegroundColor(
099:                    Workbook workbook = getWorkbook();
100:                    HSSFFont font = workbook.createFont();
101:                    style.setFont(font);
102:                    font.setFontHeightInPoints((short) getUnit());
103:                    //font.setFontName(getFont());
104:                    font.setItalic(getItalic());
105:                    if (getBold()) {
106:                        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
107:                    } else {
108:                        font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
109:                    }
110:                    font.setUnderline((byte) getUnderline());
111:                    font.setStrikeout(getStrikeThrough());
112:
113:                    color = (HSSFColor) colorhash.get(pstyle
114:                            .getForegroundColor().toString());
115:                    //System.out.println(pstyle.getForegroundColor().toString());
116:                    if (color == null)
117:                        color = new HSSFColor.BLACK();
118:                    font.setColor(color.getIndex());
119:                    hssfFont = font;
120:                }
121:            }
122:
123:            /**
124:             * @return unit
125:             * @exception IOException
126:             */
127:            public double getUnit() throws IOException {
128:                if (_unit == null) {
129:                    _unit = NumericConverter
130:                            .extractDouble(getValue(_unit_attribute));
131:                }
132:                return _unit.doubleValue();
133:            }
134:
135:            /**
136:             * @return bold
137:             * @exception IOException
138:             */
139:            public boolean getBold() throws IOException {
140:                if (_bold == null) {
141:                    _bold = BooleanConverter
142:                            .extractBoolean(getValue(_bold_attribute));
143:                }
144:                return _bold.booleanValue();
145:            }
146:
147:            /**
148:             * @return italic
149:             * @exception IOException
150:             */
151:            public boolean getItalic() throws IOException {
152:                if (_italic == null) {
153:                    _italic = BooleanConverter
154:                            .extractBoolean(getValue(_italic_attribute));
155:                }
156:                return _italic.booleanValue();
157:            }
158:
159:            /**
160:             * @return underline as one of the public variables in UnderlineType
161:             * @exception IOException
162:             */
163:            public int getUnderline() throws IOException {
164:                if (_underline == null) {
165:                    _underline = NumericConverter.extractInteger(
166:                            getValue(_underline_attribute),
167:                            _underline_type_validator);
168:                }
169:                return _underline.intValue();
170:            }
171:
172:            /**
173:             * @return strikeThrough
174:             * @exception IOException
175:             */
176:
177:            public boolean getStrikeThrough() throws IOException {
178:                if (_strike_through == null) {
179:                    _strike_through = BooleanConverter
180:                            .extractBoolean(getValue(_strike_through_attribute));
181:                }
182:                return _strike_through.booleanValue();
183:            }
184:
185:            /**
186:             * @return name of the font
187:             */
188:
189:            public String getFont() {
190:                if (_font == null) {
191:                    try {
192:                        _font = getData();
193:                    } catch (NullPointerException ignored) { /* VOID */
194:                    }
195:                }
196:
197:                return _font;
198:            }
199:
200:            private HSSFFont getHSSFFont() {
201:                return hssfFont;
202:            }
203:
204:            /**
205:             * push the data into the font
206:             * @exception IOException
207:             */
208:
209:            public void endProcessing() throws IOException {
210:                String thefont = getFont();
211:                if (thefont != null && !thefont.trim().equals("")
212:                        && getHSSFFont() != null) {
213:                    getHSSFFont().setFontName(thefont);
214:                } else if (getHSSFFont() != null) {
215:                    getHSSFFont().setFontName("Arial"); //default excel font
216:                }
217:            }
218:        } // end public class EPFont
w__w___w___.ja___va__2s.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.