001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.components.image;
031:
032: import java.awt.Image;
033: import java.beans.BeanDescriptor;
034: import java.beans.BeanInfo;
035: import java.beans.EventSetDescriptor;
036: import java.beans.Introspector;
037: import java.beans.MethodDescriptor;
038: import java.beans.PropertyDescriptor;
039: import java.util.ArrayList;
040:
041: import javax.swing.JComponent;
042:
043: /**
044: * Defines the BeanInfo for ImageComponent.
045: *
046: * @author Jeff Tassin
047: */
048: public class ImageComponentBeanInfo implements BeanInfo {
049: private PropertyDescriptor[] m_props = null;
050:
051: /**
052: * ctor
053: */
054: public ImageComponentBeanInfo() {
055: try {
056: ArrayList props = new ArrayList();
057: BeanInfo info = Introspector.getBeanInfo(JComponent.class);
058: PropertyDescriptor[] pds = info.getPropertyDescriptors();
059: for (int index = 0; index < pds.length; index++) {
060: PropertyDescriptor pd = pds[index];
061: if ("font".equals(pd.getName()))
062: pd.setPreferred(false);
063:
064: props.add(pd);
065: }
066:
067: PropertyDescriptor icondef = new PropertyDescriptor("icon",
068: ImageComponent.class, "getIcon", "setIcon");
069: PropertyDescriptor halign = new PropertyDescriptor(
070: "horizontalAlignment", ImageComponent.class,
071: "getHorizontalAlignment", "setHorizontalAlignment");
072: PropertyDescriptor valign = new PropertyDescriptor(
073: "verticalAlignment", ImageComponent.class,
074: "getVerticalAlignment", "setVerticalAlignment");
075:
076: icondef.setPreferred(true);
077: halign.setPreferred(true);
078: valign.setPreferred(true);
079: props.add(icondef);
080: props.add(halign);
081: props.add(valign);
082: m_props = (PropertyDescriptor[]) props
083: .toArray(new PropertyDescriptor[0]);
084: } catch (Exception e) {
085: m_props = new PropertyDescriptor[0];
086: e.printStackTrace();
087: }
088: }
089:
090: public BeanInfo[] getAdditionalBeanInfo() {
091: return new BeanInfo[0];
092: }
093:
094: public BeanDescriptor getBeanDescriptor() {
095: return new BeanDescriptor(ImageComponent.class);
096: }
097:
098: public int getDefaultEventIndex() {
099: return 0;
100: }
101:
102: public int getDefaultPropertyIndex() {
103: return 0;
104: }
105:
106: public EventSetDescriptor[] getEventSetDescriptors() {
107: return new EventSetDescriptor[0];
108: }
109:
110: public Image getIcon(int i) {
111: return null;
112: }
113:
114: public MethodDescriptor[] getMethodDescriptors() {
115: return new MethodDescriptor[0];
116: }
117:
118: /**
119: * @return a collection of JETAPropertyDescriptor objects
120: */
121: public PropertyDescriptor[] getPropertyDescriptors() {
122: return m_props;
123: }
124:
125: }
|