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

  1. package symantec.itools.awt;
  2.  
  3. import java.beans.*;
  4. import symantec.itools.beans.*;
  5. import java.util.ResourceBundle;
  6.  
  7. /**
  8.  * BeanInfo for StateCheckBox
  9.  *
  10.  */
  11.  
  12. public class StateCheckBoxBeanInfo extends SimpleBeanInfo {
  13.  
  14.     /**
  15.      * Constructs a StateCheckBoxBeanInfo object.
  16.      */
  17.     public StateCheckBoxBeanInfo() {
  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("GroupAdditional"); 
  41.  
  42.         SymantecBeanDescriptor bd = new SymantecBeanDescriptor(beanClass);
  43.         bd.setFolder(s);
  44.         bd.setToolbar(s);
  45.         bd.setWinHelp("0x123A7");
  46.  
  47.         ResourceBundle conn = ResourceBundle.getBundle("symantec.itools.resources.ConnBundle");
  48.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  49.                                                 "%name%.TWO_STATE",
  50.                                                 conn.getString("TWO_STATE")));
  51.  
  52.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  53.                                                 "%name%.THREE_STATE",
  54.                                                 conn.getString("THREE_STATE")));
  55.  
  56.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  57.                                                 "%name%.STATE_UNCHECKED",
  58.                                                 conn.getString("STATE_UNCHECKED")));
  59.  
  60.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  61.                                                 "%name%.STATE_CHECKED",
  62.                                                 conn.getString("STATE_CHECKED")));
  63.  
  64.         bd.addConnectionDescriptor(new ConnectionDescriptor("output", "int", "",
  65.                                                 "%name%.STATE_DEFAULT",
  66.                                                 conn.getString("STATE_DEFAULT")));
  67.  
  68.  
  69.         return (BeanDescriptor) bd;
  70.     }
  71.  
  72.     /**
  73.      * Gets an image that may be used to visually represent this bean
  74.      * (in the toolbar, on a form, etc).
  75.      * @param iconKind the type of icon desired, one of: BeanInfo.ICON_MONO_16x16,
  76.      * BeanInfo.ICON_COLOR_16x16, BeanInfo.ICON_MONO_32x32, or BeanInfo.ICON_COLOR_32x32.
  77.      * @return an image for this bean, always color even if requested monochrome
  78.      * @see BeanInfo#ICON_MONO_16x16
  79.      * @see BeanInfo#ICON_COLOR_16x16
  80.      * @see BeanInfo#ICON_MONO_32x32
  81.      * @see BeanInfo#ICON_COLOR_32x32
  82.      */
  83.     public java.awt.Image getIcon(int iconKind) {
  84.         if (iconKind == BeanInfo.ICON_MONO_16x16 ||
  85.             iconKind == BeanInfo.ICON_COLOR_16x16) {
  86.             java.awt.Image img = loadImage("StateCheckBoxC16.gif");
  87.             return img;
  88.         }
  89.  
  90.         if (iconKind == BeanInfo.ICON_MONO_32x32 ||
  91.             iconKind == BeanInfo.ICON_COLOR_32x32) {
  92.             java.awt.Image img = loadImage("StateCheckBoxC32.gif");
  93.             return img;
  94.         }
  95.  
  96.         return null;
  97.     }
  98.  
  99.     /**
  100.      * Gets an array of descriptions of the methods used for "connections" by
  101.      * Visual CafΘ's Interaction Wizard.
  102.      * Included in each method description is a CONNECTIONS ConnectionDescriptor.
  103.      * @return method descriptions for this bean
  104.      * @see symantec.itools.beans.ConnectionDescriptor#CONNECTIONS
  105.      */
  106.     public MethodDescriptor[] getMethodDescriptors() {
  107.         Class[] args;
  108.         ConnectionDescriptor connection;
  109.         java.util.Vector connections;
  110.         java.util.Vector md = new java.util.Vector();
  111.         ResourceBundle conn = ResourceBundle.getBundle("symantec.itools.resources.ConnBundle");
  112.  
  113.         try{
  114.             args = new Class[1];
  115.             args[0] = java.lang.Integer.TYPE ;
  116.             MethodDescriptor setStyle = new MethodDescriptor(beanClass.getMethod("setStyle", args));
  117.  
  118.             connections = new java.util.Vector();
  119.             connection = new ConnectionDescriptor("input", "int", "",
  120.                                     "%name%.setStyle(%arg%);",
  121.                                     conn.getString("setStyleCheckBox"));
  122.             connections.addElement(connection);
  123.  
  124.             setStyle.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  125.             md.addElement(setStyle);
  126.         } catch (Exception e) { throw new Error("setStyle:: " + e.toString()); }
  127.  
  128.         try{
  129.             args = null;
  130.             MethodDescriptor getStyle = new MethodDescriptor(beanClass.getMethod("getStyle", args));
  131.  
  132.             connections = new java.util.Vector();
  133.             connection = new ConnectionDescriptor("output", "int", "",
  134.                                     "%name%.getStyle()",
  135.                                     conn.getString("getStyleCheckBox"));
  136.             connections.addElement(connection);
  137.  
  138.             getStyle.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  139.             md.addElement(getStyle);
  140.         } catch (Exception e) { throw new Error("getStyle:: " + e.toString()); }
  141.  
  142.         try{
  143.             args = new Class[1];
  144.             args[0] = java.lang.Integer.TYPE ;
  145.             MethodDescriptor setState = new MethodDescriptor(beanClass.getMethod("setState", args));
  146.  
  147.             connections = new java.util.Vector();
  148.             connection = new ConnectionDescriptor("input", "int", "",
  149.                                     "%name%.setState(%arg%);",
  150.                                     conn.getString("setStateState"));
  151.             connections.addElement(connection);
  152.  
  153.             connection = new ConnectionDescriptor("input", "void", "",
  154.                                     "%name%.setState(%name%.STATE_UNCHECKED);",
  155.                                     conn.getString("setStateClear"));
  156.             connections.addElement(connection);
  157.  
  158.             connection = new ConnectionDescriptor("input", "void", "",
  159.                                     "%name%.setState(%name%.STATE_CHECKED);",
  160.                                     conn.getString("setStateCheck"));
  161.             connections.addElement(connection);
  162.  
  163.             setState.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  164.             md.addElement(setState);
  165.         } catch (Exception e) { throw new Error("setState:: " + e.toString()); }
  166.  
  167.         try{
  168.             args = null;
  169.             MethodDescriptor getState = new MethodDescriptor(beanClass.getMethod("getState", args));
  170.  
  171.             connections = new java.util.Vector();
  172.             connection = new ConnectionDescriptor("output", "int", "",
  173.                                     "%name%.getState()",
  174.                                     conn.getString("getState"));
  175.             connections.addElement(connection);
  176.  
  177.             connection = new ConnectionDescriptor("output", "boolean", "",
  178.                                     "(%name%.getState() == %name%.STATE_CHECKED)",
  179.                                     conn.getString("getStateOn"));
  180.             connections.addElement(connection);
  181.  
  182.             connection = new ConnectionDescriptor("output", "boolean", "",
  183.                                     "(%name%.getState() == %name%.STATE_UNCHECKED)",
  184.                                     conn.getString("getStateOff"));
  185.             connections.addElement(connection);
  186.  
  187.             getState.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  188.             md.addElement(getState);
  189.         } catch (Exception e) { throw new Error("getState:: " + e.toString()); }
  190.  
  191.         MethodDescriptor[] rv = new MethodDescriptor[md.size()];
  192.         md.copyInto(rv);
  193.  
  194.         return rv;
  195.     }
  196.  
  197.     /**
  198.      * Returns descriptions of this bean's properties.
  199.      */
  200.     public PropertyDescriptor[] getPropertyDescriptors() {
  201.         ResourceBundle prop = ResourceBundle.getBundle("symantec.itools.resources.PropBundle");
  202.  
  203.         try{
  204.         PropertyDescriptor style = new PropertyDescriptor("style", beanClass);
  205.         style.setBound(true);
  206.         style.setConstrained(true);
  207.         style.setDisplayName(prop.getString("style"));
  208.         style.setValue("ENUMERATION", "TWO_STATE=0, THREE_STATE=1");
  209.  
  210.         PropertyDescriptor state = new PropertyDescriptor("state", beanClass);
  211.         state.setBound(true);
  212.         state.setConstrained(true);
  213.         state.setDisplayName(prop.getString("state"));
  214.         state.setValue("ENUMERATION", "STATE_UNCHECKED=0, STATE_CHECKED=1, STATE_DEFAULT=2");
  215.  
  216.         PropertyDescriptor[] rv = {
  217.             style,
  218.             state};
  219.         return rv;
  220.         } catch (IntrospectionException e) { throw new Error(e.toString()); }
  221.     }
  222.  
  223.     private final static Class beanClass = StateCheckBox.class;
  224.  
  225.     }    //  end of class StateCheckBoxBeanInfo