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.gui.form;
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.JPanel;
042:
043: /**
044: * Defines the BeanInfo for a GridView. When the user selects a form in the
045: * designer, the properties pane shows several properties for that form. Forms
046: * use GridViews as their underlying Java bean component. So, the designer is
047: * really updating properties for a GridView object. The allows the user to set
048: * standard properties such as border and background color for forms. A custom
049: * BeanInfo is provided instead of the standard JPanel BeanInfo because we don't
050: * want nor need all of the JPanel properties.
051: *
052: * @author Jeff Tassin
053: */
054: public class GridViewBeanInfo implements BeanInfo {
055: private PropertyDescriptor[] m_props = new PropertyDescriptor[0];
056:
057: /**
058: * ctor
059: */
060: public GridViewBeanInfo() {
061: try {
062: ArrayList props = new ArrayList();
063:
064: /** we don't need every property from JPanel, just name and opaque */
065: BeanInfo info = Introspector.getBeanInfo(JPanel.class);
066: PropertyDescriptor[] pds = info.getPropertyDescriptors();
067: for (int index = 0; index < pds.length; index++) {
068: PropertyDescriptor pd = pds[index];
069: if ("name".equals(pd.getName()))
070: props.add(pd);
071:
072: if ("opaque".equals(pd.getName())) {
073: props.add(pd);
074: }
075: }
076:
077: m_props = (PropertyDescriptor[]) props
078: .toArray(new PropertyDescriptor[0]);
079: } catch (Exception e) {
080: e.printStackTrace();
081: }
082: }
083:
084: public BeanInfo[] getAdditionalBeanInfo() {
085: return new BeanInfo[0];
086: }
087:
088: public BeanDescriptor getBeanDescriptor() {
089: return null;
090: }
091:
092: public int getDefaultEventIndex() {
093: return 0;
094: }
095:
096: public int getDefaultPropertyIndex() {
097: return 0;
098: }
099:
100: public EventSetDescriptor[] getEventSetDescriptors() {
101: return new EventSetDescriptor[0];
102: }
103:
104: public Image getIcon(int i) {
105: return null;
106: }
107:
108: public MethodDescriptor[] getMethodDescriptors() {
109: return new MethodDescriptor[0];
110: }
111:
112: /**
113: * @return a collection of JETAPropertyDescriptor objects
114: */
115: public PropertyDescriptor[] getPropertyDescriptors() {
116: return m_props;
117: }
118:
119: }
|