Source Code Cross Referenced for JRefactory.java in  » UML » jrefactory » org » acm » seguin » ide » standalone » 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.standalone 
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.standalone;
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.HashMap;
0022:        import java.util.Properties;
0023:        import java.util.Iterator;
0024:        import javax.swing.Icon;
0025:        import javax.swing.ImageIcon;
0026:        import javax.swing.JButton;
0027:        import javax.swing.JFileChooser;
0028:        import javax.swing.JFrame;
0029:        import javax.swing.JLabel;
0030:        import javax.swing.JMenuBar;
0031:        import javax.swing.JMenuItem;
0032:        import javax.swing.JOptionPane;
0033:        import javax.swing.JPanel;
0034:        import javax.swing.JRootPane;
0035:        import javax.swing.JScrollPane;
0036:        import javax.swing.JTabbedPane;
0037:        import javax.swing.JTextField;
0038:        import javax.swing.JTextPane;
0039:        import javax.swing.SwingUtilities;
0040:        import javax.swing.text.Document;
0041:        import javax.swing.tree.TreeNode;
0042:        import javax.swing.event.DocumentEvent;
0043:        import javax.swing.event.DocumentListener;
0044:
0045:        import edu.umd.cs.findbugs.DetectorFactoryCollection;
0046:        import org.acm.seguin.ide.command.CommandLineSourceBrowser;
0047:        import org.acm.seguin.ide.command.ExitMenuSelection;
0048:        import org.acm.seguin.ide.common.ASTViewerPane;
0049:        import org.acm.seguin.ide.common.CPDDuplicateCodeViewer;
0050:        import org.acm.seguin.ide.common.CodingStandardsViewer;
0051:        import org.acm.seguin.ide.common.ExitOnCloseAdapter;
0052:        import org.acm.seguin.ide.common.IDEInterface;
0053:        import org.acm.seguin.ide.common.IDEPlugin;
0054:        import org.acm.seguin.ide.common.PackageSelectorPanel;
0055:        import org.acm.seguin.ide.common.SourceBrowser;
0056:        import org.acm.seguin.ide.common.PackageSelectorPanel;
0057:        import org.acm.seguin.ide.common.Navigator;
0058:        import org.acm.seguin.ide.common.options.PropertiesFile;
0059:        import org.acm.seguin.io.AllFileFilter;
0060:
0061:        import org.acm.seguin.pmd.cpd.CPD;
0062:        import org.acm.seguin.pmd.cpd.FileFinder;
0063:        import org.acm.seguin.pmd.cpd.JavaLanguage;
0064:
0065:        import org.acm.seguin.JRefactoryVersion;
0066:        import org.acm.seguin.summary.*;
0067:        import org.acm.seguin.tools.RefactoryInstaller;
0068:        import net.sourceforge.jrefactory.uml.loader.ReloaderSingleton;
0069:        import org.acm.seguin.util.FileSettings;
0070:
0071:        import net.sourceforge.jrefactory.ast.Node;
0072:        import net.sourceforge.jrefactory.parser.JavaParser;
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:            private ASTViewerPane astv;
0085:            private Navigation navigation;
0086:            private Frame aView;
0087:            private static PropertiesFile properties = null;
0088:            private Properties ideProperties = new Properties();
0089:            private JTextPane textPane;
0090:            private JTabbedPane tabbedPane;
0091:            private Map fileNametoTextPaneMap = new HashMap();
0092:            private Map textPhoneToScrollPaneMap = new HashMap();
0093:
0094:            /**  Description of the Field */
0095:            public static String JAVASTYLE_DIR = "";
0096:            /**  Description of the Field */
0097:            public static File PRETTY_SETTINGS_FILE = null;
0098:
0099:            private final static File userDir = new File(System
0100:                    .getProperty("user.dir"));
0101:            private static Map propertiesMap = new HashMap();
0102:
0103:            private static JFrame frame = null;
0104:
0105:            /**
0106:             *  Create a new <code>JRefactory</code>.
0107:             *
0108:             * @param  view  Description of Parameter
0109:             */
0110:            public JRefactory(Frame view) {
0111:                super (new BorderLayout());
0112:                aView = view;
0113:                System.out.println("new JRefactory()");
0114:
0115:                // plug into JRefactory some classes that adapt it to jEdit.
0116:                org.acm.seguin.ide.common.ExitOnCloseAdapter
0117:                        .setExitOnWindowClose(true);
0118:
0119:                // check whether JavaStyle is invoked for the first time
0120:                boolean firstTime = !PRETTY_SETTINGS_FILE.exists();
0121:
0122:                //  Make sure everything is installed properly
0123:                (new RefactoryInstaller(true)).run();
0124:                properties = getProperties("pretty", null);
0125:                try {
0126:                    ideProperties.load(getClass().getResourceAsStream(
0127:                            "/ui/JavaStyle.props"));
0128:                } catch (java.io.IOException e) {
0129:                    e.printStackTrace();
0130:                }
0131:
0132:                // if JavaStyle is invoked for the first time, we need to
0133:                // correct some default values:
0134:                if (firstTime) {
0135:                    setDefaultValues();
0136:                }
0137:
0138:                SourceBrowser.set(new CommandLineSourceBrowser());
0139:
0140:                cpdViewer = new CPDDuplicateCodeViewer(aView);
0141:
0142:                PackageSelectorPanel panel = PackageSelectorPanel
0143:                        .getMainPanel(null);
0144:                JPanel jRefactoryPanel = (panel == null) ? new ReloadChooserPanel()
0145:                        : panel.getPanel();
0146:
0147:                astv = new ASTViewerPane(aView);
0148:                textPane = new JTextPane();
0149:                textPane.setSelectionColor(java.awt.Color.BLUE.brighter()
0150:                        .brighter());
0151:                textPane.setSelectedTextColor(java.awt.Color.BLACK);
0152:                textPane
0153:                        .setHighlighter(new javax.swing.text.DefaultHighlighter());
0154:
0155:                MyScrollPane scrollPane = new MyScrollPane(textPane);
0156:                textPhoneToScrollPaneMap.put(textPane, scrollPane);
0157:
0158:                tabbedPane = new JTabbedPane();
0159:                tabbedPane.add("none", scrollPane);
0160:
0161:                navigation = new Navigation(aView, textPane);
0162:
0163:                JRootPane findBugs = null;
0164:
0165:                try {
0166:                    ClassLoader classLoader = this .getClass().getClassLoader();
0167:                    java.net.URL url = classLoader
0168:                            .getResource("org/acm/seguin/ide/standalone/JRefactory.class");
0169:                    //System.out.println("url="+url);
0170:                    java.util.List plugins = new java.util.ArrayList();
0171:                    if (url != null) {
0172:                        String urlStr = url.toString();
0173:                        if (urlStr.indexOf('!') > 0) {
0174:                            String xStr = urlStr.substring("jar:file:/"
0175:                                    .length(), urlStr.indexOf('!'));
0176:                            //System.out.println("xStr="+xStr);
0177:                            xStr = replace(xStr, "%20", " ");
0178:                            //System.out.println("xStr="+xStr);
0179:                            File file = new File(xStr);
0180:                            //System.out.println("file="+file);
0181:                            if (file.exists()) {
0182:                                System.out.println(" file exists");
0183:                                plugins.add(file);
0184:                            }
0185:                        }
0186:                    }
0187:                    File findBugsDir = new File(JAVASTYLE_DIR, "findbugs");
0188:                    //System.out.println("findBugsDir="+findBugsDir);
0189:                    if (findBugsDir.exists() && findBugsDir.isDirectory()) {
0190:                        File[] files = findBugsDir.listFiles();
0191:                        for (int i = 0; i < files.length; i++) {
0192:                            if (files[i].getName().endsWith(".jar")) {
0193:                                plugins.add(files[i]);
0194:                            }
0195:                        }
0196:                    }
0197:
0198:                    File corePluginFile = new File(userDir, "coreplugin.jar");
0199:                    if (corePluginFile.exists()) {
0200:                        //System.out.println(" file " + corePluginFile + " exists");
0201:                        plugins.add(corePluginFile);
0202:                    }
0203:
0204:                    File[] pluginList = (File[]) plugins
0205:                            .toArray(new File[plugins.size()]);
0206:
0207:                    //File[] pluginList = (corePluginFile.exists()) ? new File[]{corePluginFile} : new File[0];
0208:                    for (int i = 0; i < pluginList.length; i++) {
0209:                        System.out.println("pluginList[" + i + "]="
0210:                                + pluginList[i]);
0211:                    }
0212:
0213:                    DetectorFactoryCollection.setPluginList(pluginList);
0214:                    findBugs = org.acm.seguin.findbugs.FindBugsFrame
0215:                            .createFindBugsPanel(aView);
0216:                } catch (Throwable e) {
0217:                    e.printStackTrace();
0218:                }
0219:
0220:                csViewer = new CodingStandardsViewer(aView);
0221:                mainstage = new JTabbedPane(JTabbedPane.TOP);
0222:                mainstage.addTab("JRefactory", jRefactoryPanel);
0223:                mainstage.addTab("Cut & paste detector", cpdViewer);
0224:                mainstage.addTab("Coding standards", csViewer);
0225:                if (findBugs != null) {
0226:                    mainstage.addTab("Find Bugs", findBugs);
0227:                }
0228:                mainstage.addTab("Abstract Syntax Tree", astv);
0229:                mainstage.addTab("navigator", navigation);
0230:                add(mainstage, BorderLayout.CENTER);
0231:                add(tabbedPane, BorderLayout.EAST);
0232:
0233:                // print some version info
0234:                String jversion = new JRefactoryVersion().toString();
0235:                String fversion = properties.getString("version");
0236:
0237:                log(1, this , "JRefactory version: " + jversion);
0238:                log(1, this , "pretty settings file version: " + fversion);
0239:                navigation.addBuffer(textPane);
0240:            }
0241:
0242:            private static String replace(String from, String oldStr,
0243:                    String newStr) {
0244:                StringBuffer sb = new StringBuffer();
0245:                int y = 0;
0246:                int x = from.indexOf(oldStr);
0247:                while (x >= 0) {
0248:                    System.out.println("part=" + from.substring(y, x));
0249:                    sb.append(from.substring(y, x)).append(newStr);
0250:                    y = x + oldStr.length();
0251:                    x = from.indexOf(oldStr, y);
0252:                }
0253:                System.out.println("lastpart=" + from.substring(y));
0254:                sb.append(from.substring(y));
0255:                return sb.toString();
0256:            }
0257:
0258:            /**  Sets the DefaultValues attribute of the JavaStylePlugin object */
0259:            private void setDefaultValues() {
0260:                // these default settings need to be corrected:
0261:                setProperty("end.line", "NL"); // jEdit requires this
0262:                setProperty("space.before.javadoc", "true"); // default (false) looks odd
0263:            }
0264:
0265:            /**
0266:             *  Sets the Property attribute of the JavaStylePlugin class
0267:             *
0268:             * @param  key    The new Property value
0269:             * @param  value  The new Property value
0270:             */
0271:            public static void setProperty(String key, String value) {
0272:                properties.setString(key, value);
0273:            }
0274:
0275:            /**
0276:             *  Description of the Method
0277:             *
0278:             * @param  view      Description of Parameter
0279:             * @param  fileName  The new Buffer value
0280:             */
0281:            public void setBuffer(Frame view, Object fileName) {
0282:                System.out.println("setBuffer(" + fileName + ")");
0283:                textPane = (JTextPane) fileNametoTextPaneMap.get(fileName);
0284:                if (textPane != null) {
0285:                    tabbedPane
0286:                            .setSelectedComponent((JScrollPane) textPhoneToScrollPaneMap
0287:                                    .get(textPane));
0288:                } else {
0289:                    // FIXME
0290:                }
0291:            }
0292:
0293:            /**
0294:             *  Description of the Method
0295:             *
0296:             * @param  view   Description of Parameter
0297:             * @param  start  The new Selection value
0298:             * @param  end    The new Selection value
0299:             */
0300:            public void setSelection(Frame view, Object buffer, int start,
0301:                    int end) {
0302:                System.out.println("setSelection(view, " + start + "," + end
0303:                        + ")");
0304:
0305:                textPane = (JTextPane) buffer;
0306:                tabbedPane
0307:                        .setSelectedComponent((JScrollPane) textPhoneToScrollPaneMap
0308:                                .get(textPane));
0309:                javax.swing.text.Caret caret = textPane.getCaret();
0310:
0311:                caret.setDot(start);
0312:                caret.moveDot(end);
0313:                caret.setVisible(true);
0314:                caret.setSelectionVisible(true);
0315:            }
0316:
0317:            /**  Gets the userSelection attribute of the JRefactory object */
0318:            public void getUserSelection() {
0319:                JFileChooser chooser = new JFileChooser();
0320:
0321:                //  Add other file filters - All
0322:                AllFileFilter allFilter = new AllFileFilter();
0323:
0324:                chooser.addChoosableFileFilter(allFilter);
0325:
0326:                //  Set it so that files and directories can be selected
0327:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0328:
0329:                //  Set the directory to the current directory
0330:                chooser.setCurrentDirectory(userDir);
0331:
0332:                int returnVal = chooser.showOpenDialog(null);
0333:
0334:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0335:                    PackageSelectorPanel panel = PackageSelectorPanel
0336:                            .getMainPanel(chooser.getSelectedFile()
0337:                                    .getAbsolutePath());
0338:
0339:                    ReloaderSingleton.register(panel);
0340:                    mainstage.setComponentAt(0, panel.getPanel());
0341:                } else {
0342:                    mainstage.setComponentAt(0, new ReloadChooserPanel());
0343:                }
0344:            }
0345:
0346:            /**
0347:             *  Gets the IDEProperty attribute of the IDEInterface object
0348:             *
0349:             * @param  prop  Description of Parameter
0350:             * @return       The IDEProperty value
0351:             */
0352:            public String getIDEProperty(String prop) {
0353:                System.out.println("getIDEProperty(" + prop + ")");
0354:                return ideProperties.getProperty(prop);
0355:            }
0356:
0357:            /**
0358:             *  Gets the IDEProperty attribute of the IDEInterface object
0359:             *
0360:             * @param  prop   Description of Parameter
0361:             * @param  deflt  Description of Parameter
0362:             * @return        The IDEProperty value
0363:             */
0364:            public String getIDEProperty(String prop, String deflt) {
0365:                System.out
0366:                        .println("getIDEProperty(" + prop + "," + deflt + ")");
0367:                return ideProperties.getProperty(prop, deflt);
0368:            }
0369:
0370:            /**
0371:             *  Load an icon from the IDE
0372:             *
0373:             * @param  name  The name of the icon.
0374:             * @return       An icon (or null if the icon cannot be found).
0375:             */
0376:            public Icon loadIcon(String name) {
0377:                ClassLoader classLoader = this .getClass().getClassLoader();
0378:                Icon icon = null;
0379:                try {
0380:                    icon = new ImageIcon(classLoader.getResource(name));
0381:                } catch (Exception e) {
0382:                }
0383:                if (icon == null) {
0384:                    try {
0385:                        icon = new ImageIcon(classLoader
0386:                                .getResource("org/acm/seguin/ide/common/icons/"
0387:                                        + name));
0388:                    } catch (Exception e) {
0389:                    }
0390:                }
0391:                return icon;
0392:            }
0393:
0394:            /**
0395:             * Get the line number of the cursor within the current buffer.
0396:             *
0397:             * @return       The ine number of the cursor in the current buffer, or -1 if no current buffer.
0398:             */
0399:            public int getLineNumber() {
0400:                String text = textPane.getText();
0401:                javax.swing.text.Caret caret = textPane.getCaret();
0402:                int pos = caret.getDot();
0403:                int i = 0;
0404:
0405:                while (pos > 0 && i < text.length()) {
0406:                    if (text.charAt(i++) == '\n') {
0407:                        pos--;
0408:                    }
0409:                }
0410:                return i;
0411:            }
0412:
0413:            /**
0414:             *  Gets the IDEProjects attribute of the IDEInterface object
0415:             *
0416:             * @param  parent  Description of Parameter
0417:             * @return         The IDEProjects value
0418:             */
0419:            public String[] getIDEProjects(Frame parent) {
0420:                System.out.println("getIDEProjects(" + parent + ")");
0421:                return new String[] { "default" };
0422:                //return new String[0];
0423:            }
0424:
0425:            /**
0426:             *  Gets the Properties attribute of the IDEInterface object
0427:             *
0428:             * @param  type     Description of Parameter
0429:             * @param  project  Description of Parameter
0430:             * @return          The Properties value
0431:             */
0432:            public PropertiesFile getProperties(String type, String project) {
0433:                System.out.println("getProperties(" + type + "," + project
0434:                        + ")");
0435:
0436:                //System.out.println("getProperties(" + type+","+project + ")");
0437:                String key = ("default".equals(project)) ? type + "::null"
0438:                        : type + "::" + project;
0439:                PropertiesFile projectProperties = (PropertiesFile) propertiesMap
0440:                        .get(key);
0441:
0442:                //System.out.println("  key="+key+" ->projectProperties="+projectProperties);
0443:                if (projectProperties == null) {
0444:                    //System.out.println("  getting Properties(FileSettings.getSettings("+project+", \"Refactory\", "+type+")");
0445:                    projectProperties = new PropertiesFile(
0446:                            org.acm.seguin.util.FileSettings.getSettings(
0447:                                    project, "Refactory", type));
0448:                    propertiesMap.put(key, projectProperties);
0449:                }
0450:                return projectProperties;
0451:            }
0452:
0453:            /**
0454:             *  Description of the Method
0455:             *
0456:             * @param  buffer  Description of Parameter
0457:             * @param  begin   Description of Parameter
0458:             * @return         The BeginLine value
0459:             */
0460:            public int getLineStartOffset(Object buffer, int begin) {
0461:                System.out.println("getLineStartOffset(" + buffer + "," + begin
0462:                        + ")");
0463:
0464:                textPane = (JTextPane) buffer;
0465:                String text = textPane.getText();
0466:                int i = 0;
0467:                int pos = begin;
0468:
0469:                while (pos > 0 && i < text.length()) {
0470:                    if (text.charAt(i++) == '\n') {
0471:                        pos--;
0472:                    }
0473:                }
0474:                //return i - begin;
0475:                return i;
0476:            }
0477:
0478:            /**
0479:             *  Description of the Method
0480:             *
0481:             * @param  buffer  Description of Parameter
0482:             * @param  end     Description of Parameter
0483:             * @return         The LineEndOffset value
0484:             */
0485:            public int getLineEndOffset(Object buffer, int end) {
0486:                System.out.println("getLineEndOffset(" + buffer + "," + end
0487:                        + ")");
0488:
0489:                textPane = (JTextPane) buffer;
0490:                String text = textPane.getText();
0491:                int i = 0;
0492:                int pos = end;
0493:
0494:                while (pos > 0 && i < text.length()) {
0495:                    if (text.charAt(i++) == '\n') {
0496:                        pos--;
0497:                    }
0498:                }
0499:                //return i - 1 - end;
0500:                return i - 1;
0501:            }
0502:
0503:            /**
0504:             *  Description of the Method
0505:             *
0506:             * @param  view    Description of Parameter
0507:             * @param  buffer  Description of Parameter
0508:             * @return         The Text value
0509:             */
0510:            public String getText(Frame view, Object buffer) {
0511:                System.out.println("getText(view, " + buffer + ")");
0512:                if (buffer != null) {
0513:                    textPane = (JTextPane) buffer;
0514:                }
0515:                return textPane.getText();
0516:            }
0517:
0518:            /**
0519:             *  Description of the Method
0520:             *
0521:             * @param  buffer  Description of Parameter
0522:             * @return         The LineEndOffset value
0523:             */
0524:            public int getLineCount(Object buffer) {
0525:                System.out.println("getLineCount(" + buffer + ")");
0526:
0527:                textPane = (JTextPane) buffer;
0528:                String text = textPane.getText();
0529:                int lc = 1;
0530:                int i = 0;
0531:
0532:                while (i < text.length()) {
0533:                    if (text.charAt(i++) == '\n') {
0534:                        lc++;
0535:                    }
0536:                }
0537:                return lc;
0538:            }
0539:
0540:            /**
0541:             *  Returns the frame that contains the editor. If this is not available or
0542:             *  you want dialog boxes to be centered on the screen return null from this
0543:             *  operation.
0544:             *
0545:             *@return    the frame
0546:             */
0547:            public Frame getEditorFrame() {
0548:                return null;
0549:            }
0550:
0551:            /**
0552:             * Get the current (atcive) buffer.
0553:             *
0554:             * @param  view  The frame containing the IDE.
0555:             * @return       The active buffer or null if no active buffer.
0556:             */
0557:            public Object getCurrentBuffer(Frame view) {
0558:                return textPane;
0559:            }
0560:
0561:            /**
0562:             * Get the line number of the cursor within the current buffer.
0563:             *
0564:             * @return       The ine number of the cursor in the current buffer, or -1 if no current buffer.
0565:             */
0566:            public int getLineNumber(Frame view, Object buffer) {
0567:                System.out.println("getLineNumber(view," + buffer + ")");
0568:                textPane = (JTextPane) buffer;
0569:                JTextPane pane = (JTextPane) buffer;
0570:                String text = pane.getText();
0571:                javax.swing.text.Caret caret = pane.getCaret();
0572:                int pos = caret.getDot();
0573:                int lines = 0;
0574:
0575:                for (int i = 0; i < pos; i++) {
0576:                    if (text.charAt(i) == '\n') {
0577:                        lines++;
0578:                    }
0579:                }
0580:                return lines;
0581:            }
0582:
0583:            /**
0584:             * Sets the line number
0585:             *
0586:             * @param  value  New 1-based line number
0587:             */
0588:            public void setLineNumber(Frame view, Object buffer, int lineNumber) {
0589:                System.out.println("setLineNumber(view," + buffer + ","
0590:                        + lineNumber + ")");
0591:                textPane = (JTextPane) buffer;
0592:                JTextPane pane = (JTextPane) buffer;
0593:                String text = pane.getText();
0594:                javax.swing.text.Caret caret = pane.getCaret();
0595:                int lines = 0;
0596:
0597:                for (int i = 0; i < text.length(); i++) {
0598:                    if (text.charAt(i) == '\n') {
0599:                        if (--lineNumber == 0) {
0600:                            caret.setDot(i);
0601:                            break;
0602:                        }
0603:                    }
0604:                }
0605:            }
0606:
0607:            /**
0608:             *  Does the buffer contain Java source code.
0609:             *
0610:             * @param  view  The frame containing the IDE.
0611:             * @param  buffer  Description of Parameter
0612:             *@return <code>true</code> if the buffer contains Java source code, <code>false</code> otherwise.
0613:             */
0614:            public boolean bufferContainsJavaSource(Frame view, Object buffer) {
0615:                System.out.println("bufferContainsJavaSource(view," + buffer
0616:                        + ")");
0617:                if (buffer == null) {
0618:                    return false;
0619:                }
0620:                for (Iterator i = fileNametoTextPaneMap.keySet().iterator(); i
0621:                        .hasNext();) {
0622:                    String key = (String) i.next();
0623:                    if (buffer == fileNametoTextPaneMap.get(key)) {
0624:                        return key.endsWith(".java");
0625:                    }
0626:                }
0627:                return false;
0628:            }
0629:
0630:            /**
0631:             *  Gets the file that is being edited
0632:             *
0633:             *@return    The File value
0634:             */
0635:            public File getFile(Frame view, Object buffer) {
0636:                System.out.println("getFile(view," + buffer + ")");
0637:                if (buffer == null) {
0638:                    return null;
0639:                }
0640:                for (Iterator i = fileNametoTextPaneMap.keySet().iterator(); i
0641:                        .hasNext();) {
0642:                    String key = (String) i.next();
0643:                    if (buffer == fileNametoTextPaneMap.get(key)) {
0644:                        return new File(key);
0645:                    }
0646:                }
0647:                return null;
0648:            }
0649:
0650:            /**
0651:             * Indicates that a buffer has been parsed and that an Abstract Syntax Tree is available.
0652:             *
0653:             * @param  view  The frame containing the IDE.
0654:             * @param  buffer  The buffer (containing Java Source) that has been parsed.
0655:             * @param  compilationUnit  The root node of the AST.
0656:             */
0657:            public void bufferParsed(Frame view, Object buffer,
0658:                    Node compilationUnit) {
0659:                System.out.println("NOT IMPLEMENTED: bufferParsed()");
0660:            }
0661:
0662:            /**
0663:             * Indicates that a buffer has been parsed and that a navigator tree of the source is available.
0664:             *
0665:             * @param  view    The frame containing the IDE.
0666:             * @param  buffer  The buffer (containing Java Source) that has been parsed.
0667:             * @param  node    The root node of the tree.
0668:             */
0669:            public void bufferNavigatorTree(Frame view, Object buffer,
0670:                    TreeNode node) {
0671:                System.out.println("NOT IMPLEMENTED: bufferNavigatorTree()");
0672:            }
0673:
0674:            /**
0675:             *  Sets the string in the IDE
0676:             *
0677:             * @param  view  The frame containing the IDE.
0678:             * @param  buffer  Description of Parameter
0679:             *@param  value  The new file contained in a string
0680:             */
0681:            public void setText(Frame view, Object buffer, String value) {
0682:                System.out
0683:                        .println("getFile(view," + buffer + "," + value + ")");
0684:                if (buffer != null) {
0685:                    textPane = (JTextPane) buffer;
0686:                }
0687:                textPane.setText(value);
0688:                tabbedPane
0689:                        .setSelectedComponent((JScrollPane) textPhoneToScrollPaneMap
0690:                                .get(textPane));
0691:            }
0692:
0693:            /**
0694:             *  Description of the Method
0695:             *
0696:             * @param  view    Description of Parameter
0697:             * @param  buffer  Description of Parameter
0698:             * @return         The ProjectName value
0699:             */
0700:            public String getProjectName(Frame view, Object buffer) {
0701:                System.out.println("getProjectName(" + buffer + ")");
0702:                return getProjectName(view);
0703:            }
0704:
0705:            /**
0706:             *  Description of the Method
0707:             *
0708:             * @param  buffer  Description of Parameter
0709:             * @return         The File path for this buffer
0710:             */
0711:            public String getFilePathForBuffer(Object buffer) {
0712:                System.out.println("getFilePathForBuffer(" + buffer + ")");
0713:                for (Iterator i = fileNametoTextPaneMap.keySet().iterator(); i
0714:                        .hasNext();) {
0715:                    String key = (String) i.next();
0716:                    if (buffer == fileNametoTextPaneMap.get(key)) {
0717:                        return key;
0718:                    }
0719:                }
0720:                return "";
0721:            }
0722:
0723:            /**
0724:             *  Description of the Method
0725:             *
0726:             * @param  view    Description of Parameter
0727:             * @param  buffer  Description of Parameter
0728:             */
0729:            public void goToBuffer(Frame view, Object buffer) {
0730:                System.out.println("goToBuffer(view" + ", " + buffer + ")");
0731:                textPane = (JTextPane) buffer;
0732:                tabbedPane
0733:                        .setSelectedComponent((JScrollPane) textPhoneToScrollPaneMap
0734:                                .get(textPane));
0735:            }
0736:
0737:            /**
0738:             *  Description of the Method
0739:             *
0740:             * @param  parent  Description of Parameter
0741:             */
0742:            public void showWaitCursor(Frame parent) {
0743:                System.out.println("NOT IMPLEMENTED: showWaitCursor(" + parent
0744:                        + ")");
0745:            }
0746:
0747:            /**
0748:             *  Description of the Method
0749:             *
0750:             * @param  parent  Description of Parameter
0751:             */
0752:            public void hideWaitCursor(Frame parent) {
0753:                System.out.println("NOT IMPLEMENTED: hideWaitCursor(" + parent
0754:                        + ")");
0755:            }
0756:
0757:            /**
0758:             *  Description of the Method
0759:             *
0760:             * @param  urgency  Description of Parameter
0761:             * @param  source   Description of Parameter
0762:             * @param  message  Description of Parameter
0763:             */
0764:            public void log(int urgency, Object source, Object message) {
0765:                System.out.println("log(" + urgency + "," + source.getClass()
0766:                        + "," + message + ")");
0767:            }
0768:
0769:            /**
0770:             *  Description of the Method
0771:             *
0772:             * @param  view             Description of Parameter
0773:             * @exception  IOException  Description of Exception
0774:             */
0775:            public void cpdBuffer(Frame view, Object buffer) {
0776:                System.out.println("NOT IMPLEMENTED: cpdBuffer(view,buffer)");
0777:            }
0778:
0779:            /**
0780:             *  Description of the Method
0781:             *
0782:             * @param  view             Description of Parameter
0783:             * @exception  IOException  Description of Exception
0784:             */
0785:            public void cpdAllOpenBuffers(Frame view) {
0786:                System.out.println("NOT IMPLEMENTED: cpdAllOpenBuffers(view)");
0787:            }
0788:
0789:            /**
0790:             *  Description of the Method
0791:             *
0792:             * @param  view             Description of Parameter
0793:             * @param  recursive        Description of Parameter
0794:             * @exception  IOException  Description of Exception
0795:             */
0796:            public void cpdDir(Frame view, boolean recursive)
0797:                    throws IOException {
0798:                System.out.println("cpdDir(view)");
0799:
0800:                JFileChooser chooser = new JFileChooser(
0801:                        getIDEProperty("pmd.cpd.lastDirectory"));
0802:
0803:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0804:
0805:                JPanel pnlAccessory = new JPanel();
0806:
0807:                pnlAccessory.add(new JLabel("Minimum Tile size :"));
0808:
0809:                JTextField txttilesize = new JTextField("100");
0810:
0811:                pnlAccessory.add(txttilesize);
0812:                chooser.setAccessory(pnlAccessory);
0813:
0814:                int returnVal = chooser.showOpenDialog(view);
0815:                File selectedFile = null;
0816:
0817:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0818:                    selectedFile = chooser.getSelectedFile();
0819:                    if (!selectedFile.isDirectory()) {
0820:                        JOptionPane.showMessageDialog(view,
0821:                                "Selection not a directory.", "JRefactory",
0822:                                JOptionPane.ERROR_MESSAGE);
0823:                        return;
0824:                    }
0825:                } else {
0826:                    return;
0827:                }
0828:                // In case the user presses cancel or escape.
0829:
0830:                getIDEProperty("pmd.cpd.lastDirectory", selectedFile
0831:                        .getCanonicalPath());
0832:
0833:                int tilesize = 100;
0834:
0835:                try {
0836:                    tilesize = Integer.parseInt(txttilesize.getText());
0837:                } catch (NumberFormatException e) {
0838:                    //use the default.
0839:                    tilesize = 100;
0840:                }
0841:
0842:                CPD cpd = new CPD(tilesize, new JavaLanguage());
0843:
0844:                if (recursive) {
0845:                    cpd.addRecursively(selectedFile.getCanonicalPath());
0846:                } else {
0847:                    cpd.addAllInDirectory(selectedFile.getCanonicalPath());
0848:                }
0849:
0850:                cpd.go();
0851:                if (cpdViewer != null) {
0852:                    cpdViewer.processDuplicates(cpd, view);
0853:                }
0854:            }
0855:
0856:            /**
0857:             *  Description of the Method
0858:             *
0859:             * @param  view             Description of Parameter
0860:             * @param  fileName         Description of Parameter
0861:             * @return                  Description of the Returned Value
0862:             * @exception  IOException  Description of Exception
0863:             */
0864:            public Object openFile(Frame view, String fileName)
0865:                    throws IOException {
0866:                System.out.println("openFile(view, " + fileName + ")");
0867:
0868:                File file = new File(fileName);
0869:
0870:                if (file.exists()) {
0871:                    try {
0872:                        //navigation.removeBuffer(textPane.getDocument());
0873:                        for (Iterator i = fileNametoTextPaneMap.keySet()
0874:                                .iterator(); i.hasNext();) {
0875:                            String key = (String) i.next();
0876:                            if (key.equals(fileName)) {
0877:                                textPane = (JTextPane) fileNametoTextPaneMap
0878:                                        .get(key);
0879:                                MyScrollPane scrollPane = (MyScrollPane) textPhoneToScrollPaneMap
0880:                                        .get(textPane);
0881:                                if (scrollPane == null) {
0882:                                    // ERROR
0883:                                    break;
0884:                                }
0885:                                tabbedPane.setSelectedComponent(scrollPane);
0886:                                return textPane;
0887:                            }
0888:                        }
0889:                        if (fileNametoTextPaneMap.size() == 0) {
0890:                            tabbedPane.removeTabAt(0);
0891:                        }
0892:                        textPane = new JTextPane();
0893:                        textPane.setSelectionColor(java.awt.Color.BLUE
0894:                                .brighter().brighter());
0895:                        textPane.setSelectedTextColor(java.awt.Color.BLACK);
0896:                        textPane
0897:                                .setHighlighter(new javax.swing.text.DefaultHighlighter());
0898:
0899:                        MyScrollPane scrollPane = new MyScrollPane(textPane);
0900:                        textPhoneToScrollPaneMap.put(textPane, scrollPane);
0901:                        fileNametoTextPaneMap.put(fileName, textPane);
0902:
0903:                        tabbedPane.add(getClassName(fileName), scrollPane);
0904:                        textPane.read(new java.io.FileReader(file), file);
0905:                        navigation.addBuffer(textPane);
0906:                    } catch (IOException e) {
0907:                        JOptionPane.showMessageDialog(textPane, e.getMessage(),
0908:                                "JRefactory", JOptionPane.INFORMATION_MESSAGE);
0909:                    }
0910:                }
0911:                return textPane;
0912:            }
0913:
0914:            private String getClassName(String fileName) {
0915:                int x = fileName.lastIndexOf("\\");
0916:                int y = fileName.lastIndexOf("/");
0917:                if (y < x) {
0918:                    y = x;
0919:                }
0920:                if (y >= 0) {
0921:                    return fileName.substring(y + 1);
0922:                }
0923:                return fileName;
0924:            }
0925:
0926:            /**
0927:             *  Description of the Method
0928:             *
0929:             * @param  view   Description of Parameter
0930:             * @param  start  Description of Parameter
0931:             */
0932:            public void moveCaretPosition(Frame view, Object buffer, int start) {
0933:                System.out.println("moveCaretPosition(view, " + start + ")");
0934:
0935:                textPane = (JTextPane) buffer;
0936:                tabbedPane
0937:                        .setSelectedComponent((JScrollPane) textPhoneToScrollPaneMap
0938:                                .get(textPane));
0939:                javax.swing.text.Caret caret = textPane.getCaret();
0940:
0941:                caret.moveDot(start);
0942:                caret.setVisible(true);
0943:            }
0944:
0945:            /**
0946:             *  Description of the Method
0947:             *
0948:             * @param  runnable  Description of Parameter
0949:             */
0950:            public void runInAWTThread(Runnable runnable) {
0951:                System.out.println("runInAWTThread(" + runnable + ")");
0952:                SwingUtilities.invokeLater(runnable);
0953:            }
0954:
0955:            /**
0956:             *  Description of the Method
0957:             *
0958:             * @param  view  Description of Parameter
0959:             */
0960:            public void checkBuffer(Frame view, Object buffer) {
0961:                System.out.println("check(view, " + buffer + ")");
0962:                if (buffer == null) {
0963:                    buffer = textPane;
0964:                }
0965:                csViewer.check(view, buffer, false);
0966:            }
0967:
0968:            /**
0969:             *  Description of the Method
0970:             *
0971:             * @param  view  Description of Parameter
0972:             */
0973:            public void checkAllOpenBuffers(Frame view) {
0974:                System.out.println("checkAllOpenBuffers(view)");
0975:                for (Iterator i = fileNametoTextPaneMap.keySet().iterator(); i
0976:                        .hasNext();) {
0977:                    String key = (String) i.next();
0978:                    checkBuffer(view, fileNametoTextPaneMap.get(key));
0979:                }
0980:            }
0981:
0982:            /**
0983:             *  Description of the Method
0984:             *
0985:             * @param  view       Description of Parameter
0986:             * @param  recursive  Description of Parameter
0987:             */
0988:            public void checkDirectory(Frame view, boolean recursive) {
0989:                System.out.println("checkDirectory(view" + recursive + ")");
0990:
0991:                JFileChooser chooser = new JFileChooser();
0992:
0993:                //  Add other file filters - All
0994:                AllFileFilter allFilter = new AllFileFilter();
0995:
0996:                chooser.addChoosableFileFilter(allFilter);
0997:
0998:                //  Set it so that files and directories can be selected
0999:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1000:
1001:                //  Set the directory to the current directory
1002:                chooser.setCurrentDirectory(userDir);
1003:
1004:                //  Get the user's selection
1005:                int returnVal = chooser.showOpenDialog(null);
1006:
1007:                if (returnVal == JFileChooser.APPROVE_OPTION) {
1008:                    //selectionPanel(chooser.getSelectedFile().getAbsolutePath());
1009:                    process(findFiles(chooser.getSelectedFile()
1010:                            .getAbsolutePath(), recursive), view);
1011:                }
1012:            }
1013:
1014:            /**  Description of the Method */
1015:            public void saveProperties() {
1016:                for (java.util.Iterator i = propertiesMap.keySet().iterator(); i
1017:                        .hasNext();) {
1018:                    PropertiesFile projectProperties = (PropertiesFile) propertiesMap
1019:                            .get(i.next());
1020:
1021:                    projectProperties.save();
1022:                }
1023:            }
1024:
1025:            /**
1026:             *  Description of the Method
1027:             *
1028:             * @param  dir      Description of Parameter
1029:             * @param  recurse  Description of Parameter
1030:             * @return          Description of the Returned Value
1031:             */
1032:            private List findFiles(String dir, boolean recurse) {
1033:                FileFinder finder = new FileFinder();
1034:
1035:                return finder.findFilesFrom(dir,
1036:                        new JavaLanguage.JavaFileOrDirectoryFilter(), recurse);
1037:            }
1038:
1039:            /**
1040:             *  Description of the Method
1041:             *
1042:             * @param  files  Description of Parameter
1043:             * @param  view   Description of Parameter
1044:             */
1045:            private void process(final List files, final Frame view) {
1046:                new Thread(new Runnable() {
1047:                    public void run() {
1048:                        processFiles(files, view);
1049:                    }
1050:                }).start();
1051:            }
1052:
1053:            /**
1054:             *  Description of the Method
1055:             *
1056:             * @param  files  Description of Parameter
1057:             * @param  view   Description of Parameter
1058:             */
1059:            private void processFiles(List files, Frame view) {
1060:                List contexts = csViewer.checkFiles(files, view, null);
1061:            }
1062:
1063:            /**
1064:             *  Sets the projectData attribute of the JEditPrettyPrinter object
1065:             *
1066:             * @param  view  Description of Parameter
1067:             * @return       The projectName value
1068:             */
1069:            public static String getProjectName(Frame view) {
1070:                return "";
1071:            }
1072:
1073:            /**
1074:             *  The main program
1075:             *
1076:             * @param  args  the command line arguments
1077:             */
1078:            public static void main(String[] args) {
1079:                try {
1080:                    System.setOut(new java.io.PrintStream(
1081:                            new java.io.FileOutputStream("out.txt")));
1082:                    System.setErr(new java.io.PrintStream(
1083:                            new java.io.FileOutputStream("err.txt")));
1084:                } catch (java.io.FileNotFoundException e) {
1085:                    e.printStackTrace();
1086:                    System.exit(1);
1087:                }
1088:
1089:                Properties props = System.getProperties();
1090:
1091:                props.list(System.out);
1092:
1093:                JAVASTYLE_DIR = new File(props.getProperty("user.home")
1094:                        + File.separator + ".JRefactory" + File.separator
1095:                        + "javastyle").getAbsolutePath();
1096:                PRETTY_SETTINGS_FILE = new File(JAVASTYLE_DIR + File.separator
1097:                        + ".Refactory", "pretty.settings");
1098:                FileSettings.setSettingsRoot(JAVASTYLE_DIR);
1099:
1100:                JavaParser.setTargetJDK("1.4.2");
1101:                for (int ndx = 0; ndx < args.length; ndx++) {
1102:                    if (args[ndx].equals("-config")) {
1103:                        String dir = args[ndx + 1];
1104:
1105:                        ndx++;
1106:                        FileSettings.setSettingsRoot(dir);
1107:                    }
1108:                }
1109:
1110:                //if (args.length == 0) {
1111:                //   elixir();
1112:                //} else {
1113:                //   selectionPanel(args[0]);
1114:                //}
1115:                frame = new JFrame();
1116:                frame.setTitle("JRefactory");
1117:
1118:                JRefactory refactory = new JRefactory(frame);
1119:
1120:                IDEPlugin.setPlugin(refactory);
1121:                frame.getContentPane().add(refactory);
1122:
1123:                JMenuBar menuBar = new JMenuBar();
1124:
1125:                frame.setJMenuBar(menuBar);
1126:
1127:                JMenuItem options = new JMenuItem("Options");
1128:
1129:                options.addActionListener(new ActionListener() {
1130:                    public void actionPerformed(ActionEvent e) {
1131:                        new org.acm.seguin.ide.common.options.JSOptionDialog(
1132:                                frame);
1133:                    }
1134:                });
1135:
1136:                menuBar.add(options);
1137:
1138:                frame.addWindowListener(new ExitMenuSelection());
1139:                frame.pack();
1140:                refactory.astv.initDividers();
1141:                frame.show();
1142:
1143:            }
1144:
1145:            /**
1146:             *  Creates the selection panel
1147:             *
1148:             * @param  directory  Description of Parameter
1149:             */
1150:            public static void selectionPanel(String directory) {
1151:                PackageSelectorPanel panel = PackageSelectorPanel
1152:                        .getMainPanel(directory);
1153:
1154:                ReloaderSingleton.register(panel);
1155:            }
1156:
1157:            /**  Insertion point for elixir */
1158:            public static void elixir() {
1159:                if (PackageSelectorPanel.getMainPanel(null) != null) {
1160:                    return;
1161:                }
1162:
1163:                JFileChooser chooser = new JFileChooser();
1164:
1165:                //  Add other file filters - All
1166:                AllFileFilter allFilter = new AllFileFilter();
1167:
1168:                chooser.addChoosableFileFilter(allFilter);
1169:
1170:                //  Set it so that files and directories can be selected
1171:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1172:
1173:                //  Set the directory to the current directory
1174:                chooser.setCurrentDirectory(userDir);
1175:
1176:                //  Get the user's selection
1177:                int returnVal = chooser.showOpenDialog(null);
1178:
1179:                if (returnVal == JFileChooser.APPROVE_OPTION) {
1180:                    selectionPanel(chooser.getSelectedFile().getAbsolutePath());
1181:                }
1182:            }
1183:
1184:            /**
1185:             *  Description of the Class
1186:             *
1187:             * @author    Mike Atkinson
1188:             */
1189:            private class MyScrollPane extends JScrollPane {
1190:                private Dimension size = new Dimension(600, 300);
1191:
1192:                /**
1193:                 *  Constructor for the MyScrollPane object
1194:                 *
1195:                 * @param  component  Description of Parameter
1196:                 */
1197:                public MyScrollPane(java.awt.Component component) {
1198:                    super (component);
1199:                }
1200:
1201:                /**
1202:                 *  Gets the MinimumSize attribute of the MyTextPane object
1203:                 *
1204:                 * @return    The MinimumSize value
1205:                 */
1206:                public Dimension getMinimumSize() {
1207:                    return size;
1208:                }
1209:
1210:                /**
1211:                 *  Gets the PreferredSize attribute of the MyTextPane object
1212:                 *
1213:                 * @return    The PreferredSize value
1214:                 */
1215:                public Dimension getPreferredSize() {
1216:                    return size;
1217:                }
1218:            }
1219:
1220:            /**
1221:             *  Description of the Class
1222:             *
1223:             * @author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike Atkinson</a>
1224:             * @created    23 July 2003
1225:             * @version    $Id: JRefactory.java,v 1.16 2004/05/06 20:59:06 mikeatkinson Exp $
1226:             * @since      0.1.0
1227:             */
1228:            private final class ReloadChooserPanel extends JPanel {
1229:                /**  Constructor for the ReloadChooserPanel object */
1230:                public ReloadChooserPanel() {
1231:                    //System.out.println("new ReloadChooserPanel()");
1232:                    JButton load = new JButton("load JRefactory UML viewer");
1233:
1234:                    load.addActionListener(new ActionListener() {
1235:                        public void actionPerformed(ActionEvent event) {
1236:                            JRefactory.this .getUserSelection();
1237:                        }
1238:                    });
1239:                    add(load);
1240:                }
1241:            }
1242:
1243:            private final class Navigation extends JScrollPane {
1244:                private Frame view;
1245:                private JTextPane textPane;
1246:                private Document doc;
1247:                private final Navigator navigator;
1248:
1249:                public Navigation(Frame view, JTextPane textPane) {
1250:                    this .view = view;
1251:                    this .textPane = textPane;
1252:                    navigator = new Navigator(view);
1253:                    doc = textPane.getDocument();
1254:                    navigator.viewCreated(view);
1255:                    navigator.addBuffer(textPane);
1256:                    setViewportView(navigator);
1257:                    System.out.println("Navigation created");
1258:                }
1259:
1260:                public void addBuffer(final JTextPane textPane) {
1261:                    System.out.println("Navigation.addBuffer(doc)");
1262:                    navigator.addBuffer(textPane);
1263:                    textPane.getDocument().addDocumentListener(
1264:                            new MyDocumentListener(navigator));
1265:                    System.out.println("added listener");
1266:                    navigator.contentInserted(view, doc, 0, 16);
1267:                }
1268:
1269:                public void removeBuffer(final JTextPane textPane) {
1270:                    textPane.getDocument().removeDocumentListener(
1271:                            new MyDocumentListener(navigator));
1272:                    navigator.removeBuffer(textPane);
1273:                }
1274:
1275:                private class MyDocumentListener implements  DocumentListener {
1276:                    private Navigator navigator;
1277:
1278:                    public MyDocumentListener(Navigator navigator) {
1279:                        this .navigator = navigator;
1280:                    }
1281:
1282:                    public void changedUpdate(DocumentEvent e) {
1283:                        System.out.println("changeUpdate(" + e + ")");
1284:                        navigator.contentInserted(view, e.getDocument(), e
1285:                                .getOffset(), e.getLength());
1286:                    }
1287:
1288:                    public void insertUpdate(DocumentEvent e) {
1289:                        System.out.println("insertUpdate(" + e + ")");
1290:                        navigator.contentInserted(view, e.getDocument(), e
1291:                                .getOffset(), e.getLength());
1292:                    }
1293:
1294:                    public void removeUpdate(DocumentEvent e) {
1295:                        System.out.println("removeUpdate(" + e + ")");
1296:                        navigator.contentRemoved(view, e.getDocument(), e
1297:                                .getOffset(), e.getLength());
1298:                    }
1299:                };
1300:            }
1301:
1302:            /**
1303:             * Adds an annotation to an ide buffer.
1304:             *
1305:             * @param  view         The frame containing the IDE.
1306:             * @param  buffer       The buffer (containing Java Source) that has been parsed.
1307:             * @param  type         either CODING_STANDARDS or CUT_AND_PASTE_DETECTION
1308:             * @param  lineNo       The line number of the annotation.
1309:             * @param  description  The annotation
1310:             */
1311:            public void addAnnotation(Frame view, Object buffer, int type,
1312:                    int lineNo, String description) {
1313:                System.out.println("NOT IMPLEMENTED: clearAnnotations()");
1314:            }
1315:
1316:            /**
1317:             * Clears all annotation for an ide buffer.
1318:             *
1319:             * @param  view         The frame containing the IDE.
1320:             * @param  buffer       The buffer (containing Java Source) that has been parsed.
1321:             */
1322:            public void clearAnnotations(Frame view, Object buffer, int type) {
1323:                System.out.println("NOT IMPLEMENTED: clearAnnotations()");
1324:            }
1325:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.