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 Michael Danilov
019: * @version $Revision$
020: */package java.awt.dnd;
021:
022: import java.awt.event.InputEvent;
023:
024: public class DragSourceDragEvent extends DragSourceEvent {
025:
026: private static final long serialVersionUID = 481346297933902471L;
027: private int userAction;
028: private int targetAction;
029: private int modifiers;
030: private int modifiersEx;
031:
032: public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
033: int action, int modifiers) {
034: super (dsc);
035:
036: initFields(dropAction, action, modifiers);
037: }
038:
039: public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
040: int action, int modifiers, int x, int y) {
041: super (dsc, x, y);
042:
043: initFields(dropAction, action, modifiers);
044: }
045:
046: private void initFields(int dropAction, int action, int modifiers) {
047: userAction = dropAction;
048: targetAction = action;
049: this .modifiers = getInputModifiers(modifiers);
050: this .modifiersEx = modifiers;
051: }
052:
053: public int getUserAction() {
054: return userAction;
055: }
056:
057: public int getTargetActions() {
058: return targetAction;
059: }
060:
061: public int getGestureModifiersEx() {
062: return modifiersEx;
063: }
064:
065: public int getGestureModifiers() {
066: return modifiers;
067: }
068:
069: public int getDropAction() {
070: return (userAction & targetAction & getDragSourceContext()
071: .getSourceActions());
072: }
073:
074: private int getInputModifiers(int modifiersEx) {
075: // TODO: share this code with KeyEvent.getModifiers()
076: int modifiers = 0;
077:
078: if ((modifiersEx & InputEvent.SHIFT_DOWN_MASK) != 0) {
079: modifiers |= InputEvent.SHIFT_MASK;
080: }
081: if ((modifiersEx & InputEvent.CTRL_DOWN_MASK) != 0) {
082: modifiers |= InputEvent.CTRL_MASK;
083: }
084: if ((modifiersEx & InputEvent.META_DOWN_MASK) != 0) {
085: modifiers |= InputEvent.META_MASK;
086: }
087: if ((modifiersEx & InputEvent.ALT_DOWN_MASK) != 0) {
088: modifiers |= InputEvent.ALT_MASK;
089: }
090: if ((modifiersEx & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
091: modifiers |= InputEvent.ALT_GRAPH_MASK;
092: }
093: if ((modifiersEx & InputEvent.BUTTON1_DOWN_MASK) != 0) {
094: modifiers |= InputEvent.BUTTON1_MASK;
095: }
096: if ((modifiersEx & InputEvent.BUTTON2_DOWN_MASK) != 0) {
097: modifiers |= InputEvent.BUTTON2_MASK;
098: }
099: if ((modifiersEx & InputEvent.BUTTON3_DOWN_MASK) != 0) {
100: modifiers |= InputEvent.BUTTON3_MASK;
101: }
102:
103: return modifiers;
104: }
105: }
|