Source Code Cross Referenced for DynamicLineStyle2D.java in  » GIS » GeoTools-2.4.1 » org » geotools » renderer » style » 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 » GIS » GeoTools 2.4.1 » org.geotools.renderer.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation; either
009:         *    version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.renderer.style;
017:
018:        import java.awt.AlphaComposite;
019:        import java.awt.BasicStroke;
020:        import java.awt.Color;
021:        import java.awt.Composite;
022:        import java.awt.Paint;
023:
024:        import org.geotools.feature.Feature;
025:        import org.geotools.styling.LineSymbolizer;
026:        import org.geotools.styling.Stroke;
027:        import org.opengis.filter.expression.Expression;
028:
029:        /**
030:         * A dynamic line style, that will compute its parameters each time they are requested instead of
031:         * caching them
032:         *
033:         * @author jamesm
034:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/render/src/main/java/org/geotools/renderer/style/DynamicLineStyle2D.java $
035:         */
036:        public class DynamicLineStyle2D extends
037:                org.geotools.renderer.style.LineStyle2D {
038:            /** The feature that will be styled as a polygon */
039:            protected Feature feature;
040:
041:            /** The line symbolizer used to get stroke/composite/... */
042:            protected LineSymbolizer ls;
043:
044:            /**
045:             * Creates a new instance of DynamicLineStyle2D
046:             */
047:            public DynamicLineStyle2D(Feature feature, LineSymbolizer sym) {
048:                this .feature = feature;
049:                ls = sym;
050:            }
051:
052:            /**
053:             * Computes and returns the stroke
054:             */
055:            public java.awt.Stroke getStroke() {
056:                Stroke stroke = ls.getStroke();
057:
058:                if (stroke == null) {
059:                    return null;
060:                }
061:
062:                // resolve join type into a join code
063:                String joinType;
064:                int joinCode;
065:
066:                joinType = evaluateExpression(stroke.getLineJoin(), feature,
067:                        "miter");
068:
069:                joinCode = SLDStyleFactory.lookUpJoin(joinType);
070:
071:                // resolve cap type into a cap code
072:                String capType;
073:                int capCode;
074:
075:                capType = evaluateExpression(stroke.getLineCap(), feature,
076:                        "square");
077:                capCode = SLDStyleFactory.lookUpCap(capType);
078:
079:                // get the other properties needed for the stroke
080:                float[] dashes = stroke.getDashArray();
081:                float width = ((Float) stroke.getWidth().evaluate(feature,
082:                        Float.class)).floatValue();
083:                float dashOffset = ((Float) stroke.getDashOffset().evaluate(
084:                        feature, Float.class)).floatValue();
085:
086:                // Simple optimization: let java2d use the fast drawing path if the line width
087:                // is small enough...
088:                if (width <= 1) {
089:                    width = 0;
090:                }
091:
092:                // now set up the stroke
093:                BasicStroke stroke2d;
094:
095:                if ((dashes != null) && (dashes.length > 0)) {
096:                    stroke2d = new BasicStroke(width, capCode, joinCode, 1,
097:                            dashes, dashOffset);
098:                } else {
099:                    stroke2d = new BasicStroke(width, capCode, joinCode, 1);
100:                }
101:
102:                return stroke2d;
103:            }
104:
105:            /**
106:             * Computes and returns the contour style
107:             */
108:            public java.awt.Composite getContourComposite() {
109:                Stroke stroke = ls.getStroke();
110:
111:                if (stroke == null) {
112:                    return null;
113:                }
114:
115:                float opacity = ((Float) stroke.getOpacity().evaluate(feature,
116:                        Float.class)).floatValue();
117:                Composite composite = AlphaComposite.getInstance(
118:                        AlphaComposite.SRC_OVER, opacity);
119:
120:                return composite;
121:            }
122:
123:            /**
124:             * Returns the contour paint
125:             *
126:             * @return the contour paint
127:             */
128:            public java.awt.Paint getContour() {
129:                Stroke stroke = ls.getStroke();
130:
131:                if (stroke == null) {
132:                    return null;
133:                }
134:
135:                // the foreground color
136:                Paint contourPaint = (Color) stroke.getColor().evaluate(
137:                        feature, Color.class);
138:                if (contourPaint == null) {
139:                    String text = (String) stroke.getColor().evaluate(feature,
140:                            String.class);
141:                    if (text != null) {
142:                        contourPaint = Color.decode(text);
143:                    }
144:                }
145:
146:                // if a graphic fill is to be used, prepare the paint accordingly....
147:                org.geotools.styling.Graphic gr = stroke.getGraphicFill();
148:                SLDStyleFactory fac = new SLDStyleFactory();
149:
150:                if (gr != null) {
151:                    contourPaint = fac.getTexturePaint(gr, feature);
152:                }
153:
154:                return contourPaint;
155:            }
156:
157:            /**
158:             * Evaluates an expression over the passed feature, if the expression or the result is null,
159:             * the default value will be returned
160:             */
161:            private String evaluateExpression(Expression e, Feature feature,
162:                    String defaultValue) {
163:                String result = defaultValue;
164:
165:                if (e != null) {
166:                    result = (String) e.evaluate(feature, defaultValue
167:                            .getClass());
168:
169:                    if (result == null) {
170:                        result = defaultValue;
171:                    }
172:                }
173:
174:                return result;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.