Search in sources :

Example 1 with EventListenerAggregate

use of sun.awt.EventListenerAggregate in project jdk8u_jdk by JetBrains.

the class SunClipboard method removeFlavorListener.

public synchronized void removeFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    AppContext appContext = AppContext.getAppContext();
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate) appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    if (contextFlavorListeners == null) {
        //else we throw NullPointerException, but it is forbidden
        return;
    }
    if (contextFlavorListeners.remove(listener) && --numberOfFlavorListeners == 0) {
        unregisterClipboardViewerChecked();
        currentFormats = null;
    }
}
Also used : EventListenerAggregate(sun.awt.EventListenerAggregate) AppContext(sun.awt.AppContext)

Example 2 with EventListenerAggregate

use of sun.awt.EventListenerAggregate in project jdk8u_jdk by JetBrains.

the class Clipboard method addFlavorListener.

/**
     * Registers the specified <code>FlavorListener</code> to receive
     * <code>FlavorEvent</code>s from this clipboard.
     * If <code>listener</code> is <code>null</code>, no exception
     * is thrown and no action is performed.
     *
     * @param listener the listener to be added
     *
     * @see #removeFlavorListener
     * @see #getFlavorListeners
     * @see FlavorListener
     * @see FlavorEvent
     * @since 1.5
     */
public synchronized void addFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    if (flavorListeners == null) {
        currentDataFlavors = getAvailableDataFlavorSet();
        flavorListeners = new EventListenerAggregate(FlavorListener.class);
    }
    flavorListeners.add(listener);
}
Also used : EventListenerAggregate(sun.awt.EventListenerAggregate)

Example 3 with EventListenerAggregate

use of sun.awt.EventListenerAggregate in project jdk8u_jdk by JetBrains.

the class SunClipboard method checkChange.

/**
     * Checks change of the <code>DataFlavor</code>s and, if necessary,
     * posts notifications on <code>FlavorEvent</code>s to the
     * AppContexts' EDTs.
     * The parameter <code>formats</code> is null iff we have just
     * failed to get formats available on the clipboard.
     *
     * @param formats data formats that have just been retrieved from
     *        this clipboard
     */
protected final void checkChange(final long[] formats) {
    if (Arrays.equals(formats, currentFormats)) {
        // don't notify
        return;
    }
    currentFormats = formats;
    class SunFlavorChangeNotifier implements Runnable {

        private final FlavorListener flavorListener;

        SunFlavorChangeNotifier(FlavorListener flavorListener) {
            this.flavorListener = flavorListener;
        }

        public void run() {
            if (flavorListener != null) {
                flavorListener.flavorsChanged(new FlavorEvent(SunClipboard.this));
            }
        }
    }
    ;
    for (Iterator it = AppContext.getAppContexts().iterator(); it.hasNext(); ) {
        AppContext appContext = (AppContext) it.next();
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        EventListenerAggregate flavorListeners = (EventListenerAggregate) appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
        if (flavorListeners != null) {
            FlavorListener[] flavorListenerArray = (FlavorListener[]) flavorListeners.getListenersInternal();
            for (int i = 0; i < flavorListenerArray.length; i++) {
                SunToolkit.postEvent(appContext, new PeerEvent(this, new SunFlavorChangeNotifier(flavorListenerArray[i]), PeerEvent.PRIORITY_EVENT));
            }
        }
    }
}
Also used : EventListenerAggregate(sun.awt.EventListenerAggregate) FlavorEvent(java.awt.datatransfer.FlavorEvent) PeerEvent(sun.awt.PeerEvent) AppContext(sun.awt.AppContext) Iterator(java.util.Iterator) FlavorListener(java.awt.datatransfer.FlavorListener)

Example 4 with EventListenerAggregate

use of sun.awt.EventListenerAggregate in project jdk8u_jdk by JetBrains.

the class SunClipboard method addFlavorListener.

public synchronized void addFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    AppContext appContext = AppContext.getAppContext();
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate) appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    if (contextFlavorListeners == null) {
        contextFlavorListeners = new EventListenerAggregate(FlavorListener.class);
        appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, contextFlavorListeners);
    }
    contextFlavorListeners.add(listener);
    if (numberOfFlavorListeners++ == 0) {
        long[] currentFormats = null;
        try {
            openClipboard(null);
            currentFormats = getClipboardFormats();
        } catch (final IllegalStateException ignored) {
        } finally {
            closeClipboard();
        }
        this.currentFormats = currentFormats;
        registerClipboardViewerChecked();
    }
}
Also used : EventListenerAggregate(sun.awt.EventListenerAggregate) AppContext(sun.awt.AppContext) FlavorListener(java.awt.datatransfer.FlavorListener)

Aggregations

EventListenerAggregate (sun.awt.EventListenerAggregate)4 AppContext (sun.awt.AppContext)3 FlavorListener (java.awt.datatransfer.FlavorListener)2 FlavorEvent (java.awt.datatransfer.FlavorEvent)1 Iterator (java.util.Iterator)1 PeerEvent (sun.awt.PeerEvent)1