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: not-yet-released
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
029 package org.jfree.beans;
030
031 import java.awt.Image;
032 import java.beans.BeanInfo;
033 import java.beans.IntrospectionException;
034 import java.beans.PropertyDescriptor;
035 import java.beans.SimpleBeanInfo;
036 import java.net.URL;
037 import java.util.List;
038 import java.util.ResourceBundle;
039
040 import javax.swing.ImageIcon;
041
042 /**
043 * Bean info for the {@link JBarChart} bean.
044 */
045 public class JBarChartBeanInfo 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 class.
053 *
054 * @return Additional bean info.
055 */
056 public BeanInfo[] getAdditionalBeanInfo() {
057 return new BeanInfo[] {new AbstractCategoryChartBeanInfo(),
058 new AbstractChartBeanInfo()};
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 = "JBarChart.";
070
071 // these regular properties are defined...
072 Object[][] props = new Object[][] {
073 {"dataset", Boolean.FALSE, "Category.Dataset"},
074 {"barOutlineVisible", Boolean.FALSE, "Category.BarRenderer"},
075 {"barItemMargin", Boolean.TRUE, "Category.BarRenderer"},
076 {"barBaseValue", Boolean.TRUE, "Category.BarRenderer"}
077 };
078
079 // create property descriptors for the regular properties...
080 List pds = new java.util.ArrayList();
081 for (int i = 0; i < props.length; i++) {
082 try {
083 String name = (String) props[i][0];
084 PropertyDescriptor pd = new PropertyDescriptor(name,
085 JBarChart.class);
086 Boolean expert = (Boolean) props[i][1];
087 pd.setExpert(expert.booleanValue());
088 String desc = localizationResources.getString(prefix + name);
089 pd.setShortDescription(desc);
090 pd.setValue("category", localizationResources.getString(
091 (String) props[i][2]));
092 pds.add(pd);
093 }
094 catch (IntrospectionException e) {
095 // swallow...
096 }
097 }
098
099 // create and return an array of all property descriptors...
100 PropertyDescriptor[] result = new PropertyDescriptor[pds.size()];
101 for (int i = 0; i < pds.size(); i++) {
102 result[i] = (PropertyDescriptor) pds.get(i);
103 }
104 return result;
105 }
106
107 /* (non-Javadoc)
108 * @see java.beans.SimpleBeanInfo#getIcon(int)
109 */
110 @Override
111 public Image getIcon(int iconKind) {
112 if (iconKind == BeanInfo.ICON_COLOR_16x16) {
113 URL imageURL = this.getClass().getClassLoader().getResource(
114 "org/jfree/beans/bar16.png");
115 if (imageURL != null) {
116 ImageIcon temp = new ImageIcon(imageURL);
117 // use ImageIcon because it waits for the image to load...
118 return temp.getImage();
119 }
120 else {
121 return super.getIcon(iconKind);
122 }
123 }
124 else {
125 return super.getIcon(iconKind);
126 }
127 }
128
129
130 }