|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.netbeans.agent; |
| 20 | + |
| 21 | +import java.awt.datatransfer.Clipboard; |
| 22 | +import java.awt.datatransfer.ClipboardOwner; |
| 23 | +import java.awt.datatransfer.Transferable; |
| 24 | +import java.io.IOException; |
| 25 | +import javax.swing.JTextField; |
| 26 | +import org.netbeans.agent.hooks.api.TrackingHooks; |
| 27 | +import org.netbeans.agent.hooks.api.TrackingHooks.Hooks; |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + * @author lahvac |
| 32 | + */ |
| 33 | +public class TestClipboard { |
| 34 | + public static void main(String... args) throws IOException { |
| 35 | + Clipboard testClipboard = new Clipboard("test") { |
| 36 | + @Override |
| 37 | + public void setContents(Transferable contents, ClipboardOwner owner) { |
| 38 | + System.err.println("setContents"); |
| 39 | + } |
| 40 | + @Override |
| 41 | + public Transferable getContents(Object requestor) { |
| 42 | + System.err.println("getContents"); |
| 43 | + return null; |
| 44 | + } |
| 45 | + }; |
| 46 | + TrackingHooks.register(new TrackingHooks() { |
| 47 | + @Override |
| 48 | + protected Clipboard getClipboard() { |
| 49 | + return testClipboard; |
| 50 | + } |
| 51 | + }, 0, Hooks.CLIPBOARD); |
| 52 | + JTextField textField = new JTextField("test"); |
| 53 | + textField.getCaret().setDot(0); |
| 54 | + textField.getCaret().moveDot(1); |
| 55 | + System.err.println("going to copy:"); |
| 56 | + textField.copy(); |
| 57 | + System.err.println("going to cut:"); |
| 58 | + textField.cut(); |
| 59 | + System.err.println("going to paste:"); |
| 60 | + textField.paste(); |
| 61 | + } |
| 62 | +} |
0 commit comments