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: * @author Pavel Dolgov
019: * @version $Revision$
020: */package org.apache.harmony.awt.datatransfer;
021:
022: import java.awt.Point;
023: import java.awt.dnd.DragSourceContext;
024: import java.awt.dnd.DragSourceDragEvent;
025: import java.awt.dnd.DragSourceDropEvent;
026: import java.awt.dnd.DragSourceEvent;
027:
028: /**
029: * Dispatches DragSource events on event dispatch thread
030: * in conjunction with {@link java.awt.EventQueue#invokeLater(Runnable)}
031: */
032: public class DragSourceEventProxy implements Runnable {
033: public static final int DRAG_ENTER = 1;
034: public static final int DRAG_OVER = 2;
035: public static final int DRAG_ACTION_CHANGED = 3;
036: public static final int DRAG_MOUSE_MOVED = 4;
037: public static final int DRAG_EXIT = 5;
038: public static final int DRAG_DROP_END = 6;
039:
040: private final DragSourceContext context;
041:
042: private final int type;
043: private final int userAction;
044: private final int targetActions;
045: private final int x;
046: private final int y;
047: private final int modifiers;
048: private final boolean success;
049:
050: public DragSourceEventProxy(DragSourceContext context, int type,
051: int userAction, int targetActions, Point location,
052: int modifiers) {
053: this .context = context;
054: this .type = type;
055: this .userAction = userAction;
056: this .targetActions = targetActions;
057: this .x = location.x;
058: this .y = location.y;
059: this .modifiers = modifiers;
060: this .success = false;
061: }
062:
063: public DragSourceEventProxy(DragSourceContext context, int type,
064: int userAction, boolean success, Point location,
065: int modifiers) {
066: this .context = context;
067: this .type = type;
068: this .userAction = userAction;
069: this .targetActions = userAction;
070: this .x = location.x;
071: this .y = location.y;
072: this .modifiers = modifiers;
073: this .success = success;
074: }
075:
076: public void run() {
077: switch (type) {
078: case DRAG_ENTER:
079: context.dragEnter(newDragSourceDragEvent());
080: break;
081: case DRAG_OVER:
082: context.dragOver(newDragSourceDragEvent());
083: break;
084: case DRAG_ACTION_CHANGED:
085: context.dropActionChanged(newDragSourceDragEvent());
086: break;
087: case DRAG_MOUSE_MOVED:
088: context.dragMouseMoved(newDragSourceDragEvent());
089: break;
090: case DRAG_EXIT:
091: context.dragExit(new DragSourceEvent(context, x, y));
092: break;
093: case DRAG_DROP_END:
094: context.dragExit(new DragSourceDropEvent(context,
095: userAction, success, x, y));
096: break;
097: }
098: }
099:
100: private DragSourceDragEvent newDragSourceDragEvent() {
101: return new DragSourceDragEvent(context, userAction,
102: targetActions, modifiers, x, y);
103: }
104: }
|