/** * Constructor for PasteAction */ public PasteAction(Application application) { super(getActionName(), application); // add listener, so that button state would update event if clipboard was filled // by other app Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this); }
public void watchClipboard() { getClipboard().addFlavorListener(new FlavorListener() { public void flavorsChanged(FlavorEvent e) { enable(isSupportedFlavor()); } }); }
import java.awt.Toolkit; import java.awt.datatransfer.FlavorEvent; import java.awt.datatransfer.FlavorListener; public class Main { public static void main(String[] args) throws Exception { Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) { System.out.println("changed!!! " + e.getSource() + " " + e.toString()); } }); Thread.sleep(100000L); } }
import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.FlavorEvent; import java.awt.datatransfer.FlavorListener; public class Test { public static void main(String[] args) throws InterruptedException { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) { System.out.println(e); } }); // sleep forever Object o = new Object(); synchronized (o) { o.wait(); } } }
@Override public void run() { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable contents = cb.getContents(null); cb.addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) { try { System.out.println("Got Data:"+(String)contents.getTransferData(DataFlavor.stringFlavor)); } catch (UnsupportedFlavorException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } }); t.setDaemon(true); t.start(); while (true) Thread.sleep(Long.MAX_VALUE); }
public class NewClass implements FlavorListener, ClipboardOwner{ private Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); public NewClass() { System.out.println("NewClass constructor"); clip.setContents(clip.getContents(null), this); clip.addFlavorListener(this); try { Thread.sleep(100000L); } catch (InterruptedException e) { } } @Override public void flavorsChanged(FlavorEvent e) { System.out.println("ClipBoard Changed!!!"); clip.removeFlavorListener(this); clip.setContents(clip.getContents(null), this); clip.addFlavorListener(this); } @Override public void lostOwnership(Clipboard arg0, Transferable arg1) { System.out.println("ownership losted"); } }
private void registerListener() { if (flavL == null) { Clipboard c = getClipboard(); if (c != null) { flavL = WeakListeners.create(FlavorListener.class, this, c); c.addFlavorListener(flavL); } } }
/** * Starts monitoring the clipboard for files and dynamically enable/disable the specified action accordingly. * The action is initially enabled if the clipboard contains files. * * @param action the action to dynamically enable/disable when files are present/not present */ public ClipboardNotifier(Action action) { this.action = action; // Toggle initial state toggleActionState(); // Monitor clipboard changes ClipboardSupport.getClipboard().addFlavorListener(this); }
NbClipboard( Clipboard systemClipboard ) { super("NBClipboard"); // NOI18N this.systemClipboard = systemClipboard; result = Lookup.getDefault().lookupResult(ExClipboard.Convertor.class); result.addLookupListener(this); systemClipboard.addFlavorListener(this); resultChanged(null); if (System.getProperty("netbeans.slow.system.clipboard.hack") != null) { slowSystemClipboard = Boolean.getBoolean("netbeans.slow.system.clipboard.hack"); // NOI18N } else if (Utilities.isMac()) { slowSystemClipboard = false; } else { slowSystemClipboard = true; } if (System.getProperty("sun.awt.datatransfer.timeout") == null) { // NOI18N System.setProperty("sun.awt.datatransfer.timeout", "1000"); // NOI18N } if (slowSystemClipboard) { Toolkit.getDefaultToolkit().addAWTEventListener( this, AWTEvent.WINDOW_EVENT_MASK); } }
clipboard.addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) {
public TextActions(ApplicationContext context) { this.context = context; markerAction = new javax.swing.AbstractAction() { public void actionPerformed(ActionEvent e) { } }; textComponentCaretListener = new TextComponentCaretListener(); textComponentPCL = new TextComponentPCL(); getClipboard().addFlavorListener(new ClipboardListener()); }
public void run() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.addFlavorListener(new FlavorListener() {
public TextActions(ApplicationContext context) { this.context = context; markerAction = new javax.swing.AbstractAction() { @Override public void actionPerformed(ActionEvent e) { } }; textComponentCaretListener = new TextComponentCaretListener(); textComponentPCL = new TextComponentPCL(); getClipboard().addFlavorListener(new ClipboardListener()); }
setLayout(new BorderLayout()); add(new JScrollPane(textArea)); Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) {
putValue(NAME, "Paste"); final Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) {
cb.addFlavorListener(new FlavorListener() { @Override public void flavorsChanged(FlavorEvent e) {