java.awt.datatransfer.FlavorListener Java Examples

The following examples show how to use java.awt.datatransfer.FlavorListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SunClipboard.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #2
Source File: SunClipboard.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #3
Source File: SunClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #4
Source File: SunClipboard.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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();
        currentDataFlavors = null;
    }
}
 
Example #5
Source File: SunClipboard.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void addFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    AppContext appContext = AppContext.getAppContext();
    Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
    if (flavorListeners == null) {
        flavorListeners = new HashSet<>();
        appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, flavorListeners);
    }
    flavorListeners.add(listener);

    if (numberOfFlavorListeners++ == 0) {
        long[] currentFormats = null;
        try {
            openClipboard(null);
            currentFormats = getClipboardFormats();
        } catch (final IllegalStateException ignored) {
        } finally {
            closeClipboard();
        }
        this.currentFormats = currentFormats;

        registerClipboardViewerChecked();
    }
}
 
Example #6
Source File: SunClipboard.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
        currentDataFlavors = null;
    }
}
 
Example #7
Source File: SunClipboard.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public synchronized void addFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    AppContext appContext = AppContext.getAppContext();
    Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
    if (flavorListeners == null) {
        flavorListeners = new HashSet<>();
        appContext.put(CLIPBOARD_FLAVOR_LISTENER_KEY, flavorListeners);
    }
    flavorListeners.add(listener);

    if (numberOfFlavorListeners++ == 0) {
        long[] currentFormats = null;
        try {
            openClipboard(null);
            currentFormats = getClipboardFormats();
        } catch (final IllegalStateException ignored) {
        } finally {
            closeClipboard();
        }
        this.currentFormats = currentFormats;

        registerClipboardViewerChecked();
    }
}
 
Example #8
Source File: SunClipboard.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #9
Source File: NbClipboardTimeoutTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void makeSureSystemClipboardContainsString(
    Clipboard sys, NbClipboard clip
) throws InterruptedException {
    final CountDownLatch wait = new CountDownLatch(1);
    class FL implements FlavorListener {
        @Override
        public void flavorsChanged(FlavorEvent e) {
            wait.countDown();
        }
    }
    FL fl = new FL();
    sys.addFlavorListener(fl);
    StringSelection ss = new StringSelection("empty");
    clip.setContents(ss, ss);
    wait.await();
}
 
Example #10
Source File: SunClipboard.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #11
Source File: SunClipboard.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #12
Source File: SunClipboard.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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();
        currentDataFlavors = null;
    }
}
 
Example #13
Source File: SunClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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();
        currentDataFlavors = null;
    }
}
 
Example #14
Source File: SunClipboard.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #15
Source File: SunClipboard.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #16
Source File: NbClipboard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final void fireChange() {
    Boolean prev = FIRING.get();
    try {
        FIRING.set(true);
        FlavorEvent e = new FlavorEvent(this);
        fireClipboardChange();
        for (FlavorListener l : super.getFlavorListeners()) {
            l.flavorsChanged(e);
        }
    } finally {
        FIRING.set(prev);
    }
}
 
Example #17
Source File: SunClipboard.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks change of the {@code DataFlavor}s and, if necessary,
 * posts notifications on {@code FlavorEvent}s to the
 * AppContexts' EDTs.
 * The parameter {@code formats} 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)) {
        // we've been able to successfully get available on the clipboard
        // DataFlavors this and previous time and they are coincident;
        // don't notify
        return;
    }
    currentFormats = formats;

    for (final AppContext appContext : AppContext.getAppContexts()) {
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
        if (flavorListeners != null) {
            for (FlavorListener listener : flavorListeners) {
                if (listener != null) {
                    PeerEvent peerEvent = new PeerEvent(this,
                            () -> listener.flavorsChanged(new FlavorEvent(SunClipboard.this)),
                            PeerEvent.PRIORITY_EVENT);
                    SunToolkit.postEvent(appContext, peerEvent);
                }
            }
        }
    }
}
 
Example #18
Source File: SunClipboard.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void removeFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    Set<FlavorListener> flavorListeners = getFlavorListeners(AppContext.getAppContext());
    if (flavorListeners == null){
        //else we throw NullPointerException, but it is forbidden
        return;
    }
    if (flavorListeners.remove(listener) && --numberOfFlavorListeners == 0) {
        unregisterClipboardViewerChecked();
        currentFormats = null;
    }
}
 
Example #19
Source File: SunClipboard.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Checks change of the {@code DataFlavor}s and, if necessary,
 * posts notifications on {@code FlavorEvent}s to the
 * AppContexts' EDTs.
 * The parameter {@code formats} 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)) {
        // we've been able to successfully get available on the clipboard
        // DataFlavors this and previous time and they are coincident;
        // don't notify
        return;
    }
    currentFormats = formats;

    for (final AppContext appContext : AppContext.getAppContexts()) {
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
        if (flavorListeners != null) {
            for (FlavorListener listener : flavorListeners) {
                if (listener != null) {
                    PeerEvent peerEvent = new PeerEvent(this,
                            () -> listener.flavorsChanged(new FlavorEvent(SunClipboard.this)),
                            PeerEvent.PRIORITY_EVENT);
                    SunToolkit.postEvent(appContext, peerEvent);
                }
            }
        }
    }
}
 
Example #20
Source File: SunClipboard.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public synchronized void removeFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    Set<FlavorListener> flavorListeners = getFlavorListeners(AppContext.getAppContext());
    if (flavorListeners == null){
        //else we throw NullPointerException, but it is forbidden
        return;
    }
    if (flavorListeners.remove(listener) && --numberOfFlavorListeners == 0) {
        unregisterClipboardViewerChecked();
        currentFormats = null;
    }
}
 
Example #21
Source File: ExplorerPanelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void setContents (Transferable t, ClipboardOwner o) {
    super.setContents (t, o);
    fireClipboardChange ();
    FlavorEvent ev = new FlavorEvent(this);
    for (FlavorListener flavorListener : getFlavorListeners()) {
        flavorListener.flavorsChanged(ev);
    }
}
 
Example #22
Source File: ExplorerActionsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void registerListener() {
    if (flavL == null) {
        Clipboard c = getClipboard();
        if (c != null) {
            flavL = WeakListeners.create(FlavorListener.class, this, c);
            c.addFlavorListener(flavL);
        }
    }
}
 
Example #23
Source File: NbClipboard.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void addFlavorListener(FlavorListener listener) {
    Boolean prev = FIRING.get();
    try {
        FIRING.set(true);
        super.addFlavorListener(listener); 
    } finally {
        FIRING.set(prev);
    }
}
 
Example #24
Source File: SunClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #25
Source File: SunClipboard.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #26
Source File: SunClipboard.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #27
Source File: SunClipboard.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #28
Source File: SunClipboard.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #29
Source File: SunClipboard.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
 
Example #30
Source File: SunClipboard.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}