home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / Wrapper.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  22.4 KB  |  783 lines

  1.  
  2. package sun.beanbox;
  3.  
  4. /**
  5.  * This wrapper class keeps track of various BeanBox related
  6.  * state for each bean in the composition window.
  7.  *
  8.  * Among other things, it draws the black-and-white hashed
  9.  * border around the currenty active component.
  10.  */
  11.  
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import java.io.*;
  15. import java.beans.*;
  16. import java.util.*;
  17. import java.lang.reflect.Method;
  18. import java.lang.reflect.InvocationTargetException;
  19. import java.applet.Applet;
  20.  
  21. public class Wrapper extends Panel implements Serializable, 
  22.                 MouseListener, MouseMotionListener {
  23.  
  24.     static final long serialVersionUID = 1144602051002987355L;
  25.  
  26.     public Wrapper(Object bean, String beanLabel, String beanName) {
  27.         this.bean = bean;
  28.     if (beanName == null) {
  29.         beanName = bean.getClass().getName();
  30.     }
  31.     if (beanLabel == null) {
  32.         beanLabel = beanName;
  33.     }
  34.     this.beanName = beanName;
  35.     this.beanLabel = beanLabel;
  36.     setLayout(null);
  37.     if (Beans.isInstanceOf(bean, Component.class)) {
  38.             child = (Component)Beans.getInstanceOf(bean, Component.class);
  39.     } else {
  40.         invisibleWrappers.addElement(this);
  41.         child = new OurLabel(beanLabel);
  42.         if (BeanBoxFrame.getHideInvisibleBeans()) {
  43.         setVisible(false);
  44.         }
  45.     }
  46.     add(child);
  47.     child.setLocation(borderWidth, borderWidth);
  48.     initialize();
  49.     attachListeners();
  50.     }
  51.  
  52.     void initialize() { 
  53.     if (! Beans.isInstanceOf(bean, Component.class)) {
  54.         invisibleWrappers.addElement(this);
  55.         if (BeanBoxFrame.getHideInvisibleBeans()) {
  56.         setVisible(false);
  57.         }
  58.     }
  59.     esdMap = new Hashtable();
  60.     try {
  61.         BeanInfo bi = Introspector.getBeanInfo(bean.getClass());
  62.         EventSetDescriptor[] esds = bi.getEventSetDescriptors();
  63.         for (int i = 0; i < esds.length; i++) {
  64.             esdMap.put(esds[i].getName(), esds[i]);
  65.         }
  66.     } catch (IntrospectionException ex) {
  67.         System.err.println("Wrapper couldn't introspect on bean: " + bean);
  68.         }
  69.     if (eventTargets == null) {
  70.         eventTargets = new Vector();
  71.     }
  72.     }
  73.  
  74.     private void readObject(ObjectInputStream s)
  75.                 throws ClassNotFoundException, IOException {
  76.     s.defaultReadObject();
  77.     initialize();
  78.     }
  79.  
  80.     synchronized void addPropertychangeListener(String propertyName,
  81.                 PropertyChangeListener listener) {
  82.     }
  83.  
  84.     Class[] getEventTargetClasses() {
  85.     int s = eventTargets.size();
  86.     Class[] back = new Class[s];
  87.     int i = 0;
  88.     Enumeration e = eventTargets.elements();
  89.     while (e.hasMoreElements()) {
  90.         WrapperEventTarget et = (WrapperEventTarget) e.nextElement();
  91.         Object l = et.targetListener;
  92.         back[i] = l.getClass();
  93.         i += 1;
  94.     }
  95.     return back;
  96.     }
  97.  
  98.     synchronized void addEventTarget(String eventSetName,
  99.             Wrapper targetWrapper, Object listener) {
  100.     WrapperEventTarget et = new WrapperEventTarget();
  101.     et.eventSetName = eventSetName;
  102.     if (targetWrapper != null) {
  103.         et.targetBean = targetWrapper.getBean();
  104.     }
  105.     et.targetListener = listener;
  106.     eventTargets.addElement(et);
  107.     EventSetDescriptor esd = (EventSetDescriptor) esdMap.get(eventSetName);
  108.     if (esd == null) {
  109.         System.err.println("Internal error: Wrapper.addEventTarget missing event set");
  110.         System.err.println("        eventSetName = " + eventSetName);
  111.         System.err.println("        bean = " + bean);
  112.         return;
  113.     }
  114.     Method adder = esd.getAddListenerMethod();
  115.     Method remover = esd.getRemoveListenerMethod();
  116.     if (adder == null || remover == null) {
  117.         System.err.println("Internal error: Wrapper.addEventTarget missing add/remote listener");
  118.         System.err.println("        eventSetName = " + eventSetName);
  119.         System.err.println("        bean = " + bean);
  120.         return;
  121.     }
  122.     try {
  123.         Object args[] = { listener };
  124.         adder.invoke(bean, args);
  125.     } catch (InvocationTargetException ex) {
  126.         System.err.println("Wrapper: adding event listener for " + eventSetName + " failed:");
  127.         System.err.println("    " + ex.getTargetException());
  128.     } catch (Exception ex) {
  129.         System.err.println("Wrapper: adding event listener for " + eventSetName + " failed:");
  130.         System.err.println("    " + ex);
  131.     }
  132.     }
  133.  
  134.     /**
  135.      * Temporarily remove any event listeners.
  136.      */
  137.  
  138.     void removeListeners() {
  139.     Enumeration enum = eventTargets.elements();
  140.     while (enum.hasMoreElements()) {
  141.         WrapperEventTarget et = (WrapperEventTarget)enum.nextElement();
  142.         EventSetDescriptor esd = (EventSetDescriptor) esdMap.get(et.eventSetName);
  143.         Method remover = esd.getRemoveListenerMethod();
  144.         try {
  145.             Object args[] = { et.targetListener };
  146.             remover.invoke(bean, args);
  147.         } catch (InvocationTargetException ex) {
  148.             System.err.println("Wrapper: removing event listener for "
  149.                      + et.eventSetName + " failed:");
  150.             System.err.println("    " + ex.getTargetException());
  151.         ex.getTargetException().printStackTrace();
  152.         } catch (Exception ex) {
  153.             System.err.println("Wrapper: removing event listener for "
  154.                      + et.eventSetName + " failed:");
  155.             System.err.println("    " + ex);
  156.         ex.printStackTrace();
  157.         }
  158.     }
  159.     // Remove mouse listeners.
  160.     listenForMice(false);
  161.     }
  162.  
  163.     /**
  164.       * (Re)-attach any event listeners.
  165.       */
  166.     void attachListeners() {   
  167.     Enumeration enum = eventTargets.elements();
  168.     while (enum.hasMoreElements()) {
  169.         WrapperEventTarget et = (WrapperEventTarget)enum.nextElement();
  170.         EventSetDescriptor esd = (EventSetDescriptor) esdMap.get(et.eventSetName);
  171.         Method adder = esd.getAddListenerMethod();
  172.         try {
  173.             Object args[] = { et.targetListener };
  174.             adder.invoke(bean, args);
  175.         } catch (InvocationTargetException ex) {
  176.             System.err.println("Wrapper: adding event listener for "
  177.                      + et.eventSetName + " failed:");
  178.             System.err.println("    bean = " + bean);
  179.             System.err.println("    " + ex.getTargetException());
  180.         ex.getTargetException().printStackTrace();
  181.         } catch (Exception ex) {
  182.             System.err.println("Wrapper: adding event listener for "
  183.                      + et.eventSetName + " failed:");
  184.             System.err.println("    bean = " + bean);
  185.             System.err.println("    " + ex);
  186.         ex.printStackTrace();
  187.         }
  188.     }
  189.     // Reattach mouse listeners.
  190.     listenForMice(true);
  191.     }
  192.  
  193.  
  194.     void writeNakedBean(ObjectOutputStream oos) throws IOException {
  195.  
  196.     // First, detach all event listeners.
  197.     removeListeners();
  198.                     
  199.     // Now write the bean.
  200.     oos.writeObject(bean);
  201.  
  202.     // Now rettach all event listeners.
  203.     attachListeners();
  204.     }
  205.  
  206.     /**
  207.      * Cleanup is called when a Wrapper has been "cut" from the BeanBox.
  208.      */
  209.     void cleanup() {
  210.     if (bean instanceof Applet) {
  211.         Applet apl = (Applet)bean;
  212.         apl.stop();
  213.         apl.destroy();
  214.     }
  215.     removeListeners();    
  216.     // We should also remove ourself from any event sources...
  217.     }
  218.  
  219.  
  220.     /**
  221.      * get the wrapped bean.
  222.      */
  223.     public Object getBean() {
  224.     return bean;
  225.     }
  226.  
  227.     /**
  228.      * get the wrapped beanName
  229.      */
  230.     public String getBeanLabel() {
  231.     return beanLabel;
  232.     }
  233.  
  234.     /**
  235.      * get the wrapped beanName
  236.      */
  237.     public String getBeanName() {
  238.     return beanName;
  239.     }
  240.  
  241.     /**
  242.      * get the AWT component used to represent the wrapped bean.
  243.      */
  244.     public Component getChild() {
  245.     return child;
  246.     }
  247.  
  248.     /**
  249.      * Static method to map from an AWT component to the associated Wrapper.
  250.      */
  251.     public static Wrapper findWrapper(Component comp) {
  252.     for (;;) {
  253.         if (comp == null) {
  254.             throw new Error("component has no wrapper!?");
  255.         }
  256.         if (comp instanceof Wrapper) {
  257.         return (Wrapper) comp;
  258.         }
  259.         if (comp instanceof BeanBoxFrame) {
  260.         return BeanBoxFrame.getTopWrapper();
  261.         }
  262.         comp = comp.getParent();
  263.     }
  264.     }
  265.  
  266.     public void doLayout() {
  267.     // Has the child gotten bigger?  If so, expand to fit.
  268.     Dimension d = getSize();
  269.     Dimension cd = child.getMinimumSize();
  270.     if (cd.width > (d.width - (2*borderWidth)) ||
  271.         cd.height > (d.height - (2*borderWidth))) {
  272.         int width = d.width;
  273.         if (cd.width > (d.width - (2*borderWidth))) {
  274.         width = cd.width + (2*borderWidth);
  275.         }
  276.         int height = d.height;
  277.         if (cd.height > (d.height - (2*borderWidth))) {
  278.             height = cd.height + (2*borderWidth);
  279.         }
  280.         setSize(width,height);
  281.     }
  282.     }
  283.  
  284.     public void setActive(boolean isActive) {
  285.     active = isActive;
  286.     repaint();
  287.     }
  288.  
  289.     public Dimension getPreferredSize() {
  290.     Dimension childSize = child.getPreferredSize();
  291.     if (childHasStupidPreferredSize()) {
  292.         childSize = child.getSize();
  293.     }
  294.     int width = childSize.width;
  295.     int height = childSize.height;
  296.     // Make sure the child is at least its minimum size.
  297.     Dimension minSize = child.getMinimumSize();
  298.     if (minSize.height > height) {
  299.         height = minSize.height;
  300.     }
  301.     if (minSize.width > width) {
  302.         width = minSize.width;
  303.     }
  304.     width += (2 * borderWidth);
  305.     height += (2 * borderWidth);
  306.     return new Dimension(width, height);
  307.     }
  308.  
  309.     private boolean childHasStupidPreferredSize() {
  310.     // We do a special check for demented behaviour from empty Panels
  311.     // for the sake of applets.  If an applet does not explicitly
  312.     // specify a dimension, then we allow it to be resized arbitrarily
  313.     // rather than limiting it to the tiny size returned by the FlowLayout
  314.     if (child instanceof Panel) {
  315.         Container cont = (Container)child;
  316.         LayoutManager lay = cont.getLayout();
  317.         if (cont.getComponentCount() == 0 && lay instanceof FlowLayout) {
  318.         FlowLayout flow = (FlowLayout) lay;
  319.         Dimension cd = child.getPreferredSize();
  320.         Dimension fd = flow.preferredLayoutSize(cont);
  321.         if (cd.width == fd.width && cd.height == fd.height) {
  322.             return true;
  323.         }
  324.         }
  325.     }
  326.     return false;
  327.     }
  328.  
  329.     public void setBounds(int x, int y, int width, int height) {
  330.  
  331.     // If we're the top level wrapper, there is no dickering.
  332.     if (getParent() != null && getParent() instanceof Frame) {
  333.         super.setBounds(x,y,width,height);
  334.         child.setBounds(borderWidth, borderWidth,
  335.         width-(2*borderWidth), height-(2*borderWidth));
  336.         child.validate();
  337.         return;
  338.     }
  339.  
  340.     // Figure out what size we want to set the child 
  341.     width -= (2 * borderWidth);
  342.     height -= (2 * borderWidth);
  343.  
  344.     // Make sure the child is at least its minimum size.
  345.     Dimension minSize = child.getMinimumSize();
  346.     if (minSize.height > height) {
  347.         height = minSize.height;
  348.     }
  349.     if (minSize.width > width) {
  350.         width = minSize.width;
  351.     }
  352.  
  353.     // Make sure the child is under its maximum size.
  354.     Dimension maxSize = child.getMaximumSize();
  355.     if (height > maxSize.height) {
  356.         height = maxSize.height;
  357.     }
  358.     if (width > maxSize.width) {
  359.         width = maxSize.width;
  360.     }
  361.  
  362.     // Now we can set the child's size.
  363.     child.setBounds(borderWidth, borderWidth, width, height);
  364.  
  365.     // Finally we can set our own size.
  366.     width += (2 * borderWidth);
  367.     height += (2 * borderWidth);
  368.     super.setBounds(x, y, width, height);
  369.  
  370.     child.validate();
  371.     }
  372.  
  373.     // Note that to avoid deadlocks, paint is *not* synchronized
  374.     public void paint(Graphics g) {
  375.     if (active && Beans.isDesignTime()) {
  376.         int width = getSize().width;
  377.         int height = getSize().height;
  378.  
  379.         getHashBars(this);
  380.  
  381.         // Draw the bounding hasbox as a set of images.
  382.  
  383.         // First draw the top and bottom bars.
  384.         int nudge = 2 * hashBarWidth;
  385.         int bottomNudge = - ((height-hashBarWidth) % nudge);
  386.         for (int x = 0; x < width; x += hashBarLength) {
  387.             g.drawImage(xHashBar, x, 0, null);
  388.             g.drawImage(xHashBar, x + bottomNudge, height-hashBarWidth, null);
  389.         }
  390.         // Now draw the left and right bars.
  391.         int rightNudge = - ((width-hashBarWidth) % nudge);
  392.         for (int y = 0; y < height; y += hashBarLength) {
  393.             g.drawImage(yHashBar, 0, y, null);
  394.             g.drawImage(yHashBar, width-hashBarWidth, y+rightNudge, null);
  395.         }
  396.  
  397.  
  398.     }
  399.     super.paint(g);
  400.     }
  401.  
  402.     public synchronized void activate() {
  403.     active = true;
  404.     repaint();
  405.     }
  406.  
  407.     public synchronized void deactivate() {
  408.     active = false;
  409.     repaint();
  410.     }
  411.  
  412.    public synchronized void doMouseStuff(MouseEvent evt) {
  413.     // Code to handle drawing the resize/move cursor.
  414.  
  415.     if (!active || !Beans.isDesignTime()) {
  416.         return;
  417.     }
  418.     Component parent = getParent();
  419.  
  420.     // You can't move or resize the top-level beanbox.
  421.     if (parent != null && parent instanceof BeanBoxFrame) {
  422.         return;
  423.     }
  424.  
  425.     int x = evt.getX();
  426.     int y = evt.getY();
  427.       int id = evt.getID();
  428.  
  429.     int lowX = borderWidth;
  430.     int highX = getSize().width - borderWidth;
  431.     int lowY = borderWidth;
  432.     int highY = getSize().height - borderWidth;
  433.     boolean onTheBorder = ((evt.getSource() == this) &&
  434.             (x < lowX || x > highX || y < lowY || y > highY));
  435.  
  436.     Cursor newCursor = defaultCursor;
  437.  
  438.     if (onTheBorder) {
  439.         if (id == MouseEvent.MOUSE_PRESSED) {
  440.             // Check if we need to resize or move.
  441.             if (cursor == nwResizeCursor || 
  442.             cursor == swResizeCursor ||
  443.             cursor == neResizeCursor ||
  444.             cursor == seResizeCursor) {
  445.             getBeanBox().startResize(this, x, y, cursor);
  446.             } else if (cursor == moveCursor) {
  447.             getBeanBox().startMove(this, x, y);
  448.             } 
  449.  
  450.         } else if (id == MouseEvent.MOUSE_ENTERED 
  451.                 || id == MouseEvent.MOUSE_MOVED) {
  452.  
  453.         // If we're in a corner set the cursor to indicate a
  454.         // resize, otherwise a move.
  455.         lowX += resizeDelta;
  456.         lowY += resizeDelta;
  457.         highX -= resizeDelta;
  458.         highY -= resizeDelta;
  459.  
  460.             if (x < lowX && y < lowY) {
  461.             newCursor = nwResizeCursor;
  462.             } else if (x < lowX && y > highY) {
  463.             newCursor = swResizeCursor;
  464.             } else if (x > highX && y < lowY) {
  465.             newCursor = neResizeCursor;
  466.             } else if (x > highX && y > highY) {
  467.             newCursor = seResizeCursor;
  468.         } else {
  469.             newCursor = moveCursor;
  470.         }
  471.         }
  472.     }
  473.  
  474.     if (newCursor != cursor) {
  475.         cursor = newCursor;
  476.         // To workaround a bug on JDK 1.1, we avoid changing the user
  477.         // visible cursor on a straight JDK 1.1 system.
  478.         if (!isJDK("1.1_Final")) {
  479.         setCursor(cursor);
  480.         }
  481.     }
  482.     }
  483.  
  484.     final BeanBox getBeanBox() {
  485.     Component parent = getParent();
  486.     if (parent instanceof BeanBox) {
  487.         return (BeanBox)parent;
  488.     }
  489.     // Hmm, our parent isn't a BeanBox.  We may be the
  490.     // top-level wrapper.
  491.     if (parent instanceof BeanBoxFrame && child instanceof BeanBox) {
  492.         return (BeanBox) child;
  493.     }
  494.     // Otherwise we're hopelessly confused.
  495.     System.err.println("Warning: Can't find BeanBox from wrapper");
  496.     // System.err.println("    this = " + this);
  497.     // System.err.println("    child = " + child);
  498.     // System.err.println("    parent = " + getParent());
  499.     // System.err.println("    child.parent = " + child.getParent());
  500.     // Since we don't know who we are, punt to the top-level BeanBox.
  501.     return BeanBoxFrame.getTopBox();
  502.     }
  503.  
  504.     /**
  505.      * show or hide all the "invisible beans".
  506.      */
  507.     static void showInvisibleBeans(boolean show)  {
  508.     for (int i = 0; i < invisibleWrappers.size(); i++) {
  509.         ((Wrapper)invisibleWrappers.elementAt(i)).setVisible(show);
  510.     }
  511.     }
  512.  
  513.     //----------------------------------------------------------------------
  514.  
  515.     // Mouse listener methods for target bean.
  516.     // We also report all mouse events to our containing BeanBox.
  517.  
  518.     public void mouseClicked(MouseEvent evt) {
  519.     doMouseStuff(evt);
  520.     getBeanBox().mouseClicked(evt);
  521.     }
  522.  
  523.     public void mousePressed(MouseEvent evt) {
  524.     doMouseStuff(evt);
  525.     getBeanBox().mousePressed(evt);
  526.     }
  527.  
  528.     public void mouseReleased(MouseEvent evt) {
  529.     doMouseStuff(evt);
  530.     getBeanBox().mouseReleased(evt);
  531.     }
  532.  
  533.     public void mouseEntered(MouseEvent evt) {
  534.     doMouseStuff(evt);
  535.     getBeanBox().mouseEntered(evt);
  536.     }
  537.  
  538.     public void mouseExited(MouseEvent evt) {
  539.     doMouseStuff(evt);
  540.     getBeanBox().mouseExited(evt);
  541.     }
  542.  
  543.     public void mouseDragged(MouseEvent evt) {
  544.     doMouseStuff(evt);
  545.     getBeanBox().mouseDragged(evt);
  546.     }
  547.  
  548.     public void mouseMoved(MouseEvent evt) {
  549.     doMouseStuff(evt);
  550.     getBeanBox().mouseMoved(evt);
  551.     }
  552.  
  553.     //----------------------------------------------------------------------
  554.  
  555.     /**
  556.      * @deprecated  Provided for backwards compatibility only.
  557.      * We support old-style event handling as a backward compatibility
  558.      * feature when we're wrapping a bean using the old event model.
  559.      */
  560.     
  561.     public boolean handleEvent(Event evt) {
  562.     Component source = (Component) evt.target;
  563.     MouseEvent me;
  564.     int x = evt.x;
  565.     int y = evt.y;
  566.     if (source == child) {
  567.        // remap coordinate to child's space.
  568.         x = x - borderWidth;
  569.         y = y - borderWidth;
  570.     }
  571.     if (evt.id == Event.MOUSE_DOWN) {
  572.         me = new MouseEvent(source, MouseEvent.MOUSE_PRESSED,
  573.             0, 0, x, y, 0, false);
  574.         mousePressed(me);
  575.     } else if (evt.id == Event.MOUSE_UP) {
  576.         if (sawMouseDown) {
  577.             me = new MouseEvent(source, MouseEvent.MOUSE_CLICKED,
  578.             0, 0, x, y, 0, false);
  579.             mouseClicked(me);
  580.         }
  581.         sawMouseDown = false;
  582.         me = new MouseEvent(source, MouseEvent.MOUSE_RELEASED,
  583.             0, 0, x, y, 0, false);
  584.         mouseReleased(me);
  585.     } else if (evt.id == Event.MOUSE_MOVE) {
  586.         me = new MouseEvent(source, MouseEvent.MOUSE_MOVED,
  587.             0, 0, x, y, 0, false);
  588.         mouseMoved(me);
  589.     } else if (evt.id == Event.MOUSE_ENTER) {
  590.         sawMouseDown = false;
  591.         me = new MouseEvent(source, MouseEvent.MOUSE_ENTERED,
  592.             0, 0, x, y, 0, false);
  593.         mouseEntered(me);
  594.     } else if (evt.id == Event.MOUSE_EXIT) {
  595.         sawMouseDown = false;
  596.         me = new MouseEvent(source, MouseEvent.MOUSE_EXITED,
  597.             0, 0, x, y, 0, false);
  598.         mouseExited(me);
  599.     } else if (evt.id == Event.MOUSE_DRAG) {
  600.         me = new MouseEvent(source, MouseEvent.MOUSE_DRAGGED,
  601.             0, 0, x, y, 0, false);
  602.         mouseDragged(me);
  603.     }
  604.     return false;
  605.     }
  606.  
  607.     //----------------------------------------------------------------------
  608.     private static Hashtable eventModelCache = new Hashtable();
  609.  
  610.     // Check if our child needs to use the old AWT event mnodel.
  611.  
  612.     private synchronized boolean useNewEventModel() {
  613.     // Check our cache first.
  614.     Boolean b = (Boolean) eventModelCache.get(child.getClass());
  615.     if (b != null) {
  616.         return b.booleanValue();
  617.     }
  618.  
  619.     // We check whether the bean has any public methods that take
  620.     // old AWT event objects.  If so, we assume it wants the
  621.         // old event model, otherwise we assume it wants the new.
  622.     boolean useNew = true;
  623.  
  624.     try {
  625.         Class clz = child.getClass();
  626.         while (useNew && clz != null) {
  627.  
  628.         java.lang.reflect.Method methods[] = clz.getDeclaredMethods();
  629.  
  630.         for (int i = 0; i < methods.length; i++) {
  631.             java.lang.reflect.Method m = methods[i];
  632.             int mods = m.getModifiers();
  633.             if (!java.lang.reflect.Modifier.isPublic(mods)) {
  634.             // Skip non=public methods.
  635.             continue;
  636.             }
  637.             Class params[] = m.getParameterTypes();
  638.             if (params.length > 0 && params[0] == java.awt.Event.class) {
  639.             // First arg is java.awt.Event.  We assume this is an
  640.             // old-style AWT event handler method.
  641.             useNew = false;
  642.             break;
  643.             }
  644.         }
  645.         clz = clz.getSuperclass();
  646.         if (clz.getName().indexOf("java.") == 0) {
  647.            // We've reached a java.* class, so we're done.
  648.             break;
  649.           }
  650.         }
  651.     } catch (Exception ex) {
  652.         System.err.println("Wrapper.useOldEventModel caught: " + ex);
  653.     }
  654.  
  655.     eventModelCache.put(child.getClass(), new Boolean(useNew));
  656.     return useNew;
  657.     }
  658.  
  659.  
  660.     void listenForMice(boolean enable) {
  661.     // If the child uses the old event mode we rely on receiving events
  662.     // through handleEvent.  Otherwise we use the new event model and
  663.     // register explicit listeners for mouse events.
  664.     if (!useNewEventModel()) {
  665.         return;
  666.     }
  667.     if (enable) {
  668.            this.addMouseListener(this);
  669.         this.addMouseMotionListener(this);
  670.         child.addMouseListener(this);
  671.         child.addMouseMotionListener(this);
  672.     } else {
  673.            this.removeMouseListener(this);
  674.         this.removeMouseMotionListener(this);
  675.         child.removeMouseListener(this);
  676.         child.removeMouseMotionListener(this);
  677.     }
  678.     }
  679.  
  680.     private static synchronized void getHashBars(Component c) {
  681.     if (xHashBar != null) {
  682.         return;
  683.     }
  684.     int len = hashBarLength + 20;
  685.  
  686.     xHashBar = c.createImage(len, hashBarWidth);
  687.     yHashBar = c.createImage(hashBarWidth, len);
  688.  
  689.     Polygon poly = new Polygon();
  690.     Graphics g = xHashBar.getGraphics();
  691.     for (int i = 0; i < 4; i++) {
  692.         poly.addPoint(0,0);
  693.     }
  694.        poly.ypoints[2] = hashBarWidth;
  695.        poly.ypoints[3] = hashBarWidth;
  696.  
  697.     for (int x = 0; x < (hashBarWidth+len); x += hashBarWidth) {
  698.         // draw alternate dark gray and light gray stripes.
  699.         if (((x/hashBarWidth)%2) == 0) {
  700.             g.setColor(Color.darkGray);
  701.         } else {
  702.             g.setColor(Color.lightGray);
  703.         }
  704.         poly.xpoints[0] = x;
  705.         poly.xpoints[1] = x + hashBarWidth;
  706.         poly.xpoints[2] = x;
  707.         poly.xpoints[3] = x - hashBarWidth;
  708.         g.fillPolygon(poly);
  709.     }
  710.  
  711.     g = yHashBar.getGraphics();
  712.        poly.xpoints[0] = 0;
  713.        poly.xpoints[1] = hashBarWidth;
  714.        poly.xpoints[2] = hashBarWidth;
  715.        poly.xpoints[3] = 0;
  716.  
  717.     for (int y = 0; y < (hashBarWidth+len); y += hashBarWidth) {
  718.         // draw alternate dark gray and light gray stripes.
  719.         if (((y/hashBarWidth)%2) == 0) {
  720.             g.setColor(Color.darkGray);
  721.         } else {
  722.             g.setColor(Color.lightGray);
  723.         }
  724.         poly.ypoints[0] = y;
  725.         poly.ypoints[1] = y - hashBarWidth;
  726.         poly.ypoints[2] = y;
  727.         poly.ypoints[3] = y + hashBarWidth;
  728.         g.fillPolygon(poly);
  729.     }
  730.     }
  731.  
  732.     private static boolean isJDK(String version) {
  733.     return System.getProperty("java.version").equals(version);
  734.     }
  735.  
  736.     //----------------------------------------------------------------------
  737.  
  738.     private Component child;
  739.     private Object bean;
  740.     private String beanLabel;
  741.     private String beanName;
  742.     private transient boolean active;
  743.     private transient Cursor cursor = defaultCursor;
  744.  
  745.     private final static int borderWidth = 5;
  746.     private final static int resizeDelta = 8;    
  747.  
  748.     // Shorthands for the cursors.
  749.     private static Cursor nwResizeCursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
  750.     private static Cursor neResizeCursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
  751.     private static Cursor swResizeCursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
  752.     private static Cursor seResizeCursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
  753.     private static Cursor moveCursor     = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
  754.     private static Cursor defaultCursor  = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
  755.  
  756.     private static Vector invisibleWrappers = new Vector();
  757.     private transient boolean sawMouseDown;
  758.  
  759.     // Table that maps events set names to EventDescriptors.
  760.     private transient Hashtable esdMap;
  761.     // List of WrapperEventTargets that we fire events at.
  762.     private Vector eventTargets;
  763.  
  764.     private static int hashBarWidth = 4;
  765.     private static int hashBarLength = 104;
  766.     private static Image xHashBar;
  767.     private static Image yHashBar;
  768.  
  769.     //----------------------------------------------------------------------
  770.  
  771. }
  772.  
  773. // Class to hold state on event listener hookup for which this
  774. // Wrapper's bean is a source.
  775.  
  776. class WrapperEventTarget implements Serializable {
  777.     static final long serialVersionUID = 4831901854891942741L;
  778.  
  779.     String eventSetName;
  780.     Object targetBean;
  781.     Object targetListener;
  782. }
  783.