Source for java.awt.dnd.DragGestureRecognizer

   1: /* DragGestureRecognizer.java --
   2:    Copyright (C) 2002,2006 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.awt.dnd;
  40: 
  41: import gnu.classpath.NotImplementedException;
  42: 
  43: import java.awt.Component;
  44: import java.awt.Point;
  45: import java.awt.event.InputEvent;
  46: import java.io.IOException;
  47: import java.io.ObjectInputStream;
  48: import java.io.ObjectOutputStream;
  49: import java.io.Serializable;
  50: import java.util.ArrayList;
  51: import java.util.TooManyListenersException;
  52: 
  53: /**
  54:  * STUBBED
  55:  * @since 1.2
  56:  */
  57: public abstract class DragGestureRecognizer implements Serializable
  58: {
  59:   /**
  60:    * Compatible with JDK 1.2+.
  61:    */
  62:   private static final long serialVersionUID = 8996673345831063337L;
  63: 
  64:   protected DragSource dragSource;
  65:   protected Component component;
  66:   protected transient DragGestureListener dragGestureListener;
  67:   protected int sourceActions;
  68:   protected ArrayList events = new ArrayList();
  69: 
  70:   protected DragGestureRecognizer(DragSource ds, Component c, int sa,
  71:                                   DragGestureListener dgl)
  72:   {
  73:     if (ds == null)
  74:       throw new IllegalArgumentException();
  75:     dragSource = ds;
  76:     component = c;
  77:     sourceActions = sa;
  78:     dragGestureListener = dgl;
  79:   }
  80: 
  81:   protected DragGestureRecognizer(DragSource ds, Component c, int sa)
  82:   {
  83:     this(ds, c, sa, null);
  84:   }
  85: 
  86:   protected DragGestureRecognizer(DragSource ds, Component c)
  87:   {
  88:     this(ds, c, 0, null);
  89:   }
  90: 
  91:   protected DragGestureRecognizer(DragSource ds)
  92:   {
  93:     this(ds, null, 0, null);
  94:   }
  95: 
  96:   protected abstract void registerListeners();
  97: 
  98:   protected abstract void unregisterListeners();
  99: 
 100:   public DragSource getDragSource()
 101:   {
 102:     return dragSource;
 103:   }
 104: 
 105:   public Component getComponent()
 106:   {
 107:     return component;
 108:   }
 109: 
 110:   public void setComponent(Component c)
 111:   {
 112:     component = c;
 113:   }
 114: 
 115:   public int getSourceActions()
 116:   {
 117:     return sourceActions;
 118:   }
 119: 
 120:   public void setSourceActions(int sa)
 121:   {
 122:     sourceActions = sa;
 123:   }
 124: 
 125:   public InputEvent getTriggerEvent()
 126:   {
 127:     return events.size() > 0 ? (InputEvent) events.get(0) : null;
 128:   }
 129: 
 130:   public void resetRecognizer()
 131:     throws NotImplementedException
 132:   {
 133:     events = new ArrayList();
 134:     // FIXME: Not implemented fully.
 135:   }
 136: 
 137:   /**
 138:    * Register a new DragGestureListener.
 139:    *
 140:    * @exception TooManyListenersException If a DragGestureListener has already
 141:    * been added.
 142:    */
 143:   public void addDragGestureListener(DragGestureListener dgl)
 144:     throws TooManyListenersException
 145:   {
 146:     if (dragGestureListener != null)
 147:       throw new TooManyListenersException();
 148:     dragGestureListener = dgl;
 149:   }
 150: 
 151:   public void removeDragGestureListener(DragGestureListener dgl)
 152:   {
 153:     if (dragGestureListener != dgl)
 154:       throw new IllegalArgumentException();
 155:     dragGestureListener = null;
 156:   }
 157: 
 158:   /**
 159:    * Fires a <code>DragGestureEvent</code> to the DragGestureListener
 160:    * associated with this object, if there is one.
 161:    */
 162:   protected void fireDragGestureRecognized(int dragAction, Point p)
 163:   {
 164:     if(dragGestureListener != null)
 165:       dragGestureListener.dragGestureRecognized
 166:     (new DragGestureEvent(this, dragAction, p, events));
 167:   }
 168: 
 169:   protected void appendEvent(InputEvent e)
 170:   {
 171:     if (e == null)
 172:       return;
 173:     events.add(e);
 174:   }
 175: 
 176:   private void readObject(ObjectInputStream s)
 177:     throws ClassNotFoundException, IOException
 178:   {
 179:     s.defaultReadObject();
 180:     dragGestureListener = (DragGestureListener) s.readObject();
 181:   }
 182: 
 183:   private void writeObject(ObjectOutputStream s) throws IOException
 184:   {
 185:     s.defaultWriteObject();
 186:     s.writeObject(dragGestureListener instanceof Serializable
 187:                   ? dragGestureListener : null);
 188:   }
 189: } // class DragGestureRecognizer