
    public class DragRuleGestureListener implements DragGestureListener {

        /**
         * Start the drag if the operation is ok. uses
         * java.awt.datatransfer.StringSelection to transfer the label's data
         * 
         * @param e
         *            the event object
         */
        public void dragGestureRecognized(DragGestureEvent e) {

            // if the action is ok we go ahead
            // otherwise we punt
            // System.out.println(e.getDragAction());
            //if((e.getDragAction() & DragLabel.this.dragAction) == 0)
            //  return;
            // System.out.println( "kicking off drag");

            // get the label's text and put it inside a Transferable
            // Transferable transferable = new StringSelection(
            // DragLabel.this.getText() );
            Transferable transferable = new StringSelection(
                    BrickPanel.this.brick_type_);

            // now kick off the drag
            try {
                // initial cursor, transferrable, dsource listener
                e.startDrag(DragSource.DefaultCopyNoDrop, transferable,
                        BrickPanel.this.drag_rule_listener_);

                // or if dragSource is a variable
                // dragSource.startDrag(e, DragSource.DefaultCopyDrop,
                // transferable, dsListener);

                // or if you'd like to use a drag image if supported

                /*
                 * if(DragSource.isDragImageSupported() ) // cursor, image,
                 * point, transferrable, dsource listener
                 * e.startDrag(DragSource.DefaultCopyDrop, image, point,
                 * transferable, dsListener);
                 */

            } catch (InvalidDnDOperationException idoe) {
                // System.err.println( idoe );
            }
        }
    }
  
    /** ************************************************************************ */
    public class DragRuleSourceListener implements DragSourceListener {
        /**
         * @param e
         *            the event
         */
        public void dragDropEnd(DragSourceDropEvent e) {
            if (e.getDropSuccess() == false) {
                // System.out.println( "not successful");
                return;
            }

            /*
             * the dropAction should be what the drop target specified in
             * acceptDrop
             */
            // System.out.println( "dragdropend action " + e.getDropAction() );
            // this is the action selected by the drop target
            if (e.getDropAction() == DnDConstants.ACTION_MOVE) {
                // System.out.println("ACTION_MOVE choosen by drop target");
            }
        }

        /**
         * @param e
         *            the event
         */
        public void dragEnter(DragSourceDragEvent e) {
            // System.out.println( "draglabel enter " + e);
            DragSourceContext context = e.getDragSourceContext();
            //intersection of the users selected action, and the source and
            // target actions
            int myaction = e.getDropAction();
            if ((myaction & BrickPanel.this.drag_action_) != 0) {
                context.setCursor(DragSource.DefaultCopyDrop);
            } else {
                context.setCursor(DragSource.DefaultCopyNoDrop);
            }

        }

        /**
         * @param e
         *            the event
         */
        public void dragOver(DragSourceDragEvent e) {
            DragSourceContext context = e.getDragSourceContext();
            int sa = context.getSourceActions();
            int ua = e.getUserAction();
            int da = e.getDropAction();
            int ta = e.getTargetActions();
            // System.out.println("dl dragOver source actions" + sa);
            // System.out.println("user action" + ua);
            // System.out.println("drop actions" + da);
            // System.out.println("target actions" + ta);
        }

        /**
         * @param e
         *            the event
         */
        public void dragExit(DragSourceEvent e) {
            // System.out.println( "draglabel exit " + e);
            DragSourceContext context = e.getDragSourceContext();
            BrickPanel.this.current_image_ = BrickPanel.this.default_image_;
            BrickPanel.this.repaint();
        }

        /**
         * for example, press shift during drag to change to a link action
         * 
         * @param e
         *            the event
         */
        public void dropActionChanged(DragSourceDragEvent e) {
            DragSourceContext context = e.getDragSourceContext();
            context.setCursor(DragSource.DefaultCopyNoDrop);
        }

    }