本文整理匯總了Java中java.awt.dnd.DropTargetDropEvent.getDropTargetContext方法的典型用法代碼示例。如果您正苦於以下問題:Java DropTargetDropEvent.getDropTargetContext方法的具體用法?Java DropTargetDropEvent.getDropTargetContext怎麽用?Java DropTargetDropEvent.getDropTargetContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.dnd.DropTargetDropEvent
的用法示例。
在下文中一共展示了DropTargetDropEvent.getDropTargetContext方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public void drop(DropTargetDropEvent dtde) {
Point p = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
// Sets the original glass pane
setOriginalGlassPane(tree);
// Cancel tree item expanding
dragOverTreePath = null;
// Get the parent and sibling paths and nodes
TreePath currentPath = tree.getPathForLocation(p.x, p.y);
DefaultMutableTreeNode parent =
(DefaultMutableTreeNode) getNodeForPath
(getParentPathForPosition(currentPath));
Node dropTargetNode = getDomNodeFromTreeNode(parent);
DefaultMutableTreeNode sibling =
(DefaultMutableTreeNode)
getNodeForPath(getSiblingPathForPosition(currentPath));
Node siblingNode = getDomNodeFromTreeNode(sibling);
if (this.transferData != null) {
ArrayList nodelist =
getNodeListForParent(this.transferData.getNodeList(),
dropTargetNode);
fireDropCompleted
(new DOMDocumentTreeEvent
(new DropCompletedInfo
(dropTargetNode, siblingNode, nodelist)));
dtde.dropComplete(true);
return;
}
dtde.rejectDrop();
}
示例2: _getFiles
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
private static List<File> _getFiles(DropTargetDropEvent dtde, IApplication app, boolean allowMoreThanOneFile)
{
try
{
DropTargetContext context = dtde.getDropTargetContext();
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable t = dtde.getTransferable();
List<File> filesToOpen = new ArrayList<File>();
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
filesToOpen = handleJavaFileListFlavor(t, app, allowMoreThanOneFile);
} else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
filesToOpen = handleStringFlavor(t, app, allowMoreThanOneFile);
} else {
filesToOpen = handleUriListFlavor(t);
}
context.dropComplete(true);
if (null != filesToOpen)
{
return filesToOpen;
}
else
{
return new ArrayList<File>();
}
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
示例3: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public synchronized void drop(DropTargetDropEvent dtde) {
try {
TreeNode sourceNode = (TreeNode) dtde.getTransferable().getTransferData(
NodeTransferWrapper.ATLAS_OBJECT_FLAVOR);
Point pt = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
TreeNode targetNode = (TreeNode) parentpath.getLastPathComponent();
if (targetNode.equals(sourceNode) || targetNode.getParent().equals(sourceNode)) {
dtde.rejectDrop();
return;
}
AtlasTreeModel atlasTreeModel = (AtlasTreeModel) atlasTree.getModel();
if (sourceNode instanceof LayerInterface && targetNode instanceof LayerInterface)
mergeLayers(atlasTreeModel, (LayerInterface) sourceNode,
(LayerInterface) targetNode);
if (targetNode instanceof MapInterface)
// We can not make a map child of another map
// -> use it's layer instead
targetNode = targetNode.getParent();
if (sourceNode instanceof MapInterface && targetNode instanceof LayerInterface)
moveMap(atlasTreeModel, (MapInterface) sourceNode, (LayerInterface) targetNode);
} catch (Exception e) {
log.error("", e);
atlasTree.getTreeModel().notifyStructureChanged();
dtde.rejectDrop();
}
}
示例4: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
@Override
public void drop(DropTargetDropEvent dtde)
{
if (dtde.isDataFlavorSupported(CardFlavor.cardFlavor) && this.canDrop)
{
Transferable trans = dtde.getTransferable();
try
{
Object data = trans.getTransferData(CardFlavor.cardFlavor);
CardWindow card =(CardWindow)data;
DropTargetContext context = dtde.getDropTargetContext();
CardCollection comp = (CardCollection)context.getComponent();
Container parent = comp.getParent();
GameController.getController(false)
.makeMove(CardCollection.getMoveFromIndex(comp.getCardMouseLocation(), new OrderedCard(card.card, card.cardLocation)));
if (parent != null)
parent.remove(card);
comp.setCard(card, comp.getCardMouseLocation());
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
comp.validate();
comp.repaint();
dtde.dropComplete(true);
}
catch (Exception e)
{
dtde.rejectDrop();
dtde.dropComplete(false);
JOptionPane.showMessageDialog(MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
else
{
dtde.rejectDrop();
dtde.dropComplete(false);
JOptionPane.showMessageDialog(MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE);
}
}
示例5: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
/** Drop On Node ! */
public void drop(DropTargetDropEvent dtde)
{
// Global.debugPrintln(this,"Dropping:"+dtde);
DropTargetContext dtc = dtde.getDropTargetContext();
Component comp = dtc.getComponent();
Point p=dtde.getLocation();
Transferable data = dtde.getTransferable();
ResourceTreeNode rtnode = getRTNode(comp,p);
// check dropped data:
if (VTransferData.canConvertToVRLs(data))
{
// I: accept drop:
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
// supply ResourceTree as (J)Component but TreeNode as VComponent !
VTransferHandler.getDefault().interActiveDrop(comp,rtnode,p,data);
// III: complete the drag !
dtde.getDropTargetContext().dropComplete(true);
}
else
dtde.rejectDrop();
}
示例6: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public void drop(DropTargetDropEvent dtde)
{
//UIGlobal.debugPrintf(this,"drop:%s\n",dtde);
DropTargetContext dtc = dtde.getDropTargetContext();
Component comp = dtc.getComponent();
Point p=dtde.getLocation();
// II : get data:
Transferable data = dtde.getTransferable();
// check dropped data:
if (VTransferData.canConvertToVRLs(data))
{
// I: accept drop:
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
// Implementation now in VTransferHandler:
VTransferHandler.getDefault().interActiveDrop(comp,p,data);
// III: complete the drag !
dtde.getDropTargetContext().dropComplete(true);
}
else
{
dtde.rejectDrop();
}
}
示例7: drop
import java.awt.dnd.DropTargetDropEvent; //導入方法依賴的package包/類
public void drop(DropTargetDropEvent dtde)
{
// currently this method does all the work when a drop is performed
try
{
Transferable data = dtde.getTransferable();
DropTargetContext dtc = dtde.getDropTargetContext();
Component comp = dtc.getComponent();
int action = dtde.getDropAction();
// check dataFlavor
/* if (t.isDataFlavorSupported (DataFlavor.javaFileListFlavor))
{
// Handle Java File List
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
java.util.List fileList = (java.util.List)
t.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
int len=fileList.size();
VRL sourceLocs[]=new VRL[len];
int index=0;
dtde.getDropTargetContext().dropComplete(true);
if (len<=0)
return;
while (iterator.hasNext())
{
java.io.File file = (File)iterator.next();
Debug("name="+file.getName());
Debug("url="+file.toURL().toString());
Debug("path="+file.getAbsolutePath());
sourceLocs[index++]=new VRL("file",null,file.getAbsolutePath());
}
viewerController.handleDropEvent(comp,sourceLocs[0].toString());
boolean isMove=(action==DnDConstants.ACTION_MOVE);
}
else*/
// String types for now:
if (VTransferData.canConvertToVRLs(data))
{
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
VRL vrls[]=VTransferData.getVRLsFrom(data);
controller.handleDrop(vrls[0]);
}
else if (data.isDataFlavorSupported (DataFlavor.stringFlavor))
{
dtde.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
String txt= (String)
data.getTransferData(DataFlavor.stringFlavor);
dtde.getDropTargetContext().dropComplete(true);
controller.setContents(txt);
}
}
catch (Exception e)
{
UILogger.logException(this,ClassLogger.ERROR,e,"Exception:%s\n",e);
}
}