001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.ide.jbuilder;
053:
054: import com.borland.primetime.PrimeTime;
055: import com.borland.primetime.actions.ActionGroup;
056: import com.borland.primetime.actions.UpdateAction;
057: import com.borland.primetime.editor.EditorManager;
058: import com.borland.primetime.ide.Context;
059: import com.borland.primetime.ide.Browser;
060: import com.borland.primetime.ide.ProjectView;
061: import com.borland.primetime.node.DuplicateNodeException;
062: import com.borland.primetime.node.FileNode;
063: import com.borland.primetime.node.FileType;
064: import com.borland.primetime.node.Node;
065: import com.borland.primetime.node.Project;
066: import com.borland.primetime.vfs.InvalidUrlException;
067: import com.borland.primetime.vfs.Url;
068: import java.io.File;
069: import java.io.IOException;
070: import javax.swing.Action;
071: import javax.swing.Icon;
072: import javax.swing.JFrame;
073: import javax.swing.JComponent;
074: import org.acm.seguin.ide.common.action.GenericAction;
075: import org.acm.seguin.ide.common.MultipleDirClassDiagramReloader;
076: import org.acm.seguin.ide.common.PackageNameLoader;
077: import org.acm.seguin.ide.common.SourceBrowser;
078: import org.acm.seguin.ide.common.UMLIcon;
079: import org.acm.seguin.ide.common.action.CurrentSummary;
080: import org.acm.seguin.ide.common.action.ExtractMethodAction;
081: import net.sourceforge.jrefactory.action.PrettyPrinterAction;
082: import org.acm.seguin.ide.jbuilder.refactor.JBuilderCurrentSummary;
083: import org.acm.seguin.ide.jbuilder.refactor.JBuilderRefactoringFactory;
084: import org.acm.seguin.ide.jbuilder.refactor.MenuBuilder; //import org.acm.seguin.tools.RefactoryInstaller;
085: import net.sourceforge.jrefactory.uml.UMLPackage;
086: import org.acm.seguin.util.FileSettings;
087: import org.acm.seguin.ide.command.ExitMenuSelection;
088: import org.acm.seguin.ide.common.IDEPlugin;
089:
090: /**
091: * File node representing the JBuilder Plugin
092: *
093: *@author Mike Atkinson
094: *@created October 06, 2003
095: */
096: public class JBuilderPlugin extends
097: com.borland.primetime.viewer.AbstractNodeViewer {
098: private static JFrame frame;
099: private static JRefactory refactory;
100:
101: public static String JAVASTYLE_DIR = "";
102: private UMLPackage packageDiagram;
103: private String packageName;
104:
105: public JComponent createViewerComponent() {
106: return refactory;
107: }
108:
109: public JComponent createStructureComponent() {
110: return refactory;
111: }
112:
113: public JBuilderPlugin(Context context) {
114: super (context);
115:
116: JRefactory.log("JBuilderPlugin(" + context + ")");
117: Node top = context.getNode();
118: Node parent = top;
119: while (parent != null) {
120: top = parent;
121: parent = parent.getParent();
122: }
123:
124: printchild(top, 0);
125: JRefactory.log("JBuilderPlugin() - OK");
126: }
127:
128: public String getViewerTitle() {
129: return "JRefactory";
130: }
131:
132: /**
133: * Constructor for the JBuilderPlugin object
134: *
135: *@param project Description of Parameter
136: *@param parent Description of Parameter
137: *@param url Description of Parameter
138: *@exception DuplicateNodeException Description of Exception
139: */
140: /*
141: public JBuilderPlugin(Project project,
142: Node parent,
143: Url url)
144: throws DuplicateNodeException {
145: super(project, parent, url);
146:
147: JRefactory.log("JBuilderPlugin("+project+", "+parent+", "+url+")");
148:
149: Node top = parent;
150: while (parent != null) {
151: top = parent;
152: parent = parent.getParent();
153: }
154:
155: printchild(top, 0);
156:
157: MultipleDirClassDiagramReloader reloader = UMLNodeViewerFactory.getFactory().getReloader();
158: if (!reloader.isNecessary()) {
159: reloader.setNecessary(true);
160: reloader.reload();
161: }
162:
163: PackageNameLoader loader = new PackageNameLoader();
164: packageName = loader.load(url.getFile());
165: JRefactory.log("JBuilderPlugin() - OK");
166: }
167: */
168:
169: private void printchild(Node node, int x) {
170: //for (int i=0; i<x; i++) {
171: // System.out.print(" ");
172: //}
173: JRefactory.log("node=" + node);
174: Node[] children = node.getChildren();
175: for (int i = 0; i < children.length; i++) {
176: printchild(children[i], x + 3);
177: }
178: }
179:
180: /**
181: * Sets the Diagram attribute of the JBuilderPlugin object
182: *
183: *@param diagram The new Diagram value
184: */
185: public void setDiagram(UMLPackage diagram) {
186: packageDiagram = diagram;
187: }
188:
189: /**
190: * Setup the key maps
191: *
192: *@param prettyPrint the pretty print action
193: *@param extractMethod the extract method action
194: */
195: private static void setupKeys(Action prettyPrint,
196: Action extractMethod) {
197: ModifyKeyBinding m = new ModifyKeyBinding(prettyPrint,
198: extractMethod);
199: EditorManager.addPropertyChangeListener(m);
200: }
201:
202: /**
203: * Gets the Diagram attribute of the JBuilderPlugin object
204: *
205: *@return The Diagram value
206: */
207: public UMLPackage getDiagram() {
208: return packageDiagram;
209: }
210:
211: /**
212: * Gets the DisplayIcon attribute of the JBuilderPlugin object
213: *
214: *@return The DisplayIcon value
215: */
216: public Icon getDisplayIcon() {
217: return new UMLIcon();
218: }
219:
220: /**
221: * Gets the DisplayName attribute of the JBuilderPlugin object
222: *
223: *@return The DisplayName value
224: */
225: public String getDisplayName() {
226: if ((PrimeTime.CURRENT_MAJOR_VERSION >= 4)
227: && (PrimeTime.CURRENT_MINOR_VERSION >= 1)) {
228: return packageName + ".uml";
229: }
230: return packageName;
231: }
232:
233: /**
234: * Determines if the diagram has been modified
235: *
236: *@return true if it has
237: */
238: public boolean isModified() {
239: if (packageDiagram == null) {
240: return false;
241: }
242: return packageDiagram.isDirty();
243: }
244:
245: /**
246: * Gets the Persistant attribute of the JBuilderPlugin object
247: *
248: *@return The Persistant value
249: */
250: public boolean isPersistant() {
251: return false;
252: }
253:
254: /**
255: * Description of the Method
256: */
257: private static void cleanJBuilderSetting() {
258: File file = new File(FileSettings.getRefactorySettingsRoot(),
259: "jbuilder.settings");
260: if (file.exists()) {
261: file.delete();
262: }
263: }
264:
265: /**
266: * Initialize the open tools
267: *
268: *@param majorVersion the version number
269: *@param minorVersion the version number
270: */
271: public static void initOpenTool(byte majorVersion, byte minorVersion) {
272: JRefactory.log("initOpenTool(" + majorVersion + ", "
273: + minorVersion + ")");
274: if (majorVersion != PrimeTime.CURRENT_MAJOR_VERSION) {
275: return;
276: }
277: JRefactory.log("Version: " + majorVersion + "." + minorVersion
278: + " (Primetime: "
279: + PrimeTime.CURRENT_MAJOR_VERSION + "."
280: + PrimeTime.CURRENT_MINOR_VERSION + ")");
281:
282: java.util.Properties props = System.getProperties();
283: JAVASTYLE_DIR = new File(props.getProperty("user.home")
284: + File.separator + ".jbuilder" + File.separator
285: + "javastyle").getAbsolutePath();
286: FileSettings.setSettingsRoot(JAVASTYLE_DIR);
287:
288: // Create the property files
289: initJRefactory1();
290: cleanJBuilderSetting();
291:
292: // Register the source browser
293: JBuilderBrowser sourceBrowser = new JBuilderBrowser();
294: SourceBrowser.set(sourceBrowser);
295: CurrentSummary.register(new JBuilderCurrentSummary());
296:
297: // Initialize OpenTool here...
298: FileType.registerFileType("uml", new FileType("Class Diagram",
299: JBuilderPlugin.class, new TestObject(), new UMLIcon()));
300:
301: FileNode.registerFileNodeClass("uml", "Class Diagram",
302: JBuilderPlugin.class, new UMLIcon());
303:
304: Browser.registerNodeViewerFactory(UMLNodeViewerFactory
305: .getFactory(), true);
306: Browser.addStaticBrowserListener(new NewProjectAdapter());
307:
308: // Adds a menu item
309: ActionGroup group = new ActionGroup("JRefactory");
310: Action prettyPrintAction = new PrettyPrinterAction();
311: prettyPrintAction.putValue(UpdateAction.ACCELERATOR,
312: prettyPrintAction.getValue(GenericAction.ACCELERATOR));
313: group.add(prettyPrintAction);
314:
315: Action jrefactoryAction = new JRefactoryAction();
316: group.add(jrefactoryAction);
317:
318: ActionGroup csGroup = new ActionGroup("Coding Standards");
319: csGroup.setPopup(true);
320: csGroup.add(new CSCheckBufferAction());
321: csGroup.add(new CSCheckAllBuffersAction());
322: csGroup.add(new CSCheckDirAction());
323: csGroup.add(new CSCheckDirRecurseAction());
324: group.add(csGroup);
325:
326: ActionGroup cpdGroup = new ActionGroup("Cut&Paste detector");
327: cpdGroup.setPopup(true);
328: cpdGroup.add(new CPDCheckBufferAction());
329: cpdGroup.add(new CPDCheckAllBuffersAction());
330: cpdGroup.add(new CPDCheckDirAction());
331: cpdGroup.add(new CPDCheckDirRecurseAction());
332: group.add(cpdGroup);
333:
334: ActionGroup refactorGroup = new ActionGroup("Refactor");
335: Action extractMethodAction = new ExtractMethodAction();
336: extractMethodAction
337: .putValue(UpdateAction.ACCELERATOR, extractMethodAction
338: .getValue(GenericAction.ACCELERATOR));
339: refactorGroup.add(extractMethodAction);
340: group.add(refactorGroup);
341:
342: ActionGroup umlGroup = new ActionGroup("UML");
343: umlGroup.setPopup(true);
344: umlGroup.add(new ReloadAction());
345: umlGroup.add(new NewClassDiagramAction());
346: umlGroup.add(MenuBuilder.build());
347: umlGroup.add(new UndoAction());
348: umlGroup.add(new PrintAction());
349: umlGroup.add(new JPGFileAction());
350: umlGroup.add(umlGroup);
351: ActionGroup zoomGroup = new ActionGroup("Zoom");
352: zoomGroup.setPopup(true);
353: zoomGroup.add(new ZoomAction(0.1));
354: zoomGroup.add(new ZoomAction(0.25));
355: zoomGroup.add(new ZoomAction(0.5));
356: zoomGroup.add(new ZoomAction(1.0));
357: group.add(zoomGroup);
358: group.add(new PrettyPrinterConfigAction());
359: group.add(new AboutAction());
360: Browser.addMenuGroup(8, group);
361:
362: ProjectView
363: .registerContextActionProvider(new ProjectViewRefactorings());
364: JBuilderRefactoringFactory.register();
365:
366: setupKeys(prettyPrintAction, extractMethodAction);
367: initJRefactory2();
368: refactory.setSourceBrowser(sourceBrowser);
369: }
370:
371: public static void initJRefactory1() {
372: frame = new JFrame();
373: frame.setTitle("JRefactory");
374: refactory = new JRefactory(frame);
375: }
376:
377: public static void initJRefactory2() {
378: IDEPlugin.setPlugin(refactory);
379: frame.getContentPane().add(refactory);
380:
381: frame.addWindowListener(new ExitMenuSelection());
382: frame.pack();
383: refactory.astv.initDividers();
384: }
385:
386: public static void showJRefactory() {
387: //initJRefactory1();
388: refactory.astv.initDividers();
389: frame.show();
390: }
391:
392: /**
393: * Saves the diagram to the disk
394: *
395: *@exception IOException Description of Exception
396: *@exception InvalidUrlException Description of Exception
397: */
398: public void save() throws IOException, InvalidUrlException {
399: if (packageDiagram != null) {
400: packageDiagram.save();
401: }
402: }
403:
404: /**
405: * Description of the Method
406: *
407: *@param url Description of Parameter
408: *@exception IOException Description of Exception
409: *@exception InvalidUrlException Description of Exception
410: *@exception DuplicateNodeException Description of Exception
411: */
412: public void saveAs(Url url) throws IOException,
413: InvalidUrlException, DuplicateNodeException {
414: save();
415: }
416: }
|