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 Project: dragonwell8_jdk   Author: alibaba   File: SunClipboard.java    License: 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 Project: TencentKona-8   Author: Tencent   File: SunClipboard.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: SunClipboard.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 #5
Source Project: netbeans   Author: apache   File: NbClipboardTimeoutTest.java    License: 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 #6
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 #7
Source Project: Bytecoder   Author: mirkosertic   File: SunClipboard.java    License: 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 #9
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: SunClipboard.java    License: 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 #10
Source Project: hottub   Author: dsrg-uoft   File: SunClipboard.java    License: 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 Project: openjdk-8-source   Author: keerath   File: SunClipboard.java    License: 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 #12
Source Project: openjdk-8   Author: bpupadhyaya   File: SunClipboard.java    License: 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 Project: jdk8u_jdk   Author: JetBrains   File: SunClipboard.java    License: 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 #14
Source Project: jdk8u-jdk   Author: frohoff   File: SunClipboard.java    License: 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 #15
Source Project: jdk8u-dev-jdk   Author: frohoff   File: SunClipboard.java    License: 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 #16
Source Project: netbeans   Author: apache   File: NbClipboard.java    License: 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 #17
Source Project: netbeans   Author: apache   File: NbClipboard.java    License: 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 #18
Source Project: netbeans   Author: apache   File: ExplorerActionsImpl.java    License: 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 #19
Source Project: netbeans   Author: apache   File: ExplorerPanelTest.java    License: 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 #20
Source Project: Bytecoder   Author: mirkosertic   File: SunClipboard.java    License: 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 Project: Bytecoder   Author: mirkosertic   File: SunClipboard.java    License: 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 #22
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 #23
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 #24
Source Project: dragonwell8_jdk   Author: alibaba   File: SunClipboard.java    License: 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 Project: TencentKona-8   Author: Tencent   File: SunClipboard.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: SunClipboard.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 Project: netbeans   Author: apache   File: NbClipboard.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public  FlavorListener[] getFlavorListeners() {
    return new FlavorListener[0];
}
 
Example #29
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SunClipboard.java    License: 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 Project: Bytecoder   Author: mirkosertic   File: SunClipboard.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Set<FlavorListener> getFlavorListeners(AppContext appContext) {
    return (Set<FlavorListener>)appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
}