java.awt.datatransfer.FlavorEvent Java Examples

The following examples show how to use java.awt.datatransfer.FlavorEvent. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: NbClipboard.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void flavorsChanged(FlavorEvent e) {
    if( !anyWindowIsActivated )
        return; //#227236 - don't react to system clipboard changes when the IDE window is in the background
    fireChange();
}
 
Example #7
Source File: ExplorerActionsImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void flavorsChanged(FlavorEvent ev) {
    schedule();
}
 
Example #8
Source File: MMDGraphEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void flavorsChanged(@Nonnull final FlavorEvent e) {
  processClipboardChange((Clipboard) e.getSource());
}