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 JTimeSeriesChart} bean. 044 */ 045 public class JTimeSeriesChartBeanInfo 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()}; 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 = "JTimeSeriesChart."; 070 071 // these regular properties are defined... 072 Object[][] props = new Object[][] { 073 {"dataset", Boolean.FALSE, "Category.Dataset"}, 074 {"shapesVisible", Boolean.FALSE, "Category.Renderer"} 075 }; 076 077 // create property descriptors for the regular properties... 078 List pds = new java.util.ArrayList(); 079 for (int i = 0; i < props.length; i++) { 080 try { 081 String name = (String) props[i][0]; 082 PropertyDescriptor pd = new PropertyDescriptor(name, 083 JTimeSeriesChart.class); 084 Boolean expert = (Boolean) props[i][1]; 085 pd.setExpert(expert.booleanValue()); 086 String desc = localizationResources.getString(prefix + name); 087 pd.setShortDescription(desc); 088 pd.setValue("category", localizationResources.getString( 089 (String) props[i][2])); 090 pds.add(pd); 091 } 092 catch (IntrospectionException e) { 093 // swallow... 094 } 095 } 096 097 // create and return an array of all property descriptors... 098 PropertyDescriptor[] result = new PropertyDescriptor[pds.size()]; 099 for (int i = 0; i < pds.size(); i++) { 100 result[i] = (PropertyDescriptor) pds.get(i); 101 } 102 return result; 103 } 104 105 /* (non-Javadoc) 106 * @see java.beans.SimpleBeanInfo#getIcon(int) 107 */ 108 @Override 109 public Image getIcon(int iconKind) { 110 if (iconKind == BeanInfo.ICON_COLOR_16x16) { 111 URL imageURL = this.getClass().getClassLoader().getResource( 112 "org/jfree/beans/time16.png"); 113 if (imageURL != null) { 114 ImageIcon temp = new ImageIcon(imageURL); 115 // use ImageIcon because it waits for the image to load... 116 return temp.getImage(); 117 } 118 else { 119 return super.getIcon(iconKind); 120 } 121 } 122 else { 123 return super.getIcon(iconKind); 124 } 125 } 126 127 }