All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.glass.ui.swt.SWTClipboard Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2012, 2013, Oracle  and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package com.sun.glass.ui.swt;

import com.sun.glass.ui.Pixels;
import com.sun.glass.ui.Clipboard;
import com.sun.glass.ui.SystemClipboard;

import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Set;

import org.eclipse.swt.*;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

class SWTClipboard extends SystemClipboard {
    org.eclipse.swt.dnd.Clipboard clipboard;
    static final String CLIPBOARD_KEY = "SWTClipboard";
    
    //TODO - temporary code to enable multiple transfers on Windows only
    static final boolean MULTIPLE_TRANSFERS = SWT.getPlatform().equals("win32");
    
    // Define local constants to avoid name conflicts
    static final int DROP_NONE = org.eclipse.swt.dnd.DND.DROP_NONE;
    static final int DROP_COPY = org.eclipse.swt.dnd.DND.DROP_COPY;
    static final int DROP_MOVE = org.eclipse.swt.dnd.DND.DROP_MOVE;
    static final int DROP_LINK = org.eclipse.swt.dnd.DND.DROP_LINK;

    private static final boolean MUTIPLE_TRANSFERS = false;
    
    // Define standard transfer types including custom transfers
    static Transfer [] StandardTransfers = new Transfer [] {
        TextTransfer.getInstance(),
        RTFTransfer.getInstance(),
        HTMLTransfer.getInstance(),
        URLTransfer.getInstance(),
        ImageTransfer.getInstance(),
        FileTransfer.getInstance(),
    };
    static Transfer [] CustomTransfers = new Transfer [0];

    public SWTClipboard(String name) {
        super(name);
        //TODO - implement selection clipboard for Linux
        if (name.equals(SYSTEM)) {
            Display display = Display.getDefault();
            clipboard = (org.eclipse.swt.dnd.Clipboard) display.getData(CLIPBOARD_KEY);
            if (clipboard == null) {
                clipboard = new org.eclipse.swt.dnd.Clipboard(display);
                display.setData(CLIPBOARD_KEY, clipboard);
                display.disposeExec(new Runnable() {
                    public void run () {
                        clipboard.dispose();
                    }
                });
            }
        }
    }
    
    static Transfer [] getAllTransfers () {
        Transfer [] transfers = new Transfer[StandardTransfers.length + CustomTransfers.length];
        System.arraycopy(StandardTransfers, 0, transfers, 0, StandardTransfers.length);
        System.arraycopy(CustomTransfers, 0, transfers, StandardTransfers.length, CustomTransfers.length);
        return transfers;
    }
    
    static Transfer getCustomTransfer(String mime) {
        for (int i=0; i data, int supportedActions) {
        int count = 0;
        ImageData imageData = null;
        Set keys = data.keySet();
        Object [] objects = new Object [keys.size()];
        Transfer[] transfers = new Transfer[keys.size()];
        for (String key : keys) {
            Transfer transfer = getTransferType(key);
            if (transfer != null) {
                //TODO - image not done, format wrong, alpha wrong
                if (transfer instanceof ImageTransfer && data.get(key) instanceof Pixels) {
                    Pixels pixels = (Pixels) data.get(key);
                    objects[count] = imageData = SWTApplication.createImageData(pixels);
                } else {
                    objects[count] = data.get(key);
                }
                transfers [count] = transfer;
                count++;
            }
        }
        if (count == 0) return;
        if (count != objects.length) {
            Object [] newObjects = new Object [objects.length];
            System.arraycopy(objects, 0, newObjects, 0, objects.length);
            objects = newObjects;
            Transfer [] newTransfers = new Transfer [transfers.length];
            System.arraycopy(transfers, 0, newTransfers, 0, transfers.length);
            transfers = newTransfers;
        }
        if (clipboard != null) {
            //TODO - setting and empty string to the clipboard causes an exception
            //TODO - clear the contents instead (what about multiple objects?)
            for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy