home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / Source.bin / CalendarBeanInfo.java < prev    next >
Text File  |  1998-03-18  |  6KB  |  193 lines

  1. package symantec.itools.awt.util;
  2.  
  3. import java.beans.*;
  4. import symantec.itools.beans.*;
  5. import java.util.ResourceBundle;
  6.  
  7. /**
  8.  * BeanInfo for Calendar.
  9.  *
  10.  */
  11.  
  12. public class CalendarBeanInfo extends SimpleBeanInfo {
  13.  
  14.     /**
  15.      * Constructs a CalendarBeanInfo object.
  16.      */
  17.     public CalendarBeanInfo() {
  18.     }
  19.  
  20.     /**
  21.      * Gets a BeanInfo for the superclass of this bean.
  22.      * @return BeanInfo[] containing this bean's superclass BeanInfo
  23.      */
  24.     public BeanInfo[] getAdditionalBeanInfo() {
  25.         try {
  26.             BeanInfo[] bi = new BeanInfo[1];
  27.             bi[0] = Introspector.getBeanInfo(beanClass.getSuperclass());
  28.             return bi;
  29.         }
  30.         catch (IntrospectionException e) { throw new Error(e.toString());}
  31.     }
  32.  
  33.     /**
  34.      * Gets the SymantecBeanDescriptor for this bean.
  35.      * @return an object of type SymantecBeanDescriptor
  36.      * @see symantec.itools.beans.SymantecBeanDescriptor
  37.      */
  38.     public BeanDescriptor getBeanDescriptor() {
  39.         ResourceBundle group = ResourceBundle.getBundle("symantec.itools.resources.GroupBundle");
  40.         String s=group.getString("GroupUtility"); 
  41.  
  42.         SymantecBeanDescriptor bd = new SymantecBeanDescriptor(beanClass);
  43.         bd.setCanAddChild(false);
  44.         bd.setWinHelp("0x1238C");
  45.         bd.setFolder(s);
  46.         bd.setToolbar(s);
  47.  
  48.         return (BeanDescriptor) bd;
  49.     }
  50.  
  51.     /**
  52.      * Gets an image that may be used to visually represent this bean
  53.      * (in the toolbar, on a form, etc).
  54.      * @param iconKind the type of icon desired, one of: BeanInfo.ICON_MONO_16x16,
  55.      * BeanInfo.ICON_COLOR_16x16, BeanInfo.ICON_MONO_32x32, or BeanInfo.ICON_COLOR_32x32.
  56.      * @return an image for this bean, always color even if requested monochrome
  57.      * @see BeanInfo#ICON_MONO_16x16
  58.      * @see BeanInfo#ICON_COLOR_16x16
  59.      * @see BeanInfo#ICON_MONO_32x32
  60.      * @see BeanInfo#ICON_COLOR_32x32
  61.      */
  62.     public java.awt.Image getIcon(int iconKind) {
  63.         if (iconKind == BeanInfo.ICON_MONO_16x16 ||
  64.             iconKind == BeanInfo.ICON_COLOR_16x16) {
  65.             java.awt.Image img = loadImage("CalendarC16.gif");
  66.             return img;
  67.         }
  68.  
  69.         if (iconKind == BeanInfo.ICON_MONO_32x32 ||
  70.             iconKind == BeanInfo.ICON_COLOR_32x32) {
  71.             java.awt.Image img = loadImage("CalendarC32.gif");
  72.             return img;
  73.         }
  74.  
  75.         return null;
  76.     }
  77.  
  78.     /**
  79.      * Gets an array of descriptions of the methods used for "connections" by
  80.      * Visual CafΘ's Interaction Wizard.
  81.      * Included in each method description is a CONNECTIONS ConnectionDescriptor.
  82.      * @return method descriptions for this bean
  83.      * @see symantec.itools.beans.ConnectionDescriptor#CONNECTIONS
  84.      */
  85.     public MethodDescriptor[] getMethodDescriptors() {
  86.         Class[] args;
  87.         ConnectionDescriptor connection;
  88.         java.util.Vector connections;
  89.         java.util.Vector md = new java.util.Vector();
  90.         ResourceBundle conn = ResourceBundle.getBundle("symantec.itools.resources.ConnBundle");
  91.  
  92.         try{
  93.             args = new Class[1];
  94.             args[0] = java.lang.String.class ;
  95.             MethodDescriptor setDate = new MethodDescriptor(beanClass.getMethod("setDate", args));
  96.  
  97.             connections = new java.util.Vector();
  98.             connection = new ConnectionDescriptor("input", "String", "",
  99.                                     "%name%.setDate(%arg%);",
  100.                                     conn.getString("setDate"));
  101.             connections.addElement(connection);
  102.  
  103.             setDate.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  104.             md.addElement(setDate);
  105.         } catch (Exception e) { throw new Error("setDate:: " + e.toString()); }
  106.  
  107.         try{
  108.             args = null;
  109.             MethodDescriptor getSelectedColor = new MethodDescriptor(beanClass.getMethod("getSelectedColor", args));
  110.  
  111.             connections = new java.util.Vector();
  112.             connection = new ConnectionDescriptor("output", "Color", "",
  113.                                     "%name%.getSelectedColor()",
  114.                                     conn.getString("getSelectedColor"));
  115.             connections.addElement(connection);
  116.  
  117.             getSelectedColor.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  118.             md.addElement(getSelectedColor);
  119.         } catch (Exception e) { throw new Error("getSelectedColor:: " + e.toString()); }
  120.  
  121.         try{
  122.             args = new Class[1];
  123.             args[0] = java.awt.Color.class ;
  124.             MethodDescriptor setSelectedColor = new MethodDescriptor(beanClass.getMethod("setSelectedColor", args));
  125.  
  126.             connections = new java.util.Vector();
  127.             connection = new ConnectionDescriptor("input", "Color", "",
  128.                                     "%name%.setSelectedColor(%arg%);",
  129.                                     conn.getString("setSelectedColor"));
  130.             connections.addElement(connection);
  131.  
  132.             setSelectedColor.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  133.             md.addElement(setSelectedColor);
  134.         } catch (Exception e) { throw new Error("setSelectedColor:: " + e.toString()); }
  135.  
  136.         try{
  137.             args = null;
  138.             MethodDescriptor getDate = new MethodDescriptor(beanClass.getMethod("getDate", args));
  139.  
  140.             connections = new java.util.Vector();
  141.             connection = new ConnectionDescriptor("output", "String", "",
  142.                                     "%name%.getDate()",
  143.                                     conn.getString("getDate"));
  144.             connections.addElement(connection);
  145.  
  146.             getDate.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  147.             md.addElement(getDate);
  148.         } catch (Exception e) { throw new Error("getDate:: " + e.toString()); }
  149.  
  150.         MethodDescriptor[] rv = new MethodDescriptor[md.size()];
  151.         md.copyInto(rv);
  152.  
  153.         return rv;
  154.     }
  155.  
  156.     /**
  157.      * Returns descriptions of this bean's properties.
  158.      */
  159.     public PropertyDescriptor[] getPropertyDescriptors() {
  160.         ResourceBundle prop = ResourceBundle.getBundle("symantec.itools.resources.PropBundle");
  161.  
  162.         try{
  163.         PropertyDescriptor defProperty = new PropertyDescriptor("date", beanClass);
  164.         defProperty.setBound(true);
  165.         defProperty.setConstrained(true);
  166.         defProperty.setDisplayName(prop.getString("date"));
  167.  
  168.         PropertyDescriptor selectedColor = new PropertyDescriptor("selectedColor", beanClass);
  169.         selectedColor.setBound(true);
  170.         selectedColor.setConstrained(true);
  171.         selectedColor.setDisplayName(prop.getString("selectedColor"));
  172.  
  173.         PropertyDescriptor layout = new PropertyDescriptor("layout", beanClass);
  174.         layout.setHidden(true);
  175.  
  176.         PropertyDescriptor[] rv = {
  177.             defProperty,
  178.             selectedColor,
  179.             layout};
  180.         return rv;
  181.         } catch (IntrospectionException e) { throw new Error(e.toString()); }
  182.     }
  183.  
  184.     /**
  185.      * Returns the index of the property expected to be changed most often by the designer.
  186.      */
  187.     public int getDefaultPropertyIndex() {
  188.         return 0;    //  the index for our default property is always 0
  189.     }
  190.  
  191.     private final static Class beanClass = Calendar.class;
  192.  
  193.     }    //  end of class CalendarBeanInfo