本文整理汇总了Java中java.awt.datatransfer.Clipboard类的典型用法代码示例。如果您正苦于以下问题:Java Clipboard类的具体用法?Java Clipboard怎么用?Java Clipboard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Clipboard类属于java.awt.datatransfer包,在下文中一共展示了Clipboard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
@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);
}
}
}
示例2: makeSureSystemClipboardContainsString
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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();
}
示例3: testClipboard
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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));
}
示例4: testOwnershipLostEvent
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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);
}
示例5: paste
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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) {
}
}
}
示例6: stackToCLBD
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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);
}
示例7: insertRows
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
/**
* 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);
}
示例8: doCopy
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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
}
}
}
示例9: copy
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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);
}
示例10: setClipboardContents
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
/**
* 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);
}
}
示例11: CopySVGMenuItem
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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);
}
});
}
}
示例12: doPaste
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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();
}
}
示例13: NbClipboard
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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);
}
}
示例14: getSystemSelection
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
@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;
}
示例15: doCopy
import java.awt.datatransfer.Clipboard; //导入依赖的package包/类
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();
}
}