本文整理汇总了Java中java.awt.dnd.DnDConstants类的典型用法代码示例。如果您正苦于以下问题:Java DnDConstants类的具体用法?Java DnDConstants怎么用?Java DnDConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DnDConstants类属于java.awt.dnd包,在下文中一共展示了DnDConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeDrop
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
@Override
public boolean executeDrop(JTree targetTree, Object draggedNode, Object targetNode, int action) {
if (action == DnDConstants.ACTION_COPY) {
return false;
} else if (action == DnDConstants.ACTION_MOVE) {
if (canMove(draggedNode, targetNode)) {
if (draggedNode == targetNode)
return true;
listener.moveRequested(new Event(null), (AddTool) draggedNode, (AddTool) targetNode);
return true;
} else {
return false;
}
} else {
return false;
}
}
示例2: ImageDragSource
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
ImageDragSource() {
formats = retrieveFormatsToTest();
passedArray = new boolean[formats.length];
final DragSourceListener dsl = new DragSourceAdapter() {
public void dragDropEnd(DragSourceDropEvent e) {
System.err.println("Drop was successful=" + e.getDropSuccess());
notifyTransferSuccess(e.getDropSuccess());
if (++fi < formats.length) {
leaveFormat(formats[fi]);
}
}
};
new DragSource().createDefaultDragGestureRecognizer(frame,
DnDConstants.ACTION_COPY,
dge -> dge.startDrag(null, new ImageSelection(image), dsl));
leaveFormat(formats[fi]);
}
示例3: checkNodeForAction
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/** Utility method.
* @return true if given node supports given action,
* false otherwise.
*/
static boolean checkNodeForAction(Node node, int dragAction) {
if (
node.canCut() &&
((dragAction == DnDConstants.ACTION_MOVE) || (dragAction == DnDConstants.ACTION_COPY_OR_MOVE))
) {
return true;
}
if (
node.canCopy() &&
((dragAction == DnDConstants.ACTION_COPY) || (dragAction == DnDConstants.ACTION_COPY_OR_MOVE) ||
(dragAction == DnDConstants.ACTION_LINK) || (dragAction == DnDConstants.ACTION_REFERENCE))
) {
return true;
}
// hmmm, conditions not satisfied..
return false;
}
示例4: testMoveItemAfter
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/**
* Test of moveItem method, of class org.netbeans.modules.palette.Category.
*/
public void testMoveItemAfter() throws IOException {
PaletteActions actions = new DummyActions();
PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
Model model = pc.getModel();
Category[] categories = model.getCategories();
Category cat = categories[0];
Item[] itemsBeforeMove = cat.getItems();
Item source = itemsBeforeMove[0];
Item target = itemsBeforeMove[itemsBeforeMove.length-1];
cat.dropItem( createTransferable( source ), DnDConstants.ACTION_COPY_OR_MOVE, target, false );
Item[] itemsAfterMove = cat.getItems();
assertEquals( itemsBeforeMove.length, itemsAfterMove.length );
assertEquals( source.getName(), itemsAfterMove[itemsAfterMove.length-1].getName() );
assertEquals( itemsBeforeMove[1].getName(), itemsAfterMove[0].getName() );
assertEquals( target.getName(), itemsAfterMove[itemsAfterMove.length-1-1].getName() );
}
示例5: testCanDropText
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
public void testCanDropText() throws Exception {
PaletteActions actions = new DummyActions();
PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
Model model = pc.getModel();
Category cat = model.getCategories()[0];
DragAndDropHandler handler = new TextDragAndDropHandler();
DataFlavor[] flavors = new DataFlavor[] { new DataFlavor( "text/xml" ) };
assertTrue( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
flavors = new DataFlavor[] { new DataFlavor( "text/html" ) };
assertTrue( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
flavors = new DataFlavor[] { new DataFlavor( "unsupported/mimetype" ) };
assertFalse( handler.canDrop( cat.getLookup(), flavors, DnDConstants.ACTION_COPY_OR_MOVE ) );
}
示例6: initAndShowUI
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
private static void initAndShowUI() {
frame = new JFrame("Test frame");
frame.setSize(SIZE, SIZE);
frame.setLocationRelativeTo(null);
final JTextArea jta = new JTextArea();
jta.setBackground(Color.RED);
frame.add(jta);
jta.setText("1234567890");
jta.setFont(jta.getFont().deriveFont(150f));
jta.setDragEnabled(true);
jta.selectAll();
jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY,
new TestdropTargetListener()));
jta.addMouseListener(new TestMouseAdapter());
frame.setVisible(true);
}
示例7: mouseDragged
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/**
* Invoked when a mouse button is pressed on a component.
*/
public void mouseDragged(MouseEvent e) {
if (!events.isEmpty()) { // gesture pending
int dop = mapDragOperationFromModifiers(e);
if (dop == DnDConstants.ACTION_NONE) {
return;
}
MouseEvent trigger = (MouseEvent)events.get(0);
Point origin = trigger.getPoint();
Point current = e.getPoint();
int dx = Math.abs(origin.x - current.x);
int dy = Math.abs(origin.y - current.y);
if (dx > motionThreshold || dy > motionThreshold) {
fireDragGestureRecognized(dop, ((MouseEvent)getTriggerEvent()).getPoint());
} else
appendEvent(e);
}
}
示例8: mapDragOperationFromModifiers
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/**
* determine the drop action from the event
*/
protected int mapDragOperationFromModifiers(MouseEvent e) {
int mods = e.getModifiersEx();
int btns = mods & ButtonMask;
// Do not allow right mouse button drag since Motif DnD does not
// terminate drag operation on right mouse button release.
if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
btns == InputEvent.BUTTON2_DOWN_MASK)) {
return DnDConstants.ACTION_NONE;
}
return
SunDragSourceContextPeer.convertModifiersToDropAction(mods,
getSourceActions());
}
示例9: mapDragOperationFromModifiers
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/**
* determine the drop action from the event
*/
protected int mapDragOperationFromModifiers(MouseEvent e) {
int mods = e.getModifiersEx();
int btns = mods & ButtonMask;
// Prohibit multi-button drags.
if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
btns == InputEvent.BUTTON2_DOWN_MASK ||
btns == InputEvent.BUTTON3_DOWN_MASK)) {
return DnDConstants.ACTION_NONE;
}
return
SunDragSourceContextPeer.convertModifiersToDropAction(mods,
getSourceActions());
}
示例10: drop
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
try {
Transferable t = dtde.getTransferable();
DataFlavor[] dataFlavors = t.getTransferDataFlavors();
for (DataFlavor df : dataFlavors) {
if (df.isFlavorJavaFileListType()) {
File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
pathNameTextField.setText(getFilesName(filesArray));
}
}
} catch (UnsupportedFlavorException e2) {
} catch (IOException ex) {
Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例11: mapOperation
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
/**
* mapOperation
*/
private int mapOperation(int operation) {
int[] operations = {
DnDConstants.ACTION_MOVE,
DnDConstants.ACTION_COPY,
DnDConstants.ACTION_LINK,
};
int ret = DnDConstants.ACTION_NONE;
for (int i = 0; i < operations.length; i++) {
if ((operation & operations[i]) == operations[i]) {
ret = operations[i];
break;
}
}
return ret;
}
示例12: processXdndStatus
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
private boolean processXdndStatus(XClientMessageEvent xclient) {
int action = DnDConstants.ACTION_NONE;
/* Ignore XDnD messages from all other windows. */
if (xclient.get_data(0) != getTargetWindow()) {
return true;
}
if ((xclient.get_data(1) & XDnDConstants.XDND_ACCEPT_DROP_FLAG) != 0) {
/* This feature is new in XDnD version 2, but we can use it as XDnD
compliance only requires supporting version 3 and up. */
action = XDnDConstants.getJavaActionForXDnDAction(xclient.get_data(4));
}
getProtocolListener().handleDragReply(action);
return true;
}
示例13: doUpdateTargetWindow
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
private void doUpdateTargetWindow(long subwindow, long time) {
long clientWindow = 0;
long proxyWindow = 0;
XDragSourceProtocol protocol = null;
boolean isReceiver = false;
if (subwindow != 0) {
clientWindow = findClientWindow(subwindow);
}
if (clientWindow != 0) {
Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
while (dragProtocols.hasNext()) {
XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
if (dragProtocol.attachTargetWindow(clientWindow, time)) {
protocol = dragProtocol;
break;
}
}
}
/* Update the global state. */
dragProtocol = protocol;
targetAction = DnDConstants.ACTION_NONE;
targetRootSubwindow = subwindow;
}
示例14: drop
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
public void drop(DropTargetDropEvent e)
{
if (dragSource != null)
{
e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Point p = e.getLocation();
int targetRow = rowAtPoint(p);
Object edge = graph.insertEdge(null, null, null,
dragSource.cell, JTableRenderer.this.cell, "sourceRow="
+ sourceRow + ";targetRow=" + targetRow);
graph.setSelectionCell(edge);
// System.out.println("clearing drag source");
dragSource = null;
e.dropComplete(true);
}
else
{
e.rejectDrop();
}
}
示例15: importData
import java.awt.dnd.DnDConstants; //导入依赖的package包/类
@Override
public boolean importData(TransferHandler.TransferSupport info) {
if (!info.isDrop()) {
return false;
}
if (!canImportHere(info)) {
if (
(JDragDropList.this.dropListener != null) &&
JDragDropList.this.dropListener.acceptDrop(JDragDropList.this, info)
) {
return JDragDropList.this.dropListener.handleDrop(JDragDropList.this, info);
} else {
return false;
}
}
JDDLTransferData<T> data = getData(info);
int destIndex = JDragDropList.this.getDropLocation().getIndex();
/*
System.err.print("[ ");
for (int index : data.getIndices()) {
System.err.print(index + " ");
}
System.err.print("] -> ");
System.err.println(destIndex);
*/
if ((info.getDropAction() & DnDConstants.ACTION_COPY) != 0) {
copyItems(data.getSourceList(), JDragDropList.this, data.getValuesList(), destIndex);
} else if ((info.getDropAction() & DnDConstants.ACTION_MOVE) != 0) {
moveItems(data.getSourceList(), JDragDropList.this, data.getIndices(), destIndex);
} else {
return false;
}
return true;
}