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


0001:        /*
0002:         *  Author:  Mike Atkinson
0003:         *  This software has been developed under the copyleft
0004:         *  rules of the GNU General Public License.  Please
0005:         *  consult the GNU General Public License for more
0006:         *  details about use and distribution of this software.
0007:         */
0008:        package org.acm.seguin.ide.jbuilder;
0009:
0010:        import java.awt.BorderLayout;
0011:        import java.awt.Dimension;
0012:        import java.awt.Frame;
0013:
0014:        import java.awt.event.ActionEvent;
0015:        import java.awt.event.ActionListener;
0016:        import java.io.File;
0017:        import java.io.IOException;
0018:        import java.util.HashMap;
0019:        import java.util.List;
0020:        import java.util.Map;
0021:        import java.util.Properties;
0022:        import javax.swing.Icon;
0023:        import javax.swing.ImageIcon;
0024:        import javax.swing.JButton;
0025:        import javax.swing.JFileChooser;
0026:        import javax.swing.JFrame;
0027:        import javax.swing.JLabel;
0028:        import javax.swing.JOptionPane;
0029:        import javax.swing.JPanel;
0030:        import javax.swing.JRootPane;
0031:        import javax.swing.JScrollPane;
0032:        import javax.swing.JTabbedPane;
0033:        import javax.swing.JTextField;
0034:        import javax.swing.JTextPane;
0035:        import javax.swing.JMenuBar;
0036:        import javax.swing.JMenuItem;
0037:        import javax.swing.tree.TreeNode;
0038:
0039:        import edu.umd.cs.findbugs.DetectorFactoryCollection;
0040:        import org.acm.seguin.ide.command.CommandLineSourceBrowser;
0041:        import org.acm.seguin.ide.command.ExitMenuSelection;
0042:        import org.acm.seguin.ide.common.ASTViewerPane;
0043:        import org.acm.seguin.ide.common.CPDDuplicateCodeViewer;
0044:        import org.acm.seguin.ide.common.CodingStandardsViewer;
0045:        import org.acm.seguin.ide.common.ExitOnCloseAdapter;
0046:        import org.acm.seguin.ide.common.IDEInterface;
0047:        import org.acm.seguin.ide.common.IDEPlugin;
0048:        import org.acm.seguin.ide.common.PackageSelectorPanel;
0049:        import org.acm.seguin.ide.common.SourceBrowser;
0050:        import org.acm.seguin.ide.common.options.PropertiesFile;
0051:        import org.acm.seguin.io.AllFileFilter;
0052:
0053:        import org.acm.seguin.pmd.cpd.CPD;
0054:        import org.acm.seguin.pmd.cpd.FileFinder;
0055:        import org.acm.seguin.pmd.cpd.JavaLanguage;
0056:
0057:        import org.acm.seguin.summary.*;
0058:        import org.acm.seguin.tools.RefactoryInstaller;
0059:        import net.sourceforge.jrefactory.uml.loader.ReloaderSingleton;
0060:        import org.acm.seguin.util.FileSettings;
0061:
0062:        import net.sourceforge.jrefactory.parser.JavaParser;
0063:
0064:        import com.borland.primetime.viewer.AbstractTextNodeViewer;
0065:        import com.borland.primetime.node.Node;
0066:        import com.borland.primetime.node.FileNode;
0067:        import com.borland.primetime.node.TextFileNode;
0068:        import com.borland.jbuilder.node.JavaFileNode;
0069:        import com.borland.primetime.vfs.Buffer;
0070:        import com.borland.primetime.ide.Browser;
0071:        import com.borland.primetime.editor.EditorPane;
0072:        import com.borland.primetime.vfs.ReadOnlyException;
0073:
0074:        /**
0075:         *  Draws a UML diagram for all the classes in a package
0076:         *
0077:         * @author    Mike Atkinson
0078:         */
0079:        public class JRefactory extends JPanel implements  IDEInterface {
0080:
0081:            private JTabbedPane mainstage;
0082:            private CPDDuplicateCodeViewer cpdViewer;
0083:            private CodingStandardsViewer csViewer;
0084:            protected ASTViewerPane astv;
0085:            private Frame aView;
0086:            private static Properties ideProperties = null;;
0087:            private JTextPane pane;
0088:            private JBuilderBrowser sourceBrowser;
0089:
0090:            /**  Description of the Field */
0091:            //public static String JAVASTYLE_DIR = "";
0092:            private final static File userDir = new File(System
0093:                    .getProperty("user.dir"));
0094:            //private JPanel panel = null;
0095:            private static Map propertiesMap = new HashMap();
0096:
0097:            /**
0098:             *  Create a new <code>JRefactory</code>.
0099:             *
0100:             * @param  view  Description of Parameter
0101:             */
0102:            public JRefactory(Frame view) {
0103:                super (new BorderLayout());
0104:                aView = view;
0105:                log("new JRefactory()");
0106:                Properties props = System.getProperties();
0107:                props.list(System.out);
0108:
0109:                initialiseIDEProperties();
0110:
0111:                //JAVASTYLE_DIR = new File(props.getProperty("user.home") + File.separator + ".JRefactory" + File.separator + "javastyle").getAbsolutePath();
0112:
0113:                // plug into JRefactory some classes that adapt it to jEdit.
0114:                org.acm.seguin.ide.common.ExitOnCloseAdapter
0115:                        .setExitOnWindowClose(false);
0116:
0117:                //  Make sure everything is installed properly
0118:                FileSettings.setSettingsRoot(JBuilderPlugin.JAVASTYLE_DIR);
0119:                (new RefactoryInstaller(true)).run();
0120:                SourceBrowser.set(new CommandLineSourceBrowser());
0121:
0122:                cpdViewer = new CPDDuplicateCodeViewer(aView);
0123:                PackageSelectorPanel panel = PackageSelectorPanel
0124:                        .getMainPanel(null);
0125:                JPanel jRefactoryPanel = panel.getPanel();
0126:                astv = new ASTViewerPane(aView);
0127:
0128:                JRootPane findBugs = null;
0129:                try {
0130:                    File corePluginDir = new File(userDir, "coreplugin.jar");
0131:                    File[] pluginList = (corePluginDir.exists()) ? new File[] { corePluginDir }
0132:                            : new File[0];
0133:                    DetectorFactoryCollection.setPluginList(pluginList);
0134:                    findBugs = org.acm.seguin.findbugs.FindBugsFrame
0135:                            .createFindBugsPanel(aView);
0136:                } catch (Throwable e) {
0137:                    e.printStackTrace();
0138:                }
0139:
0140:                csViewer = new CodingStandardsViewer(aView);
0141:                mainstage = new JTabbedPane(JTabbedPane.TOP);
0142:                mainstage.addTab("JRefactory", jRefactoryPanel);
0143:                mainstage.addTab("Cut & paste detector", cpdViewer);
0144:                mainstage.addTab("Coding standards", csViewer);
0145:                if (findBugs != null) {
0146:                    mainstage.addTab("Find Bugs", findBugs);
0147:                }
0148:                mainstage.addTab("Abstract Syntax Tree", astv);
0149:                add(mainstage, BorderLayout.CENTER);
0150:                pane = new JTextPane();
0151:                add(new MyScrollPane(pane), BorderLayout.EAST);
0152:                pane.setSelectionColor(java.awt.Color.BLUE.brighter()
0153:                        .brighter());
0154:                pane.setSelectedTextColor(java.awt.Color.BLACK);
0155:                pane.setHighlighter(new javax.swing.text.DefaultHighlighter());
0156:            }
0157:
0158:            public void initialiseIDEProperties() {
0159:                if (ideProperties == null) {
0160:                    try {
0161:                        ideProperties = new Properties();
0162:                        java.io.InputStream is = getClass()
0163:                                .getResourceAsStream("/ui/JavaStyle.props");
0164:                        ideProperties.load(is);
0165:                        ideProperties.list(System.out);
0166:                    } catch (java.io.IOException e) {
0167:                        e.printStackTrace();
0168:                    }
0169:                }
0170:            }
0171:
0172:            /**
0173:             *  Description of the Method
0174:             *
0175:             * @param  view      Description of Parameter
0176:             * @param  fileName  The new Buffer value
0177:             */
0178:            public void setBuffer(Frame view, Object fileName) {
0179:                log("setBuffer(view, " + fileName + ")");
0180:            }
0181:
0182:            /**
0183:             *  Description of the Method
0184:             *
0185:             * @param  buffer  Description of Parameter
0186:             * @return         The File path for this buffer
0187:             */
0188:            public String getFilePathForBuffer(Object buffer) {
0189:                return ""; // FIXME "" means the file path is not known.
0190:            }
0191:
0192:            /**
0193:             *  Description of the Method
0194:             *
0195:             * @param  view   Description of Parameter
0196:             * @param  start  The new Selection value
0197:             * @param  end    The new Selection value
0198:             */
0199:            public void setSelection(Frame view, Object buffer, int start,
0200:                    int end) {
0201:                log("setSelection(view, " + start + "," + end + ")");
0202:                javax.swing.text.Caret caret = pane.getCaret();
0203:                caret.setDot(start);
0204:                caret.moveDot(end);
0205:                caret.setVisible(true);
0206:                caret.setSelectionVisible(true);
0207:            }
0208:
0209:            /**  Gets the userSelection attribute of the JRefactory object */
0210:            public void getUserSelection() {
0211:                JFileChooser chooser = new JFileChooser();
0212:
0213:                //  Add other file filters - All
0214:                AllFileFilter allFilter = new AllFileFilter();
0215:                chooser.addChoosableFileFilter(allFilter);
0216:
0217:                //  Set it so that files and directories can be selected
0218:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0219:
0220:                //  Set the directory to the current directory
0221:                chooser.setCurrentDirectory(userDir);
0222:
0223:                int returnVal = chooser.showOpenDialog(null);
0224:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0225:                    PackageSelectorPanel panel = PackageSelectorPanel
0226:                            .getMainPanel(chooser.getSelectedFile()
0227:                                    .getAbsolutePath());
0228:                    ReloaderSingleton.register(panel);
0229:                    mainstage.setComponentAt(0, panel.getPanel());
0230:                } else {
0231:                    mainstage.setComponentAt(0, new ReloadChooserPanel());
0232:                }
0233:            }
0234:
0235:            /**
0236:             *  Gets the IDEProperty attribute of the IDEInterface object
0237:             *
0238:             * @param  prop  Description of Parameter
0239:             * @return       The IDEProperty value
0240:             */
0241:            public String getIDEProperty(String prop) {
0242:                log("getIDEProperty(" + prop + ")");
0243:                initialiseIDEProperties();
0244:                return ideProperties.getProperty(prop);
0245:            }
0246:
0247:            /**
0248:             *  Gets the IDEProperty attribute of the IDEInterface object
0249:             *
0250:             * @param  prop   Description of Parameter
0251:             * @param  deflt  Description of Parameter
0252:             * @return        The IDEProperty value
0253:             */
0254:            public String getIDEProperty(String prop, String deflt) {
0255:                log("getIDEProperty(" + prop + "," + deflt + ")");
0256:                initialiseIDEProperties();
0257:                return ideProperties.getProperty(prop, deflt);
0258:            }
0259:
0260:            /**
0261:             *  Gets the IDEProjects attribute of the IDEInterface object
0262:             *
0263:             * @param  parent  Description of Parameter
0264:             * @return         The IDEProjects value
0265:             */
0266:            public String[] getIDEProjects(Frame parent) {
0267:                log("getIDEProjects(" + parent + ")");
0268:                return new String[] { "default" };
0269:            }
0270:
0271:            /**
0272:             *  Gets the Properties attribute of the IDEInterface object
0273:             *
0274:             * @param  type     Description of Parameter
0275:             * @param  project  Description of Parameter
0276:             * @return          The Properties value
0277:             */
0278:            public PropertiesFile getProperties(String type, String project) {
0279:                log("getProperties(" + type + "," + project + ")");
0280:                //log("getProperties(" + type+","+project + ")");
0281:                String key = ("default".equals(project)) ? type + "::null"
0282:                        : type + "::" + project;
0283:                PropertiesFile projectProperties = (PropertiesFile) propertiesMap
0284:                        .get(key);
0285:
0286:                //log("  key="+key+" ->projectProperties="+projectProperties);
0287:                if (projectProperties == null) {
0288:                    //log("  getting Properties(FileSettings.getSettings("+project+", \"Refactory\", "+type+")");
0289:                    projectProperties = new PropertiesFile(
0290:                            org.acm.seguin.util.FileSettings.getSettings(
0291:                                    project, "Refactory", type));
0292:                    propertiesMap.put(key, projectProperties);
0293:                }
0294:                return projectProperties;
0295:            }
0296:
0297:            /**
0298:             *  Load an icon from the IDE
0299:             *
0300:             * @param  name  The name of the icon.
0301:             * @return       An icon (or null if the icon cannot be found).
0302:             */
0303:            public Icon loadIcon(String name) {
0304:                ClassLoader classLoader = this .getClass().getClassLoader();
0305:                Icon icon = null;
0306:                try {
0307:                    icon = new ImageIcon(classLoader.getResource(name));
0308:                } catch (Exception e) {
0309:                }
0310:                if (icon == null) {
0311:                    try {
0312:                        icon = new ImageIcon(classLoader
0313:                                .getResource("org/acm/seguin/ide/common/icons/"
0314:                                        + name));
0315:                    } catch (Exception e) {
0316:                    }
0317:                }
0318:                return icon;
0319:            }
0320:
0321:            /**
0322:             *  Description of the Method
0323:             *
0324:             * @param  buffer  Description of Parameter
0325:             * @param  begin   Description of Parameter
0326:             * @return         The BeginLine value
0327:             */
0328:            public int getLineStartOffset(Object buffer, int begin) {
0329:                log("getLineStartOffset(" + buffer + "," + begin + ")");
0330:                String text = getText(null, null);
0331:                int i = 0;
0332:                int pos = begin;
0333:                while (pos > 0 && i < text.length()) {
0334:                    if (text.charAt(i++) == '\n') {
0335:                        pos--;
0336:                    }
0337:                }
0338:                return i - begin;
0339:            }
0340:
0341:            /**
0342:             *  Description of the Method
0343:             *
0344:             * @param  buffer  Description of Parameter
0345:             * @param  end     Description of Parameter
0346:             * @return         The LineEndOffset value
0347:             */
0348:            public int getLineEndOffset(Object buffer, int end) {
0349:                log("getLineEndOffset(" + buffer + "," + end + ")");
0350:                String text = getText(null, null);
0351:                int i = 0;
0352:                int pos = end;
0353:                while (pos > 0 && i < text.length()) {
0354:                    if (text.charAt(i++) == '\n') {
0355:                        pos--;
0356:                    }
0357:                }
0358:                return i - 1 - end;
0359:            }
0360:
0361:            /**
0362:             *  Description of the Method
0363:             *
0364:             * @param  view  Description of Parameter
0365:             * @return       The Text value
0366:             */
0367:            public String getText(Frame view, Object buffer) {
0368:                log("getText(view)");
0369:                Node active = (Node) buffer;
0370:                if (active instanceof  TextFileNode) {
0371:                    TextFileNode jtn = (TextFileNode) active;
0372:                    try {
0373:                        Buffer buff = jtn.getBuffer();
0374:                        byte[] contents = buff.getContent();
0375:                        return new String(contents);
0376:                    } catch (java.io.IOException ioex) {
0377:                        ioex.printStackTrace();
0378:                    }
0379:                }
0380:
0381:                return "";
0382:            }
0383:
0384:            /**
0385:             *  Description of the Method
0386:             *
0387:             * @param  buffer  Description of Parameter
0388:             * @return         The LineEndOffset value
0389:             */
0390:            public int getLineCount(Object buffer) {
0391:                log("getLineCount(" + buffer + ")");
0392:                String text = getText(null, null);
0393:                int lc = 1;
0394:                int i = 0;
0395:                while (i < text.length()) {
0396:                    if (text.charAt(i++) == '\n') {
0397:                        lc++;
0398:                    }
0399:                }
0400:                return lc;
0401:            }
0402:
0403:            /**
0404:             *  Description of the Method
0405:             *
0406:             * @param  view    Description of Parameter
0407:             * @param  buffer  Description of Parameter
0408:             * @return         The ProjectName value
0409:             */
0410:            public String getProjectName(Frame view, Object buffer) {
0411:                return getProjectName(view);
0412:            }
0413:
0414:            /**
0415:             *  Description of the Method
0416:             *
0417:             * @param  view    Description of Parameter
0418:             * @param  buffer  Description of Parameter
0419:             */
0420:            public void goToBuffer(Frame view, Object buffer) {
0421:                log("goToBuffer(view" + ", " + buffer + ")");
0422:                sourceBrowser.showNode((FileNode) buffer);
0423:            }
0424:
0425:            /**
0426:             *  Description of the Method
0427:             *
0428:             * @param  parent  Description of Parameter
0429:             */
0430:            public void showWaitCursor(Frame parent) {
0431:                log("showWaitCursor(" + parent + ")");
0432:            }
0433:
0434:            private static java.io.PrintStream logger = null;
0435:            private static java.io.PrintStream logger2 = null;
0436:
0437:            public static void initLog() {
0438:                if (logger == null) {
0439:                    try {
0440:                        logger = new java.io.PrintStream(
0441:                                new java.io.FileOutputStream(
0442:                                        "C:\\temp\\JBuilder.log.txt"));
0443:                        logger2 = new java.io.PrintStream(
0444:                                new java.io.FileOutputStream(
0445:                                        "C:\\temp\\JBuilder.err.txt"));
0446:                        System.setOut(logger);
0447:                        System.setErr(logger2);
0448:                    } catch (java.io.FileNotFoundException e) {
0449:                        e.printStackTrace(System.err);
0450:                        logger = System.err;
0451:                    }
0452:                }
0453:            }
0454:
0455:            public static void log(String message) {
0456:                initLog();
0457:                logger.println(message);
0458:            }
0459:
0460:            /**
0461:             *  Description of the Method
0462:             *
0463:             * @param  parent  Description of Parameter
0464:             */
0465:            public void hideWaitCursor(Frame parent) {
0466:                log("hideWaitCursor(" + parent + ")");
0467:            }
0468:
0469:            /**
0470:             *  Description of the Method
0471:             *
0472:             * @param  urgency  Description of Parameter
0473:             * @param  source   Description of Parameter
0474:             * @param  message  Description of Parameter
0475:             */
0476:            public void log(int urgency, Object source, Object message) {
0477:                log("log(" + urgency + "," + source + "," + message + ")");
0478:            }
0479:
0480:            /**
0481:             *  Description of the Method
0482:             *
0483:             * @param  view             Description of Parameter
0484:             * @exception  IOException  Description of Exception
0485:             */
0486:            public void cpdBuffer(Frame view, Object buffer) throws IOException {
0487:                log("cpdBuffer(view)");
0488:            }
0489:
0490:            /**
0491:             *  Description of the Method
0492:             *
0493:             * @param  view             Description of Parameter
0494:             * @exception  IOException  Description of Exception
0495:             */
0496:            public void cpdAllOpenBuffers(Frame view) throws IOException {
0497:                log("cpdAllOpenBuffers(view)");
0498:            }
0499:
0500:            /**
0501:             *  Description of the Method
0502:             *
0503:             * @param  view             Description of Parameter
0504:             * @param  recursive        Description of Parameter
0505:             * @exception  IOException  Description of Exception
0506:             */
0507:            public void cpdDir(Frame view, boolean recursive)
0508:                    throws IOException {
0509:                log("cpdDir(view)");
0510:                JFileChooser chooser = new JFileChooser(
0511:                        getIDEProperty("pmd.cpd.lastDirectory"));
0512:
0513:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0514:
0515:                JPanel pnlAccessory = new JPanel();
0516:
0517:                pnlAccessory.add(new JLabel("Minimum Tile size :"));
0518:
0519:                JTextField txttilesize = new JTextField("100");
0520:
0521:                pnlAccessory.add(txttilesize);
0522:                chooser.setAccessory(pnlAccessory);
0523:
0524:                int returnVal = chooser.showOpenDialog(view);
0525:                File selectedFile = null;
0526:
0527:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0528:                    selectedFile = chooser.getSelectedFile();
0529:                    if (!selectedFile.isDirectory()) {
0530:                        JOptionPane.showMessageDialog(view,
0531:                                "Selection not a directory.", "JRefactory",
0532:                                JOptionPane.ERROR_MESSAGE);
0533:                        return;
0534:                    }
0535:                } else {
0536:                    return;
0537:                }
0538:                // In case the user presses cancel or escape.
0539:
0540:                getIDEProperty("pmd.cpd.lastDirectory", selectedFile
0541:                        .getCanonicalPath());
0542:
0543:                int tilesize = 100;
0544:
0545:                try {
0546:                    tilesize = Integer.parseInt(txttilesize.getText());
0547:                } catch (NumberFormatException e) {
0548:                    //use the default.
0549:                    tilesize = 100;
0550:                }
0551:
0552:                CPD cpd = new CPD(tilesize, new JavaLanguage());
0553:
0554:                if (recursive) {
0555:                    cpd.addRecursively(selectedFile.getCanonicalPath());
0556:                } else {
0557:                    cpd.addAllInDirectory(selectedFile.getCanonicalPath());
0558:                }
0559:
0560:                cpd.go();
0561:                if (cpdViewer != null) {
0562:                    cpdViewer.processDuplicates(cpd, view);
0563:                }
0564:            }
0565:
0566:            /**
0567:             *  Description of the Method
0568:             *
0569:             * @param  view             Description of Parameter
0570:             * @param  fileName         Description of Parameter
0571:             * @return                  Description of the Returned Value
0572:             * @exception  IOException  Description of Exception
0573:             */
0574:            public Object openFile(Frame view, String fileName)
0575:                    throws IOException {
0576:                log("openFile(view, " + fileName + ")");
0577:                File file = new File(fileName);
0578:                if (file.exists()) {
0579:                    try {
0580:                        pane.read(new java.io.FileReader(file), file);
0581:                    } catch (IOException e) {
0582:                        JOptionPane.showMessageDialog(pane, e.getMessage(),
0583:                                "JRefactory", JOptionPane.INFORMATION_MESSAGE);
0584:                    }
0585:                }
0586:                return new File(fileName);
0587:            }
0588:
0589:            /**
0590:             *  Description of the Method
0591:             *
0592:             * @param  view   Description of Parameter
0593:             * @param  start  Description of Parameter
0594:             */
0595:            public void moveCaretPosition(Frame view, Object buffer, int start) {
0596:                log("moveCaretPosition(view, " + start + ")");
0597:                javax.swing.text.Caret caret = pane.getCaret();
0598:                caret.moveDot(start);
0599:                caret.setVisible(true);
0600:            }
0601:
0602:            /**
0603:             *  Description of the Method
0604:             *
0605:             * @param  runnable  Description of Parameter
0606:             */
0607:            public void runInAWTThread(Runnable runnable) {
0608:                log("runInAWTThread(" + runnable + ")");
0609:            }
0610:
0611:            /**
0612:             *  Description of the Method
0613:             *
0614:             * @param  view  Description of Parameter
0615:             */
0616:            public void checkBuffer(Frame view, Object buffer) {
0617:                log("check(view)");
0618:                csViewer.check(view, null, false);
0619:            }
0620:
0621:            /**
0622:             *  Description of the Method
0623:             *
0624:             * @param  view  Description of Parameter
0625:             */
0626:            public void checkAllOpenBuffers(Frame view) {
0627:                log("checkAllOpenBuffers(view)");
0628:                checkBuffer(view, null);
0629:            }
0630:
0631:            /**
0632:             *  Description of the Method
0633:             *
0634:             * @param  view       Description of Parameter
0635:             * @param  recursive  Description of Parameter
0636:             */
0637:            public void checkDirectory(Frame view, boolean recursive) {
0638:                log("checkDirectory(view" + recursive + ")");
0639:                JFileChooser chooser = new JFileChooser();
0640:
0641:                //  Add other file filters - All
0642:                AllFileFilter allFilter = new AllFileFilter();
0643:                chooser.addChoosableFileFilter(allFilter);
0644:
0645:                //  Set it so that files and directories can be selected
0646:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0647:
0648:                //  Set the directory to the current directory
0649:                chooser.setCurrentDirectory(userDir);
0650:
0651:                //  Get the user's selection
0652:                int returnVal = chooser.showOpenDialog(null);
0653:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0654:                    //selectionPanel(chooser.getSelectedFile().getAbsolutePath());
0655:                    process(findFiles(chooser.getSelectedFile()
0656:                            .getAbsolutePath(), recursive), view);
0657:                }
0658:            }
0659:
0660:            /**
0661:             *  Description of the Method
0662:             *
0663:             * @param  dir      Description of Parameter
0664:             * @param  recurse  Description of Parameter
0665:             * @return          Description of the Returned Value
0666:             */
0667:            private List findFiles(String dir, boolean recurse) {
0668:                FileFinder finder = new FileFinder();
0669:                return finder.findFilesFrom(dir,
0670:                        new JavaLanguage.JavaFileOrDirectoryFilter(), recurse);
0671:            }
0672:
0673:            /**
0674:             *  Description of the Method
0675:             *
0676:             * @param  files  Description of Parameter
0677:             * @param  view   Description of Parameter
0678:             */
0679:            private void process(final List files, final Frame view) {
0680:                new Thread(new Runnable() {
0681:                    public void run() {
0682:                        processFiles(files, view);
0683:                    }
0684:                }).start();
0685:            }
0686:
0687:            /**
0688:             *  Description of the Method
0689:             *
0690:             * @param  files  Description of Parameter
0691:             * @param  view   Description of Parameter
0692:             */
0693:            private void processFiles(List files, Frame view) {
0694:                List contexts = csViewer.checkFiles(files, view, null);
0695:            }
0696:
0697:            /**
0698:             *  Sets the projectData attribute of the JRefactory object
0699:             *
0700:             * @param  view  Description of Parameter
0701:             * @return       The projectName value
0702:             */
0703:            public static String getProjectName(Frame view) {
0704:                return "";
0705:            }
0706:
0707:            private static JFrame frame = null;
0708:
0709:            /**
0710:             *  The main program
0711:             *
0712:             * @param  args  the command line arguments
0713:             */
0714:            /*
0715:             public static void main(String[] args) {
0716:             try {
0717:             System.setOut(new java.io.PrintStream(new java.io.FileOutputStream("out.txt")));
0718:             System.setErr(new java.io.PrintStream(new java.io.FileOutputStream("err.txt")));
0719:             } catch (java.io.FileNotFoundException e) {
0720:             e.printStackTrace();
0721:             System.exit(1);
0722:             }
0723:             try {
0724:             FileSettings bundle = FileSettings.getRefactoryPrettySettings();
0725:             JavaParser.setTargetJDK(bundle.getString("jdk"));
0726:             } catch (Exception e) {
0727:             net.sourceforge.jrefactory.parser.JavaParser.setTargetJDK("1.4.2");
0728:             }
0729:             for (int ndx = 0; ndx < args.length; ndx++) {
0730:             if (args[ndx].equals("-config")) {
0731:             String dir = args[ndx + 1];
0732:             ndx++;
0733:             FileSettings.setSettingsRoot(dir);
0734:             }
0735:             }
0736:
0737:             ExitOnCloseAdapter.setExitOnWindowClose(true);
0738:
0739:             //  Make sure everything is installed properly
0740:             (new RefactoryInstaller(true)).run();
0741:             SourceBrowser.set(new CommandLineSourceBrowser());
0742:
0743:             //if (args.length == 0) {
0744:             //   elixir();
0745:             //} else {
0746:             //   selectionPanel(args[0]);
0747:             //}
0748:             frame = new JFrame();
0749:             frame.setTitle("JRefactory");
0750:             JRefactory refactory = new JRefactory(frame);
0751:             IDEPlugin.setPlugin(refactory);
0752:             frame.getContentPane().add(refactory);
0753:
0754:             JMenuBar menuBar = new JMenuBar();
0755:             frame.setJMenuBar(menuBar);
0756:             JMenuItem options = new JMenuItem("Options");
0757:             options.addActionListener(new ActionListener() {
0758:             public void actionPerformed(ActionEvent e) {
0759:             new org.acm.seguin.ide.common.options.JSOptionDialog(frame);
0760:             }
0761:             });
0762:
0763:             menuBar.add(options);
0764:
0765:             frame.addWindowListener(new ExitMenuSelection());
0766:             frame.pack();
0767:             refactory.astv.initDividers();
0768:             frame.show();
0769:            
0770:             }
0771:             */
0772:
0773:            /**
0774:             *  Creates the selection panel
0775:             *
0776:             * @param  directory  Description of Parameter
0777:             */
0778:            public static void selectionPanel(String directory) {
0779:                PackageSelectorPanel panel = PackageSelectorPanel
0780:                        .getMainPanel(directory);
0781:                ReloaderSingleton.register(panel);
0782:            }
0783:
0784:            /**  Insertion point for elixir */
0785:            public static void elixir() {
0786:                if (PackageSelectorPanel.getMainPanel(null) != null) {
0787:                    return;
0788:                }
0789:
0790:                JFileChooser chooser = new JFileChooser();
0791:
0792:                //  Add other file filters - All
0793:                AllFileFilter allFilter = new AllFileFilter();
0794:                chooser.addChoosableFileFilter(allFilter);
0795:
0796:                //  Set it so that files and directories can be selected
0797:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0798:
0799:                //  Set the directory to the current directory
0800:                chooser.setCurrentDirectory(userDir);
0801:
0802:                //  Get the user's selection
0803:                int returnVal = chooser.showOpenDialog(null);
0804:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0805:                    selectionPanel(chooser.getSelectedFile().getAbsolutePath());
0806:                }
0807:            }
0808:
0809:            /**
0810:             *  Description of the Class
0811:             *
0812:             * @author    Mike Atkinson
0813:             */
0814:            private class MyScrollPane extends JScrollPane {
0815:                private Dimension size = new Dimension(600, 300);
0816:
0817:                /**
0818:                 *  Constructor for the MyScrollPane object
0819:                 *
0820:                 * @param  component  Description of Parameter
0821:                 */
0822:                public MyScrollPane(java.awt.Component component) {
0823:                    super (component);
0824:                }
0825:
0826:                /**
0827:                 *  Gets the MinimumSize attribute of the MyTextPane object
0828:                 *
0829:                 * @return    The MinimumSize value
0830:                 */
0831:                public Dimension getMinimumSize() {
0832:                    return size;
0833:                }
0834:
0835:                /**
0836:                 *  Gets the PreferredSize attribute of the MyTextPane object
0837:                 *
0838:                 * @return    The PreferredSize value
0839:                 */
0840:                public Dimension getPreferredSize() {
0841:                    return size;
0842:                }
0843:            }
0844:
0845:            /**
0846:             *  Description of the Class
0847:             *
0848:             * @author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike Atkinson</a>
0849:             * @created    23 July 2003
0850:             * @version    $Id: JRefactory.java,v 1.14 2004/05/04 17:44:25 mikeatkinson Exp $
0851:             * @since      0.1.0
0852:             */
0853:            private final class ReloadChooserPanel extends JPanel {
0854:                /**  Constructor for the ReloadChooserPanel object */
0855:                public ReloadChooserPanel() {
0856:                    //log("new ReloadChooserPanel()");
0857:                    JButton load = new JButton("load JRefactory UML viewer");
0858:                    load.addActionListener(new ActionListener() {
0859:                        public void actionPerformed(ActionEvent event) {
0860:                            JRefactory.this .getUserSelection();
0861:                        }
0862:                    });
0863:                    add(load);
0864:                }
0865:            }
0866:
0867:            /**
0868:             *  Description of the Method
0869:             *
0870:             *@param  view    Description of Parameter
0871:             *@param  buffer  Description of Parameter
0872:             */
0873:            public void saveProperties() {
0874:                for (java.util.Iterator i = propertiesMap.keySet().iterator(); i
0875:                        .hasNext();) {
0876:                    PropertiesFile projectProperties = (PropertiesFile) propertiesMap
0877:                            .get(i.next());
0878:                    projectProperties.save();
0879:                }
0880:            }
0881:
0882:            /**
0883:             *  Gets the ActiveNode attribute of the PrintAction object
0884:             *
0885:             *@return    The ActiveNode value
0886:             */
0887:            private Node getActiveNode() {
0888:                Browser browser = Browser.getActiveBrowser();
0889:                return browser.getActiveNode();
0890:            }
0891:
0892:            public void setSourceBrowser(JBuilderBrowser sourceBrowser) {
0893:                this .sourceBrowser = sourceBrowser;
0894:            }
0895:
0896:            /**
0897:             *  Sets the line number
0898:             *
0899:             *@param  value  The new LineNumber value
0900:             */
0901:            public void setLineNumber(Frame view, Object buffer, int value) {
0902:                Browser browser = Browser.getActiveBrowser();
0903:                Node active = browser.getActiveNode();
0904:                AbstractTextNodeViewer sourceViewer = (AbstractTextNodeViewer) browser
0905:                        .getViewerOfType(active, AbstractTextNodeViewer.class);
0906:                EditorPane editor = sourceViewer.getEditor();
0907:                editor.gotoPosition(value, 1, false, EditorPane.CENTER_ALWAYS);
0908:            }
0909:
0910:            /**
0911:             *  Sets the string in the IDE
0912:             *
0913:             *@param  value  The new file contained in a string
0914:             */
0915:            public void setText(Frame view, Object buffer, String value) {
0916:                if (value != null) {
0917:                    //try {
0918:                    //((Buffer)buffer).setContent(value.getBytes());
0919:                    if (buffer instanceof  TextFileNode) {
0920:                        TextFileNode jtn = (TextFileNode) buffer;
0921:                        try {
0922:                            Buffer buff = jtn.getBuffer();
0923:                            buff.setContent(value.getBytes());
0924:                        } catch (java.io.IOException ioex) {
0925:                            ioex.printStackTrace();
0926:                        }
0927:                    }
0928:                    //    JOptionPane.showMessageDialog(null,
0929:                    //            "The file that you ran the pretty printer on is read only.",
0930:                    //            "Read Only Error",
0931:                    //            JOptionPane.ERROR_MESSAGE);
0932:                    //}
0933:                }
0934:            }
0935:
0936:            /**
0937:             *  Returns the frame that contains the editor. If this is not available or
0938:             *  you want dialog boxes to be centered on the screen return null from this
0939:             *  operation.
0940:             *
0941:             *@return    the frame
0942:             */
0943:            public Frame getEditorFrame() {
0944:                return Browser.getActiveBrowser();
0945:            }
0946:
0947:            /**
0948:             *  Gets the file that is being edited
0949:             *
0950:             *@return    The File value
0951:             */
0952:            public File getFile(Frame view, Object buffer) {
0953:                Node active = (Node) buffer;
0954:
0955:                if (active instanceof  FileNode) {
0956:                    return ((FileNode) active).getUrl().getFileObject();
0957:                } else {
0958:                    return null;
0959:                }
0960:            }
0961:
0962:            /**
0963:             * Indicates that a buffer has been parsed and that an Abstract Syntax Tree is available.
0964:             *
0965:             * @param  view  The frame containing the IDE.
0966:             * @param  buffer  The buffer (containing Java Source) that has been parsed.
0967:             * @param  compilationUnit  The root node of the AST.
0968:             */
0969:            public void bufferParsed(Frame view, Object buffer,
0970:                    net.sourceforge.jrefactory.ast.Node compilationUnit) {
0971:                System.out.println("NOT IMPLEMENTED: bufferParsed()");
0972:            }
0973:
0974:            /**
0975:             * Indicates that a buffer has been parsed and that a navigator tree of the source is available.
0976:             *
0977:             * @param  view    The frame containing the IDE.
0978:             * @param  buffer  The buffer (containing Java Source) that has been parsed.
0979:             * @param  node    The root node of the tree.
0980:             */
0981:            public void bufferNavigatorTree(Frame view, Object buffer,
0982:                    TreeNode node) {
0983:                System.out.println("NOT IMPLEMENTED: bufferNavigatorTree()");
0984:            }
0985:
0986:            /**
0987:             *  Returns the initial line number
0988:             *
0989:             *@return    The LineNumber value
0990:             */
0991:            public int getLineNumber(Frame view, Object buffer) {
0992:                Node active = (Node) buffer;
0993:                if (active == null) {
0994:                    return -1;
0995:                }
0996:
0997:                AbstractTextNodeViewer sourceViewer = (AbstractTextNodeViewer) ((Browser) view)
0998:                        .getViewerOfType(active, AbstractTextNodeViewer.class);
0999:                if (sourceViewer == null) {
1000:                    return -1;
1001:                }
1002:
1003:                EditorPane editor = sourceViewer.getEditor();
1004:                if (editor == null) {
1005:                    return -1;
1006:                }
1007:
1008:                int pos = editor.getCaretPosition();
1009:                return editor.getLineNumber(pos);
1010:            }
1011:
1012:            /**
1013:             *  Gets the SelectionFromIDE attribute of the JBuilderExtractMethod object
1014:             *
1015:             *@return    The SelectionFromIDE value
1016:             */
1017:            public String getSelectedText(Frame view, Object buffer) {
1018:                AbstractTextNodeViewer sourceViewer = (AbstractTextNodeViewer) ((Browser) view)
1019:                        .getViewerOfType((Node) buffer,
1020:                                AbstractTextNodeViewer.class);
1021:                EditorPane editor = sourceViewer.getEditor();
1022:                return editor.getSelectedText();
1023:            }
1024:
1025:            /**
1026:             *  Returns true if the current file being edited is a java file
1027:             *
1028:             *@return    true if the current file is a java file
1029:             */
1030:            public boolean bufferContainsJavaSource(Frame view, Object buffer) {
1031:                return (buffer instanceof  JavaFileNode);
1032:            }
1033:
1034:            public Object getCurrentBuffer(Frame view) {
1035:                return ((Browser) view).getActiveNode();
1036:            }
1037:
1038:            /**
1039:             * Adds an annotation to an ide buffer.
1040:             *
1041:             * @param  view         The frame containing the IDE.
1042:             * @param  buffer       The buffer (containing Java Source) that has been parsed.
1043:             * @param  type         either CODING_STANDARDS or CUT_AND_PASTE_DETECTION
1044:             * @param  lineNo       The line number of the annotation.
1045:             * @param  description  The annotation
1046:             */
1047:            public void addAnnotation(Frame view, Object buffer, int type,
1048:                    int lineNo, String description) {
1049:                log("NOT IMPLEMENTED: clearAnnotations()");
1050:            }
1051:
1052:            /**
1053:             * Clears all annotation for an ide buffer.
1054:             *
1055:             * @param  view         The frame containing the IDE.
1056:             * @param  buffer       The buffer (containing Java Source) that has been parsed.
1057:             * @param  type         either CODING_STANDARDS or CUT_AND_PASTE_DETECTION
1058:             */
1059:            public void clearAnnotations(Frame view, Object buffer, int type) {
1060:                log("NOT IMPLEMENTED: clearAnnotations()");
1061:            }
1062:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.