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-ffa450edef68master
@@ -1,5 +1,15 @@ | |||
2000-11-16 Simeon H.K. Fitch <simeon@fitch.net> | |||
* 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 | |||
@@ -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 | |||
@@ -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); | |||
@@ -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(); | |||
@@ -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( | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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; | |||
} | |||
} | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -52,6 +52,7 @@ | |||
* <http://www.apache.org/>. | |||
*/ | |||
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); | |||
} | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
} | |||
@@ -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 <code>PropertyDescriptor</code>s. | |||
* | |||
@@ -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(); | |||