Source Code Cross Referenced for GenerateSVG.java in  » GIS » GeoTools-2.4.1 » org » geotools » 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 » GIS » GeoTools 2.4.1 » org.geotools.svg 
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:         *    (C) 2002, Centre for Computational Geography
006:         *
007:         *    This library is free software; you can redistribute it and/or
008:         *    modify it under the terms of the GNU Lesser General Public
009:         *    License as published by the Free Software Foundation; either
010:         *    version 2.1 of the License, or (at your option) any later version.
011:         *
012:         *    This library is distributed in the hope that it will be useful,
013:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         *    Lesser General Public License for more details.
016:         */
017:        package org.geotools.svg;
018:
019:        import java.awt.Dimension;
020:        import java.awt.Rectangle;
021:        import java.awt.geom.AffineTransform;
022:        import java.io.IOException;
023:        import java.io.OutputStream;
024:        import java.io.OutputStreamWriter;
025:        import java.util.logging.Logger;
026:
027:        import javax.xml.parsers.DocumentBuilder;
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import javax.xml.parsers.FactoryConfigurationError;
030:        import javax.xml.parsers.ParserConfigurationException;
031:
032:        import org.apache.batik.svggen.SVGGeneratorContext;
033:        import org.apache.batik.svggen.SVGGraphics2D;
034:        import org.geotools.map.MapContext;
035:        import org.geotools.renderer.lite.StreamingRenderer;
036:        import org.w3c.dom.Document;
037:
038:        import com.vividsolutions.jts.geom.Envelope;
039:
040:        /**
041:         * This is a simple support class which allows you to generate an SVG file from a map.
042:         *
043:         * To use, setup a Map object with the layers you want to render, create an envelope for the
044:         * region to be drawn and pass in an OutputStream (probably attached to a new file) for the
045:         * resulting SVG information to be stored in.
046:         *
047:         * Optionaly you can change the default size of the SVG cavas (in effect increasing the resolution)
048:         * by calling setCavasSize before calling go.
049:         *
050:         * @author James Macgill, PennState
051:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/demo/svgsupport/src/main/java/org/geotools/svg/GenerateSVG.java $
052:         * @version $Id: GenerateSVG.java 27862 2007-11-12 19:51:19Z desruisseaux $
053:         */
054:        public class GenerateSVG {
055:            private static Logger LOGGER = org.geotools.util.logging.Logging
056:                    .getLogger("org.geotools.svgsupport");
057:            private Dimension canvasSize = new Dimension(300, 300);
058:
059:            /**
060:             * Creates a new instance of GenerateSVG.
061:             */
062:            public GenerateSVG() {
063:            }
064:
065:            /** Generate an SVG document from the supplied information.
066:             * Note, call setCavasSize first if you want to change the default output size.
067:             * @param map Contains the layers (features + styles) to be rendered
068:             * @param env The portion of the map to generate an SVG from
069:             * @param out Stream to write the resulting SVG out to (probable should be a new file)
070:             * @throws IOException Should anything go wrong whilst writing to 'out'
071:             * @throws ParserConfigurationException If critical XML tools are missing from the classpath
072:             */
073:            public void go(MapContext map, Envelope env, OutputStream out)
074:                    throws IOException, ParserConfigurationException {
075:                SVGGeneratorContext ctx = setupContext();
076:                ctx
077:                        .setComment("Generated by GeoTools2 with Batik SVG Generator");
078:
079:                SVGGraphics2D g2d = new SVGGraphics2D(ctx, true);
080:
081:                g2d.setSVGCanvasSize(getCanvasSize());
082:
083:                renderMap(map, env, g2d);
084:                LOGGER.finest("writing to file");
085:                OutputStreamWriter osw = null;
086:                try {
087:                    osw = new OutputStreamWriter(out, "UTF-8");
088:                    g2d.stream(osw);
089:                } finally {
090:                    if (osw != null)
091:                        osw.close();
092:                }
093:
094:            }
095:
096:            /**
097:             * DOCUMENT ME!
098:             *
099:             * @param map
100:             * @param env
101:             * @param g2d
102:             */
103:            private void renderMap(final MapContext map, final Envelope env,
104:                    final SVGGraphics2D g2d) throws IOException {
105:                StreamingRenderer renderer = new StreamingRenderer();
106:                renderer.setContext(map);
107:
108:                Rectangle outputArea = new Rectangle(g2d.getSVGCanvasSize());
109:                Envelope dataArea = map.getLayerBounds();
110:
111:                LOGGER.finest("rendering map");
112:                renderer.paint(g2d, outputArea, dataArea);
113:            }
114:
115:            /**
116:             * DOCUMENT ME!
117:             *
118:             * @return
119:             *
120:             * @throws FactoryConfigurationError
121:             * @throws ParserConfigurationException
122:             */
123:            private SVGGeneratorContext setupContext()
124:                    throws FactoryConfigurationError,
125:                    ParserConfigurationException {
126:                Document document = null;
127:
128:                DocumentBuilderFactory dbf = DocumentBuilderFactory
129:                        .newInstance();
130:                DocumentBuilder db = dbf.newDocumentBuilder();
131:
132:                // Create an instance of org.w3c.dom.Document
133:                document = db.getDOMImplementation().createDocument(null,
134:                        "svg", null);
135:
136:                // Set up the context
137:                SVGGeneratorContext ctx = SVGGeneratorContext
138:                        .createDefault(document);
139:
140:                return ctx;
141:            }
142:
143:            public Dimension getCanvasSize() {
144:                return this .canvasSize;
145:            }
146:
147:            public void setCanvasSize(final Dimension size) {
148:                this.canvasSize = size;
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.