From d830141f773d284b894679215e4d17a379422033 Mon Sep 17 00:00:00 2001 From: metasim Date: Fri, 10 Nov 2000 20:41:21 +0000 Subject: [PATCH] Started addition of a generic Bean editor/property sheet and supporting infrastructure for Ant Elements. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268168 13f79535-47bb-0310-9956-ffa450edef68 --- src/antidote/ChangeLog | 5 + .../org/apache/tools/ant/gui/Console.java | 1 + .../apache/tools/ant/gui/LabelFieldGBC.java | 144 +++++++++ .../apache/tools/ant/gui/PropertyEditor.java | 120 ++------ .../apache/tools/ant/gui/ResourceManager.java | 22 +- .../tools/ant/gui/acs/ACSBeanDescriptor.java | 74 +++++ .../apache/tools/ant/gui/acs/ACSElement.java | 133 +++----- .../tools/ant/gui/acs/ACSNamedElement.java | 129 ++++++++ .../tools/ant/gui/acs/ACSProjectElement.java | 10 +- .../gui/acs/ACSProjectElementBeanInfo.java | 106 +++++++ .../tools/ant/gui/acs/ACSTargetElement.java | 21 +- .../ant/gui/acs/ACSTargetElementBeanInfo.java | 108 +++++++ .../tools/ant/gui/acs/ACSTreeNodeElement.java | 175 +++++++++++ .../tools/ant/gui/acs/BaseBeanInfo.java | 118 ++++++++ .../tools/ant/gui/acs/beaninfo.properties | 14 + .../customizer/AbstractPropertyEditor.java | 244 +++++++++++++++ .../gui/customizer/DoublePropertyEditor.java | 173 +++++++++++ .../ant/gui/customizer/DynamicCustomizer.java | 286 ++++++++++++++++++ .../gui/customizer/IntegerPropertyEditor.java | 175 +++++++++++ .../gui/customizer/StringPropertyEditor.java | 153 ++++++++++ .../ant/gui/resources/antidote.properties | 12 - .../tools/ant/gui/resources/default.gif | Bin 1212 -> 987 bytes .../apache/tools/ant/gui/resources/new.gif | Bin 139 -> 997 bytes .../apache/tools/ant/gui/resources/open.gif | Bin 146 -> 1001 bytes .../apache/tools/ant/gui/resources/save.gif | Bin 184 -> 981 bytes .../apache/tools/ant/gui/resources/start.gif | Bin 888 -> 988 bytes .../apache/tools/ant/gui/resources/stop.gif | Bin 888 -> 989 bytes .../org/apache/tools/ant/gui/version.txt | 5 +- 28 files changed, 1987 insertions(+), 241 deletions(-) create mode 100644 src/antidote/org/apache/tools/ant/gui/LabelFieldGBC.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/ACSNamedElement.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java create mode 100644 src/antidote/org/apache/tools/ant/gui/acs/beaninfo.properties create mode 100644 src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java create mode 100644 src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java create mode 100644 src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java diff --git a/src/antidote/ChangeLog b/src/antidote/ChangeLog index 251ea73b5..60eae2817 100644 --- a/src/antidote/ChangeLog +++ b/src/antidote/ChangeLog @@ -1,3 +1,8 @@ +2000-11-10 Simeon H.K. Fitch + + * org/apache/tools/ant/gui/PropertyEditor.java: Added new + DynamicCustomizer class instead of HTML based info. + 2000-11-09 Simeon H.K. Fitch * org/apache/tools/ant/gui/ProjectProxy.java: Started rework of diff --git a/src/antidote/org/apache/tools/ant/gui/Console.java b/src/antidote/org/apache/tools/ant/gui/Console.java index 87bc8da98..2e5413fd3 100644 --- a/src/antidote/org/apache/tools/ant/gui/Console.java +++ b/src/antidote/org/apache/tools/ant/gui/Console.java @@ -95,6 +95,7 @@ public class Console extends AntEditor { context.getResources().getString(getClass(), "logLevel")); controls.add(label); _logLevel = new JComboBox(LogLevelEnum.getValues()); + _logLevel.setSelectedItem(LogLevelEnum.INFO); controls.add(_logLevel); add(BorderLayout.NORTH, controls); diff --git a/src/antidote/org/apache/tools/ant/gui/LabelFieldGBC.java b/src/antidote/org/apache/tools/ant/gui/LabelFieldGBC.java new file mode 100644 index 000000000..c3cbca812 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/LabelFieldGBC.java @@ -0,0 +1,144 @@ +/* + * 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.awt.GridBagConstraints; +import java.awt.Insets; +import java.awt.Container; +import javax.swing.JLabel; + +/** + * Convenience specialization of the GridBagConstraints for laying + * out label:field pairs. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class LabelFieldGBC extends GridBagConstraints { + + /** + * Default ctor. Sets up the default settings. + * + */ + public LabelFieldGBC() { + // Add small abount of padding. + insets = new Insets(1,3,1,3); + // All vertical layout is relative + gridy = RELATIVE; + // Grid dimensions are equal (one label field pair per row). + gridheight = 1; + gridwidth = 1; + } + + /** + * Set up constraint values for placing a label before a field. + * + * @return Constraints for a label. + */ + public LabelFieldGBC forLabel() { + // Labels should only take up as much room as needed. + fill = NONE; + // Set location to left side. + gridx = 0; + // Move it over to be as close to field as possible. + anchor = EAST; + // Don't take up any extra. + weightx = 0.0; + return this; + } + + /** + * Provide the same setup as forLabel(), but allow it to expand vertically + * to use up any extra space there may be. + * + * @return Constraints for label that sucks up vertical space. + */ + public LabelFieldGBC forLastLabel() { + forLabel(); + fill = VERTICAL; + weighty = 1.0; + return this; + } + + /** + * Set up constraint values for placing a field after a label. + * + * @return Constraints for a field. + */ + public LabelFieldGBC forField() { + // The field should take up as much space as is necessary. + fill = HORIZONTAL; + // Set the location to the right side. + gridx = 1; + // Center the field in the space available (a noop in this case). + anchor = CENTER; + // Take up any extra space. + weightx = 1.0; + return this; + } + + /** + * Provide the same setup as forField(), but allow it to expand vertically + * + * + * @return Constraintes for field that sucks up vertical space. + */ + public LabelFieldGBC forLastField() { + forField(); + fill = BOTH; + weighty = 1.0; + return this; + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java index 776fb409c..7a91005cb 100644 --- a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java +++ b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java @@ -52,7 +52,9 @@ * . */ package org.apache.tools.ant.gui; -import org.apache.tools.ant.gui.acs.ACSTargetElement; + +import org.apache.tools.ant.gui.customizer.DynamicCustomizer; +import org.apache.tools.ant.gui.acs.*; import org.apache.tools.ant.gui.event.*; import javax.swing.*; import java.util.*; @@ -68,8 +70,8 @@ import java.awt.BorderLayout; */ class PropertyEditor extends AntEditor { - /** Text pane. */ - private JEditorPane _text = null; + /** The property sheet. */ + private DynamicCustomizer _customizer = null; /** * Standard ctor. @@ -80,115 +82,27 @@ class PropertyEditor extends AntEditor { super(context); context.getEventBus().addMember(EventBus.MONITORING, new Handler()); setLayout(new BorderLayout()); - - _text = new JEditorPane("text/html", getAppContext().getResources(). - getString(getClass(), "noTargets")); - _text.setEditable(false); - _text.setOpaque(false); - - JScrollPane scroller = new JScrollPane(_text); - - add(BorderLayout.CENTER, scroller); } /** - * Populate the display with the given target info. + * Update the display for the current item. * - * @param targets Targets to display info for. + * @param item Current item. */ - private void displayTargetInfo(ACSTargetElement[] targets) { - - // The text to display. - String text = null; - - int num = targets == null ? 0 : targets.length; - Object[] args = null; - switch(num) { - case 0: - text = getAppContext().getResources(). - getString(getClass(), "noTargets"); - break; - case 1: - args = getTargetParams(targets[0]); - text = getAppContext().getResources(). - getMessage(getClass(), "oneTarget", args); - break; - default: - args = getTargetParams(targets); - text = getAppContext().getResources(). - getMessage(getClass(), "manyTargets", args); - break; + private void updateDisplay(ACSElement item) { + if(_customizer != null) { + remove(_customizer); + _customizer = null; } - if(text != null) { - _text.setText(text); + if(item != null) { + _customizer = new DynamicCustomizer(item.getClass(), true); + _customizer.setObject(item); + add(BorderLayout.CENTER, _customizer); } + validate(); } - /** - * Get the parameters for the formatted message presented for a single - * target. - * - * @param target Target to generate params for. - * @return Argument list for the formatted message. - */ - private Object[] getTargetParams(ACSTargetElement target) { - List args = new LinkedList(); - args.add(target.getName()); - args.add(target.getDescription() == null ? - "" : target.getDescription()); - StringBuffer buf = new StringBuffer(); - String[] depends = target.getDependencyNames(); - for(int i = 0; i < depends.length; i++) { - buf.append(depends[i]); - if(i < depends.length - 1) { - buf.append(", "); - } - } - args.add(buf.toString()); - - return args.toArray(); - } - - /** - * Get the parameters for the formatted message presented for multiple - * targets. - * - * @param target Targets to generate params for. - * @return Argument list for the formatted message. - */ - private Object[] getTargetParams(ACSTargetElement[] targets) { - List args = new LinkedList(); - - StringBuffer buf = new StringBuffer(); - Set depends = new HashSet(); - for(int i = 0; i < targets.length; i++) { - buf.append(targets[i].getName()); - if(i < targets.length - 1) { - buf.append(", "); - } - - String[] dependNames = targets[i].getDependencyNames(); - for(int j = 0; j < dependNames.length; j++) { - depends.add(dependNames[j]); - } - } - - args.add(buf.toString()); - - Iterator it = depends.iterator(); - buf = new StringBuffer(); - while(it.hasNext()) { - buf.append(it.next()); - if(it.hasNext()) { - buf.append(", "); - } - } - - args.add(buf.toString()); - - return args.toArray(); - } /** Class for handling project events. */ private class Handler implements BusMember { @@ -212,7 +126,7 @@ class PropertyEditor extends AntEditor { public void eventPosted(EventObject event) { TargetSelectionEvent e = (TargetSelectionEvent) event; ACSTargetElement[] targets = e.getSelectedTargets(); - displayTargetInfo(targets); + updateDisplay(targets.length == 0 ? null : targets[0]); } } diff --git a/src/antidote/org/apache/tools/ant/gui/ResourceManager.java b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java index 9b03913f2..a066487af 100644 --- a/src/antidote/org/apache/tools/ant/gui/ResourceManager.java +++ b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java @@ -67,9 +67,25 @@ import java.io.File; * @author Simeon H.K. Fitch */ public class ResourceManager { - private ResourceBundle _resources = - ResourceBundle.getBundle( - "org.apache.tools.ant.gui.resources.antidote"); + /** Resources to reference. */ + private ResourceBundle _resources = null; + + /** + * Default ctor. Uses the default properties file for antidote. + * + */ + public ResourceManager() { + this("org.apache.tools.ant.gui.resources.antidote"); + } + + /** + * Standard ctor. + * + * @param propName Fully qualified name of the resources to use. + */ + public ResourceManager(String propName) { + _resources = ResourceBundle.getBundle(propName); + } /** * Get a string resource for the given class. diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java new file mode 100644 index 000000000..fbd1dc116 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.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.acs; + +import org.apache.tools.ant.gui.ResourceManager; +import java.beans.*; + +/** + * Specialized BeanDescriptor for providing more descriptive information. + * + * @version $Revision$ + * @author Simeon Fitch + */ +class ACSBeanDescriptor extends BeanDescriptor { + + public ACSBeanDescriptor(BaseBeanInfo type) { + super(type.getType()); + setDisplayName( + type.getResources().getString(type.getClass(), "beanName")); + setShortDescription( + type.getResources().getString(type.getClass(), "beanDescription")); + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java index ba4eb24b6..b563ebca9 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSElement.java @@ -53,11 +53,10 @@ */ package org.apache.tools.ant.gui.acs; - -import org.w3c.dom.Node; import com.sun.xml.tree.ElementNode; -import javax.swing.tree.TreeNode; -import java.util.*; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeSupport; /** * Abstract base class for all Ant Construction Set @@ -65,9 +64,10 @@ import java.util.*; * * @version $Revision$ * @author Simeon Fitch */ -public abstract class ACSElement extends ElementNode implements TreeNode { - /** Cache of TreeNode only children. */ - private List _treeNodeCache = null; +public abstract class ACSElement extends ElementNode { + + /** Event support. */ + private PropertyChangeSupport _propSupport = null; /** * Default ctor. @@ -87,105 +87,42 @@ public abstract class ACSElement extends ElementNode implements TreeNode { } /** - * Get the cache of TreeNode only children. + * Add a change listener. * - * @return List of TreeNodes that are children. + * @param l Listener to add. */ - private List getCache() { - if(_treeNodeCache == null) { - _treeNodeCache = new ArrayList(); - - for(int i = 0; i < getLength(); i++) { - if(item(i) instanceof TreeNode) { - _treeNodeCache.add(item(i)); - } - } + public void addPropertyChangeListener(PropertyChangeListener l) { + if(_propSupport == null) { + _propSupport = new PropertyChangeSupport(this); } - - return _treeNodeCache; - } - /** - * Returns the child TreeNode at index - * childIndex. - */ - public TreeNode getChildAt(int childIndex) { - List nodes = getCache(); - return (TreeNode) nodes.get(childIndex); + _propSupport.addPropertyChangeListener(l); } - /** - * Returns the number of children TreeNodes the receiver - * contains. - */ - public int getChildCount() { - List nodes = getCache(); - return nodes.size(); - } - - /** - * Returns the parent TreeNode of the receiver. - */ - public TreeNode getParent() { - return (TreeNode) getParent(); - } - - /** - * Returns the index of node in the receivers children. - * If the receiver does not contain node, -1 will be - * returned. - */ - public int getIndex(TreeNode node) { - List nodes = getCache(); - return nodes.indexOf(node); - } - - /** - * Returns true if the receiver allows children. - */ - public boolean getAllowsChildren() { - return true; - } - - /** - * Returns true if the receiver is a leaf. - */ - public boolean isLeaf() { - List nodes = getCache(); - return nodes.size() <= 0; - } - /** - * Returns the children of the reciever as an Enumeration. - */ - public Enumeration children() { - return new NodeEnum(); - } - - /** Internal iterator for the child nodes. */ - private class NodeEnum implements Enumeration { - /** Current child index. */ - private int _index = 0; - - /** - * Determine if there are more elements to visit. - * - * @return True if nextElement() can be called, false otherwise. - */ - public boolean hasMoreElements() { - List nodes = getCache(); - return _index < nodes.size(); + /** + * Remove a change listener + * + * @param l Listener to remove. + */ + public void removePropertyChangeListener(PropertyChangeListener l) { + if(_propSupport == null) { + _propSupport = new PropertyChangeSupport(this); } + _propSupport.removePropertyChangeListener(l); + } - /** - * Get the next element. hasMoreElements() must currently return true. - * - * @return Next element - */ - public Object nextElement() { - List nodes = getCache(); - return nodes.get(_index++); + /** + * Fire a change event to all listener. + * + * @param propName Name of the property. + * @param oldValue The old value. + * @param newValue The new value. + */ + protected void firePropertyChange( + String propName, Object oldValue, Object newValue) { + + if(_propSupport != null) { + _propSupport.firePropertyChange(propName, oldValue, newValue); } - } - } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSNamedElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSNamedElement.java new file mode 100644 index 000000000..971126b5a --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSNamedElement.java @@ -0,0 +1,129 @@ +/* + * 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.acs; + +import com.sun.xml.tree.ElementNode; +import java.util.StringTokenizer; + +/** + * Class representing an element with a name and description. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSNamedElement extends ACSTreeNodeElement { + /** The 'name' property name. */ + public static final String NAME = "name"; + /** The discription property name. */ + public static final String DESCRIPTION = "description"; + + /** + * Default ctor. + * + */ + public ACSNamedElement() { + + } + + /** + * Get the target name. + * + * @return Target name. + */ + public String getName() { + return getAttribute(NAME); + } + + /** + * Set the name. + * + * @param name New name value. + */ + public void setName(String name) { + String old = getName(); + setAttribute(NAME, name); + firePropertyChange(NAME, old, name); + } + + /** + * Get the long description of the target. + * + * @return Target description. + */ + public String getDescription() { + return getAttribute(DESCRIPTION); + } + + /** + * Set the description + * + * @param description New description value. + */ + public void setDescription(String description) { + String old = getDescription(); + setAttribute(DESCRIPTION, description); + firePropertyChange(DESCRIPTION, old, description); + } + + /** + * Get the display name. + * + * @return Display name. + */ + public String getDisplayName() { + return getTagName() + ": " + getName(); + } + + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java index 983fb044d..7a3c37b6b 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java @@ -61,18 +61,18 @@ import com.sun.xml.tree.ElementNode; * @version $Revision$ * @author Simeon Fitch */ -public class ACSProjectElement extends ACSElement { +public class ACSProjectElement extends ACSNamedElement { public ACSProjectElement() { } /** - * Get the project name. + * Get the type that this BeanInfo represents. * - * @return Project name. + * @return Type. */ - public String getName() { - return getAttribute("name"); + public Class getType() { + return ACSProjectElement.class; } /** diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java new file mode 100644 index 000000000..43515ec1a --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.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.acs; + +import java.beans.*; + +/** + * BeanInfo for the ACSTargetElement class. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSProjectElementBeanInfo extends BaseBeanInfo { + /** + * Default ctor. + * + */ + public ACSProjectElementBeanInfo() { + } + + /** + * Get the type that this BeanInfo represents. + * + * @return Type. + */ + public Class getType() { + return ACSProjectElement.class; + } + + /** + * Get the property descriptors. + * + * @return Property descriptors. + */ + public PropertyDescriptor[] getPropertyDescriptors() { + PropertyDescriptor[] retval = null; + + try { + retval = new PropertyDescriptor[] { + new PropertyDescriptor(ACSProjectElement.NAME, + ACSProjectElement.class), + new PropertyDescriptor(ACSProjectElement.DESCRIPTION, + ACSProjectElement.class) + + }; + } + catch(IntrospectionException ex) { + ex.printStackTrace(); + throw new Error(ex.toString()); + } + + return retval; + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java index f010d1841..c0cc21856 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElement.java @@ -62,31 +62,14 @@ import java.util.StringTokenizer; * @version $Revision$ * @author Simeon Fitch */ -public class ACSTargetElement extends ACSElement { +public class ACSTargetElement extends ACSNamedElement { + /** * Default ctor. * */ public ACSTargetElement() { - } - - /** - * Get the target name. - * - * @return Target name. - */ - public String getName() { - return getAttribute("name"); - } - - /** - * Get the long description of the target. - * - * @return Target description. - */ - public String getDescription() { - return getAttribute("description"); } /** diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java new file mode 100644 index 000000000..68d9653c3 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java @@ -0,0 +1,108 @@ +/* + * 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.acs; + +import java.beans.*; + +/** + * BeanInfo for the ACSTargetElement class. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class ACSTargetElementBeanInfo extends BaseBeanInfo { + /** + * Default ctor. + * + */ + public ACSTargetElementBeanInfo() { + } + + /** + * Get the type that this BeanInfo represents. + * + * @return Type. + */ + public Class getType() { + return ACSTargetElement.class; + } + + /** + * Get the property descriptors. + * + * @return Property descriptors. + */ + public PropertyDescriptor[] getPropertyDescriptors() { + PropertyDescriptor[] retval = null; + + try { + retval = new PropertyDescriptor[] { + new PropertyDescriptor(getResources().getString( + getClass(),ACSTargetElement.NAME), + ACSTargetElement.class), + new PropertyDescriptor(getResources().getString( + getClass(),ACSTargetElement.DESCRIPTION), + ACSTargetElement.class) + + }; + } + catch(IntrospectionException ex) { + ex.printStackTrace(); + throw new Error(ex.toString()); + } + + return retval; + } + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java new file mode 100644 index 000000000..e0f887a4a --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java @@ -0,0 +1,175 @@ +/* + * 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.acs; + + +import org.w3c.dom.Node; +import com.sun.xml.tree.ElementNode; +import javax.swing.tree.TreeNode; +import java.util.*; + +/** + * Abstract base class for all ACSElement classes that are also tree node. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public abstract class ACSTreeNodeElement extends ACSElement + implements TreeNode { + + /** Cache of TreeNode only children. */ + private List _treeNodeCache = null; + + /** + * Get the cache of TreeNode only children. + * + * @return List of TreeNodes that are children. + */ + private List getCache() { + if(_treeNodeCache == null) { + _treeNodeCache = new ArrayList(); + + for(int i = 0; i < getLength(); i++) { + if(item(i) instanceof TreeNode) { + _treeNodeCache.add(item(i)); + } + } + } + + return _treeNodeCache; + } + /** + * Returns the child TreeNode at index + * childIndex. + */ + public TreeNode getChildAt(int childIndex) { + List nodes = getCache(); + return (TreeNode) nodes.get(childIndex); + } + + /** + * Returns the number of children TreeNodes the receiver + * contains. + */ + public int getChildCount() { + List nodes = getCache(); + return nodes.size(); + } + + /** + * Returns the parent TreeNode of the receiver. + */ + public TreeNode getParent() { + return (TreeNode) getParent(); + } + + /** + * Returns the index of node in the receivers children. + * If the receiver does not contain node, -1 will be + * returned. + */ + public int getIndex(TreeNode node) { + List nodes = getCache(); + return nodes.indexOf(node); + } + + /** + * Returns true if the receiver allows children. + */ + public boolean getAllowsChildren() { + return true; + } + + /** + * Returns true if the receiver is a leaf. + */ + public boolean isLeaf() { + List nodes = getCache(); + return nodes.size() <= 0; + } + + /** + * Returns the children of the reciever as an Enumeration. + */ + public Enumeration children() { + return new NodeEnum(); + } + + /** Internal iterator for the child nodes. */ + private class NodeEnum implements Enumeration { + /** Current child index. */ + private int _index = 0; + + /** + * Determine if there are more elements to visit. + * + * @return True if nextElement() can be called, false otherwise. + */ + public boolean hasMoreElements() { + List nodes = getCache(); + return _index < nodes.size(); + } + + /** + * Get the next element. hasMoreElements() must currently return true. + * + * @return Next element + */ + public Object nextElement() { + List nodes = getCache(); + return nodes.get(_index++); + } + + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java new file mode 100644 index 000000000..c8ac38fa9 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java @@ -0,0 +1,118 @@ +/* + * 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.acs; + +import org.apache.tools.ant.gui.ResourceManager; +import java.beans.*; + +/** + * Abstract base class for ACS BeanInfo classes. + * + * @version $Revision$ + * @author Simeon Fitch + */ +abstract class BaseBeanInfo extends SimpleBeanInfo { + + /** Resource provider for bean info. */ + private static ResourceManager _resources = new ResourceManager( + "org.apache.tools.ant.gui.acs.beaninfo"); + + /** + * Default ctor. + * + */ + protected BaseBeanInfo() { + } + + /** + * Get the local resources. + * + * @return Resources. + */ + ResourceManager getResources() { + return _resources; + } + + /** + * Get the bean descriptor. + * + * @return Bean descriptor. + */ + public BeanDescriptor getBeanDescriptor() { + return new ACSBeanDescriptor(this); + } + + /** + * Get the type that this BeanInfo represents. + * + * @return Type. + */ + public abstract Class getType(); + + /** + * Gets the beans PropertyDescriptors. + * + * @return An array of PropertyDescriptors describing the editable + * properties supported by this bean. May return null if the + * information should be obtained by automatic analysis. + *

+ * If a property is indexed, then its entry in the result array will + * belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor. + * A client of getPropertyDescriptors can use "instanceof" to check + * if a given PropertyDescriptor is an IndexedPropertyDescriptor. + */ + public abstract PropertyDescriptor[] getPropertyDescriptors(); + + +} diff --git a/src/antidote/org/apache/tools/ant/gui/acs/beaninfo.properties b/src/antidote/org/apache/tools/ant/gui/acs/beaninfo.properties new file mode 100644 index 000000000..d949388b0 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/acs/beaninfo.properties @@ -0,0 +1,14 @@ +# Properties file for BeanInfo strings + +org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.beanName=Target +org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.beanDescription=\ + An executable target in the build. +org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.name=Name +org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.description=Description + +org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.beanName=Project +org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.beanDescription=\ + The top level project in the build definition. +org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.name=Name +org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.description=Description + diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java new file mode 100644 index 000000000..6534a71c2 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/customizer/AbstractPropertyEditor.java @@ -0,0 +1,244 @@ +/* + * 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.customizer; + +import java.beans.*; +import java.awt.Graphics; +import java.awt.Component; +import java.awt.Rectangle; +import javax.swing.JComponent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusAdapter; + +/** + * Abstract base class for the custom type property editors. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public abstract class AbstractPropertyEditor implements PropertyEditor { + + /** Bean property change property name. */ + public static final String BEAN_PROP = "BeanEditorProperty"; + + private PropertyChangeSupport _listeners = new PropertyChangeSupport(this); + /** + * Default constructor. + * + */ + protected AbstractPropertyEditor() { + } + + /** + * Paint a representation of the value into a given area of screen + * real estate. Note that the propertyEditor is responsible for doing + * its own clipping so that it fits into the given rectangle. + *

+ * If the PropertyEditor doesn't honor paint requests (see isPaintable) + * this method should be a silent noop. + *

+ * The given Graphics object will have the default font, color, etc of + * the parent container. The PropertyEditor may change graphics attributes + * such as font and color and doesn't need to restore the old values. + * + * @param gfx Graphics object to paint into. + * @param box Rectangle within graphics object into which we should paint. + */ + public void paintValue(Graphics gfx, Rectangle box) { + Object o = getValue(); + String s = o == null ? "" : o.toString(); + gfx.drawString(s, box.x, box.y); + } + + + /** + * Fire a property change event to listeners. + * + * @param oldValue Old value. + * @param newValue New value. + */ + public void firePropertyChange(Object oldValue, Object newValue) { + _listeners.firePropertyChange(BEAN_PROP, oldValue, newValue); + } + + /** + * Add a property change listener. XXX This may cause undesired + * side affects with merging property changes with JPanel class. + * Need to test for a while. + * + * @param l Change listener. + */ + public void addPropertyChangeListener(PropertyChangeListener l) { + _listeners.addPropertyChangeListener(l); + } + + /** + * Remove a property change listener. + * + * @param l Change listener. + */ + public void removePropertyChangeListener(PropertyChangeListener l) { + _listeners.removePropertyChangeListener(l); + } + + /** + * @return True if the class will honor the paintValue method. + */ + public boolean isPaintable() { + return true; + } + + /** + * If the property value must be one of a set of known tagged values, + * then this method should return an array of the tags. This can + * be used to represent (for example) enum values. If a PropertyEditor + * supports tags, then it should support the use of setAsText with + * a tag value as a way of setting the value and the use of getAsText + * to identify the current value. + * + * @return The tag values for this property. May be null if this + * property cannot be represented as a tagged value. + * + */ + public String[] getTags() { + return null; + } + + /** + * A PropertyEditor may choose to make available a full custom Component + * that edits its property value. It is the responsibility of the + * PropertyEditor to hook itself up to its editor Component itself and + * to report property value changes by firing a PropertyChange event. + *

+ * The higher-level code that calls getCustomEditor may either embed + * the Component in some larger property sheet, or it may put it in + * its own individual dialog, or ... + * + * @return A java.awt.Component that will allow a human to directly + * edit the current property value. May be null if this is + * not supported. + */ + public Component getCustomEditor() { + return getChild(); + } + + /** + * @return True if the propertyEditor can provide a custom editor. + */ + public boolean supportsCustomEditor() { + return true; + } + + /** + * This method is intended for use when generating Java code to set + * the value of the property. It should return a fragment of Java code + * that can be used to initialize a variable with the current property + * value. + *

+ * Example results are "2", "new Color(127,127,34)", "Color.orange", etc. + * + * @return A fragment of Java code representing an initializer for the + * current value. + */ + public String getJavaInitializationString() { + return ""; + } + + /** + * Get the child editing component. + * + * @return Child editing component. + */ + protected abstract Component getChild(); + + /** Helper class for detecting changes and generating change events + * on a focus lost event. */ + protected static class FocusHandler extends FocusAdapter { + /** Last value of the editor. */ + private Object _value = null; + /** Editor of interest. */ + private AbstractPropertyEditor _editor = null; + + /** + * Standard constructor. + * + * @param editor Editor of interest. + */ + public FocusHandler(AbstractPropertyEditor editor) { + _editor = editor; + } + + /** + * Called when focus is gained. + * + * @param e Focus event. + */ + public void focusGained(FocusEvent e) { + _value = _editor.getValue(); + } + + /** + * Called when focus is lost. Checks to see if value changed and + * fires a change event if needed. + * + * @param e Focus event. + */ + public void focusLost(FocusEvent e) { + if((_value != null && !_value.equals(_editor.getValue())) || + (_value == null && _editor.getValue() != null)) { + _editor.firePropertyChange(_value, _editor.getValue()); + } + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java new file mode 100644 index 000000000..8ba7db30e --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/customizer/DoublePropertyEditor.java @@ -0,0 +1,173 @@ +/* + * 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.customizer; + +import javax.swing.*; +import java.awt.Component; + +/** + * Custom property editor for editing double values. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class DoublePropertyEditor extends AbstractPropertyEditor { + /** Editing widget. */ + private JTextField _widget = null; + + /** + * Default ctor. + * + */ + public DoublePropertyEditor() { + _widget = new JTextField(); + _widget.addFocusListener(new FocusHandler(this)); + } + + /** + * Get the child editing component. Uses JComponent so we can have tool + * tips, etc. + * + * @return Child editing component. + */ + protected Component getChild() { + return _widget; + } + + /** + * This method is intended for use when generating Java code to set + * the value of the property. It should return a fragment of Java code + * that can be used to initialize a variable with the current property + * value. + *

+ * Example results are "2", "new Color(127,127,34)", "Color.orange", etc. + * + * @return A fragment of Java code representing an initializer for the + * current value. + */ + public String getJavaInitializationString() { + return "new Double(" + getAsText() + ")"; + } + + /** + * Set (or change) the object that is to be edited. Builtin types such + * as "int" must be wrapped as the corresponding object type such as + * "java.lang.Integer". + * + * @param value The new target object to be edited. Note that this + * object should not be modified by the PropertyEditor, rather + * the PropertyEditor should create a new object to hold any + * modified value. + */ + public void setValue(Object value) { + Object old = _widget.getText(); + if(!(value instanceof Double)) { + value = new Double(0); + } + + _widget.setText(value.toString()); + + firePropertyChange(old, value); + } + + /** + * @return The value of the property. Builtin types such as "int" will + * be wrapped as the corresponding object type such as "java.lang.Integer". + */ + public Object getValue() { + Double retval = null; + try { + retval = new Double(_widget.getText()); + } + catch(NumberFormatException ex) { + retval = new Double(0); + _widget.setText(retval.toString()); + } + return retval; + } + + /** + * Set the property value by parsing a given String. May raise + * java.lang.IllegalArgumentException if either the String is + * badly formatted or if this kind of property can't be expressed + * as text. + * @param text The string to be parsed. + */ + public void setAsText(String text) { + Object old = _widget.getText(); + Double val = null; + try { + val = new Double(text); + } + catch(NumberFormatException ex) { + val = new Double(0); + } + text = val.toString(); + _widget.setText(text); + firePropertyChange(old, text); + } + + /** + * @return The property value as a human editable string. + *

Returns null if the value can't be expressed + * as an editable string. + *

If a non-null value is returned, then the PropertyEditor should + * be prepared to parse that string back in setAsText(). + */ + public String getAsText() { + return _widget.getText(); + } +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java new file mode 100644 index 000000000..51c94ad22 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java @@ -0,0 +1,286 @@ +/* + * 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.customizer; + +import org.apache.tools.ant.gui.LabelFieldGBC; +import java.lang.reflect.*; +import java.beans.*; +import javax.swing.*; +import java.util.Hashtable; +import java.util.Enumeration; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Component; + +/** + * Widget for dynamically constructing a property editor based on the + * an Object's BeanInfo. Essentially a property sheet. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class DynamicCustomizer extends JPanel { + static { + PropertyEditorManager.registerEditor( + String.class, StringPropertyEditor.class); + PropertyEditorManager.registerEditor( + int.class, IntegerPropertyEditor.class); + PropertyEditorManager.registerEditor( + Integer.class, IntegerPropertyEditor.class); + PropertyEditorManager.registerEditor( + double.class, DoublePropertyEditor.class); + PropertyEditorManager.registerEditor( + Double.class, DoublePropertyEditor.class); + } + + /** The type that this editor instance can handle. */ + private Class _type = null; + /** The value currently being edited. */ + private Object _value = null; + /** Mapping from PropertyDescriptor to PropertyEditor. */ + private Hashtable _prop2Editor = new Hashtable(); + /** Mapping from PropertyEditor to field PropertyDescriptor. */ + private Hashtable _editor2Prop = new Hashtable(); + /** Listener for receiving change events from the editors. */ + private EditorChangeListener _eListener = new EditorChangeListener(); + /** Read-only flag. */ + private boolean _readOnly = false; + + + /** + * Standard constructor. + * + * @param type Type that you are going to be creating and editor for. + */ + public DynamicCustomizer(Class type) { + this(type, false); + } + + /** + * Standard constructor. + * + * @param type Type that you are going to be creating and editor for. + * @param readOnly Set to true to create a read-only customizer. + */ + public DynamicCustomizer(Class type, boolean readOnly) { + super(new GridBagLayout()); + _readOnly = readOnly; + _type = type; + + LabelFieldGBC gbc = new LabelFieldGBC(); + try { + BeanInfo info = Introspector.getBeanInfo(type); + setBorder(BorderFactory.createTitledBorder( + info.getBeanDescriptor().getDisplayName())); + PropertyDescriptor[] props = info.getPropertyDescriptors(); + for(int i = 0; i < props.length; i++) { + if(props[i].getName().equals("class")) continue; + JLabel label = new JLabel(props[i].getDisplayName() + ":"); + + // Lookup the editor. + PropertyEditor editor = getEditorForProperty(props[i]); + if(editor == null) continue; + // Add a listener to the editor so we know when to update + // the bean's fields. + editor.addPropertyChangeListener(_eListener); + + // XXX What we need to do right here is provide a component + // that makes use of the "paintable" capability of the editor. + Component comp = editor.getCustomEditor(); + if(comp == null) { + comp = new JLabel("<>"); + } + + // See if it is a read-only property. If so, then just + // display it. + if(_readOnly || props[i].getWriteMethod() == null) { + comp.setEnabled(false); + } + + // Setup the accellerator key. + label.setLabelFor(comp); + label.setDisplayedMnemonic(label.getText().charAt(0)); + + // Set the tool tip text, if any. + String tip = props[i].getShortDescription(); + if(tip != null) { + label.setToolTipText(tip); + if(comp instanceof JComponent) { + ((JComponent)comp).setToolTipText(tip); + } + } + + + // Add the label and fields. + add(label, gbc.forLabel()); + add(comp, gbc.forField()); + + // Set the mappings between editor and property, etc. for + // quick lookup later. + _prop2Editor.put(props[i], editor); + _editor2Prop.put(editor, props[i]); + } + // Filler... + add(new JLabel(), gbc.forLastLabel()); + + } + catch(Exception ex) { + ex.printStackTrace(); + } + } + + + /** + * Set the object to be edited. + * + * @param value The object to be edited. + */ + public void setObject(Object value) { + if(!(_type.isInstance(value))) { + throw new IllegalArgumentException( + value.getClass() + " is not of type " + _type); + } + _value = value; + + // Iterate over each property, doing a lookup on the associated editor + // and setting the editor's value to the value of the property. + Enumeration enum = _prop2Editor.keys(); + while(enum.hasMoreElements()) { + PropertyDescriptor desc = (PropertyDescriptor) enum.nextElement(); + PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc); + Method reader = desc.getReadMethod(); + if(reader != null) { + try { + Object val = reader.invoke(_value, null); + editor.setValue(val); + } + catch(IllegalAccessException ex) { + ex.printStackTrace(); + } + catch(InvocationTargetException ex) { + ex.getTargetException().printStackTrace(); + } + } + } + } + + private PropertyEditor getEditorForProperty(PropertyDescriptor prop) { + PropertyEditor retval = null; + Class type = prop.getPropertyEditorClass(); + if(type != null) { + try { + retval = (PropertyEditor) type.newInstance(); + } + catch(Exception ex) { + ex.printStackTrace(); + } + } + // Handle case where there is no special editor + // associated with the property. In that case we ask the + // PropertyEditor manager for the editor registered for the + // given property type. + if(retval == null) { + retval = PropertyEditorManager.findEditor(prop.getPropertyType()); + } + + return retval; + } + + /** Class for receiving change events from teh PropertyEditor objects. */ + private class EditorChangeListener implements PropertyChangeListener { + public void propertyChange(PropertyChangeEvent e) { + PropertyEditor editor = (PropertyEditor) e.getSource(); + PropertyDescriptor prop = + (PropertyDescriptor) _editor2Prop.get(editor); + Method writer = prop.getWriteMethod(); + if(writer != null) { + try { + Object[] params = { editor.getValue() }; + writer.invoke(_value, params); + //firePropertyChange( + //prop.getName(), null, editor.getValue()); + } + catch(IllegalAccessException ex) { + ex.printStackTrace(); + } + catch(InvocationTargetException ex) { + ex.getTargetException().printStackTrace(); + } + } + } + } + + + /** + * Test code. + * + * @param args First arg is the class name to create + */ + public static void main(String[] args) { + + try { + Class c = Class.forName(args[0]); + JFrame f = new JFrame(c.getName()); + DynamicCustomizer custom = + new DynamicCustomizer(c); + custom.setObject(c.newInstance()); + f.getContentPane().add(custom); + f.pack(); + f.setVisible(true); + } + catch(Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java new file mode 100644 index 000000000..ccd6077e8 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/customizer/IntegerPropertyEditor.java @@ -0,0 +1,175 @@ +/* + * 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.customizer; + +import javax.swing.*; +import java.awt.Component; + +/** + * Custom property editor for integer types. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class IntegerPropertyEditor extends AbstractPropertyEditor { + /** Editing widget. */ + private JTextField _widget = null; + + /** + * Default ctor. + * + */ + public IntegerPropertyEditor() { + _widget = new JTextField(); + _widget.addFocusListener(new FocusHandler(this)); + } + + /** + * Get the child editing component. Uses JComponent so we can have tool + * tips, etc. + * + * @return Child editing component. + */ + protected Component getChild() { + return _widget; + } + + /** + * This method is intended for use when generating Java code to set + * the value of the property. It should return a fragment of Java code + * that can be used to initialize a variable with the current property + * value. + *

+ * Example results are "2", "new Color(127,127,34)", "Color.orange", etc. + * + * @return A fragment of Java code representing an initializer for the + * current value. + */ + public String getJavaInitializationString() { + return "new Integer(" + getAsText() + ")"; + } + + /** + * Set (or change) the object that is to be edited. Builtin types such + * as "int" must be wrapped as the corresponding object type such as + * "java.lang.Integer". + * + * @param value The new target object to be edited. Note that this + * object should not be modified by the PropertyEditor, rather + * the PropertyEditor should create a new object to hold any + * modified value. + */ + public void setValue(Object value) { + Object old = _widget.getText(); + if(!(value instanceof Integer)) { + value = new Integer(0); + } + + _widget.setText(value.toString()); + + firePropertyChange(old, value); + } + + /** + * @return The value of the property. Builtin types such as "int" will + * be wrapped as the corresponding object type such as "java.lang.Integer". + */ + public Object getValue() { + Integer retval = null; + try { + retval = new Integer(_widget.getText()); + } + catch(NumberFormatException ex) { + retval = new Integer(0); + _widget.setText(retval.toString()); + } + return retval; + } + + /** + * Set the property value by parsing a given String. May raise + * java.lang.IllegalArgumentException if either the String is + * badly formatted or if this kind of property can't be expressed + * as text. + * @param text The string to be parsed. + */ + public void setAsText(String text) { + Object old = _widget.getText(); + Integer val = null; + try { + val = new Integer(text); + } + catch(NumberFormatException ex) { + val = new Integer(0); + } + text = val.toString(); + _widget.setText(text); + firePropertyChange(old, text); + } + + /** + * @return The property value as a human editable string. + *

Returns null if the value can't be expressed + * as an editable string. + *

If a non-null value is returned, then the PropertyEditor should + * be prepared to parse that string back in setAsText(). + */ + public String getAsText() { + return _widget.getText(); + } + + +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java new file mode 100644 index 000000000..b679b8062 --- /dev/null +++ b/src/antidote/org/apache/tools/ant/gui/customizer/StringPropertyEditor.java @@ -0,0 +1,153 @@ +/* + * 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.customizer; + +import javax.swing.*; +import java.awt.Component; + +/** + * Custom property editor for string types. + * + * @version $Revision$ + * @author Simeon Fitch + */ +public class StringPropertyEditor extends AbstractPropertyEditor { + private JTextField _widget = null; + + /** + * Default ctor. + * + */ + public StringPropertyEditor() { + _widget = new JTextField(); + _widget.addFocusListener(new FocusHandler(this)); + } + + /** + * Get the child editing component. Uses JComponent so we can have tool + * tips, etc. + * + * @return Child editing component. + */ + protected Component getChild() { + return _widget; + } + + /** + * This method is intended for use when generating Java code to set + * the value of the property. It should return a fragment of Java code + * that can be used to initialize a variable with the current property + * value. + *

+ * Example results are "2", "new Color(127,127,34)", "Color.orange", etc. + * + * @return A fragment of Java code representing an initializer for the + * current value. + */ + public String getJavaInitializationString() { + return getAsText(); + } + + /** + * Set (or change) the object that is to be edited. Builtin types such + * as "int" must be wrapped as the corresponding object type such as + * "java.lang.Integer". + * + * @param value The new target object to be edited. Note that this + * object should not be modified by the PropertyEditor, rather + * the PropertyEditor should create a new object to hold any + * modified value. + */ + public void setValue(Object value) { + Object old = _widget.getText(); + _widget.setText(String.valueOf(value)); + firePropertyChange(old, value); + } + + /** + * @return The value of the property. Builtin types such as "int" will + * be wrapped as the corresponding object type such as "java.lang.Integer". + */ + public Object getValue() { + return _widget.getText(); + } + + /** + * Set the property value by parsing a given String. May raise + * java.lang.IllegalArgumentException if either the String is + * badly formatted or if this kind of property can't be expressed + * as text. + * @param text The string to be parsed. + */ + public void setAsText(String text) throws IllegalArgumentException { + Object old = _widget.getText(); + _widget.setText(text); + firePropertyChange(old, text); + } + + /** + * @return The property value as a human editable string. + *

Returns null if the value can't be expressed + * as an editable string. + *

If a non-null value is returned, then the PropertyEditor should + * be prepared to parse that string back in setAsText(). + */ + public String getAsText() { + return _widget.getText(); + } + + +} + + diff --git a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties index 83797c9ab..580929282 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -18,18 +18,6 @@ org.apache.tools.ant.gui.SourceEditor.name=Source org.apache.tools.ant.gui.PropertyEditor.name=Target Info org.apache.tools.ant.gui.PropertyEditor.noTargets=No targets selected. -org.apache.tools.ant.gui.PropertyEditor.oneTarget=\ - \ - \ - \ - \ -
Name:{0}
Description:{1}
Depends:{2}
- -org.apache.tools.ant.gui.PropertyEditor.manyTargets=\ - \ - \ - \ -
Names:{0}
Depends:{1}
org.apache.tools.ant.gui.ProjectNavigator.name=Project org.apache.tools.ant.gui.Console.name=Console diff --git a/src/antidote/org/apache/tools/ant/gui/resources/default.gif b/src/antidote/org/apache/tools/ant/gui/resources/default.gif index 0c42bd3ae1268697e3420ad88c83d8ba8dc59422..46261fce3d596f41eb0140a9d768e4476707d526 100644 GIT binary patch literal 987 zcmZvbPiPZC7{#9`+JhDkvCuz)MK-92+JOJi_Mo7f1z{E1hR;~PF0e)DE_#&>Mm zcp!oZeiEU~nKEb03_H^t3FVL6cp5P9IN{Q>STLAZ=_qvIry*0YlMov87&z&1%w^W% zfI*=$p|Bl(9I_R53xoo_9`roAE-j0OK~<%qQ~)24fDH&hM>sP{cZ^n+#sF18B|)_N zh)cBEXc16!)YA*-PSEmb6sYE@IE3RPEs?U36wq|U=#egIkp`)f3M;7i@Fk=TTR`a0 zXTxF|ehM-PTZ4!}pACy~_^psFuoZ}U=v7$Zh5k=A8x|4w(JIkmLlLOgXTu`WK2j1% z8=62&ufifK75F}+gl$6z=;2J@a>Al#u%I$OomN#~9w%LnS8f|E3sI9H#?_hZN zx@nrzkDcLh(-wNTglhgZZw@dAtHa&!M?`=ciMchAp07>!Pkt%h-k#_l-hS@$yC-uO zuW3SW@Z#DTHCT%7xA*&}N{gDz(~V0r-(MbmojbDbuADj*J7iwLzJkAUF#7cB=i`sw zOVPON;>UMq8?}2YHucQ^(0i~LDQ!4bt}WftejI+#{U%?Ys$0{%*WL1Dm4BhGwEM)K zn;j2_)_;1Qd!4CU=nQ6eqv6<{%Z=Z^J+rpSFYh~FMw6G8$A`B53HCqkU$VCI#Qs;y Nww+(NdBHqv`3sPz^cnyF literal 1212 zcmZ?wbhEHblwy!#_|Cxa|Ns9ZJO)P?)DGK(9X9Yitm1rF!tzi~?V*I?Lm^p*JQ5Dh zU2<^Ztb?r+4py`u0D`UC53F3fyRdoJ&b_x85C_Q3?4QfXcS>HD!6cfv9*bbpHHRY!$W2^ zRgDG@iw%y4+C>yZp3DePXlCG%v+%GysMOpf>}=-|QNYy9q?~5tp=r3(afYd4LCJ%J z1WpbP2QHmcg$oWW<8k|;6Se5z5fT0k+gvOrE?{1$B&o3DB!lMRMfR+I0+t_MUt#3+ zSkp2gi6Oj6HB-!2al(;9Q-uX;mcA@eIx}5Mnn%Nc;Sd9hxTe&con_A)w{g#%*=LrmWMg^-3O5Nzac6=~S4tS|+)4_NW9+ z(a17C$|HTj(O>M>fuqG@W%z?og0Q5`fEDVwsD!6>*<&D+Zc_L4Dtk%;!~>RWDK_?<7m!w(Lh^F604*m>yS zrDil^nQ#a|Y8I z6Dozwu*4qNL6{xTeGn294`^953~Cxxm9k7pssJ`%0y-c71RF40GOZ#Fi&~cI6y?-vVEU2y$z(hpk4B^Y{r!6bc0b0l(kh+S=;%dK(%V_@_KR z{xlYgtvq%*$E}#-&f;jt?>ZOYLc6o;{D@}2J%e?1hkoQQ4Bc@zjy1hg#*d)UdjiLd zofz1#wSM2%i;ri!5_7ISxnGgacw@`;`7fJ}4_({I`}^;m>3eJALGKN|fp VdG|o~_6v=^w?ogHu55JU$Uk+^?j!&J 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$ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/open.gif b/src/antidote/org/apache/tools/ant/gui/resources/open.gif index fe0914f2832310a80a05be1741cbe2401a76e0bd..3bd72bee0b648a3a353f688e56113583d0d51b7f 100644 GIT binary patch literal 1001 zcmZvbUuYav7{yO&!8DYm+LW@}KSuP%ihbE>tD#MTsBLCP#Hl6OCm$TzrzxTILXdqL zX^A0iCv}7ogoKFJ%0!eA8uyB!F}2yWfk^c}#eu@6ghESQqtKSZ9;bP;n*-lHe3uU{ zzkBZODIDr}?Sodd;y#heTP<(ZytMPY=~T(|*Vk*T=?B&LruJ`KbFY-msYqOn@O^+! zOK==m77PPi(yYXs@HygAnk)+TA}K(1A`pgTfSQWS~a1OSH5rpW>5?WX zSVuiUqM$;A64HiU)2znSK4)E)O-6zd7$7M@IS4IC1NK^2EFkHE$|DqzS=bF&>4iQ? zwiXsqNYJH_4zGy8(-+*O4Sp3SkH-VW%^-m{p(J<*do_DprIf zfGQz$AT8L2=2Fax&k2_!CZ%8z4S{Lun6XdarEAg@6b)EdqOLHWpg%%a(kxQ+K8b}I zb(OKEKTEevGg=Mo|5#u{U=3JUSy@?LUS3>WTv%9`nVFfKoQ$GqY-}tDg2BPTQmNG6 z-|sk1UtgbPS>4^;hGDd~x94)XOeVuewej(AKw3BbNtadv>hD&=k_xfdOqH?W$#eOjSFv|ZaKAoI(zcg<%?D99cnxB zve%P6yK{8-z0qFz?9A|%`AaW(am(+~JFk4P+q=}VeQxwX@s0Hxb~Sa5&wqCB{hv39 ze|Ow%`}WRVR1Yj3X$YIESrXPhmW-gM=x`|X#L r*2pP7U!ywx%qr7gSy{nMIp4U&`cFQ4nR(VvxbMTvG{5sI3=Gx)p1?TS diff --git a/src/antidote/org/apache/tools/ant/gui/resources/save.gif b/src/antidote/org/apache/tools/ant/gui/resources/save.gif index 6acb73056060276829ad560ce1cf7ec3d7ee444a..fc7fc0507e3cf7afe6e083a30746beaec82dd203 100644 GIT binary patch literal 981 zcmZvbT}TvB9L0|mXhlARFG@iXV^IdWP$r@UQO<5rL!le=)bt@VCE@Ku_G!S-AQ*F_ zi7d=Mh?oUo`VfZ*RM4%61?h%hgW(#|OSalWgte#9w_FeW@8N&>!{v9+y>;OOyDLu? zp$NZ-K;~kZi)IF$X$}PP2cEvqFe90EDJ_l|>{sb1bl}I~#bE0Y5ojTBN;2s(VX?!Y zP#INN4?hgA26hF60<9R7lCDe3qG3=~sVG^%2Ry(A1fU_9nWCGdm7vin|>Gj!9mB#jZO{Zt&n@e%hBv!M$_G=wNgm$XQOR7r(dWPSJ^JR7!v(4Z}c z#W?&JJRNofA_Q$YEQaCNz^j0*KompE!3r*PDcN#ZMA%1-hYA~tK(V$Q77_Om^Pt;^ z2!ym8EFznQ@5A$8+Yka;Fq3hawkQpbsO(=zD{+_ zzd2dmJToyo-`IPq#+k6vq>{j#UI{8ZPPs^?z^Zf#u~U;lPpW9rKE z`OxXQm(NBYZ{MNIx1*cY&TW$qPp#^4J|&Jv8$P_h-FT#Z&*%MrOLjfd9#plKDo*c( z6PLcF-tF8nTlV^D%g^-XZi!(!`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$ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/start.gif b/src/antidote/org/apache/tools/ant/gui/resources/start.gif index 6a67694bed874061c749975414206db30a2f6d07..072861596df01e26a4464f6310129e2598ed098e 100644 GIT binary patch literal 988 zcmZvbK}Zx)9LB#$YC+keM9@$QnXMoSHzBDMrL5VZVhYqQh7FyXu;5k17BM7kkTKQ@ zQxJ)PbyzzzS<6llnB*=LE*&NUn<&;2I#kPckO=l`^p@)f?|r<-A09t`y#0}VO*@WP zq7rkMkFl_fg);n;VT}9n#vi`PGw(8I(>0manUa~1n1C0D6NRNgC{V-TjLVG8QIi8Y zh0HFA9q=M>nqf6SNKmUm*QIUKG^y*9WlB;J@Bjy}00F4*XJ%+;XpT}Jpe!hL5gi^P z4w@}A2uLcb>E>zYXu8zXlv9)vM8ZSdLDYgKpr{DbC2i6qby6lJ7E$!zIdCjk0z!ql z6c*#~qHr`=3Pc#{Qdo?@YlhPROM<9|T7pGjG1*dBM8re0g9ZzdK()FQ77_Olb)Z>L z1j1?w7Evt1^WZqJEC>PBpUK4rNROf(9A+ZZ3!d$vGZIh-> zU8XEiD#5}G-3;wfngi4Yp)fl;J3T#} z&1NSiCX&fyB9Ryx8j8o`u~;k`jrR8TYMR#B*{LW>OG`^Q91ev-H8nNCV32?F!^0zn zVfb!9|GD|{+u!_b_*1qFScWbBt^Xq`(HeM;<$;RF*;=D7u=e@7P4B+6o%^*qR(?BQ zyXVS^5A9DU?W1;I`L?REn_IR1!HsRlUI%)*cU?f}$c>fjzqVdOx_$SZHTTaB%8JRpsfbOz5m$b^7hSPbcawU3~V+qA>F!m z%2Jt9);<=<;x%)po__B;&&-@T=lq`ICyyOEd~O-b_>BpzJz6`||D^2roR2?zr@;*} zgdq)O0AU0PCqx91L=kY9gARAd5sq|}qvx4G!PSEiLJHMb0ShqT0RTWm%ikK8!%lfr*i)l^DOxM>Y4s4$t%~Z!wy8Q*1V~P$*N4JU7E)^!1o6BQhf^ z8oY6OWOsLA=W_Ayd&DD2i@q!iEY^-b`&Y-#zw6gcdVjy{FJc*3I*Y}|Z6{vD+p9}k z_HKLf{QjG38@8Xivh?H2`VY+SivG!pi z0uhpe*@)&LaqNN#?S_dJ4FuZ|;(`znZ5BlY`!)KO>j(ey@jv|G@H^i*dqTT6Z9Gzj zGW;fd>64{Tn(lYH-tWunzc-j=*5#;8*I-g(uR=?r1uqUK3Nr!`hAM*@mnoYGgB==$ z!X}9g@Ir9vUIOF;34Fo z&O}f^QW2n=r9Dc+rIw`9OUWWE4{--k6A^*13YjixlLo1g3Mny%oCnW=W5N^=D%9z) z7>5^y6M-3qkfBb8#SpwYI6;^aL;z|YmVcpB$)>|1LLTZI1WiZ+0d+boBJLsTAYvjc zAgg&;L@o!BoE|FOWl!1Ay#K0ZD+HkMAO zhlhs;1_pY1dMwN8?CgxkU2QI9y*}FUxXub#+BWMR9R4|7N?o zx^-QjcYl?hf59J9c>J^Utn5=a=43uTIyrY(Vf;L=E{S=Mp~ZDO`N!MsvM3Uq44qZf}0voEo@z Uyzjxs?^g4f*3xyA%Sy22AKGl_!TG!_#%*>f{&hI&S>co+w=a;dJ-*k7}HqBuI+S(lOlsmvU-5ie6sG8 zGo0xxXOlEdsf!XrOtHjfZZZ8HR4{@WtYFJwIYT|EWF#|L$=1kW;WPvk||7SDiemyEabCJBR5FTQ|oI!Te?fGaHXrfM|O7?c5Wi1luBwR zEYy6wQ=tfDs6uUzrJAI7T`E$Us#JSsrDpEkT#8bbs)V^0O|RYVqV}-uYG=kpv(dtB zCWd8NmbE$U!wBRYm>79liSgTfRC6Ef@J!G07NdDL#bz@Lg)-I1b2BVPUys=`A~Uk0 z!5gPXc6S$cE*Jm4M?8|W=*zOeV*Ti|e|7BsyK%#$5BAIcB9?)rb69NNvGO9`UR&C> zf5*M&=igl4wDa`Ur5|5bZ*ARvVfEhSukWwzI(}ly+Dluzv*pZ#*H3=#d3*QJ*>{ir jT)FiA{^66~K0SSP@yzYL2W~vO`D@?Dhb!ARZN#zvQ?hZ% diff --git a/src/antidote/org/apache/tools/ant/gui/version.txt b/src/antidote/org/apache/tools/ant/gui/version.txt index 603801ec1..f1257d47b 100644 --- a/src/antidote/org/apache/tools/ant/gui/version.txt +++ b/src/antidote/org/apache/tools/ant/gui/version.txt @@ -1,3 +1,6 @@ VERSION=@VERSION@ DATE=@DATE@ -CONTRIBUTORS=Simeon H.K. Fitch, Ant Development Team +CONTRIBUTORS=\ + Simeon H.K. Fitch, \ + Ant Development Team, \ + Icons Copyright © 1998 Dean S. Jones