Source Code Cross Referenced for InstallKeyPanPlugIn.java in  » GIS » openjump » org » openjump » core » ui » plugin » view » 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 » openjump » org.openjump.core.ui.plugin.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * 
003:         */package org.openjump.core.ui.plugin.view;
004:
005:        import java.awt.event.KeyEvent;
006:        import java.awt.geom.NoninvertibleTransformException;
007:
008:        import javax.swing.JInternalFrame;
009:
010:        import com.vividsolutions.jts.geom.Envelope;
011:        import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
012:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
013:        import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
014:        import com.vividsolutions.jump.workbench.ui.TaskFrame;
015:        import com.vividsolutions.jump.workbench.ui.Viewport;
016:
017:        /**
018:         * Plug in for navigation with keyboards keys. <br/>
019:         * Navigation is as follows:<br/>
020:         * Arrows keys move the viewport.<br/>
021:         * Page down and up are zoom in and zoom out, respectively<br/>
022:         * Home key zooms in or out to full extent<br/>
023:         * Pan and zoom percentage is, by default, 20%
024:         * 
025:         * @author Ugo Taddei <taddei@lat-lon.de>
026:         *
027:         */
028:        public class InstallKeyPanPlugIn extends AbstractPlugIn {
029:
030:            private static final int NORTH = 0;
031:            private static final int EAST = 1;
032:            private static final int SOUTH = 2;
033:            private static final int WEST = 3;
034:
035:            private static final int ZOOM_IN = 4;
036:            private static final int ZOOM_OUT = 5;
037:
038:            /* matrix defining directions */
039:            private static final int[][] DIRECTIONS = { { 0, -1, 0, -1 }, //NORTH
040:                    { -1, 0, -1, 0 }, //EAST
041:                    { 0, 1, 0, 1 }, { 1, 0, 1, 0 }, { 1, 1, -1, -1 }, //ZOOM_IN
042:                    { -1, -1, 1, 1 } };//ZOOM_OUT
043:
044:            private static double panPercentage;
045:
046:            /**
047:             * Default constructor 
048:             */
049:            public InstallKeyPanPlugIn() {
050:                this (0.2);
051:            }
052:
053:            /**
054:             * 
055:             * Creates a new plug-in with pan_percentage as pan percentage value
056:             *   
057:             * pan_percentage The value in percent of screen size to pan/zoom. Accepted 
058:             * values are in the range 0 < percentage <= 1
059:             */
060:            public InstallKeyPanPlugIn(double panPercentag) {
061:                super ();
062:                setPanPercentage(panPercentag);
063:            }
064:
065:            public boolean execute(PlugInContext context) throws Exception {
066:                context.getLayerViewPanel().getViewport().zoomToFullExtent();
067:                return true;
068:            }
069:
070:            private static Envelope createEnvelopeFromDirection(
071:                    Envelope oldEnvelope, int direction) {
072:
073:                double oldWidth = panPercentage * oldEnvelope.getWidth();
074:                double oldHeight = panPercentage * oldEnvelope.getHeight();
075:
076:                double dxPlus = DIRECTIONS[direction][0] * oldWidth;
077:                double dyPlus = DIRECTIONS[direction][1] * oldHeight;
078:                double dxMinus = DIRECTIONS[direction][2] * oldWidth;
079:                double dyMinus = DIRECTIONS[direction][3] * oldHeight;
080:
081:                return new Envelope(oldEnvelope.getMinX() - dxMinus,
082:                        oldEnvelope.getMaxX() - dxPlus, oldEnvelope.getMinY()
083:                                - dyMinus, oldEnvelope.getMaxY() - dyPlus);
084:            }
085:
086:            public boolean pan(JInternalFrame jif, int direction) {
087:
088:                if (jif instanceof  TaskFrame) {
089:                    TaskFrame taskFrame = (TaskFrame) jif;
090:                    LayerViewPanel lvp = taskFrame.getLayerViewPanel();
091:                    Viewport vp = lvp.getViewport();
092:                    Envelope oldEnvelope = vp.getEnvelopeInModelCoordinates();
093:
094:                    try {
095:                        vp.zoom(createEnvelopeFromDirection(oldEnvelope,
096:                                direction));
097:                    } catch (NoninvertibleTransformException e1) {
098:                        e1.printStackTrace();
099:                        return false;
100:                    }
101:                }
102:                return true;
103:            }
104:
105:            public void initialize(PlugInContext context) throws Exception {
106:                super .initialize(context);
107:
108:                AbstractPlugIn[] plugIns = { this , new PanHelper(NORTH),
109:                        new PanHelper(EAST), new PanHelper(SOUTH),
110:                        new PanHelper(WEST), new PanHelper(ZOOM_IN),
111:                        new PanHelper(ZOOM_OUT) };
112:
113:                int[] keys = { KeyEvent.VK_HOME, KeyEvent.VK_UP,
114:                        KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT,
115:                        KeyEvent.VK_PAGE_DOWN, KeyEvent.VK_PAGE_UP };
116:
117:                for (int i = 0; i < keys.length; i++) {
118:                    context.getWorkbenchContext().getWorkbench().getFrame()
119:                            .addKeyboardShortcut(keys[i], 0, plugIns[i], null);
120:
121:                }
122:
123:            }
124:
125:            public String getName() {
126:                return "";
127:            }
128:
129:            /**
130:             * Get the pan/zoom percentage, a value between 0 and 1. Deafult is 0.25 (=25%) 
131:             * @return
132:             */
133:            public static double getPanPercentage() {
134:                return 2 * panPercentage;
135:            }
136:
137:            /**
138:             * Set the pan percentage. Legal values are between greater than 0 and less than 
139:             * or equal to 1.0
140:             * @param panPercentage The value in percent of screen size to pan/zoom. Accepted 
141:             * values are in the range 0 < percentage <= 1
142:             */
143:            public static void setPanPercentage(double panPercent) {
144:                if (panPercent <= 0 || panPercent > 1d) {
145:                    throw new IllegalArgumentException(
146:                            "Accepted values are in the "
147:                                    + " range 0 < percentage <= 1");
148:                }
149:                //have percentage, otherwise it's percentage value in each direction
150:                //making it twice as much!
151:                panPercentage = panPercent / 2d;
152:            }
153:
154:            /**
155:             * Helper class to pan in the direction given in constructor 
156:             */
157:            private class PanHelper extends AbstractPlugIn {
158:                private final int direction;
159:
160:                public PanHelper(int direction) {
161:                    this .direction = direction;
162:                }
163:
164:                public boolean execute(PlugInContext context) throws Exception {
165:                    return pan(context.getWorkbenchFrame()
166:                            .getActiveInternalFrame(), direction);
167:                }
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.