JXCollapsiblePaneBeanInfo.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:6k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: JXCollapsiblePaneBeanInfo.java,v 1.3 2005/10/10 18:01:49 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx;
  22. import java.awt.Image;
  23. import java.beans.BeanDescriptor;
  24. import java.beans.BeanInfo;
  25. import java.beans.IntrospectionException;
  26. import java.beans.Introspector;
  27. import java.beans.MethodDescriptor;
  28. import java.beans.PropertyDescriptor;
  29. import java.beans.SimpleBeanInfo;
  30. import java.lang.reflect.Method;
  31. import java.util.Vector;
  32. /**
  33.  * BeanInfo class for JXCollapsiblePane.
  34.  */
  35. public class JXCollapsiblePaneBeanInfo extends SimpleBeanInfo
  36. {
  37.    /** Description of the Field */
  38.    protected BeanDescriptor bd = new BeanDescriptor(JXCollapsiblePane.class);
  39.    /** Description of the Field */
  40.    protected Image iconMono16;
  41.    /** Description of the Field */
  42.    protected Image iconColor16;
  43.    /** Description of the Field */
  44.    protected Image iconMono32;
  45.    /** Description of the Field */
  46.    protected Image iconColor32;
  47.    /** Constructor for the JXCollapsiblePaneBeanInfo object */
  48.    public JXCollapsiblePaneBeanInfo() throws java.beans.IntrospectionException
  49.    {
  50.     // setup bean descriptor in constructor. 
  51.        bd.setName("JXCollapsiblePane");
  52.        bd.setShortDescription("A pane which hides its content with an animation.");
  53.        bd.setValue("isContainer",Boolean.TRUE);
  54.        bd.setValue("containerDelegate","getContentPane");
  55.        BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass());
  56.        String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder");
  57.        PropertyDescriptor[] pd = getPropertyDescriptors();
  58.        for (int i = 0; i != pd.length; i++)
  59.        {
  60.           if (order.indexOf(pd[i].getName()) == -1)
  61.           {
  62.              order = order + (order.length() == 0 ? "" : ":") + pd[i].getName();
  63.           }
  64.        }
  65.        getBeanDescriptor().setValue("propertyorder", order);
  66.    }
  67.    /**
  68.     * Gets the additionalBeanInfo
  69.     *
  70.     * @return   The additionalBeanInfo value
  71.     */
  72.    public BeanInfo[] getAdditionalBeanInfo()
  73.    {
  74.       Vector bi = new Vector();
  75.       BeanInfo[] biarr = null;
  76.       try
  77.       {
  78.          for (Class cl = JXCollapsiblePane.class.getSuperclass(); !cl.equals(java.awt.Component.class.getSuperclass()); cl = cl.getSuperclass()) {
  79.             bi.addElement(Introspector.getBeanInfo(cl));
  80.          }
  81.          biarr = new BeanInfo[bi.size()];
  82.          bi.copyInto(biarr);
  83.       }
  84.       catch (Exception e)
  85.       {
  86.          // Ignore it
  87.       }
  88.       return biarr;
  89.    }
  90.    /**
  91.     * Gets the beanDescriptor
  92.     *
  93.     * @return   The beanDescriptor value
  94.     */
  95.    public BeanDescriptor getBeanDescriptor()
  96.    {
  97.       return bd;
  98.    }
  99.    /**
  100.     * Gets the defaultPropertyIndex
  101.     *
  102.     * @return   The defaultPropertyIndex value
  103.     */
  104.    public int getDefaultPropertyIndex()
  105.    {
  106.       String defName = "";
  107.       if (defName.equals(""))
  108.       {
  109.          return -1;
  110.       }
  111.       PropertyDescriptor[] pd = getPropertyDescriptors();
  112.       for (int i = 0; i < pd.length; i++)
  113.       {
  114.          if (pd[i].getName().equals(defName))
  115.          {
  116.             return i;
  117.          }
  118.       }
  119.       return -1;
  120.    }
  121.    /**
  122.     * Gets the icon
  123.     *
  124.     * @param type  Description of the Parameter
  125.     * @return      The icon value
  126.     */
  127.    public Image getIcon(int type)
  128.    {
  129.       if (type == BeanInfo.ICON_COLOR_16x16)
  130.       {
  131.          return iconColor16;
  132.       }
  133.       if (type == BeanInfo.ICON_MONO_16x16)
  134.       {
  135.          return iconMono16;
  136.       }
  137.       if (type == BeanInfo.ICON_COLOR_32x32)
  138.       {
  139.          return iconColor32;
  140.       }
  141.       if (type == BeanInfo.ICON_MONO_32x32)
  142.       {
  143.          return iconMono32;
  144.       }
  145.       return null;
  146.    }
  147.    /**
  148.     * Gets the Property Descriptors
  149.     *
  150.     * @return   The propertyDescriptors value
  151.     */
  152.    public PropertyDescriptor[] getPropertyDescriptors() 
  153.    {
  154.       try
  155.       {
  156.          Vector descriptors = new Vector();
  157.          PropertyDescriptor descriptor = null;
  158.          try
  159.          {
  160.             descriptor = new PropertyDescriptor("animated", JXCollapsiblePane.class);
  161.          }
  162.          catch (IntrospectionException e)
  163.          {
  164.             descriptor = new PropertyDescriptor("animated", JXCollapsiblePane.class, "getAnimated", null);
  165.          }
  166.          descriptor.setPreferred(true);
  167.          descriptor.setBound(true);
  168.          descriptors.add(descriptor);
  169.          try
  170.          {
  171.             descriptor = new PropertyDescriptor("collapsed", JXCollapsiblePane.class);
  172.          }
  173.          catch (IntrospectionException e)
  174.          {
  175.             descriptor = new PropertyDescriptor("collapsed", JXCollapsiblePane.class, "getCollapsed", null);
  176.          }
  177.          descriptor.setPreferred(true);
  178.          descriptor.setBound(true);
  179.          descriptors.add(descriptor);
  180.          return (PropertyDescriptor[]) descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
  181.       }
  182.       catch (Exception e)
  183.       {
  184.         // Ignored
  185.       }
  186.       return null;
  187.    }
  188.    /**
  189.     * Gets the methodDescriptors attribute ...
  190.     *
  191.     * @return   The methodDescriptors value
  192.     */
  193.    public MethodDescriptor[] getMethodDescriptors() {
  194.       Vector descriptors = new Vector();
  195.       MethodDescriptor descriptor = null;
  196.       Method[] m;
  197.       Method method;
  198.       try {
  199.          m = Class.forName("org.jdesktop.swingx.JXCollapsiblePane").getMethods();
  200.       } catch (ClassNotFoundException e) {
  201.          return new MethodDescriptor[0];
  202.       }
  203.       return (MethodDescriptor[]) descriptors.toArray(new MethodDescriptor[descriptors.size()]);
  204.    }
  205. }