java.awt.dnd.DropTargetAdapter Java Examples

The following examples show how to use java.awt.dnd.DropTargetAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageTransferTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #2
Source File: ImageTransferTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #3
Source File: ImageTransferTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #4
Source File: ImageTransferTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #5
Source File: ImageTransferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #6
Source File: ImageTransferTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #7
Source File: Trace.java    From Method_Trace_Tool with Apache License 2.0 5 votes vote down vote up
public static void drag()//定义的拖拽方法
{
    //panel表示要接受拖拽的控件
    new DropTarget(JlPath, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde)//重写适配器的drop方法
        {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))//如果拖入的文件格式受支持
                {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);//接收拖拽来的数据
                    List<File> list = (List<File>) (dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
                    String temp = "";
                    for (File file : list) {
                        temp = file.getAbsolutePath();
                        JlPath.setText(temp);
                        break;
                    }
                    //JOptionPane.showMessageDialog(null, temp);
                    dtde.dropComplete(true);//指示拖拽操作已完成
                } else {
                    dtde.rejectDrop();//否则拒绝拖拽来的数据
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #8
Source File: ImageTransferTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #9
Source File: ImageTransferTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #10
Source File: ShellTextComponent.java    From basicv2 with The Unlicense 5 votes vote down vote up
public ShellTextComponent(BasicShell sf) {
	parent = sf;
	setBackground(new Color(Colors.COLORS[6]));
	setDoubleBuffered(true);
	setForeground(new Color(Colors.COLORS[14]));
	setCaretColor(new Color(Colors.COLORS[14]));
	setToolTipText("<html>Type one of:<br>" + "- cls<br>- list<br>- run<br>- new<br>"
			+ "- save[file]<br>- load[file]<br>- compile[file]<br>- dir<br>"
			+ "or edit your BASIC code here</html>");
	BlockCaret mc = new BlockCaret();
	mc.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
	setCaret(mc);
	setFont(ResourceLoader.getFont());
	new DropTarget(this, new DropTargetAdapter() {
		@Override
		public void drop(DropTargetDropEvent event) {
			event.acceptDrop(DnDConstants.ACTION_COPY);
			Transferable transferable = event.getTransferable();
			DataFlavor[] flavors = transferable.getTransferDataFlavors();
			for (DataFlavor flavor : flavors) {
				try {
					if (flavor.isFlavorJavaFileListType()) {
						@SuppressWarnings("unchecked")
						List<File> files = (List<File>) transferable.getTransferData(flavor);
						File f = files.get(0);
						parent.getStore().load(f.getPath());
						parent.putStringUCase("Loaded: " + f.getName() + "\n" + ProgramStore.OK);
						return; // only one file
					}
				} catch (Exception e) {
					parent.putString(ProgramStore.ERROR);
				}
			}
		}
	});
}
 
Example #11
Source File: Button2DragTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}
 
Example #12
Source File: MainFrame.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
/**
 * Enables dragging and dropping files onto Sc2gears.<br>
 * If the dropped file list contains only a single replay (amongst other files), that will be opened in the Replay analyzer.<br>
 * If the dropped file list contains multiple replays and/or folders, those will be opened in a replay search.<br>
 * If the dropped file list contains replay sources and/or replay lists, those will be opened respectively in replay searches.<br>
 */
private void setupDropTarget() {
	new DropTarget( this, new DropTargetAdapter() {
		@Override
		public void drop( final DropTargetDropEvent event ) {
			final Transferable transferable = event.getTransferable();
			for ( final DataFlavor flavor : transferable.getTransferDataFlavors() ) {
				if ( flavor.isFlavorJavaFileListType() ) {
					// It's a file list, accept it!
					event.acceptDrop( DnDConstants.ACTION_COPY_OR_MOVE );
					try {
						@SuppressWarnings("unchecked")
						final List< File > fileList       = (List< File >) transferable.getTransferData( flavor );
						final List< File > replayFileList = new ArrayList< File >();
						
						for ( final File file : fileList ) {
							if ( file.isDirectory() )
								replayFileList.add( file );
							else {
								if ( GuiUtils.SC2_REPLAY_LIST_FILE_FILTER.accept( file ) )
									createNewInternalFrame( newRepSearchNode, null, file );
								else if ( GuiUtils.SC2_REPLAY_SOURCE_FILE_FILTER.accept( file ) )
									createNewInternalFrame( newRepSearchNode, file, null );
								else
									replayFileList.add( file );
							}
						}
						
						if ( replayFileList.size() == 1 && replayFileList.get( 0 ).isFile() )
							openReplayFile( replayFileList.get( 0 ) );
						else if ( replayFileList.size() > 0 ) // It might contain 1 folder only...
							createNewInternalFrame( newRepSearchNode, null, null, replayFileList.toArray( new File[ replayFileList.size() ] ) );
						
						event.dropComplete( true );
						
					} catch ( final Exception e ) {
						e.printStackTrace();
						event.rejectDrop();
					}
					break;
				}
			}
		}
	} );
}