Source Code Cross Referenced for BatikStarElementBridge.java in  » Graphic-Library » batik » org » apache » batik » extension » svg » 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 » Graphic Library » batik » org.apache.batik.extension.svg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Licensed to the Apache Software Foundation (ASF) under one or more
004:           contributor license agreements.  See the NOTICE file distributed with
005:           this work for additional information regarding copyright ownership.
006:           The ASF licenses this file to You under the Apache License, Version 2.0
007:           (the "License"); you may not use this file except in compliance with
008:           the License.  You may obtain a copy of the License at
009:
010:               http://www.apache.org/licenses/LICENSE-2.0
011:
012:           Unless required by applicable law or agreed to in writing, software
013:           distributed under the License is distributed on an "AS IS" BASIS,
014:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:           See the License for the specific language governing permissions and
016:           limitations under the License.
017:
018:         */
019:        package org.apache.batik.extension.svg;
020:
021:        import java.awt.geom.GeneralPath;
022:
023:        import org.apache.batik.bridge.Bridge;
024:        import org.apache.batik.bridge.BridgeContext;
025:        import org.apache.batik.bridge.BridgeException;
026:        import org.apache.batik.bridge.SVGDecoratedShapeElementBridge;
027:        import org.apache.batik.bridge.SVGUtilities;
028:        import org.apache.batik.bridge.UnitProcessor;
029:        import org.apache.batik.gvt.ShapeNode;
030:        import org.w3c.dom.Element;
031:
032:        /**
033:         * Bridge class for a star element.
034:         *
035:         * @author <a href="mailto:thomas.deweese@kodak.com">Thomas Deweese</a>
036:         * @version $Id: BatikStarElementBridge.java 501922 2007-01-31 17:47:47Z dvholten $
037:         */
038:        public class BatikStarElementBridge extends
039:                SVGDecoratedShapeElementBridge implements  BatikExtConstants {
040:
041:            /**
042:             * Constructs a new bridge for the &lt;rect> element.
043:             */
044:            public BatikStarElementBridge() { /* nothing */
045:            }
046:
047:            /**
048:             * Returns the SVG namespace URI.
049:             */
050:            public String getNamespaceURI() {
051:                return BATIK_EXT_NAMESPACE_URI;
052:            }
053:
054:            /**
055:             * Returns 'rect'.
056:             */
057:            public String getLocalName() {
058:                return BATIK_EXT_STAR_TAG;
059:            }
060:
061:            /**
062:             * Returns a new instance of this bridge.
063:             */
064:            public Bridge getInstance() {
065:                return new BatikStarElementBridge();
066:            }
067:
068:            /**
069:             * Constructs a star polygone according to the specified parameters.
070:             *
071:             * @param ctx the bridge context to use
072:             * @param e the element that describes a rect element
073:             * @param shapeNode the shape node to initialize
074:             */
075:            protected void buildShape(BridgeContext ctx, Element e,
076:                    ShapeNode shapeNode) {
077:
078:                UnitProcessor.Context uctx = UnitProcessor
079:                        .createContext(ctx, e);
080:                String s;
081:
082:                // 'cx' attribute - default is 0
083:                s = e.getAttributeNS(null, SVG_CX_ATTRIBUTE);
084:                float cx = 0;
085:                if (s.length() != 0) {
086:                    cx = UnitProcessor.svgHorizontalCoordinateToUserSpace(s,
087:                            SVG_CX_ATTRIBUTE, uctx);
088:                }
089:
090:                // 'cy' attribute - default is 0
091:                s = e.getAttributeNS(null, SVG_CY_ATTRIBUTE);
092:                float cy = 0;
093:                if (s.length() != 0) {
094:                    cy = UnitProcessor.svgVerticalCoordinateToUserSpace(s,
095:                            SVG_CY_ATTRIBUTE, uctx);
096:                }
097:
098:                // 'r' attribute - required
099:                s = e.getAttributeNS(null, SVG_R_ATTRIBUTE);
100:                float r;
101:                if (s.length() == 0)
102:                    throw new BridgeException(ctx, e, ERR_ATTRIBUTE_MISSING,
103:                            new Object[] { SVG_R_ATTRIBUTE, s });
104:                r = UnitProcessor.svgOtherLengthToUserSpace(s, SVG_R_ATTRIBUTE,
105:                        uctx);
106:
107:                // 'ir' attribute - required
108:                s = e.getAttributeNS(null, BATIK_EXT_IR_ATTRIBUTE);
109:                float ir;
110:                if (s.length() == 0)
111:                    throw new BridgeException(ctx, e, ERR_ATTRIBUTE_MISSING,
112:                            new Object[] { BATIK_EXT_IR_ATTRIBUTE, s });
113:
114:                ir = UnitProcessor.svgOtherLengthToUserSpace(s,
115:                        BATIK_EXT_IR_ATTRIBUTE, uctx);
116:
117:                // 'sides' attribute - default is 3
118:                int sides = convertSides(e, BATIK_EXT_SIDES_ATTRIBUTE, 3, ctx);
119:
120:                GeneralPath gp = new GeneralPath();
121:                double angle, x, y;
122:                final double SECTOR = 2.0 * Math.PI / sides;
123:                final double HALF_PI = Math.PI / 2.0;
124:
125:                for (int i = 0; i < sides; i++) {
126:                    angle = i * SECTOR - HALF_PI;
127:                    x = cx + ir * Math.cos(angle);
128:                    y = cy - ir * Math.sin(angle);
129:                    if (i == 0)
130:                        gp.moveTo((float) x, (float) y);
131:                    else
132:                        gp.lineTo((float) x, (float) y);
133:
134:                    angle = (i + 0.5) * SECTOR - HALF_PI;
135:                    x = cx + r * Math.cos(angle);
136:                    y = cy - r * Math.sin(angle);
137:                    gp.lineTo((float) x, (float) y);
138:                }
139:                gp.closePath();
140:
141:                shapeNode.setShape(gp);
142:            }
143:
144:            /**
145:             * Stolen from AbstractSVGFilterPrimitiveElementBridge.
146:             * Converts on the specified filter primitive element, the specified
147:             * attribute that represents an integer and with the specified
148:             * default value.
149:             *
150:             * @param filterElement the filter primitive element
151:             * @param attrName the name of the attribute
152:             * @param defaultValue the default value of the attribute
153:             * @param ctx the BridgeContext to use for error information
154:             */
155:            protected static int convertSides(Element filterElement,
156:                    String attrName, int defaultValue, BridgeContext ctx) {
157:                String s = filterElement.getAttributeNS(null, attrName);
158:                if (s.length() == 0) {
159:                    return defaultValue;
160:                } else {
161:                    int ret = 0;
162:                    try {
163:                        ret = SVGUtilities.convertSVGInteger(s);
164:                    } catch (NumberFormatException nfEx) {
165:                        throw new BridgeException(ctx, filterElement, nfEx,
166:                                ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {
167:                                        attrName, s });
168:                    }
169:
170:                    if (ret < 3)
171:                        throw new BridgeException(ctx, filterElement,
172:                                ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] {
173:                                        attrName, s });
174:                    return ret;
175:                }
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.