Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 2889 invoked by uid 500); 9 Nov 2000 23:14:12 -0000 Delivered-To: apmail-jakarta-ant-cvs@apache.org Received: (qmail 2883 invoked by uid 1209); 9 Nov 2000 23:14:12 -0000 Date: 9 Nov 2000 23:14:12 -0000 Message-ID: <20001109231412.2882.qmail@locus.apache.org> From: metasim@locus.apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui AntTreeCellRenderer.java About.java ProjectNavigator.java ProjectProxy.java ProjectTreeModel.java PropertyEditor.java TargetSelectionModel.java metasim 00/11/09 15:14:12 Modified: src/antidote/org/apache/tools/ant/gui About.java ProjectNavigator.java ProjectProxy.java ProjectTreeModel.java PropertyEditor.java TargetSelectionModel.java Added: src/antidote/org/apache/tools/ant/gui AntTreeCellRenderer.java Log: Started work on the Ant Construction Set classes (ACS), which will map directly to DOM elements allowing easier manipulation of the XML and better editing of Ant projects. NB: The code currently requires the Sun JAXP library (which Ant needs anyway). Revision Changes Path 1.2 +13 -2 jakarta-ant/src/antidote/org/apache/tools/ant/gui/About.java Index: About.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/About.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- About.java 2000/11/03 12:04:23 1.1 +++ About.java 2000/11/09 23:14:10 1.2 @@ -64,7 +64,7 @@ /** * Dialog displaying information on the application. * - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * @author Simeon Fitch */ public class About extends JDialog { @@ -99,9 +99,17 @@ // presented nicely in box. contributors = props.getProperty("CONTRIBUTORS", "??"); + StringBuffer buf = new StringBuffer(); + StringTokenizer tok = new StringTokenizer(contributors, ","); + while(tok.hasMoreTokens()) { + String name = tok.nextToken(); + buf.append(name); + buf.append("
\n"); + } + String message = context.getResources().getMessage( getClass(), "message", - new Object[] { version, date, contributors }); + new Object[] { version, date, buf.toString() }); String title = context.getResources().getString( getClass(), "title"); @@ -117,6 +125,9 @@ JPanel p = new JPanel(); p.add(ok); getContentPane().add(BorderLayout.SOUTH, p); + + getRootPane().setDefaultButton(ok); + // Just go ahead and show it... pack(); 1.4 +2 -1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java Index: ProjectNavigator.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectNavigator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ProjectNavigator.java 2000/11/07 14:22:29 1.3 +++ ProjectNavigator.java 2000/11/09 23:14:10 1.4 @@ -61,7 +61,7 @@ /** * AntEditor for displaying the project target in a * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Simeon Fitch */ class ProjectNavigator extends AntEditor { @@ -82,6 +82,7 @@ _tree = new JTree(); _tree.setModel(null); + _tree.setCellRenderer(new AntTreeCellRenderer()); JScrollPane scroller = new JScrollPane(_tree); add(scroller); 1.4 +72 -73 jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java Index: ProjectProxy.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectProxy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ProjectProxy.java 2000/11/07 14:22:30 1.3 +++ ProjectProxy.java 2000/11/09 23:14:10 1.4 @@ -54,6 +54,7 @@ package org.apache.tools.ant.gui; import org.apache.tools.ant.*; import org.apache.tools.ant.gui.event.*; +import org.apache.tools.ant.gui.acs.*; import java.io.File; import java.io.IOException; import javax.swing.tree.TreeModel; @@ -70,7 +71,7 @@ * (or other external datamodel) occurs. This class also provides various * views into the data model, such as TreeModel, Documenet, etc. * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Simeon Fitch */ public class ProjectProxy { @@ -80,7 +81,7 @@ /** The file where the project was last saved. */ private File _file = null; /** The real Ant Project instance. */ - private Project _project = null; + private ACSProjectElement _project = null; /** The current thread executing a build. */ private Thread _buildThread = null; /** The selection model for selected targets. */ @@ -102,23 +103,9 @@ * */ private void loadProject() throws IOException { - _project = new Project(); + _project = ACSFactory.getInstance().load(_file); _selections = new TargetSelectionModel(); _selections.addTreeSelectionListener(new SelectionForwarder()); - synchronized(_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); - } } /** @@ -137,9 +124,21 @@ * */ public void build() throws BuildException { - if(_project == null) return; + Project 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); + - _buildThread = new Thread(new BuildRunner()); + _buildThread = new Thread(new BuildRunner(project)); _buildThread.start(); } @@ -180,75 +179,75 @@ * @return Document view on project. */ public Document getDocument() { - if(_project != null) { - // This is what the call should look like - //return new ProjectDocument(_project); - + // This is what the call should look like + //return new ProjectDocument(_project); + if(_file != null) { return new ProjectDocument(_file); } return null; } - /** - * Convenience method for causeing the project to fire a build event. - * Implemented because the corresponding method in the Project class - * is not publically accessible. - * - * @param event Event to fire. - */ - private void fireBuildEvent(BuildEvent event, BuildEventType type) { - synchronized(_project) { + /** Class for executing the build in a separate thread. */ + private class BuildRunner implements Runnable { + private Project _project = null; + public BuildRunner(Project project) { + _project = project; + } + + /** + * Convenience method for causeing the project to fire a build event. + * Implemented because the corresponding method in the Project class + * is not publically accessible. + * + * @param event Event to fire. + */ + private void fireBuildEvent(BuildEvent event, BuildEventType type) { Enumeration enum = _project.getBuildListeners().elements(); while(enum.hasMoreElements()) { BuildListener l = (BuildListener) enum.nextElement(); type.fireEvent(event, l); } } - } - /** Class for executing the build in a separate thread. */ - private class BuildRunner implements Runnable { public void run() { - synchronized(_project) { - // Add the build listener for - // dispatching BuildEvent objects to the - // EventBus. - BuildEventForwarder handler = - new BuildEventForwarder(_context); - _project.addBuildListener(handler); - try { - fireBuildEvent(new BuildEvent( - _project), BuildEventType.BUILD_STARTED); - - // Generate list of targets to execute. - Target[] targets = _selections.getSelectedTargets(); - Vector targetNames = new Vector(); - if(targets.length == 0) { - targetNames.add(_project.getDefaultTarget()); - } - else { - for(int i = 0; i < targets.length; i++) { - targetNames.add(targets[i].getName()); - } - } - - // Execute build on selected targets. XXX It would be - // nice if the Project API supported passing in target - // objects rather than String names. - _project.executeTargets(targetNames); - } - catch(BuildException ex) { - BuildEvent errorEvent = new BuildEvent(_project); - errorEvent.setException(ex); - errorEvent.setMessage(ex.getMessage(), Project.MSG_ERR); - fireBuildEvent(errorEvent, BuildEventType.MESSAGE_LOGGED); + // Add the build listener for + // dispatching BuildEvent objects to the + // EventBus. + BuildEventForwarder handler = + new BuildEventForwarder(_context); + _project.addBuildListener(handler); + try { + fireBuildEvent(new BuildEvent( + _project), BuildEventType.BUILD_STARTED); + + // Generate list of targets to execute. + ACSTargetElement[] targets = _selections.getSelectedTargets(); + Vector targetNames = new Vector(); + if(targets.length == 0) { + targetNames.add(_project.getDefaultTarget()); } - finally { - fireBuildEvent(new BuildEvent( - _project), BuildEventType.BUILD_FINISHED); - _project.removeBuildListener(handler); - _buildThread = null; + else { + for(int i = 0; i < targets.length; i++) { + targetNames.add(targets[i].getName()); + } } + + // Execute build on selected targets. XXX It would be + // nice if the Project API supported passing in target + // objects rather than String names. + _project.executeTargets(targetNames); + } + catch(BuildException ex) { + BuildEvent errorEvent = new BuildEvent(_project); + errorEvent.setException(ex); + errorEvent.setMessage(ex.getMessage(), Project.MSG_ERR); + fireBuildEvent(errorEvent, BuildEventType.MESSAGE_LOGGED); + } + finally { + fireBuildEvent(new BuildEvent( + _project), BuildEventType.BUILD_FINISHED); + _project.removeBuildListener(handler); + _buildThread = null; } } } 1.2 +9 -137 jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java Index: ProjectTreeModel.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/ProjectTreeModel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProjectTreeModel.java 2000/11/03 12:04:24 1.1 +++ ProjectTreeModel.java 2000/11/09 23:14:10 1.2 @@ -54,146 +54,18 @@ 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.*; +import javax.swing.tree.DefaultTreeModel; +import org.apache.tools.ant.gui.acs.ACSProjectElement; /** - * Provides a tree model view of the Project class. + * Provides a tree model view of the Project class. XXX This + * is a major hack right now that needs to be cleaned up. * - * @version $Revision: 1.1 $ - * @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); + * @version $Revision: 1.2 $ + * @author Simeon H.K. Fitch */ +public class ProjectTreeModel extends DefaultTreeModel { + public ProjectTreeModel(ACSProjectElement root) { + super(root); } - - - /** - * 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(); - } - } - - } 1.3 +16 -14 jakarta-ant/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java Index: PropertyEditor.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PropertyEditor.java 2000/11/07 14:22:32 1.2 +++ PropertyEditor.java 2000/11/09 23:14:10 1.3 @@ -52,7 +52,7 @@ * . */ package org.apache.tools.ant.gui; -import org.apache.tools.ant.Target; +import org.apache.tools.ant.gui.acs.ACSTargetElement; import org.apache.tools.ant.gui.event.*; import javax.swing.*; import java.util.*; @@ -63,7 +63,7 @@ /** * Stub for a property editor. * - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @author Simeon H.K. Fitch */ class PropertyEditor extends AntEditor { @@ -86,7 +86,9 @@ _text.setEditable(false); _text.setOpaque(false); - add(BorderLayout.CENTER, _text); + JScrollPane scroller = new JScrollPane(_text); + + add(BorderLayout.CENTER, scroller); } /** @@ -94,7 +96,7 @@ * * @param targets Targets to display info for. */ - private void displayTargetInfo(Target[] targets) { + private void displayTargetInfo(ACSTargetElement[] targets) { // The text to display. String text = null; @@ -130,16 +132,16 @@ * @param target Target to generate params for. * @return Argument list for the formatted message. */ - private Object[] getTargetParams(Target target) { + private Object[] getTargetParams(ACSTargetElement target) { List args = new LinkedList(); args.add(target.getName()); args.add(target.getDescription() == null ? "" : target.getDescription()); StringBuffer buf = new StringBuffer(); - Enumeration enum = target.getDependencies(); - while(enum.hasMoreElements()) { - buf.append(enum.nextElement()); - if(enum.hasMoreElements()) { + String[] depends = target.getDependencyNames(); + for(int i = 0; i < depends.length; i++) { + buf.append(depends[i]); + if(i < depends.length - 1) { buf.append(", "); } } @@ -155,7 +157,7 @@ * @param target Targets to generate params for. * @return Argument list for the formatted message. */ - private Object[] getTargetParams(Target[] targets) { + private Object[] getTargetParams(ACSTargetElement[] targets) { List args = new LinkedList(); StringBuffer buf = new StringBuffer(); @@ -166,9 +168,9 @@ buf.append(", "); } - Enumeration enum = targets[i].getDependencies(); - while(enum.hasMoreElements()) { - depends.add(enum.nextElement()); + String[] dependNames = targets[i].getDependencyNames(); + for(int j = 0; j < dependNames.length; j++) { + depends.add(dependNames[j]); } } @@ -209,7 +211,7 @@ */ public void eventPosted(EventObject event) { TargetSelectionEvent e = (TargetSelectionEvent) event; - Target[] targets = e.getSelectedTargets(); + ACSTargetElement[] targets = e.getSelectedTargets(); displayTargetInfo(targets); } 1.2 +5 -5 jakarta-ant/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java Index: TargetSelectionModel.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/TargetSelectionModel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TargetSelectionModel.java 2000/11/07 14:22:33 1.1 +++ TargetSelectionModel.java 2000/11/09 23:14:10 1.2 @@ -52,7 +52,7 @@ * . */ package org.apache.tools.ant.gui; -import org.apache.tools.ant.Target; +import org.apache.tools.ant.gui.acs.ACSTargetElement; import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreePath; @@ -61,7 +61,7 @@ /** * Selection model for the currently selected targets. * - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * @author Simeon Fitch */ class TargetSelectionModel extends DefaultTreeSelectionModel { @@ -79,17 +79,17 @@ * * @return the currently selected targets. */ - public Target[] getSelectedTargets() { + public ACSTargetElement[] getSelectedTargets() { TreePath[] path = getSelectionPaths(); List values = new LinkedList(); for(int i = 0; path != null && i < path.length; i++) { Object val = path[i].getLastPathComponent(); - if(val instanceof Target) { + if(val instanceof ACSTargetElement) { values.add(val); } } - Target[] retval = new Target[values.size()]; + ACSTargetElement[] retval = new ACSTargetElement[values.size()]; values.toArray(retval); return retval; } 1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java Index: AntTreeCellRenderer.java =================================================================== /* * 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.acs.ACSElement; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.JTree; import java.awt.Component; /** * Cell renderer for displaying the Ant XML file in a JTree. * * @version $Revision: 1.1 $ * @author Simeon Fitch */ public class AntTreeCellRenderer extends DefaultTreeCellRenderer { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if(value instanceof ACSElement) { setText(((ACSElement)value).getDisplayName()); } return this; } }