diff --git a/src/antidote/TODO b/src/antidote/TODO index 52165c104..aa1f40c1f 100644 --- a/src/antidote/TODO +++ b/src/antidote/TODO @@ -1,4 +1,10 @@ TODO List: + * Implement some for of refid hyperlinking functionality. + + * Provide some sort of class path debugging support. + + * Eat own dog food more. + * Dispatch tree node change events when the properties editor changes a node value. This will make sure that the node gets displayed correctly in the project navigator. diff --git a/src/antidote/build.xml b/src/antidote/build.xml index 9a24f3d3f..2104bcf08 100644 --- a/src/antidote/build.xml +++ b/src/antidote/build.xml @@ -24,6 +24,7 @@ + diff --git a/src/antidote/org/apache/tools/ant/gui/ActionManager.java b/src/antidote/org/apache/tools/ant/gui/ActionManager.java index 334957f58..ba87e1325 100644 --- a/src/antidote/org/apache/tools/ant/gui/ActionManager.java +++ b/src/antidote/org/apache/tools/ant/gui/ActionManager.java @@ -1,3 +1,50 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (C) 2000 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Ant" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation. For more information on the + * Apache Software Foundation, please see . + * + */ + /* * The Apache Software License, Version 1.1 * @@ -54,6 +101,7 @@ package org.apache.tools.ant.gui; import org.apache.tools.ant.gui.event.*; +import org.apache.tools.ant.gui.command.Command; import javax.swing.*; import java.util.*; @@ -106,9 +154,7 @@ public class ActionManager { // For each action we need to add the reverse event trigger // lookup. _mapper.addAction(action); - } - } /** @@ -212,6 +258,38 @@ public class ActionManager { return retval; } + /** + * Get the command assocaited with the Action with the given id. + * + * @param actionID Id of action to get command for. + * @return Command associated with action, or null if none available. + */ + public Command getActionCommand(String actionID, AppContext context) { + Command retval = null; + AntAction action = (AntAction) _actions.get(actionID); + if(action != null) { + Class clazz = action.getCommandClass(); + if(clazz != null) { + try { + retval = (Command) clazz.newInstance(); + retval.setContext(context); + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } + } + } + return retval; + } + + + /** + * Add tool tip, Mnemonic, etc. + * + * @param button Button to work on. + * @param action Associated action. + */ private void addNiceStuff(AbstractButton button, AntAction action) { // Set the action command so that it is consitent // no matter what language the display is in. diff --git a/src/antidote/org/apache/tools/ant/gui/AntAction.java b/src/antidote/org/apache/tools/ant/gui/AntAction.java index 034b62f65..266cf5f58 100644 --- a/src/antidote/org/apache/tools/ant/gui/AntAction.java +++ b/src/antidote/org/apache/tools/ant/gui/AntAction.java @@ -76,6 +76,7 @@ public class AntAction extends AbstractAction { public static final String ENABLE_ON = "enableOn"; public static final String DISABLE_ON = "disableOn"; public static final String TOGGLE = "toggle"; + public static final String COMMAND = "command"; /** Property resources. */ private ResourceBundle _resources = null; @@ -127,6 +128,19 @@ public class AntAction extends AbstractAction { _toggle = Boolean.valueOf(toggle).booleanValue(); } + // See if there is a command associated with the action. + String command = getString(COMMAND); + if(command != null) { + try { + Class cmd = Class.forName(command); + putValue(COMMAND, cmd); + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } + } + // Add an icon if any (which means it'll show up on the tool bar). String iconName = getString("icon"); if(iconName != null) { @@ -290,6 +304,16 @@ public class AntAction extends AbstractAction { return _toggle; } + + /** + * Get the assciated command class. + * + * @return Command class. + */ + public Class getCommandClass() { + return (Class) getValue(COMMAND); + } + /** * Pass the action on to the EventBus. * diff --git a/src/antidote/org/apache/tools/ant/gui/AppContext.java b/src/antidote/org/apache/tools/ant/gui/AppContext.java index 33f541d94..b2a47ff36 100644 --- a/src/antidote/org/apache/tools/ant/gui/AppContext.java +++ b/src/antidote/org/apache/tools/ant/gui/AppContext.java @@ -154,6 +154,16 @@ public class AppContext { _buildListeners.remove(l); } + /** + * Determine if the given BuildListener is registered. + * + * @param l Listener to test for. + * @return True if listener has been added, false if unknown. + */ + public boolean isRegisteredBuildListener(BuildListener l) { + return _buildListeners.contains(l); + } + /** * Get the set of current build listeners. * diff --git a/src/antidote/org/apache/tools/ant/gui/EventResponder.java b/src/antidote/org/apache/tools/ant/gui/EventResponder.java index b9102f61f..801924e09 100644 --- a/src/antidote/org/apache/tools/ant/gui/EventResponder.java +++ b/src/antidote/org/apache/tools/ant/gui/EventResponder.java @@ -114,44 +114,17 @@ class EventResponder { public boolean eventPosted(EventObject event) { String command = ((ActionEvent)event).getActionCommand(); - // XXX turn this switch structure into a command - // lookup using an initialized hash table. - if(command.equals(OpenCmd.ACTION_NAME)) { - new OpenCmd(_context).execute(); - } - else if(command.equals(SaveCmd.ACTION_NAME)) { - new SaveCmd(_context).execute(); - } - else if(command.equals(SaveAsCmd.ACTION_NAME)) { - new SaveAsCmd(_context).execute(); - } - else if(command.equals(BuildCmd.ACTION_NAME)) { - new BuildCmd(_context).execute(); - } - else if(command.equals(CloseCmd.ACTION_NAME)) { - new CloseCmd(_context).execute(); - } - else if(command.equals(ExitCmd.ACTION_NAME)) { - new ExitCmd(_context).execute(); - } - else if(command.equals(AboutCmd.ACTION_NAME)) { - new AboutCmd(_context).execute(); - } - else if(command.equals(ChangeLookAndFeelCmd.ACTION_NAME)) { - new ChangeLookAndFeelCmd(_context).execute(); - } - else if(command.equals(ChangeLookAndFeelCmd.ACTION_NAME)) { - new ChangeLookAndFeelCmd(_context).execute(); - } - else if(command.equals(EmacsNotifyCmd.ACTION_NAME)) { - AbstractButton source = (AbstractButton) event.getSource(); - new EmacsNotifyCmd(_context, source.isSelected()).execute(); + Command cmd = + _context.getActions().getActionCommand(command, _context); + if(cmd != null) { + cmd.run(); + return false; } else { // XXX log me. System.err.println("Unhandled action: " + command); + return true; } - return true; } } @@ -186,8 +159,8 @@ class EventResponder { public boolean eventPosted(EventObject event) { AntEvent e = (AntEvent) event; Command cmd = e.createDefaultCmd(); - cmd.execute(); - return true; + cmd.run(); + return cmd instanceof NoOpCmd; } } diff --git a/src/antidote/org/apache/tools/ant/gui/Main.java b/src/antidote/org/apache/tools/ant/gui/Main.java index adfb2cac4..fe855a091 100644 --- a/src/antidote/org/apache/tools/ant/gui/Main.java +++ b/src/antidote/org/apache/tools/ant/gui/Main.java @@ -96,11 +96,13 @@ public class Main { f.setVisible(true); - // XXX this will change once full command line argument parsing // is supported. if(args.length > 0) { - new LoadFileCmd(context, new File(args[0])).execute(); + LoadFileCmd load = new LoadFileCmd(); + load.setFile(new File(args[0])); + load.setContext(context); + load.run(); } } catch(Exception ex) { diff --git a/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java b/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java index f8b4430f3..19fa1ab22 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java @@ -64,25 +64,20 @@ import java.awt.event.WindowEvent; * @version $Revision$ * @author Simeon Fitch */ -public class AboutCmd implements Command { - /** Name of the about command. */ - public static final String ACTION_NAME = "about"; - /** Application context. */ - private AppContext _context = null; +public class AboutCmd extends AbstractCommand { + /** * Standard constructor. * - * @param window */ - public AboutCmd(AppContext context) { - _context = context; + public AboutCmd() { } /** * Show the about box. * */ - public void execute() { - new About(_context); + public void run() { + new About(getContext()); } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/AbstractCommand.java b/src/antidote/org/apache/tools/ant/gui/command/AbstractCommand.java new file mode 100644 index 000000000..34858a819 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/AbstractCommand.java @@ -0,0 +1,99 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999, 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.tools.ant.gui.command; +import org.apache.tools.ant.gui.AppContext; + + +/** + * Convenience base class for Command implementations. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public abstract class AbstractCommand implements Command { + /** Application context. */ + private AppContext _context = null; + + /** + * Default ctor. + * + */ + protected AbstractCommand() { + } + + /** + * Set the application context. + * + * @param context Application context. + */ + public void setContext(AppContext context) { + _context = context; + } + + /** + * Get the application context that was provided to setContext(); + * + * @return Application context. + */ + protected AppContext getContext() { + return _context; + } + + /** + * Run the command. From interface Runnable. + * + */ + public abstract void run(); + +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java b/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java index b8d15c90e..19350a97e 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/BuildCmd.java @@ -62,34 +62,28 @@ import org.apache.tools.ant.gui.event.ErrorEvent; * @version $Revision$ * @author Simeon Fitch */ -public class BuildCmd implements Command { - /** Name of the action the command maps to. */ - public static final String ACTION_NAME = "startBuild"; - - /** The application context */ - private AppContext _context = null; +public class BuildCmd extends AbstractCommand { /** * Standard ctor. * - * @param context Application context. */ - public BuildCmd(AppContext context) { - _context = context; + public BuildCmd() { } /** * Start the Ant build. * */ - public void execute() { - ProjectProxy project = _context.getProject(); + public void run() { + ProjectProxy project = getContext().getProject(); if(project != null) { try { project.build(); } catch(Throwable ex) { - _context.getEventBus().postEvent(new ErrorEvent(_context, ex)); + getContext().getEventBus().postEvent( + new ErrorEvent(getContext(), ex)); } } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java b/src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java index 3db684b87..83110efea 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/ChangeLookAndFeelCmd.java @@ -60,28 +60,21 @@ import org.apache.tools.ant.gui.ChangeLookAndFeel; * * @version $Revision$ * @author Erik Meade + * @author Simeon Fitch */ -public class ChangeLookAndFeelCmd implements Command { - /** Name of the action the command maps to. */ - public static final String ACTION_NAME = "changeLookAndFeel"; - - /** The application context */ - private AppContext _context = null; - +public class ChangeLookAndFeelCmd extends AbstractCommand { /** * Standard ctor. * - * @param context Application context. */ - public ChangeLookAndFeelCmd(AppContext context) { - _context = context; + public ChangeLookAndFeelCmd() { } /** * Successfully do nothing. * */ - public void execute() { - new ChangeLookAndFeel(_context); + public void run() { + new ChangeLookAndFeel(getContext()); } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java b/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java index 6f8b11840..9d9d836e9 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java @@ -62,28 +62,22 @@ import org.apache.tools.ant.gui.event.ProjectClosedEvent; * @version $Revision$ * @author Simeon Fitch */ -public class CloseCmd implements Command { - /** Name of the exit command. */ - public static final String ACTION_NAME = "close"; - - /** Application context. */ - private AppContext _context = null; +public class CloseCmd extends AbstractCommand { /** * Standard constructor. * - * @param window */ - public CloseCmd(AppContext context) { - _context = context; + public CloseCmd() { } /** * Send a close event to the parent window. * */ - public void execute() { - _context.setProject(null); - _context.getEventBus().postEvent(new ProjectClosedEvent(_context)); + public void run() { + getContext().setProject(null); + getContext().getEventBus().postEvent( + new ProjectClosedEvent(getContext())); } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/Command.java b/src/antidote/org/apache/tools/ant/gui/command/Command.java index ceb06a9bb..f04547892 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/Command.java +++ b/src/antidote/org/apache/tools/ant/gui/command/Command.java @@ -52,13 +52,28 @@ * . */ package org.apache.tools.ant.gui.command; +import org.apache.tools.ant.gui.AppContext; + + /** - * Interface for commands. Details TBD + * Interface for commands. Implementation needs to have a default ctor. + * Details TBD * * @version $Revision$ * @author Simeon Fitch */ -public interface Command { - public void execute(); +public interface Command extends Runnable { + /** + * Set the application context. + * + * @param context Application context. + */ + public void setContext(AppContext context); + + /** + * Run the command. From interface Runnable. + * + */ + public void run(); } diff --git a/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java index 079532ca8..ebea8e8a2 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java @@ -65,25 +65,28 @@ import java.awt.event.ActionEvent; * @version $Revision$ * @author Simeon H.K. Fitch */ -public class DisplayErrorCmd implements Command { - /** The application context */ - private AppContext _context = null; +public class DisplayErrorCmd extends AbstractCommand { /** Text description of error. */ private String _message = null; /** Throwable associated with the error. */ private Throwable _ex = null; + /** + * Default ctor. + * + */ + public DisplayErrorCmd() { + } + /** * Standard constuctor. * - * @param context Application context. * @param message Error message. * @param ex Throwable assocated with error. */ - public DisplayErrorCmd(AppContext context, String message, Throwable ex) { - _context = context; - _message = message; - _ex = ex; + public DisplayErrorCmd(String message, Throwable ex) { + setMessage(message); + setThrowable(_ex); } /** @@ -92,20 +95,38 @@ public class DisplayErrorCmd implements Command { * @param context Application context. * @param message Error message. */ - public DisplayErrorCmd(AppContext context, String message) { - this(context, message, null); + public DisplayErrorCmd(String message) { + this(message, null); + } + + /** + * Set the error message. + * + * @param message Error message. + */ + public void setMessage(String message) { + _message = message; + } + + /** + * Set the throwable associated with the error. + * + * @param ex Throwable associated with the error. + */ + public void setThrowable(Throwable ex) { + _ex = ex; } /** * Display the error. * */ - public void execute() { - // XXX change this so that exceptions can be optionally shown. - String title = _context.getResources().getString(getClass(), "title"); + public void run() { + String title = getContext().getResources(). + getString(getClass(), "title"); JOptionPane.showMessageDialog( - _context.getParentFrame(), new MsgPanel(), + getContext().getParentFrame(), new MsgPanel(), title, JOptionPane.ERROR_MESSAGE); } @@ -116,7 +137,7 @@ public class DisplayErrorCmd implements Command { add(new JLabel(_message)); if(_ex != null) { add(new JLabel(_ex.getMessage())); - JButton b = new JButton(_context.getResources(). + JButton b = new JButton(getContext().getResources(). getString(DisplayErrorCmd.class, "expand")); b.addActionListener(this); diff --git a/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java b/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java index 9b532581c..ce7fa624d 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java @@ -62,39 +62,28 @@ import org.apache.tools.ant.gui.ide.EmacsNotifier; * @version $Revision$ * @author Simeon Fitch */ -public class EmacsNotifyCmd implements Command { - /** Action command. */ - public static final String ACTION_NAME = "notifyEmacs"; - +public class EmacsNotifyCmd extends AbstractCommand { /** A global notifier can be used as it stores no state. */ private static EmacsNotifier _notifier = new EmacsNotifier(); - /** Application context. */ - private AppContext _context = null; - /** State notification should be in. */ - private boolean _notify = false; /** * Standard ctor. * - * @param context Application context. * @param state True if notifying on, false for notifying off. */ - public EmacsNotifyCmd(AppContext context, boolean state) { - _context = context; - _notify = state; + public EmacsNotifyCmd() { } /** * Turn on or off the notifying of emacs. * */ - public void execute() { - if(_notify) { - _context.addBuildListener(_notifier); + public void run() { + if(getContext().isRegisteredBuildListener(_notifier)) { + getContext().removeBuildListener(_notifier); } else { - _context.removeBuildListener(_notifier); + getContext().addBuildListener(_notifier); } - } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java b/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java index 94ea43d41..bc3f71cfb 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java @@ -65,28 +65,20 @@ import java.awt.event.WindowEvent; * @version $Revision$ * @author Simeon Fitch */ -public class ExitCmd implements Command { - /** Name of the exit command. */ - public static final String ACTION_NAME = "exit"; - - /** Window to send close event to. */ - private Window _window = null; - +public class ExitCmd extends AbstractCommand { /** * Standard constructor. * - * @param context Application context. */ - public ExitCmd(AppContext context) { - _window = context.getParentFrame(); + public ExitCmd() { } /** * Send a close event to the parent window. * */ - public void execute() { + public void run() { // Manually send a window close event to the window. - WindowUtils.sendCloseEvent(_window); + WindowUtils.sendCloseEvent(getContext().getParentFrame()); } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java index c69f37955..35fe4174f 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java @@ -64,20 +64,23 @@ import java.io.IOException; * @version $Revision$ * @author Simeon Fitch */ -public class LoadFileCmd implements Command { - /** The application context */ - private AppContext _context = null; +public class LoadFileCmd extends AbstractCommand { /** The file to load. */ private File _file = null; /** * Standard ctor. * - * @param context Application context. - * @param file The file to load. */ - public LoadFileCmd(AppContext context, File file) { - _context = context; + public LoadFileCmd() { + } + + /** + * Set the file to load. + * + * @param file File to load. + */ + public void setFile(File file) { _file = file; } @@ -85,26 +88,26 @@ public class LoadFileCmd implements Command { * Open the file and load it. * */ - public void execute() { + public void run() { if(!_file.exists()) { - String message = _context.getResources().getMessage( + String message = getContext().getResources().getMessage( getClass(), "noFile", new Object[] { _file.toString() }); - _context.getEventBus(). - postEvent(new ErrorEvent(_context, message)); + getContext().getEventBus(). + postEvent(new ErrorEvent(getContext(), message)); } else { try { - ProjectProxy project = new ProjectProxy(_context, _file); - _context.setProject(project); + ProjectProxy project = new ProjectProxy(getContext(), _file); + getContext().setProject(project); } catch(Exception ex) { - String message = _context.getResources().getMessage( + String message = getContext().getResources().getMessage( getClass(), "loadError", new Object[] { _file.toString() }); - _context.getEventBus(). - postEvent(new ErrorEvent(_context, message, ex)); + getContext().getEventBus(). + postEvent(new ErrorEvent(getContext(), message, ex)); } } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java b/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java index 9105c64ae..bb3ff9c36 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java @@ -59,10 +59,10 @@ package org.apache.tools.ant.gui.command; * @version $Revision$ * @author Simeon Fitch */ -public class NoOpCmd implements Command { +public class NoOpCmd extends AbstractCommand { /** * Successfully do nothing. * */ - public void execute() {} + public void run() {} } diff --git a/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java b/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java index 40a6da6b7..ccb13766c 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java @@ -67,23 +67,12 @@ import java.io.File; * @version $Revision$ * @author Simeon Fitch */ -public class OpenCmd implements Command { - /** Name of the action the command maps to. */ - public static final String ACTION_NAME = "open"; - - /** The application context */ - private AppContext _context = null; - /** Filter for showing only XML files. */ - private FileFilter _filter = null; - +public class OpenCmd extends AbstractCommand { /** * Standard ctor. * - * @param context Application context. */ - public OpenCmd(AppContext context) { - _context = context; - _filter = new XMLFileFilter(_context.getResources()); + public OpenCmd() { } /** @@ -92,14 +81,16 @@ public class OpenCmd implements Command { * operation be completed. * */ - public void execute() { + public void run() { + FileFilter filter = new XMLFileFilter(getContext().getResources()); + JFileChooser chooser = new JFileChooser(); - chooser.addChoosableFileFilter(_filter); - int val = chooser.showOpenDialog(_context.getParentFrame()); + chooser.addChoosableFileFilter(filter); + int val = chooser.showOpenDialog(getContext().getParentFrame()); if(val == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); - _context.getEventBus().postEvent( - new OpenRequestEvent(_context, selected)); + getContext().getEventBus().postEvent( + new OpenRequestEvent(getContext(), selected)); } } } diff --git a/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java b/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java index 85f95a47c..6bffa840d 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java @@ -53,6 +53,15 @@ */ package org.apache.tools.ant.gui.command; import org.apache.tools.ant.gui.AppContext; +import org.apache.tools.ant.gui.ProjectProxy; +import org.apache.tools.ant.gui.event.ErrorEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import org.apache.tools.ant.gui.XMLFileFilter; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.swing.JOptionPane; /** @@ -61,16 +70,98 @@ import org.apache.tools.ant.gui.AppContext; * @version $Revision$ * @author Simeon Fitch */ -public class SaveAsCmd extends SaveCmd { - /** Name of the action the command maps to. */ - public static final String ACTION_NAME = "saveas"; +public class SaveAsCmd extends AbstractCommand { + /** File to save to. */ + private File _file = null; /** * Standard ctor. * - * @param context Application context. */ - public SaveAsCmd(AppContext context) { - super(context, null); + public SaveAsCmd() { } + + /** + * Set the file to save to. + * + * @param file File to save to. + */ + public void setFile(File file) { + _file = file; + } + + + /** + * Save the project to the current file name. + * + */ + public void run() { + FileFilter filter = new XMLFileFilter(getContext().getResources()); + + ProjectProxy project = getContext().getProject(); + if(project != null) { + if(_file == null) { + // XXX code here to select a file to save to. + JFileChooser chooser = new JFileChooser(); + chooser.addChoosableFileFilter(filter); + int val = chooser.showSaveDialog( + getContext().getParentFrame()); + if(val == JFileChooser.APPROVE_OPTION) { + _file = chooser.getSelectedFile(); + if(_file.exists()) { + String title = getContext().getResources(). + getString(SaveCmd.class, "title"); + String message = getContext().getResources(). + getMessage(SaveCmd.class, "overwrite", + new Object[] {_file.toString()}); + val = JOptionPane.showConfirmDialog( + getContext().getParentFrame(), message, title, + JOptionPane.YES_NO_OPTION); + // If cancelled unset file. + if(val != JOptionPane.YES_OPTION) { + _file = null; + } + } + } + } + + if(_file != null) { + project.setFile(_file); + FileWriter out = null; + try { + out = new FileWriter(_file); + project.write(out); + } + catch(IOException ex) { + String message = getContext().getResources().getMessage( + SaveCmd.class, "saveError", + new Object[] { _file.toString() }); + + getContext().getEventBus(). + postEvent(new ErrorEvent(getContext(), message)); + } + finally { + if (out != null) { + try { + out.flush(); + out.close(); + } + catch(IOException ex) { + // Intentionally ignored. + } + } + } + } + } + else { + // We shouldn't ever get here. + String message = getContext().getResources().getString( + SaveCmd.class, "noProject"); + + getContext().getEventBus(). + postEvent(new ErrorEvent(getContext(), message)); + + } + } + } diff --git a/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java b/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java index bd476a498..a6459144f 100644 --- a/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java +++ b/src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java @@ -53,15 +53,6 @@ */ package org.apache.tools.ant.gui.command; import org.apache.tools.ant.gui.AppContext; -import org.apache.tools.ant.gui.ProjectProxy; -import org.apache.tools.ant.gui.event.ErrorEvent; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import org.apache.tools.ant.gui.XMLFileFilter; -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.swing.JOptionPane; /** * Command to execute the saving of the current build file. @@ -69,106 +60,18 @@ import javax.swing.JOptionPane; * @version $Revision$ * @author Simeon Fitch */ -public class SaveCmd implements Command { - /** Name of the action the command maps to. */ - public static final String ACTION_NAME = "save"; +public class SaveCmd extends SaveAsCmd { - /** The application context */ - private AppContext _context = null; - /** Filter for showing only XML files. */ - private FileFilter _filter = null; - /** File to save to. */ - private File _file = null; - - /** - * Standard ctor with file. - * - * @param context Application context. - * @param file File to save to, or null. - */ - public SaveCmd(AppContext context, File file) { - _context = context; - _filter = new XMLFileFilter(_context.getResources()); - _file = file; + public SaveCmd() { } /** - * Standard ctor. - * - * @param context Application context. - */ - public SaveCmd(AppContext context) { - this(context, context.getProject() == null ? null : - context.getProject().getFile()); - } - - /** - * Save the project to the current file name. + * Set the application context. * + * @param context Application context. */ - public void execute() { - ProjectProxy project = _context.getProject(); - if(project != null) { - if(_file == null) { - // XXX code here to select a file to save to. - JFileChooser chooser = new JFileChooser(); - chooser.addChoosableFileFilter(_filter); - int val = chooser.showSaveDialog(_context.getParentFrame()); - if(val == JFileChooser.APPROVE_OPTION) { - _file = chooser.getSelectedFile(); - if(_file.exists()) { - String title = _context.getResources().getString( - SaveCmd.class, "title"); - String message = _context.getResources().getMessage( - SaveCmd.class, "overwrite", - new Object[] {_file.toString()}); - val = JOptionPane.showConfirmDialog( - _context.getParentFrame(), message, title, - JOptionPane.YES_NO_OPTION); - // If cancelled unset file. - if(val != JOptionPane.YES_OPTION) { - _file = null; - } - } - } - } - - if(_file != null) { - project.setFile(_file); - FileWriter out = null; - try { - out = new FileWriter(_file); - project.write(out); - } - catch(IOException ex) { - String message = _context.getResources().getMessage( - SaveCmd.class, "saveError", - new Object[] { _file.toString() }); - - _context.getEventBus(). - postEvent(new ErrorEvent(_context, message)); - } - finally { - if (out != null) { - try { - out.flush(); - out.close(); - } - catch(IOException ex) { - // Intentionally ignored. - } - } - } - } - } - else { - // We shouldn't ever get here. - String message = _context.getResources().getString( - SaveCmd.class, "noProject"); - - _context.getEventBus(). - postEvent(new ErrorEvent(_context, message)); - - } + public void setContext(AppContext context) { + super.setContext(context); + setFile(context.getProject().getFile()); } } diff --git a/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java b/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java index 717567e60..a6a5cf337 100644 --- a/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java +++ b/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java @@ -81,7 +81,7 @@ public abstract class AntEvent extends EventObject { * * @return Application context. */ - protected AppContext getAppContext() { + protected AppContext getContext() { return (AppContext) getSource(); } diff --git a/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java b/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java index 54811808d..04817fefe 100644 --- a/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java +++ b/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java @@ -109,7 +109,9 @@ public class ErrorEvent extends AntEvent { * @return Command representing an appropriate response to this event. */ public Command createDefaultCmd() { - return new DisplayErrorCmd(getAppContext(), _message, _ex); + Command retval = new DisplayErrorCmd(_message, _ex); + retval.setContext(getContext()); + return retval; } /** diff --git a/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java b/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java index a9ef777e5..d1788a284 100644 --- a/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java +++ b/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java @@ -85,7 +85,10 @@ public class OpenRequestEvent extends AntEvent { * @return Load command. */ public Command createDefaultCmd() { - return new LoadFileCmd(getAppContext(), _file); + LoadFileCmd load = new LoadFileCmd(); + load.setFile(_file); + load.setContext(getContext()); + return load; } } diff --git a/src/antidote/org/apache/tools/ant/gui/resources/action.properties b/src/antidote/org/apache/tools/ant/gui/resources/action.properties index 97b85446d..ef4b5cc46 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/action.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/action.properties @@ -14,12 +14,14 @@ open.parentMenuName=File open.icon=open.gif open.accelerator=control O open.enabled=true +open.command=org.apache.tools.ant.gui.command.OpenCmd save.name=Save save.shortDescription=Save the current project save.parentMenuName=File save.icon=save.gif save.accelerator=control S +save.command=org.apache.tools.ant.gui.command.SaveCmd save.enabled=false save.disableOn= \ org.apache.tools.ant.gui.event.ProjectClosedEvent, \ @@ -31,6 +33,7 @@ save.enableOn= \ saveas.name=Save As... saveas.shortDescription=Save to a specific file saveas.parentMenuName=File +saveas.command=org.apache.tools.ant.gui.command.SaveAsCmd saveas.enabled=false saveas.disableOn= \ org.apache.tools.ant.gui.event.ProjectClosedEvent, \ @@ -42,6 +45,7 @@ saveas.enableOn= \ close.name=Close close.shortDescription=Close the current project close.parentMenuName=File +close.command=org.apache.tools.ant.gui.command.CloseCmd close.enabled=false close.disableOn= \ org.apache.tools.ant.gui.event.ProjectClosedEvent, \ @@ -54,6 +58,7 @@ exit.name=Exit exit.shortDescription=Quit the application exit.parentMenuName=File exit.separator=true +exit.command=org.apache.tools.ant.gui.command.ExitCmd exit.enabled=true about.name=About... @@ -61,6 +66,7 @@ about.shortDescription=About this application about.parentMenuName=Help about.separator=true; about.enabled=true +about.command=org.apache.tools.ant.gui.command.AboutCmd startBuild.name=Start Build startBuild.shortDescription=Start build of selected target @@ -68,6 +74,7 @@ startBuild.parentMenuName=Build startBuild.icon=start.gif startBuild.separator=true startBuild.accelerator=control B +startBuild.command=org.apache.tools.ant.gui.command.BuildCmd startBuild.enabled=false startBuild.enableOn=\ org.apache.tools.ant.gui.event.NewProjectEvent, \ @@ -90,6 +97,7 @@ stopBuild.disableOn=\ changeLookAndFeel.name=Look and Feel... changeLookAndFeel.shortDescription=Change the Look and Feel changeLookAndFeel.parentMenuName=Options +changeLookAndFeel.command=org.apache.tools.ant.gui.command.ChangeLookAndFeelCmd changeLookAndFeel.enabled=true changeLookAndFeel.separator=true @@ -98,3 +106,4 @@ notifyEmacs.shortDescription=\ Send a notification event to Emacs on build errors. notifyEmacs.parentMenuName=Options notifyEmacs.toggle=true +notifyEmacs.command=org.apache.tools.ant.gui.command.EmacsNotifyCmd