Source Code Cross Referenced for HighlightManager.java in  » GIS » GeoTools-2.4.1 » org » geotools » gui » swing » 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.gui.swing 
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.gui.swing;
017:
018:        /**
019:         * a simple highlight manager
020:         * @author Ian Turton
021:         */
022:        import java.awt.Rectangle;
023:        import java.awt.event.MouseEvent;
024:        import java.awt.event.MouseMotionAdapter;
025:        import javax.swing.event.EventListenerList;
026:        import com.vividsolutions.jts.geom.Coordinate;
027:        import com.vividsolutions.jts.geom.Envelope;
028:        import com.vividsolutions.jts.geom.Geometry;
029:        import com.vividsolutions.jts.geom.GeometryFactory;
030:        import org.opengis.filter.Filter;
031:        import org.opengis.filter.FilterFactory2;
032:        import org.geotools.filter.IllegalFilterException;
033:        import org.geotools.gui.swing.event.HighlightChangeListener;
034:        import org.geotools.gui.swing.event.HighlightChangedEvent;
035:        import org.geotools.map.MapLayer;
036:
037:        public class HighlightManager extends MouseMotionAdapter {
038:            EventListenerList listeners = new EventListenerList();
039:
040:            /**
041:             * the layer to highlight
042:             */
043:            MapLayer highlightLayer;
044:
045:            /**
046:             * The filterfactory needed to create the highlight filter
047:             */
048:            FilterFactory2 ff = (FilterFactory2) org.geotools.factory.CommonFactoryFinder
049:                    .getFilterFactory(null);
050:
051:            /**
052:             * the geometry factory to convert the mouse point to a jts.Point
053:             */
054:            GeometryFactory gf = new GeometryFactory();
055:
056:            /**
057:             * stores our best guess as to what the name of the geometry
058:             * in the highlighted layer is.
059:             */
060:            String geomName;
061:            Filter lastFilter = null;
062:
063:            public HighlightManager(MapLayer layer) {
064:                setHighlightLayer(layer);
065:            }
066:
067:            /**
068:             * listens for mouse moved events
069:             * @param e - MouseEvent
070:             */
071:            public void mouseMoved(MouseEvent e) {
072:                if (highlightLayer == null) {
073:                    return;
074:                }
075:
076:                Rectangle bounds = e.getComponent().getBounds();
077:                JMapPane pane = (JMapPane) e.getSource();
078:                Envelope mapArea = pane.mapArea;
079:                double x = (double) (e.getX());
080:                double y = (double) (e.getY());
081:                double width = mapArea.getWidth();
082:                double height = mapArea.getHeight();
083:
084:                double mapX = ((x * width) / (double) bounds.width)
085:                        + mapArea.getMinX();
086:                double mapY = (((bounds.getHeight() - y) * height) / (double) bounds.height)
087:                        + mapArea.getMinY();
088:                Filter f = null;
089:
090:                Geometry geometry = gf.createPoint(new Coordinate(mapX, mapY));
091:
092:                try {
093:                    Filter bb = ff.bbox(ff.property(geomName), mapArea
094:                            .getMinX(), mapArea.getMinY(), mapArea.getMaxX(),
095:                            mapArea.getMaxY(), pane.getContext()
096:                                    .getCoordinateReferenceSystem().toString());
097:                    f = ff
098:                            .contains(ff.property(geomName), ff
099:                                    .literal(geometry));
100:                    f = ff.and(bb, f);
101:                    if (f == lastFilter) {
102:                        return;
103:                    }
104:
105:                    lastFilter = f;
106:                    this .highlightChanged(e.getSource(), f);
107:                } catch (IllegalFilterException ex) {
108:                    // TODO Auto-generated catch block
109:                    ex.printStackTrace();
110:                }
111:            }
112:
113:            /**
114:             * add a HighlightChangedListener to this manager, note this need not
115:             * be a map which is why we pass a filter back not a map point.
116:             * @param l - the listener
117:             */
118:            public void addHighlightChangeListener(HighlightChangeListener l) {
119:                listeners.add(HighlightChangeListener.class, l);
120:            }
121:
122:            /**
123:             * Remove a highlightlistener
124:             * @param l - the listener
125:             */
126:            public void removeHightlightChangeListener(HighlightChangeListener l) {
127:                listeners.remove(HighlightChangeListener.class, l);
128:            }
129:
130:            /**
131:             * notify listeners that the highlight has changed
132:             * @param source - where the mousemovement came from
133:             * @param filter - the filter which selects the
134:             * highlighted feature(s)
135:             */
136:            public void highlightChanged(Object source, Filter filter) {
137:                HighlightChangeListener[] l = (HighlightChangeListener[]) listeners
138:                        .getListeners(HighlightChangeListener.class);
139:                HighlightChangedEvent ev = new HighlightChangedEvent(source,
140:                        filter);
141:
142:                for (int i = 0; i < l.length; i++) {
143:                    l[i].highlightChanged(ev);
144:                }
145:            }
146:
147:            /**
148:             * get the highlighted layer
149:             * @return - the layer
150:             */
151:            public MapLayer getHighlightLayer() {
152:                return highlightLayer;
153:            }
154:
155:            /**
156:             * sets the highlighted layer
157:             * @param highlightLayer - the layer
158:             */
159:            public void setHighlightLayer(MapLayer highlightLayer) {
160:                this .highlightLayer = highlightLayer;
161:
162:                if (this .highlightLayer != null) {
163:                    geomName = this .highlightLayer.getFeatureSource()
164:                            .getSchema().getDefaultGeometry().getName();
165:
166:                    if ((geomName == null) || (geomName == "")) {
167:                        geomName = "the_geom";
168:                    }
169:                }
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.