001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.awt.dnd;
019:
020: import java.awt.Component;
021: import java.awt.Cursor;
022: import java.awt.Image;
023: import java.awt.Point;
024: import java.awt.datatransfer.Transferable;
025: import java.awt.event.InputEvent;
026: import java.util.EventObject;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import org.apache.harmony.awt.internal.nls.Messages;
031:
032: public class DragGestureEvent extends EventObject {
033:
034: private static final long serialVersionUID = 9080172649166731306L;
035:
036: private final DragGestureRecognizer recognizer;
037:
038: private final Point origin;
039:
040: private final List<InputEvent> eventList;
041:
042: private final int action;
043:
044: @SuppressWarnings("unchecked")
045: public DragGestureEvent(DragGestureRecognizer dgr, int act,
046: Point ori, List<? extends InputEvent> evs) {
047: super (dgr);
048:
049: if (dgr.getComponent() == null) {
050: // awt.185=Component is null.
051: throw new IllegalArgumentException(Messages
052: .getString("awt.185")); //$NON-NLS-1$
053: }
054: if (dgr.getDragSource() == null) {
055: // awt.186=DragSource is null.
056: throw new IllegalArgumentException(Messages
057: .getString("awt.186")); //$NON-NLS-1$
058: }
059: if (!DnDConstants.isValidAction(act)) {
060: // awt.184=Invalid action.
061: throw new IllegalArgumentException(Messages
062: .getString("awt.184")); //$NON-NLS-1$
063: }
064: if (ori == null) {
065: // awt.187=Origin is null.
066: throw new IllegalArgumentException(Messages
067: .getString("awt.187")); //$NON-NLS-1$
068: }
069: if (evs == null) {
070: // awt.188=Event list is null.
071: throw new IllegalArgumentException(Messages
072: .getString("awt.188")); //$NON-NLS-1$
073: }
074: if (evs.isEmpty()) {
075: // awt.189=Event list is empty.
076: throw new IllegalArgumentException(Messages
077: .getString("awt.189")); //$NON-NLS-1$
078: }
079:
080: recognizer = dgr;
081: action = act;
082: origin = ori;
083: eventList = (List<InputEvent>) evs;
084: }
085:
086: public DragSource getDragSource() {
087: return recognizer.getDragSource();
088: }
089:
090: public DragGestureRecognizer getSourceAsDragGestureRecognizer() {
091: return recognizer;
092: }
093:
094: public Point getDragOrigin() {
095: return new Point(origin);
096: }
097:
098: public Component getComponent() {
099: return recognizer.getComponent();
100: }
101:
102: public int getDragAction() {
103: return action;
104: }
105:
106: public Object[] toArray(Object[] array) {
107: return eventList.toArray(array);
108: }
109:
110: public Object[] toArray() {
111: return eventList.toArray();
112: }
113:
114: public Iterator<InputEvent> iterator() {
115: return eventList.iterator();
116: }
117:
118: public InputEvent getTriggerEvent() {
119: return recognizer.getTriggerEvent();
120: }
121:
122: public void startDrag(Cursor dragCursor, Transferable transferable)
123: throws InvalidDnDOperationException {
124: DragSourceListener[] listeners = recognizer.dragSource
125: .getDragSourceListeners();
126: DragSourceListener dsl = listeners.length > 0 ? new DragSourceMulticaster(
127: listeners)
128: : null;
129: startDrag(dragCursor, transferable, dsl);
130: }
131:
132: public void startDrag(Cursor dragCursor, Image dragImage,
133: Point imageOffset, Transferable transferable,
134: DragSourceListener dsl) throws InvalidDnDOperationException {
135:
136: recognizer.getDragSource().startDrag(this , dragCursor,
137: dragImage, imageOffset, transferable, dsl);
138: }
139:
140: public void startDrag(Cursor dragCursor, Transferable transferable,
141: DragSourceListener dsl) throws InvalidDnDOperationException {
142:
143: recognizer.getDragSource().startDrag(this, dragCursor,
144: transferable, dsl);
145: }
146:
147: }
|