Source Code Cross Referenced for DemoGUI.java in  » GIS » GeoTools-2.4.1 » org » example » geotools » base » 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.example.geotools.base 
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:         *    (C) 2006, Adrian Custer, assigned to the PMC.
006:         *
007:         *    This file is hereby placed into the Public Domain. This means anyone is
008:         *    free to do whatever they wish with this file. Use it well and enjoy!
009:         */
010:
011:        package org.example.geotools.base;
012:
013:        import java.awt.BorderLayout;
014:        import java.awt.Color;
015:        import java.awt.Container;
016:        import java.awt.Dimension;
017:        import java.awt.Panel;
018:        import java.awt.ScrollPane;
019:        import java.awt.event.ActionEvent;
020:        import java.awt.event.ActionListener;
021:
022:        import javax.swing.Action;
023:        import javax.swing.Box;
024:        import javax.swing.BoxLayout;
025:        import javax.swing.ImageIcon;
026:        import javax.swing.JButton;
027:        import javax.swing.JFrame;
028:        import javax.swing.JLabel;
029:        import javax.swing.JOptionPane;
030:        import javax.swing.JPanel;
031:        import javax.swing.JTextArea;
032:        import javax.swing.JToolBar;
033:        import javax.swing.WindowConstants;
034:
035:        import org.geotools.gui.swing.JMapPane;
036:        import org.geotools.gui.swing.PanAction;
037:        import org.geotools.gui.swing.ResetAction;
038:        import org.geotools.gui.swing.SelectAction;
039:        import org.geotools.gui.swing.ZoomInAction;
040:        import org.geotools.gui.swing.ZoomOutAction;
041:        import org.geotools.map.DefaultMapContext;
042:        import org.geotools.map.DefaultMapLayer;
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.FactoryException;
049:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
050:
051:        /**
052:         * The DemoGUI class which produces the top level JFrame for the introductory 
053:         * demo application. 
054:         * 
055:         * @author  Adrian Custer
056:         * 
057:         * @version 0.03
058:         * @since   2.3-M0
059:         *
060:         */
061:        public class DemoGUI {
062:
063:            /* A link to the DemoBase instance, to pass control back to the 'button*'
064:             * methods in that instance. */
065:            final DemoBase demoBase;
066:
067:            /* GUI frame, pane and extras */
068:            final JFrame frame;
069:            JPanel visPanel;
070:            ScrollPane infoSP;
071:            JToolBar jtb;
072:            JLabel text;
073:            JButton quitButton;
074:            JButton createButton;
075:            JButton styleButton;
076:            JButton renderButton;
077:            JButton projectButton;
078:            JButton filterButton;
079:            JButton captureButton;
080:            JButton saveButton;
081:            JButton commitButton;
082:            JButton analyzeButton;
083:            JTextArea textArea;
084:
085:            /* Display elements */
086:            JMapPane jmp;
087:            MapContext context;
088:            GTRenderer renderer;
089:
090:            com.vividsolutions.jts.geom.Envelope worldbounds;
091:
092:            /*
093:             * Create the Demo's GUI.
094:             * 
095:             * Geotools users can skip this swing code, go to create_FeatureSource...
096:             * 
097:             */
098:            public DemoGUI(DemoBase db) {
099:
100:                this .demoBase = db;
101:
102:                frame = new JFrame("Geotools Demo");
103:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
104:                frame.setBounds(20, 20, 800, 500);
105:                //        frame.setBackground(Color.cyan);
106:
107:                Container contentPane = frame.getContentPane();
108:                BoxLayout layout = new BoxLayout(contentPane, BoxLayout.X_AXIS);
109:                contentPane.setLayout(layout);
110:                //        contentPane.setBackground(Color.red);
111:
112:                JPanel buttonPanel = new JPanel();
113:                //        buttonPanel.setBackground(Color.blue);
114:                buttonPanel.setVisible(true);
115:                visPanel = new JPanel();
116:                //        visPanel.setBackground(Color.gray);
117:                visPanel.setVisible(true);
118:
119:                contentPane.add(Box.createRigidArea(new Dimension(10, 0)));
120:                contentPane.add(buttonPanel);
121:                contentPane.add(Box.createRigidArea(new Dimension(10, 0)));
122:                contentPane.add(visPanel);
123:                contentPane.add(Box.createRigidArea(new Dimension(10, 0)));
124:
125:                /* The action button Panel */
126:                JPanel actionButtonPanel = new JPanel();
127:                //        actionButtonPanel.setBackground(Color.green);
128:                actionButtonPanel.setVisible(true);
129:
130:                BoxLayout aBPlayout = new BoxLayout(actionButtonPanel,
131:                        BoxLayout.Y_AXIS);
132:                actionButtonPanel.setLayout(aBPlayout);
133:
134:                int BUTTON_WIDTH = 100;
135:                createButton = new JButton("1. Create Features");
136:                createButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
137:                actionButtonPanel.add(createButton);
138:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
139:                styleButton = new JButton("2. Style Features");
140:                styleButton.setEnabled(false);
141:                styleButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
142:                actionButtonPanel.add(styleButton);
143:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
144:                renderButton = new JButton("3. Render Map");
145:                renderButton.setEnabled(false);
146:                renderButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
147:                actionButtonPanel.add(renderButton);
148:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
149:                projectButton = new JButton("4. Project Map");
150:                projectButton.setEnabled(false);
151:                projectButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
152:                actionButtonPanel.add(projectButton);
153:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
154:                filterButton = new JButton("5. Filter Features");
155:                filterButton.setEnabled(false);
156:                filterButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
157:                actionButtonPanel.add(filterButton);
158:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
159:                captureButton = new JButton("6. Capture Image");
160:                captureButton.setEnabled(false);
161:                captureButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
162:                actionButtonPanel.add(captureButton);
163:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
164:                saveButton = new JButton("7. Save to file");
165:                saveButton.setEnabled(false);
166:                saveButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
167:                actionButtonPanel.add(saveButton);
168:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
169:                commitButton = new JButton("8. Commit to WFS");
170:                commitButton.setEnabled(false);
171:                commitButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
172:                actionButtonPanel.add(commitButton);
173:                actionButtonPanel.add(Box.createRigidArea(new Dimension(0, 6)));
174:                analyzeButton = new JButton("9. Analyze network");
175:                analyzeButton.setEnabled(false);
176:                analyzeButton.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
177:                actionButtonPanel.add(analyzeButton);
178:
179:                /* The button Panel */
180:                BoxLayout buttonPanelBoxLayout = new BoxLayout(buttonPanel,
181:                        BoxLayout.Y_AXIS);
182:                buttonPanel.setLayout(buttonPanelBoxLayout);
183:                buttonPanel.add(Box.createRigidArea(new Dimension(0, 10)));
184:                //TODO: verify the file can be found
185:                java.net.URL imgURL = DemoGUI.class
186:                        .getResource("/GeotoolsBoxLogo.png");
187:                //        System.out.println(imgURL);
188:                ImageIcon icon = new ImageIcon(imgURL, "The Geotools Logo");
189:                JLabel iconLabel = new JLabel(icon);
190:                buttonPanel.add(iconLabel);
191:                buttonPanel.add(Box.createRigidArea(new Dimension(0, 20)));
192:                buttonPanel.add(actionButtonPanel);
193:                buttonPanel.add(Box.createVerticalGlue());
194:                JButton quitButton = new JButton("QUIT");
195:                buttonPanel.add(quitButton);
196:                buttonPanel.add(Box.createRigidArea(new Dimension(0, 10)));
197:
198:                quitButton.addActionListener(new ActionListener() {
199:                    public void actionPerformed(ActionEvent e) {
200:
201:                        frame.dispose();
202:
203:                    }
204:                });
205:
206:                createButton.addActionListener(new ActionListener() {
207:                    public void actionPerformed(ActionEvent e) {
208:
209:                        createButton.setEnabled(false);
210:                        demoBase.buttonCreateFeatures();
211:                        styleButton.setEnabled(true);
212:                    }
213:                });
214:                styleButton.addActionListener(new ActionListener() {
215:                    public void actionPerformed(ActionEvent e) {
216:
217:                        styleButton.setEnabled(false);
218:                        demoBase.buttonCreateStyles();
219:                        renderButton.setEnabled(true);
220:                    }
221:                });
222:                renderButton.addActionListener(new ActionListener() {
223:                    public void actionPerformed(ActionEvent e) {
224:
225:                        renderButton.setEnabled(false);
226:                        demoBase.buttonCreateMap();
227:                        projectButton.setEnabled(true);
228:                    }
229:                });
230:                projectButton.addActionListener(new ActionListener() {
231:                    public void actionPerformed(ActionEvent e) {
232:
233:                        projectButton.setEnabled(false);
234:                        demoBase.buttonProjectMap();
235:                        //DemoApp.filterButton.setEnabled(true);
236:
237:                    }
238:                });
239:                filterButton.addActionListener(new ActionListener() {
240:                    public void actionPerformed(ActionEvent e) {
241:
242:                        filterButton.setEnabled(false);
243:
244:                        captureButton.setEnabled(true);
245:                    }
246:                });
247:                captureButton.addActionListener(new ActionListener() {
248:                    public void actionPerformed(ActionEvent e) {
249:
250:                        captureButton.setEnabled(false);
251:                        //              DemoBase.captureImage();
252:                        saveButton.setEnabled(true);
253:                    }
254:                });
255:                saveButton.addActionListener(new ActionListener() {
256:                    public void actionPerformed(ActionEvent e) {
257:
258:                        saveButton.setEnabled(false);
259:
260:                        commitButton.setEnabled(true);
261:
262:                    }
263:                });
264:                commitButton.addActionListener(new ActionListener() {
265:                    public void actionPerformed(ActionEvent e) {
266:
267:                        commitButton.setEnabled(false);
268:
269:                        analyzeButton.setEnabled(true);
270:
271:                    }
272:                });
273:                analyzeButton.addActionListener(new ActionListener() {
274:                    public void actionPerformed(ActionEvent e) {
275:
276:                        analyzeButton.setEnabled(false);
277:
278:                    }
279:                });
280:
281:                /* The info Text Area */
282:                textArea = new JTextArea();
283:                textArea.append("Welcome to the Geotools Demo.\n\n");
284:                textArea.append("Click on the \"Create\" button to start.\n\n");
285:                infoSP = new ScrollPane();
286:                infoSP.add(textArea);
287:
288:                //TOOD: use a Logger to output to the textArea. Not sure how to do this
289:                //without using classes: annonymous inner class?
290:                //        OutputStream os = new  anOutputStream() extends OutputStream {
291:                //              public void write( int b ) throws IOException {
292:                //                  // append the data as characters to the JTextArea control
293:                //                  DemoApp.textArea.append( String.valueOf( ( char )b ) );
294:                //              }
295:                //        };
296:                //        StreamHandler sh = new StreamHandler(os , new Formatter());
297:
298:                /* The visuals Panel */
299:                BoxLayout visPanelBoxLayout = new BoxLayout(visPanel,
300:                        BoxLayout.Y_AXIS);
301:                visPanel.setLayout(visPanelBoxLayout);
302:                visPanel.add(Box.createRigidArea(new Dimension(0, 10)));
303:                visPanel.add(infoSP);
304:                visPanel.add(Box.createRigidArea(new Dimension(0, 10)));
305:
306:                contentPane.setVisible(true);
307:                contentPane.doLayout();
308:                frame.doLayout();
309:                frame.setVisible(true);
310:                frame.repaint();
311:
312:            }
313:
314:            /*
315:             * Create a GUI map displayer.
316:             * 
317:             * This is all Swing stuff for the JMapPane.
318:             * 
319:             */
320:            public void initialize_JMapPane() {
321:                textArea.append("Start: Initialize the GUI.\n");
322:
323:                Panel mapGUI = new Panel();
324:                mapGUI.setLayout(new BorderLayout());
325:                jmp = new JMapPane();
326:                jmp.setBackground(Color.white);
327:
328:                /* Renderer */
329:                renderer = new StreamingRenderer();
330:
331:                /* Context */
332:                context = new DefaultMapContext(DefaultGeographicCRS.WGS84);
333:                context.setAreaOfInterest(demoBase.envlp_NoEdges2);
334:
335:                /* Add to JMapPane */
336:                jmp.setRenderer(renderer);
337:                jmp.setContext(context);
338:
339:                /* The toolbar */
340:                jtb = new JToolBar();
341:                Action zoomIn = new ZoomInAction(jmp);
342:                Action zoomOut = new ZoomOutAction(jmp);
343:                Action pan = new PanAction(jmp);
344:                Action select = new SelectAction(jmp);
345:                Action reset = new ResetAction(jmp);
346:                jtb.add(zoomIn);
347:                jtb.add(zoomOut);
348:                jtb.add(pan);
349:                jtb.addSeparator();
350:                jtb.add(reset);
351:                jtb.addSeparator();
352:                jtb.add(select);
353:                final JButton button = new JButton();
354:                button.setText("CRS");
355:                button.setToolTipText("Change map prjection");
356:                button.addActionListener(new ActionListener() {
357:                    public void actionPerformed(ActionEvent e) {
358:
359:                        String code = JOptionPane.showInputDialog(button,
360:                                "Coordinate Reference System:", "EPSG:4326");
361:                        try {
362:                            CoordinateReferenceSystem crs = CRS.decode(code);
363:                            jmp.getContext().setAreaOfInterest(
364:                                    jmp.getContext().getAreaOfInterest(), crs);
365:                            jmp.setReset(true);
366:                            jmp.repaint();
367:
368:                        } catch (FactoryException fe) {
369:                            JOptionPane.showMessageDialog(button, fe
370:                                    .getMessage(), fe.getClass().toString(),
371:                                    JOptionPane.ERROR_MESSAGE);
372:                            return;
373:                        }
374:                    }
375:                });
376:                jtb.add(button);
377:                mapGUI.add(jtb, BorderLayout.NORTH);
378:                mapGUI.add(jmp);
379:
380:                infoSP.setSize(new Dimension(300, 60));
381:                BoxLayout visPanelBoxLayout = new BoxLayout(visPanel,
382:                        BoxLayout.Y_AXIS);
383:                visPanel.setLayout(visPanelBoxLayout);
384:                visPanel.add(Box.createRigidArea(new Dimension(0, 10)));
385:                visPanel.add(infoSP);
386:                visPanel.add(Box.createRigidArea(new Dimension(0, 10)));
387:                visPanel.add(mapGUI);
388:                visPanel.add(Box.createRigidArea(new Dimension(0, 10)));
389:                frame.getContentPane().doLayout();
390:                infoSP.setSize(new Dimension(3, 3));
391:                frame.getContentPane().doLayout();
392:                frame.setVisible(true);
393:
394:                textArea.append("  End: Initialized the GUI.\n");
395:
396:            }
397:
398:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.