本文整理汇总了Java中org.openide.util.datatransfer.PasteType.paste方法的典型用法代码示例。如果您正苦于以下问题:Java PasteType.paste方法的具体用法?Java PasteType.paste怎么用?Java PasteType.paste使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.datatransfer.PasteType
的用法示例。
在下文中一共展示了PasteType.paste方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent event) {
PasteType type = getPasteType();
if (type != null) {
try {
Transferable trans = type.paste();
if (trans != null) {
ClipboardOwner owner = trans instanceof ClipboardOwner ?
(ClipboardOwner)trans : new StringSelection(""); // NOI18N
Clipboard clipboard = (Clipboard)Lookup.getDefault().lookup(ExClipboard.class);
clipboard.setContents(trans, owner);
}
} catch (java.io.IOException e) {
ERR.log( Level.INFO, e.getLocalizedMessage(), e );
}
}
}
示例2: testJavaFileListPasteTypes
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
public void testJavaFileListPasteTypes() throws ClassNotFoundException, IOException {
FileObject testFO = FileUtil.createData( testFileSystem.getRoot(), "testFile.txt" );
File testFile = FileUtil.toFile( testFO );
ArrayList fileList = new ArrayList(1);
fileList.add( testFile );
Transferable t = new MockTransferable( new DataFlavor[] {DataFlavor.javaFileListFlavor}, fileList );
DataFolder.FolderNode node = (DataFolder.FolderNode)folderNode;
ArrayList list = new ArrayList();
node.createPasteTypes( t, list );
assertFalse( list.isEmpty() );
PasteType paste = (PasteType)list.get( 0 );
paste.paste();
FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir" ).getChildren();
assertEquals( 1, children.length );
assertEquals( children[0].getNameExt(), "testFile.txt" );
}
示例3: testUriFileListPasteTypes
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
public void testUriFileListPasteTypes() throws ClassNotFoundException, IOException {
DataFlavor flavor = new DataFlavor( "unsupported/flavor;class=java.lang.Object" );
FileObject testFO = FileUtil.createData( testFileSystem.getRoot(), "testFile.txt" );
File testFile = FileUtil.toFile( testFO );
String uriList = Utilities.toURI(testFile) + "\r\n";
Transferable t = new MockTransferable( new DataFlavor[] {new DataFlavor("text/uri-list;class=java.lang.String")}, uriList );
DataFolder.FolderNode node = (DataFolder.FolderNode)folderNode;
ArrayList list = new ArrayList();
node.createPasteTypes( t, list );
assertFalse( list.isEmpty() );
PasteType paste = (PasteType)list.get( 0 );
paste.paste();
FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir" ).getChildren();
assertEquals( 1, children.length );
assertEquals( children[0].getNameExt(), "testFile.txt" );
}
示例4: testJavaFileListWithRelativePaths
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
/**
* Test for bug 233673.
*
* @throws java.io.IOException
*/
public void testJavaFileListWithRelativePaths() throws IOException {
FileObject testFO = FileUtil.createData(testFileSystem.getRoot(),
"absoluteTestFile.txt");
File absoluteTestFile = FileUtil.toFile(testFO);
File relativeTestFile = new File("relativeFile.txt");
ArrayList fileList = new ArrayList(2);
fileList.add(relativeTestFile);
fileList.add(absoluteTestFile);
Transferable t = new MockTransferable(
new DataFlavor[]{DataFlavor.javaFileListFlavor}, fileList);
DataFolder.FolderNode node = (DataFolder.FolderNode) folderNode;
ArrayList<PasteType> list = new ArrayList<PasteType>();
node.createPasteTypes(t, list);
assertEquals("Relative path should be skipped", 1, list.size());
PasteType paste = (PasteType) list.get(0);
paste.paste();
FileObject[] children = testFileSystem.getRoot().getFileObject(
"testDir").getChildren();
assertEquals(1, children.length);
assertEquals(children[0].getNameExt(), "absoluteTestFile.txt");
}
示例5: Copy
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
@NbBundle.Messages({
"# Text appended to action name so that it is clear that the action",
"# will be invoked on parent node. For example:",
"# Paste -> Copy (to parent); Paste -> Refactory Copy... (to parent)",
"# Please note the leading space.",
"LBL_PasteToParent= (to parent)"
})
private PasteType[] updateParentPasteTypes(PasteType[] parentTypes) {
PasteType[] ret = new PasteType[parentTypes.length];
for (int i = 0; i < parentTypes.length; i++) {
final PasteType parentType = parentTypes[i];
ret[i] = new PasteType() {
@Override
public Transferable paste() throws IOException {
return parentType.paste();
}
@Override
public String getName() {
return parentType.getName() + Bundle.LBL_PasteToParent();
}
@Override
public HelpCtx getHelpCtx() {
return parentType.getHelpCtx();
}
};
}
return ret;
}
示例6: performPaste
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
/**
* Performs the drop. Performs paste on given paste type.
* (part of bugfix #37279, performPaste returns array of new nodes in target folder)
* @param type paste type
* @param targetFolder target folder for given paste type, can be null
* @return array of new added nodes in target folder
*/
static Node[] performPaste(PasteType type, Node targetFolder) {
//System.out.println("performing drop...."+type); // NOI18N
try {
if (targetFolder == null) {
// call paste action
type.paste();
return new Node[] { };
}
Node[] preNodes = targetFolder.getChildren().getNodes(true);
// call paste action
type.paste();
Node[] postNodes = targetFolder.getChildren().getNodes(true);
// calculate new nodes
List<Node> pre = Arrays.asList(preNodes);
List<Node> post = Arrays.asList(postNodes);
Iterator<Node> it = post.iterator();
List<Node> diff = new ArrayList<Node>();
while (it.hasNext()) {
Node n = it.next();
if (!pre.contains(n)) {
diff.add(n);
}
}
return diff.toArray(new Node[diff.size()]);
/*Clipboard clipboard = T opManager.getDefault().getClipboard();
if (trans != null) {
ClipboardOwner owner = trans instanceof ClipboardOwner ?
(ClipboardOwner)trans
:
new StringSelection ("");
clipboard.setContents(trans, owner);
}*/
} catch (UserCancelException exc) {
// ignore - user just pressed cancel in some dialog....
return new Node[] { };
} catch (IOException e) {
Exceptions.printStackTrace(e);
return new Node[] { };
}
}
示例7: doDrop
import org.openide.util.datatransfer.PasteType; //导入方法依赖的package包/类
/**
* Perform the drop operation and add the dragged item into the given category.
*
* @param targetCategory Lookup of the category that accepts the drop.
* @param item Transferable holding the item being dragged.
* @param dndAction Drag'n'drop action type.
* @param dropIndex Zero-based position where the dragged item should be dropped.
*
* @return True if the drop has been successful, false otherwise.
*/
public boolean doDrop( Lookup targetCategory, Transferable item, int dndAction, int dropIndex ) {
Node categoryNode = (Node)targetCategory.lookup( Node.class );
try {
//first check if we're reordering items within the same category
if( item.isDataFlavorSupported( PaletteController.ITEM_DATA_FLAVOR ) ) {
Lookup itemLookup = (Lookup)item.getTransferData( PaletteController.ITEM_DATA_FLAVOR );
if( null != itemLookup ) {
Node itemNode = (Node)itemLookup.lookup( Node.class );
if( null != itemNode ) {
Index order = (Index)categoryNode.getCookie( Index.class );
if( null != order && order.indexOf( itemNode ) >= 0 ) {
//the drop item comes from the targetCategory so let's
//just change the order of items
return moveItem( targetCategory, itemLookup, dropIndex );
}
}
}
}
PasteType paste = categoryNode.getDropType( item, dndAction, dropIndex );
if( null != paste ) {
Node[] itemsBefore = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
paste.paste();
Node[] itemsAfter = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
if( itemsAfter.length == itemsBefore.length+1 ) {
int currentIndex = -1;
Node newItem = null;
for( int i=itemsAfter.length-1; i>=0; i-- ) {
newItem = itemsAfter[i];
currentIndex = i;
for( int j=0; j<itemsBefore.length; j++ ) {
if( newItem.equals( itemsBefore[j] ) ) {
newItem = null;
break;
}
}
if( null != newItem ) {
break;
}
}
if( null != newItem && dropIndex >= 0 ) {
if( currentIndex < dropIndex )
dropIndex++;
moveItem( targetCategory, newItem.getLookup(), dropIndex );
}
}
return true;
}
if( isTextDnDEnabled && null != DataFlavor.selectBestTextFlavor(item.getTransferDataFlavors()) ) {
importTextIntoPalette( targetCategory, item, dropIndex );
return false; //return false to retain the original dragged text in its source
}
} catch( IOException ioE ) {
Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, ioE );
} catch( UnsupportedFlavorException e ) {
Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, e );
}
return false;
}