From 0c852dba516bf705d62a2d53c47a7b1b1cdd5048 Mon Sep 17 00:00:00 2001 From: metasim Date: Thu, 16 Nov 2000 22:38:43 +0000 Subject: [PATCH] Changed mechanism by which the PropertyEditor editor is instantiated so that it uses whatever class is retured by BeanDescriptor.getCustomizerClass() rather than assuming DynamicCustomizer. This will allow BeanSpecific customizers to be used in leu of the DynamicCustomizer. Also finally figured out the IllegalAccessException problem with calling the NodeList methods in the ACSTreeNodeElement classes, which turned out only to happen when jikes was used for compiling. Implemented a work around. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268199 13f79535-47bb-0310-9956-ffa450edef68 --- src/antidote/ChangeLog | 10 ++++ src/antidote/README | 3 +- .../org/apache/tools/ant/gui/Main.java | 9 ---- .../apache/tools/ant/gui/PropertyEditor.java | 22 +++++--- .../tools/ant/gui/acs/ACSBeanDescriptor.java | 3 +- .../gui/acs/ACSProjectElementBeanInfo.java | 16 ++++++ .../tools/ant/gui/acs/ACSPropertyElement.java | 4 +- .../gui/acs/ACSPropertyElementBeanInfo.java | 16 ++++++ .../ant/gui/acs/ACSTargetElementBeanInfo.java | 17 +++++++ .../ant/gui/acs/ACSTaskElementBeanInfo.java | 16 ++++++ .../tools/ant/gui/acs/ACSTreeNodeElement.java | 18 +++++-- .../tools/ant/gui/acs/BaseBeanInfo.java | 7 +++ .../ant/gui/customizer/DynamicCustomizer.java | 50 +++++++++++++++++-- 13 files changed, 164 insertions(+), 27 deletions(-) diff --git a/src/antidote/ChangeLog b/src/antidote/ChangeLog index 0385f5308..38a2d6121 100644 --- a/src/antidote/ChangeLog +++ b/src/antidote/ChangeLog @@ -1,5 +1,15 @@ 2000-11-16 Simeon H.K. Fitch + * org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java: Fixed + nasty java.lang.IllegalAccessException bug that I thought was + related to Java 1.3 Blackdown RC1, but wasn't. It was related to + using Jikes, which interprests method resolution differently than + javac, resulting in a call trying to access a private method + implementation of a public interface. + + * org/apache/tools/ant/gui/ResourceManager.java: Added convenience + method for getting resource images for a given class. + * org/apache/tools/ant/gui/AntAction.java: Added toggle property. * org/apache/tools/ant/gui/ActionManager.java: Added ability to diff --git a/src/antidote/README b/src/antidote/README index 79816540d..a7597365a 100644 --- a/src/antidote/README +++ b/src/antidote/README @@ -48,8 +48,7 @@ Running ------- - Antidote requires at least Java 1.2 to run. It will *not* work with JVM - version Blackdown-1.3.0-RC1, but Blackdown-1.3.0-FCS does work. So upgrade. + Antidote requires at least Java 1.2 to run. Upon successful building of Ant and Antidote (in that order), go to ~/build/ant/bin and run "antidote". You will probably have to set the diff --git a/src/antidote/org/apache/tools/ant/gui/Main.java b/src/antidote/org/apache/tools/ant/gui/Main.java index 7c619e07f..adfb2cac4 100644 --- a/src/antidote/org/apache/tools/ant/gui/Main.java +++ b/src/antidote/org/apache/tools/ant/gui/Main.java @@ -72,15 +72,6 @@ public class Main { public static void main(String[] args) { XMLHelper.init(); - String vmVersion = System.getProperty("java.vm.vendor"); - if(vmVersion.indexOf("Blackdown") > 0 && - vmVersion.indexOf("RC") > 0) { - System.err.println( - "Warning: Antidote will not work with VM version " + - "Blackdown-1.3.0-RC1."); - System.err.println("Your version: " + vmVersion); - } - try { JFrame f = new JFrame("Antidote"); AppContext context = new AppContext(f); diff --git a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java index ac4790e17..6329ffa78 100644 --- a/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java +++ b/src/antidote/org/apache/tools/ant/gui/PropertyEditor.java @@ -58,9 +58,11 @@ import org.apache.tools.ant.gui.acs.*; import org.apache.tools.ant.gui.event.*; import javax.swing.*; import java.util.*; +import java.beans.*; import java.io.StringReader; import java.io.IOException; import java.awt.BorderLayout; +import java.awt.Component; /** * Stub for a property editor. @@ -70,8 +72,8 @@ import java.awt.BorderLayout; */ class PropertyEditor extends AntEditor { - /** The property sheet. */ - private DynamicCustomizer _customizer = null; + /** The editor for current bean.*/ + private Customizer _customizer = null; /** Container for the customizer. */ private JPanel _container = null; @@ -95,14 +97,22 @@ class PropertyEditor extends AntEditor { */ private void updateDisplay(ACSElement[] items) { if(_customizer != null) { - _container.remove(_customizer); + _container.remove((Component)_customizer); _customizer = null; } if(items != null && items.length == 1) { - _customizer = new DynamicCustomizer(items[0].getClass()); - _customizer.setObject(items[0]); - _container.add(BorderLayout.CENTER, _customizer); + try { + BeanInfo info = Introspector.getBeanInfo(items[0].getClass()); + _customizer = (Customizer) info.getBeanDescriptor(). + getCustomizerClass().newInstance(); + _customizer.setObject(items[0]); + _container.add(BorderLayout.CENTER, (Component) _customizer); + } + catch(Exception ex) { + // XXX log me. + ex.printStackTrace(); + } } validate(); diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java index fbd1dc116..28710388f 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSBeanDescriptor.java @@ -63,9 +63,8 @@ import java.beans.*; * @author Simeon Fitch */ class ACSBeanDescriptor extends BeanDescriptor { - public ACSBeanDescriptor(BaseBeanInfo type) { - super(type.getType()); + super(type.getType(), type.getCustomizerType()); setDisplayName( type.getResources().getString(type.getClass(), "beanName")); setShortDescription( diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java index 95b38cf5f..7445f0ca4 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElementBeanInfo.java @@ -53,6 +53,7 @@ */ package org.apache.tools.ant.gui.acs; +import org.apache.tools.ant.gui.customizer.DynamicCustomizer; import java.beans.*; /** @@ -78,6 +79,15 @@ public class ACSProjectElementBeanInfo extends BaseBeanInfo { return ACSProjectElement.class; } + /** + * Get the customizer type. + * + * @return Customizer type. + */ + public Class getCustomizerType() { + return Customizer.class; + } + /** * Get the property descriptors. * @@ -117,4 +127,10 @@ public class ACSProjectElementBeanInfo extends BaseBeanInfo { return retval; } + /** Customizer for this bean info. */ + public static class Customizer extends DynamicCustomizer { + public Customizer() { + super(ACSProjectElement.class); + } + } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElement.java index d3c92a78c..7647f9b5b 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElement.java @@ -85,10 +85,10 @@ public class ACSPropertyElement extends ACSTreeNodeElement { String file = getFile(); if(file == null || file.trim().length() == 0) { - return "Property: " + getName(); + return "property: " + getName(); } else { - return "Property File: " + file; + return "property file: " + file; } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElementBeanInfo.java index 97fe45a59..89199238c 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElementBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSPropertyElementBeanInfo.java @@ -53,6 +53,7 @@ */ package org.apache.tools.ant.gui.acs; +import org.apache.tools.ant.gui.customizer.DynamicCustomizer; import java.beans.*; /** @@ -78,6 +79,15 @@ public class ACSPropertyElementBeanInfo extends BaseBeanInfo { return ACSPropertyElement.class; } + /** + * Get the customizer type. + * + * @return Customizer type. + */ + public Class getCustomizerType() { + return Customizer.class; + } + /** * Get the property descriptors. * @@ -113,4 +123,10 @@ public class ACSPropertyElementBeanInfo extends BaseBeanInfo { return retval; } + /** Customizer for this bean info. */ + public static class Customizer extends DynamicCustomizer { + public Customizer() { + super(ACSPropertyElement.class); + } + } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java index 92b2a70c9..c952db525 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTargetElementBeanInfo.java @@ -52,6 +52,7 @@ * . */ package org.apache.tools.ant.gui.acs; +import org.apache.tools.ant.gui.customizer.DynamicCustomizer; import java.beans.*; @@ -78,6 +79,15 @@ public class ACSTargetElementBeanInfo extends BaseBeanInfo { return ACSTargetElement.class; } + /** + * Get the customizer type. + * + * @return Customizer type. + */ + public Class getCustomizerType() { + return Customizer.class; + } + /** * Get the property descriptors. * @@ -127,4 +137,11 @@ public class ACSTargetElementBeanInfo extends BaseBeanInfo { return retval; } + + /** Customizer for this bean info. */ + public static class Customizer extends DynamicCustomizer { + public Customizer() { + super(ACSTargetElement.class); + } + } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java index a48338c7b..2edc606ca 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTaskElementBeanInfo.java @@ -53,6 +53,7 @@ */ package org.apache.tools.ant.gui.acs; +import org.apache.tools.ant.gui.customizer.DynamicCustomizer; import java.beans.*; /** @@ -78,6 +79,15 @@ public class ACSTaskElementBeanInfo extends BaseBeanInfo { return ACSTaskElement.class; } + /** + * Get the customizer type. + * + * @return Customizer type. + */ + public Class getCustomizerType() { + return Customizer.class; + } + /** * Get the property descriptors. * @@ -111,4 +121,10 @@ public class ACSTaskElementBeanInfo extends BaseBeanInfo { return retval; } + /** Customizer for this bean info. */ + public static class Customizer extends DynamicCustomizer { + public Customizer() { + super(ACSTaskElement.class); + } + } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java index e0f887a4a..d3387d91e 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/ACSTreeNodeElement.java @@ -55,6 +55,7 @@ package org.apache.tools.ant.gui.acs; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import com.sun.xml.tree.ElementNode; import javax.swing.tree.TreeNode; import java.util.*; @@ -80,9 +81,20 @@ public abstract class ACSTreeNodeElement extends ACSElement if(_treeNodeCache == null) { _treeNodeCache = new ArrayList(); - for(int i = 0; i < getLength(); i++) { - if(item(i) instanceof TreeNode) { - _treeNodeCache.add(item(i)); + // XXX this crazy casting is to get around an + // inconsistency between jikes and javac whereby + // the call without this cast when compiled with + // jikes causes an IllegalAccessException + // because the implementation of getLength() and + // item() are actually in a package only class + // in the Sun implementation classes. + int len = ((NodeList)this).getLength(); + + for(int i = 0; i < len; i++) { + Object n = ((NodeList)this).item(i); + + if(n instanceof TreeNode) { + _treeNodeCache.add(n); } } } diff --git a/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java b/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java index 2051fb81f..9d75c7daa 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java @@ -134,6 +134,13 @@ abstract class BaseBeanInfo extends SimpleBeanInfo { */ public abstract Class getType(); + /** + * Get the type of the customizer to use. + * + * @return Customizer to use. + */ + public abstract Class getCustomizerType(); + /** * Gets the beans PropertyDescriptors. * diff --git a/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java index e763caa75..ed78d2f97 100644 --- a/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java +++ b/src/antidote/org/apache/tools/ant/gui/customizer/DynamicCustomizer.java @@ -69,7 +69,7 @@ import java.awt.Component; * @version $Revision$ * @author Simeon Fitch */ -public class DynamicCustomizer extends JPanel { +public class DynamicCustomizer extends JPanel implements Customizer { static { PropertyEditorManager.registerEditor( String.class, StringPropertyEditor.class); @@ -102,6 +102,9 @@ public class DynamicCustomizer extends JPanel { private EditorChangeListener _eListener = new EditorChangeListener(); /** Read-only flag. */ private boolean _readOnly = false; + /** List of property change listeners interested when the bean + * being edited has been changed. */ + private List _changeListeners = new LinkedList(); /** @@ -259,6 +262,47 @@ public class DynamicCustomizer extends JPanel { return retval; } + /** + * Add the given listener. Will receive a change event for + * changes to the bean being edited. + * + * @param l Listner to add. + */ + public void addPropertyChangeListener(PropertyChangeListener l) { + _changeListeners.add(l); + } + + + /** + * Remove the given property change listener. + * + * @param l Listener to remove. + */ + public void removePropertyChangeListener(PropertyChangeListener l) { + _changeListeners.remove(l); + } + + /** + * Fire a property change event to each listener. + * + * @param bean Bean being edited. + * @param propName Name of the property. + * @param oldValue Old value. + * @param newValue New value. + */ + protected void firePropertyChange(Object bean, String propName, + Object oldValue, Object newValue) { + + PropertyChangeEvent e = new PropertyChangeEvent( + bean, propName, oldValue, newValue); + + Iterator it = _changeListeners.iterator(); + while(it.hasNext()) { + PropertyChangeListener l = (PropertyChangeListener) it.next(); + l.propertyChange(e); + } + } + /** Class for receiving change events from the PropertyEditor objects. */ private class EditorChangeListener implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { @@ -271,8 +315,8 @@ public class DynamicCustomizer extends JPanel { Object[] params = { editor.getValue() }; writer.invoke(_value, params); setObject(_value); - //firePropertyChange( - //prop.getName(), null, editor.getValue()); + firePropertyChange( + _value, prop.getName(), null, editor.getValue()); } catch(IllegalAccessException ex) { ex.printStackTrace();