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


0001:        /*
0002:         *  JavaStylePlugin.java - a Java pretty printer plugin for jEdit
0003:         *  Copyright (c) 1999 Andreas "Mad" Schaefer (andreas.schaefer@madplanet.ch)
0004:         *  Copyright (c) 2000,2001 Dirk Moebius (dmoebius@gmx.net)
0005:         *
0006:         *  jEdit buffer options:
0007:         *  :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
0008:         *
0009:         *  This program is free software; you can redistribute it and/or
0010:         *  modify it under the terms of the GNU General Public License
0011:         *  as published by the Free Software Foundation; either version 2
0012:         *  of the License, or any later version.
0013:         *
0014:         *  This program is distributed in the hope that it will be useful,
0015:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0016:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017:         *  GNU General Public License for more details.
0018:         *
0019:         *  You should have received a copy of the GNU General Public License
0020:         *  along with this program; if not, write to the Free Software
0021:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0022:         */
0023:        package org.acm.seguin.ide.netbeans;
0024:
0025:        import java.awt.BorderLayout;
0026:        import java.awt.Frame;
0027:
0028:        import java.awt.event.ActionEvent;
0029:        import java.awt.event.ActionListener;
0030:        import java.io.File;
0031:        import java.io.IOException;
0032:        import java.util.List;
0033:        import java.util.Iterator;
0034:        import java.util.Map;
0035:        import java.util.HashMap;
0036:        import java.util.Properties;
0037:        import javax.swing.Icon;
0038:        import javax.swing.ImageIcon;
0039:        import javax.swing.JButton;
0040:        import javax.swing.JFileChooser;
0041:        import javax.swing.JLabel;
0042:        import javax.swing.JOptionPane;
0043:        import javax.swing.JPanel;
0044:        import javax.swing.JRootPane;
0045:        import javax.swing.JTabbedPane;
0046:        import javax.swing.JTextField;
0047:        import javax.swing.JEditorPane;
0048:        import javax.swing.text.StyledDocument;
0049:        import javax.swing.tree.TreeNode;
0050:
0051:        import org.openide.ErrorManager;
0052:        import org.openide.cookies.*;
0053:        import org.openide.nodes.Node;
0054:        import org.openide.util.HelpCtx;
0055:        import org.openide.util.NbBundle;
0056:        import org.openide.util.actions.*;
0057:        import org.openide.util.Lookup;
0058:        import org.openide.filesystems.FileObject;
0059:        import org.openide.loaders.DataObject;
0060:        import org.openide.loaders.MultiDataObject;
0061:        import org.openide.filesystems.FileUtil;
0062:        import org.openide.windows.*;
0063:        import org.openide.text.NbDocument;
0064:        import org.openide.text.Annotation;
0065:
0066:        import org.netbeans.modules.java.JavaDataObject;
0067:        import org.netbeans.modules.java.JavaEditor;
0068:        import org.netbeans.modules.java.JavaDataLoader;
0069:
0070:        import edu.umd.cs.findbugs.DetectorFactoryCollection;
0071:        import net.sourceforge.jrefactory.uml.loader.ReloaderSingleton;
0072:        import org.acm.seguin.ide.command.CommandLineSourceBrowser;
0073:        import org.acm.seguin.ide.common.ASTViewerPane;
0074:        import org.acm.seguin.ide.common.CPDDuplicateCodeViewer;
0075:        import org.acm.seguin.ide.common.CodingStandardsViewer;
0076:        import org.acm.seguin.ide.common.ExitOnCloseAdapter;
0077:        import org.acm.seguin.ide.common.IDEInterface;
0078:        import org.acm.seguin.ide.common.IDEPlugin;
0079:        import org.acm.seguin.ide.common.PackageSelectorPanel;
0080:        import org.acm.seguin.ide.common.SourceBrowser;
0081:        import org.acm.seguin.ide.common.options.PropertiesFile;
0082:        import org.acm.seguin.util.FileSettings;
0083:        import org.acm.seguin.io.AllFileFilter;
0084:        import org.acm.seguin.pmd.RuleContext;
0085:        import org.acm.seguin.pmd.RuleViolation;
0086:        import org.acm.seguin.pmd.cpd.CPD;
0087:        import org.acm.seguin.pmd.cpd.FileFinder;
0088:        import org.acm.seguin.pmd.cpd.JavaLanguage;
0089:        import org.acm.seguin.summary.*;
0090:        import org.acm.seguin.tools.RefactoryInstaller;
0091:
0092:        /**
0093:         *@author     Mike Atkinson (<a href="mailto:javastyle@ladyshot.demon.co.uk">
0094:         *      Mike@ladyshot.demon.co.uk</a> )
0095:         *@created    30 September 2003
0096:         *@version    $Version: $
0097:         *@since      1.0
0098:         */
0099:
0100:        public class JRefactory extends TopComponent implements  IDEInterface {
0101:            // Possible that you may break serialization of this class accidentally:
0102:            private MySerObject state;
0103:            private transient Properties ideProperties = new Properties();
0104:            private transient JTabbedPane mainstage;
0105:            private transient JPanel jRefactoryPanel;
0106:            private transient CPDDuplicateCodeViewer cpdViewer;
0107:            private transient CodingStandardsViewer csViewer;
0108:            private transient ASTViewerPane astv;
0109:            private transient Frame aView;
0110:            private transient JRootPane findBugs = null;
0111:
0112:            private transient Annotation prevAnnotation = null;
0113:            private transient int prevLine = -1;
0114:            /*
0115:             *  // The above assumes that the SomeType is safely serializable, e.g. String or Date.
0116:             *  // If it is some class of your own that might change incompatibly, use e.g.:
0117:             *  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
0118:             *  super.readExternal(in);
0119:             *  NbMarshalledObject read = (NbMarshalledObject)in.readObject();
0120:             *  if (read != null) {
0121:             *  try {
0122:             *  setSomeState((SomeType)read.get());
0123:             *  } catch (Exception e) {
0124:             *  ErrorManager.getDefault().notify(e);
0125:             *  // If the problem would make this component inconsistent, use:
0126:             *  // throw new SafeException(e);
0127:             *  }
0128:             *  }
0129:             *  }
0130:             *  public void writeExternal(ObjectOutput out) throws IOException {
0131:             *  super.writeExternal(out);
0132:             *  Object toWrite;
0133:             *  try {
0134:             *  toWrite = new NbMarshalledObject(getSomeState());
0135:             *  } catch (Exception e) {
0136:             *  ErrorManager.getDefault().notify(e);
0137:             *  toWrite = null;
0138:             *  // Again you may prefer to use:
0139:             *  // throw new SafeException(e);
0140:             *  }
0141:             *  out.writeObject(toWrite);
0142:             *  }
0143:             */
0144:            /*
0145:             *  // Use this to discard the component after restarts (make it nonpersistent):
0146:             *  private Object readResolve() throws ObjectStreamException {
0147:             *  return null;
0148:             *  // If you wish to conditionally discard it, make readExternal set
0149:             *  // or clear some flag acc. to the condition, then use:
0150:             *  // return discardFlag ? null : this;
0151:             *  // Singleton component using private static JRefactory theInstance:
0152:             *  // if (theInstance == null) theInstance = this;
0153:             *  // return theInstance;
0154:             *  }
0155:             */
0156:            // ACTIONS
0157:            /*
0158:             *  // If you wish to have extra actions appear in the window's
0159:             *  // popup menu, they can go here:
0160:             *  public SystemAction[] getSystemActions() {
0161:             *  SystemAction[] supe = super.getSystemActions();
0162:             *  SystemAction[] mine = new SystemAction[supe.length + 1];
0163:             *  System.arraycopy(supe, 0, mine, 0, supe.length);
0164:             *  mine[supe.length] = SystemAction.get(SomeActionOfMine.class);
0165:             *  return mine;
0166:             *  }
0167:             */
0168:            /*
0169:             *  // Associate implementations with copying, searching, etc.:
0170:             *  protected void componentActivated() {
0171:             *  ((CallbackSystemAction)SystemAction.get(FindAction.class)).setActionPerformer(new ActionPerformer() {
0172:             *  public void performAction(SystemAction action) {
0173:             *  // search this component somehow
0174:             *  }
0175:             *  });
0176:             *  // similar for CopyAction, CutAction, DeleteAction, GotoAction, ReplaceAction, etc.
0177:             *  // for PasteAction, use:
0178:             *  // ((PasteAction)SystemAction.get(PasteAction.class)).setPasteTypes(new PasteType[] {...});
0179:             *  }
0180:             *  protected void componentDeactivated() {
0181:             *  // FindAction will be turned off by itself
0182:             *  // ((PasteAction)SystemAction.get(PasteAction.class)).setPasteTypes(null);
0183:             *  }
0184:             */
0185:            /*
0186:             *  // If you want UndoAction and RedoAction to be enabled on this component:
0187:             *  public UndoRedo getUndoRedo() {
0188:             *  return new MyUndoRedo(this);
0189:             *  }
0190:             */
0191:            // Printing, saving, compiling, etc.: use cookies on some appropriate node and
0192:            // use this node as the node selection.
0193:
0194:            /**
0195:             *  Description of the Field
0196:             */
0197:            public static final String OPTION_RULES_PREFIX = "options.pmd.rules.";
0198:            /**
0199:             *  Description of the Field
0200:             */
0201:            public static final String OPTION_UI_DIRECTORY_POPUP = "pmd.ui.directorypopup";
0202:            /**
0203:             *  Description of the Field
0204:             */
0205:            public static final String DEFAULT_TILE_MINSIZE_PROPERTY = "pmd.cpd.defMinTileSize";
0206:            /**
0207:             *  Description of the Field
0208:             */
0209:            public static final String NAME = "javastyle";
0210:
0211:            /**
0212:             *  Description of the Field
0213:             */
0214:            public static File PRETTY_SETTINGS_FILE;
0215:            /**
0216:             *  Description of the Field
0217:             */
0218:            public static String JAVASTYLE_DIR = "";
0219:            /*
0220:             *  public HelpCtx getHelpCtx() {
0221:             *  return new HelpCtx(JRefactory.class);
0222:             *  }
0223:             */
0224:            /*
0225:             *  // If you are using CloneableTopComponent, probably you should override:
0226:             *  protected CloneableTopComponent createClonedObject() {
0227:             *  return new JRefactory();
0228:             *  }
0229:             *  protected boolean closeLast() {
0230:             *  // You might want to prompt the user first and maybe return false:
0231:             *  return true;
0232:             *  }
0233:             */
0234:            // APPEARANCE
0235:            /**
0236:             *  This method is called from within the constructor to initialize the form.
0237:             *  WARNING: Do NOT modify this code. The content of this method is always
0238:             *  regenerated by the FormEditor.
0239:             */
0240:
0241:            // Variables declaration - do not modify
0242:            // End of variables declaration
0243:            // MODES AND WORKSPACES
0244:            /*
0245:             *  // If you want it to open in a specific mode:
0246:             *  public static final String JRefactory_MODE = "JRefactory";
0247:             *  public void open(Workspace ws) {
0248:             *  super.open(ws);
0249:             *  if (ws == null) ws = WindowManager.getDefault().getCurrentWorkspace();
0250:             *  Mode m = ws.findMode(JRefactory_MODE);
0251:             *  if (m == null) {
0252:             *  try {
0253:             *  m = ws.createMode(JRefactory_MODE, // code name
0254:             *  NbBundle.getMessage(JRefactory.class, "LBL_mode_name"), // display name
0255:             *  new URL("nbresloc:/src/JRefactoryIcon.gif"));
0256:             *  } catch (MalformedURLException mfue) {
0257:             *  ErrorManager.getDefault().notify(mfue);
0258:             *  return;
0259:             *  }
0260:             *  // If you want it in a specific position:
0261:             *  // m.setBounds(...ws.getBounds()...);
0262:             *  }
0263:             *  m.dockInto(this);
0264:             *  }
0265:             */
0266:            /*
0267:             *  // If you are not specifying a mode you may wish to use:
0268:             *  public Dimension getPreferredSize() {
0269:             *  return ...WindowManager.getDefault().getCurrentWorkspace().getBounds()...;
0270:             *  }
0271:             */
0272:            /*
0273:             *  // If you want it to open on a specific workspace:
0274:             *  public static final String JRefactory_WORKSPACE = NbBundle.getMessage(JRefactory.class, "LBL_workspace_name");
0275:             *  public void open() {
0276:             *  WindowManager wm = WindowManager.getDefault();
0277:             *  Workspace ws = wm.findWorkspace(JRefactory_WORKSPACE);
0278:             *  if (ws == null)
0279:             *  ws = wm.createWorkspace(JRefactory_WORKSPACE);
0280:             *  open(ws);
0281:             *  ws.activate();
0282:             *  }
0283:             */
0284:            // PERSISTENCE
0285:            private static final long serialVersionUID = 5L;
0286:            /**
0287:             *  Description of the Field
0288:             */
0289:
0290:            /**
0291:             *  Description of the Field
0292:             */
0293:            private static JRefactory jsPlugin = null;
0294:            private static PropertiesFile properties = null;
0295:            private static final File userDir = new File(System
0296:                    .getProperty("user.dir"));
0297:            //private JPanel panel = null;
0298:            private static Map propertiesMap = new HashMap();
0299:
0300:            /**
0301:             *  Constructor for the JRefactory object
0302:             */
0303:            public JRefactory() {
0304:                log("JRefactory()");
0305:                initThisComponent();
0306:            }
0307:
0308:            // REMEMBER: You should have a public default constructor!
0309:            // This is for externalization. If you have a nondefault
0310:            // constructor for normal creation of the component, leave
0311:            // in a default constructor that will put the component into
0312:            // a consistent but unconfigured state, and make sure readExternal
0313:            // initializes it properly. Or, be creative with writeReplace().
0314:            /**
0315:             *  Constructor for the JRefactory object
0316:             *
0317:             *@param  view  Description of Parameter
0318:             */
0319:            public JRefactory(Frame view) {
0320:                log("JRefactory(" + view + ")");
0321:                aView = view;
0322:                initThisComponent();
0323:            }
0324:
0325:            /**
0326:             *  Sets the View attribute of the JRefactory object
0327:             *
0328:             *@param  view  The new View value
0329:             */
0330:            public void setView(Frame view) {
0331:                cpdViewer.setView(view);
0332:                csViewer.setView(view);
0333:                astv.setView(view);
0334:                findBugs = org.acm.seguin.findbugs.FindBugsFrame
0335:                        .createFindBugsPanel(view);
0336:            }
0337:
0338:            /**
0339:             *  Sets the line number
0340:             *
0341:             *@param  view        The new LineNumber value
0342:             *@param  buffer      The new LineNumber value
0343:             *@param  lineNumber  The new lineNumber value
0344:             */
0345:            public void setLineNumber(Frame view, Object buffer, int lineNumber) {
0346:                JavaDataObject jdo = (JavaDataObject) buffer;
0347:                EditorCookie editor = (EditorCookie) jdo
0348:                        .getCookie(EditorCookie.class);
0349:                editor.open();
0350:                try {
0351:                    StyledDocument doc = editor.openDocument();
0352:                    JEditorPane pane = getEditorPane(buffer);
0353:                    int targetOffset = NbDocument.findLineOffset(doc,
0354:                            lineNumber);
0355:                    pane.setCaretPosition(targetOffset);
0356:                } catch (IOException e) {
0357:                    e.printStackTrace();
0358:                }
0359:            }
0360:
0361:            /**
0362:             *  Sets the string in the IDE
0363:             *
0364:             *@param  view    The frame containing the IDE.
0365:             *@param  buffer  Description of Parameter
0366:             *@param  value   The new file contained in a string
0367:             */
0368:            public void setText(Frame view, Object buffer, String value) {
0369:                JEditorPane pane = getEditorPane(buffer);
0370:                if (pane != null) {
0371:                    pane.setText(value);
0372:                }
0373:            }
0374:
0375:            /**
0376:             *  Description of the Method
0377:             *
0378:             *@param  view    Description of Parameter
0379:             *@param  buffer  The new Selection value
0380:             *@param  start   The new Selection value
0381:             *@param  end     The new Selection value
0382:             */
0383:            public void setSelection(Frame view, Object buffer, int start,
0384:                    int end) {
0385:                log("setSelection(view, " + start + "," + end + ")");
0386:                javax.swing.text.Caret caret = getCaret();
0387:                caret.setDot(start);
0388:                caret.moveDot(end);
0389:                caret.setVisible(true);
0390:                caret.setSelectionVisible(true);
0391:                //for (int lineNo=start; lineNo<=end; lineNo++) {
0392:                //    log("  line="+lineNo);
0393:                //    addAnnotation(view, buffer, IDEInterface.CUT_AND_PASTE_DETECTOR, lineNo, "duplicate code");
0394:                //}
0395:            }
0396:
0397:            /**
0398:             *  Description of the Method
0399:             *
0400:             *@param  view      Description of Parameter
0401:             *@param  fileName  The new Buffer value
0402:             */
0403:            public void setBuffer(Frame view, Object fileName) {
0404:                try {
0405:                    if (fileName instanceof  JavaDataObject) {
0406:                        JavaDataObject jdo = (JavaDataObject) fileName;
0407:                        EditorCookie editor = (EditorCookie) jdo
0408:                                .getCookie(EditorCookie.class);
0409:                        //log("ec="+ec);
0410:                        editor.open();
0411:                        return;
0412:                    }
0413:                    DataObject dataObj = null;
0414:                    if (fileName instanceof  String) {
0415:                        File file = new File((String) fileName);
0416:                        FileObject fileObj = FileUtil.fromFile(file)[0];
0417:                        //log("fileObj="+fileObj);
0418:                        if (fileObj != null) {
0419:                            dataObj = DataObject.find(fileObj);
0420:                        }
0421:                        if (dataObj == null) {
0422:                            JavaDataLoader dataLoader = new JavaDataLoader();
0423:                            //log("dataLoader="+dataLoader);
0424:                            dataObj = new JavaDataObject(fileObj, dataLoader);
0425:                        }
0426:                    } else if (fileName instanceof  MultiDataObject) {
0427:                        dataObj = ((MultiDataObject) fileName);
0428:                    }
0429:                    //log("dataObj="+dataObj);
0430:                    if (dataObj != null) {
0431:                        JavaEditor editor = (JavaEditor) dataObj
0432:                                .getCookie(JavaEditor.class);
0433:                        //log("editor="+editor);
0434:                        editor.open();
0435:                    }
0436:                } catch (IOException e) {
0437:                    JOptionPane.showMessageDialog(view, e.getMessage(),
0438:                            "JRefactory", JOptionPane.INFORMATION_MESSAGE);
0439:                }
0440:            }
0441:
0442:            /**
0443:             *  Gets the PersistenceType attribute of the JRefactory object
0444:             *
0445:             *@return    The PersistenceType value
0446:             */
0447:            public int getPersistenceType() {
0448:                return PERSISTENCE_ALWAYS;
0449:            }
0450:
0451:            /**
0452:             *  Gets the Frame attribute of the JRefactory object
0453:             *
0454:             *@return    The Frame value
0455:             */
0456:            public Frame getFrame() {
0457:                return aView;
0458:            }
0459:
0460:            /**
0461:             *  Gets the CodingStandardsViewer attribute of the JRefactory object
0462:             *
0463:             *@return    The CodingStandardsViewer value
0464:             */
0465:            public CodingStandardsViewer getCodingStandardsViewer() {
0466:                return csViewer;
0467:            }
0468:
0469:            /**
0470:             *  Gets the IDEProperty attribute of the IDEInterface object
0471:             *
0472:             *@param  prop  Description of Parameter
0473:             *@return       The IDEProperty value
0474:             */
0475:            public String getIDEProperty(String prop) {
0476:                //log("getIDEProperty(" + prop + ")");
0477:                return ideProperties.getProperty(prop);
0478:            }
0479:
0480:            /**
0481:             *  Gets the IDEProperty attribute of the IDEInterface object
0482:             *
0483:             *@param  prop   Description of Parameter
0484:             *@param  deflt  Description of Parameter
0485:             *@return        The IDEProperty value
0486:             */
0487:            public String getIDEProperty(String prop, String deflt) {
0488:                //log("getIDEProperty(" + prop + "," + deflt + ")");
0489:                return ideProperties.getProperty(prop, deflt);
0490:            }
0491:
0492:            /**
0493:             *  Gets the IDEProjects attribute of the IDEInterface object
0494:             *
0495:             *@param  parent  Description of Parameter
0496:             *@return         The IDEProjects value
0497:             */
0498:            public String[] getIDEProjects(Frame parent) {
0499:                //log("getIDEProjects(" + parent + ")");
0500:                return new String[] { "default" };
0501:                // FIXME: only gets "default" project at present.
0502:            }
0503:
0504:            /**
0505:             *  Description of the Method
0506:             *
0507:             *@param  view    Description of Parameter
0508:             *@param  buffer  Description of Parameter
0509:             *@return         The ProjectName value
0510:             */
0511:            public String getProjectName(Frame view, Object buffer) {
0512:                return getProjectName(view);
0513:            }
0514:
0515:            /**
0516:             *  Description of the Method
0517:             *
0518:             *@param  buffer  Description of Parameter
0519:             *@return         The File path for this buffer
0520:             */
0521:            public String getFilePathForBuffer(Object buffer) {
0522:                JavaDataObject jdo = (JavaDataObject) buffer;
0523:                FileObject primary = jdo.getPrimaryEntry().getFile();
0524:                String path = primary.getPath();
0525:                try {
0526:                    String fsPath = primary.getFileSystem().toString();
0527:                    fsPath = fsPath.substring(0, fsPath.indexOf('['));
0528:                    File fullPath = new File(new File(fsPath), primary
0529:                            .getPath());
0530:                    path = fullPath.getPath();
0531:                } catch (Exception e) {
0532:                    e.printStackTrace();
0533:                }
0534:                return path;
0535:            }
0536:
0537:            /**
0538:             *  Returns the frame that contains the editor. If this is not available or
0539:             *  you want dialog boxes to be centered on the screen return null from this
0540:             *  operation.
0541:             *
0542:             *@return    the frame
0543:             */
0544:            public Frame getEditorFrame() {
0545:                return aView;
0546:            }
0547:
0548:            /**
0549:             *  Get the current (atcive) buffer.
0550:             *
0551:             *@param  view  The frame containing the IDE.
0552:             *@return       The active buffer or null if no active buffer.
0553:             */
0554:            public Object getCurrentBuffer(Frame view) {
0555:                JavaDataObject jdo = null;
0556:                Mode mode = WindowManager.getDefault().findMode("editor");
0557:                TopComponent[] topc = mode.getTopComponents();
0558:                for (int n = 0; n < topc.length; n++) {
0559:                    if (topc[n].isVisible()
0560:                            && topc[n] instanceof  JavaEditor.JavaEditorComponent) {
0561:                        Lookup lookup = topc[n].getLookup();
0562:                        jdo = (JavaDataObject) lookup
0563:                                .lookup(JavaDataObject.class);
0564:                        break;
0565:                    }
0566:                }
0567:                return jdo;
0568:            }
0569:
0570:            /**
0571:             *  Get the line number of the cursor within the current buffer.
0572:             *
0573:             *@param  x:String  Description of Parameter
0574:             *@param  buffer    Description of Parameter
0575:             *@return           The line number of the cursor in the current buffer, or
0576:             *      -1 if no current buffer.
0577:             */
0578:            public int getLineNumber(Frame view, Object buffer) {
0579:                JavaDataObject jdo = (JavaDataObject) buffer;
0580:                EditorCookie editor = (EditorCookie) jdo
0581:                        .getCookie(EditorCookie.class);
0582:                editor.open();
0583:                try {
0584:                    StyledDocument doc = editor.openDocument();
0585:                    JEditorPane pane = getEditorPane(buffer);
0586:                    int pos = pane.getCaretPosition();
0587:                    return NbDocument.findLineNumber(doc, pos);
0588:                } catch (IOException e) {
0589:                    e.printStackTrace();
0590:                }
0591:                return 0;
0592:            }
0593:
0594:            /**
0595:             *  Gets the file that is being edited
0596:             *
0597:             *@param  view    Description of Parameter
0598:             *@param  buffer  Description of Parameter
0599:             *@return         The File value
0600:             */
0601:            public File getFile(Frame view, Object buffer) {
0602:                try {
0603:                    if (buffer != null && buffer instanceof  JavaDataObject) {
0604:                        JavaDataObject jdo = (JavaDataObject) buffer;
0605:                        FileObject primary = jdo.getPrimaryFile();
0606:                        String fsPath = primary.getFileSystem().toString();
0607:                        fsPath = fsPath.substring(0, fsPath.indexOf('['));
0608:                        return new File(new File(fsPath), primary.getPath());
0609:                    }
0610:                } catch (Exception e) {
0611:                    e.printStackTrace();
0612:                }
0613:                log("getFile(view" + ", " + buffer + ") FAILED");
0614:                return null;
0615:            }
0616:
0617:            /**
0618:             *  Description of the Method
0619:             *
0620:             *@param  view    Description of Parameter
0621:             *@param  buffer  Description of Parameter
0622:             *@return         The Text value
0623:             */
0624:            public String getText(Frame view, Object buffer) {
0625:                //log("getText(view)->"+ (((JEditorPane)buffer).getText()));
0626:                JEditorPane pane = getEditorPane(buffer);
0627:                if (pane != null) {
0628:                    return pane.getText();
0629:                }
0630:                log("ERROR: can't get text for:");
0631:                log("view=" + view);
0632:                log("buffer=" + buffer);
0633:                return "";
0634:            }
0635:
0636:            /**
0637:             *  Description of the Method
0638:             *
0639:             *@param  buffer  Description of Parameter
0640:             *@param  begin   Description of Parameter
0641:             *@return         The BeginLine value
0642:             */
0643:            public int getLineStartOffset(Object buffer, int begin) {
0644:                //log("getLineStartOffset(" + buffer + "," + begin + ")");
0645:                JavaDataObject jdo = (JavaDataObject) buffer;
0646:                EditorCookie editor = (EditorCookie) jdo
0647:                        .getCookie(EditorCookie.class);
0648:                editor.open();
0649:                try {
0650:                    StyledDocument doc = editor.openDocument();
0651:                    return NbDocument.findLineOffset(doc, begin);
0652:                } catch (IOException e) {
0653:                    e.printStackTrace();
0654:                }
0655:                String text = getText(null, buffer);
0656:                int index = 0;
0657:                int pos = begin;
0658:                while (pos > 0 && index < text.length()) {
0659:                    if (text.charAt(index++) == '\n') {
0660:                        pos--;
0661:                    }
0662:                }
0663:                return index;
0664:            }
0665:
0666:            /**
0667:             *  Description of the Method
0668:             *
0669:             *@param  buffer  Description of Parameter
0670:             *@param  end     Description of Parameter
0671:             *@return         The LineEndOffset value
0672:             */
0673:            public int getLineEndOffset(Object buffer, int end) {
0674:                //log("getLineEndOffset(" + buffer + "," + end + ")");
0675:                JavaDataObject jdo = (JavaDataObject) buffer;
0676:                EditorCookie editor = (EditorCookie) jdo
0677:                        .getCookie(EditorCookie.class);
0678:                editor.open();
0679:                try {
0680:                    StyledDocument doc = editor.openDocument();
0681:                    return NbDocument.findLineOffset(doc, end);
0682:                } catch (IOException e) {
0683:                    e.printStackTrace();
0684:                }
0685:                String text = getText(null, buffer);
0686:                int index = 0;
0687:                int pos = end;
0688:                while (pos > 0 && index < text.length()) {
0689:                    if (text.charAt(index++) == '\n') {
0690:                        pos--;
0691:                    }
0692:                }
0693:                return index;
0694:            }
0695:
0696:            /**
0697:             *  Gets the Properties attribute of the JavaStylePlugin class
0698:             *
0699:             *@param  type     Description of Parameter
0700:             *@param  project  Description of Parameter
0701:             *@return          The Properties value
0702:             */
0703:            public PropertiesFile getProperties(String type, String project) {
0704:                //log("getProperties(" + type+","+project + ")");
0705:
0706:                String key = type + "::"
0707:                        + (("default".equals(project)) ? null : project);
0708:                PropertiesFile propertiesFile = (PropertiesFile) propertiesMap
0709:                        .get(key);
0710:
0711:                //log("  key="+key+" ->propertiesFile="+propertiesFile);
0712:                if (propertiesFile == null) {
0713:                    //log("  getting Properties(FileSettings.getSettings("+project+", \"Refactory\", "+type+")");
0714:                    propertiesFile = new PropertiesFile(
0715:                            org.acm.seguin.util.FileSettings.getSettings(
0716:                                    project, "Refactory", type));
0717:                    propertiesMap.put(key, propertiesFile);
0718:                }
0719:                return propertiesFile;
0720:            }
0721:
0722:            /**
0723:             *  Description of the Method
0724:             *
0725:             *@param  buffer  Description of Parameter
0726:             *@return         The LineEndOffset value
0727:             */
0728:            public int getLineCount(Object buffer) {
0729:                //log("getLineCount(" + buffer + ")");
0730:                String text = getText(null, buffer);
0731:                int lineCount = 1;
0732:                int index = 0;
0733:                while (index < text.length()) {
0734:                    if (text.charAt(index++) == '\n') {
0735:                        lineCount++;
0736:                    }
0737:                }
0738:                return lineCount;
0739:            }
0740:
0741:            /**
0742:             *  Gets the userSelection attribute of the JRefactory object
0743:             */
0744:            public void getUserSelection() {
0745:                JFileChooser chooser = new JFileChooser();
0746:
0747:                //  Add other file filters - All
0748:                AllFileFilter allFilter = new AllFileFilter();
0749:                chooser.addChoosableFileFilter(allFilter);
0750:
0751:                //  Set it so that files and directories can be selected
0752:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0753:
0754:                //  Set the directory to the current directory
0755:                chooser.setCurrentDirectory(userDir);
0756:
0757:                int returnVal = chooser.showOpenDialog(null);
0758:                if (returnVal == JFileChooser.APPROVE_OPTION) {
0759:                    PackageSelectorPanel panel = PackageSelectorPanel
0760:                            .getMainPanel(chooser.getSelectedFile()
0761:                                    .getAbsolutePath());
0762:                    ReloaderSingleton.register(panel);
0763:                    mainstage.setComponentAt(0, panel.getPanel());
0764:                } else {
0765:                    mainstage.setComponentAt(0, new ReloadChooserPanel());
0766:                }
0767:            }
0768:
0769:            /**
0770:             *  Description of the Method
0771:             *
0772:             *@return    Description of the Returned Value
0773:             */
0774:            public String preferredID() {
0775:                return "JRefactory";
0776:            }
0777:
0778:            // ...
0779:
0780:            /**
0781:             *  Description of the Method
0782:             *
0783:             *@param  oo               Description of Parameter
0784:             *@exception  IOException  Description of Exception
0785:             */
0786:            public void writeExternal(java.io.ObjectOutput oo)
0787:                    throws IOException {
0788:                super .writeExternal(oo);
0789:                state = new MySerObject();
0790:                state.xxx = 10;
0791:                Object toWrite;
0792:                try {
0793:                    toWrite = new org.openide.util.io.NbMarshalledObject(state);
0794:                } catch (Exception e) {
0795:                    ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
0796:                    toWrite = null;
0797:                }
0798:                oo.writeObject(toWrite);
0799:            }
0800:
0801:            /**
0802:             *  Description of the Method
0803:             *
0804:             *@param  oi                          Description of Parameter
0805:             *@exception  IOException             Description of Exception
0806:             *@exception  ClassNotFoundException  Description of Exception
0807:             */
0808:            public void readExternal(java.io.ObjectInput oi)
0809:                    throws ClassNotFoundException, IOException {
0810:                super .readExternal(oi);
0811:                state = new MySerObject();
0812:                org.openide.util.io.NbMarshalledObject read = (org.openide.util.io.NbMarshalledObject) oi
0813:                        .readObject();
0814:                if (read != null) {
0815:                    try {
0816:                        state = (MySerObject) read.get();
0817:                    } catch (Exception e) {
0818:                        ErrorManager.getDefault().notify(ErrorManager.WARNING,
0819:                                e);
0820:                    }
0821:                }
0822:                log("state.xxx=" + state.xxx);
0823:            }
0824:
0825:            /**
0826:             *  Create a new <code>JRefactory</code>.
0827:             *
0828:             */
0829:            public void initComponents() {
0830:                initThisComponent();
0831:            }
0832:
0833:            /**
0834:             *  Description of the Method
0835:             */
0836:            public void showCSTab() {
0837:                mainstage.setSelectedComponent(csViewer);
0838:            }
0839:
0840:            /**
0841:             *  Description of the Method
0842:             */
0843:            public void showCPDTab() {
0844:                mainstage.setSelectedComponent(cpdViewer);
0845:            }
0846:
0847:            /**
0848:             *  Description of the Method
0849:             */
0850:            public void showJRefactoryTab() {
0851:                mainstage.setSelectedComponent(jRefactoryPanel);
0852:            }
0853:
0854:            /**
0855:             *  Load an icon from the IDE
0856:             *
0857:             *@param  name  The name of the icon.
0858:             *@return       An icon (or null if the icon cannot be found).
0859:             */
0860:            public Icon loadIcon(String name) {
0861:                ClassLoader classLoader = this .getClass().getClassLoader();
0862:                Icon icon = null;
0863:                try {
0864:                    icon = new ImageIcon(classLoader.getResource(name));
0865:                } catch (Exception e) {
0866:                }
0867:                if (icon == null) {
0868:                    try {
0869:                        icon = new ImageIcon(classLoader
0870:                                .getResource("org/acm/seguin/ide/common/icons/"
0871:                                        + name));
0872:                    } catch (Exception e) {
0873:                    }
0874:                }
0875:                return icon;
0876:            }
0877:
0878:            /**
0879:             *  Does the buffer contain Java source code.
0880:             *
0881:             *@param  view    The frame containing the IDE.
0882:             *@param  buffer  Description of Parameter
0883:             *@return         <code>true</code> if the buffer contains Java source code,
0884:             *      <code>false</code> otherwise.
0885:             */
0886:            public boolean bufferContainsJavaSource(Frame view, Object buffer) {
0887:                //log("bufferContainsJavaSource(view" + ", " + buffer + ")");
0888:                return (buffer != null && buffer instanceof  JavaDataObject);
0889:            }
0890:
0891:            /**
0892:             *  Indicates that a buffer has been parsed and that an Abstract Syntax Tree
0893:             *  is available.
0894:             *
0895:             *@param  view             The frame containing the IDE.
0896:             *@param  buffer           The buffer (containing Java Source) that has been
0897:             *      parsed.
0898:             *@param  compilationUnit  The root node of the AST.
0899:             */
0900:            public void bufferParsed(Frame view, Object buffer,
0901:                    net.sourceforge.jrefactory.ast.Node compilationUnit) {
0902:                log("NOT IMPLEMENTED: bufferParsed()");
0903:            }
0904:
0905:            /**
0906:             *  Indicates that a buffer has been parsed and that a navigator tree of the
0907:             *  source is available.
0908:             *
0909:             *@param  view    The frame containing the IDE.
0910:             *@param  buffer  The buffer (containing Java Source) that has been parsed.
0911:             *@param  node    The root node of the tree.
0912:             */
0913:            public void bufferNavigatorTree(Frame view, Object buffer,
0914:                    TreeNode node) {
0915:                log("NOT IMPLEMENTED: bufferNavigatorTree()");
0916:            }
0917:
0918:            /**
0919:             *  Description of the Method
0920:             *
0921:             *@param  view    Description of Parameter
0922:             *@param  buffer  Description of Parameter
0923:             */
0924:            public void goToBuffer(Frame view, Object buffer) {
0925:                log("goToBuffer(view" + ", " + buffer + ")");
0926:                JEditorPane editor = getEditorPane(buffer);
0927:                java.awt.Container pane = editor;
0928:                //log("  pane=" + pane);
0929:                while (pane != null
0930:                        && !(pane instanceof  javax.swing.JTabbedPane)) {
0931:                    pane = pane.getParent();
0932:                    //log("  pane=" + pane);
0933:                    if (pane instanceof  javax.swing.JTabbedPane) {
0934:                        ((javax.swing.JTabbedPane) pane)
0935:                                .setSelectedComponent(editor);
0936:                    }
0937:                }
0938:            }
0939:
0940:            private transient java.awt.Cursor oldCursor = null;
0941:
0942:            /**
0943:             *  Description of the Method
0944:             *
0945:             *@param  parent  Description of Parameter
0946:             */
0947:            public void showWaitCursor(Frame parent) {
0948:                log("showWaitCursor(" + parent + ")");
0949:                oldCursor = parent.getCursor();
0950:                java.awt.Cursor cursor = java.awt.Cursor
0951:                        .getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR);
0952:                parent.setCursor(cursor);
0953:            }
0954:
0955:            /**
0956:             *  Description of the Method
0957:             *
0958:             *@param  parent  Description of Parameter
0959:             */
0960:            public void hideWaitCursor(Frame parent) {
0961:                log("hideWaitCursor(" + parent + ")");
0962:                if (oldCursor == null) {
0963:                    parent.setCursor(java.awt.Cursor.getDefaultCursor());
0964:                } else {
0965:                    parent.setCursor(oldCursor);
0966:                }
0967:            }
0968:
0969:            /**
0970:             *  Description of the Method
0971:             *
0972:             *@param  view    Description of Parameter
0973:             *@param  buffer  Description of Parameter
0974:             */
0975:            public void checkBuffer(Frame view, Object buffer) {
0976:                log("check(view," + buffer + ")");
0977:                showCSTab();
0978:                csViewer.check(view, ((buffer == null) ? getCurrentBuffer(view)
0979:                        : buffer), false);
0980:            }
0981:
0982:            /**
0983:             *  Description of the Method
0984:             *
0985:             *@param  view  Description of Parameter
0986:             */
0987:            public void checkAllOpenBuffers(Frame view) {
0988:                log("checkAllOpenBuffers(view)");
0989:                showCSTab();
0990:                Mode mode = WindowManager.getDefault().findMode("editor");
0991:                TopComponent[] topc = mode.getTopComponents();
0992:                for (int n = 0; n < topc.length; n++) {
0993:                    if (topc[n] instanceof  JavaEditor.JavaEditorComponent) {
0994:                        Lookup lookup = topc[n].getLookup();
0995:                        JavaDataObject jdo = (JavaDataObject) lookup
0996:                                .lookup(JavaDataObject.class);
0997:                        checkBuffer(view, jdo);
0998:                    }
0999:                }
1000:            }
1001:
1002:            /**
1003:             *  Description of the Method
1004:             *
1005:             *@param  view       Description of Parameter
1006:             *@param  recursive  Description of Parameter
1007:             */
1008:            public void checkDirectory(Frame view, boolean recursive) {
1009:                //log("checkDirectory(view" + recursive + ")");
1010:                showCSTab();
1011:                JFileChooser chooser = new JFileChooser();
1012:
1013:                //  Add other file filters - All
1014:                AllFileFilter allFilter = new AllFileFilter();
1015:                chooser.addChoosableFileFilter(allFilter);
1016:
1017:                //  Set it so that files and directories can be selected
1018:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1019:
1020:                //  Set the directory to the current directory
1021:                chooser.setCurrentDirectory(userDir);
1022:
1023:                //  Get the user's selection
1024:                int returnVal = chooser.showOpenDialog(null);
1025:                if (returnVal == JFileChooser.APPROVE_OPTION) {
1026:                    process(findFiles(chooser.getSelectedFile()
1027:                            .getAbsolutePath(), recursive), view);
1028:                }
1029:            }
1030:
1031:            /**
1032:             *  Description of the Method
1033:             *
1034:             *@param  view             Description of Parameter
1035:             *@param  fileName         Description of Parameter
1036:             *@return                  Description of the Returned Value
1037:             *@exception  IOException  Description of Exception
1038:             */
1039:            public Object openFile(Frame view, String fileName)
1040:                    throws IOException {
1041:                log("openFile(view, " + fileName + ")");
1042:                File file = new File(fileName);
1043:                if (file.exists()) {
1044:                    log("file exists");
1045:                    try {
1046:                        FileObject fileObj = FileUtil.fromFile(file)[0];
1047:                        DataObject dataObj = DataObject.find(fileObj);
1048:                        if (dataObj != null) {
1049:                            JavaEditor editor = (JavaEditor) dataObj
1050:                                    .getCookie(JavaEditor.class);
1051:                            editor.open();
1052:                            return dataObj;
1053:                        } else {
1054:                            JavaDataLoader jdl = new JavaDataLoader();
1055:                            JavaDataObject jdo = new JavaDataObject(fileObj,
1056:                                    jdl);
1057:                            EditorCookie editor = (EditorCookie) jdo
1058:                                    .getCookie(EditorCookie.class);
1059:                            editor.open();
1060:                            return jdo;
1061:                        }
1062:                    } catch (IOException e) {
1063:                        JOptionPane.showMessageDialog(view, e.getMessage(),
1064:                                "JRefactory", JOptionPane.INFORMATION_MESSAGE);
1065:                    }
1066:                }
1067:                return null;
1068:            }
1069:
1070:            /**
1071:             *  Description of the Method
1072:             *
1073:             *@param  runnable  Description of Parameter
1074:             */
1075:            public void runInAWTThread(Runnable runnable) {
1076:                //log("runInAWTThread(" + runnable + ")");
1077:                runnable.run();
1078:                // FIXME: need to run in AWT Thread.
1079:            }
1080:
1081:            /**
1082:             *  Description of the Method
1083:             *
1084:             *@param  view    Description of Parameter
1085:             *@param  buffer  Description of Parameter
1086:             *@param  start   Description of Parameter
1087:             */
1088:            public void moveCaretPosition(Frame view, Object buffer, int start) {
1089:                //log("moveCaretPosition(view, " + start + ")");
1090:                javax.swing.text.Caret caret = getCaret();
1091:                caret.moveDot(start);
1092:                caret.setVisible(true);
1093:            }
1094:
1095:            /**
1096:             *  write new settings
1097:             */
1098:            public void saveProperties() {
1099:                for (java.util.Iterator i = propertiesMap.keySet().iterator(); i
1100:                        .hasNext();) {
1101:                    PropertiesFile projectProps = (PropertiesFile) propertiesMap
1102:                            .get(i.next());
1103:                    projectProps.save();
1104:                }
1105:            }
1106:
1107:            /**
1108:             *  Description of the Method
1109:             *
1110:             *@param  view             Description of Parameter
1111:             *@param  buffer           Description of Parameter
1112:             *@exception  IOException  Description of Exception
1113:             */
1114:            public void cpdBuffer(Frame view, Object buffer) throws IOException {
1115:                log("cpdBuffer(view," + buffer + ")");
1116:                showCPDTab();
1117:                if (buffer != null) {
1118:                    JavaEditor editor = ((JavaDataObject) buffer)
1119:                            .getJavaEditor();
1120:                    JEditorPane[] panes = (JEditorPane[]) editor
1121:                            .getOpenedPanes();
1122:                    if (panes != null && panes.length > 0) {
1123:                        //String str = panes[0].getText();
1124:
1125:                        CPD cpd = new CPD(100, new JavaLanguage());
1126:                        //cpd.add(new java.io.File(new java.io.StringReader(str)));
1127:
1128:                        cpd.go();
1129:                        if (cpdViewer != null) {
1130:                            cpdViewer.processDuplicates(cpd, view);
1131:                        }
1132:                    }
1133:
1134:                }
1135:
1136:            }
1137:
1138:            /**
1139:             *  Description of the Method
1140:             *
1141:             *@param  view             Description of Parameter
1142:             *@exception  IOException  Description of Exception
1143:             */
1144:            public void cpdAllOpenBuffers(Frame view) throws IOException {
1145:                log("cpdAllOpenBuffers");
1146:                showCPDTab();
1147:                Mode mode = WindowManager.getDefault().findMode("editor");
1148:                TopComponent[] topc = mode.getTopComponents();
1149:                for (int n = 0; n < topc.length; n++) {
1150:                    if (topc[n] instanceof  JavaEditor.JavaEditorComponent) {
1151:                        Lookup lookup = topc[n].getLookup();
1152:                        JavaDataObject jdo = (JavaDataObject) lookup
1153:                                .lookup(JavaDataObject.class);
1154:                        cpdBuffer(view, jdo);
1155:                    }
1156:                }
1157:            }
1158:
1159:            /**
1160:             *  Description of the Method
1161:             *
1162:             *@param  view             Description of Parameter
1163:             *@param  recursive        Description of Parameter
1164:             *@exception  IOException  Description of Exception
1165:             */
1166:            public void cpdDir(Frame view, boolean recursive)
1167:                    throws IOException {
1168:                //log("cpdDir(view)");
1169:                showCPDTab();
1170:                JFileChooser chooser = new JFileChooser(
1171:                        getIDEProperty("pmd.cpd.lastDirectory"));
1172:
1173:                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1174:
1175:                JPanel pnlAccessory = new JPanel();
1176:
1177:                pnlAccessory.add(new JLabel("Minimum Tile size :"));
1178:
1179:                JTextField txttilesize = new JTextField("100");
1180:
1181:                pnlAccessory.add(txttilesize);
1182:                chooser.setAccessory(pnlAccessory);
1183:
1184:                int returnVal = chooser.showOpenDialog(view);
1185:                File selectedFile = null;
1186:
1187:                if (returnVal == JFileChooser.APPROVE_OPTION) {
1188:                    selectedFile = chooser.getSelectedFile();
1189:                    if (!selectedFile.isDirectory()) {
1190:                        JOptionPane.showMessageDialog(view,
1191:                                "Selection not a directory.", "JRefactory",
1192:                                JOptionPane.ERROR_MESSAGE);
1193:                        return;
1194:                    }
1195:                } else {
1196:                    return;
1197:                }
1198:                // In case the user presses cancel or escape.
1199:
1200:                getIDEProperty("pmd.cpd.lastDirectory", selectedFile
1201:                        .getCanonicalPath());
1202:
1203:                int tilesize = 100;
1204:
1205:                try {
1206:                    tilesize = Integer.parseInt(txttilesize.getText());
1207:                } catch (NumberFormatException e) {
1208:                    //use the default.
1209:                    tilesize = 100;
1210:                }
1211:
1212:                CPD cpd = new CPD(tilesize, new JavaLanguage());
1213:
1214:                if (recursive) {
1215:                    cpd.addRecursively(selectedFile.getCanonicalPath());
1216:                } else {
1217:                    cpd.addAllInDirectory(selectedFile.getCanonicalPath());
1218:                }
1219:
1220:                cpd.go();
1221:                if (cpdViewer != null) {
1222:                    cpdViewer.processDuplicates(cpd, view);
1223:                }
1224:            }
1225:
1226:            /**
1227:             *  Description of the Method
1228:             *
1229:             *@param  urgency  Description of Parameter
1230:             *@param  source   Description of Parameter
1231:             *@param  message  Description of Parameter
1232:             */
1233:            public void log(int urgency, Object source, Object message) {
1234:                int type = ErrorManager.INFORMATIONAL;
1235:                switch (urgency) {
1236:                case IDEInterface.DEBUG:
1237:                    type = ErrorManager.USER;
1238:                case IDEInterface.ERROR:
1239:                    type = ErrorManager.ERROR;
1240:                case IDEInterface.MESSAGE:
1241:                    type = ErrorManager.INFORMATIONAL;
1242:                case IDEInterface.NOTICE:
1243:                    type = ErrorManager.INFORMATIONAL;
1244:                case IDEInterface.WARNING:
1245:                    type = ErrorManager.WARNING;
1246:                default:
1247:                    type = ErrorManager.INFORMATIONAL;
1248:                }
1249:                System.err.println(source + ": " + message);
1250:                ErrorManager.getDefault().log(type, source + ": " + message);
1251:            }
1252:
1253:            /**
1254:             *  Adds an annotation to an ide buffer.
1255:             *
1256:             *@param  view         The frame containing the IDE.
1257:             *@param  buffer       The buffer (containing Java Source) that has been
1258:             *      parsed.
1259:             *@param  type         either CODING_STANDARDS or CUT_AND_PASTE_DETECTION
1260:             *@param  lineNo       The line number of the annotation.
1261:             *@param  description  The annotation
1262:             */
1263:            public void addAnnotation(Frame view, Object buffer, int type,
1264:                    int lineNo, String description) {
1265:                if (buffer != null) {
1266:                    JavaDataObject jdo = null;
1267:                    if (buffer instanceof  String) {
1268:                        // find the buffer for the annotation but don't load it
1269:                        File file = new File((String) buffer);
1270:                        if (file.exists()) {
1271:                            try {
1272:                                FileObject fileObj = FileUtil.fromFile(file)[0];
1273:                                jdo = (JavaDataObject) DataObject.find(fileObj);
1274:                            } catch (Exception e) {
1275:                            }
1276:                        }
1277:                    } else {
1278:                        jdo = (JavaDataObject) buffer;
1279:                    }
1280:                    if (jdo == null) {
1281:                        return;
1282:                    }
1283:                    JavaEditor editor = jdo.getJavaEditor();
1284:                    if (editor == null) {
1285:                        return;
1286:                    }
1287:                    LineCookie cookie = (LineCookie) jdo
1288:                            .getCookie(LineCookie.class);
1289:                    org.openide.text.Line.Set lineset = cookie.getLineSet();
1290:                    org.openide.text.Line line = lineset
1291:                            .getOriginal(lineNo - 1);
1292:                    if (type == IDEInterface.CODING_STANDARDS) {
1293:                        if (prevLine == lineNo
1294:                                && prevAnnotation instanceof  CSAnnotation) {
1295:                            CSAnnotation annotation = (CSAnnotation) prevAnnotation;
1296:                            annotation.setErrorMessage(annotation
1297:                                    .getShortDescription()
1298:                                    + "\n" + description);
1299:                        } else {
1300:                            CSAnnotation annotation = CSAnnotation
1301:                                    .getNewInstance();
1302:                            annotation.setErrorMessage(description);
1303:                            annotation.attach(line);
1304:                            line.addPropertyChangeListener(annotation);
1305:                        }
1306:                    } else if (type == IDEInterface.CUT_AND_PASTE_DETECTOR) {
1307:                        CPDAnnotation annotation = CPDAnnotation
1308:                                .getNewInstance();
1309:                        annotation.setErrorMessage(description);
1310:                        annotation.attach(line);
1311:                        line.addPropertyChangeListener(annotation);
1312:                    }
1313:                    line.show(org.openide.text.Line.SHOW_GOTO);
1314:                    org.openide.awt.StatusDisplayer.getDefault().setStatusText(
1315:                            description);
1316:                }
1317:            }
1318:
1319:            /**
1320:             *  Clears all annotation for an ide buffer.
1321:             *
1322:             *@param  view    The frame containing the IDE.
1323:             *@param  buffer  The buffer (containing Java Source) that has been parsed.
1324:             *@param  type    either CODING_STANDARDS or CUT_AND_PASTE_DETECTION
1325:             */
1326:            public void clearAnnotations(Frame view, Object buffer, int type) {
1327:                if (type == IDEInterface.CODING_STANDARDS) {
1328:                    CSAnnotation.clearAll();
1329:                } else if (type == IDEInterface.CUT_AND_PASTE_DETECTOR) {
1330:                    CPDAnnotation.clearAll();
1331:                }
1332:            }
1333:
1334:            /**
1335:             *  Gets the EditorPane attribute of the JRefactory object
1336:             *
1337:             *@param  buffer  Description of Parameter
1338:             *@return         The EditorPane value
1339:             */
1340:            private JEditorPane getEditorPane(Object buffer) {
1341:                if (buffer != null && buffer instanceof  JavaDataObject) {
1342:                    JavaDataObject jdo = (JavaDataObject) buffer;
1343:                    JavaEditor editor = jdo.getJavaEditor();
1344:                    JEditorPane[] panes = (JEditorPane[]) editor
1345:                            .getOpenedPanes();
1346:                    if (panes != null && panes.length > 0) {
1347:                        return panes[0];
1348:                    }
1349:                }
1350:
1351:                if (buffer != null && buffer instanceof  JEditorPane) {
1352:                    return (JEditorPane) buffer;
1353:                } else {
1354:                    //log("buffer="+buffer);
1355:                    return getCurrentEditorPane(null);
1356:                    //log("getText(view)->"+ (((JEditorPane)buffer).getText()));
1357:                }
1358:            }
1359:
1360:            /**
1361:             *  Gets the CurrentEditorPane attribute of the NetBeansExtractMethodDialog
1362:             *  object
1363:             *
1364:             *@param  cookie  Description of Parameter
1365:             *@return         The CurrentEditorPane value
1366:             */
1367:            private JEditorPane getCurrentEditorPane(EditorCookie cookie) {
1368:                WindowManager windowManager = (WindowManager) Lookup
1369:                        .getDefault().lookup(WindowManager.class);
1370:                TopComponent comp = windowManager.getRegistry().getActivated();
1371:                Node[] nodes = comp.getRegistry().getActivatedNodes();
1372:                log("nodes.length=" + nodes.length);
1373:                log("cookie=" + cookie);
1374:
1375:                //(NOTE) This is a hack fix
1376:                EditorCookie editorCookie = null;
1377:                for (int i = 0; i < nodes.length; i++) {
1378:                    editorCookie = (EditorCookie) nodes[i]
1379:                            .getCookie(EditorCookie.class);
1380:                    if (editorCookie != null) {
1381:                        JEditorPane[] panes = editorCookie.getOpenedPanes();
1382:                        //log("panes.length="+panes.length);
1383:                        if (panes != null && panes.length == 1) {
1384:                            return panes[0];
1385:                        }
1386:                        break;
1387:                    }
1388:                }
1389:
1390:                return null;
1391:            }
1392:
1393:            /**
1394:             *  Gets the Caret attribute of the JRefactory object
1395:             *
1396:             *@return    The Caret value
1397:             */
1398:            private javax.swing.text.Caret getCaret() {
1399:                JEditorPane pane = getCurrentEditorPane(null);
1400:                return (pane == null) ? null : pane.getCaret();
1401:            }
1402:
1403:            /**
1404:             *  Create a new <code>JRefactory</code>.
1405:             *
1406:             */
1407:            private void initThisComponent() {
1408:                log("initComponents() jsPlugin=" + jsPlugin);
1409:                if (jsPlugin != null) {
1410:                    return;
1411:                }
1412:                jsPlugin = this ;
1413:                IDEPlugin.setPlugin(jsPlugin);
1414:                if (aView == null) {
1415:                    aView = WindowManager.getDefault().getMainWindow();
1416:                }
1417:
1418:                log("initComponents()");
1419:                setLayout(new java.awt.BorderLayout());
1420:                Properties props = System.getProperties();
1421:                props.list(System.out);
1422:
1423:                JAVASTYLE_DIR = new File(props.getProperty("user.home")
1424:                        + File.separator + ".netbeans" + File.separator
1425:                        + "javastyle").getAbsolutePath();
1426:                PRETTY_SETTINGS_FILE = new File(JAVASTYLE_DIR + File.separator
1427:                        + ".Refactory", "pretty.settings");
1428:
1429:                // plug into JRefactory some classes that adapt it to jEdit.
1430:                ExitOnCloseAdapter.setExitOnWindowClose(false);
1431:
1432:                //  Make sure everything is installed properly
1433:                FileSettings.setSettingsRoot(JAVASTYLE_DIR);
1434:                log("running RefactoryInstaller");
1435:                (new RefactoryInstaller(true)).run();
1436:                SourceBrowser.set(new CommandLineSourceBrowser());
1437:                net.sourceforge.jrefactory.action.CurrentSummary
1438:                        .register(new NetbeansCurrentSummary(aView));
1439:
1440:                log("creating cpdViewer");
1441:                cpdViewer = new CPDDuplicateCodeViewer(aView);
1442:                PackageSelectorPanel panel = PackageSelectorPanel
1443:                        .getMainPanel(null);
1444:                jRefactoryPanel = panel.getPanel();
1445:                astv = new ASTViewerPane(aView);
1446:
1447:                try {
1448:                    ClassLoader classLoader = this .getClass().getClassLoader();
1449:                    java.net.URL url = classLoader
1450:                            .getResource("org/acm/seguin/ide/netbeans/JRefactory.class");
1451:                    //System.out.println("url="+url);
1452:                    java.util.List plugins = new java.util.ArrayList();
1453:                    if (url != null) {
1454:                        String urlStr = url.toString();
1455:                        if (urlStr.indexOf('!') > 0) {
1456:                            String xStr = urlStr.substring("jar:file:/"
1457:                                    .length(), urlStr.indexOf('!'));
1458:                            //System.out.println("xStr="+xStr);
1459:                            xStr = replace(xStr, "%20", " ");
1460:                            //System.out.println("xStr="+xStr);
1461:                            File file = new File(xStr);
1462:                            //System.out.println("file="+file);
1463:                            if (file.exists()) {
1464:                                System.out.println(" file exists");
1465:                                plugins.add(file);
1466:                            }
1467:                        }
1468:                    }
1469:                    File findBugsDir = new File(JAVASTYLE_DIR, "findbugs");
1470:                    //System.out.println("findBugsDir="+findBugsDir);
1471:                    if (findBugsDir.exists() && findBugsDir.isDirectory()) {
1472:                        File[] files = findBugsDir.listFiles();
1473:                        for (int i = 0; i < files.length; i++) {
1474:                            if (files[i].getName().endsWith(".jar")) {
1475:                                plugins.add(files[i]);
1476:                            }
1477:                        }
1478:                    }
1479:
1480:                    File corePluginFile = new File(userDir, "coreplugin.jar");
1481:                    if (corePluginFile.exists()) {
1482:                        //System.out.println(" file " + corePluginFile + " exists");
1483:                        plugins.add(corePluginFile);
1484:                    }
1485:
1486:                    log("creating findBugs");
1487:                    corePluginFile = new File("./Modules/JRefactoryModule.jar");
1488:                    log("corePluginFile=" + corePluginFile.getCanonicalPath());
1489:                    if (!corePluginFile.exists()) {
1490:                        corePluginFile = new File(
1491:                                "./Modules/autoload/JRefactoryModule.jar");
1492:                    }
1493:                    if (!corePluginFile.exists()) {
1494:                        corePluginFile = new File(
1495:                                "./Modules/eager/JRefactoryModule.jar");
1496:                    }
1497:                    if (!corePluginFile.exists()) {
1498:                        plugins.add(corePluginFile);
1499:                    }
1500:                    File[] pluginList = (File[]) plugins
1501:                            .toArray(new File[plugins.size()]);
1502:
1503:                    //File[] pluginList = (corePluginFile.exists()) ? new File[]{corePluginFile} : new File[0];
1504:                    for (int i = 0; i < pluginList.length; i++) {
1505:                        System.out.println("pluginList[" + i + "]="
1506:                                + pluginList[i]);
1507:                    }
1508:                    //File[] pluginList = (corePluginDir.exists()) ? new File[]{corePluginDir} : new File[0];
1509:                    DetectorFactoryCollection.setPluginList(pluginList);
1510:                    findBugs = org.acm.seguin.findbugs.FindBugsFrame
1511:                            .createFindBugsPanel(aView);
1512:                } catch (Throwable e) {
1513:                    e.printStackTrace();
1514:                }
1515:
1516:                log("running csViewer");
1517:                csViewer = new CodingStandardsViewer(aView);
1518:                mainstage = new JTabbedPane(JTabbedPane.TOP);
1519:                mainstage.addTab("JRefactory", jRefactoryPanel);
1520:                mainstage.addTab("Cut & paste detector", cpdViewer);
1521:                mainstage.addTab("Coding standards", csViewer);
1522:                if (findBugs != null) {
1523:                    mainstage.addTab("Find Bugs", findBugs);
1524:                }
1525:                mainstage.addTab("Abstract Syntax Tree", astv);
1526:                add(mainstage, BorderLayout.CENTER);
1527:                try {
1528:                    log("loading properties");
1529:                    ideProperties.load(getClass().getResourceAsStream(
1530:                            "/ui/JavaStyle.props"));
1531:                } catch (java.io.IOException e) {
1532:                    e.printStackTrace();
1533:                }
1534:
1535:                log("docking into explorer");
1536:                java.util.Set modes = WindowManager.getDefault().getModes();
1537:                log("== modes ==");
1538:                for (java.util.Iterator i = modes.iterator(); i.hasNext();) {
1539:                    log("  " + i.next());
1540:                }
1541:                Mode mode = WindowManager.getDefault().findMode("explorer");
1542:                log("mode=" + mode);
1543:                if (mode != null) {
1544:                    log("   opening in explorer");
1545:                    mode.dockInto(this );
1546:                    log("opening JRefactory TopComponent pane");
1547:                    open();
1548:                    requestVisible();
1549:                }
1550:
1551:                setCloseOperation(CLOSE_LAST);
1552:                // or CLOSE_EACH
1553:                // Display name of this window (not needed if you use the DataObject constructor):
1554:                setName(NbBundle.getMessage(JRefactory.class, "LBL_jrefactory"));
1555:                // You may set the icon, but often it is better to set the icon for an associated mode instead:
1556:                // setIcon(Utilities.loadImage("src/JRefactoryIcon.gif", true));
1557:                // Use the Component Inspector to set tool-tip text. This will be saved
1558:                // automatically. Other JComponent properties you may need to save yuorself.
1559:                // At any time you can affect the node selection:
1560:                // setActivatedNodes(new Node[] {...});
1561:            }
1562:
1563:            private static String replace(String from, String oldStr,
1564:                    String newStr) {
1565:                StringBuffer sb = new StringBuffer();
1566:                int y = 0;
1567:                int x = from.indexOf(oldStr);
1568:                while (x >= 0) {
1569:                    System.out.println("part=" + from.substring(y, x));
1570:                    sb.append(from.substring(y, x)).append(newStr);
1571:                    y = x + oldStr.length();
1572:                    x = from.indexOf(oldStr, y);
1573:                }
1574:                System.out.println("lastpart=" + from.substring(y));
1575:                sb.append(from.substring(y));
1576:                return sb.toString();
1577:            }
1578:
1579:            /**
1580:             *  Description of the Method
1581:             *
1582:             *@param  dir      Description of Parameter
1583:             *@param  recurse  Description of Parameter
1584:             *@return          Description of the Returned Value
1585:             */
1586:            private List findFiles(String dir, boolean recurse) {
1587:                FileFinder finder = new FileFinder();
1588:                return finder.findFilesFrom(dir,
1589:                        new JavaLanguage.JavaFileOrDirectoryFilter(), recurse);
1590:            }
1591:
1592:            /**
1593:             *  Description of the Method
1594:             *
1595:             *@param  files  Description of Parameter
1596:             *@param  view   Description of Parameter
1597:             */
1598:            private void process(final List files, final Frame view) {
1599:                new Thread(new Runnable() {
1600:                    public void run() {
1601:                        processFiles(files, view);
1602:                    }
1603:                }).start();
1604:            }
1605:
1606:            /**
1607:             *  Description of the Method
1608:             *
1609:             *@param  files  Description of Parameter
1610:             *@param  view   Description of Parameter
1611:             */
1612:            private void processFiles(List files, Frame view) {
1613:                List contexts = csViewer.checkFiles(files, view, null);
1614:                org.openide.windows.IOProvider iop = org.openide.windows.IOProvider
1615:                        .getDefault();
1616:                org.openide.windows.InputOutput inOut = iop.getIO("JRefactory",
1617:                        true);
1618:                java.io.PrintWriter out = new java.io.PrintWriter(inOut
1619:                        .getErr());
1620:
1621:                boolean foundProblems = false;
1622:                for (Iterator i = contexts.iterator(); i.hasNext();) {
1623:                    RuleContext ctx = (RuleContext) i.next();
1624:                    for (Iterator j = ctx.getReport().iterator(); j.hasNext();) {
1625:                        foundProblems = true;
1626:                        RuleViolation ruleViolation = (RuleViolation) j.next();
1627:                        //errorSource.addError(ErrorSource.WARNING, ctx.getSourceCodeFilename(), ruleViolation.getLine() - 1, 0, 0, ruleViolation.getDescription());
1628:                        out.println(ctx.getSourceCodeFilename() + " ["
1629:                                + (ruleViolation.getLine() - 1) + "] "
1630:                                + ruleViolation.getDescription());
1631:                    }
1632:                }
1633:                if (!foundProblems) {
1634:                    //JOptionPane.showMessageDialog(jEdit.getFirstView(), "No problems found", NAME, JOptionPane.INFORMATION_MESSAGE);
1635:                    //errorSource.clear();
1636:                    inOut.closeInputOutput();
1637:                }
1638:
1639:            }
1640:
1641:            /**
1642:             *  Sets the Property attribute of the JavaStylePlugin class
1643:             *
1644:             *@param  key    The new Property value
1645:             *@param  value  The new Property value
1646:             */
1647:            public static void setProperty(String key, String value) {
1648:                properties.setString(key, value);
1649:            }
1650:
1651:            /**
1652:             *  Gets the JRefactoryFrame attribute of the JRefactory class
1653:             *
1654:             *@return    The JRefactoryFrame value
1655:             */
1656:            public static Frame getJRefactoryFrame() {
1657:                ensureVisible();
1658:                return WindowManager.getDefault().getMainWindow();
1659:            }
1660:
1661:            /**
1662:             *  Gets the SettingsDirectory attribute of the JRefactory class
1663:             *
1664:             *@return    The SettingsDirectory value
1665:             */
1666:            public static String getSettingsDirectory() {
1667:                return System.getProperty("user.dir") + File.separator
1668:                        + ".JRefactory";
1669:            }
1670:
1671:            /**
1672:             *  Sets the projectData attribute of the JEditPrettyPrinter object
1673:             *
1674:             *@param  view  Description of Parameter
1675:             *@return       The projectName value
1676:             */
1677:            public static String getProjectName(Frame view) {
1678:                return "";
1679:            }
1680:
1681:            /**
1682:             *  Description of the Method
1683:             */
1684:            public static void ensureVisible() {
1685:                log("ensureVisible()");
1686:                if (jsPlugin == null) {
1687:                    jsPlugin = new JRefactory();
1688:                }
1689:                if (!jsPlugin.isVisible()) {
1690:                    Mode mode = WindowManager.getDefault().findMode("explorer");
1691:                    if (mode != null) {
1692:                        mode.dockInto(jsPlugin);
1693:                    }
1694:                    java.util.Set modes = WindowManager.getDefault().getModes();
1695:                    log("== modes2 ==");
1696:                    for (java.util.Iterator i = modes.iterator(); i.hasNext();) {
1697:                        log("  " + i.next());
1698:                    }
1699:                }
1700:                jsPlugin.open();
1701:                jsPlugin.requestVisible();
1702:            }
1703:
1704:            /**
1705:             *  Description of the Method
1706:             *
1707:             *@param  key  Description of Parameter
1708:             */
1709:            public static void deleteProperty(String key) {
1710:                properties.deleteKey(key);
1711:            }
1712:
1713:            /**
1714:             *  Description of the Method
1715:             *
1716:             *@param  message  Description of Parameter
1717:             */
1718:            public static void log(Object message) {
1719:                System.err.println("JavaStyle: " + message);
1720:                ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
1721:                        "JavaStyle: " + message);
1722:            }
1723:
1724:            /**
1725:             *  Description of the Class
1726:             *
1727:             *@author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike
1728:             *      Atkinson</a>
1729:             *@created    23 July 2003
1730:             *@version    $Id: JRefactory.java,v 1.16 2004/05/07 00:35:02 mikeatkinson Exp $
1731:             *@since      0.1.0
1732:             */
1733:            private final class ReloadChooserPanel extends JPanel {
1734:                /**
1735:                 *  Constructor for the ReloadChooserPanel object
1736:                 */
1737:                public ReloadChooserPanel() {
1738:                    //log("new ReloadChooserPanel()");
1739:                    JButton load = new JButton("load JRefactory UML viewer");
1740:                    load.addActionListener(new ActionListener() {
1741:                        public void actionPerformed(ActionEvent event) {
1742:                            JRefactory.this .getUserSelection();
1743:                        }
1744:                    });
1745:                    add(load);
1746:                }
1747:            }
1748:
1749:            /**
1750:             *  Description of the Class
1751:             *
1752:             *@author    Chris Seguin
1753:             */
1754:            public static class MySerObject implements  java.io.Serializable {
1755:                int xxx = 1;
1756:                private static final long serialVersionUID = -5300379359373857991L;
1757:            }
1758:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.