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.Browser;
059: import com.borland.primetime.ide.ProjectView;
060: import com.borland.primetime.node.DuplicateNodeException;
061: import com.borland.primetime.node.FileNode;
062: import com.borland.primetime.node.FileType;
063: import com.borland.primetime.node.Node;
064: import com.borland.primetime.node.Project;
065: import com.borland.primetime.vfs.InvalidUrlException;
066: import com.borland.primetime.vfs.Url;
067: import java.io.File;
068: import java.io.IOException;
069: import javax.swing.Action;
070: import javax.swing.Icon;
071: import org.acm.seguin.ide.common.action.GenericAction;
072: import org.acm.seguin.ide.common.MultipleDirClassDiagramReloader;
073: import org.acm.seguin.ide.common.PackageNameLoader;
074: import org.acm.seguin.ide.common.SourceBrowser;
075: import org.acm.seguin.ide.common.UMLIcon;
076: import org.acm.seguin.ide.common.action.CurrentSummary;
077: import org.acm.seguin.ide.common.action.ExtractMethodAction;
078: import net.sourceforge.jrefactory.action.PrettyPrinterAction;
079: import org.acm.seguin.ide.jbuilder.refactor.JBuilderCurrentSummary;
080: import org.acm.seguin.ide.jbuilder.refactor.JBuilderRefactoringFactory;
081: import org.acm.seguin.ide.jbuilder.refactor.MenuBuilder;
082: import org.acm.seguin.tools.RefactoryInstaller;
083: import net.sourceforge.jrefactory.uml.UMLPackage;
084: import org.acm.seguin.util.FileSettings;
085:
086: /**
087: * File node representing a UML class diagram
088: *
089: *@author Chris Seguin
090: *@created October 18, 2001
091: */
092: public class UMLNode extends FileNode {
093: public static String JAVASTYLE_DIR = "";
094: private UMLPackage packageDiagram;
095: private String packageName;
096:
097: /**
098: * Constructor for the UMLNode object
099: *
100: *@param project Description of Parameter
101: *@param parent Description of Parameter
102: *@param url Description of Parameter
103: *@exception DuplicateNodeException Description of Exception
104: */
105: public UMLNode(Project project, Node parent, Url url)
106: throws DuplicateNodeException {
107: super (project, parent, url);
108:
109: initLog();
110: log("UMLNode(" + project + ", " + parent + ", " + url + ")");
111: MultipleDirClassDiagramReloader reloader = UMLNodeViewerFactory
112: .getFactory().getReloader();
113: if (!reloader.isNecessary()) {
114: reloader.setNecessary(true);
115: reloader.reload();
116: }
117:
118: PackageNameLoader loader = new PackageNameLoader();
119: packageName = loader.load(url.getFile());
120: log("UMLNode() - OK");
121: }
122:
123: /**
124: * Sets the Diagram attribute of the UMLNode object
125: *
126: *@param diagram The new Diagram value
127: */
128: public void setDiagram(UMLPackage diagram) {
129: packageDiagram = diagram;
130: }
131:
132: /**
133: * Setup the key maps
134: *
135: *@param prettyPrint the pretty print action
136: *@param extractMethod the extract method action
137: */
138: private static void setupKeys(Action prettyPrint,
139: Action extractMethod) {
140: ModifyKeyBinding m = new ModifyKeyBinding(prettyPrint,
141: extractMethod);
142: EditorManager.addPropertyChangeListener(m);
143: }
144:
145: /**
146: * Gets the Diagram attribute of the UMLNode object
147: *
148: *@return The Diagram value
149: */
150: public UMLPackage getDiagram() {
151: return packageDiagram;
152: }
153:
154: /**
155: * Gets the DisplayIcon attribute of the UMLNode object
156: *
157: *@return The DisplayIcon value
158: */
159: public Icon getDisplayIcon() {
160: return new UMLIcon();
161: }
162:
163: /**
164: * Gets the DisplayName attribute of the UMLNode object
165: *
166: *@return The DisplayName value
167: */
168: public String getDisplayName() {
169: if ((PrimeTime.CURRENT_MAJOR_VERSION >= 4)
170: && (PrimeTime.CURRENT_MINOR_VERSION >= 1)) {
171: return packageName + ".uml";
172: }
173: return packageName;
174: }
175:
176: /**
177: * Determines if the diagram has been modified
178: *
179: *@return true if it has
180: */
181: public boolean isModified() {
182: if (packageDiagram == null) {
183: return false;
184: }
185: return packageDiagram.isDirty();
186: }
187:
188: /**
189: * Gets the Persistant attribute of the UMLNode object
190: *
191: *@return The Persistant value
192: */
193: public boolean isPersistant() {
194: return false;
195: }
196:
197: /**
198: * Description of the Method
199: */
200: private static void cleanJBuilderSetting() {
201: File file = new File(FileSettings.getRefactorySettingsRoot(),
202: "jbuilder.settings");
203: if (file.exists()) {
204: file.delete();
205: }
206: }
207:
208: /**
209: * Initialize the open tools
210: *
211: *@param majorVersion the version number
212: *@param minorVersion the version number
213: */
214: public static void initOpenTool(byte majorVersion, byte minorVersion) {
215: initLog();
216: log("initOpenTool(" + majorVersion + ", " + minorVersion + ")");
217: if (majorVersion != PrimeTime.CURRENT_MAJOR_VERSION) {
218: return;
219: }
220: log("Version: " + majorVersion + "." + minorVersion
221: + " (Primetime: "
222: + PrimeTime.CURRENT_MAJOR_VERSION + "."
223: + PrimeTime.CURRENT_MINOR_VERSION + ")");
224:
225: java.util.Properties props = System.getProperties();
226: JAVASTYLE_DIR = new File(props.getProperty("user.home")
227: + File.separator + ".jbuilder" + File.separator
228: + "javastyle").getAbsolutePath();
229: FileSettings.setSettingsRoot(JAVASTYLE_DIR);
230: // Create the property files
231: (new RefactoryInstaller(true)).run();
232: cleanJBuilderSetting();
233:
234: // Register the source browser
235: SourceBrowser.set(new JBuilderBrowser());
236: CurrentSummary.register(new JBuilderCurrentSummary());
237:
238: // Initialize OpenTool here...
239: FileType.registerFileType("uml", new FileType("Class Diagram",
240: UMLNode.class, new TestObject(), new UMLIcon()));
241:
242: FileNode.registerFileNodeClass("uml", "Class Diagram",
243: UMLNode.class, new UMLIcon());
244:
245: Browser.registerNodeViewerFactory(UMLNodeViewerFactory
246: .getFactory(), true);
247: Browser.addStaticBrowserListener(new NewProjectAdapter());
248: //Browser.addStaticBrowserListener(new RefactoringAdapter());
249:
250: // Adds a menu item
251: ActionGroup group = new ActionGroup("JRefactory");
252: Action prettyPrintAction = new PrettyPrinterAction();
253: prettyPrintAction.putValue(UpdateAction.ACCELERATOR,
254: prettyPrintAction.getValue(GenericAction.ACCELERATOR));
255: group.add(prettyPrintAction);
256: ActionGroup refactorGroup = new ActionGroup("Refactor");
257: Action extractMethodAction = new ExtractMethodAction();
258: extractMethodAction
259: .putValue(UpdateAction.ACCELERATOR, extractMethodAction
260: .getValue(GenericAction.ACCELERATOR));
261: refactorGroup.add(extractMethodAction);
262: group.add(refactorGroup);
263:
264: ActionGroup umlGroup = new ActionGroup("UML");
265: umlGroup.add(new ReloadAction());
266: umlGroup.add(new NewClassDiagramAction());
267: umlGroup.add(MenuBuilder.build());
268: umlGroup.add(new UndoAction());
269: umlGroup.add(new PrintAction());
270: umlGroup.add(new JPGFileAction());
271: umlGroup.add(umlGroup);
272: ActionGroup zoomGroup = new ActionGroup("Zoom");
273: zoomGroup.setPopup(true);
274: zoomGroup.add(new ZoomAction(0.1));
275: zoomGroup.add(new ZoomAction(0.25));
276: zoomGroup.add(new ZoomAction(0.5));
277: zoomGroup.add(new ZoomAction(1.0));
278: group.add(zoomGroup);
279: group.add(new PrettyPrinterConfigAction());
280: group.add(new AboutAction());
281: Browser.addMenuGroup(8, group);
282:
283: ProjectView
284: .registerContextActionProvider(new ProjectViewRefactorings());
285: JBuilderRefactoringFactory.register();
286:
287: setupKeys(prettyPrintAction, extractMethodAction);
288: }
289:
290: private static java.io.PrintStream logger = null;
291:
292: public static void initLog() {
293: if (logger == null) {
294: try {
295: logger = new java.io.PrintStream(
296: new java.io.FileOutputStream(
297: "C:\\temp\\JBuilder.log.txt"));
298: System.setOut(logger);
299: } catch (java.io.FileNotFoundException e) {
300: e.printStackTrace(System.err);
301: logger = System.err;
302: }
303: }
304: }
305:
306: public static void log(String message) {
307: logger.println(message);
308: }
309:
310: /**
311: * Saves the diagram to the disk
312: *
313: *@exception IOException Description of Exception
314: *@exception InvalidUrlException Description of Exception
315: */
316: public void save() throws IOException, InvalidUrlException {
317: if (packageDiagram != null) {
318: packageDiagram.save();
319: }
320: }
321:
322: /**
323: * Description of the Method
324: *
325: *@param url Description of Parameter
326: *@exception IOException Description of Exception
327: *@exception InvalidUrlException Description of Exception
328: *@exception DuplicateNodeException Description of Exception
329: */
330: public void saveAs(Url url) throws IOException,
331: InvalidUrlException, DuplicateNodeException {
332: save();
333: }
334: }
|