0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.api.visual.action;
0042:
0043: import org.netbeans.api.visual.widget.Widget;
0044:
0045: import java.awt.*;
0046: import java.awt.datatransfer.DataFlavor;
0047: import java.awt.datatransfer.Transferable;
0048: import java.awt.dnd.DropTargetDragEvent;
0049: import java.awt.dnd.DropTargetContext;
0050: import java.awt.dnd.DropTargetDropEvent;
0051: import java.awt.dnd.DropTargetEvent;
0052: import java.awt.event.FocusEvent;
0053: import java.awt.event.KeyEvent;
0054: import java.awt.event.MouseEvent;
0055: import java.awt.event.MouseWheelEvent;
0056: import java.util.ArrayList;
0057: import java.util.Collections;
0058: import java.util.List;
0059:
0060: /**
0061: * This interface is defining an action that is usually assigned to a widget. The action is notified about all Swing events
0062: * related to the widget where the action is assigned.
0063: * <p>
0064: * Events: mouse, mouse-motion, mouse-wheel, drag'n'drop, focus, keyboard.
0065: * <p>
0066: * Each event handler has to return a state of the event processing (represented by WidgetAction.State).
0067: * <p>
0068: * Each Swing event is processed by all actions of all widgets in a scene. The processing can be stopped by consuming the event.
0069: * When processing event for a widget, then all children widget (from the last) of widget are asked for processing first.
0070: * Then finally the event is processed by all actions (from the first to the last) assigned to the widget.
0071: *
0072: * @author David Kaspar
0073: */
0074: public interface WidgetAction {
0075:
0076: /**
0077: * Represents a state of event processing.
0078: */
0079: public static abstract class State {
0080:
0081: /**
0082: * The state that means: The event is not processed by the action and has to be processed by other actions too.
0083: */
0084: public static final State REJECTED = new State() {
0085: public boolean isLockedInChain() {
0086: return false;
0087: }
0088:
0089: public boolean isConsumed() {
0090: return false;
0091: }
0092:
0093: public Widget getLockedWidget() {
0094: return null;
0095: }
0096:
0097: public WidgetAction getLockedAction() {
0098: return null;
0099: }
0100: };
0101:
0102: /**
0103: * The state that means: The event is processed by the action and the processing has to stopped immediately (no other action should processed it).
0104: */
0105: public static final State CONSUMED = new State() {
0106: public boolean isLockedInChain() {
0107: return false;
0108: }
0109:
0110: public boolean isConsumed() {
0111: return true;
0112: }
0113:
0114: public Widget getLockedWidget() {
0115: return null;
0116: }
0117:
0118: public WidgetAction getLockedAction() {
0119: return null;
0120: }
0121: };
0122:
0123: /**
0124: * The state that means: The event is processed by the action and only actions that are in the same chain can process the event too.
0125: */
0126: public static final State CHAIN_ONLY = new State() {
0127: public boolean isLockedInChain() {
0128: return true;
0129: }
0130:
0131: public boolean isConsumed() {
0132: return false;
0133: }
0134:
0135: public Widget getLockedWidget() {
0136: return null;
0137: }
0138:
0139: public WidgetAction getLockedAction() {
0140: return null;
0141: }
0142: };
0143:
0144: /**
0145: * Creates a state that means: The event is processed and the processing has to stopped immediately (no other action should processed it).
0146: * Next event will be processed by the lockedAction on lockedAction first.
0147: * Only if the lockedAction reject the event, then the event will be processed regularly.
0148: * It is used for locking the event processing for a long-term operation like moving, resizing, rectangular selection, ...
0149: * (usually they are using mouse motion events).
0150: */
0151: public static State createLocked(final Widget lockedWidget,
0152: final WidgetAction lockedAction) {
0153: assert lockedWidget != null;
0154: assert lockedAction != null;
0155: return new State() {
0156: public boolean isLockedInChain() {
0157: return false;
0158: }
0159:
0160: public boolean isConsumed() {
0161: return true;
0162: }
0163:
0164: public Widget getLockedWidget() {
0165: return lockedWidget;
0166: }
0167:
0168: public WidgetAction getLockedAction() {
0169: return lockedAction;
0170: }
0171: };
0172: }
0173:
0174: private State() {
0175: }
0176:
0177: /**
0178: * Returns whether the event processing has to be stopped after the processing by the chain where the actions is added.
0179: * @return true if locked in chain
0180: */
0181: public abstract boolean isLockedInChain();
0182:
0183: /**
0184: * Returns whether the event is consumed
0185: * @return true if the event is consumed
0186: */
0187: public abstract boolean isConsumed();
0188:
0189: /**
0190: * Returns whether (and by which widget) the next event has to be processed prior to regular processing.
0191: * @return the locked widget; if null, then there is no prior widget
0192: */
0193: public abstract Widget getLockedWidget();
0194:
0195: /**
0196: * Returns whether (and by which action) the next event has to be processed prior to regular processing.
0197: * @return the locked action; if null, then there is no prior action
0198: */
0199: public abstract WidgetAction getLockedAction();
0200:
0201: }
0202:
0203: /**
0204: * Called for handling a mouseClicked event.
0205: * @param widget the widget where the action is assigned
0206: * @param event the mouse event
0207: * @return the event state
0208: */
0209: public State mouseClicked(Widget widget, WidgetMouseEvent event);
0210:
0211: /**
0212: * Called for handling a mousePressed event.
0213: * @param widget the widget where the action is assigned
0214: * @param event the mouse event
0215: * @return the event state
0216: */
0217: public State mousePressed(Widget widget, WidgetMouseEvent event);
0218:
0219: /**
0220: * Called for handling a mouseReleased event.
0221: * @param widget the widget where the action is assigned
0222: * @param event the mouse event
0223: * @return the event state
0224: */
0225: public State mouseReleased(Widget widget, WidgetMouseEvent event);
0226:
0227: /**
0228: * Called for handling a mouseEntered event.
0229: * @param widget the widget where the action is assigned
0230: * @param event the mouse event
0231: * @return the event state
0232: */
0233: public State mouseEntered(Widget widget, WidgetMouseEvent event);
0234:
0235: /**
0236: * Called for handling a mouseExited event.
0237: * @param widget the widget where the action is assigned
0238: * @param event the mouse event
0239: * @return the event state
0240: */
0241: public State mouseExited(Widget widget, WidgetMouseEvent event);
0242:
0243: /**
0244: * Called for handling a mouseDragged event.
0245: * @param widget the widget where the action is assigned
0246: * @param event the mouse event
0247: * @return the event state
0248: */
0249: public State mouseDragged(Widget widget, WidgetMouseEvent event);
0250:
0251: /**
0252: * Called for handling a mouseMoved event.
0253: * @param widget the widget where the action is assigned
0254: * @param event the mouse event
0255: * @return the event state
0256: */
0257: public State mouseMoved(Widget widget, WidgetMouseEvent event);
0258:
0259: /**
0260: * Called for handling a mouseWheelMoved event.
0261: * @param widget the widget where the action is assigned
0262: * @param event the mouse wheel event
0263: * @return the event state
0264: */
0265: public State mouseWheelMoved(Widget widget,
0266: WidgetMouseWheelEvent event);
0267:
0268: /**
0269: * Called for handling a keyTyped event.
0270: * @param widget the widget where the action is assigned
0271: * @param event the key event
0272: * @return the event state
0273: */
0274: public State keyTyped(Widget widget, WidgetKeyEvent event);
0275:
0276: /**
0277: * Called for handling a keyPressed event.
0278: * @param widget the widget where the action is assigned
0279: * @param event the key event
0280: * @return the event state
0281: */
0282: public State keyPressed(Widget widget, WidgetKeyEvent event);
0283:
0284: /**
0285: * Called for handling a keyReleased event.
0286: * @param widget the widget where the action is assigned
0287: * @param event the key event
0288: * @return the event state
0289: */
0290: public State keyReleased(Widget widget, WidgetKeyEvent event);
0291:
0292: /**
0293: * Called for handling a focusGained event.
0294: * @param widget the widget where the action is assigned
0295: * @param event the focus event
0296: * @return the event state
0297: */
0298: public State focusGained(Widget widget, WidgetFocusEvent event);
0299:
0300: /**
0301: * Called for handling a focusLost event.
0302: * @param widget the widget where the action is assigned
0303: * @param event the focus event
0304: * @return the event state
0305: */
0306: public State focusLost(Widget widget, WidgetFocusEvent event);
0307:
0308: /**
0309: * Called for handling a dragEnter event.
0310: * @param widget the widget where the action is assigned
0311: * @param event the drop target drag event
0312: * @return the event state
0313: */
0314: public State dragEnter(Widget widget,
0315: WidgetDropTargetDragEvent event);
0316:
0317: /**
0318: * Called for handling a dragOver event.
0319: * @param widget the widget where the action is assigned
0320: * @param event the drop target drag event
0321: * @return the event state
0322: */
0323: public State dragOver(Widget widget, WidgetDropTargetDragEvent event);
0324:
0325: /**
0326: * Called for handling a dropActionChanged event.
0327: * @param widget the widget where the action is assigned
0328: * @param event the drop target drag event
0329: * @return the event state
0330: */
0331: public State dropActionChanged(Widget widget,
0332: WidgetDropTargetDragEvent event);
0333:
0334: /**
0335: * Called for handling a dragExit event.
0336: * @param widget the widget where the action is assigned
0337: * @param event the drop target event
0338: * @return the event state
0339: */
0340: public State dragExit(Widget widget, WidgetDropTargetEvent event);
0341:
0342: /**
0343: * Called for handling a drop event.
0344: * @param widget the widget where the action is assigned
0345: * @param event the drop target drop event
0346: * @return the event state
0347: */
0348: public State drop(Widget widget, WidgetDropTargetDropEvent event);
0349:
0350: /**
0351: * An adapter of the widget action. All methods return rejected event state.
0352: */
0353: public static class Adapter implements WidgetAction {
0354:
0355: /**
0356: * Called for handling a mouseClicked event.
0357: * @param widget the widget where the action is assigned
0358: * @param event the mouse event
0359: * @return the event state
0360: */
0361: public State mouseClicked(Widget widget, WidgetMouseEvent event) {
0362: return State.REJECTED;
0363: }
0364:
0365: /**
0366: * Called for handling a mousePressed event.
0367: * @param widget the widget where the action is assigned
0368: * @param event the mouse event
0369: * @return the event state
0370: */
0371: public State mousePressed(Widget widget, WidgetMouseEvent event) {
0372: return State.REJECTED;
0373: }
0374:
0375: /**
0376: * Called for handling a mouseReleased event.
0377: * @param widget the widget where the action is assigned
0378: * @param event the mouse event
0379: * @return the event state
0380: */
0381: public State mouseReleased(Widget widget, WidgetMouseEvent event) {
0382: return State.REJECTED;
0383: }
0384:
0385: /**
0386: * Called for handling a mouseEntered event.
0387: * @param widget the widget where the action is assigned
0388: * @param event the mouse event
0389: * @return the event state
0390: */
0391: public State mouseEntered(Widget widget, WidgetMouseEvent event) {
0392: return State.REJECTED;
0393: }
0394:
0395: /**
0396: * Called for handling a mouseExited event.
0397: * @param widget the widget where the action is assigned
0398: * @param event the mouse event
0399: * @return the event state
0400: */
0401: public State mouseExited(Widget widget, WidgetMouseEvent event) {
0402: return State.REJECTED;
0403: }
0404:
0405: /**
0406: * Called for handling a mouseDragged event.
0407: * @param widget the widget where the action is assigned
0408: * @param event the mouse event
0409: * @return the event state
0410: */
0411: public State mouseDragged(Widget widget, WidgetMouseEvent event) {
0412: return State.REJECTED;
0413: }
0414:
0415: /**
0416: * Called for handling a mouseMoved event.
0417: * @param widget the widget where the action is assigned
0418: * @param event the mouse event
0419: * @return the event state
0420: */
0421: public State mouseMoved(Widget widget, WidgetMouseEvent event) {
0422: return State.REJECTED;
0423: }
0424:
0425: /**
0426: * Called for handling a mouseWheelMoved event.
0427: * @param widget the widget where the action is assigned
0428: * @param event the mouse wheel event
0429: * @return the event state
0430: */
0431: public State mouseWheelMoved(Widget widget,
0432: WidgetMouseWheelEvent event) {
0433: return State.REJECTED;
0434: }
0435:
0436: /**
0437: * Called for handling a keyTyped event.
0438: * @param widget the widget where the action is assigned
0439: * @param event the key event
0440: * @return the event state
0441: */
0442: public State keyTyped(Widget widget, WidgetKeyEvent event) {
0443: return State.REJECTED;
0444: }
0445:
0446: /**
0447: * Called for handling a keyPressed event.
0448: * @param widget the widget where the action is assigned
0449: * @param event the key event
0450: * @return the event state
0451: */
0452: public State keyPressed(Widget widget, WidgetKeyEvent event) {
0453: return State.REJECTED;
0454: }
0455:
0456: /**
0457: * Called for handling a keyReleased event.
0458: * @param widget the widget where the action is assigned
0459: * @param event the key event
0460: * @return the event state
0461: */
0462: public State keyReleased(Widget widget, WidgetKeyEvent event) {
0463: return State.REJECTED;
0464: }
0465:
0466: /**
0467: * Called for handling a focusGained event.
0468: * @param widget the widget where the action is assigned
0469: * @param event the focus event
0470: * @return the event state
0471: */
0472: public State focusGained(Widget widget, WidgetFocusEvent event) {
0473: return State.REJECTED;
0474: }
0475:
0476: /**
0477: * Called for handling a focusLost event.
0478: * @param widget the widget where the action is assigned
0479: * @param event the focus event
0480: * @return the event state
0481: */
0482: public State focusLost(Widget widget, WidgetFocusEvent event) {
0483: return State.REJECTED;
0484: }
0485:
0486: /**
0487: * Called for handling a dragEnter event.
0488: * @param widget the widget where the action is assigned
0489: * @param event the drop target drag event
0490: * @return the event state
0491: */
0492: public State dragEnter(Widget widget,
0493: WidgetDropTargetDragEvent event) {
0494: return State.REJECTED;
0495: }
0496:
0497: /**
0498: * Called for handling a dragOver event.
0499: * @param widget the widget where the action is assigned
0500: * @param event the drop target drag event
0501: * @return the event state
0502: */
0503: public State dragOver(Widget widget,
0504: WidgetDropTargetDragEvent event) {
0505: return State.REJECTED;
0506: }
0507:
0508: /**
0509: * Called for handling a dropActionChanged event.
0510: * @param widget the widget where the action is assigned
0511: * @param event the drop target drag event
0512: * @return the event state
0513: */
0514: public State dropActionChanged(Widget widget,
0515: WidgetDropTargetDragEvent event) {
0516: return State.REJECTED;
0517: }
0518:
0519: /**
0520: * Called for handling a dragExit event.
0521: * @param widget the widget where the action is assigned
0522: * @param event the drop target event
0523: * @return the event state
0524: */
0525: public State dragExit(Widget widget, WidgetDropTargetEvent event) {
0526: return State.REJECTED;
0527: }
0528:
0529: /**
0530: * Called for handling a drop event.
0531: * @param widget the widget where the action is assigned
0532: * @param event the drop target drop event
0533: * @return the event state
0534: */
0535: public State drop(Widget widget, WidgetDropTargetDropEvent event) {
0536: return State.REJECTED;
0537: }
0538:
0539: }
0540:
0541: /**
0542: * An adapter of the widget action. All methods return locked or rejected event state based on a result of isLocked method.
0543: * This is often used for long-term actions like MoveAction.
0544: */
0545: public static abstract class LockedAdapter implements WidgetAction {
0546:
0547: /**
0548: * Called by event handlers to resolve whether they should return locked or rejected event state.
0549: * @return if true, then locked event state is used; if false, then rejected event state is used.
0550: */
0551: protected abstract boolean isLocked();
0552:
0553: /**
0554: * Called for handling a mouseClicked event.
0555: * @param widget the widget where the action is assigned
0556: * @param event the mouse event
0557: * @return the event state
0558: */
0559: public State mouseClicked(Widget widget, WidgetMouseEvent event) {
0560: return isLocked() ? State.createLocked(widget, this )
0561: : State.REJECTED;
0562: }
0563:
0564: /**
0565: * Called for handling a mousePressed event.
0566: * @param widget the widget where the action is assigned
0567: * @param event the mouse event
0568: * @return the event state
0569: */
0570: public State mousePressed(Widget widget, WidgetMouseEvent event) {
0571: return isLocked() ? State.createLocked(widget, this )
0572: : State.REJECTED;
0573: }
0574:
0575: /**
0576: * Called for handling a mouseReleased event.
0577: * @param widget the widget where the action is assigned
0578: * @param event the mouse event
0579: * @return the event state
0580: */
0581: public State mouseReleased(Widget widget, WidgetMouseEvent event) {
0582: return isLocked() ? State.createLocked(widget, this )
0583: : State.REJECTED;
0584: }
0585:
0586: /**
0587: * Called for handling a mouseEntered event.
0588: * @param widget the widget where the action is assigned
0589: * @param event the mouse event
0590: * @return the event state
0591: */
0592: public State mouseEntered(Widget widget, WidgetMouseEvent event) {
0593: return isLocked() ? State.createLocked(widget, this )
0594: : State.REJECTED;
0595: }
0596:
0597: /**
0598: * Called for handling a mouseExited event.
0599: * @param widget the widget where the action is assigned
0600: * @param event the mouse event
0601: * @return the event state
0602: */
0603: public State mouseExited(Widget widget, WidgetMouseEvent event) {
0604: return isLocked() ? State.createLocked(widget, this )
0605: : State.REJECTED;
0606: }
0607:
0608: /**
0609: * Called for handling a mouseDragged event.
0610: * @param widget the widget where the action is assigned
0611: * @param event the mouse event
0612: * @return the event state
0613: */
0614: public State mouseDragged(Widget widget, WidgetMouseEvent event) {
0615: return isLocked() ? State.createLocked(widget, this )
0616: : State.REJECTED;
0617: }
0618:
0619: /**
0620: * Called for handling a mouseMoved event.
0621: * @param widget the widget where the action is assigned
0622: * @param event the mouse event
0623: * @return the event state
0624: */
0625: public State mouseMoved(Widget widget, WidgetMouseEvent event) {
0626: return isLocked() ? State.createLocked(widget, this )
0627: : State.REJECTED;
0628: }
0629:
0630: /**
0631: * Called for handling a mouseWheelMoved event.
0632: * @param widget the widget where the action is assigned
0633: * @param event the mouse wheel event
0634: * @return the event state
0635: */
0636: public State mouseWheelMoved(Widget widget,
0637: WidgetMouseWheelEvent event) {
0638: return isLocked() ? State.createLocked(widget, this )
0639: : State.REJECTED;
0640: }
0641:
0642: /**
0643: * Called for handling a keyTyped event.
0644: * @param widget the widget where the action is assigned
0645: * @param event the key event
0646: * @return the event state
0647: */
0648: public State keyTyped(Widget widget, WidgetKeyEvent event) {
0649: return isLocked() ? State.createLocked(widget, this )
0650: : State.REJECTED;
0651: }
0652:
0653: /**
0654: * Called for handling a keyPressed event.
0655: * @param widget the widget where the action is assigned
0656: * @param event the key event
0657: * @return the event state
0658: */
0659: public State keyPressed(Widget widget, WidgetKeyEvent event) {
0660: return isLocked() ? State.createLocked(widget, this )
0661: : State.REJECTED;
0662: }
0663:
0664: /**
0665: * Called for handling a keyReleased event.
0666: * @param widget the widget where the action is assigned
0667: * @param event the key event
0668: * @return the event state
0669: */
0670: public State keyReleased(Widget widget, WidgetKeyEvent event) {
0671: return isLocked() ? State.createLocked(widget, this )
0672: : State.REJECTED;
0673: }
0674:
0675: /**
0676: * Called for handling a focusGained event.
0677: * @param widget the widget where the action is assigned
0678: * @param event the focus event
0679: * @return the event state
0680: */
0681: public State focusGained(Widget widget, WidgetFocusEvent event) {
0682: return isLocked() ? State.createLocked(widget, this )
0683: : State.REJECTED;
0684: }
0685:
0686: /**
0687: * Called for handling a focusLost event.
0688: * @param widget the widget where the action is assigned
0689: * @param event the focus event
0690: * @return the event state
0691: */
0692: public State focusLost(Widget widget, WidgetFocusEvent event) {
0693: return isLocked() ? State.createLocked(widget, this )
0694: : State.REJECTED;
0695: }
0696:
0697: /**
0698: * Called for handling a dragEnter event.
0699: * @param widget the widget where the action is assigned
0700: * @param event the drop target drag event
0701: * @return the event state
0702: */
0703: public State dragEnter(Widget widget,
0704: WidgetDropTargetDragEvent event) {
0705: return isLocked() ? State.createLocked(widget, this )
0706: : State.REJECTED;
0707: }
0708:
0709: /**
0710: * Called for handling a dragOver event.
0711: * @param widget the widget where the action is assigned
0712: * @param event the drop target drag event
0713: * @return the event state
0714: */
0715: public State dragOver(Widget widget,
0716: WidgetDropTargetDragEvent event) {
0717: return isLocked() ? State.createLocked(widget, this )
0718: : State.REJECTED;
0719: }
0720:
0721: /**
0722: * Called for handling a dropActionChanged event.
0723: * @param widget the widget where the action is assigned
0724: * @param event the drop target drag event
0725: * @return the event state
0726: */
0727: public State dropActionChanged(Widget widget,
0728: WidgetDropTargetDragEvent event) {
0729: return isLocked() ? State.createLocked(widget, this )
0730: : State.REJECTED;
0731: }
0732:
0733: /**
0734: * Called for handling a dragExit event.
0735: * @param widget the widget where the action is assigned
0736: * @param event the drop target event
0737: * @return the event state
0738: */
0739: public State dragExit(Widget widget, WidgetDropTargetEvent event) {
0740: return isLocked() ? State.createLocked(widget, this )
0741: : State.REJECTED;
0742: }
0743:
0744: /**
0745: * Called for handling a drop event.
0746: * @param widget the widget where the action is assigned
0747: * @param event the drop target drop event
0748: * @return the event state
0749: */
0750: public State drop(Widget widget, WidgetDropTargetDropEvent event) {
0751: return isLocked() ? State.createLocked(widget, this )
0752: : State.REJECTED;
0753: }
0754:
0755: }
0756:
0757: /**
0758: * Represents a chain of widget actions.
0759: */
0760: public static final class Chain implements WidgetAction {
0761:
0762: private List<WidgetAction> actions;
0763: private List<WidgetAction> actionsUm;
0764:
0765: /**
0766: * Creates a chain.
0767: */
0768: public Chain() {
0769: actions = new ArrayList<WidgetAction>();
0770: actionsUm = Collections.unmodifiableList(actions);
0771: }
0772:
0773: /**
0774: * Returns a list of actions in the chain.
0775: * @return the lst of actions
0776: */
0777: public List<WidgetAction> getActions() {
0778: return actionsUm;
0779: }
0780:
0781: /**
0782: * Adds an action.
0783: * @param action the action to be added
0784: */
0785: public void addAction(WidgetAction action) {
0786: assert action != null;
0787: actions.add(action);
0788: }
0789:
0790: /**
0791: * Adds an action at a specific index
0792: * @param index the index; the action will be added before the action at the index position
0793: * @param action the action to be added
0794: */
0795: public void addAction(int index, WidgetAction action) {
0796: assert action != null;
0797: actions.add(index, action);
0798: }
0799:
0800: /**
0801: * Removes an action.
0802: * @param action the action
0803: */
0804: public void removeAction(WidgetAction action) {
0805: actions.remove(action);
0806: }
0807:
0808: /**
0809: * Removes an action at specified index.
0810: * @param index the index
0811: */
0812: public void removeAction(int index) {
0813: actions.remove(index);
0814: }
0815:
0816: /**
0817: * Called for handling a mouseClicked event.
0818: * @param widget the widget where the action is assigned
0819: * @param event the mouse event
0820: * @return the event state
0821: */
0822: public State mouseClicked(Widget widget, WidgetMouseEvent event) {
0823: WidgetAction[] actionsArray = actions
0824: .toArray(new WidgetAction[actions.size()]);
0825: State chainState = State.REJECTED;
0826: for (WidgetAction action : actionsArray) {
0827: State state = action.mouseClicked(widget, event);
0828: if (state.isConsumed())
0829: return state;
0830: if (state.isLockedInChain())
0831: chainState = State.CONSUMED;
0832: }
0833: return chainState;
0834: }
0835:
0836: /**
0837: * Called for handling a mousePressed event.
0838: * @param widget the widget where the action is assigned
0839: * @param event the mouse event
0840: * @return the event state
0841: */
0842: public State mousePressed(Widget widget, WidgetMouseEvent event) {
0843: WidgetAction[] actionsArray = actions
0844: .toArray(new WidgetAction[actions.size()]);
0845: State chainState = State.REJECTED;
0846: for (WidgetAction action : actionsArray) {
0847: State state = action.mousePressed(widget, event);
0848: if (state.isConsumed())
0849: return state;
0850: if (state.isLockedInChain())
0851: chainState = State.CONSUMED;
0852: }
0853: return chainState;
0854: }
0855:
0856: /**
0857: * Called for handling a mouseReleased event.
0858: * @param widget the widget where the action is assigned
0859: * @param event the mouse event
0860: * @return the event state
0861: */
0862: public State mouseReleased(Widget widget, WidgetMouseEvent event) {
0863: WidgetAction[] actionsArray = actions
0864: .toArray(new WidgetAction[actions.size()]);
0865: State chainState = State.REJECTED;
0866: for (WidgetAction action : actionsArray) {
0867: State state = action.mouseReleased(widget, event);
0868: if (state.isConsumed())
0869: return state;
0870: if (state.isLockedInChain())
0871: chainState = State.CONSUMED;
0872: }
0873: return chainState;
0874: }
0875:
0876: /**
0877: * Called for handling a mouseEntered event.
0878: * @param widget the widget where the action is assigned
0879: * @param event the mouse event
0880: * @return the event state
0881: */
0882: public State mouseEntered(Widget widget, WidgetMouseEvent event) {
0883: WidgetAction[] actionsArray = actions
0884: .toArray(new WidgetAction[actions.size()]);
0885: State chainState = State.REJECTED;
0886: for (WidgetAction action : actionsArray) {
0887: State state = action.mouseEntered(widget, event);
0888: if (state.isConsumed())
0889: return state;
0890: if (state.isLockedInChain())
0891: chainState = State.CONSUMED;
0892: }
0893: return chainState;
0894: }
0895:
0896: /**
0897: * Called for handling a mouseExited event.
0898: * @param widget the widget where the action is assigned
0899: * @param event the mouse event
0900: * @return the event state
0901: */
0902: public State mouseExited(Widget widget, WidgetMouseEvent event) {
0903: WidgetAction[] actionsArray = actions
0904: .toArray(new WidgetAction[actions.size()]);
0905: State chainState = State.REJECTED;
0906: for (WidgetAction action : actionsArray) {
0907: State state = action.mouseExited(widget, event);
0908: if (state.isConsumed())
0909: return state;
0910: if (state.isLockedInChain())
0911: chainState = State.CONSUMED;
0912: }
0913: return chainState;
0914: }
0915:
0916: /**
0917: * Called for handling a mouseMoved event.
0918: * @param widget the widget where the action is assigned
0919: * @param event the mouse event
0920: * @return the event state
0921: */
0922: public State mouseDragged(Widget widget, WidgetMouseEvent event) {
0923: WidgetAction[] actionsArray = actions
0924: .toArray(new WidgetAction[actions.size()]);
0925: State chainState = State.REJECTED;
0926: for (WidgetAction action : actionsArray) {
0927: State state = action.mouseDragged(widget, event);
0928: if (state.isConsumed())
0929: return state;
0930: if (state.isLockedInChain())
0931: chainState = State.CONSUMED;
0932: }
0933: return chainState;
0934: }
0935:
0936: /**
0937: * Called for handling a mouseWheelMoved event.
0938: * @param widget the widget where the action is assigned
0939: * @param event the mouse wheel event
0940: * @return the event state
0941: */
0942: public State mouseMoved(Widget widget, WidgetMouseEvent event) {
0943: WidgetAction[] actionsArray = actions
0944: .toArray(new WidgetAction[actions.size()]);
0945: State chainState = State.REJECTED;
0946: for (WidgetAction action : actionsArray) {
0947: State state = action.mouseMoved(widget, event);
0948: if (state.isConsumed())
0949: return state;
0950: if (state.isLockedInChain())
0951: chainState = State.CONSUMED;
0952: }
0953: return chainState;
0954: }
0955:
0956: /**
0957: * Called for handling a keyTyped event.
0958: * @param widget the widget where the action is assigned
0959: * @param event the key event
0960: * @return the event state
0961: */
0962: public State mouseWheelMoved(Widget widget,
0963: WidgetMouseWheelEvent event) {
0964: WidgetAction[] actionsArray = actions
0965: .toArray(new WidgetAction[actions.size()]);
0966: State chainState = State.REJECTED;
0967: for (WidgetAction action : actionsArray) {
0968: State state = action.mouseWheelMoved(widget, event);
0969: if (state.isConsumed())
0970: return state;
0971: if (state.isLockedInChain())
0972: chainState = State.CONSUMED;
0973: }
0974: return chainState;
0975: }
0976:
0977: /**
0978: * Called for handling a keyTyped event.
0979: * @param widget the widget where the action is assigned
0980: * @param event the key event
0981: * @return the event state
0982: */
0983: public State keyTyped(Widget widget, WidgetKeyEvent event) {
0984: WidgetAction[] actionsArray = actions
0985: .toArray(new WidgetAction[actions.size()]);
0986: State chainState = State.REJECTED;
0987: for (WidgetAction action : actionsArray) {
0988: State state = action.keyTyped(widget, event);
0989: if (state.isConsumed())
0990: return state;
0991: if (state.isLockedInChain())
0992: chainState = State.CONSUMED;
0993: }
0994: return chainState;
0995: }
0996:
0997: /**
0998: * Called for handling a keyPressed event.
0999: * @param widget the widget where the action is assigned
1000: * @param event the key event
1001: * @return the event state
1002: */
1003: public State keyPressed(Widget widget, WidgetKeyEvent event) {
1004: WidgetAction[] actionsArray = actions
1005: .toArray(new WidgetAction[actions.size()]);
1006: State chainState = State.REJECTED;
1007: for (WidgetAction action : actionsArray) {
1008: State state = action.keyPressed(widget, event);
1009: if (state.isConsumed())
1010: return state;
1011: if (state.isLockedInChain())
1012: chainState = State.CONSUMED;
1013: }
1014: return chainState;
1015: }
1016:
1017: /**
1018: * Called for handling a keyReleased event.
1019: * @param widget the widget where the action is assigned
1020: * @param event the key event
1021: * @return the event state
1022: */
1023: public State keyReleased(Widget widget, WidgetKeyEvent event) {
1024: WidgetAction[] actionsArray = actions
1025: .toArray(new WidgetAction[actions.size()]);
1026: State chainState = State.REJECTED;
1027: for (WidgetAction action : actionsArray) {
1028: State state = action.keyReleased(widget, event);
1029: if (state.isConsumed())
1030: return state;
1031: if (state.isLockedInChain())
1032: chainState = State.CONSUMED;
1033: }
1034: return chainState;
1035: }
1036:
1037: /**
1038: * Called for handling a focusGained event.
1039: * @param widget the widget where the action is assigned
1040: * @param event the focus event
1041: * @return the event state
1042: */
1043: public State focusGained(Widget widget,
1044: WidgetAction.WidgetFocusEvent event) {
1045: WidgetAction[] actionsArray = actions
1046: .toArray(new WidgetAction[actions.size()]);
1047: State chainState = State.REJECTED;
1048: for (WidgetAction action : actionsArray) {
1049: State state = action.focusGained(widget, event);
1050: if (state.isConsumed())
1051: return state;
1052: if (state.isLockedInChain())
1053: chainState = State.CONSUMED;
1054: }
1055: return chainState;
1056: }
1057:
1058: /**
1059: * Called for handling a focusLost event.
1060: * @param widget the widget where the action is assigned
1061: * @param event the focus event
1062: * @return the event state
1063: */
1064: public State focusLost(Widget widget,
1065: WidgetAction.WidgetFocusEvent event) {
1066: WidgetAction[] actionsArray = actions
1067: .toArray(new WidgetAction[actions.size()]);
1068: State chainState = State.REJECTED;
1069: for (WidgetAction action : actionsArray) {
1070: State state = action.focusLost(widget, event);
1071: if (state.isConsumed())
1072: return state;
1073: if (state.isLockedInChain())
1074: chainState = State.CONSUMED;
1075: }
1076: return chainState;
1077: }
1078:
1079: /**
1080: * Called for handling a dragEnter event.
1081: * @param widget the widget where the action is assigned
1082: * @param event the drop target drag event
1083: * @return the event state
1084: */
1085: public State dragEnter(Widget widget,
1086: WidgetDropTargetDragEvent event) {
1087: WidgetAction[] actionsArray = actions
1088: .toArray(new WidgetAction[actions.size()]);
1089: State chainState = State.REJECTED;
1090: for (WidgetAction action : actionsArray) {
1091: State state = action.dragEnter(widget, event);
1092: if (state.isConsumed())
1093: return state;
1094: if (state.isLockedInChain())
1095: chainState = State.CONSUMED;
1096: }
1097: return chainState;
1098: }
1099:
1100: /**
1101: * Called for handling a dragOver event.
1102: * @param widget the widget where the action is assigned
1103: * @param event the drop target drag event
1104: * @return the event state
1105: */
1106: public State dragOver(Widget widget,
1107: WidgetDropTargetDragEvent event) {
1108: WidgetAction[] actionsArray = actions
1109: .toArray(new WidgetAction[actions.size()]);
1110: State chainState = State.REJECTED;
1111: for (WidgetAction action : actionsArray) {
1112: State state = action.dragOver(widget, event);
1113: if (state.isConsumed())
1114: return state;
1115: if (state.isLockedInChain())
1116: chainState = State.CONSUMED;
1117: }
1118: return chainState;
1119: }
1120:
1121: /**
1122: * Called for handling a dropActionChanged event.
1123: * @param widget the widget where the action is assigned
1124: * @param event the drop target drag event
1125: * @return the event state
1126: */
1127: public State dropActionChanged(Widget widget,
1128: WidgetDropTargetDragEvent event) {
1129: WidgetAction[] actionsArray = actions
1130: .toArray(new WidgetAction[actions.size()]);
1131: State chainState = State.REJECTED;
1132: for (WidgetAction action : actionsArray) {
1133: State state = action.dropActionChanged(widget, event);
1134: if (state.isConsumed())
1135: return state;
1136: if (state.isLockedInChain())
1137: chainState = State.CONSUMED;
1138: }
1139: return chainState;
1140: }
1141:
1142: /**
1143: * Called for handling a dragExit event.
1144: * @param widget the widget where the action is assigned
1145: * @param event the drop target event
1146: * @return the event state
1147: */
1148: public State dragExit(Widget widget, WidgetDropTargetEvent event) {
1149: WidgetAction[] actionsArray = actions
1150: .toArray(new WidgetAction[actions.size()]);
1151: State chainState = State.REJECTED;
1152: for (WidgetAction action : actionsArray) {
1153: State state = action.dragExit(widget, event);
1154: if (state.isConsumed())
1155: return state;
1156: if (state.isLockedInChain())
1157: chainState = State.CONSUMED;
1158: }
1159: return chainState;
1160: }
1161:
1162: /**
1163: * Called for handling a drop event.
1164: * @param widget the widget where the action is assigned
1165: * @param event the drop target drop event
1166: * @return the event state
1167: */
1168: public State drop(Widget widget, WidgetDropTargetDropEvent event) {
1169: WidgetAction[] actionsArray = actions
1170: .toArray(new WidgetAction[actions.size()]);
1171: State chainState = State.REJECTED;
1172: for (WidgetAction action : actionsArray) {
1173: State state = action.drop(widget, event);
1174: if (state.isConsumed())
1175: return state;
1176: if (state.isLockedInChain())
1177: chainState = State.CONSUMED;
1178: }
1179: return chainState;
1180: }
1181:
1182: }
1183:
1184: /**
1185: * Represents an widget event.
1186: */
1187: public static interface WidgetEvent {
1188:
1189: /**
1190: * Returns an event id.
1191: * @return the event id
1192: */
1193: public long getEventID();
1194:
1195: }
1196:
1197: /**
1198: * Represents an location event used for controlling mouse location.
1199: */
1200: public static interface WidgetLocationEvent extends WidgetEvent {
1201:
1202: /**
1203: * Returns stored location.
1204: * @return the location
1205: */
1206: public Point getPoint();
1207:
1208: /**
1209: * Sets a new location. This is called by a event provider only.
1210: * Do not call this method unless you know what it does exactly.
1211: * @param point the new location
1212: */
1213: public void setPoint(Point point);
1214:
1215: /**
1216: * Translates the stored location.
1217: * Do not call this method unless you know what it does exactly.
1218: * @param x the x-axis addition
1219: * @param y the y-axis addition
1220: */
1221: public void translatePoint(int x, int y);
1222:
1223: }
1224:
1225: /**
1226: * Represents a mouse event.
1227: */
1228: public static final class WidgetMouseEvent implements
1229: WidgetLocationEvent {
1230:
1231: private long id;
1232: private MouseEvent event;
1233: private int x, y;
1234:
1235: /**
1236: * Creates a mouse event.
1237: * @param id the event id
1238: * @param event the Swing event
1239: */
1240: public WidgetMouseEvent(long id, MouseEvent event) {
1241: this .id = id;
1242: this .event = event;
1243: x = event.getX();
1244: y = event.getY();
1245: }
1246:
1247: /**
1248: * Returns an event id.
1249: * @return the event id
1250: */
1251: public long getEventID() {
1252: return id;
1253: }
1254:
1255: /**
1256: * Returns stored location.
1257: * @return the location
1258: */
1259: public Point getPoint() {
1260: return new Point(x, y);
1261: }
1262:
1263: /**
1264: * Sets a new location. This is called by a event provider only.
1265: * Do not call this method unless you know what it does exactly.
1266: * @param point the new location
1267: */
1268: public void setPoint(Point point) {
1269: x = point.x;
1270: y = point.y;
1271: }
1272:
1273: /**
1274: * Translates the stored location.
1275: * Do not call this method unless you know what it does exactly.
1276: * @param x the x-axis addition
1277: * @param y the y-axis addition
1278: */
1279: public void translatePoint(int x, int y) {
1280: this .x += x;
1281: this .y += y;
1282: }
1283:
1284: /**
1285: * @see MouseEvent
1286: */
1287: public int getClickCount() {
1288: return event.getClickCount();
1289: }
1290:
1291: /**
1292: * @see MouseEvent
1293: */
1294: public int getButton() {
1295: return event.getButton();
1296: }
1297:
1298: /**
1299: * @see MouseEvent
1300: */
1301: public boolean isPopupTrigger() {
1302: return event.isPopupTrigger();
1303: }
1304:
1305: /**
1306: * @see MouseEvent
1307: */
1308: public boolean isShiftDown() {
1309: return event.isShiftDown();
1310: }
1311:
1312: /**
1313: * @see MouseEvent
1314: */
1315: public boolean isControlDown() {
1316: return event.isControlDown();
1317: }
1318:
1319: /**
1320: * @see MouseEvent
1321: */
1322: public boolean isMetaDown() {
1323: return event.isMetaDown();
1324: }
1325:
1326: /**
1327: * @see MouseEvent
1328: */
1329: public boolean isAltDown() {
1330: return event.isAltDown();
1331: }
1332:
1333: /**
1334: * @see MouseEvent
1335: */
1336: public boolean isAltGraphDown() {
1337: return event.isAltGraphDown();
1338: }
1339:
1340: /**
1341: * @see MouseEvent
1342: */
1343: public long getWhen() {
1344: return event.getWhen();
1345: }
1346:
1347: /**
1348: * @see MouseEvent
1349: */
1350: public int getModifiers() {
1351: return event.getModifiers();
1352: }
1353:
1354: /**
1355: * @see MouseEvent
1356: */
1357: public int getModifiersEx() {
1358: return event.getModifiersEx();
1359: }
1360:
1361: }
1362:
1363: public static final class WidgetMouseWheelEvent implements
1364: WidgetLocationEvent {
1365:
1366: private long id;
1367: private MouseWheelEvent event;
1368: private int x, y;
1369:
1370: /**
1371: * Creates a mouse wheel event.
1372: * @param id the event id
1373: * @param event the Swing event
1374: */
1375: public WidgetMouseWheelEvent(long id, MouseWheelEvent event) {
1376: this .id = id;
1377: this .event = event;
1378: x = event.getX();
1379: y = event.getY();
1380: }
1381:
1382: /**
1383: * Returns an event id.
1384: * @return the event id
1385: */
1386: public long getEventID() {
1387: return id;
1388: }
1389:
1390: /**
1391: * Returns stored location.
1392: * @return the location
1393: */
1394: public Point getPoint() {
1395: return new Point(x, y);
1396: }
1397:
1398: /**
1399: * Sets a new location. This is called by a event provider only.
1400: * Do not call this method unless you know what it does exactly.
1401: * @param point the new location
1402: */
1403: public void setPoint(Point point) {
1404: x = point.x;
1405: y = point.y;
1406: }
1407:
1408: /**
1409: * Translates the stored location.
1410: * Do not call this method unless you know what it does exactly.
1411: * @param x the x-axis addition
1412: * @param y the y-axis addition
1413: */
1414: public void translatePoint(int x, int y) {
1415: this .x += x;
1416: this .y += y;
1417: }
1418:
1419: /**
1420: * @see MouseEvent
1421: */
1422: public int getClickCount() {
1423: return event.getClickCount();
1424: }
1425:
1426: /**
1427: * @see MouseEvent
1428: */
1429: public int getButton() {
1430: return event.getButton();
1431: }
1432:
1433: /**
1434: * @see MouseEvent
1435: */
1436: public boolean isPopupTrigger() {
1437: return event.isPopupTrigger();
1438: }
1439:
1440: /**
1441: * @see MouseEvent
1442: */
1443: public boolean isShiftDown() {
1444: return event.isShiftDown();
1445: }
1446:
1447: /**
1448: * @see MouseEvent
1449: */
1450: public boolean isControlDown() {
1451: return event.isControlDown();
1452: }
1453:
1454: /**
1455: * @see MouseEvent
1456: */
1457: public boolean isMetaDown() {
1458: return event.isMetaDown();
1459: }
1460:
1461: /**
1462: * @see MouseEvent
1463: */
1464: public boolean isAltDown() {
1465: return event.isAltDown();
1466: }
1467:
1468: /**
1469: * @see MouseEvent
1470: */
1471: public boolean isAltGraphDown() {
1472: return event.isAltGraphDown();
1473: }
1474:
1475: /**
1476: * @see MouseEvent
1477: */
1478: public long getWhen() {
1479: return event.getWhen();
1480: }
1481:
1482: /**
1483: * @see MouseEvent
1484: */
1485: public int getModifiers() {
1486: return event.getModifiers();
1487: }
1488:
1489: /**
1490: * @see MouseEvent
1491: */
1492: public int getModifiersEx() {
1493: return event.getModifiersEx();
1494: }
1495:
1496: /**
1497: * @see MouseWheelEvent
1498: */
1499: public int getScrollType() {
1500: return event.getScrollType();
1501: }
1502:
1503: /**
1504: * @see MouseWheelEvent
1505: */
1506: public int getScrollAmount() {
1507: return event.getScrollAmount();
1508: }
1509:
1510: /**
1511: * @see MouseWheelEvent
1512: */
1513: public int getWheelRotation() {
1514: return event.getWheelRotation();
1515: }
1516:
1517: /**
1518: * @see MouseWheelEvent
1519: */
1520: public int getUnitsToScroll() {
1521: return event.getUnitsToScroll();
1522: }
1523:
1524: }
1525:
1526: /**
1527: * Represents a key event.
1528: */
1529: public static final class WidgetKeyEvent implements WidgetEvent {
1530:
1531: private long id;
1532: private KeyEvent event;
1533:
1534: /**
1535: * Creates a key event.
1536: * @param id the event id
1537: * @param event the Swing event
1538: */
1539: public WidgetKeyEvent(long id, KeyEvent event) {
1540: this .id = id;
1541: this .event = event;
1542: }
1543:
1544: /**
1545: * Returns an event id.
1546: * @return the event id
1547: */
1548: public long getEventID() {
1549: return id;
1550: }
1551:
1552: /**
1553: * @see KeyEvent
1554: */
1555: public int getKeyCode() {
1556: return event.getKeyCode();
1557: }
1558:
1559: /**
1560: * @see KeyEvent
1561: */
1562: public char getKeyChar() {
1563: return event.getKeyChar();
1564: }
1565:
1566: /**
1567: * @see KeyEvent
1568: */
1569: public int getKeyLocation() {
1570: return event.getKeyLocation();
1571: }
1572:
1573: /**
1574: * @see KeyEvent
1575: */
1576: public boolean isActionKey() {
1577: return event.isActionKey();
1578: }
1579:
1580: /**
1581: * @see KeyEvent
1582: */
1583: public boolean isShiftDown() {
1584: return event.isShiftDown();
1585: }
1586:
1587: /**
1588: * @see KeyEvent
1589: */
1590: public boolean isControlDown() {
1591: return event.isControlDown();
1592: }
1593:
1594: /**
1595: * @see KeyEvent
1596: */
1597: public boolean isMetaDown() {
1598: return event.isMetaDown();
1599: }
1600:
1601: /**
1602: * @see KeyEvent
1603: */
1604: public boolean isAltDown() {
1605: return event.isAltDown();
1606: }
1607:
1608: /**
1609: * @see KeyEvent
1610: */
1611: public boolean isAltGraphDown() {
1612: return event.isAltGraphDown();
1613: }
1614:
1615: /**
1616: * @see KeyEvent
1617: */
1618: public long getWhen() {
1619: return event.getWhen();
1620: }
1621:
1622: /**
1623: * @see KeyEvent
1624: */
1625: public int getModifiers() {
1626: return event.getModifiers();
1627: }
1628:
1629: /**
1630: * @see KeyEvent
1631: */
1632: public int getModifiersEx() {
1633: return event.getModifiersEx();
1634: }
1635:
1636: }
1637:
1638: /**
1639: * Represents a focus event of a scene view.
1640: */
1641: public static final class WidgetFocusEvent implements WidgetEvent {
1642:
1643: private long id;
1644: private FocusEvent event;
1645:
1646: /**
1647: * Creates a focus event.
1648: * @param id the event id
1649: * @param event the Swing event
1650: */
1651: public WidgetFocusEvent(long id, FocusEvent event) {
1652: this .id = id;
1653: this .event = event;
1654: }
1655:
1656: /**
1657: * Returns an event id.
1658: * @return the event id
1659: */
1660: public long getEventID() {
1661: return id;
1662: }
1663:
1664: /**
1665: * @see FocusEvent
1666: */
1667: // TODO
1668: public Object getOppositeComponent() {
1669: return event.getOppositeComponent();
1670: }
1671:
1672: /**
1673: * @see FocusEvent
1674: */
1675: public String paramString() {
1676: return event.paramString();
1677: }
1678:
1679: /**
1680: * @see FocusEvent
1681: */
1682: public boolean isTemporary() {
1683: return event.isTemporary();
1684: }
1685: }
1686:
1687: /**
1688: * Represents a drop target drag event.
1689: */
1690: public static final class WidgetDropTargetDragEvent implements
1691: WidgetLocationEvent {
1692:
1693: private long id;
1694: private DropTargetDragEvent event;
1695: private int x, y;
1696:
1697: /**
1698: * Creates a drop target drag event.
1699: * @param id the event id
1700: * @param event the Swing event
1701: */
1702: public WidgetDropTargetDragEvent(long id,
1703: DropTargetDragEvent event) {
1704: this .id = id;
1705: this .event = event;
1706: Point location = event.getLocation();
1707: x = location.x;
1708: y = location.y;
1709: }
1710:
1711: /**
1712: * Returns an event id.
1713: * @return the event id
1714: */
1715: public long getEventID() {
1716: return id;
1717: }
1718:
1719: /**
1720: * Returns stored location.
1721: * @return the location
1722: */
1723: public Point getPoint() {
1724: return new Point(x, y);
1725: }
1726:
1727: /**
1728: * Sets a new location. This is called by a event provider only.
1729: * Do not call this method unless you know what it does exactly.
1730: * @param point the new location
1731: */
1732: public void setPoint(Point point) {
1733: x = point.x;
1734: y = point.y;
1735: }
1736:
1737: /**
1738: * Translates the stored location.
1739: * Do not call this method unless you know what it does exactly.
1740: * @param x the x-axis addition
1741: * @param y the y-axis addition
1742: */
1743: public void translatePoint(int x, int y) {
1744: this .x += x;
1745: this .y += y;
1746: }
1747:
1748: /**
1749: * @see DropTargetDragEvent
1750: */
1751: public DataFlavor[] getCurrentDataFlavors() {
1752: return event.getCurrentDataFlavors();
1753: }
1754:
1755: /**
1756: * @see DropTargetDragEvent
1757: */
1758: public List<DataFlavor> getCurrentDataFlavorsAsList() {
1759: return event.getCurrentDataFlavorsAsList();
1760: }
1761:
1762: /**
1763: * @see DropTargetDragEvent
1764: */
1765: public boolean isDataFlavorSupported(DataFlavor df) {
1766: return event.isDataFlavorSupported(df);
1767: }
1768:
1769: /**
1770: * @see DropTargetDragEvent
1771: */
1772: public int getSourceActions() {
1773: return event.getSourceActions();
1774: }
1775:
1776: /**
1777: * @see DropTargetDragEvent
1778: */
1779: public int getDropAction() {
1780: return event.getDropAction();
1781: }
1782:
1783: /**
1784: * @see DropTargetDragEvent
1785: */
1786: public Transferable getTransferable() {
1787: return event.getTransferable();
1788: }
1789:
1790: /**
1791: * @see DropTargetDragEvent
1792: */
1793: public DropTargetContext getDropTargetContext() {
1794: return event.getDropTargetContext();
1795: }
1796:
1797: /**
1798: * @see DropTargetDragEvent
1799: */
1800: public void acceptDrag(int dragOperation) {
1801: event.acceptDrag(dragOperation);
1802: }
1803:
1804: /**
1805: * @see DropTargetDragEvent
1806: */
1807: public void rejectDrag() {
1808: event.rejectDrag();
1809: }
1810:
1811: }
1812:
1813: /**
1814: * Represents a drop target drop event.
1815: */
1816: public static final class WidgetDropTargetDropEvent implements
1817: WidgetLocationEvent {
1818:
1819: private long id;
1820: private DropTargetDropEvent event;
1821: private int x, y;
1822:
1823: /**
1824: * Creates a drop target drop event.
1825: * @param id the event id
1826: * @param event the Swing event
1827: */
1828: public WidgetDropTargetDropEvent(long id,
1829: DropTargetDropEvent event) {
1830: this .id = id;
1831: this .event = event;
1832: Point location = event.getLocation();
1833: x = location.x;
1834: y = location.y;
1835: }
1836:
1837: /**
1838: * Returns an event id.
1839: * @return the event id
1840: */
1841: public long getEventID() {
1842: return id;
1843: }
1844:
1845: /**
1846: * Returns stored location.
1847: * @return the location
1848: */
1849: public Point getPoint() {
1850: return new Point(x, y);
1851: }
1852:
1853: /**
1854: * Sets a new location. This is called by a event provider only.
1855: * Do not call this method unless you know what it does exactly.
1856: * @param point the new location
1857: */
1858: public void setPoint(Point point) {
1859: x = point.x;
1860: y = point.y;
1861: }
1862:
1863: /**
1864: * Translates the stored location.
1865: * Do not call this method unless you know what it does exactly.
1866: * @param x the x-axis addition
1867: * @param y the y-axis addition
1868: */
1869: public void translatePoint(int x, int y) {
1870: this .x += x;
1871: this .y += y;
1872: }
1873:
1874: /**
1875: * @see DropTargetDropEvent
1876: */
1877: public DataFlavor[] getCurrentDataFlavors() {
1878: return event.getCurrentDataFlavors();
1879: }
1880:
1881: /**
1882: * @see DropTargetDropEvent
1883: */
1884: public List<DataFlavor> getCurrentDataFlavorsAsList() {
1885: return event.getCurrentDataFlavorsAsList();
1886: }
1887:
1888: /**
1889: * @see DropTargetDropEvent
1890: */
1891: public boolean isDataFlavorSupported(DataFlavor df) {
1892: return event.isDataFlavorSupported(df);
1893: }
1894:
1895: /**
1896: * @see DropTargetDropEvent
1897: */
1898: public int getSourceActions() {
1899: return event.getSourceActions();
1900: }
1901:
1902: /**
1903: * @see DropTargetDropEvent
1904: */
1905: public int getDropAction() {
1906: return event.getDropAction();
1907: }
1908:
1909: /**
1910: * @see DropTargetDropEvent
1911: */
1912: public Transferable getTransferable() {
1913: return event.getTransferable();
1914: }
1915:
1916: /**
1917: * @see DropTargetDropEvent
1918: */
1919: public boolean isLocalTransfer() {
1920: return event.isLocalTransfer();
1921: }
1922:
1923: /**
1924: * @see DropTargetDropEvent
1925: */
1926: public DropTargetContext getDropTargetContext() {
1927: return event.getDropTargetContext();
1928: }
1929:
1930: /**
1931: * @see DropTargetDropEvent
1932: */
1933: public void acceptDrop(int dragOperation) {
1934: event.acceptDrop(dragOperation);
1935: }
1936:
1937: /**
1938: * @see DropTargetDropEvent
1939: */
1940: public void rejectDrop() {
1941: event.rejectDrop();
1942: }
1943:
1944: }
1945:
1946: /**
1947: * Represents a drop target event.
1948: */
1949: public static final class WidgetDropTargetEvent implements
1950: WidgetEvent {
1951:
1952: private long id;
1953: private DropTargetEvent event;
1954:
1955: /**
1956: * Creates a drop target event.
1957: * @param id the event id
1958: * @param event the Swing event
1959: */
1960: public WidgetDropTargetEvent(long id, DropTargetEvent event) {
1961: this .id = id;
1962: this .event = event;
1963: }
1964:
1965: /**
1966: * Returns an event id.
1967: * @return the event id
1968: */
1969: public long getEventID() {
1970: return id;
1971: }
1972:
1973: /**
1974: * @see DropTargetEvent
1975: */
1976: public DropTargetContext getDropTargetContext() {
1977: return event.getDropTargetContext();
1978: }
1979:
1980: }
1981:
1982: }
|