Source Code Cross Referenced for JRefactory.java in  » UML » jrefactory » org » acm » seguin » ide » jedit » 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 » UML » jrefactory » org.acm.seguin.ide.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            This program is free software; you can redistribute it and/or
003:            modify it under the terms of the GNU General Public License
004:            as published by the Free Software Foundation; either version 2
005:            of the License, or any later version.
006:            This program is distributed in the hope that it will be useful,
007:            but WITHOUT ANY WARRANTY; without even the implied warranty of
008:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
009:            GNU General Public License for more detaProjectTreeSelectionListenerils.
010:            You should have received a copy of the GNU General Public License
011:            along with this program; if not, write to the Free Software
012:            Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
013:         */
014:        package org.acm.seguin.ide.jedit;
015:
016:        import java.awt.BorderLayout;
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.ActionListener;
019:
020:        import java.io.File;
021:        import java.util.ArrayList;
022:        import java.util.HashMap;
023:        import java.util.HashSet;
024:        import java.util.Iterator;
025:
026:        import javax.swing.JButton;
027:        import javax.swing.JFileChooser;
028:        import javax.swing.JPanel;
029:        import javax.swing.JRootPane;
030:        import javax.swing.JTabbedPane;
031:
032:        import edu.umd.cs.findbugs.DetectorFactoryCollection;
033:        import org.acm.seguin.ide.command.CommandLineSourceBrowser;
034:        import org.acm.seguin.ide.common.ASTViewerPane;
035:        import org.acm.seguin.ide.common.CPDDuplicateCodeViewer;
036:        import org.acm.seguin.ide.common.CodingStandardsViewer;
037:        import org.acm.seguin.ide.common.PackageSelectorPanel;
038:        import org.acm.seguin.ide.common.SourceBrowser;
039:        import org.acm.seguin.ide.common.PluginSourceBrowser;
040:        import net.sourceforge.jrefactory.action.CurrentSummary;
041:        import org.acm.seguin.ide.jedit.action.Action;
042:        import org.acm.seguin.ide.jedit.action.HideAction;
043:        import org.acm.seguin.ide.jedit.action.ReloadAction;
044:        import org.acm.seguin.ide.jedit.action.ReloadAllAction;
045:        import org.acm.seguin.ide.jedit.action.ShowAction;
046:
047:        import org.acm.seguin.ide.jedit.event.JRefactoryEvent;
048:        import org.acm.seguin.ide.jedit.event.JRefactoryListener;
049:        import org.acm.seguin.io.AllFileFilter;
050:        import org.acm.seguin.project.Project;
051:        import org.acm.seguin.tools.RefactoryInstaller;
052:        import net.sourceforge.jrefactory.uml.loader.ReloaderSingleton;
053:        import org.gjt.sp.jedit.EBComponent;
054:        import org.gjt.sp.jedit.EBMessage;
055:        import org.gjt.sp.jedit.EditBus;
056:        import org.gjt.sp.jedit.EditPlugin;
057:
058:        import org.gjt.sp.jedit.View;
059:        import org.gjt.sp.jedit.jEdit;
060:        import org.gjt.sp.util.Log;
061:
062:        /**
063:         *  Main GUI for JRefactory
064:         *
065:         *@author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike Atkinson</a>
066:         *@created    23 July 2003
067:         *@version    $Id: JRefactory.java,v 1.11 2004/05/06 20:59:05 mikeatkinson Exp $
068:         *@since      0.0.1
069:         */
070:        public final class JRefactory extends JPanel implements  EBComponent {
071:
072:            private View view;
073:            private JTabbedPane mainstage;
074:            private CPDDuplicateCodeViewer cpdViewer;
075:            private CodingStandardsViewer csViewer;
076:
077:            /**  Description of the Field */
078:            public final static String CREATE_NEW_PROJECT = jEdit
079:                    .getProperty("jrefactory.create_project");
080:
081:            private final static HashMap viewers = new HashMap();
082:            private final static HashMap listeners = new HashMap();
083:            private final static ArrayList viewerList = new ArrayList();
084:            private final static ArrayList actions = new ArrayList();
085:
086:            /**
087:             *  Create a new <code>JRefactory</code>.
088:             *
089:             *@param  aView  Description of Parameter `
090:             */
091:            public JRefactory(View aView) {
092:                super (new BorderLayout());
093:                //System.out.println("new JRefactory()");
094:                view = aView;
095:
096:                if (viewers.get(aView) == null) {
097:                    viewers.put(aView, this );
098:                }
099:                viewerList.add(this );
100:
101:                EditBus.addToBus(this );
102:
103:                // plug into JRefactory some classes that adapt it to jEdit.
104:                org.acm.seguin.ide.common.ExitOnCloseAdapter
105:                        .setExitOnWindowClose(false);
106:                org.acm.seguin.refactor.undo.UndoStack.get().setUndoAction(
107:                        org.acm.seguin.ide.jedit.action.JEditUndoAction.class);
108:                org.acm.seguin.refactor.Refactoring
109:                        .setComplexTransform(org.acm.seguin.ide.jedit.JEditComplexTransform.class);
110:
111:                //  Make sure everything is installed properly
112:                (new RefactoryInstaller(true)).run();
113:                SourceBrowser.set(new PluginSourceBrowser(view));
114:                //CurrentSummary.register(new JEditCurrentSummary(view));
115:                net.sourceforge.jrefactory.action.CurrentSummary
116:                        .register(new JEditCurrentSummary(view));
117:
118:                cpdViewer = new CPDDuplicateCodeViewer(aView);
119:                PackageSelectorPanel panel = PackageSelectorPanel
120:                        .getMainPanel(null);
121:                JPanel jRefactoryPanel = panel.getPanel();
122:                ASTViewerPane astv = new ASTViewerPane(aView);
123:
124:                JRootPane findBugs = null;
125:                try {
126:                    EditPlugin this Plugin = jEdit.getPlugin("JavaStylePlugin");
127:                    if (this Plugin == null) {
128:                        this Plugin = jEdit
129:                                .getPlugin("org.acm.seguin.ide.jedit.JavaStylePlugin");
130:                    }
131:                    File[] pluginList = new File[0];
132:                    if (this Plugin != null) {
133:                        pluginList = new File[] { this Plugin.getPluginJAR()
134:                                .getFile() };
135:                    }
136:                    DetectorFactoryCollection.setPluginList(pluginList);
137:                    findBugs = org.acm.seguin.findbugs.FindBugsFrame
138:                            .createFindBugsPanel(aView);
139:                } catch (Throwable e) {
140:                    e.printStackTrace();
141:                }
142:
143:                csViewer = new CodingStandardsViewer(aView);
144:                mainstage = new JTabbedPane(JTabbedPane.TOP);
145:                mainstage.addTab("JRefactory", jRefactoryPanel);
146:                mainstage.addTab("Cut & paste detector", cpdViewer);
147:                mainstage.addTab("Coding standards", csViewer);
148:                if (findBugs != null) {
149:                    mainstage.addTab("Find Bugs", findBugs);
150:                }
151:                mainstage.addTab("Abstract Syntax Tree", astv);
152:                add(mainstage, BorderLayout.CENTER);
153:                astv.initDividers();
154:                setInitialProject(view);
155:                addProjectListener(view);
156:            }
157:
158:            public void setVisible(String toView) {
159:                if (toView == null) {
160:                    return;
161:                }
162:                int count = mainstage.getTabCount();
163:                for (int i = 0; i < count; i++) {
164:                    if (toView.equals(mainstage.getTitleAt(i))) {
165:                        java.awt.Component c = mainstage.getComponentAt(i);
166:                        mainstage.setSelectedComponent(c);
167:                        break;
168:                    }
169:                }
170:            }
171:
172:            public void setInitialProject(View view) {
173:                try {
174:                    Class clazz = Class.forName("projectviewer.ProjectViewer");
175:                    projectviewer.vpt.VPTProject current = null;
176:                    projectviewer.ProjectViewer projectViewer = projectviewer.ProjectViewer
177:                            .getViewer(view);
178:                    if (projectViewer == null) {
179:                        return;
180:                    }
181:                    projectviewer.vpt.VPTNode treeRoot = projectViewer
182:                            .getRoot();
183:                    if (treeRoot.isProject()) {
184:                        current = (projectviewer.vpt.VPTProject) treeRoot;
185:
186:                        Project project = Project.getProject(current.getName());
187:                        if (project == null) {
188:                            project = org.acm.seguin.project.Project
189:                                    .createProject(current.getName());
190:                        }
191:                        org.acm.seguin.project.Project
192:                                .setCurrentProject(project);
193:                    }
194:                } catch (ClassNotFoundException e) {
195:                }
196:            }
197:
198:            public void addProjectListener(View view) {
199:                try {
200:                    Class clazz = Class.forName("projectviewer.ProjectViewer");
201:                    projectviewer.event.ProjectViewerListener listener = new projectviewer.event.ProjectViewerListener() {
202:
203:                        /** Notifies the changing of the active project. */
204:                        public void projectLoaded(
205:                                projectviewer.event.ProjectViewerEvent evt) {
206:                            projectviewer.ProjectViewer viewer = evt
207:                                    .getProjectViewer();
208:                            projectviewer.vpt.VPTProject proj = evt
209:                                    .getProject();
210:                            Project project = Project
211:                                    .getProject(proj.getName());
212:                            if (project == null) {
213:                                project = org.acm.seguin.project.Project
214:                                        .createProject(proj.getName());
215:                            }
216:                            org.acm.seguin.project.Project
217:                                    .setCurrentProject(project);
218:                        }
219:
220:                        /** Notifies the creation of a project. */
221:                        public void projectAdded(
222:                                projectviewer.event.ProjectViewerEvent evt) {
223:                        }
224:
225:                        /** Notifies the removal of a project. */
226:                        public void projectRemoved(
227:                                projectviewer.event.ProjectViewerEvent evt) {
228:                        }
229:                    };
230:                    projectviewer.ProjectViewer.addProjectViewerListener(
231:                            listener, view);
232:                } catch (ClassNotFoundException e) {
233:                }
234:            }
235:
236:            /**
237:             *  Gets the CPDDuplicateCodeViewer attribute of the JRefactory object
238:             *
239:             *@return    The CPDDuplicateCodeViewer value
240:             */
241:            public CPDDuplicateCodeViewer getCPDDuplicateCodeViewer() {
242:                return cpdViewer;
243:            }
244:
245:            /**
246:             *  Gets the CodingStandardsViewer attribute of the JRefactory object
247:             *
248:             *@return    The CodingStandardsViewer value
249:             */
250:            public CodingStandardsViewer getCodingStandardsViewer() {
251:                return csViewer;
252:            }
253:
254:            /**  Gets the userSelection attribute of the JRefactory object */
255:            public void getUserSelection() {
256:                JFileChooser chooser = new JFileChooser();
257:
258:                //  Add other file filters - All
259:                AllFileFilter allFilter = new AllFileFilter();
260:                chooser.addChoosableFileFilter(allFilter);
261:
262:                //  Set it so that files and directories can be selected
263:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
264:
265:                //  Set the directory to the current directory
266:                chooser.setCurrentDirectory(new File(System
267:                        .getProperty("user.dir")));
268:
269:                int returnVal = chooser.showOpenDialog(null);
270:                if (returnVal == JFileChooser.APPROVE_OPTION) {
271:                    PackageSelectorPanel panel = PackageSelectorPanel
272:                            .getMainPanel(chooser.getSelectedFile()
273:                                    .getAbsolutePath());
274:                    ReloaderSingleton.register(panel);
275:                    mainstage.setComponentAt(0, panel.getPanel());
276:                } else {
277:                    mainstage.setComponentAt(0, new ReloadChooserPanel());
278:                }
279:            }
280:
281:            /**
282:             *  Description of the Method
283:             *
284:             *@param  msg  Description of the Parameter
285:             */
286:            public void handleMessage(EBMessage msg) {
287:                //if (msg instanceof ViewUpdate) {
288:                //    ViewUpdate vu = (ViewUpdate) msg;
289:                //    //System.out.println("JRefactory.handleMessage("+vu+")");
290:                //} else if (msg instanceof EditorExitRequested) {
291:                //    // Editor is exiting, save info about current project
292:                //    EditorExitRequested eer = (EditorExitRequested) msg;
293:                //    //System.out.println("JRefactory.handleMessage("+eer+")");
294:                //} else if (msg instanceof BufferUpdate) {
295:                //    BufferUpdate bu = (BufferUpdate) msg;
296:                //    //System.out.println("JRefactory.handleMessage("+bu+")");
297:                //}
298:            }
299:
300:            /**
301:             *  Returns the viewer associated with the given view, or null if none exists.
302:             *
303:             *@param  view  Description of the Parameter
304:             *@return       The viewer value
305:             */
306:            public static JRefactory getViewer(View view) {
307:                return (JRefactory) viewers.get(view);
308:            }
309:
310:            /**
311:             *  Adds an action to be shown on the toolbar.
312:             *
313:             *@param  action  Description of the Parameter
314:             */
315:            public static void registerAction(Action action) {
316:                actions.add(action);
317:                actionsChanged();
318:            }
319:
320:            /**
321:             *  Removes an action from the toolbar.
322:             *
323:             *@param  action  Description of the Parameter
324:             */
325:            public static void unregisterAction(Action action) {
326:                actions.remove(action);
327:                actionsChanged();
328:            }
329:
330:            /**
331:             *  Add a listener for the instance of project viewer of the given view. If the given view is null, the listener will
332:             *  be called from all instances. <p>
333:             *
334:             *  Additionally, for listeners that are registered for all views, a JRefactoryEvent is fired when a different view
335:             *  is selected.</p>
336:             *
337:             *@param  lstnr  The listener to add.
338:             *@param  view   The view that the lstnr is attached to, or <code>null</code> if the listener wants to be called from
339:             *      all views.
340:             */
341:            public static void addJRefactoryListener(JRefactoryListener lstnr,
342:                    View view) {
343:                ArrayList lst = (ArrayList) listeners.get(view);
344:                if (lst == null) {
345:                    lst = new ArrayList();
346:                    listeners.put(view, lst);
347:                }
348:                lst.add(lstnr);
349:            }
350:
351:            /**
352:             *  Remove the listener from the list of listeners for the given view. As with the {@link
353:             *  #addJRefactoryListener(JRefactoryListener, View) add} method, <code>view</code> can be <code>null</code>.
354:             *
355:             *@param  lstnr  Description of the Parameter
356:             *@param  view   Description of the Parameter
357:             */
358:            public static void removeJRefactoryListener(
359:                    JRefactoryListener lstnr, View view) {
360:                ArrayList lst = (ArrayList) listeners.get(view);
361:                if (lst != null) {
362:                    lst.remove(lstnr);
363:                }
364:            }
365:
366:            /**
367:             *  Fires an event for the loading of a project. Notify all the listeners registered for this instance's view and
368:             *  listeners registered for all views. <p>
369:             *
370:             *  If the view provided is null, only the listeners registered for the null View will receive the event.</p>
371:             *
372:             *@param  src  Description of the Parameter
373:             *@param  p    The activated project.
374:             *@param  v    The view where the change occured, or null.
375:             */
376:            public static void fireProjectLoaded(Object src, UMLProject p,
377:                    View v) {
378:                JRefactoryEvent evt;
379:                if (src instanceof  JRefactory) {
380:                    evt = new JRefactoryEvent((JRefactory) src, p);
381:                } else {
382:                    JRefactory viewer = (JRefactory) viewers.get(v);
383:                    evt = new JRefactoryEvent(src, p);
384:                }
385:
386:                ArrayList lst;
387:                if (v != null) {
388:                    lst = (ArrayList) listeners.get(v);
389:                    if (lst != null) {
390:                        for (Iterator i = lst.iterator(); i.hasNext();) {
391:                            ((JRefactoryListener) i.next()).projectLoaded(evt);
392:                        }
393:                    }
394:                }
395:
396:                lst = (ArrayList) listeners.get(null);
397:                if (lst != null) {
398:                    for (Iterator i = lst.iterator(); i.hasNext();) {
399:                        ((JRefactoryListener) i.next()).projectLoaded(evt);
400:                    }
401:                }
402:            }
403:
404:            /**
405:             *  Fires a "project added" event. All listeners, regardless of the view, are notified of this event.
406:             *
407:             *@param  src  Description of the Parameter
408:             *@param  p    Description of the Parameter
409:             */
410:            public static void fireProjectAdded(Object src, UMLProject p) {
411:                HashSet notify = new HashSet();
412:                for (Iterator i = listeners.values().iterator(); i.hasNext();) {
413:                    notify.addAll((ArrayList) i.next());
414:                }
415:
416:                JRefactoryEvent evt = new JRefactoryEvent(src, p);
417:                for (Iterator i = notify.iterator(); i.hasNext();) {
418:                    ((JRefactoryListener) i.next()).projectAdded(evt);
419:                }
420:            }
421:
422:            /**
423:             *  Fires a "project removed" event. All listeners, regardless of the view, are notified of this event.
424:             *
425:             *@param  src  Description of the Parameter
426:             *@param  p    Description of the Parameter
427:             */
428:            public static void fireProjectRemoved(Object src, UMLProject p) {
429:                HashSet notify = new HashSet();
430:                for (Iterator i = listeners.values().iterator(); i.hasNext();) {
431:                    notify.addAll((ArrayList) i.next());
432:                }
433:
434:                JRefactoryEvent evt = new JRefactoryEvent(src, p);
435:                for (Iterator i = notify.iterator(); i.hasNext();) {
436:                    ((JRefactoryListener) i.next()).projectRemoved(evt);
437:                }
438:            }
439:
440:            /**  Reloads the action list for the toolbar. */
441:            private static void actionsChanged() {
442:                for (Iterator it = viewers.values().iterator(); it.hasNext();) {
443:                    JRefactory v = (JRefactory) it.next();
444:                }
445:            }
446:
447:            /**
448:             *  Description of the Class
449:             *
450:             *@author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike Atkinson</a>
451:             *@created    23 July 2003
452:             *@version    $Id: JRefactory.java,v 1.11 2004/05/06 20:59:05 mikeatkinson Exp $
453:             *@since      0.1.0
454:             */
455:            private final class ReloadChooserPanel extends JPanel {
456:                /**  Constructor for the ReloadChooserPanel object */
457:                public ReloadChooserPanel() {
458:                    //System.out.println("new ReloadChooserPanel()");
459:                    JButton load = new JButton("load JRefactory UML viewer");
460:                    load.addActionListener(new ActionListener() {
461:                        public void actionPerformed(ActionEvent event) {
462:                            JRefactory.this .getUserSelection();
463:                        }
464:                    });
465:                    add(load);
466:                }
467:            }
468:
469:            static {
470:                actions.add(new ShowAction());
471:                actions.add(new HideAction());
472:                actions.add(new ReloadAction());
473:                actions.add(new ReloadAllAction());
474:            }
475:
476:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.