public UMLDiagramPanel(DiagramEditor _editorLoader) { diagramEditor = _editorLoader; isOpenGLEnabled = Boolean.parseBoolean(System.getProperty("sun.java2d.opengl")); if (!isOpenGLEnabled) { logger.warn("OpenGL is not enabled, there could be some performance and quality issues. It can be enabled using -Dsun.java2d.opengl=true runtime argument."); } // we are going to listen mouse clicks and movements for various operations this.addMouseListener(this); this.addMouseMotionListener(this); this.addMouseWheelListener(this); this.setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try { dtde.acceptDrop(dtde.getDropAction()); Object transferData = dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (transferData != null && transferData instanceof List) { List files = (List) transferData; if (files.size() > 0) { diagramEditor.open((File) files.get(0)); dtde.dropComplete(true); } } } catch (Exception e) { logger.error(e.getMessage(), e); InformationDialog.display(e.getMessage()); } } else { dtde.rejectDrop(); } } })); this.setBackground(Color.WHITE); }
ImageDropTarget() throws AWTException { DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { checkImage(dtde); startImageDrag(); } }; new DropTarget(frame, dropTargetAdapter); robot = new Robot(); }
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(); } } }); }
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>- 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); } } } }); }
/** * Initialisiert Drop auf Windows * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516 */ private void initJListFileDropOnWindows(){ DropTarget target = new DropTarget(jList1, new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { if(dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){ dtde.acceptDrop(dtde.getDropAction()); try { //siehe: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516 final List<File> list = (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); //Hier steht der eigentliche Drop Code if(CollectionManager.INSTANCE.isACollectionCreated()){ //ImportGUI im extra Thread, damit durch den Import Prozess keine Verzögerungen auftreten Runnable runImport = new Runnable() { @Override public void run() { ImportDirectoryGUI fileImport = new ImportDirectoryGUI( MovieManagerGUI.getInstance(), true, MovieManagerGUI.getInstance().getTabNames(), list, collection); fileImport.showGUI(); } }; SwingUtilities.invokeLater(runImport); } } catch (UnsupportedFlavorException | IOException ex) { LOG.error("Error while dropping file into MovieList.", ex); } } } }); jList1.setDropTarget(target); }
/** * Initialisiert Drop auf Windows * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516 */ private void initJListFileDropOnWindows(){ DropTarget target = new DropTarget(jTree1, new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { if(dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){ dtde.acceptDrop(dtde.getDropAction()); try { //siehe: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516 final List<File> list = (List<File>) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); //Hier steht der eigentliche Drop Code if(CollectionManager.INSTANCE.isACollectionCreated()){ //ImportGUI im extra Thread, damit durch den Import Prozess keine Verzögerungen auftreten Runnable runImport = new Runnable() { @Override public void run() { ImportDirectoryGUI fileImport = new ImportDirectoryGUI( MovieManagerGUI.getInstance(), true, MovieManagerGUI.getInstance().getTabNames(), list, collection); fileImport.showGUI(); } }; SwingUtilities.invokeLater(runImport); } } catch (UnsupportedFlavorException | IOException ex) { LOG.error("Error while dropping file into SeriesTree.", ex); } } } }); jTree1.setDropTarget(target); }
public ExtractionPanel(OnpromToolkit toolkit) { super(null); ontology.setStartX(50); ontology.setStartY(100); mapping.setStartX(200); mapping.setStartY(100); queries.setStartX(350); queries.setStartY(100); event.setStartX(500); event.setStartY(300); extraction.setStartX(200); extraction.setStartY(300); xesLog.setStartX(200); xesLog.setStartY(500); //connections shapes.add(new ResourceConnection(ontology, extraction)); shapes.add(new ResourceConnection(mapping, extraction)); shapes.add(new ResourceConnection(queries, extraction)); shapes.add(new ResourceConnection(event, extraction)); shapes.add(new ResourceConnection(extraction, xesLog)); shapes.add(ontology); shapes.add(mapping); shapes.add(queries); shapes.add(event); shapes.add(extraction); shapes.add(xesLog); this.setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { try { dtde.acceptDrop(dtde.getDropAction()); Transferable transferData = dtde.getTransferable(); int[] selected = (int[]) transferData.getTransferData(INT_ARRAY_FLAVOR); for (int i : selected) { TreeNode node = toolkit.getResourceNode(i); if (node.getType().equals(FileType.ONTOLOGY)) { ontology.setTreeNode(node); } if (node.getType().equals(FileType.MAPPING)) { mapping.setTreeNode(node); } if (node.getType().equals(FileType.QUERIES)) { queries.setTreeNode(node); } repaint(); } dtde.dropComplete(true); } catch (Exception e) { e.printStackTrace(); } } })); }
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"); } }
/** * 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; } } } } ); }
/** * Creates new form FfmpegUI */ public FFmpegUI() { initComponents(); targetText.setLabel("target file/dir"); tempText.setLabel("temp dir"); fromText.setLabel("from time, split as U like"); toText.setLabel("to time, split as U like"); DropTargetAdapter fileDropListener = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dtde) { try { Transferable tr = dtde.getTransferable(); Component target = dtde.getDropTargetContext().getDropTarget().getComponent(); JTextComponent jText; if (target instanceof JTextComponent) { jText = (JTextComponent) target; } else return; if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List files = (List) (tr.getTransferData(DataFlavor.javaFileListFlavor)); for (Object fo : files) { File f = (File) fo; jText.setText(jText.getText() + f.getAbsolutePath() + '\n'); } dtde.dropComplete(true); } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String text = (String) tr.getTransferData(DataFlavor.stringFlavor); jText.setText(jText.getText() + text + '\n'); } else { dtde.rejectDrop(); } } catch (Exception e) { e.printStackTrace(); } } }; new DropTarget(srcText, DnDConstants.ACTION_COPY_OR_MOVE, fileDropListener); new DropTarget(targetText, DnDConstants.ACTION_COPY_OR_MOVE, fileDropListener); new DropTarget(tempText, DnDConstants.ACTION_COPY_OR_MOVE, fileDropListener); }