diff --git a/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java b/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java index 360d1d3a4..f954915de 100644 --- a/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java +++ b/src/antidote/org/apache/tools/ant/gui/AntTreeCellRenderer.java @@ -56,7 +56,10 @@ package org.apache.tools.ant.gui; import org.apache.tools.ant.gui.acs.ACSElement; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.JTree; +import javax.swing.ImageIcon; import java.awt.Component; +import java.awt.Image; +import java.beans.*; /** * Cell renderer for displaying the Ant XML file in a JTree. @@ -75,9 +78,23 @@ public class AntTreeCellRenderer extends DefaultTreeCellRenderer { boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - if(value instanceof ACSElement) { - setText(((ACSElement)value).getDisplayName()); + + try { + BeanInfo info = Introspector.getBeanInfo(value.getClass()); + Image icon = info.getIcon(BeanInfo.ICON_COLOR_16x16); + setIcon(new ImageIcon(icon)); + if(value instanceof ACSElement) { + setText(((ACSElement)value).getDisplayName()); + } + else { + setText(info.getBeanDescriptor().getDisplayName()); + } + } + catch(IntrospectionException ex) { + // XXX log me. + ex.printStackTrace(); } + return this; } } diff --git a/src/antidote/org/apache/tools/ant/gui/ResourceManager.java b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java index a066487af..9c5ea88bb 100644 --- a/src/antidote/org/apache/tools/ant/gui/ResourceManager.java +++ b/src/antidote/org/apache/tools/ant/gui/ResourceManager.java @@ -162,6 +162,18 @@ public class ResourceManager { return MessageFormat.format(format, arguments); } + /** + * Get the image as an ImageIcon assigned to the given class with the + * given key. + * + * @param clazz The class to load icon for. + * @param key The key for looking up the icon. + * @return Image as an ImageIcon, or null if not found. + */ + public ImageIcon getImageIcon(Class clazz, String key) { + return getImageIcon(getString(clazz, key)); + } + /** * Get the image as an ImageIcon with the given file name. * For example "open.gif". The image is loaded from the resources package. @@ -170,6 +182,8 @@ public class ResourceManager { * @return Image as an ImageIcon, or null if not found. */ public ImageIcon getImageIcon(String fileName) { + if(fileName == null) return null; + ImageIcon icon = null; URL location = getClass().getResource("resources/" + fileName); 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 10954ec95..2051fb81f 100644 --- a/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java +++ b/src/antidote/org/apache/tools/ant/gui/acs/BaseBeanInfo.java @@ -56,6 +56,8 @@ package org.apache.tools.ant.gui.acs; import org.apache.tools.ant.gui.ResourceManager; import org.apache.tools.ant.gui.customizer.DynamicCustomizer; import java.beans.*; +import javax.swing.ImageIcon; +import java.awt.Image; /** * Abstract base class for ACS BeanInfo classes. @@ -66,15 +68,22 @@ import java.beans.*; abstract class BaseBeanInfo extends SimpleBeanInfo { /** Property name for specifiying a sorting order. */ public static final String SORT_ORDER = DynamicCustomizer.SORT_ORDER; - /** Resource provider for bean info. */ private static ResourceManager _resources = new ResourceManager(); + /** Icon for this. */ + private Image _icon = null; + /** * Default ctor. * */ protected BaseBeanInfo() { + // Load the icon. + ImageIcon img = _resources.getImageIcon(getClass(), "icon"); + if(img != null) { + _icon = img.getImage(); + } } /** @@ -95,6 +104,17 @@ abstract class BaseBeanInfo extends SimpleBeanInfo { return new ACSBeanDescriptor(this); } + /** + * Get the icon for displaying this bean. + * + * @param kind Kind of icon. XXX currently ignored + * @return Image for bean, or null if none. + */ + public Image getIcon(int kind) { + // XXX kind is currently ignored. + return _icon; + } + /** * Set the sorting order property of the given objects based * on the order that they appear in the array. 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 4d08defc8..7240af0d1 100644 --- a/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties +++ b/src/antidote/org/apache/tools/ant/gui/resources/antidote.properties @@ -77,6 +77,7 @@ org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.depends=Dependencies org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.if=if Clause org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.unless=unless Clause org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.xmlString=XML Code +org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.icon=target.gif org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.beanName=Project org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.beanDescription=\ @@ -85,6 +86,7 @@ org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.name=Name org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.description=Description org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.basedir=Base Directory org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.default=Default Target +org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.icon=project.gif org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.beanName=Property org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.beanDescription=\ @@ -92,12 +94,14 @@ org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.beanDescription=\ org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.name=Name org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.value=Value org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.file=File +org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.icon=property.gif org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.beanName=Task org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.beanDescription=\ A scoped property org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.taskType=Type org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.xmlString=XML Code +org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.icon=task.gif diff --git a/src/antidote/org/apache/tools/ant/gui/resources/project.gif b/src/antidote/org/apache/tools/ant/gui/resources/project.gif new file mode 100644 index 000000000..3a2bed667 Binary files /dev/null and b/src/antidote/org/apache/tools/ant/gui/resources/project.gif differ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/property.gif b/src/antidote/org/apache/tools/ant/gui/resources/property.gif new file mode 100644 index 000000000..08058a84d Binary files /dev/null and b/src/antidote/org/apache/tools/ant/gui/resources/property.gif differ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/target.gif b/src/antidote/org/apache/tools/ant/gui/resources/target.gif new file mode 100644 index 000000000..3488dd3fe Binary files /dev/null and b/src/antidote/org/apache/tools/ant/gui/resources/target.gif differ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/task.gif b/src/antidote/org/apache/tools/ant/gui/resources/task.gif new file mode 100644 index 000000000..8c091865b Binary files /dev/null and b/src/antidote/org/apache/tools/ant/gui/resources/task.gif differ diff --git a/src/antidote/org/apache/tools/ant/gui/resources/unknown.gif b/src/antidote/org/apache/tools/ant/gui/resources/unknown.gif new file mode 100644 index 000000000..cd94e5f68 Binary files /dev/null and b/src/antidote/org/apache/tools/ant/gui/resources/unknown.gif differ