From 7f80f383cfd4df8b6d30bbf64ceac0ba03b69bfc Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Fri, 3 Nov 2000 12:04:32 +0000 Subject: [PATCH] The initial checkin of antidote - the ant GUI. This initial version is mainly to establish the source infrastructure. The code currently compiles under JDK 1.2+ and provides a basic GUI which is able to open a build.xml file. Stay tuned ... Submitted by: Simeon Fitch git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268148 13f79535-47bb-0310-9956-ffa450edef68 --- src/antidote/ChangeLog | 13 + src/antidote/build.xml | 130 ++++++++ src/antidote/docs/gui-requirements.html | 245 ++++++++++++++ src/antidote/etc/manifest | 4 + .../org/apache/tools/ant/gui/About.java | 134 ++++++++ .../apache/tools/ant/gui/ActionManager.java | 303 ++++++++++++++++++ .../org/apache/tools/ant/gui/AntEditor.java | 99 ++++++ .../org/apache/tools/ant/gui/Antidote.java | 145 +++++++++ .../org/apache/tools/ant/gui/AppContext.java | 146 +++++++++ .../org/apache/tools/ant/gui/Console.java | 84 +++++ .../apache/tools/ant/gui/EventResponder.java | 176 ++++++++++ .../org/apache/tools/ant/gui/Main.java | 95 ++++++ .../apache/tools/ant/gui/ProjectDocument.java | 94 ++++++ .../tools/ant/gui/ProjectNavigator.java | 139 ++++++++ .../apache/tools/ant/gui/ProjectProxy.java | 149 +++++++++ .../tools/ant/gui/ProjectTreeModel.java | 199 ++++++++++++ .../apache/tools/ant/gui/PropertyEditor.java | 69 ++++ .../apache/tools/ant/gui/ResourceManager.java | 146 +++++++++ .../apache/tools/ant/gui/SourceEditor.java | 127 ++++++++ .../apache/tools/ant/gui/XMLFileFilter.java | 102 ++++++ .../org/apache/tools/ant/gui/XMLHelper.java | 74 +++++ .../tools/ant/gui/command/AboutCmd.java | 88 +++++ .../tools/ant/gui/command/CloseCmd.java | 87 +++++ .../apache/tools/ant/gui/command/Command.java | 64 ++++ .../ant/gui/command/DisplayErrorCmd.java | 107 +++++++ .../apache/tools/ant/gui/command/ExitCmd.java | 92 ++++++ .../tools/ant/gui/command/LoadFileCmd.java | 111 +++++++ .../apache/tools/ant/gui/command/NoOpCmd.java | 68 ++++ .../apache/tools/ant/gui/command/OpenCmd.java | 106 ++++++ .../apache/tools/ant/gui/event/AntEvent.java | 113 +++++++ .../apache/tools/ant/gui/event/BusFilter.java | 73 +++++ .../apache/tools/ant/gui/event/BusMember.java | 80 +++++ .../tools/ant/gui/event/ErrorEvent.java | 133 ++++++++ .../apache/tools/ant/gui/event/EventBus.java | 170 ++++++++++ .../tools/ant/gui/event/NewProjectEvent.java | 84 +++++ .../tools/ant/gui/event/OpenRequestEvent.java | 92 ++++++ .../tools/ant/gui/resources/action.properties | 32 ++ .../ant/gui/resources/antidote.properties | 35 ++ .../apache/tools/ant/gui/resources/new.gif | Bin 0 -> 139 bytes .../apache/tools/ant/gui/resources/open.gif | Bin 0 -> 146 bytes .../apache/tools/ant/gui/resources/save.gif | Bin 0 -> 184 bytes .../apache/tools/ant/gui/util/StackFrame.java | 208 ++++++++++++ .../tools/ant/gui/util/WindowUtils.java | 97 ++++++ .../org/apache/tools/ant/gui/version.txt | 3 + 44 files changed, 4516 insertions(+) create mode 100644 src/antidote/ChangeLog create mode 100644 src/antidote/build.xml create mode 100644 src/antidote/docs/gui-requirements.html create mode 100644 src/antidote/etc/manifest create mode 100644 src/antidote/org/apache/tools/ant/gui/About.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ActionManager.java create mode 100644 src/antidote/org/apache/tools/ant/gui/AntEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/Antidote.java create mode 100644 src/antidote/org/apache/tools/ant/gui/AppContext.java create mode 100644 src/antidote/org/apache/tools/ant/gui/Console.java create mode 100644 src/antidote/org/apache/tools/ant/gui/EventResponder.java create mode 100644 src/antidote/org/apache/tools/ant/gui/Main.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ProjectDocument.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ProjectProxy.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java create mode 100644 src/antidote/org/apache/tools/ant/gui/PropertyEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/ResourceManager.java create mode 100644 src/antidote/org/apache/tools/ant/gui/SourceEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/XMLFileFilter.java create mode 100644 src/antidote/org/apache/tools/ant/gui/XMLHelper.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/Command.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/AntEvent.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/BusFilter.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/BusMember.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/EventBus.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/NewProjectEvent.java create mode 100644 src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java create mode 100644 src/antidote/org/apache/tools/ant/gui/resources/action.properties create mode 100644 src/antidote/org/apache/tools/ant/gui/resources/antidote.properties create mode 100644 src/antidote/org/apache/tools/ant/gui/resources/new.gif create mode 100644 src/antidote/org/apache/tools/ant/gui/resources/open.gif create mode 100644 src/antidote/org/apache/tools/ant/gui/resources/save.gif create mode 100644 src/antidote/org/apache/tools/ant/gui/util/StackFrame.java create mode 100644 src/antidote/org/apache/tools/ant/gui/util/WindowUtils.java create mode 100644 src/antidote/org/apache/tools/ant/gui/version.txt diff --git a/src/antidote/ChangeLog b/src/antidote/ChangeLog new file mode 100644 index 000000000..c491cd8cb --- /dev/null +++ b/src/antidote/ChangeLog @@ -0,0 +1,13 @@ +2000-11-02 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/event/EventBus.java: Added interrupt + level support. + + * org/apache/tools/ant/gui/About.java: Created + +2000-11-01 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/Main.java: Added XMLHelper.init() call + + * build.xml: Updated run target to include ant.jar in classpath. + diff --git a/src/antidote/build.xml b/src/antidote/build.xml new file mode 100644 index 000000000..8a37bc514 --- /dev/null +++ b/src/antidote/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/antidote/docs/gui-requirements.html b/src/antidote/docs/gui-requirements.html new file mode 100644 index 000000000..e9d9a085d --- /dev/null +++ b/src/antidote/docs/gui-requirements.html @@ -0,0 +1,245 @@ + + + + Ant GUI Feature List + + +

Ant GUI Feature List

+

Version 0.3 (2000/10/31)

+

Authors: + Simeon H.K. Fitch, + Chris Todd, + Clint Combs, + Conor MacNeill, + Matthew Kuperus Heun, + James Duncan Davidson + + +

The purpose of this document is to capture the proposed feature list for + the Ant Graphical User Interface. This is not a hard requirements + specification; you won't find the word "shall" in it (other than that one + time). :-)

+ +

In general, the purpose of the GUI is to allow the quick generation and + modification of Ant build files, helping the user define their build process + and track down build problems. For it to be successful it must make the user + more efficient and productive, insofar as their involvement in build + management and use of Ant goes. It should first address the needs of the + novice Ant user, and then add abilities for the "power" user. This does not + imply that the UI should be "dumbed down", it just means that usability + should come before slick but complicated features.

+ +

The features are in a loose order of expressed interested by + contributors.

+ + + +
    + + +
  1. Build Management

  2. +

    Once a build file is created, the user will want to start and + stop it from the UI. This will serve both as a testing facility as well as + a general compile tool. Monitoring of the build can occur through the Ant + BuildListener interface.

    +
      +
    1. Build execution.
    2. +
        +
      1. Initiate a build starting from any task.
      2. +
      3. Stop a currently active build.
      4. +
      +
    3. Build monitoring.
    4. +
        +
      1. Provide feedback on the current status of the build.
        + This is where you can have more fun with the directed graph view, + where the current build activity is highlighted on the screen, making + the whole thing behave like a dynamic state transition diagram. You + can then highlight the node where the build fails, etc.
      2. +
      3. Show log messages from the build, allowing the user to determine + the task they originated from.
      4. +
      5. Provide the ability to filter logged messages, adn to display the + messages in color codes corresponding to logging levels.
      6. +
      7. Allow the installation of custom log listeners
      8. +
      9. Record runtime statistics to determine bottleneck in the build + process
        + This may be of limited use, as calling <javac> probably takes + the most time. But maybe not.
      10. +
      +
    +
    + + +
  3. Build Wizard (auto-configure)

  4. +

    To make starting a new project with Ant as easy as possible, the a + wizard type of UI can be used where the user provides some basic + information and the application deduces what a default build.xml file for + it should look like.

    +
      +
    1. Project attributes.
    2. +
        +
      1. Provide input for the required project attributes.
        + This probably means project name and default target.
      2. +
      +
    3. Project directories.
    4. +
        +
      1. Ask for the source directory.
      2. +
      3. Ask for the destination directory.
      4. +
      5. Ask for the necessary JAR files.
      6. +
      +
    5. Project properties.
    6. +
        +
      1. Provide a default set of project properties.
        + In here would be things like classpath, build.compiler, version, + etc.
      2. +
      3. Allow the user to add to or remove from properties the default set + of properties.
      4. +
      +
    7. Task creation
    8. +
        +
      1. Provide a list of "standard" tasks to insert into the project.
        + This would be tasks like <javac> and + <javadoc>.
      2. +
      3. Generate default init, compile, javadoc, and clean targets.
      4. +
      +
    9. Creation review.
    10. +
        +
      1. Provide a review of the contents of the generated build.xml + file.
      2. +
      3. Allow the user to go back to any step in the process to change a + setting.
      4. +
      5. Prompt the user to save the build.xml file.
      6. +
      +
    +
    + + +
  5. IDE Integration

  6. +

    Components of the Ant GUI shoule support plugging into IDEs and code + editors.

    +
      +
    1. Emacs
    2. +
        +
      1. Provide support for launching builds from emacs, and notification + of errors.
      2. +
      +
    3. JEdit
    4. +
        +
      1. Provide JEdit plug-in.
      2. +
      +
    5. ProjectBuilder
    6. +
        +
      1. Provide integration with OSX ProjectBuilder.
      2. +
      +
    7. NetBeans
    8. +
        +
      1. Provide integration with the NetBeans IDE.
      2. +
      +
    +
    + + +
  7. Project Editing

  8. +

    The Ant UI will be centered around the project file. All operations of + the UI will be on a project, whether it be existing or new. How + sub-projects are handled (i.e. via the <ant> task) needs to be + determined.

    +
      +
    1. Load a project.
    2. +
        +
      1. Read the native Ant XML format as defined by the Ant users' + manual.
      2. +
      3. When possible, automatically handle changes in the Ant element + set, or at least changes to the task set, as well as the valid set of + attributes.
        + Possible approach: load "default.properties", use + introspection to discover attribute set, then reference some other + mechanism for attributes that are manifested as properties. +
      4. +
      5. Report errors in the XML source.
      6. +
      +
    3. View project contents.
    4. +
        +
      1. View the project in it's XML source format.
      2. +
      3. View the project in a non-source format.
        + This is left ambiguous to keep the implementation out of the + requirements. The different presentation formats are likely to evolve + over time. +
      4. +
      5. View the project properties.
      6. +
      7. View the project contents (tasks).
      8. +
      +
    5. Modify a project.
    6. +
        +
      1. Edit via the XML source.
      2. +
      3. Edit properties via a property sheet.
      4. +
      5. Provide facility for editing XML references used in the build + file.
      6. +
      +
    7. Save a project.
    8. +
        +
      1. Save to the native Ant XML format as defined by the Ant users' + manual.
      2. +
      3. Default save name is "build.xml".
      4. +
      5. Verify before overwriting existing file when in "Save as" + mode.
      6. +
      +
    9. Create a new project.
    10. +
        +
      1. Define a project name.
      2. +
      3. Define the default target.
      4. +
      5. Define the project base directory.
      6. +
      +
    +
    + + +
  9. Task Editing

  10. +

    Tasks define what it is that Ant is to do, and will be the object most + edited in the UI. Task is to Paragraph as + Project is to Document. +

      +
    1. View tasks.
    2. +
        +
      1. View a sorted list of tasks.
        + Provide sorting based on name, depth in dependency tree, how many + tasks depend in it...
      2. +
      3. View tasks as a directed graph.
        + Need a good graph editing library. Looked at GEF but it still needs a lot of + work, to make it easily reusable. Long term status unknown.
      4. +
      5. View tasks as a dependency tree.
      6. +
      7. View task as a properties sheet.
      8. +
      9. Provide dependency viewing, both immediate and "flattened" + views.
      10. +
      +
    3. Modify task.
    4. +
        +
      1. Allow editing of a task via a property sheet.
      2. +
      3. Allow editing of a task via XML source.
      4. +
      5. Allow the graphical editing of task dependencies
        + This is where you can go hog wild with the component wiring type of + UI.
      6. +
      7. Allow non-graphical editing of dependencies.
      8. +
      9. Provide detection of circular dependencies.
      10. +
      11. Facilitate definition of conditional tasks with evaluation + editor.
      12. +
      +
    +
    + +
  11. Build File Source Editing

  12. +

    This section listes desired features for editing the Ant build file + directly. Some components of this could be met by a generic XML editing + capability, but other parts will be Ant specific features.

    +
      +
    1. XML Editor.
    2. +
        +
      1. Provide syntax higlighting.
      2. +
      3. Provide auto-indentation.
      4. +
      5. Provide smart tag completion.
      6. +
      7. Provide visual highlighting of syntax errors.
      8. +
      9. Support auto-reparsing of contents and model update.
      10. +
      +
    + + diff --git a/src/antidote/etc/manifest b/src/antidote/etc/manifest new file mode 100644 index 000000000..c06eb52b9 --- /dev/null +++ b/src/antidote/etc/manifest @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Main-Class: org.apache.tools.ant.gui.Main + + diff --git a/src/antidote/org/apache/tools/ant/gui/About.java b/src/antidote/org/apache/tools/ant/gui/About.java new file mode 100644 index 000000000..dd4f3b4cd --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/About.java @@ -0,0 +1,134 @@ +/* + * 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; +import org.apache.tools.ant.gui.util.WindowUtils; + +import javax.swing.*; +import java.io.IOException; +import java.util.*; +import java.awt.BorderLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +/** + * Dialog displaying information on the application. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class About extends JDialog { + + /** + * Standard ctor. + * + * @param context Application context. + */ + public About(AppContext context) { + super(context.getParentFrame(), true); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + + String version = null; + String date = null; + String contributors = null; + + Properties props = new Properties(); + + try { + props.load(getClass().getResourceAsStream("version.txt")); + } + catch(IOException ex) { + // XXX log me. + ex.printStackTrace(); + return; + } + + version = props.getProperty("VERSION", "??"); + date = props.getProperty("DATE", "??"); + // XXX eventually this should be tokenized on commas and + // presented nicely in box. + contributors = props.getProperty("CONTRIBUTORS", "??"); + + String message = context.getResources().getMessage( + getClass(), "message", + new Object[] { version, date, contributors }); + + String title = context.getResources().getString( + getClass(), "title"); + setTitle(title); + + JLabel contents = new JLabel(message); + getContentPane().add(BorderLayout.CENTER, contents); + + // Add the OK button. + JButton ok = new JButton( + context.getResources().getString(getClass(), "ok")); + ok.addActionListener(new ActionHandler()); + JPanel p = new JPanel(); + p.add(ok); + getContentPane().add(BorderLayout.SOUTH, p); + + // Just go ahead and show it... + pack(); + WindowUtils.centerWindow(context.getParentFrame(), this); + setVisible(true); + } + + /** Handles press of the OK button. */ + private class ActionHandler implements ActionListener { + public void actionPerformed(ActionEvent e) { + WindowUtils.sendCloseEvent(About.this); + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/ActionManager.java b/src/antidote/org/apache/tools/ant/gui/ActionManager.java new file mode 100644 index 000000000..9274cc0a8 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ActionManager.java @@ -0,0 +1,303 @@ +/* + * 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; + +import org.apache.tools.ant.gui.event.*; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; +import java.net.URL; + +/** + * Manager of antidote actions. Receives its configuration from the action + * ResourceBundle. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ActionManager { + private ResourceBundle _resources = + ResourceBundle.getBundle( + "org.apache.tools.ant.gui.resources.action"); + + /** Array of action identifiers. */ + private String[] _actionIDs = null; + + /** Look table of all defined actions. */ + private Map _actions = new HashMap(); + + /** Event bus. */ + private EventBus _bus = null; + + /** + * Standard ctor. + * + * @param bus Event bus to post events to. + */ + public ActionManager(EventBus bus) { + _bus = bus; + + // Configure the set of actions. + String toTok = _resources.getString("actions"); + StringTokenizer tok = new StringTokenizer(toTok, ", "); + _actionIDs = new String[tok.countTokens()]; + for(int i = 0; i < _actionIDs.length; i++) { + _actionIDs[i] = tok.nextToken(); + _actions.put(_actionIDs[i], new AntAction(_actionIDs[i])); + } + } + + /** + * Create a menubar for the application based on the configuration file. + * + * @return Menubar. + */ + public JMenuBar createMenuBar() { + JMenuBar retval = new JMenuBar(); + Map menus = new HashMap(); + + String toTok = _resources.getString("menus"); + StringTokenizer tok = new StringTokenizer(toTok, ", "); + while(tok.hasMoreTokens()) { + String name = tok.nextToken(); + JMenu menu = new JMenu(name); + retval.add(menu); + menus.put(name, menu); + } + + for(int i = 0; i < _actionIDs.length; i++) { + AntAction action = (AntAction) _actions.get(_actionIDs[i]); + String parent = action.getParentMenuName(); + if(parent != null) { + JMenu menu = (JMenu) menus.get(parent); + // A well configured file shouldn't cause this, + // but be safe anyway. + if(menu == null) { + menu = new JMenu(parent); + retval.add(menu); + menus.put(parent, menu); + } + + if(action.isPreceededBySeparator()) { + menu.addSeparator(); + } + JMenuItem item = menu.add(action); + addNiceStuff(item, action); + } + } + + return retval; + } + + /** + * Create a tool bar based on the current configuration. + * + * @return Toolbar ready for action. + */ + public JToolBar createToolBar() { + JToolBar retval = new JToolBar(); + + for(int i = 0; i < _actionIDs.length; i++) { + AntAction action = (AntAction) _actions.get(_actionIDs[i]); + // If it has an icon, then we add it to the toolbar. + if(action.getIcon() != null) { + if(action.isPreceededBySeparator()) { + retval.addSeparator(); + } + + JButton button = retval.add(action); + button.setText(null); + + addNiceStuff(button, action); + } + } + + return retval; + } + + private void addNiceStuff(AbstractButton button, AntAction action) { + // Set the action command so that it is consitent + // no matter what language the display is in. + button.setActionCommand(action.getID()); + String tip = action.getShortDescription(); + if(tip != null) { + button.setToolTipText(tip); + } + } + + /** + * Convenience method for looking put a resource with the name + * "id.key". Will return null if the resource doesn't exist. + * + * @param id Action id. + * @param key Key name for the action. + * @return String resource for composite key, or null if not found. + */ + private String getString(String id, String key) { + String retval = null; + try { + retval = _resources.getString(id + "." + key); + } + catch(MissingResourceException ex) { + // Its ok to be missing a resource name... + // Too bad the API throws an exception in this case. + } + return retval; + } + + /** Class representing an action in the Antidote application. */ + private class AntAction extends AbstractAction { + /** Property name for the parent menu item. */ + public static final String PARENT_MENU_NAME = "parentMenuName"; + public static final String SEPARATOR = "separator"; + + /** Unique id. */ + private String _id = null; + + /** + * Standard ctor. + * + * @param id Unique id for the action + */ + public AntAction(String id) { + _id = id; + putValue(NAME, getString(id, "name")); + putValue(SHORT_DESCRIPTION, getString(id, "shortDescription")); + putValue(PARENT_MENU_NAME, getString(id, "parentMenuName")); + putValue(SEPARATOR, getString(id, "separator")); + + String iconName = getString(id, "icon"); + if(iconName != null) { + try { + URL imageLoc = + AntAction.class.getResource("resources/" + iconName); + if(imageLoc != null) { + putValue(SMALL_ICON, new ImageIcon(imageLoc)); + } + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } + } + + } + + /** + * Unique id for the action. + * + * @return Action id. + */ + public String getID() { + return _id; + } + + /** + * Get the name of the menu in the menu bar that this action shoul + * appear under. + * + * @return Menu to appear under, or null if not a menu action. + */ + public String getParentMenuName() { + return (String) getValue(PARENT_MENU_NAME); + } + + /** + * Get the localized name for the action. + * + * @return Name + */ + public String getName() { + return (String) getValue(NAME); + } + + /** + * Get the short description. Used in tool tips. + * + * @return Short description. + */ + public String getShortDescription() { + return (String) getValue(SHORT_DESCRIPTION); + } + + /** + * Determine if a separator should appear before the action. + * + * @return True if add separator, false otherwise. + */ + public boolean isPreceededBySeparator() { + return Boolean.valueOf( + String.valueOf(getValue(SEPARATOR))).booleanValue(); + } + + /** + * Get the icon. + * + * @return Icon for action, or null if none. + */ + public Icon getIcon() { + return (Icon) getValue(SMALL_ICON); + } + + /** + * Pass the action on to the EventBus. + * + * @param e Event to forward. + */ + public void actionPerformed(ActionEvent e) { + _bus.postEvent(e); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/AntEditor.java b/src/antidote/org/apache/tools/ant/gui/AntEditor.java new file mode 100644 index 000000000..a9ed5fe87 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/AntEditor.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; + +import javax.swing.JPanel; + +/** + * Abstract base class for an "editor", which is really anything that + * can send or receive events, or edit or view the model. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public abstract class AntEditor extends JPanel { + + /** Parameters to the Contructor. Used for loading + classes through reflection. */ + public static final Class[] CTOR_PARAMS = { AppContext.class }; + + /** The application context. */ + private AppContext _context = null; + + /** + * Standard constuctor. + * + * @param context Application context. + */ + protected AntEditor(AppContext context) { + _context = context; + } + + /** + * Get the application context. + * + * @return Application context. + */ + public AppContext getAppContext() { + return _context; + } + /** + * Get the name of the editor. + * + * @return Editor's name. + */ + public String getName() { + return _context.getResources().getString(getClass(), "name"); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/Antidote.java b/src/antidote/org/apache/tools/ant/gui/Antidote.java new file mode 100644 index 000000000..956bc0fb9 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/Antidote.java @@ -0,0 +1,145 @@ +/* + * 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; + +import javax.swing.*; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.lang.reflect.Constructor; + +/** + * The root class for the Ant GUI. Assembles all the graphical components + * based on the configuration files. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class Antidote extends JPanel { + + + /** Logging console. */ + private Console _console = null; + + /** Source of application state data. */ + private AppContext _context = null; + + /** + * Default ctor. + * + */ + public Antidote(AppContext context) { + setLayout(new BorderLayout()); + + _context = context; + + _console = new Console(_context); + + + // Add the various editors/views to the editing area. + JSplitPane splitter = new JSplitPane(); + splitter.add(JSplitPane.LEFT, populateEditors("left")); + splitter.add(JSplitPane.RIGHT, populateEditors("right")); + + add(BorderLayout.CENTER, splitter); + + add(BorderLayout.SOUTH, _console); + + setPreferredSize(new Dimension(640, 480)); + } + + + /** + * Instantiate the configured editors. + * + * @return Component containing the editor(s). + */ + private JComponent populateEditors(String prefix) { + + String[] classNames = _context.getResources(). + getStringArray(getClass(), prefix + ".editors"); + + AntEditor[] editors = new AntEditor[classNames.length]; + + for(int i = 0; i < classNames.length; i++) { + try { + Class editorType = Class.forName(classNames[i]); + + Constructor ctor = + editorType.getConstructor(AntEditor.CTOR_PARAMS); + + editors[i] = + (AntEditor) ctor.newInstance(new Object[] { _context }); + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } + } + + if(editors.length == 1) { + return editors[0]; + } + else if(editors.length > 1) { + JTabbedPane tabbed = new JTabbedPane(JTabbedPane.BOTTOM); + + for(int i = 0; i < editors.length; i++) { + tabbed.addTab(editors[i].getName(), editors[i]); + } + return tabbed; + } + else { + return new JLabel("I shouldn't be here..."); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/AppContext.java b/src/antidote/org/apache/tools/ant/gui/AppContext.java new file mode 100644 index 000000000..d74014ce1 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/AppContext.java @@ -0,0 +1,146 @@ +/* + * 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; +import org.apache.tools.ant.gui.event.*; +import java.awt.Frame; + + +/** + * A container for the state information for the application. Provides + * a centeralized place to gain access to resources and data. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class AppContext { + /** Event bus. */ + private EventBus _eventBus = new EventBus(); + /** Application resources. */ + private ResourceManager _resources = new ResourceManager(); + /** Application actions. */ + private ActionManager _actions = new ActionManager(_eventBus); + + /** Parent frame used in various operations. XXX what do we do + * in the applet context. */ + private Frame _parentFrame = null; + + /** The current data model. */ + private ProjectProxy _project = null; + + + public AppContext(Frame parent) { + _parentFrame = parent; + } + + /** + * Get the localized resources. + * + * @return Resources. + */ + public ResourceManager getResources() { + return _resources; + } + + /** + * Get the action manager. + * + * @return Action manager. + */ + public ActionManager getActions() { + return _actions; + } + + /** + * Get the event bus. + * + * @return EventBus. + */ + public EventBus getEventBus() { + return _eventBus; + } + + /** + * Get the parent frame. XXX may change... + * + * @return Parent frame. + */ + public Frame getParentFrame() { + return _parentFrame; + } + + /** + * Get the current project. + * + * @return Current project. NUll if no active project. + */ + public ProjectProxy getProject() { + return _project; + } + + /** + * Set the current project. + * + * @param project Next project to operate on. May be null for the "close" + * action. + + */ + public void setProject(ProjectProxy project) { + if(_project == null || !_project.equals(project)) { + _project = project; + getEventBus().postEvent(new NewProjectEvent(this)); + } + } +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/Console.java b/src/antidote/org/apache/tools/ant/gui/Console.java new file mode 100644 index 000000000..defa1947c --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/Console.java @@ -0,0 +1,84 @@ +/* + * 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; + +import javax.swing.*; +import java.awt.GridLayout; +import java.awt.Dimension; + +/** + * Logging console display. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class Console extends JPanel { + private AppContext _context = null; + private JTextPane _text = null; + + public Console(AppContext context) { + setLayout(new GridLayout(1,1)); + _context = context; + + _text = new JTextPane(); + _text.setEditable(false); + JScrollPane scroller = new JScrollPane(_text); + + add(scroller); + + _text.setText( + "This is the console area. \nLots of stuff to see here..."); + setPreferredSize(new Dimension(200, 40)); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/EventResponder.java b/src/antidote/org/apache/tools/ant/gui/EventResponder.java new file mode 100644 index 000000000..0b32da1b5 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/EventResponder.java @@ -0,0 +1,176 @@ +/* + * 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; + +import org.apache.tools.ant.gui.event.*; +import org.apache.tools.ant.gui.command.*; +import java.util.EventObject; +import java.awt.event.ActionEvent; +import javax.swing.JFrame; + +/** + * The purpose of this class is to watch for events that require some sort + * of action, like opening a file. + * + * @version $Revision$ + * @author Simeon Fitch + */ +class EventResponder { + + /** The application context. */ + private AppContext _context = null; + + /** + * Standard constructor. + * + * @param context Application context. + */ + public EventResponder(AppContext context) { + _context = context; + + // XXX This needs to be changed, along with the event bus, + // to allow the EventResponder to be the last listener + // to receive the event. This will allow the addition + // of event filters to yank an event out of the bus, sort of + // like an interrupt level. + _context.getEventBus().addMember( + EventBus.RESPONDING, new ActionResponder()); + _context.getEventBus().addMember( + EventBus.RESPONDING, new AntResponder()); + } + + /** Handler for bus events. */ + private class ActionResponder implements BusMember { + private final ActionFilter _filter = new ActionFilter(); + + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter() { + return _filter; + } + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void 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(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 { + // XXX log me. + System.err.println("Unhandled action: " + command); + } + } + } + + /** Filter for action events. */ + private static class ActionFilter implements BusFilter { + public boolean accept(EventObject event) { + return event instanceof ActionEvent; + } + } + + /** Handler for bus events. */ + private class AntResponder implements BusMember { + private final AntFilter _filter = new AntFilter(); + + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter() { + return _filter; + } + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void eventPosted(EventObject event) { + AntEvent e = (AntEvent) event; + Command cmd = e.createDefaultCmd(); + cmd.execute(); + } + } + + /** Filter for ant events. */ + private static class AntFilter implements BusFilter { + public boolean accept(EventObject event) { + return event instanceof AntEvent; + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/Main.java b/src/antidote/org/apache/tools/ant/gui/Main.java new file mode 100644 index 000000000..492d44a34 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/Main.java @@ -0,0 +1,95 @@ +/* + * 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; + +import javax.swing.*; +import java.awt.BorderLayout; + +/** + * Launch point for the Antidote GUI. Configurs it as an application. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class Main { + /** + * Application start. + * + * @param args TBD + */ + public static void main(String[] args) { + XMLHelper.init(); + try { + JFrame f = new JFrame("Antidote"); + AppContext context = new AppContext(f); + EventResponder resp = new EventResponder(context); + Antidote gui = new Antidote(context); + + f.setDefaultCloseOperation(3 /*JFrame.EXIT_ON_CLOSE*/); + f.setJMenuBar(context.getActions().createMenuBar()); + f.getContentPane().add(BorderLayout.CENTER, gui); + f.getContentPane().add(BorderLayout.NORTH, + context.getActions().createToolBar()); + + f.pack(); + f.setVisible(true); + // Hack around linux window placement annoyance. + f.setLocation(100, 100); + + } + catch(Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectDocument.java b/src/antidote/org/apache/tools/ant/gui/ProjectDocument.java new file mode 100644 index 000000000..b962e3d8e --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ProjectDocument.java @@ -0,0 +1,94 @@ +/* + * 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; +import org.apache.tools.ant.Project; +import javax.swing.text.DefaultStyledDocument; +import java.io.*; + +/** + * Provides a Document view on the Project XML source. + * NB: This class currently looks nothing like it should. + * Rather than just rendering a copy of the build file contents, + * this class should implement a true document model, representing + * the true XML sturcture of the build file. This is just a temporary + * implementation. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ProjectDocument extends DefaultStyledDocument { + + // This is what the real constructor needs to look like... + //public ProjectDocument(Project project) { + //} + + public ProjectDocument(File f) { + // XXX stubbed method. will go away. + try { + // XXX hack hack hack.... + Reader reader = new BufferedReader(new FileReader(f)); + char[] buf = new char[1024]; + int num = 0; + while((num = reader.read(buf)) >= 0) { + insertString(getLength(), new String(buf, 0, num), null); + } + + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java new file mode 100644 index 000000000..31ff1af89 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java @@ -0,0 +1,139 @@ +/* + * 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; +import org.apache.tools.ant.gui.event.*; +import javax.swing.*; +import java.awt.GridLayout; +import java.awt.Dimension; +import java.util.EventObject; + +/** + * AntEditor for displaying the project target in a + * + * @version $Revision$ + * @author Simeon Fitch + */ +class ProjectNavigator extends AntEditor { + + /** Navigation via a tree widget. */ + private JTree _tree = null; + + /** + * Standard ctor. + * + * @param context Application context. + */ + public ProjectNavigator(AppContext context) { + super(context); + context.getEventBus().addMember(EventBus.MONITORING, new Handler()); + + setLayout(new GridLayout(1,1)); + + _tree = new JTree(); + _tree.setModel(null); + JScrollPane scroller = new JScrollPane(_tree); + add(scroller); + + setPreferredSize(new Dimension(100, 100)); + + } + + /** Class for handling project events. */ + private class Handler implements BusMember { + private final Filter _filter = new Filter(); + + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter() { + return _filter; + } + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void eventPosted(EventObject event) { + ProjectProxy project = getAppContext().getProject(); + + if(project == null) { + // The project has been closed. + // XXX this needs to be tested against + // different version of Swing... + _tree.setModel(null); + } + else { + _tree.setModel(project.getTreeModel()); + } + } + } + + /** Class providing filtering for project events. */ + private static class Filter implements BusFilter { + /** + * Determines if the given event should be accepted. + * + * @param event Event to test. + * @return True if event should be given to BusMember, false otherwise. + */ + public boolean accept(EventObject event) { + return event instanceof NewProjectEvent; + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java b/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java new file mode 100644 index 000000000..b6979a43e --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java @@ -0,0 +1,149 @@ +/* + * 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; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; +import java.io.File; +import java.io.IOException; +import javax.swing.tree.TreeModel; +import javax.swing.text.Document; + +/** + * This class provides the gateway interface to the data model for + * the application. The translation between the Ant datamodel, + * (or other external datamodel) occurs. This class also provides various + * views into the data model, such as TreeModel, Documenet, etc. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ProjectProxy { + + /** The file where the project was last saved. */ + private File _file = null; + + /** The real Ant Project instance. */ + private Project _project = null; + + /** + * Default constructor. NB: right now it is private, but + * will be opened up once the gui supports creating new projects. + * + */ + private ProjectProxy() { + } + + /** + * File loading ctor. + * + * @param file File containing build file to load. + */ + public ProjectProxy(File file) throws IOException { + this(); + _file = file; + loadProject(); + } + + + private void loadProject() throws IOException { + _project = new Project(); + _project.init(); + + // XXX there is a bunch of stuff in the class org.apache.tools.ant.Main + // that needs to be abstracted out so that it doesn't + // have to be replicated here. + + // XXX need to provide a way to pass in externally defined properties. + // Perhaps define an external Antidote properties file. + _project.setUserProperty("ant.file" , _file.getAbsolutePath()); + ProjectHelper.configureProject(_project, _file); + } + + /** + * Get the file where the project is saved to. If the project + * is a new one that has never been saved the this will return null. + * + * @return Project file, or null if not save yet. + */ + public File getFile() { + return _file; + } + + /** + * Get the TreeModel perspective on the data. + * + * @return TreeModel view on project. + */ + public TreeModel getTreeModel() { + if(_project != null) { + return new ProjectTreeModel(_project); + } + return null; + } + + /** + * Get the Document perspective on the data. + * + * @return Document view on project. + */ + public Document getDocument() { + if(_project != null) { + // This is what the call should look like + //return new ProjectDocument(_project); + + return new ProjectDocument(_file); + } + return null; + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java b/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java new file mode 100644 index 000000000..2939251d9 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java @@ -0,0 +1,199 @@ +/* + * 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; + + +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; +import javax.swing.event.TreeModelListener; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Target; +import java.util.*; + + +/** + * Provides a tree model view of the Project class. + * + * @version $Revision$ + * @author Simeon H.K. Fitch + */ +public class ProjectTreeModel implements TreeModel { + + private Project _project = null; + private ProjectWrapper _wrapper = null; + + // XXX temp doesn't handle dynamic updates. + /** Defines an ordering for the tasks. */ + private List _targetOrdering = new ArrayList(); + + public ProjectTreeModel(Project project) { + _project = project; + _wrapper = new ProjectWrapper(); + Enumeration enum = _project.getTargets().keys(); + while(enum.hasMoreElements()) { + _targetOrdering.add(enum.nextElement()); + } + } + + /** + * Returns the root of the tree. Returns null only if the tree has + * no nodes. + * + * @return the root of the tree + */ + public Object getRoot() { + return _wrapper; + } + + + /** + * Returns the child of parent at index index in the parent's + * child array. parent must be a node previously obtained from + * this data source. This should not return null if index + * is a valid index for parent (that is index >= 0 && + * index < getChildCount(parent)). + * + * @param parent a node in the tree, obtained from this data source + * @return the child of parent at index index + */ + public Object getChild(Object parent, int index) { + if(parent != _wrapper) return null; + + Object name = _targetOrdering.get(index); + return _project.getTargets().get(name); + } + + + /** + * Returns the number of children of parent. Returns 0 if the node + * is a leaf or if it has no children. parent must be a node + * previously obtained from this data source. + * + * @param parent a node in the tree, obtained from this data source + * @return the number of children of the node parent + */ + public int getChildCount(Object parent) { + return parent == _wrapper ? _project.getTargets().size() : 0; + } + + + /** + * Returns true if node is a leaf. It is possible for this method + * to return false even if node has no children. A directory in a + * filesystem, for example, may contain no files; the node representing + * the directory is not a leaf, but it also has no children. + * + * @param node a node in the tree, obtained from this data source + * @return true if node is a leaf + */ + public boolean isLeaf(Object node) { + return node != _wrapper; + } + + /** + * Messaged when the user has altered the value for the item identified + * by path to newValue. If newValue signifies + * a truly new value the model should post a treeNodesChanged + * event. + * + * @param path path to the node that the user has altered. + * @param newValue the new value from the TreeCellEditor. + */ + public void valueForPathChanged(TreePath path, Object newValue) { + System.out.println(path); + } + + /** + * Returns the index of child in parent. + */ + public int getIndexOfChild(Object parent, Object child) { + return parent == _project ? + _targetOrdering.indexOf(((Target)child).getName()) : -1; + } + + + /** + * Adds a listener for the TreeModelEvent posted after the tree changes. + * + * @see #removeTreeModelListener + * @param l the listener to add + */ + public void addTreeModelListener(TreeModelListener l) { + + } + + /** + * Removes a listener previously added with addTreeModelListener(). + * + * @see #addTreeModelListener + * @param l the listener to remove + */ + public void removeTreeModelListener(TreeModelListener l) { + + } + + /** + * A wrapper around the Project class to provide different + * toString behavior. XXX this is temporary until a custom + * cell renderer is created. + * + */ + private class ProjectWrapper { + public String toString() { + return _project.getName(); + } + } + + +} diff --git a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java new file mode 100644 index 000000000..4b5069064 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java @@ -0,0 +1,69 @@ +/* + * 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; +import javax.swing.*; + +/** + * Stub for a property editor. + * + * @version $Revision$ + * @author Simeon H.K. Fitch + */ +class PropertyEditor extends AntEditor { + + public PropertyEditor(AppContext context) { + super(context); + add(new JLabel(getName())); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/ResourceManager.java b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java new file mode 100644 index 000000000..0ec6a5c87 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java @@ -0,0 +1,146 @@ +/* + * 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; + +import java.util.*; +import java.text.MessageFormat; + +/** + * Singleton class for accessing various resources by the application. + * Relies on the resource bundles for resource values. + * + * @version $Revision$ + * @author Simeon H.K. Fitch + */ +public class ResourceManager { + private ResourceBundle _resources = + ResourceBundle.getBundle( + "org.apache.tools.ant.gui.resources.antidote"); + + /** + * Get a string resource for the given class. + * + * @param clazz Class to get resource for. + * @param name Name of the string resource. + * @return String resource for the given class. + */ + public String getString(Class clazz, String name) { + if(clazz == null || name == null) { + return null; + } + + return _resources.getString(getKey(clazz, name)); + } + + /** + * Get an array of string resources for the given class. + * + * @param clazz Class to get resource for. + * @param name Name of the string resource. + * @return Array of string resources for the given class. + */ + public String[] getStringArray(Class clazz, String name) { + if(clazz == null || name == null) { + return null; + } + + String key = getKey(clazz, name); + + String toTok = null; + try { + toTok = _resources.getString(key); + } + catch(MissingResourceException ex) { + // Ignore as we are doing a cascading lookup. + } + + if(toTok == null) { + return _resources.getStringArray(key); + } + else { + StringTokenizer tok = new StringTokenizer(toTok, ", "); + String[] retval = new String[tok.countTokens()]; + for(int i = 0; i < retval.length; i++) { + retval[i] = tok.nextToken(); + } + return retval; + } + } + + /** + * Generate a composit key from the given class and key name. + * + * @param clazz Class to find resource for. + * @param name Name of the resource. + * @return Composite key. + */ + private String getKey(Class clazz, String name) { + return clazz.getName() + "." + name; + } + + /** + * Generate a localized message using the given set of arguments to + * format the message with. + * + * @param clazz Class to get message resource for. + * @param name + * @param arguments + * @return + */ + public String getMessage(Class clazz, String name, Object[] arguments) { + String format = getString(clazz, name); + return MessageFormat.format(format, arguments); + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/SourceEditor.java b/src/antidote/org/apache/tools/ant/gui/SourceEditor.java new file mode 100644 index 000000000..4a06cfe58 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/SourceEditor.java @@ -0,0 +1,127 @@ +/* + * 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; +import org.apache.tools.ant.gui.event.*; + +import java.util.EventObject; +import javax.swing.*; +import javax.swing.text.PlainDocument; + +import java.awt.GridLayout; +import java.awt.Font; + +/* + * AntEditor for the XML source. XXX Stubbed version. + * + * @version $Revision$ + * @author Simeon Fitch + */ +class SourceEditor extends AntEditor { + private JEditorPane _text = null; + + public SourceEditor(AppContext context) { + super(context); + context.getEventBus().addMember(EventBus.MONITORING, new Handler()); + + setLayout(new GridLayout(1,1)); + + _text = new JEditorPane(); + _text.setEditable(false); +// _text.setFont(new Font("Monospaced", 10, Font.PLAIN)); + + JScrollPane scroller = new JScrollPane(_text); + add(scroller); + } + + /** Class for handling project events. */ + private class Handler implements BusMember { + private final Filter _filter = new Filter(); + + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter() { + return _filter; + } + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void eventPosted(EventObject event) { + ProjectProxy project = getAppContext().getProject(); + + _text.setDocument(project == null ? new PlainDocument() : + project.getDocument()); + } + } + + /** Class providing filtering for project events. */ + private static class Filter implements BusFilter { + /** + * Determines if the given event should be accepted. + * + * @param event Event to test. + * @return True if event should be given to BusMember, false otherwise. + */ + public boolean accept(EventObject event) { + return event instanceof NewProjectEvent; + } + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/XMLFileFilter.java b/src/antidote/org/apache/tools/ant/gui/XMLFileFilter.java new file mode 100644 index 000000000..442063ffb --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/XMLFileFilter.java @@ -0,0 +1,102 @@ +/* + * 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; + +import javax.swing.filechooser.FileFilter; +import java.io.File; + +/** + * FileFilter for showing only XML files. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class XMLFileFilter extends FileFilter { + + /** Text description of filter. */ + private String _description = null; + + + /** + * Standard constructor. + * + * @param resources Access to text resources. + */ + public XMLFileFilter(ResourceManager resources) { + _description = resources.getString(getClass(), "description"); + } + + /** + * Accept files that end with ".xml". + * + * @param f File to test. + * @return True if accepted, false otherwise. + */ + public boolean accept(File f) { + if(f.isDirectory()) return true; + + String name = f.getName().toLowerCase(); + return name.endsWith(".xml"); + } + + /** + * Human readable description of filter. + * + * @return Description. + */ + public String getDescription() { + return _description; + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/XMLHelper.java b/src/antidote/org/apache/tools/ant/gui/XMLHelper.java new file mode 100644 index 000000000..00a03deb2 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/XMLHelper.java @@ -0,0 +1,74 @@ +/* + * 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; + +/** + * Placeholder for XML related duties. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class XMLHelper { + public static void init() { + try { + Class.forName("javax.xml.parsers.SAXParserFactory"); + } + catch(Exception ex) { + System.err.println("No JAXP compliant XML parser found. " + + "See http://java.sun.com/xml for the\n" + + "reference implementation."); + ex.printStackTrace(); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java b/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java new file mode 100644 index 000000000..f8b4430f3 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/AboutCmd.java @@ -0,0 +1,88 @@ +/* + * 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; +import org.apache.tools.ant.gui.About; +import java.awt.Window; +import java.awt.event.WindowEvent; + + +/** + * Handler for the About command. + * + * @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; + /** + * Standard constructor. + * + * @param window + */ + public AboutCmd(AppContext context) { + _context = context; + } + + /** + * Show the about box. + * + */ + public void execute() { + new About(_context); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java b/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java new file mode 100644 index 000000000..3af1acbb1 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/CloseCmd.java @@ -0,0 +1,87 @@ +/* + * 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; + + +/** + * Handler for the close command. + * + * @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; + + /** + * Standard constructor. + * + * @param window + */ + public CloseCmd(AppContext context) { + _context = context; + } + + /** + * Send a close event to the parent window. + * + */ + public void execute() { + _context.setProject(null); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/Command.java b/src/antidote/org/apache/tools/ant/gui/command/Command.java new file mode 100644 index 000000000..ceb06a9bb --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/Command.java @@ -0,0 +1,64 @@ +/* + * 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; + +/** + * Interface for commands. Details TBD + * + * @version $Revision$ + * @author Simeon Fitch + */ +public interface Command { + public void execute(); +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java new file mode 100644 index 000000000..eb247aa61 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/DisplayErrorCmd.java @@ -0,0 +1,107 @@ +/* + * 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; +import javax.swing.JOptionPane; + +/** + * Command for displaying an arbitrary error message to the user. + * + * @version $Revision$ + * @author Simeon H.K. Fitch + */ +public class DisplayErrorCmd implements Command { + /** The application context */ + private AppContext _context = null; + /** Text description of error. */ + private String _message = null; + /** Throwable associated with the error. */ + private Throwable _ex = null; + + /** + * 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; + } + + /** + * No Throwable constructor. + * + * @param context Application context. + * @param message Error message. + */ + public DisplayErrorCmd(AppContext context, String message) { + this(context, message, null); + } + + /** + * Display the error. + * + */ + public void execute() { + // XXX change this so that exceptions can be optionally shown. + String title = _context.getResources().getString(getClass(), "title"); + + JOptionPane.showMessageDialog( + _context.getParentFrame(), _message, + title, JOptionPane.ERROR_MESSAGE); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java b/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java new file mode 100644 index 000000000..94ea43d41 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/ExitCmd.java @@ -0,0 +1,92 @@ +/* + * 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; +import org.apache.tools.ant.gui.util.WindowUtils; + +import java.awt.Window; +import java.awt.event.WindowEvent; + + +/** + * Handler for an exit command . + * + * @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; + + /** + * Standard constructor. + * + * @param context Application context. + */ + public ExitCmd(AppContext context) { + _window = context.getParentFrame(); + } + + /** + * Send a close event to the parent window. + * + */ + public void execute() { + // Manually send a window close event to the window. + WindowUtils.sendCloseEvent(_window); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java new file mode 100644 index 000000000..473393c01 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/LoadFileCmd.java @@ -0,0 +1,111 @@ +/* + * 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; +import org.apache.tools.ant.gui.ProjectProxy; +import org.apache.tools.ant.gui.event.ErrorEvent; +import java.io.File; +import java.io.IOException; + +/** + * Command for reading in a build file and initializing the data model. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class LoadFileCmd implements Command { + /** The application context */ + private AppContext _context = null; + /** 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; + _file = file; + } + + /** + * Open the file and load it. + * + */ + public void execute() { + if(!_file.exists()) { + String message = _context.getResources().getMessage( + getClass(), "noFile", new Object[] { _file.toString() }); + + _context.getEventBus(). + postEvent(new ErrorEvent(_context, message)); + } + else { + try { + ProjectProxy project = new ProjectProxy(_file); + _context.setProject(project); + } + catch(IOException ex) { + String message = _context.getResources().getMessage( + getClass(), "loadError", + new Object[] { _file.toString() }); + + _context.getEventBus(). + postEvent(new ErrorEvent(_context, message)); + } + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java b/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java new file mode 100644 index 000000000..9105c64ae --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/NoOpCmd.java @@ -0,0 +1,68 @@ +/* + * 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; + +/** + * NoOp command. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class NoOpCmd implements Command { + /** + * Successfully do nothing. + * + */ + public void execute() {} +} diff --git a/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java b/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java new file mode 100644 index 000000000..a06f9f379 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java @@ -0,0 +1,106 @@ +/* + * 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; +import org.apache.tools.ant.gui.event.OpenRequestEvent; +import org.apache.tools.ant.gui.XMLFileFilter; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import java.io.File; + +/** + * Command to execute the opening of a file. A dialog is presented to the + * user for selecting a build file to open. If a file is selected then an + * OpenRequestEvent is posted. + * + * @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 file.s */ + private FileFilter _filter = null; + + /** + * Standard ctor. + * + * @param context Application context. + */ + public OpenCmd(AppContext context) { + _context = context; + _filter = new XMLFileFilter(_context.getResources()); + } + + /** + * Display a dialog asking the user to select a file to open. + * If one is selected then an event is posted requesting the open + * operation be completed. + * + */ + public void execute() { + // XXX need to set chooser text based on ResourceManager values. + JFileChooser chooser = new JFileChooser(); + chooser.addChoosableFileFilter(_filter); + int val = chooser.showOpenDialog(_context.getParentFrame()); + if(val == JFileChooser.APPROVE_OPTION) { + File selected = chooser.getSelectedFile(); + _context.getEventBus().postEvent( + new OpenRequestEvent(_context, selected)); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java b/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java new file mode 100644 index 000000000..ee815bba1 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/AntEvent.java @@ -0,0 +1,113 @@ +/* + * 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.event; +import org.apache.tools.ant.gui.command.Command; +import org.apache.tools.ant.gui.AppContext; +import java.util.EventObject; + +/** + * Base class for all Ant specific events. Details TBD. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public abstract class AntEvent extends EventObject { + + /** Flag indicating that the event has been cancelled. */ + private boolean _cancelled = false; + + /** + * Standard ctor. + * + * @param context application context. + */ + protected AntEvent(AppContext context) { + super(context); + } + + /** + * Get the application context. + * + * @return Application context. + */ + protected AppContext getAppContext() { + return (AppContext) getSource(); + } + + /** + * Determine if the event has been cancelled. + * + * @return True if cancelled, false otherwise. + */ + public boolean isCancelled() { + return _cancelled; + } + + /** + * Tag the event as being canceled. + * + */ + public void cancel() { + _cancelled = true; + } + + /** + * Create the appropriate default response command to this event. + * + * @return Command representing an appropriate response to this event. + */ + public abstract Command createDefaultCmd(); + + +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/BusFilter.java b/src/antidote/org/apache/tools/ant/gui/event/BusFilter.java new file mode 100644 index 000000000..6d0a415cd --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/BusFilter.java @@ -0,0 +1,73 @@ +/* + * 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.event; +import java.util.EventObject; + + +/** + * Interace for determining whether an event should be given to a BusMember + * instance. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public interface BusFilter { + /** + * Determines if the given event should be accepted. + * + * @param event Event to test. + * @return True if event should be given to BusMember, false otherwise. + */ + public boolean accept(EventObject event); +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/BusMember.java b/src/antidote/org/apache/tools/ant/gui/event/BusMember.java new file mode 100644 index 000000000..f8f2b6b12 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/BusMember.java @@ -0,0 +1,80 @@ +/* + * 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.event; + +import java.util.EventObject; + +/** + * Interface for classes that want to be a member of the EventBus. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public interface BusMember { + /** + * Get the filter to that is used to determine if an event should + * to to the member. + * + * @return Filter to use. + */ + public BusFilter getBusFilter(); + + /** + * Called when an event is to be posed to the member. + * + * @param event Event to post. + */ + public void eventPosted(EventObject event); + +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java b/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java new file mode 100644 index 000000000..54811808d --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/ErrorEvent.java @@ -0,0 +1,133 @@ +/* + * 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.event; +import org.apache.tools.ant.gui.AppContext; +import org.apache.tools.ant.gui.command.DisplayErrorCmd; +import org.apache.tools.ant.gui.command.Command; +import org.apache.tools.ant.gui.util.StackFrame; + + +/** + * Event fired whenever there is an error of any sort. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ErrorEvent extends AntEvent { + /** Text description of error. */ + private String _message = null; + /** Throwable associated with the error. */ + private Throwable _ex = null; + + /** + * Standard constructor. + * + * @param context Application context. + * @param message Message about the error. + * @param ex Throwable associated with the error. + */ + public ErrorEvent(AppContext context, String message, Throwable ex) { + super(context); + _message = message; + _ex = ex; + } + + /** + * Message centric constructor. + * + * @param context Application context. + * @param message Message to display. + */ + public ErrorEvent(AppContext context, String message) { + this(context, message, null); + } + + /** + * Throwable centric constructor. + * + * @param context Application context. + * @param ex Throwable behind the error. + */ + public ErrorEvent(AppContext context, Throwable ex) { + this(context, ex.getMessage(), ex); + } + + /** + * Create the appropriate response command to this event. + * + * @return Command representing an appropriate response to this event. + */ + public Command createDefaultCmd() { + return new DisplayErrorCmd(getAppContext(), _message, _ex); + } + + /** + * Create human readable version of this. + * + * @return String representation.a + */ + public String toString() { + StringBuffer buf = new StringBuffer("Error: "); + + if(_message != null) { + buf.append(_message); + buf.append('\n'); + } + if(_ex != null) { + buf.append(StackFrame.toString(_ex)); + } + return buf.toString(); + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/EventBus.java b/src/antidote/org/apache/tools/ant/gui/event/EventBus.java new file mode 100644 index 000000000..2ab048f78 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/EventBus.java @@ -0,0 +1,170 @@ +/* + * 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.event; + +import java.util.*; + +/** + * An event "bus" providing a centralized place for posting + * and recieving generic application events. To receive events a class must + * implement the "BusMember" interface. When registering as a member, an + * "interrupt level" is provided, which specifies a relative ordering level + * that the member wishes to receive events for. By convention, a member + * can be registered at the MONITORING, VETOING, or RESPONDING levels, which + * correspond to recieving events first to receiving events last. If a member + * receives an event, the event is of type AntEvent, and the member calls the + * AntEvent.cancel() method, the event is not then delivered + * to subsequent members. Members also indicate interest in an event + * by providing an instance of the BusFilter interface.
    + * + * NB: This class is overly simple right now, but will eventually + * be expanded to do better event filtering, interrupt levels, etc. + * + * @version $Revision$ + * @author Simeon Fitch +*/ +public class EventBus { + /** The default "monitoring" interrupt level, used by members who + * are only listeners/monitors of events. */ + public static final int MONITORING = 1; + /** The default "vetoing" interrupt level, used by bus members + * whose role is to veto request events or otherwise handle an + * event before it is processed by the default handler. */ + public static final int VETOING = 5; + /** The default "responding" interrupt level, for members who service + * events in a default manner. */ + public static final int RESPONDING = 10; + + /** The maximum valid interrupt value. */ + public static final int MAX_INTERRUPT = 15; + + /** Set of bus members, with a list for each interrupt level. */ + private List[] _memberSet = new List[MAX_INTERRUPT]; + + /** + * Default ctor. + * + */ + public EventBus() { + } + + /** + * Add a member to the bus. + * + * @param intLevel Interrupt level. + * @param member Member to add. + */ + public void addMember(int intLevel, BusMember member) { + if(intLevel < 1 || intLevel > MAX_INTERRUPT) { + throw new IllegalArgumentException( + "Invalid interrupt level: " + intLevel); + } + synchronized(_memberSet) { + List list = _memberSet[intLevel - 1]; + if(list == null) { + list = new LinkedList(); + _memberSet[intLevel - 1] = list; + } + list.add(member); + } + } + + + /** + * Remove a member from the bus. + * + * @param member Member to remove. + */ + public void removeMember(BusMember member) { + synchronized(_memberSet) { + // XXX lets hope we don't do too much removing. Yuck... + for(int i = 0; i < _memberSet.length; i++) { + if(_memberSet[i] == null) continue; + _memberSet[i].remove(member); + } + } + } + + /** + * Method used for sending an event to the bus. + * + * @param event Event to post. + */ + public void postEvent(EventObject event) { + synchronized(_memberSet) { + // XXX need to insert code here to test whether we are being + // executed by the AWTEventQueue, or some other thread. If + // the latter, then we need to insert our execution on the + // AWTEventQueue thread as all code executing commands assumes + // that context. + + for(int i = 0; i < _memberSet.length; i++) { + if(_memberSet[i] == null) continue; + + Iterator it = _memberSet[i].iterator(); + while(it.hasNext()) { + BusMember next = (BusMember) it.next(); + BusFilter filter = next.getBusFilter(); + if(filter == null || filter.accept(event)) { + next.eventPosted(event); + } + // Check to see if the member cancelled the event. If so + // then don't send it on to the other members. + if(event instanceof AntEvent && + ((AntEvent)event).isCancelled()) break; + } + } + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/NewProjectEvent.java b/src/antidote/org/apache/tools/ant/gui/event/NewProjectEvent.java new file mode 100644 index 000000000..fd49cb6df --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/NewProjectEvent.java @@ -0,0 +1,84 @@ +/* + * 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.event; +import org.apache.tools.ant.gui.command.Command; +import org.apache.tools.ant.gui.command.NoOpCmd; +import org.apache.tools.ant.gui.AppContext; + +/** + * Event providing notification of a change in the current project. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class NewProjectEvent extends AntEvent { + + /** + * Standard ctor. + * + * @param context application context. + */ + public NewProjectEvent(AppContext context) { + super(context); + } + + /** + * Create the appropriate default response command to this event. + * + * @return Command representing an appropriate response to this event. + */ + public Command createDefaultCmd() { + return new NoOpCmd(); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java b/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java new file mode 100644 index 000000000..a9ef777e5 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/event/OpenRequestEvent.java @@ -0,0 +1,92 @@ +/* + * 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.event; +import org.apache.tools.ant.gui.AppContext; +import org.apache.tools.ant.gui.command.Command; +import org.apache.tools.ant.gui.command.LoadFileCmd; + +import java.io.File; +/** + * Event for requesting that the given file be opened. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class OpenRequestEvent extends AntEvent { + /** The file to open. */ + private File _file = null; + + /** + * Standard ctor. + * + * @param context Application context. + * @param file File to be opened. + */ + public OpenRequestEvent(AppContext context, File file) { + super(context); + _file = file; + } + + /** + * Create the appropriate response command to this event, which is to + * load in a build file. + * + * @return Load command. + */ + public Command createDefaultCmd() { + return new LoadFileCmd(getAppContext(), _file); + } +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/resources/action.properties b/src/antidote/org/apache/tools/ant/gui/resources/action.properties new file mode 100644 index 000000000..03fddbfef --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/resources/action.properties @@ -0,0 +1,32 @@ +menus=File, Help + +actions=open, close, exit, about + +new.name=New +new.shortDescription=Create a new project +new.parentMenuName=File +new.icon=new.gif + +open.name=Open +open.shortDescription=Open an existing project +open.parentMenuName=File +open.icon=open.gif + +save.name=Save +save.shortDescription=Save the current project +save.parentMenuName=File +save.icon=save.gif + +close.name=Close +close.shortDescription=Close the current project +close.parentMenuName=File + +exit.name=Exit +exit.shortDescription=Quit the application +exit.parentMenuName=File +exit.separator=true + +about.name=About +about.shortDescription=About this application +about.parentMenuName=Help +about.separator=true; diff --git a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties new file mode 100644 index 000000000..12b8249fb --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -0,0 +1,35 @@ +# This is the general properties file for the Antidote application. + +# Configure the editors that appear on the right of the UI. +org.apache.tools.ant.gui.Antidote.right.editors=\ + org.apache.tools.ant.gui.PropertyEditor, \ + org.apache.tools.ant.gui.SourceEditor + +# Configure the editors that appear on the left of the UI. +org.apache.tools.ant.gui.Antidote.left.editors=\ + org.apache.tools.ant.gui.ProjectNavigator + +# Set specific class properties. +org.apache.tools.ant.gui.SourceEditor.name=Source +org.apache.tools.ant.gui.PropertyEditor.name=Properties +org.apache.tools.ant.gui.ProjectNavigator.name=Task Navigator + +org.apache.tools.ant.gui.XMLFileFilter.description=XML Files + +org.apache.tools.ant.gui.command.LoadFileCmd.noFile=The file "{0}" was not found. +org.apache.tools.ant.gui.command.LoadFileCmd.loadError=The file "{0}" could not be loaded. +org.apache.tools.ant.gui.command.DisplayErrorCmd.title=Error... + +org.apache.tools.ant.gui.About.title=About +org.apache.tools.ant.gui.About.ok=OK +org.apache.tools.ant.gui.About.message=\ +

    Antidote

    \ +

    Version: {0}

    \ +

    Date: {1}

    \ +

    Contributors: {2}

    \ +
    \ +

    Copyright © 2000 The Apache Software Foundation.

    +

    All rights reserved.

    \ +
    \ + + diff --git a/src/antidote/org/apache/tools/ant/gui/resources/new.gif b/src/antidote/org/apache/tools/ant/gui/resources/new.gif new file mode 100644 index 0000000000000000000000000000000000000000..0812c5771411998071912de1ab2d7bc0b5039e8e GIT binary patch literal 139 zcmV;60CfLHNk%w1VHf}y0FnOy|NsBY%>MuY0KmY&A^8LW00093EC2ui02lxm00079 zoR6u?y#k|zzzqSi*3{wvh5-g(&L@IGP*x3^j;zVR@k&2HEaI+W<8^erR4x$|{*b$3 t=!i((meHnjL_J82S;My1y;z-4?YLO>o|UzUI}#pj=5&kwjyDtl06XuCJ6Zq$ literal 0 HcmV?d00001 diff --git a/src/antidote/org/apache/tools/ant/gui/resources/open.gif b/src/antidote/org/apache/tools/ant/gui/resources/open.gif new file mode 100644 index 0000000000000000000000000000000000000000..fe0914f2832310a80a05be1741cbe2401a76e0bd GIT binary patch literal 146 zcmZ?wbhEHblwgoxSoELaKMRVR1Yj3X$YIESrXPhmW-gM=x`|X#L r*2pP7U!ywx%qr7gSy{nMIp4U&`cFQ4nR(VvxbMTvG{5sI3=Gx)p1?TS literal 0 HcmV?d00001 diff --git a/src/antidote/org/apache/tools/ant/gui/resources/save.gif b/src/antidote/org/apache/tools/ant/gui/resources/save.gif new file mode 100644 index 0000000000000000000000000000000000000000..6acb73056060276829ad560ce1cf7ec3d7ee444a GIT binary patch literal 184 zcmZ?wbhEHblwgoxSoELa|NsAI&YYP!b7opv8Uq8vfddDCBoHY6WMO1rU}ew&aX@Mr zm}?_;-T7x=<+OTl36p}EL;^>Zi!(!`z?w%=JQ)Q>>94ls*ywLP)n+c+(DrF>!_KRI z7k4YhJ1u&vE~VMNXGZ$&QeAG-=@oB|8g(~qshYdb%lgg^Yirfri%Kf?Xd5?omnBuC iYgWe;x41Pn*SEIGb@)h37Oms%uNIm$dk!BbgEatAE=J1$ literal 0 HcmV?d00001 diff --git a/src/antidote/org/apache/tools/ant/gui/util/StackFrame.java b/src/antidote/org/apache/tools/ant/gui/util/StackFrame.java new file mode 100644 index 000000000..ef369ab7a --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/util/StackFrame.java @@ -0,0 +1,208 @@ +/* + * 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.util; + +import java.io.StringWriter; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +/* + * Class for parsing the stack frame information from a Throwable's stack frame + * dump. Probably only suitable for debugging, as it depends on the specific + * output format of the stack dump, which could change with JVM releases. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class StackFrame { + private String _method = null; + private int _line = -1; + private String _clazz = null; + + /** + * Default ctor. Gets the stack frame info for the calling method. + * + */ + public StackFrame() { + this(1); + } + + public StackFrame(int frame) { + if(frame < 0) { + throw new IllegalArgumentException("Frame number must be <= 0"); + } + // Add a stack frame for this method and for + // the fillInStackTrace method. + frame += 2; + + Throwable t = new Throwable(); + t.fillInStackTrace(); + String text = toString(t); + + // Extract the line that has the stack frame info we want on it. + StringTokenizer tok = new StringTokenizer(text, "\n"); + // Ignore the first line as it just has the exception type on it. + tok.nextToken(); + String hit = null; + while(tok.hasMoreTokens() && frame-- >= 0) { + hit = tok.nextToken(); + } + + // This should always pass. '4' is the number of characters to get + // to the start of the class name ("\tat "). + if(hit != null && hit.length() > 4) { + int idx = hit.indexOf('('); + if(idx > 4) { + String before = hit.substring(4, idx); + String after = hit.substring(idx + 1, hit.length() - 1); + + // Extract the method name and class name. + idx = before.lastIndexOf('.'); + if(idx >= 0) { + _clazz = before.substring(0, idx); + _method = before.substring( + idx + 1, before.length()); + } + idx = after.lastIndexOf(':'); + // Extract the line number. If it fails in any way + // then just leave the value at -1 which is a valid value. + try { + _line = Integer.parseInt( + after.substring(idx + 1, after.length())); + } + catch(Exception ex) { + // Ignore. + } + } + } + } + + /** + * Utility method for converting a throwable object to a string. + * + * @param t Throwable to convert. + * @return String representation. + */ + public static String toString(Throwable t) { + StringWriter writer = new StringWriter(); + t.printStackTrace(new PrintWriter(writer)); + return writer.toString(); + } + + /** + * Get the stack frame class. + * + * @return + */ + public String getClassName() { + return _clazz; + } + + /** + * Get the name of the stack frame method + * + * @return + */ + public String getMethodName() { + return _method; + } + + /** + * Get the line number for the frame call. + * + * @return Line number, or -1 if unknown. + */ + public int getLineNumber() { + return _line; + } + + public String toString() { + return getClassName() + "." + getMethodName() + "(line " + + (getLineNumber() >= 0 ? + String.valueOf(getLineNumber()) : "unknown") + ")"; + } + + /** + * Test code. + * + * @param args Ignored. + */ +/* + public static void main(String[] args) { + //Test class for generating a bunch of stack frames. + class Test { + public Test() { + System.out.println("Main method: " + new StackFrame(2)); + recurse(20); + } + + private void recurse(int val) { + if(val == 0) { + System.out.println("Recurse method: " + new StackFrame()); + } + else if(val % 2 == 0) { + recurse(val - 1); + } + else { + recurse(val - 1); + } + } + } + + new Test(); + } +*/ +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/util/WindowUtils.java b/src/antidote/org/apache/tools/ant/gui/util/WindowUtils.java new file mode 100644 index 000000000..03bc38cb1 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/util/WindowUtils.java @@ -0,0 +1,97 @@ +/* + * 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.util; + +import java.awt.Window; +import java.awt.Rectangle; +import java.awt.Dimension; +import java.awt.event.WindowEvent; + +/** + * Function container for various window operations. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class WindowUtils { + /** + * Default ctor. + * + */ + private WindowUtils() {} + + /** + * Send a close event to the given window. + * + * @param window Window to send close event to. + */ + public static void sendCloseEvent(Window window) { + window.dispatchEvent( + new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); + } + + /** + * Center the given child window with repsect to the child window. + * + * @param parent Window to base centering on. + * @param child Window to center. + */ + public static void centerWindow(Window parent, Window child) { + Rectangle bounds = parent.getBounds(); + Dimension size = child.getSize(); + child.setLocation(bounds.x + (bounds.width - size.width)/2, + bounds.y + (bounds.height - size.height)/2); + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/version.txt b/src/antidote/org/apache/tools/ant/gui/version.txt new file mode 100644 index 000000000..603801ec1 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/version.txt @@ -0,0 +1,3 @@ +VERSION=@VERSION@ +DATE=@DATE@ +CONTRIBUTORS=Simeon H.K. Fitch, Ant Development Team