Source Code Cross Referenced for Styling.java in  » GIS » udig-1.1 » net » refractions » udig » project » internal » render » impl » 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 » udig 1.1 » net.refractions.udig.project.internal.render.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008:         */
009:        package net.refractions.udig.project.internal.render.impl;
010:
011:        import java.awt.Color;
012:        import java.io.IOException;
013:        import java.util.Collection;
014:        import java.util.Collections;
015:        import java.util.HashMap;
016:        import java.util.LinkedList;
017:        import java.util.List;
018:        import java.util.Map;
019:
020:        import net.refractions.udig.project.internal.Layer;
021:        import net.refractions.udig.project.internal.Messages;
022:        import net.refractions.udig.project.internal.ProjectPlugin;
023:
024:        import org.geotools.data.wms.WebMapServer;
025:        import org.geotools.styling.FeatureTypeStyle;
026:        import org.geotools.styling.LineSymbolizer;
027:        import org.geotools.styling.PointSymbolizer;
028:        import org.geotools.styling.PolygonSymbolizer;
029:        import org.geotools.styling.RasterSymbolizer;
030:        import org.geotools.styling.Style;
031:        import org.geotools.styling.StyleBuilder;
032:
033:        /**
034:         * A utility class for obtaining precanned or random styles
035:         * 
036:         * @author Jesse Eichar
037:         * @version $Revision: 1.9 $
038:         */
039:        public class Styling {
040:
041:            /** A map of default styles. */
042:            public static final Map STYLES;
043:            static {
044:                Map<String, Integer> styles = new HashMap<String, Integer>();
045:                styles.put(Messages.Styling_blueLine, Integer.valueOf(0));
046:                styles.put(Messages.Styling_greenLine, Integer.valueOf(1));
047:                styles.put(Messages.Styling_blackLine, Integer.valueOf(2));
048:                styles.put(Messages.Styling_blackLine_blueFill, Integer
049:                        .valueOf(3));
050:                styles.put(Messages.Styling_blackLine_greenFill, Integer
051:                        .valueOf(4));
052:                styles.put(Messages.Styling_blackLine_semitransparentBlueFill,
053:                        Integer.valueOf(5));
054:                styles.put(
055:                        Messages.Styling_blackLine_semitransparentYellowFill,
056:                        Integer.valueOf(6));
057:                styles.put(Messages.Styling_pointStyle, Integer.valueOf(7));
058:                STYLES = Collections.unmodifiableMap(styles);
059:            }
060:
061:            /**
062:             * Returns a Style object give a style name and a feature typename.
063:             * 
064:             * @param styleName The name of the style to creates. The list of name can be obtained from
065:             *        {@link #getStyleNames(Layer)}
066:             * @param typeName the TypeName of the feature type the style will style.
067:             * @return a Style object give a style name and a feature typename.
068:             */
069:            public static Style getStyle(String styleName, String typeName) {
070:                return getStyle(((Integer) STYLES.get(styleName)).intValue(),
071:                        typeName);
072:            }
073:
074:            /**
075:             * Returns a Style object given a value from {@link #STYLES}and the feature typename.
076:             * 
077:             * @param index a value from {@link #STYLES}
078:             * @param typeName the TypeName of the feature type the style will style.
079:             * @return a Style object given a value from {@link #STYLES}and the feature typename
080:             */
081:            public static Style getStyle(int index, String typeName) {
082:                switch (index) {
083:                case 0:
084:                    return createLineStyle(typeName, Color.BLUE);
085:                case 1:
086:                    return createLineStyle(typeName, Color.GREEN);
087:                case 2:
088:                    return createLineStyle(typeName, Color.BLACK);
089:                case 3:
090:                    return createPolyStyle(typeName, Color.BLACK, Color.BLUE);
091:                case 4:
092:                    return createPolyStyle(typeName, Color.BLACK, Color.GREEN);
093:                case 5:
094:                    return createPolyStyle(typeName, Color.BLACK, new Color(0,
095:                            0, 255, 127));
096:                case 6:
097:                    return createPolyStyle(typeName, Color.BLACK, new Color(
098:                            127, 127, 127, 127));
099:                case 7:
100:                    return createPointStyle(typeName);
101:
102:                default:
103:                    return createLineStyle(typeName, Color.BLUE);
104:                }
105:            }
106:
107:            /**
108:             * Returns a simple style to use in default cases.
109:             * 
110:             * @param typeName the TypeName of the feature type the style will style.
111:             * @return a simple style to use in default cases.
112:             */
113:            public static Style createLineStyle(String typeName) {
114:                return createLineStyle(typeName, Color.blue);
115:            }
116:
117:            /**
118:             * Returns a simple style to use in default cases.
119:             * 
120:             * @param typeName the TypeName of the feature type the style will style.
121:             * @param color the color of the style
122:             * @return a simple style to use in default cases.
123:             */
124:            public static Style createLineStyle(String typeName, Color color) {
125:                StyleBuilder sb = new StyleBuilder();
126:                Style linestyle = sb.createStyle();
127:
128:                LineSymbolizer line = sb.createLineSymbolizer(color);
129:                linestyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(line));
130:
131:                FeatureTypeStyle fts = linestyle.getFeatureTypeStyles()[0];
132:                fts.setName(Messages.Styling_name); //tag as simple 
133:                fts.setFeatureTypeName(typeName);
134:                fts.setSemanticTypeIdentifiers(new String[] {
135:                        "generic:geometry", "simple" }); //$NON-NLS-1$ //$NON-NLS-2$
136:
137:                return linestyle;
138:            }
139:
140:            /**
141:             * Returns a simple style to use in default cases.
142:             * 
143:             * @param typeName the TypeName of the feature type the style will style.
144:             * @return a simple style to use in default cases.
145:             */
146:            public static Style createPolyStyle(String typeName) {
147:                return createPolyStyle(typeName, Color.BLACK, Color.GREEN);
148:            }
149:
150:            /**
151:             * Returns a simple style to use in default cases.
152:             * 
153:             * @param typeName the TypeName of the feature type the style will style.
154:             * @param line the color of the outlines.
155:             * @param fill The color of the fills
156:             * @return a simple style to use in default cases.
157:             */
158:            public static Style createPolyStyle(String typeName, Color line,
159:                    Color fill) {
160:                StyleBuilder sb = new StyleBuilder();
161:                Style polystyle = sb.createStyle();
162:
163:                PolygonSymbolizer poly = sb.createPolygonSymbolizer(fill, line,
164:                        1);
165:                polystyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(poly));
166:
167:                polystyle.getFeatureTypeStyles()[0]
168:                        .setFeatureTypeName(typeName);
169:                return polystyle;
170:            }
171:
172:            /**
173:             * Returns a simple style to use in default cases.
174:             * 
175:             * @param typeName the TypeName of the feature type the style will style.
176:             * @return a simple style to use in default cases.
177:             */
178:            public static Style createPointStyle(String typeName) {
179:                StyleBuilder sb = new StyleBuilder();
180:                Style pointstyle = sb.createStyle();
181:                PointSymbolizer point = sb.createPointSymbolizer(sb
182:                        .createGraphic());
183:
184:                pointstyle
185:                        .addFeatureTypeStyle(sb.createFeatureTypeStyle(point));
186:
187:                pointstyle.getFeatureTypeStyles()[0]
188:                        .setFeatureTypeName(typeName);
189:                return pointstyle;
190:            }
191:
192:            /**
193:             * Returns a simple style to use in default cases.
194:             * 
195:             * @param typeName the TypeName of the feature type the style will style.
196:             * @return as simple style to use in default cases.
197:             */
198:            public static Style createRasterStyle(String typeName) {
199:                StyleBuilder sb = new StyleBuilder();
200:                Style rasterstyle = sb.createStyle();
201:                RasterSymbolizer raster = sb.createRasterSymbolizer();
202:
203:                rasterstyle.addFeatureTypeStyle(sb
204:                        .createFeatureTypeStyle(raster));
205:                rasterstyle.getFeatureTypeStyles()[0]
206:                        .setFeatureTypeName(typeName);
207:                return rasterstyle;
208:            }
209:
210:            /**
211:             * Returns a list of style names that can be used on the given layer.
212:             * 
213:             * @param currentLayer The layer to finds styles for.
214:             * @return a list of style names that can be used on the given layer.
215:             */
216:            @SuppressWarnings("unchecked")
217:            public static Collection getStyleNames(Layer currentLayer) {
218:                // URI id=currentLayer.getID();
219:                // if( id.containsKey(WMSRegistryEntry.GET_CAPABILITIES_URL) ){
220:                if (currentLayer.isType(WebMapServer.class)) { // checking for wms
221:
222:                    List<String> l = new LinkedList<String>();
223:                    try {
224:                        l.addAll(currentLayer.getResource(
225:                                org.geotools.data.ows.Layer.class, null)
226:                                .getStyles());
227:                    } catch (IOException e) {
228:                        ProjectPlugin.log(null, e);
229:                    }
230:                    l.add(Messages.Styling_default);
231:                    return l;
232:                }
233:
234:                return STYLES.keySet();
235:            }
236:        }
w_w___w.ja__v__a__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.