Search in sources :

Example 1 with InvalidDnDOperationException

use of java.awt.dnd.InvalidDnDOperationException in project jna by java-native-access.

the class DragHandler method dragGestureRecognized.

/** Called when a user drag gesture is recognized.  This method is 
     * responsible for initiating the drag operation.
     * @param e event
     */
public void dragGestureRecognized(DragGestureEvent e) {
    if ((e.getDragAction() & supportedActions) != 0 && canDrag(e)) {
        setModifiers(e.getTriggerEvent().getModifiersEx() & KEY_MASK);
        Transferable transferable = getTransferable(e);
        if (transferable == null)
            return;
        try {
            Point srcOffset = new Point(0, 0);
            Icon icon = getDragIcon(e, srcOffset);
            Point origin = e.getDragOrigin();
            // offset of the image origin from the cursor
            imageOffset = new Point(srcOffset.x - origin.x, srcOffset.y - origin.y);
            Icon dragIcon = scaleDragIcon(icon, imageOffset);
            Cursor cursor = null;
            if (dragIcon != null && DragSource.isDragImageSupported()) {
                GraphicsConfiguration gc = e.getComponent().getGraphicsConfiguration();
                e.startDrag(cursor, createDragImage(gc, dragIcon), imageOffset, transferable, this);
            } else {
                if (dragIcon != null) {
                    Point screen = dragSource.getLocationOnScreen();
                    screen.translate(origin.x, origin.y);
                    Point cursorOffset = new Point(-imageOffset.x, -imageOffset.y);
                    ghost = new GhostedDragImage(dragSource, dragIcon, getImageLocation(screen), cursorOffset);
                    ghost.setAlpha(ghostAlpha);
                }
                e.startDrag(cursor, transferable, this);
            }
            dragStarted(e);
            moved = false;
            e.getDragSource().addDragSourceMotionListener(this);
            DragHandler.transferable = transferable;
        } catch (InvalidDnDOperationException ex) {
            if (ghost != null) {
                ghost.dispose();
                ghost = null;
            }
        }
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) Icon(javax.swing.Icon) Cursor(java.awt.Cursor) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 2 with InvalidDnDOperationException

use of java.awt.dnd.InvalidDnDOperationException in project jdk8u_jdk by JetBrains.

the class XDragSourceContextPeer method startDrag.

protected void startDrag(Transferable transferable, long[] formats, Map formatMap) {
    Component component = getTrigger().getComponent();
    Component c = null;
    XWindowPeer wpeer = null;
    for (c = component; c != null && !(c instanceof Window); c = AWTAccessor.getComponentAccessor().getParent(c)) ;
    if (c instanceof Window) {
        wpeer = (XWindowPeer) c.getPeer();
    }
    if (wpeer == null) {
        throw new InvalidDnDOperationException("Cannot find top-level for the drag source component");
    }
    long xcursor = 0;
    long rootWindow = 0;
    long dragWindow = 0;
    long timeStamp = 0;
    /* Retrieve the X cursor for the drag operation. */
    {
        Cursor cursor = getCursor();
        if (cursor != null) {
            xcursor = XGlobalCursorManager.getCursor(cursor);
        }
    }
    XToolkit.awtLock();
    try {
        if (proxyModeSourceWindow != 0) {
            throw new InvalidDnDOperationException("Proxy drag in progress");
        }
        if (dndInProgress) {
            throw new InvalidDnDOperationException("Drag in progress");
        }
        /* Determine the root window for the drag operation. */
        {
            long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen());
            rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
        }
        dragWindow = XWindow.getXAWTRootWindow().getWindow();
        timeStamp = XToolkit.getCurrentServerTime();
        int dropActions = getDragSourceContext().getSourceActions();
        Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
        while (dragProtocols.hasNext()) {
            XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next();
            try {
                dragProtocol.initializeDrag(dropActions, transferable, formatMap, formats);
            } catch (XException xe) {
                throw (InvalidDnDOperationException) new InvalidDnDOperationException().initCause(xe);
            }
        }
        /* Install X grabs. */
        {
            int status;
            XWindowAttributes wattr = new XWindowAttributes();
            try {
                status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), rootWindow, wattr.pData);
                if (status == 0) {
                    throw new InvalidDnDOperationException("XGetWindowAttributes failed");
                }
                rootEventMask = wattr.get_your_event_mask();
                XlibWrapper.XSelectInput(XToolkit.getDisplay(), rootWindow, rootEventMask | ROOT_EVENT_MASK);
            } finally {
                wattr.dispose();
            }
            XBaseWindow.ungrabInput();
            status = XlibWrapper.XGrabPointer(XToolkit.getDisplay(), rootWindow, 0, GRAB_EVENT_MASK, XConstants.GrabModeAsync, XConstants.GrabModeAsync, XConstants.None, xcursor, timeStamp);
            if (status != XConstants.GrabSuccess) {
                cleanup(timeStamp);
                throwGrabFailureException("Cannot grab pointer", status);
                return;
            }
            status = XlibWrapper.XGrabKeyboard(XToolkit.getDisplay(), rootWindow, 0, XConstants.GrabModeAsync, XConstants.GrabModeAsync, timeStamp);
            if (status != XConstants.GrabSuccess) {
                cleanup(timeStamp);
                throwGrabFailureException("Cannot grab keyboard", status);
                return;
            }
        }
        /* Update the global state. */
        dndInProgress = true;
        dragInProgress = true;
        dragRootWindow = rootWindow;
        sourceActions = dropActions;
        sourceFormats = formats;
    } finally {
        XToolkit.awtUnlock();
    }
    /* This implementation doesn't use native context */
    setNativeContext(0);
    SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable);
}
Also used : Window(java.awt.Window) InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Component(java.awt.Component) Cursor(java.awt.Cursor)

Example 3 with InvalidDnDOperationException

use of java.awt.dnd.InvalidDnDOperationException in project jdk8u_jdk by JetBrains.

the class WDragSourceContextPeer method startDrag.

protected void startDrag(Transferable trans, long[] formats, Map formatMap) {
    long nativeCtxtLocal = 0;
    nativeCtxtLocal = createDragSource(getTrigger().getComponent(), trans, getTrigger().getTriggerEvent(), getTrigger().getSourceAsDragGestureRecognizer().getSourceActions(), formats, formatMap);
    if (nativeCtxtLocal == 0) {
        throw new InvalidDnDOperationException("failed to create native peer");
    }
    int[] imageData = null;
    Point op = null;
    Image im = getDragImage();
    int imageWidth = -1;
    int imageHeight = -1;
    if (im != null) {
        //image is ready (partial images are ok)
        try {
            imageWidth = im.getWidth(null);
            imageHeight = im.getHeight(null);
            if (imageWidth < 0 || imageHeight < 0) {
                throw new InvalidDnDOperationException("drag image is not ready");
            }
            //We could get an exception from user code here.
            //"im" and "dragImageOffset" are user-defined objects
            //op could not be null here
            op = getDragImageOffset();
            BufferedImage bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
            bi.getGraphics().drawImage(im, 0, 0, null);
            //we can get out-of-memory here
            imageData = ((DataBufferInt) bi.getData().getDataBuffer()).getData();
        } catch (Throwable ex) {
            throw new InvalidDnDOperationException("drag image creation problem: " + ex.getMessage());
        }
    }
    //We shouldn't have user-level exceptions since now.
    //Any exception leads to corrupted D'n'D state.
    setNativeContext(nativeCtxtLocal);
    WDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(trans);
    if (imageData != null) {
        doDragDrop(getNativeContext(), getCursor(), imageData, imageWidth, imageHeight, op.x, op.y);
    } else {
        doDragDrop(getNativeContext(), getCursor(), null, -1, -1, 0, 0);
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Point(java.awt.Point) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage)

Example 4 with InvalidDnDOperationException

use of java.awt.dnd.InvalidDnDOperationException in project jdk8u_jdk by JetBrains.

the class SunDragSourceContextPeer method startDrag.

/**
     * initiate a DnD operation ...
     */
public void startDrag(DragSourceContext dsc, Cursor c, Image di, Point p) throws InvalidDnDOperationException {
    /* Fix for 4354044: don't initiate a drag if event sequence provided by
         * DragGestureRecognizer is empty */
    if (getTrigger().getTriggerEvent() == null) {
        throw new InvalidDnDOperationException("DragGestureEvent has a null trigger");
    }
    dragSourceContext = dsc;
    cursor = c;
    sourceActions = getDragSourceContext().getSourceActions();
    dragImage = di;
    dragImageOffset = p;
    Transferable transferable = getDragSourceContext().getTransferable();
    SortedMap<Long, DataFlavor> formatMap = DataTransferer.getInstance().getFormatsForTransferable(transferable, DataTransferer.adaptFlavorMap(getTrigger().getDragSource().getFlavorMap()));
    long[] formats = DataTransferer.getInstance().keysToLongArray(formatMap);
    startDrag(transferable, formats, formatMap);
    /*
         * Fix for 4613903.
         * Filter out all mouse events that are currently on the event queue.
         */
    discardingMouseEvents = true;
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            discardingMouseEvents = false;
        }
    });
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Transferable(java.awt.datatransfer.Transferable) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 5 with InvalidDnDOperationException

use of java.awt.dnd.InvalidDnDOperationException in project freeplane by freeplane.

the class MNodeDragListener method dragGestureRecognized.

public void dragGestureRecognized(final DragGestureEvent e) {
    final MainView mainView = (MainView) e.getComponent();
    final NodeView nodeView = mainView.getNodeView();
    final MapView mapView = nodeView.getMap();
    mapView.select();
    if (!nodeView.isSelected()) {
        nodeView.getMap().getModeController().getController().getSelection().selectAsTheOnlyOneSelected(nodeView.getModel());
    }
    Rectangle bounds = new Rectangle(0, 0, mainView.getWidth(), mainView.getHeight());
    if (!bounds.contains(e.getDragOrigin()))
        return;
    final int dragActionType = e.getDragAction();
    if (dragActionType == DnDConstants.ACTION_MOVE) {
        final NodeModel node = nodeView.getModel();
        if (node.isRoot()) {
            if (!isLinkDragEvent(e))
                return;
        }
    }
    final String dragActionName;
    Cursor cursor = getCursorByAction(dragActionType);
    if (isLinkDragEvent(e)) {
        cursor = DragSource.DefaultLinkDrop;
        dragActionName = "LINK";
    } else if ((e.getTriggerEvent().getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        cursor = DragSource.DefaultCopyDrop;
        dragActionName = "COPY";
    } else {
        dragActionName = "MOVE";
    }
    final Transferable t = ClipboardController.getController().copy(Controller.getCurrentController().getSelection());
    ((MindMapNodesSelection) t).setDropAction(dragActionName);
    try {
        e.startDrag(cursor, t, new DragSourceListener() {

            public void dragDropEnd(final DragSourceDropEvent dsde) {
            }

            public void dragEnter(final DragSourceDragEvent e) {
            }

            public void dragExit(final DragSourceEvent dse) {
            }

            public void dragOver(final DragSourceDragEvent dsde) {
            }

            public void dropActionChanged(final DragSourceDragEvent dsde) {
                dsde.getDragSourceContext().setCursor(getCursorByAction(dsde.getUserAction()));
            }
        });
    } catch (final InvalidDnDOperationException ex) {
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) MainView(org.freeplane.view.swing.map.MainView) DragSourceDragEvent(java.awt.dnd.DragSourceDragEvent) Rectangle(java.awt.Rectangle) Transferable(java.awt.datatransfer.Transferable) NodeView(org.freeplane.view.swing.map.NodeView) Cursor(java.awt.Cursor) DragSourceListener(java.awt.dnd.DragSourceListener) DragSourceEvent(java.awt.dnd.DragSourceEvent) NodeModel(org.freeplane.features.map.NodeModel) MapView(org.freeplane.view.swing.map.MapView) DragSourceDropEvent(java.awt.dnd.DragSourceDropEvent) MindMapNodesSelection(org.freeplane.features.clipboard.MindMapNodesSelection)

Aggregations

InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)7 Transferable (java.awt.datatransfer.Transferable)5 Cursor (java.awt.Cursor)3 Point (java.awt.Point)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 IOException (java.io.IOException)2 AudioClip (blue.score.layers.audio.core.AudioClip)1 AudioLayer (blue.score.layers.audio.core.AudioLayer)1 AudioLayerGroup (blue.score.layers.audio.core.AudioLayerGroup)1 Component (java.awt.Component)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 Image (java.awt.Image)1 Rectangle (java.awt.Rectangle)1 Window (java.awt.Window)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 DragSourceDragEvent (java.awt.dnd.DragSourceDragEvent)1 DragSourceDropEvent (java.awt.dnd.DragSourceDropEvent)1 DragSourceEvent (java.awt.dnd.DragSourceEvent)1 DragSourceListener (java.awt.dnd.DragSourceListener)1 BufferedImage (java.awt.image.BufferedImage)1