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(); }
/** * 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); } } } } }
/** 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(); } }); }
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); } }
@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); } }
public void flavorsChanged(FlavorEvent e) /* 92: */ { /* 93:106 */ JComponent c = TextActions.this.getFocusOwner(); /* 94:107 */ if ((c instanceof JTextComponent)) { /* 95:108 */ TextActions.this.updateTextActions((JTextComponent)c); /* 96: */ } /* 97: */ }
@Override public void flavorsChanged(final FlavorEvent e) { try { final Transferable transfer = clipboard.getContents(null); final DataFlavor[] transferDataFlavors = transfer.getTransferDataFlavors(); for (final DataFlavor dataFlavor : transferDataFlavors) { if (dataFlavor.equals(DataFlavor.stringFlavor)) { this.setEnabled(true); return; } } } catch (final Exception e1) { } this.setEnabled(false); }
@Override public void flavorsChanged(FlavorEvent flavorEvent) { System.out.println("Clipboard update detected (Flavor)"); int[] currentRevision = ClipboardManager.getInstance().getCurrentRevision(); regainOwnershipAndBroadcast(currentRevision); }
@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(); }
@Override public void flavorsChanged(FlavorEvent ev) { schedule(); }
@Override public void flavorsChanged(FlavorEvent e) { //System.out.println("----------> flavors changed"); this.clipboardUpdated = true; }
@Override public void flavorsChanged(@Nonnull final FlavorEvent e) { processClipboardChange((Clipboard) e.getSource()); }
@Override public void flavorsChanged(FlavorEvent e) { adjustPasteMenuItem(); }
@Override public void flavorsChanged(FlavorEvent e) { if(reactToClipboard) PasteAction.this.contextChanged(); }