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

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