@Override
public void actionPerformed(ActionEvent e) {
File f = FileUtil.toFile(
matchingObject.getFileObject());
if (f != null) {
String path = f.getPath();
Clipboard clipboard = Lookup.getDefault().lookup(
ExClipboard.class);
if (clipboard == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit != null) {
clipboard = toolkit.getSystemClipboard();
}
}
if (clipboard != null) {
StringSelection strSel = new StringSelection(path);
clipboard.setContents(strSel, null);
}
}
}
java类java.awt.datatransfer.Clipboard的实例源码
MatchingObjectNode.java 文件源码
项目:incubator-netbeans
阅读 23
收藏 0
点赞 0
评论 0
NbClipboardTimeoutTest.java 文件源码
项目:incubator-netbeans
阅读 34
收藏 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();
}
NbClipboardNativeTest.java 文件源码
项目:incubator-netbeans
阅读 29
收藏 0
点赞 0
评论 0
public void testClipboard() throws Exception {
MockServices.setServices(Cnv.class);
Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
assertEquals("Clipboard == ExClipboard", c, ec);
assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
protected Object getData() throws IOException, UnsupportedFlavorException {
return "17";
}
}, null);
Transferable t = c.getContents(null);
assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
NbClipboardNativeTest.java 文件源码
项目:incubator-netbeans
阅读 26
收藏 0
点赞 0
评论 0
public void testOwnershipLostEvent() throws Exception {
final int[] holder = new int[] { 0 };
ExTransferable transferable = ExTransferable.create (new StringSelection("A"));
// listen on ownershipLost
transferable.addTransferListener (new TransferListener () {
public void accepted (int action) {}
public void rejected () {}
public void ownershipLost () { holder[0]++; }
});
Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
c.setContents(transferable, null);
assertTrue("Still has ownership", holder[0] == 0);
c.setContents(new StringSelection("B"), null);
assertTrue("Exactly one ownershipLost event have happened.", holder[0] == 1);
}
TableDB.java 文件源码
项目:geomapapp
阅读 23
收藏 0
点赞 0
评论 0
void paste() throws IOException {
Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clip.getContents(this);
DataFlavor[] flavors = contents.getTransferDataFlavors();
for( int k=0 ; k<flavors.length ; k++) {
try {
if( flavors[k].getHumanPresentableName().indexOf("html")>=0 )continue;
BufferedReader in = new BufferedReader(
flavors[k].getReaderForText(contents));
System.out.println( flavors[k].getHumanPresentableName());
read( in );
break;
} catch( UnsupportedFlavorException e) {
}
}
}
DebuggingActionsProvider.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
static void stackToCLBD(List<JPDAThread> threads) {
StringBuffer frameStr = new StringBuffer(512);
for (JPDAThread t : threads) {
if (frameStr.length() > 0) {
frameStr.append('\n');
}
frameStr.append("\"");
frameStr.append(t.getName());
frameStr.append("\"\n");
appendStackInfo(frameStr, t);
}
Clipboard systemClipboard = getClipboard();
Transferable transferableText =
new StringSelection(frameStr.toString());
systemClipboard.setContents(
transferableText,
null);
}
YassTable.java 文件源码
项目:Yass
阅读 21
收藏 0
点赞 0
评论 0
/**
* Description of the Method
*
* @param before Description of the Parameter
* @return Description of the Return Value
*/
public int insertRows(boolean before) {
int startRow = before ? getSelectionModel().getMinSelectionIndex()
: getSelectionModel().getMaxSelectionIndex();
if (startRow < 0) {
return 0;
}
if (startRow == 0) {
before = false;
}
String trstring = null;
try {
Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
trstring = (String) (system.getContents(this)
.getTransferData(DataFlavor.stringFlavor));
} catch (Exception e) {
return 0;
}
;
return insertRowsAt(trstring, startRow, before);
}
OutlineView.java 文件源码
项目:incubator-netbeans
阅读 32
收藏 0
点赞 0
评论 0
private void doCopy(ExplorerManager em) {
Node[] sel = em.getSelectedNodes();
Transferable trans = ExplorerActionsImpl.getTransferableOwner(sel, true);
Transferable ot = new OutlineTransferHandler().createOutlineTransferable();
if (trans != null) {
if (ot != null) {
trans = new TextAddedTransferable(trans, ot);
}
} else {
trans = ot;
}
if (trans != null) {
Clipboard clipboard = ExplorerActionsImpl.getClipboard();
if (clipboard != null) {
clipboard.setContents(trans, new StringSelection("")); // NOI18N
}
}
}
Clip.java 文件源码
项目:Logisim
阅读 23
收藏 0
点赞 0
评论 0
public void copy() {
Caret caret = editor.getCaret();
long p0 = caret.getMark();
long p1 = caret.getDot();
if (p0 < 0 || p1 < 0)
return;
if (p0 > p1) {
long t = p0;
p0 = p1;
p1 = t;
}
p1++;
int[] data = new int[(int) (p1 - p0)];
HexModel model = editor.getModel();
for (long i = p0; i < p1; i++) {
data[(int) (i - p0)] = model.get(i);
}
Clipboard clip = editor.getToolkit().getSystemClipboard();
clip.setContents(new Data(data), this);
}
CopyPathToClipboardAction.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
/**
* Sets the clipboard context in textual-format.
*
* @param content
*/
@Messages({
"# {0} - copied file path",
"CTL_Status_CopyToClipboardSingle=Copy to Clipboard: {0}",
"# {0} - number of copied paths",
"CTL_Status_CopyToClipboardMulti={0} paths were copied to clipboard"
})
private void setClipboardContents(String content, int items) {
Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
if (clipboard == null) {
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
if (clipboard != null) {
String statusText = items > 1
? Bundle.CTL_Status_CopyToClipboardMulti(items)
: Bundle.CTL_Status_CopyToClipboardSingle(content);
StatusDisplayer.getDefault().setStatusText(statusText);
clipboard.setContents(new StringSelection(content), null);
}
}
CopySVGMenuItem.java 文件源码
项目:vexillo
阅读 22
收藏 0
点赞 0
评论 0
public CopySVGMenuItem(final FlagFrame frame) {
setText("Copy SVG");
if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_S);
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputUtils.META_SHIFT_MASK));
if (frame == null) {
setEnabled(false);
} else {
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SVGExporter s = new SVGExporter(frame.getFlagFile(), frame.getFlag());
String svg = s.exportToString(frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze());
StringSelection ss = new StringSelection(svg);
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.setContents(ss, ss);
}
});
}
}
HTMLEditor.java 文件源码
项目:Neukoelln_SER316
阅读 27
收藏 0
点赞 0
评论 0
private void doPaste() {
Clipboard clip =
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
try {
Transferable content = clip.getContents(this);
if (content == null)
return;
String txt =
content
.getTransferData(new DataFlavor(String.class, "String"))
.toString();
document.replace(
editor.getSelectionStart(),
editor.getSelectionEnd() - editor.getSelectionStart(),
txt,
editorKit.getInputAttributes());
//editor.replaceSelection(content.getTransferData(new
// DataFlavor(String.class, "String")).toString());
//editor.paste();
//insertHTML(content.getTransferData(new DataFlavor(String.class,
// "String")).toString(), editor.getCaretPosition());
/*
* Element el =
* document.getParagraphElement(editor.getCaretPosition());
* insertTextInElement(el, content.getTransferData(new
* DataFlavor(String.class, "String")).toString(),
*/
} catch (Exception ex) {
ex.printStackTrace();
}
}
NbClipboard.java 文件源码
项目:incubator-netbeans
阅读 26
收藏 0
点赞 0
评论 0
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);
}
}
XToolkit.java 文件源码
项目:openjdk-jdk10
阅读 21
收藏 0
点赞 0
评论 0
@Override
public Clipboard getSystemSelection() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
}
synchronized (this) {
if (selection == null) {
selection = new XClipboard("Selection", "PRIMARY");
}
}
return selection;
}
HTMLEditor.java 文件源码
项目:SER316-Munich
阅读 18
收藏 0
点赞 0
评论 0
private void doCopy() {
/*
* java.awt.datatransfer.Clipboard clip =
* java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try {
* String text = editor.getSelectedText();
* //.getText(editor.getSelectionStart(),
* editor.getSelectionEnd()-editor.getSelectionStart());
* clip.setContents(new java.awt.datatransfer.StringSelection(text),
* null); } catch (Exception e) { e.printStackTrace();
*/
Element el = document.getParagraphElement(editor.getSelectionStart());
if (el.getName().toUpperCase().equals("P-IMPLIED"))
el = el.getParentElement();
String elName = el.getName();
StringWriter sw = new StringWriter();
String copy;
java.awt.datatransfer.Clipboard clip =
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
try {
editorKit.write(
sw,
document,
editor.getSelectionStart(),
editor.getSelectionEnd() - editor.getSelectionStart());
copy = sw.toString();
copy = copy.split("<" + elName + "(.*?)>")[1];
copy = copy.split("</" + elName + ">")[0];
clip.setContents(
new java.awt.datatransfer.StringSelection(copy.trim()),
null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
DebuggingActionsProvider.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
static Clipboard getClipboard() {
Clipboard clipboard = org.openide.util.Lookup.getDefault().lookup(Clipboard.class);
if (clipboard == null) {
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
return clipboard;
}
CallStackActionsProvider.java 文件源码
项目:incubator-netbeans
阅读 19
收藏 0
点赞 0
评论 0
private void stackToCLBD() {
JPDAThread t = debugger.getCurrentThread();
if (t == null) return ;
StringBuffer frameStr = new StringBuffer(50);
DebuggingActionsProvider.appendStackInfo(frameStr, t);
Clipboard systemClipboard = DebuggingActionsProvider.getClipboard();
Transferable transferableText =
new StringSelection(frameStr.toString());
systemClipboard.setContents(
transferableText,
null);
}
EditorCaret.java 文件源码
项目:incubator-netbeans
阅读 20
收藏 0
点赞 0
评论 0
private void updateSystemSelection() {
if(component == null) return;
Clipboard clip = null;
try {
clip = component.getToolkit().getSystemSelection();
} catch (SecurityException ex) {
// XXX: ignore for now, there is no ExClipboard for SystemSelection Clipboard
}
if(clip != null) {
StringBuilder builder = new StringBuilder();
boolean first = true;
List<CaretInfo> sortedCarets = getSortedCarets();
for (CaretInfo caret : sortedCarets) {
CaretItem caretItem = caret.getCaretItem();
if(caretItem.isSelection()) {
if(!first) {
builder.append("\n");
} else {
first = false;
}
builder.append(getSelectedText(caretItem));
}
}
if(builder.length() > 0) {
clip.setContents(new java.awt.datatransfer.StringSelection(builder.toString()), null);
}
}
}
SpikeSoundSignalHandler.java 文件源码
项目:jaer
阅读 21
收藏 0
点赞 0
评论 0
public void do_Copy_trace() {
if (spikeTimesRecord != null) {
StringBuilder sb = new StringBuilder();
sb.append(recordedMinTime+"\t0\n");
for (int i : spikeTimesRecord) {
sb.append(i+"\t0\n"+i+"\t100\n"+i+"\t0\n");
}
sb.append(recordedMaxTime+"\t0\n");
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(sb.toString());
clipboard.setContents(strSel, null);
}
}
ExplorerActionsImpl.java 文件源码
项目:incubator-netbeans
阅读 28
收藏 0
点赞 0
评论 0
/** If our clipboard is not found return the default system clipboard. */
public static Clipboard getClipboard() {
if (GraphicsEnvironment.isHeadless()) {
return null;
}
Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
if (c == null) {
c = Toolkit.getDefaultToolkit().getSystemClipboard();
}
return c;
}
ExplorerActionsImpl.java 文件源码
项目:incubator-netbeans
阅读 26
收藏 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);
}
}
}
DragDropUtilities.java 文件源码
项目:incubator-netbeans
阅读 22
收藏 0
点赞 0
评论 0
/** If our clipboard is not found return the default system clipboard. */
private static Clipboard getClipboard() {
Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
if (c == null) {
c = Toolkit.getDefaultToolkit().getSystemClipboard();
}
return c;
}
UI.java 文件源码
项目:incubator-netbeans
阅读 24
收藏 0
点赞 0
评论 0
private static Clipboard getClipboard() {
Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
if (clipboard == null) {
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
}
return clipboard;
}
HTMLEditor.java 文件源码
项目:SER316-Ingolstadt
阅读 30
收藏 0
点赞 0
评论 0
private void doCopy() {
/*
* java.awt.datatransfer.Clipboard clip =
* java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try {
* String text = editor.getSelectedText();
* //.getText(editor.getSelectionStart(),
* editor.getSelectionEnd()-editor.getSelectionStart());
* clip.setContents(new java.awt.datatransfer.StringSelection(text),
* null); } catch (Exception e) { e.printStackTrace();
*/
Element el = document.getParagraphElement(editor.getSelectionStart());
if (el.getName().toUpperCase().equals("P-IMPLIED"))
el = el.getParentElement();
String elName = el.getName();
StringWriter sw = new StringWriter();
String copy;
java.awt.datatransfer.Clipboard clip =
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
try {
editorKit.write(
sw,
document,
editor.getSelectionStart(),
editor.getSelectionEnd() - editor.getSelectionStart());
copy = sw.toString();
copy = copy.split("<" + elName + "(.*?)>")[1];
copy = copy.split("</" + elName + ">")[0];
clip.setContents(
new java.awt.datatransfer.StringSelection(copy.trim()),
null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
WToolkit.java 文件源码
项目:OpenJSharp
阅读 25
收藏 0
点赞 0
评论 0
@Override
public Clipboard getSystemClipboard() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
}
synchronized (this) {
if (clipboard == null) {
clipboard = new WClipboard();
}
}
return clipboard;
}
Terminal.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
private ActiveTerm createActiveTerminal() {
Clipboard aSystemClipboard = Lookup.getDefault().lookup(Clipboard.class);
if (aSystemClipboard == null) {
aSystemClipboard = getToolkit().getSystemClipboard();
}
return new MyActiveTerm(aSystemClipboard);
}
AddressBookPanel.java 文件源码
项目:komodoGUI
阅读 22
收藏 0
点赞 0
评论 0
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
if (row < 0)
return;
AddressBookEntry entry = entries.get(row);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(entry.address), null);
}
ImageHelper.java 文件源码
项目:Sikulix2tesseract
阅读 31
收藏 0
点赞 0
评论 0
/**
* Gets an image from Clipboard.
*
* @return image
*/
public static Image getClipboardImage() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
try {
return (Image) clipboard.getData(DataFlavor.imageFlavor);
} catch (Exception e) {
return null;
}
}
HTMLEditor.java 文件源码
项目:SER316-Aachen
阅读 22
收藏 0
点赞 0
评论 0
private void doPaste() {
Clipboard clip =
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
try {
Transferable content = clip.getContents(this);
if (content == null)
{
return;
}
String txt =
content
.getTransferData(new DataFlavor(String.class, "String"))
.toString();
document.replace(
editor.getSelectionStart(),
editor.getSelectionEnd() - editor.getSelectionStart(),
txt,
editorKit.getInputAttributes());
//editor.replaceSelection(content.getTransferData(new
// DataFlavor(String.class, "String")).toString());
//editor.paste();
//insertHTML(content.getTransferData(new DataFlavor(String.class,
// "String")).toString(), editor.getCaretPosition());
/*
* Element el =
* document.getParagraphElement(editor.getCaretPosition());
* insertTextInElement(el, content.getTransferData(new
* DataFlavor(String.class, "String")).toString(),
*/
} catch (Exception ex) {
ex.printStackTrace();
}
}
XToolkit.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
public Clipboard getSystemSelection() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
}
synchronized (this) {
if (selection == null) {
selection = new XClipboard("Selection", "PRIMARY");
}
}
return selection;
}