001/* ======================================================
002 * Orson : a free chart beans library based on JFreeChart
003 * ======================================================
004 *
005 * (C) Copyright 2007, by Object Refinery Limited.
006 *
007 * Project Info:  http://www.jfree.org/orson/
008 *
009 * This library is free software; you can redistribute it and/or modify it 
010 * under the terms of the GNU Lesser General Public License as published by 
011 * the Free Software Foundation; either version 2.1 of the License, or 
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but 
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022 * USA.  
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 * 
027 */
028
029package org.jfree.beans;
030
031import java.awt.Image;
032import java.beans.BeanInfo;
033import java.beans.IntrospectionException;
034import java.beans.PropertyDescriptor;
035import java.beans.SimpleBeanInfo;
036import java.net.URL;
037import java.util.List;
038import java.util.ResourceBundle;
039
040import javax.swing.ImageIcon;
041
042/**
043 * Bean info for the {@link JAreaChart} bean.
044 */
045public class JAreaChartBeanInfo extends SimpleBeanInfo {
046
047    /** The resourceBundle for the localization. */
048    static ResourceBundle localizationResources = 
049            ResourceBundle.getBundle("org.jfree.beans.LocalizationBundle");
050    
051    /**
052     * Returns the bean info from the super classes.
053     * 
054     * @return Additional bean info.
055     */
056    public BeanInfo[] getAdditionalBeanInfo() {
057        return new BeanInfo[] {new AbstractChartBeanInfo(), 
058                new AbstractXYChartBeanInfo(), new NumericalXYChartBeanInfo()};    
059    }
060    
061    /**
062     * Returns some property descriptors.
063     * 
064     * @return The property descriptors.
065     */
066    public PropertyDescriptor[] getPropertyDescriptors() {
067
068        // a prefix for the localised string keys
069        final String prefix = "JAreaChart.";
070        
071        // these regular properties are defined...
072        Object[][] props = new Object[][] { 
073            {"dataset", Boolean.FALSE, "Category.Dataset"}
074        };
075
076        // create property descriptors for the regular properties...
077        List pds = new java.util.ArrayList();
078        for (int i = 0; i < props.length; i++) {
079            try {
080                String name = (String) props[i][0];
081                PropertyDescriptor pd = new PropertyDescriptor(name, 
082                        JAreaChart.class);
083                Boolean expert = (Boolean) props[i][1];
084                pd.setExpert(expert.booleanValue());
085                String desc = localizationResources.getString(prefix + name);
086                pd.setShortDescription(desc);
087                pd.setValue("category", localizationResources.getString(
088                        (String) props[i][2]));
089                pds.add(pd);
090            }
091            catch (IntrospectionException e) {
092                // swallow...
093            }
094        }
095        
096        // create and return an array of all property descriptors...
097        PropertyDescriptor[] result = new PropertyDescriptor[pds.size()];
098        for (int i = 0; i < pds.size(); i++) {
099            result[i] = (PropertyDescriptor) pds.get(i);
100        }
101        return result;
102    }
103
104    /* (non-Javadoc)
105     * @see java.beans.SimpleBeanInfo#getIcon(int)
106     */
107    @Override
108    public Image getIcon(int iconKind) {       
109        if (iconKind == BeanInfo.ICON_COLOR_16x16) {
110            URL imageURL = this.getClass().getClassLoader().getResource(
111                "org/jfree/beans/line16.png");
112            if (imageURL != null) {
113                ImageIcon temp = new ImageIcon(imageURL);  
114                // use ImageIcon because it waits for the image to load...
115                return temp.getImage();
116            }
117            else {
118                return super.getIcon(iconKind);
119            }
120        }
121        else {
122            return super.getIcon(iconKind);
123        }
124    }
125
126}