Source for java.awt.dnd.DropTargetContext

   1: /* DropTargetContext.java --
   2:    Copyright (C) 2002, 2003, 2004, 2006,  Free Software Foundation
   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: package java.awt.dnd;
  39: 
  40: import java.awt.Component;
  41: import java.awt.datatransfer.DataFlavor;
  42: import java.awt.datatransfer.Transferable;
  43: import java.awt.datatransfer.UnsupportedFlavorException;
  44: import java.awt.dnd.peer.DropTargetContextPeer;
  45: import java.io.IOException;
  46: import java.io.Serializable;
  47: import java.util.Arrays;
  48: import java.util.List;
  49: 
  50: /**
  51:  * @author Michael Koch (konqueror@gmx.de)
  52:  * @since 1.2
  53:  */
  54: public class DropTargetContext implements Serializable
  55: {
  56:   static final long serialVersionUID = -634158968993743371L;
  57: 
  58:   protected class TransferableProxy implements Transferable
  59:   {
  60:     protected boolean isLocal;
  61:     protected Transferable transferable;
  62: 
  63:     TransferableProxy(Transferable t, boolean local)
  64:     {
  65:       this.transferable = t;
  66:       this.isLocal = local;
  67:     }
  68:     
  69:     public DataFlavor[] getTransferDataFlavors()
  70:     {
  71:       return transferable.getTransferDataFlavors();
  72:     }
  73: 
  74:     public boolean isDataFlavorSupported(DataFlavor flavor)
  75:     {
  76:       return transferable.isDataFlavorSupported(flavor);
  77:     }
  78: 
  79:     public Object getTransferData(DataFlavor flavor)
  80:       throws UnsupportedFlavorException, IOException
  81:     {
  82:       return transferable.getTransferData (flavor);
  83:     }
  84:   }
  85: 
  86:   private DropTarget dropTarget;
  87:   private int targetActions;
  88:   private DropTargetContextPeer dtcp;
  89: 
  90:   // package private
  91:   DropTargetContext(DropTarget dropTarget)
  92:   {
  93:     this.dropTarget = dropTarget;
  94:   }
  95: 
  96:   public DropTarget getDropTarget()
  97:   {
  98:     return dropTarget;
  99:   }
 100: 
 101:   public Component getComponent()
 102:   {
 103:     return dropTarget.getComponent();
 104:   }
 105: 
 106:   public void addNotify(DropTargetContextPeer dtcp)
 107:   {
 108:     this.dtcp = dtcp;
 109:   }
 110: 
 111:   public void removeNotify()
 112:   {
 113:     this.dtcp = null;
 114:   }
 115: 
 116:   protected void setTargetActions(int actions)
 117:   {
 118:     targetActions = actions;
 119:   }
 120: 
 121:   protected int getTargetActions()
 122:   {
 123:     return targetActions;
 124:   }
 125: 
 126:   /**
 127:    * Signals that the drop is completed.
 128:    *
 129:    * @exception InvalidDnDOperationException If a drop is not outstanding.
 130:    */
 131:   public void dropComplete(boolean success)
 132:   {
 133:     if (dtcp != null)
 134:       dtcp.dropComplete(success);
 135:   }
 136: 
 137:   protected void acceptDrag(int dragOperation)
 138:   {
 139:     if (dtcp != null)
 140:       dtcp.acceptDrag(dragOperation);
 141:   }
 142: 
 143:   protected void rejectDrag()
 144:   {
 145:     if (dtcp != null)
 146:       dtcp.rejectDrag();
 147:   }
 148: 
 149:   protected void acceptDrop(int dropOperation)
 150:   {
 151:     if (dtcp != null)
 152:       dtcp.acceptDrop(dropOperation);
 153:   }
 154: 
 155:   protected void rejectDrop()
 156:   {
 157:     if (dtcp != null)
 158:       dtcp.rejectDrop();    
 159:   }
 160: 
 161:   protected DataFlavor[] getCurrentDataFlavors()
 162:   {
 163:     if (dtcp != null)
 164:       dtcp.getTransferDataFlavors();
 165:     return null;
 166:   }
 167: 
 168:   protected List getCurrentDataFlavorsAsList()
 169:   {
 170:     return Arrays.asList(getCurrentDataFlavors());
 171:   }
 172: 
 173:   protected boolean isDataFlavorSupported(DataFlavor flavor)
 174:   {
 175:     return getCurrentDataFlavorsAsList().contains(flavor);
 176:   }
 177: 
 178:   /**
 179:    * Return the <code>Transferable</code> operandof this operation.
 180:    *
 181:    * @exception InvalidDnDOperationException If a drag is not outstanding.
 182:    */
 183:   protected Transferable getTransferable() 
 184:     throws InvalidDnDOperationException
 185:   {
 186:     // FIXME: Implement this
 187:     if (dtcp != null)
 188:       return dtcp.getTransferable();
 189:     return null;
 190:   }
 191: 
 192:   protected Transferable createTransferableProxy(Transferable t, boolean local)
 193:   {
 194:     return new TransferableProxy(t, local);
 195:   }
 196: } // class DropTargetContext