本文整理汇总了Java中java.awt.dnd.DragSourceAdapter类的典型用法代码示例。如果您正苦于以下问题:Java DragSourceAdapter类的具体用法?Java DragSourceAdapter怎么用?Java DragSourceAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DragSourceAdapter类属于java.awt.dnd包,在下文中一共展示了DragSourceAdapter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ImageDragSource
import java.awt.dnd.DragSourceAdapter; //导入依赖的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]);
}
示例2: installDragGestureHandler
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
*
*/
protected void installDragGestureHandler() {
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent e) {
if (graphComponent.isDragEnabled() && first != null) {
final TransferHandler th = graphComponent.getTransferHandler();
if (th instanceof mxGraphTransferHandler) {
final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
.createTransferable(graphComponent);
if (t != null) {
e.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t,
new DragSourceAdapter() {
/**
*
*/
public void dragDropEnd(DragSourceDropEvent dsde) {
((mxGraphTransferHandler) th).exportDone(graphComponent, t,
TransferHandler.NONE);
first = null;
}
});
}
}
}
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(graphComponent.getGraphControl(),
(isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE : DnDConstants.ACTION_MOVE,
dragGestureListener);
}
示例3: dragGestureRecognized
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
public void dragGestureRecognized(DragGestureEvent dge) {
dge.getSourceAsDragGestureRecognizer().setSourceActions(DnDConstants.ACTION_COPY);
JTree t = (JTree) dge.getComponent();
List<Object> selectedNodes = new ArrayList<Object>();
if (t.getSelectionPaths() == null) return;
for (TreePath path : t.getSelectionPaths()) {
selectedNodes.add(path.getLastPathComponent());
}
dge.getDragSource().startDrag(dge, null,
new OlapMetadataTransferable(selectedNodes.toArray()),
new DragSourceAdapter() {//just need a default adapter
}
);
}
示例4: installDragGestureHandler
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
*
*/
protected void installDragGestureHandler()
{
DragGestureListener dragGestureListener = new DragGestureListener()
{
public void dragGestureRecognized(DragGestureEvent e)
{
if (graphComponent.isDragEnabled() && first != null)
{
final TransferHandler th = graphComponent
.getTransferHandler();
if (th instanceof mxGraphTransferHandler)
{
final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
.createTransferable(graphComponent);
if (t != null)
{
e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
new Point(), t, new DragSourceAdapter()
{
/**
*
*/
public void dragDropEnd(
DragSourceDropEvent dsde)
{
((mxGraphTransferHandler) th)
.exportDone(
graphComponent,
t,
TransferHandler.NONE);
first = null;
}
});
}
}
}
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(graphComponent
.getGraphControl(),
(isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
: DnDConstants.ACTION_MOVE, dragGestureListener);
}
示例5: run
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
public void run() {
frame = new Frame();
final DragSourceListener dragSourceListener = new DragSourceAdapter() {
public void dragDropEnd(DragSourceDropEvent e) {
dropSuccess = e.getDropSuccess();
System.err.println("Drop was successful: " + dropSuccess);
}
};
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
}
};
new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
dragGestureListener);
DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
dtde.dropComplete(true);
System.err.println("Drop");
}
};
new DropTarget(frame, dropTargetListener);
//What would normally go into main() will probably go here.
//Use System.out.println for diagnostic messages that you want
//to read after the test is done.
frame.setUndecorated(true);
frame.setBounds(100, 100, 200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Robot robot = Util.createRobot();
Util.waitForIdle(robot);
Point startPoint = frame.getLocationOnScreen();
Point endPoint = new Point(startPoint);
startPoint.translate(50, 50);
endPoint.translate(150, 150);
Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
Util.waitForIdle(robot);
robot.delay(500);
if (dropSuccess) {
System.err.println("test passed");
} else {
throw new RuntimeException("test failed: drop was not successful");
}
}
示例6: makeDraggable
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
private void makeDraggable(final JButton b, final Class codenameOneClass, final String namePrefix, final CustomComponent custom) {
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(b,
TransferHandler.MOVE, new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
lockForDragging = true;
try {
com.codename1.ui.Component cmp;
if(custom != null && custom.isUiResource()) {
UIBuilderOverride u = new UIBuilderOverride();
cmp = u.createContainer(res, custom.getType());
if(b.getIcon() != null) {
DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
((ImageIcon)b.getIcon()).getImage(), new Point(0, 0),
new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
});
} else {
DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
});
}
return;
}
if(codenameOneClass == com.codename1.ui.Component.class) {
// special case for custom component which has a protected constructor
cmp = new com.codename1.ui.Component() {};
} else {
cmp = (com.codename1.ui.Component)codenameOneClass.newInstance();
}
cmp.putClientProperty(TYPE_KEY, namePrefix);
cmp.setName(findUniqueName(namePrefix));
initializeComponentText(cmp);
if(custom != null) {
cmp.putClientProperty("CustomComponent", custom);
cmp.putClientProperty(TYPE_KEY, custom.getType());
}
DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
});
} catch(Exception e) {
e.printStackTrace();
}
}
});
}
示例7: installDragGestureHandler
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
*
*/
protected void installDragGestureHandler()
{
DragGestureListener dragGestureListener = new DragGestureListener()
{
public void dragGestureRecognized(DragGestureEvent e)
{
if (graphComponent.isDragEnabled() && first != null)
{
final TransferHandler th = graphComponent
.getTransferHandler();
if (th instanceof mxGraphTransferHandler)
{
final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
.createTransferable(graphComponent);
if (t != null)
{
e.startDrag(null, mxConstants.EMPTY_IMAGE,
new Point(), t, new DragSourceAdapter()
{
/**
*
*/
public void dragDropEnd(
DragSourceDropEvent dsde)
{
((mxGraphTransferHandler) th)
.exportDone(
graphComponent,
t,
TransferHandler.NONE);
first = null;
}
});
}
}
}
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(
graphComponent.getGraphControl(),
DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}
示例8: installDragGestureHandler
import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
*
*/
protected void installDragGestureHandler()
{
DragGestureListener dragGestureListener = new DragGestureListener()
{
public void dragGestureRecognized(DragGestureEvent e)
{
if (graphComponent.isDragEnabled() && first != null)
{
final TransferHandler th = graphComponent
.getTransferHandler();
if (th instanceof mxGraphTransferHandler)
{
final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
.createTransferable(graphComponent);
if (t != null)
{
e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
new Point(), t, new DragSourceAdapter()
{
/**
*
*/
public void dragDropEnd(
DragSourceDropEvent dsde)
{
((mxGraphTransferHandler) th)
.exportDone(
graphComponent,
t,
TransferHandler.NONE);
first = null;
}
});
}
}
}
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(
graphComponent.getGraphControl(),
DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}