java类java.awt.datatransfer.FlavorListener的实例源码

NbClipboardTimeoutTest.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
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();
}
SunClipboard.java 文件源码 项目:OpenJSharp 阅读 22 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:jdk8u-jdk 阅读 36 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
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();
    }
}
SunClipboard.java 文件源码 项目:openjdk-jdk10 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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);
                }
            }
        }
    }
}
SunClipboard.java 文件源码 项目:openjdk9 阅读 26 收藏 0 点赞 0 评论 0
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();
    }
}
SunClipboard.java 文件源码 项目:jdk8u_jdk 阅读 27 收藏 0 点赞 0 评论 0
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;
    }
}
GUIClipboard.java 文件源码 项目:Prism-gsoc16 阅读 22 收藏 0 点赞 0 评论 0
/** Creates a new instance of GUIClipboard */
public GUIClipboard(GUIPrism pr)
{
    super(pr, false);
    this.prism = pr;
    initComponents();
    doUndoManagerEnables();
    doClipboardEnables();

    /* Listen to clipboard events. */
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.addFlavorListener(new FlavorListener() {
        public void flavorsChanged(FlavorEvent e) {
            doClipboardEnables();
        }
    });
}
SunClipboard.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 28 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:infobip-open-jdk-8 阅读 27 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:jdk8u-dev-jdk 阅读 27 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:jdk7-jdk 阅读 26 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk-source-code-learn 阅读 22 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:OLD-OpenJDK8 阅读 22 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 26 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk-icedtea7 阅读 30 收藏 0 点赞 0 评论 0
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;
    }
}
NbClipboard.java 文件源码 项目:incubator-netbeans 阅读 26 收藏 0 点赞 0 评论 0
@Override
public synchronized void addFlavorListener(FlavorListener listener) {
    Boolean prev = FIRING.get();
    try {
        FIRING.set(true);
        super.addFlavorListener(listener); 
    } finally {
        FIRING.set(prev);
    }
}
NbClipboard.java 文件源码 项目:incubator-netbeans 阅读 25 收藏 0 点赞 0 评论 0
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);
    }
}
ExplorerActionsImpl.java 文件源码 项目:incubator-netbeans 阅读 30 收藏 0 点赞 0 评论 0
private void registerListener() {
    if (flavL == null) {
        Clipboard c = getClipboard();
        if (c != null) {
            flavL = WeakListeners.create(FlavorListener.class, this, c);
            c.addFlavorListener(flavL);
        }
    }
}
ExplorerPanelTest.java 文件源码 项目:incubator-netbeans 阅读 27 收藏 0 点赞 0 评论 0
@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);
    }
}
SunClipboard.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk9 阅读 38 收藏 0 点赞 0 评论 0
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;
    }
}
SunClipboard.java 文件源码 项目:openjdk9 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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);
                }
            }
        }
    }
}
PasteAction.java 文件源码 项目:JRLib 阅读 28 收藏 0 点赞 0 评论 0
public PasteAction(Lookup context) {
    super(context, ClipboardUtil.Pasteable.class);
    setDisplayName(Bundle.CTL_PasteAction());
    setSmallIconPath(IMG_16);
    setLargeIconPath(IMG_32);

    cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    if(cb == null) {
        logger.warning("SystemClipboard not found! CopyAction will be disabled!");
    } else {
        cb.addFlavorListener(WeakListeners.create(FlavorListener.class, cbListener, cb));
    }
}
NbClipboard.java 文件源码 项目:incubator-netbeans 阅读 27 收藏 0 点赞 0 评论 0
@Override
public  FlavorListener[] getFlavorListeners() {
    return new FlavorListener[0];
}
SunClipboard.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
SunClipboard.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
public synchronized FlavorListener[] getFlavorListeners() {
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            AppContext.getAppContext().get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    return contextFlavorListeners == null ? new FlavorListener[0] :
            (FlavorListener[])contextFlavorListeners.getListenersCopy();
}
SunClipboard.java 文件源码 项目:openjdk-jdk10 阅读 33 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private Set<FlavorListener> getFlavorListeners(AppContext appContext) {
    return (Set<FlavorListener>)appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
}
SunClipboard.java 文件源码 项目:openjdk-jdk10 阅读 31 收藏 0 点赞 0 评论 0
public synchronized FlavorListener[] getFlavorListeners() {
    Set<FlavorListener> flavorListeners = getFlavorListeners(AppContext.getAppContext());
    return flavorListeners == null ? new FlavorListener[0]
            : flavorListeners.toArray(new FlavorListener[flavorListeners.size()]);
}
SunClipboard.java 文件源码 项目:openjdk9 阅读 24 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private Set<FlavorListener> getFlavorListeners(AppContext appContext) {
    return (Set<FlavorListener>)appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
}


问题


面经


文章

微信
公众号

扫码关注公众号