本文整理汇总了Java中java.awt.dnd.DropTargetContext类的典型用法代码示例。如果您正苦于以下问题:Java DropTargetContext类的具体用法?Java DropTargetContext怎么用?Java DropTargetContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DropTargetContext类属于java.awt.dnd包,在下文中一共展示了DropTargetContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updatePositionIndicator
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
* Sets the position indicator according to the current cursor location.
*
* @param dtde
* DropTargetDragEvent
*/
private void updatePositionIndicator(DropTargetDragEvent dtde) {
Point p = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
// Current path
TreePath currentPath = tree.getPathForLocation(p.x, p.y);
Rectangle bounds = tree.getPathBounds(currentPath);
// Upper area of the tree node
if (p.y <= bounds.y + visualTipOffset) {
positionIndicator = BEFORE;
}
// Lower area of the tree node
else if (p.y >= bounds.y + bounds.height - visualTipOffset) {
positionIndicator = AFTER;
}
// Somewhere between the upper and the lower area of the tree node
else {
positionIndicator = CURRENT;
}
}
示例2: createDropTargetContext
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
private DropTargetContext createDropTargetContext() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Constructor<DropTargetContext> c = DropTargetContext.class.getDeclaredConstructor(DropTarget.class);
c.setAccessible(true);
DropTargetContext inst = c.newInstance(dest.getDropTarget());
inst.addNotify(createDropTargetContextPeer());
return inst;
}
示例3: drop
import java.awt.dnd.DropTargetContext; //导入依赖的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();
}
示例4: getNode
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
* Gets the TreeNode from the DropTargetDragEvent
*
* @param dtde
* The DropTargetDragEvent
* @return Associated TreeNode or null
*/
private TreeNode getNode(DropTargetDragEvent dtde) {
Point p = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
TreePath path = tree.getPathForLocation(p.x, p.y);
if (path == null || path.getLastPathComponent() == null) {
return null;
}
return (TreeNode) path.getLastPathComponent();
}
示例5: _getFiles
import java.awt.dnd.DropTargetContext; //导入依赖的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);
}
}
示例6: drop
import java.awt.dnd.DropTargetContext; //导入依赖的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();
}
}
示例7: getNodeForEvent
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
private TreeNode getNodeForEvent(DropTargetDragEvent dtde) {
Point p = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
TreePath path = tree.getClosestPathForLocation(p.x, p.y);
return (TreeNode) path.getLastPathComponent();
}
示例8: drop
import java.awt.dnd.DropTargetContext; //导入依赖的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);
}
}
示例9: WinDropTarget
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
public WinDropTarget(WinDTK dtk, DropTargetContext context) {
this.dtk = dtk;
this.context = context;
ComponentInternals ci = ComponentInternals.getComponentInternals();
NativeWindow w = ci.getNativeWindow(context.getComponent());
hwnd = w.getId();
dropTargetPtr = registerDropTarget();
}
示例10: drop
import java.awt.dnd.DropTargetContext; //导入依赖的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();
}
示例11: drop
import java.awt.dnd.DropTargetContext; //导入依赖的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();
}
}
示例12: getDropTargetContext
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
* @see DropTargetDragEvent
*/
public DropTargetContext getDropTargetContext () {
return event.getDropTargetContext ();
}
示例13: processExitMessage
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
*
*/
protected void processExitMessage(SunDropTargetEvent event) {
Component c = (Component)event.getSource();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (dt == null) {
currentDT = null;
currentT = null;
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = null;
return;
}
if (dt != currentDT) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = dt.getDropTargetContext();
currentDTC.addNotify(this);
}
dtc = currentDTC;
if (dt.isActive()) try {
((DropTargetListener)dt).dragExit(new DropTargetEvent(dtc));
} catch (Exception e) {
e.printStackTrace();
} finally {
currentA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentDA = DnDConstants.ACTION_NONE;
currentDT = null;
currentT = null;
currentDTC.removeNotify();
currentDTC = null;
local = null;
dragRejected = false;
}
}
示例14: processMotionMessage
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
*
*/
protected void processMotionMessage(SunDropTargetEvent event,
boolean operationChanged) {
Component c = (Component)event.getSource();
Point hots = event.getPoint();
int id = event.getID();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (c.isShowing() && (dt != null) && dt.isActive()) {
if (currentDT != dt) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = null;
}
dtc = currentDT.getDropTargetContext();
if (dtc != currentDTC) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = dtc;
currentDTC.addNotify(this);
}
currentA = currentDT.getDefaultActions();
try {
DropTargetDragEvent dtde = new DropTargetDragEvent(dtc,
hots,
currentDA,
currentSA);
DropTargetListener dtl = (DropTargetListener)dt;
if (operationChanged) {
dtl.dropActionChanged(dtde);
} else {
dtl.dragOver(dtde);
}
if (dragRejected) {
currentDA = DnDConstants.ACTION_NONE;
}
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDA = DnDConstants.ACTION_NONE;
}
}
示例15: processDropMessage
import java.awt.dnd.DropTargetContext; //导入依赖的package包/类
/**
*
*/
protected void processDropMessage(SunDropTargetEvent event) {
Component c = (Component)event.getSource();
Point hots = event.getPoint();
DropTarget dt = c.getDropTarget();
dropStatus = STATUS_WAIT; // drop pending ACK
dropComplete = false;
if (c.isShowing() && dt != null && dt.isActive()) {
DropTargetContext dtc = dt.getDropTargetContext();
currentDT = dt;
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = dtc;
currentDTC.addNotify(this);
currentA = dt.getDefaultActions();
synchronized(_globalLock) {
if ((local = getJVMLocalSourceTransferable()) != null)
setCurrentJVMLocalSourceTransferable(null);
}
dropInProcess = true;
try {
((DropTargetListener)dt).drop(new DropTargetDropEvent(dtc,
hots,
currentDA,
currentSA,
local != null));
} finally {
if (dropStatus == STATUS_WAIT) {
rejectDrop();
} else if (dropComplete == false) {
dropComplete(false);
}
dropInProcess = false;
}
} else {
rejectDrop();
}
}