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


001:        /*
002:         * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
003:         * for visualizing and manipulating spatial features with geometry and attributes.
004:         *
005:         * JUMP is Copyright (C) 2003 Vivid Solutions
006:         *
007:         * This program implements extensions to JUMP and is
008:         * Copyright (C) 2005 Integrated Systems Analysts, Inc.
009:         * 
010:         * This program is free software; you can redistribute it and/or
011:         * modify it under the terms of the GNU General Public License
012:         * as published by the Free Software Foundation; either version 2
013:         * of the License, or (at your option) any later version.
014:         * 
015:         * This program is distributed in the hope that it will be useful,
016:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
017:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
018:         * GNU General Public License for more details.
019:         * 
020:         * You should have received a copy of the GNU General Public License
021:         * along with this program; if not, write to the Free Software
022:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
023:         * 
024:         * For more information, contact:
025:         *
026:         * Integrated Systems Analysts, Inc.
027:         * 630C Anchors St., Suite 101
028:         * Fort Walton Beach, Florida
029:         * USA
030:         *
031:         * (850)862-7321
032:         */
033:        package org.openjump.core.ui.plugin.customize;
034:
035:        import bsh.EvalError;
036:        import bsh.Interpreter;
037:
038:        import com.vividsolutions.jump.I18N;
039:        import com.vividsolutions.jump.workbench.plugin.EnableCheck;
040:        import com.vividsolutions.jump.workbench.plugin.PlugInContext;
041:        import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog;
042:        import com.vividsolutions.jump.workbench.ui.MenuNames;
043:        import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
044:        import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
045:        import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
046:
047:        import java.io.File;
048:        import java.io.IOException;
049:
050:        import javax.swing.event.MenuEvent;
051:        import javax.swing.event.MenuListener;
052:        import javax.swing.JComponent;
053:        import javax.swing.JMenu;
054:        import javax.swing.JMenuItem;
055:        import java.awt.event.ActionListener;
056:        import java.awt.event.ActionEvent;
057:
058:        import org.apache.log4j.Logger;
059:
060:        /**
061:         * This OpenJUMP PlugIn adds the capability to launch a scripted file from the menu.
062:         * The original design is from ISA (Larry Becker - 2005)
063:         * Modified by Michaël Michaud in order to make hirarchical menus possible.
064:         */
065:        public class BeanToolsPlugIn extends AbstractPlugIn {
066:
067:            private static final Logger LOG = Logger
068:                    .getLogger(BeanToolsPlugIn.class);
069:
070:            private String lastcmd = "";
071:            private String beanShellDirName;
072:            private TaskMonitorManager taskMonitorManager;
073:            private FeatureInstaller featureInstaller;
074:
075:            public void initialize(PlugInContext context) throws Exception {
076:                File plugInDirectory = context.getWorkbenchContext()
077:                        .getWorkbench().getPlugInManager().getPlugInDirectory();
078:                if (null == plugInDirectory || !plugInDirectory.exists()) {
079:                    LOG
080:                            .debug("BeanTools plugin has not been initialized : the plugin directory is missing");
081:                    return;
082:                }
083:                beanShellDirName = plugInDirectory.getPath()
084:                        + File.separator
085:                        + I18N
086:                                .get("ui.plugin.customize.BeanToolsPlugIn.BeanTools");
087:                File beanShellDir = new File(beanShellDirName);
088:                featureInstaller = context.getFeatureInstaller();
089:                taskMonitorManager = new TaskMonitorManager();
090:                if (beanShellDir.exists()) {
091:                    scanBeanShellDir(beanShellDir, context);
092:                }
093:            }
094:
095:            /**
096:             * Extracts the filepath as a String from dir to file
097:             */
098:            private String ancestors(File dir, File file) throws IOException {
099:                String path = file.getCanonicalPath();
100:                return path.substring(path.lastIndexOf(dir.getName()), path
101:                        .lastIndexOf(file.getName()));
102:            }
103:
104:            /**
105:             * Scan beanShellDir iteratively and makes a script menu-item from each
106:             * .bsh file.
107:             */
108:            private void scanBeanShellDir(final File file,
109:                    final PlugInContext context) throws IOException {
110:                // iterates over subdirectories
111:                if (file.isDirectory()) {
112:                    for (File f : file.listFiles()) {
113:                        scanBeanShellDir(f, context);
114:                    }
115:                }
116:                // add a menu item for the beanshell script
117:                else if (file.getName().endsWith(".bsh")) {
118:                    File beanShellDir = new File(beanShellDirName);
119:                    String ancestors = ancestors(beanShellDir, file);
120:                    String shellName = file.getName().substring(0,
121:                            file.getName().length() - 4);
122:                    JMenu menu = featureInstaller
123:                            .menuBarMenu(MenuNames.CUSTOMIZE);
124:                    if (menu == null) {
125:                        menu = (JMenu) featureInstaller.installMnemonic(
126:                                new JMenu(I18N.get(MenuNames.CUSTOMIZE)),
127:                                featureInstaller.menuBar());
128:                        featureInstaller.menuBar().add(menu);
129:                    }
130:                    JMenu parent = featureInstaller.createMenusIfNecessary(
131:                            menu, ancestors.split(File.separator.replace("\\",
132:                                    "\\\\")));
133:                    final JMenuItem menuItem = featureInstaller
134:                            .installMnemonic(new JMenuItem(shellName), parent);
135:                    final ActionListener listener = AbstractPlugIn
136:                            .toActionListener(this , context
137:                                    .getWorkbenchContext(), taskMonitorManager);
138:                    menuItem.addActionListener(new ActionListener() {
139:                        // if one press this menu item
140:                        public void actionPerformed(ActionEvent e) {
141:                            // change the lastcmd path
142:                            if (e != null)
143:                                lastcmd = file.getPath();
144:                            // execute this plugin execute method
145:                            listener.actionPerformed(e);
146:                        }
147:                    });
148:                    parent.add(menuItem);
149:                }
150:                // file is not a directory and it does not end with .bsh
151:                else
152:                    ;
153:            }
154:
155:            public String getName() {
156:                return "Bean Tools";
157:            }
158:
159:            public boolean execute(final PlugInContext context)
160:                    throws Exception {
161:                ToolboxDialog toolbox = new ToolboxDialog(context
162:                        .getWorkbenchContext());
163:                try {
164:                    Interpreter interpreter = new Interpreter();
165:                    interpreter
166:                            .setClassLoader(toolbox.getContext().getWorkbench()
167:                                    .getPlugInManager().getClassLoader());
168:                    interpreter.set("wc", toolbox.getContext());
169:                    interpreter.eval("setAccessibility(true)");
170:                    interpreter.eval("import com.vividsolutions.jts.geom.*");
171:                    interpreter
172:                            .eval("import com.vividsolutions.jump.feature.*");
173:                    //interpreter.source(beanShellDirName + File.separator + lastcmd + ".bsh");
174:                    interpreter.source(lastcmd);
175:                } catch (EvalError e) {
176:                    toolbox.getContext().getErrorHandler().handleThrowable(e);
177:                }
178:                return true;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.