001 /* DropTargetDragEvent.java -- 002 Copyright (C) 2002, 2004 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.awt.dnd; 040 041 import java.awt.Point; 042 import java.awt.datatransfer.DataFlavor; 043 import java.awt.datatransfer.Transferable; 044 import java.util.List; 045 046 /** 047 * @since 1.2 048 */ 049 public class DropTargetDragEvent extends DropTargetEvent 050 { 051 /** 052 * Compatible with 1.2+ 053 */ 054 private static final long serialVersionUID = -8422265619058953682L; 055 056 private final int dropAction; 057 private final int srcActions; 058 private final Point location; 059 060 /** 061 * Initializes a <code>DropTargetDragEvent</code>. 062 * 063 * @exception IllegalArgumentException If dropAction is not one of DnDConstants, 064 * srcActions is not a bitwise mask of DnDConstants, or dtc is null. 065 * @exception NullPointerException If location is null. 066 */ 067 public DropTargetDragEvent (DropTargetContext context, Point location, 068 int dropAction, int srcActions) 069 { 070 super (context); 071 072 if (location == null) 073 throw new NullPointerException (); 074 075 if (context == null) 076 throw new IllegalArgumentException (); 077 078 if (dropAction != DnDConstants.ACTION_NONE 079 && dropAction != DnDConstants.ACTION_COPY 080 && dropAction != DnDConstants.ACTION_MOVE 081 && dropAction != DnDConstants.ACTION_COPY_OR_MOVE 082 && dropAction != DnDConstants.ACTION_LINK 083 && dropAction != DnDConstants.ACTION_REFERENCE) 084 throw new IllegalArgumentException (); 085 086 int srcActionsMask = DnDConstants.ACTION_NONE 087 | DnDConstants.ACTION_COPY 088 | DnDConstants.ACTION_MOVE 089 | DnDConstants.ACTION_COPY_OR_MOVE 090 | DnDConstants.ACTION_LINK 091 | DnDConstants.ACTION_REFERENCE; 092 093 if (~(srcActions ^ srcActionsMask) != 0) 094 throw new IllegalArgumentException (); 095 096 this.dropAction = dropAction; 097 this.srcActions = srcActions; 098 this.location = location; 099 } 100 101 public void acceptDrag (int dragOperation) 102 { 103 context.acceptDrag (dragOperation); 104 } 105 106 public DataFlavor[] getCurrentDataFlavors () 107 { 108 return context.getCurrentDataFlavors (); 109 } 110 111 public List<DataFlavor> getCurrentDataFlavorsAsList () 112 { 113 return context.getCurrentDataFlavorsAsList (); 114 } 115 116 public int getDropAction() 117 { 118 return dropAction & ((DropTargetContext) source).getTargetActions(); 119 } 120 121 public Point getLocation () 122 { 123 return location; 124 } 125 126 public int getSourceActions () 127 { 128 return srcActions; 129 } 130 131 public boolean isDataFlavorSupported (DataFlavor df) 132 { 133 return context.isDataFlavorSupported (df); 134 } 135 136 public void rejectDrag () 137 { 138 context.rejectDrag (); 139 } 140 141 /** 142 * TODO 143 * 144 * @return 145 * 146 * @since 1.5 147 */ 148 public Transferable getTransferable() 149 { 150 return context.getTransferable(); 151 } 152 } // class DropTargetDragEvent