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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 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;
009:         *    version 2.1 of the License.
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.demo.mappane;
017:
018:        import java.awt.BorderLayout;
019:        import java.awt.Container;
020:        import java.awt.RenderingHints;
021:        import java.awt.event.ActionEvent;
022:        import java.awt.event.ActionListener;
023:        import java.util.HashMap;
024:
025:        import javax.swing.Action;
026:        import javax.swing.JButton;
027:        import javax.swing.JFileChooser;
028:        import javax.swing.JFrame;
029:        import javax.swing.JLabel;
030:        import javax.swing.JOptionPane;
031:        import javax.swing.JToolBar;
032:        import javax.swing.WindowConstants;
033:
034:        import org.geotools.data.ows.Layer;
035:        import org.geotools.data.wms.WebMapServer;
036:        import org.geotools.geometry.Envelope2D;
037:        import org.geotools.gui.swing.JMapPane;
038:        import org.geotools.gui.swing.PanAction;
039:        import org.geotools.gui.swing.ResetAction;
040:        import org.geotools.gui.swing.ZoomInAction;
041:        import org.geotools.gui.swing.ZoomOutAction;
042:        import org.geotools.map.DefaultMapContext;
043:        import org.geotools.map.MapContext;
044:        import org.geotools.referencing.CRS;
045:        import org.geotools.referencing.crs.DefaultGeographicCRS;
046:        import org.geotools.renderer.GTRenderer;
047:        import org.geotools.renderer.lite.StreamingRenderer;
048:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
049:
050:        import com.vividsolutions.jts.geom.Envelope;
051:
052:        /**
053:         * Sample application that may be used to try JMapPane 
054:         * to view WMS Layers
055:         * 
056:         * @author Ian Turton
057:         */
058:        public class WMSViewer implements  ActionListener {
059:            JFrame frame;
060:
061:            JMapPane mp;
062:
063:            JToolBar jtb;
064:
065:            JLabel text;
066:
067:            GTRenderer renderer;
068:
069:            MapContext context;
070:
071:            final JFileChooser jfc = new JFileChooser();
072:
073:            public WMSViewer() {
074:                frame = new JFrame("My WMS Viewer");
075:                frame.setBounds(20, 20, 450, 200);
076:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
077:                Container content = frame.getContentPane();
078:                mp = new JMapPane();
079:                // mp.addZoomChangeListener(this);
080:                content.setLayout(new BorderLayout());
081:                jtb = new JToolBar();
082:
083:                JButton load = new JButton("Load file");
084:                load.addActionListener(this );
085:                jtb.add(load);
086:                Action zoomIn = new ZoomInAction(mp);
087:                Action zoomOut = new ZoomOutAction(mp);
088:                Action pan = new PanAction(mp);
089:                // Action select = new SelectAction(mp);
090:                Action reset = new ResetAction(mp);
091:                jtb.add(zoomIn);
092:                jtb.add(zoomOut);
093:                jtb.add(pan);
094:                jtb.addSeparator();
095:                jtb.add(reset);
096:                jtb.addSeparator();
097:                // jtb.add(select);
098:                final JButton button = new JButton();
099:                button.setText("CRS");
100:                button.setToolTipText("Change map prjection");
101:                button.addActionListener(new ActionListener() {
102:                    public void actionPerformed(ActionEvent e) {
103:
104:                        String code = JOptionPane.showInputDialog(button,
105:                                "Coordinate Reference System:", "EPSG:4326");
106:                        if (code == null)
107:                            return;
108:                        try {
109:                            CoordinateReferenceSystem crs = CRS.decode(code);
110:                            setCRS(crs);
111:                        } catch (Exception fe) {
112:                            fe.printStackTrace();
113:                            JOptionPane.showMessageDialog(button, fe
114:                                    .getMessage(), fe.getClass().toString(),
115:                                    JOptionPane.ERROR_MESSAGE);
116:                            return;
117:                        }
118:                    }
119:                });
120:                jtb.add(button);
121:
122:                content.add(jtb, BorderLayout.NORTH);
123:
124:                // JComponent sp = mp.createScrollPane();
125:                mp.setSize(400, 200);
126:                content.add(mp, BorderLayout.CENTER);
127:
128:                content.doLayout();
129:                frame.setVisible(true);
130:
131:            }
132:
133:            /**
134:             * Method used to set the current map projection.
135:             * 
136:             * @param crs
137:             *            A new CRS for the mappnae.
138:             */
139:            public void setCRS(CoordinateReferenceSystem crs) {
140:                mp.getContext().setAreaOfInterest(
141:                        mp.getContext().getAreaOfInterest(), crs);
142:                mp.setReset(true);
143:                mp.repaint();
144:            }
145:
146:            public void load(WMSMapLayer layer) throws Exception {
147:
148:                Envelope2D env = layer.getGrid().getEnvelope2D();
149:                Envelope en = new Envelope(env.x, env.y, env.width, env.height);
150:                mp.setMapArea(en);
151:
152:                CoordinateReferenceSystem crs = layer.getGrid()
153:                        .getCoordinateReferenceSystem();
154:                if (crs == null)
155:                    crs = DefaultGeographicCRS.WGS84;
156:                if (context == null) {
157:                    context = new DefaultMapContext(crs);
158:                    mp.setContext(context);
159:                }
160:
161:                //this allows us to listen for resize events and ask for the right size image
162:                mp.addComponentListener(layer);
163:                context.addLayer(layer);
164:                context.addMapBoundsListener(layer);
165:                // System.out.println(context.getLayerBounds());
166:                // mp.setHighlightLayer(context.getLayer(0));
167:
168:                if (renderer == null) {
169:                    if (false) {
170:                        renderer = new StreamingRenderer();
171:                        HashMap hints = new HashMap();
172:                        hints.put("memoryPreloadingEnabled", Boolean.TRUE);
173:                        renderer.setRendererHints(hints);
174:                    } else {
175:                        renderer = new StreamingRenderer();
176:                        HashMap hints = new HashMap();
177:                        hints.put("memoryPreloadingEnabled", Boolean.FALSE);
178:                        renderer.setRendererHints(hints);
179:                        RenderingHints rhints = new RenderingHints(
180:                                RenderingHints.KEY_ANTIALIASING,
181:                                RenderingHints.VALUE_ANTIALIAS_ON);
182:                        ((StreamingRenderer) renderer).setJava2DHints(rhints);
183:                    }
184:                    mp.setRenderer(renderer);
185:
186:                }
187:                // mp.getRenderer().addLayer(new RenderedMapScale());
188:                frame.repaint();
189:                frame.doLayout();
190:            }
191:
192:            public void actionPerformed(ActionEvent e) {
193:                WMSChooser wmc = new WMSChooser(frame, "Select WMS", true);
194:                //wmc.setServer("http://www.geovista.psu.edu/geoserver/wms");
195:                wmc.setVisible(true);
196:                int returnVal = wmc.getLayer();
197:                if (returnVal == -1) {
198:                    return;
199:                }
200:                WebMapServer wms = wmc.getWms();
201:                Layer l = (Layer) wmc.getLayers().get(returnVal);
202:                WMSMapLayer layer = new WMSMapLayer(wms, l);
203:                try {
204:                    load(layer);
205:                } catch (Exception e1) {
206:                    // TODO Auto-generated catch block
207:                    e1.printStackTrace();
208:                }
209:            }
210:
211:            /**
212:             * @param args
213:             */
214:            public static void main(String[] args) throws Exception {
215:                WMSViewer mapV = new WMSViewer();
216:
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.