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.EventSetDescriptor;
034 import java.beans.IndexedPropertyDescriptor;
035 import java.beans.IntrospectionException;
036 import java.beans.PropertyDescriptor;
037 import java.beans.SimpleBeanInfo;
038 import java.net.URL;
039 import java.util.List;
040 import java.util.ResourceBundle;
041
042 import javax.swing.ImageIcon;
043
044 import org.jfree.beans.events.SectionClickListener;
045
046 /**
047 * Bean info for the {@link JPieChart} bean.
048 */
049 public class JPieChartBeanInfo extends SimpleBeanInfo {
050
051 /** The resourceBundle for the localization. */
052 static ResourceBundle localizationResources =
053 ResourceBundle.getBundle("org.jfree.beans.LocalizationBundle");
054
055 /**
056 * Returns the bean info from the super class.
057 *
058 * @return Additional bean info.
059 */
060 public BeanInfo[] getAdditionalBeanInfo() {
061 return new BeanInfo[] {new AbstractChartBeanInfo()};
062 }
063
064 /**
065 * Returns some property descriptors.
066 *
067 * @return The property descriptors.
068 */
069 public PropertyDescriptor[] getPropertyDescriptors() {
070
071 // a prefix for the localised string keys
072 final String prefix = "JPieChart.";
073
074 // these regular properties are defined...
075 Object[][] props = new Object[][] {
076 {"dataset", Boolean.FALSE, "Category.Dataset"},
077 {"circular", Boolean.FALSE, "Category.Plot"},
078 {"direction", Boolean.FALSE, "Category.Plot"},
079 {"startingAngle", Boolean.FALSE, "Category.Plot"},
080 {"labelFormat", Boolean.FALSE, "Category.Sections"},
081 {"labelFont", Boolean.FALSE, "Category.Sections"},
082 {"labelPaint", Boolean.FALSE, "Category.Sections"},
083 {"sectionToolTipFormat", Boolean.FALSE, "Category.ToolTips"}
084 };
085
086 // and these indexed properties...
087 Object[][] indexedProps = new Object[][] {
088 {"sectionPaint", Boolean.FALSE}
089 };
090
091 // create property descriptors for the regular properties...
092 List pds = new java.util.ArrayList();
093 for (int i = 0; i < props.length; i++) {
094 try {
095 String name = (String) props[i][0];
096 PropertyDescriptor pd = new PropertyDescriptor(name,
097 JPieChart.class);
098 Boolean expert = (Boolean) props[i][1];
099 pd.setExpert(expert.booleanValue());
100 String desc = localizationResources.getString(prefix + name);
101 pd.setValue("category", localizationResources.getString(
102 (String) props[i][2]));
103 pd.setShortDescription(desc);
104 pds.add(pd);
105 }
106 catch (IntrospectionException e) {
107 // swallow...
108 }
109 }
110
111 // create property descriptors for the indexed properties...
112 for (int i = 0; i < indexedProps.length; i++) {
113 try {
114 String name = (String) props[i][0];
115 PropertyDescriptor pd = new IndexedPropertyDescriptor(name,
116 JPieChart.class);
117 Boolean expert = (Boolean) props[i][1];
118 pd.setExpert(expert.booleanValue());
119 String desc = localizationResources.getString(prefix + name);
120 pd.setShortDescription(desc);
121 pds.add(pd);
122
123 }
124 catch (IntrospectionException e) {
125 // swallow...
126 }
127 }
128
129 // create and return an array of all property descriptors...
130 PropertyDescriptor[] result = new PropertyDescriptor[pds.size()];
131 for (int i = 0; i < pds.size(); i++) {
132 result[i] = (PropertyDescriptor) pds.get(i);
133 }
134 return result;
135 }
136
137 /* (non-Javadoc)
138 * @see java.beans.SimpleBeanInfo#getEventSetDescriptors()
139 */
140 public EventSetDescriptor[] getEventSetDescriptors() {
141 EventSetDescriptor e1 = null;
142 try {
143 e1 = new EventSetDescriptor(JPieChart.class, "sectionClick",
144 SectionClickListener.class, "onSectionClick");
145 e1.setInDefaultEventSet(true);
146 e1.setExpert(false);
147 e1.setPreferred(true);
148 }
149 catch (IntrospectionException e) {
150 e.printStackTrace();
151 return super.getEventSetDescriptors();
152 }
153 return new EventSetDescriptor[] {e1};
154 }
155
156 /* (non-Javadoc)
157 * @see java.beans.SimpleBeanInfo#getIcon(int)
158 */
159 @Override
160 public Image getIcon(int iconKind) {
161 if (iconKind == BeanInfo.ICON_COLOR_16x16) {
162 URL imageURL = this.getClass().getClassLoader().getResource(
163 "org/jfree/beans/pie16.png");
164 if (imageURL != null) {
165 ImageIcon temp = new ImageIcon(imageURL);
166 // use ImageIcon because it waits for the image to load...
167 return temp.getImage();
168 }
169 else {
170 return super.getIcon(iconKind);
171 }
172 }
173 else {
174 return super.getIcon(iconKind);
175 }
176 }
177
178 }