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.beans.EventSetDescriptor;
032import java.beans.IntrospectionException;
033import java.beans.PropertyDescriptor;
034import java.beans.SimpleBeanInfo;
035import java.util.List;
036import java.util.ResourceBundle;
037
038import org.jfree.beans.events.LegendClickListener;
039
040/**
041 * A description of the {@link AbstractChart} bean.
042 */
043public class AbstractChartBeanInfo extends SimpleBeanInfo {
044
045    /** The resourceBundle for the localization. */
046    static ResourceBundle localizationResources = 
047            ResourceBundle.getBundle("org.jfree.beans.LocalizationBundle");
048
049    
050    /**
051     * Returns some property descriptors.
052     * 
053     * @return The property descriptors.
054     */
055    public PropertyDescriptor[] getPropertyDescriptors() {
056
057        // a prefix for the localised string keys
058        final String prefix = "AbstractChart.";
059        
060        // these regular properties are defined...
061        Object[][] props = new Object[][] { 
062            {"antiAlias", Boolean.FALSE, "Category.Miscellaneous"},
063            {"border", Boolean.FALSE, "Category.SWING"},
064            {"chartBackgroundPaint", Boolean.FALSE, "Category.Miscellaneous"},
065            {"chartBorderVisible", Boolean.FALSE, "Category.Miscellaneous"},
066            {"chartBorderPaint", Boolean.FALSE, "Category.Miscellaneous"},
067            {"plotOutlineVisible", Boolean.FALSE, "Category.Plot"},
068            {"plotBackgroundAlpha", Boolean.TRUE, "Category.Plot"},
069            {"plotBackgroundPaint", Boolean.FALSE, "Category.Plot"},
070            {"title", Boolean.FALSE, "Category.Titles"},
071            {"titleFont", Boolean.FALSE, "Category.Titles"},
072            {"titlePaint", Boolean.TRUE, "Category.Titles"},
073            {"legendPosition", Boolean.FALSE, "Category.Legend"},
074            {"legendItemFont", Boolean.FALSE, "Category.Legend"},
075            {"legendItemPaint", Boolean.TRUE, "Category.Legend"},
076            {"minimumSize", Boolean.FALSE, "Category.SWING"},
077            {"maximumSize", Boolean.FALSE, "Category.SWING"},
078            {"name", Boolean.FALSE, "Category.SWING"},
079            {"preferredSize", Boolean.FALSE, "Category.SWING"},
080            {"source", Boolean.FALSE, "Category.Titles"},
081            {"sourceFont", Boolean.FALSE, "Category.Titles"},
082            {"sourcePaint", Boolean.TRUE, "Category.Titles"},
083            {"subtitle", Boolean.FALSE, "Category.Titles"},
084            {"subtitleFont", Boolean.FALSE, "Category.Titles"},
085            {"subtitlePaint", Boolean.TRUE, "Category.Titles"}
086        };
087        
088        // create property descriptors for the regular properties...
089        List pds = new java.util.ArrayList();
090        for (int i = 0; i < props.length; i++) {
091            try {
092                String name = (String) props[i][0];
093                PropertyDescriptor pd = new PropertyDescriptor(name, 
094                        AbstractChart.class);
095                Boolean expert = (Boolean) props[i][1];
096                pd.setExpert(expert.booleanValue());
097                String desc = localizationResources.getString(prefix + name);
098                pd.setShortDescription(desc);
099                pd.setValue("category", localizationResources.getString(
100                        (String) props[i][2]));
101                pds.add(pd);
102            }
103            catch (IntrospectionException e) {
104                // swallow...
105            }
106        }
107
108        // create and return an array of all property descriptors...
109        PropertyDescriptor[] result = new PropertyDescriptor[pds.size()];
110        for (int i = 0; i < pds.size(); i++) {
111            result[i] = (PropertyDescriptor) pds.get(i);
112        }
113        return result;
114    }
115
116    /* (non-Javadoc)
117     * @see java.beans.SimpleBeanInfo#getEventSetDescriptors()
118     */
119    public EventSetDescriptor[] getEventSetDescriptors() {
120        EventSetDescriptor e1 = null;
121        try {
122            e1 = new EventSetDescriptor(AbstractChart.class, "legendClick", 
123                    LegendClickListener.class, "onLegendClick");
124            e1.setInDefaultEventSet(true);
125            e1.setExpert(false);
126            e1.setPreferred(false);
127        }
128        catch (IntrospectionException e) {
129            e.printStackTrace();
130            return super.getEventSetDescriptors();
131        }
132        return new EventSetDescriptor[] {e1};
133    }
134
135}