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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-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:         *    Created on April 12, 2002, 1:18 PM
017:         */
018:        package org.geotools.styling;
019:
020:        import junit.framework.Test;
021:        import junit.framework.TestCase;
022:        import junit.framework.TestSuite;
023:
024:        import org.geotools.data.memory.MemoryDataStore;
025:        import org.geotools.factory.CommonFactoryFinder;
026:        import org.geotools.feature.AttributeType;
027:        import org.geotools.feature.AttributeTypeFactory;
028:        import org.geotools.feature.Feature;
029:        import org.geotools.feature.FeatureCollection;
030:        import org.geotools.feature.FeatureType;
031:        import org.geotools.feature.FeatureTypeFactory;
032:        import org.opengis.filter.FilterFactory;
033:        import org.opengis.filter.expression.PropertyName;
034:
035:        import com.vividsolutions.jts.geom.Coordinate;
036:        import com.vividsolutions.jts.geom.GeometryFactory;
037:        import com.vividsolutions.jts.geom.Point;
038:
039:        /**
040:         * Test for text symbols.
041:         *
042:         * @author jamesm
043:         *
044:         * @task REVISIT: redo the Map stuff - I commented it out since DefaultMap is
045:         *       deprecated - cholmes.
046:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/styling/TextSymbolTest.java $
047:         */
048:        public class TextSymbolTest extends TestCase {
049:            private static final FilterFactory filterFactory = CommonFactoryFinder
050:                    .getFilterFactory(null);
051:
052:            /** factory for attributes */
053:            private static AttributeTypeFactory attFactory = AttributeTypeFactory
054:                    .defaultInstance();
055:            String dataFolder;
056:
057:            public TextSymbolTest(java.lang.String testName) {
058:                super (testName);
059:                dataFolder = System.getProperty("dataFolder");
060:
061:                if (dataFolder == null) {
062:                    //then we are being run by maven
063:                    dataFolder = System.getProperty("basedir");
064:                    dataFolder += "/tests/unit/testData";
065:                }
066:            }
067:
068:            public static void main(java.lang.String[] args) {
069:                junit.textui.TestRunner.run(suite());
070:            }
071:
072:            public static Test suite() {
073:                TestSuite suite = new TestSuite(TextSymbolTest.class);
074:
075:                return suite;
076:            }
077:
078:            public void testRender() throws Exception {
079:                //System.out.println("\n\nTextSymbolTest\n");
080:
081:                // Request extent
082:                GeometryFactory geomFac = new GeometryFactory();
083:                MemoryDataStore data = new MemoryDataStore();
084:                AttributeType[] pointAttribute = new AttributeType[4];
085:                pointAttribute[0] = AttributeTypeFactory.newAttributeType(
086:                        "centre", com.vividsolutions.jts.geom.Point.class);
087:                pointAttribute[1] = AttributeTypeFactory.newAttributeType(
088:                        "size", Double.class);
089:                pointAttribute[2] = AttributeTypeFactory.newAttributeType(
090:                        "rotation", Double.class);
091:                pointAttribute[3] = AttributeTypeFactory.newAttributeType(
092:                        "symbol", String.class);
093:
094:                FeatureTypeFactory feaTypeFactory = FeatureTypeFactory
095:                        .newInstance("test");
096:                feaTypeFactory.addTypes(pointAttribute);
097:                feaTypeFactory.setName("testPoint");
098:
099:                FeatureType pointType = feaTypeFactory.getFeatureType();
100:
101:                //FlatFeatureFactory pointFac = feaTypeFactory.(pointType);
102:                Point point;
103:                Feature pointFeature;
104:
105:                // load font 
106:                String[] symbol = { "\uF04A", "\uF04B", "\uF059", "\uF05A",
107:                        "\uF06B", "\uF06C", "\uF06E" };
108:                double size = 16;
109:                double rotation = 0.0;
110:                int rows = 8;
111:
112:                for (int j = 0; j < rows; j++) {
113:                    for (int i = 0; i < symbol.length; i++) {
114:                        point = makeSamplePoint(geomFac,
115:                                ((double) i * 5.0) + 5.0, 5.0 + (j * 5));
116:                        pointFeature = pointType.create(new Object[] { point,
117:                                new Double(size), new Double(rotation),
118:                                symbol[i] });
119:                        data.addFeature(pointFeature);
120:                    }
121:
122:                    size += 2;
123:                    rotation += 45;
124:                }
125:
126:                String typeName = data.getTypeNames()[0];
127:                FeatureCollection ft = data.getFeatureSource(typeName)
128:                        .getFeatures();
129:
130:                //REVISIT: Removed since it is deprecated, not sure what this test is
131:                //is doing, what should replace it.  If someone with more knowledge of
132:                //this stuff could update the tests that'd be great - ch.
133:                //org.geotools.map.Map map = new DefaultMap();
134:                //The following is complex, and should be built from
135:                //an SLD document and not by hand
136:                org.geotools.styling.FontImpl font = new org.geotools.styling.FontImpl();
137:
138:                font.setFontFamily(filterFactory.literal(dataFolder
139:                        + "geog.ttf"));
140:                font.setFontSize(filterFactory.property("size"));
141:
142:                PropertyName symbExpr = filterFactory.property("symbol");
143:                TextMark textMark = new TextMarkImpl(font, symbExpr);
144:
145:                org.geotools.styling.FontImpl font2 = new org.geotools.styling.FontImpl();
146:                font2.setFontFamily(filterFactory
147:                        .literal("MapInfo Cartographic"));
148:                font2.setFontSize(filterFactory.property("size"));
149:                textMark.addFont(font2);
150:
151:                org.geotools.styling.FontImpl font3 = new org.geotools.styling.FontImpl();
152:                font3.setFontFamily(filterFactory.literal("ESRI Cartography"));
153:                font3.setFontSize(filterFactory.property("size"));
154:                textMark.addFont(font3);
155:
156:                GraphicImpl graphic = new GraphicImpl();
157:                graphic.addSymbol(textMark);
158:
159:                PointSymbolizerImpl pointsym = new PointSymbolizerImpl();
160:                pointsym.setGeometryPropertyName("centre");
161:                pointsym.setGraphic(graphic);
162:
163:                RuleImpl rule = new RuleImpl();
164:                rule.setSymbolizers(new Symbolizer[] { pointsym });
165:
166:                FeatureTypeStyleImpl fts = new FeatureTypeStyleImpl();
167:                fts.addRule(rule);
168:                fts.setFeatureTypeName("testPoint");
169:
170:                StyleImpl style = new StyleImpl();
171:                style.addFeatureTypeStyle(fts);
172:
173:                //map.addFeatureTable(ft,style);
174:
175:                /*Java2DRenderer renderer = new org.geotools.renderer.Java2DRenderer();
176:                   Frame frame = new Frame("text symbol test");
177:                   frame.addWindowListener(new WindowAdapter() {
178:                       public void windowClosing(WindowEvent e) {e.getWindow().dispose(); }
179:                   });
180:                   Panel p = new Panel();
181:                   frame.add(p);
182:                   frame.setSize(300,300);
183:                   frame.setVisible(true);
184:                   renderer.setOutput(p.getGraphics(),p.getBounds());
185:                   map.render(renderer,ex.getBounds());//and finaly try and draw it!
186:                
187:                   int w = 400, h =400;
188:                   BufferedImage image = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
189:                   Graphics g = image.getGraphics();
190:                   g.setColor(Color.white);
191:                   g.fillRect(0,0,w,h);
192:                   renderer.setOutput(g,new java.awt.Rectangle(0,0,w,h));
193:                   map.render(renderer,ex.getBounds());//and finaly try and draw it!
194:                   File file = new File(dataFolder, "TextSymbolTest.jpg");
195:                   FileOutputStream out = new FileOutputStream(file);
196:                   ImageIO.write(image, "JPEG", out);
197:                   Thread.sleep(5000);
198:                   frame.dispose();*/
199:            }
200:
201:            private Point makeSamplePoint(final GeometryFactory geomFac,
202:                    double x, double y) {
203:                Coordinate c = new Coordinate(x, y);
204:                Point point = geomFac.createPoint(c);
205:
206:                return point;
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.