git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268198 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -56,7 +56,10 @@ package org.apache.tools.ant.gui; | |||||
| import org.apache.tools.ant.gui.acs.ACSElement; | import org.apache.tools.ant.gui.acs.ACSElement; | ||||
| import javax.swing.tree.DefaultTreeCellRenderer; | import javax.swing.tree.DefaultTreeCellRenderer; | ||||
| import javax.swing.JTree; | import javax.swing.JTree; | ||||
| import javax.swing.ImageIcon; | |||||
| import java.awt.Component; | import java.awt.Component; | ||||
| import java.awt.Image; | |||||
| import java.beans.*; | |||||
| /** | /** | ||||
| * Cell renderer for displaying the Ant XML file in a JTree. | * Cell renderer for displaying the Ant XML file in a JTree. | ||||
| @@ -75,9 +78,23 @@ public class AntTreeCellRenderer extends DefaultTreeCellRenderer { | |||||
| boolean hasFocus) { | boolean hasFocus) { | ||||
| super.getTreeCellRendererComponent(tree, value, sel, expanded, | super.getTreeCellRendererComponent(tree, value, sel, expanded, | ||||
| leaf, row, hasFocus); | 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; | return this; | ||||
| } | } | ||||
| } | } | ||||
| @@ -162,6 +162,18 @@ public class ResourceManager { | |||||
| return MessageFormat.format(format, arguments); | 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. | * Get the image as an ImageIcon with the given file name. | ||||
| * For example "open.gif". The image is loaded from the resources package. | * 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. | * @return Image as an ImageIcon, or null if not found. | ||||
| */ | */ | ||||
| public ImageIcon getImageIcon(String fileName) { | public ImageIcon getImageIcon(String fileName) { | ||||
| if(fileName == null) return null; | |||||
| ImageIcon icon = null; | ImageIcon icon = null; | ||||
| URL location = getClass().getResource("resources/" + fileName); | URL location = getClass().getResource("resources/" + fileName); | ||||
| @@ -56,6 +56,8 @@ package org.apache.tools.ant.gui.acs; | |||||
| import org.apache.tools.ant.gui.ResourceManager; | import org.apache.tools.ant.gui.ResourceManager; | ||||
| import org.apache.tools.ant.gui.customizer.DynamicCustomizer; | import org.apache.tools.ant.gui.customizer.DynamicCustomizer; | ||||
| import java.beans.*; | import java.beans.*; | ||||
| import javax.swing.ImageIcon; | |||||
| import java.awt.Image; | |||||
| /** | /** | ||||
| * Abstract base class for ACS BeanInfo classes. | * Abstract base class for ACS BeanInfo classes. | ||||
| @@ -66,15 +68,22 @@ import java.beans.*; | |||||
| abstract class BaseBeanInfo extends SimpleBeanInfo { | abstract class BaseBeanInfo extends SimpleBeanInfo { | ||||
| /** Property name for specifiying a sorting order. */ | /** Property name for specifiying a sorting order. */ | ||||
| public static final String SORT_ORDER = DynamicCustomizer.SORT_ORDER; | public static final String SORT_ORDER = DynamicCustomizer.SORT_ORDER; | ||||
| /** Resource provider for bean info. */ | /** Resource provider for bean info. */ | ||||
| private static ResourceManager _resources = new ResourceManager(); | private static ResourceManager _resources = new ResourceManager(); | ||||
| /** Icon for this. */ | |||||
| private Image _icon = null; | |||||
| /** | /** | ||||
| * Default ctor. | * Default ctor. | ||||
| * | * | ||||
| */ | */ | ||||
| protected BaseBeanInfo() { | 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); | 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 | * Set the sorting order property of the given objects based | ||||
| * on the order that they appear in the array. | * on the order that they appear in the array. | ||||
| @@ -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.if=if Clause | ||||
| org.apache.tools.ant.gui.acs.ACSTargetElementBeanInfo.unless=unless 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.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.beanName=Project | ||||
| org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.beanDescription=\ | 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.description=Description | ||||
| org.apache.tools.ant.gui.acs.ACSProjectElementBeanInfo.basedir=Base Directory | 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.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.beanName=Property | ||||
| org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.beanDescription=\ | 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.name=Name | ||||
| org.apache.tools.ant.gui.acs.ACSPropertyElementBeanInfo.value=Value | 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.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.beanName=Task | ||||
| org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.beanDescription=\ | org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.beanDescription=\ | ||||
| A scoped property | A scoped property | ||||
| org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.taskType=Type | 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.xmlString=XML Code | ||||
| org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.icon=task.gif | |||||