本文整理汇总了Java中org.openide.util.datatransfer.ExTransferable类的典型用法代码示例。如果您正苦于以下问题:Java ExTransferable类的具体用法?Java ExTransferable怎么用?Java ExTransferable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExTransferable类属于org.openide.util.datatransfer包,在下文中一共展示了ExTransferable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paste
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
@Override
public Transferable paste() throws IOException {
if (SwingUtilities.isEventDispatchThread()) {
PackageRootNode.PKG_VIEW_RP.post(new java.lang.Runnable() {
@Override
public void run() {
final ProgressHandle h = ProgressHandleFactory.createHandle(getName());
h.start();
h.switchToIndeterminate();
try {
doPaste();
} catch (java.io.IOException ioe) {
Exceptions.printStackTrace(ioe);
} finally {
h.finish();
}
}
});
} else {
doPaste();
}
return ExTransferable.EMPTY;
}
示例2: testClipboard
import org.openide.util.datatransfer.ExTransferable; //导入依赖的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));
}
示例3: convert
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public Transferable convert(Transferable t) {
Logger.getAnonymousLogger().info("converting...");
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
final ExTransferable t2 = ExTransferable.create(t);
if (t2.isDataFlavorSupported(DataFlavor.stringFlavor) && !t2.isDataFlavorSupported(MYFLAV)) {
t2.put(new ExTransferable.Single(MYFLAV) {
protected Object getData() throws IOException, UnsupportedFlavorException {
String s = (String)t2.getTransferData(DataFlavor.stringFlavor);
try {
return new Integer(s);
} catch (NumberFormatException nfe) {
throw new IOException(nfe.toString());
}
}
});
}
return t2;
} else {
return t;
}
}
示例4: testOwnershipLostEvent
import org.openide.util.datatransfer.ExTransferable; //导入依赖的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: clipboardCopy
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
@Override
public Transferable clipboardCopy() throws IOException {
Transferable deflt = super.clipboardCopy();
ExTransferable enriched = ExTransferable.create(deflt);
ExTransferable.Single ex = new ExTransferable.Single(DataFlavor.stringFlavor) {
@Override
protected Object getData() {
return "<dependency>\n" + //NOI18N
" <groupId>" + record.getGroupId() + "</groupId>\n" + //NOI18N
" <artifactId>" + record.getArtifactId() + "</artifactId>\n" + //NOI18N
" <version>" + record.getVersion() + "</version>\n" + //NOI18N
"</dependency>"; //NOI18N
}
};
enriched.put(ex);
return enriched;
}
示例6: addDataFlavors
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public Transferable addDataFlavors(Transferable transferable) {
try {
if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.WADL_METHOD_FLAVOR)) {
Object data = transferable.getTransferData(ConsumerFlavorProvider.WADL_METHOD_FLAVOR);
if (data instanceof WadlSaasMethod) {
WadlSaasMethod method = (WadlSaasMethod) data;
ExTransferable t = ExTransferable.create(transferable);
RestClientEditorDrop editorDrop = new RestClientEditorDrop(method);
ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
t.put(s);
return t;
}
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return transferable;
}
示例7: addDataFlavors
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public Transferable addDataFlavors(Transferable transferable) {
try {
if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR)) {
Object data = transferable.getTransferData(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR);
if (data instanceof CustomSaasMethod) {
CustomSaasMethod method = (CustomSaasMethod) data;
ExTransferable t = ExTransferable.create(transferable);
CustomClientEditorDrop editorDrop = new CustomClientEditorDrop(method);
ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
t.put(s);
return t;
}
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return transferable;
}
示例8: paste
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
@Override
public Transferable paste() throws IOException {
if (java.awt.EventQueue.isDispatchThread())
return doPaste();
else { // reinvoke synchronously in AWT thread
try {
return Mutex.EVENT.readAccess(this);
}
catch (MutexException ex) {
Exception e = ex.getException();
if (e instanceof IOException)
throw (IOException) e;
else { // should not happen, ignore
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
return ExTransferable.EMPTY;
}
}
}
}
示例9: getTransferableOwner
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
/**
* Get a transferable of a selection of node(s).
* @param sel An array with selected nodes.
* @param copyCut <code>true</code> for copy, <code>false</code> for cut.
* @return The transferable or <code>null</code>
*/
public static Transferable getTransferableOwner(Node[] sel, boolean copyCut) {
Transferable trans;
if (sel.length != 1) {
Transferable[] arrayTrans = new Transferable[sel.length];
for (int i = 0; i < sel.length; i++) {
if ((arrayTrans[i] = getTransferableOwner(sel[i], copyCut)) == null) {
return null;
}
}
trans = ExternalDragAndDrop.maybeAddExternalFileDnd( new ExTransferable.Multi(arrayTrans) );
} else {
trans = getTransferableOwner(sel[0], copyCut);
}
return trans;
}
示例10: paste
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
/** Performs the paste action.
* @return Transferable which should be inserted into the clipboard after
* paste action. It can be null, which means that clipboard content
* should be cleared.
*/
@Override
public Transferable paste() throws IOException {
int size = p.length;
Transferable[] arr = new Transferable[size];
for (int i = 0; i < size; i++) {
Transferable newTransferable = p[i].paste();
if (newTransferable != null) {
arr[i] = newTransferable;
} else {
// keep the orginal
arr[i] = t[i];
}
}
return new ExTransferable.Multi(arr);
}
示例11: testMultiTransferableForCopy
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public void testMultiTransferableForCopy() throws Exception {
N node = new N();
N n2 = new N();
N[] arr = { node, n2 };
Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_COPY);
assertEquals("One call to copy", 1, node.copy);
assertEquals("One call to copy on n2", 1, n2.copy);
assertEquals("Also one call to drag which delegates to copy", 1, node.drag);
assertEquals("Also one call to drag which delegates to copy on n2", 1, n2.drag);
assertEquals("No call to cut", 0, node.cut);
assertEquals("No call to cut", 0, n2.cut);
assertNotNull("Call to convertor", last);
assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
Object obj = last.getTransferData(ExTransferable.multiFlavor);
if (!( obj instanceof MultiTransferObject)) {
fail("It should be MultiTransferObject: " + obj);
}
MultiTransferObject m = (MultiTransferObject)obj;
assertEquals("Two in multi", 2, m.getCount());
assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
示例12: testMultiTransferableForCut
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public void testMultiTransferableForCut() throws Exception {
N node = new N();
N n2 = new N();
N[] arr = { node, n2 };
Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_MOVE);
assertEquals("One call to cut ", 1, node.cut);
assertEquals("One call to cut on n2", 1, n2.cut);
assertEquals("No to drag", 0, node.drag);
assertEquals("No to drag on n2", 0, n2.drag);
assertEquals("No call to copy", 0, node.copy);
assertEquals("No call to copy on n2", 0, n2.copy);
assertNotNull("Call to convertor", last);
assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
Object obj = last.getTransferData(ExTransferable.multiFlavor);
if (!( obj instanceof MultiTransferObject)) {
fail("It should be MultiTransferObject: " + obj);
}
MultiTransferObject m = (MultiTransferObject)obj;
assertEquals("Two in multi", 2, m.getCount());
assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
示例13: testCustomize
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
public void testCustomize() throws Exception {
PaletteActions actions = new DummyActions();
PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
Model model = pc.getModel();
Item item = model.getCategories()[0].getItems()[0];
DragAndDropHandler handler = DragAndDropHandler.getDefault();
ExTransferable t = ExTransferable.create( item.cut() );
DataFlavor[] flavorsBefore = t.getTransferDataFlavors();
handler.customize( t, item.getLookup() );
DataFlavor[] flavorsAfter = t.getTransferDataFlavors();
assertEquals( "Default implementation does nothing", flavorsBefore.length, flavorsAfter.length );
for( int i=0; i<flavorsBefore.length; i++ ) {
assertEquals( "Default implementation does nothing", flavorsBefore[i], flavorsAfter[i] );
}
}
示例14: addExternalFileTransferable
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
private void addExternalFileTransferable( ExTransferable t, DataObject d ) {
FileObject fo = d.getPrimaryFile();
File file = FileUtil.toFile( fo );
if( null != file ) {
//windows & mac
final ArrayList<File> list = new ArrayList<File>(1);
list.add( file );
t.put( new ExTransferable.Single( DataFlavor.javaFileListFlavor ) {
public Object getData() {
return list;
}
});
//linux
final String uriList = Utilities.toURI(file).toString() + "\r\n";
t.put( new ExTransferable.Single( createUriListFlavor() ) {
public Object getData() {
return uriList;
}
});
}
}
示例15: createNewTransferable
import org.openide.util.datatransfer.ExTransferable; //导入依赖的package包/类
@Override
public Transferable createNewTransferable() {
return new ExTransferable.Single(Competence.dataFlavor) {
@Override
protected Object getData() throws IOException, UnsupportedFlavorException {
String competenceName = PGSupport.getIdentifierFromDialog("Name of competence");
if (competenceName == null) {
return null;
}
String elementName = PGSupport.getIdentifierFromDialog("Name of competence atom");
if (elementName == null) {
return null;
}
try {
return LapElementsFactory.createCompetence(competenceName, elementName);
} catch (DuplicateNameException ex) {
throw new FubarException("Creating new competence with only one name, what duplicate?", ex);
}
}
};
}