001 /* DropTargetDropEvent.java --
002 Copyright (C) 2002, 2006 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 package java.awt.dnd;
039
040 import java.awt.Point;
041 import java.awt.datatransfer.DataFlavor;
042 import java.awt.datatransfer.Transferable;
043 import java.util.List;
044
045 /**
046 * @since 1.2
047 */
048 public class DropTargetDropEvent extends DropTargetEvent
049 {
050 /**
051 * Compatible with JDK 1.2+
052 */
053 private static final long serialVersionUID = -1721911170440459322L;
054
055 private final int dropAction;
056 private final int actions;
057 private final Point location;
058 private final boolean isLocalTx;
059
060 /**
061 * Initializes a <code>DropTargetDropEvent</code>. By default this constructor
062 * assumes that the target is not int same JVM.
063 *
064 * @exception IllegalArgumentException If dropAction is not one of DnDConstants,
065 * actions is not a bitwise mask of DnDConstants, or dtc is null.
066 * @exception NullPointerException If location is null.
067 */
068 public DropTargetDropEvent(DropTargetContext dtc, Point location,
069 int dropAction, int actions)
070 {
071 this(dtc, location, dropAction, actions, false);
072 }
073
074 /**
075 * Initializes a <code>DropTargetDropEvent</code>.
076 *
077 * @exception IllegalArgumentException If dropAction is not one of DnDConstants,
078 * actions is not a bitwise mask of DnDConstants, or dtc is null.
079 * @exception NullPointerException If location is null.
080 */
081 public DropTargetDropEvent(DropTargetContext dtc, Point location,
082 int dropAction, int actions, boolean isLocalTx)
083 {
084 super(dtc);
085
086 if (location == null)
087 throw new NullPointerException();
088
089 if (dtc == null)
090 throw new IllegalArgumentException();
091
092 if (dropAction != DnDConstants.ACTION_NONE
093 && dropAction != DnDConstants.ACTION_COPY
094 && dropAction != DnDConstants.ACTION_MOVE
095 && dropAction != DnDConstants.ACTION_COPY_OR_MOVE
096 && dropAction != DnDConstants.ACTION_LINK
097 && dropAction != DnDConstants.ACTION_REFERENCE)
098 throw new IllegalArgumentException();
099
100 int actionsMask = DnDConstants.ACTION_NONE
101 | DnDConstants.ACTION_COPY
102 | DnDConstants.ACTION_MOVE
103 | DnDConstants.ACTION_COPY_OR_MOVE
104 | DnDConstants.ACTION_LINK
105 | DnDConstants.ACTION_REFERENCE;
106
107 if (~(actions ^ actionsMask) != 0)
108 throw new IllegalArgumentException();
109
110 this.dropAction = dropAction;
111 this.actions = actions;
112 this.location = location;
113 this.isLocalTx = isLocalTx;
114 }
115
116 public Point getLocation()
117 {
118 return location;
119 }
120
121 public DataFlavor[] getCurrentDataFlavors()
122 {
123 return context.getCurrentDataFlavors();
124 }
125
126 public List<DataFlavor> getCurrentDataFlavorsAsList()
127 {
128 return context.getCurrentDataFlavorsAsList();
129 }
130
131 public boolean isDataFlavorSupported(DataFlavor flavor)
132 {
133 return context.isDataFlavorSupported(flavor);
134 }
135
136 public int getSourceActions()
137 {
138 return actions;
139 }
140
141 public int getDropAction()
142 {
143 return dropAction;
144 }
145
146 public Transferable getTransferable()
147 {
148 return context.getTransferable ();
149 }
150
151 public void acceptDrop(int dropAction)
152 {
153 context.acceptDrop(dropAction);
154 }
155
156 public void rejectDrop()
157 {
158 context.rejectDrop();
159 }
160
161 public void dropComplete(boolean success)
162 {
163 context.dropComplete(success);
164 }
165
166 public boolean isLocalTransfer()
167 {
168 return isLocalTx;
169 }
170 } // class DropTargetDropEvent