List of usage examples for java.awt.dnd DnDConstants ACTION_COPY
int ACTION_COPY
To view the source code for java.awt.dnd DnDConstants ACTION_COPY.
Click Source Link
From source file:org.eclipse.swt.snippets.Snippet319.java
public void go() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 319"); shell.setBounds(10, 10, 600, 200);/*from ww w . ja v a2s.com*/ /* Create SWT controls and add drag source */ final Label swtLabel = new Label(shell, SWT.BORDER); swtLabel.setBounds(10, 10, 580, 50); swtLabel.setText("SWT drag source"); DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY); dragSource.setTransfer(new MyTypeTransfer()); dragSource.addDragListener(new DragSourceAdapter() { @Override public void dragSetData(DragSourceEvent event) { MyType object = new MyType(); object.name = "content dragged from SWT"; object.time = System.currentTimeMillis(); event.data = object; } }); /* Create AWT/Swing controls */ Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED); embeddedComposite.setBounds(10, 100, 580, 50); embeddedComposite.setLayout(new FillLayout()); Frame frame = SWT_AWT.new_Frame(embeddedComposite); final JLabel jLabel = new JLabel("AWT/Swing drop target"); frame.add(jLabel); /* Register the custom data flavour */ final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor"); /* * Note that according to jre/lib/flavormap.properties, the preferred way to * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL * property in an awt.properties file. * * This snippet uses the alternate approach below in order to provide a simple * stand-alone snippet that demonstrates the functionality. This implementation * works well, but if the instanceof check below fails for some reason when used * in a different context then the drop will not be accepted. */ FlavorMap map = SystemFlavorMap.getDefaultFlavorMap(); if (map instanceof SystemFlavorMap) { SystemFlavorMap systemMap = (SystemFlavorMap) map; systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor); } /* add drop target */ DropTargetListener dropTargetListener = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dropTargetDropEvent) { try { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY); ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable() .getTransferData(flavor); int available = inStream.available(); byte[] bytes = new byte[available]; inStream.read(bytes); MyType object = restoreFromByteArray(bytes); String string = object.name + ": " + new Date(object.time).toString(); jLabel.setText(string); } catch (Exception e) { e.printStackTrace(); } } }; new DropTarget(jLabel, dropTargetListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java
public EqualizerUI() { super();//from ww w . j a v a 2 s. co m setDoubleBuffered(true); config = Config.getInstance(); eqgains = new int[10]; setLayout(new AbsoluteLayout()); int[] vals = config.getLastEqualizer(); if (vals != null) { for (int h = 0; h < vals.length; h++) { gainValue[h] = vals[h]; } } // DnD support disabled. DropTargetAdapter dnd = new DropTargetAdapter() { public void processDrop(Object data) { return; } }; DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, false); }
From source file:EditorDropTarget2.java
protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) { int dropAction = dtde.getDropAction(); int sourceActions = dtde.getSourceActions(); boolean acceptedDrag = false; DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is " + DnDUtils.showActions(dropAction)); // Reject if the object being transferred // or the operations available are not acceptable if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag();/*from w w w. j ava 2 s . c o m*/ } else if (!draggingFile && !pane.isEditable()) { // Can't drag text to a read-only JEditorPane DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { // Not offering copy or move - suggest a copy DnDUtils.debugPrintln("Drop target offering COPY"); dtde.acceptDrag(DnDConstants.ACTION_COPY); acceptedDrag = true; } else { // Offering an acceptable operation: accept DnDUtils.debugPrintln("Drop target accepting drag"); dtde.acceptDrag(dropAction); acceptedDrag = true; } return acceptedDrag; }
From source file:PanelDropTarget.java
public static String showActions(int action) { String actions = ""; if ((action & (DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY_OR_MOVE)) == 0) { return "None"; }/*from w ww . j a va 2 s . com*/ if ((action & DnDConstants.ACTION_COPY) != 0) { actions += "Copy "; } if ((action & DnDConstants.ACTION_MOVE) != 0) { actions += "Move "; } if ((action & DnDConstants.ACTION_LINK) != 0) { actions += "Link"; } return actions; }
From source file:com.qspin.qtaste.ui.TestCaseTree.java
public TestCaseTree(TestCasePane testCasePn) { super();/*from w w w. ja v a 2 s .c o m*/ mTestCaseTree = this; this.setCellRenderer(new TestCaseTreeCellRenderer()); testCasePane = testCasePn; testCasePane.setTestCaseTree(this); ToolTipManager.sharedInstance().registerComponent(this); FileNode rootFileNode = createRootFileNode(); TCTreeNode rootNode = new TCTreeNode(rootFileNode, true); DefaultTreeModel tm = new DefaultTreeModel(rootNode); setModel(tm); generateScriptsTree(rootFileNode); TCTreeListener listener = new TCTreeListener(); this.addMouseListener(listener); addTreeWillExpandListener(listener); addTreeSelectionListener(listener); TreeSelectionModel selModel = this.getSelectionModel(); selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // drag drop initialization ds = new DragSource(); dt = new DropTarget(); ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); try { dt.setComponent(this); dt.addDropTargetListener(this); } catch (java.util.TooManyListenersException e) { logger.error(e.getMessage()); } }
From source file:EditorDropTarget4.java
protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) { int dropAction = dtde.getDropAction(); int sourceActions = dtde.getSourceActions(); boolean acceptedDrag = false; DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is " + DnDUtils.showActions(dropAction)); // Reject if the object being transferred // or the operations available are not acceptable. if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag();//from www.j a va2 s . c o m } else if (!draggingFile && !pane.isEditable()) { // Can't drag text to a read-only JEditorPane DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { // Not offering copy or move - suggest a copy DnDUtils.debugPrintln("Drop target offering COPY"); dtde.acceptDrag(DnDConstants.ACTION_COPY); acceptedDrag = true; } else { // Offering an acceptable operation: accept DnDUtils.debugPrintln("Drop target accepting drag"); dtde.acceptDrag(dropAction); acceptedDrag = true; } return acceptedDrag; }
From source file:FileTreeDropTarget.java
protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) { int dropAction = dtde.getDropAction(); int sourceActions = dtde.getSourceActions(); boolean acceptedDrag = false; DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is " + DnDUtils.showActions(dropAction)); Point location = dtde.getLocation(); boolean acceptableDropLocation = isAcceptableDropLocation(location); // Reject if the object being transferred // or the operations available are not acceptable. if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag();//from w w w . j a v a 2s . c om } else if (!tree.isEditable()) { // Can't drag to a read-only FileTree DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if (!acceptableDropLocation) { // Can only drag to writable directory DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { // Not offering copy or move - suggest a copy DnDUtils.debugPrintln("Drop target offering COPY"); dtde.acceptDrag(DnDConstants.ACTION_COPY); acceptedDrag = true; } else { // Offering an acceptable operation: accept DnDUtils.debugPrintln("Drop target accepting drag"); dtde.acceptDrag(dropAction); acceptedDrag = true; } return acceptedDrag; }
From source file:javazoom.jlgui.player.amp.PlayerUI.java
/** * Load main player.//from w w w .j a v a2 s . c o m * @param loader */ public void loadUI(Loader loader) { this.loader = loader; setLayout(new AbsoluteLayout()); config = Config.getInstance(); ui.setConfig(config); playlistUI = new PlaylistUI(); playlistUI.setSkin(ui); playlistUI.setPlayer(this); equalizerUI = new EqualizerUI(); equalizerUI.setSkin(ui); loadSkin(); // DnD support. DropTargetAdapter dnd = new DropTargetAdapter() { public void processDrop(Object data) { processDnD(data); } }; DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, dnd, true); }
From source file:ScribbleDragAndDrop.java
/** * This method implements the DragGestureListener interface. It will be * invoked when the DragGestureRecognizer thinks that the user has initiated * a drag. If we're not in drawing mode, then this method will try to figure * out which Scribble object is being dragged, and will initiate a drag on * that object./*from www . j a v a 2 s . c o m*/ */ public void dragGestureRecognized(DragGestureEvent e) { // Don't drag if we're not in drag mode if (!dragMode) return; // Figure out where the drag started MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent(); int x = inputEvent.getX(); int y = inputEvent.getY(); // Figure out which scribble was clicked on, if any by creating a // small rectangle around the point and testing for intersection. Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2); int numScribbles = scribbles.size(); for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles Scribble s = (Scribble) scribbles.get(i); if (s.intersects(r)) { // The user started the drag on top of this scribble, so // start to drag it. // First, remember which scribble is being dragged, so we can // delete it later (if this is a move rather than a copy) beingDragged = s; // Next, create a copy that will be the one dragged Scribble dragScribble = (Scribble) s.clone(); // Adjust the origin to the point the user clicked on. dragScribble.translate(-x, -y); // Choose a cursor based on the type of drag the user initiated Cursor cursor; switch (e.getDragAction()) { case DnDConstants.ACTION_COPY: cursor = DragSource.DefaultCopyDrop; break; case DnDConstants.ACTION_MOVE: cursor = DragSource.DefaultMoveDrop; break; default: return; // We only support move and copys } // Some systems allow us to drag an image along with the // cursor. If so, create an image of the scribble to drag if (dragSource.isDragImageSupported()) { Rectangle scribbleBox = dragScribble.getBounds(); Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height); Graphics2D g = (Graphics2D) dragImage.getGraphics(); g.setColor(new Color(0, 0, 0, 0)); // transparent background g.fillRect(0, 0, scribbleBox.width, scribbleBox.height); g.setColor(Color.black); g.setStroke(linestyle); g.translate(-scribbleBox.x, -scribbleBox.y); g.draw(dragScribble); Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y); // Now start dragging, using the image. e.startDrag(cursor, dragImage, hotspot, dragScribble, this); } else { // Or start the drag without an image e.startDrag(cursor, dragScribble, this); } // After we've started dragging one scribble, stop looking return; } } }
From source file:ca.phon.app.project.ProjectWindow.java
private void init() { /* Layout *//*from w ww . ja v a 2 s.c o m*/ setLayout(new BorderLayout()); final ProjectDataTransferHandler transferHandler = new ProjectDataTransferHandler(this); /* Create components */ newCorpusButton = createNewCorpusButton(); createCorpusButton = createCorpusButton(); corpusList = new JList<String>(); corpusModel = new CorpusListModel(getProject()); corpusList.setModel(corpusModel); corpusList.setCellRenderer(new CorpusListCellRenderer()); corpusList.setVisibleRowCount(20); corpusList.addListSelectionListener(e -> { if (getSelectedCorpus() != null) { String corpus = getSelectedCorpus(); sessionModel.setCorpus(corpus); sessionList.clearSelection(); corpusDetails.setCorpus(corpus); if (getProject().getCorpusSessions(corpus).size() == 0) { onSwapNewAndCreateSession(newSessionButton); } else { onSwapNewAndCreateSession(createSessionButton); } } }); corpusList.addMouseListener(new MouseInputAdapter() { @Override public void mousePressed(MouseEvent e) { doPopup(e); } @Override public void mouseReleased(MouseEvent e) { doPopup(e); } public void doPopup(MouseEvent e) { if (e.isPopupTrigger()) { int clickedIdx = corpusList.locationToIndex(e.getPoint()); if (clickedIdx >= 0 && Arrays.binarySearch(corpusList.getSelectedIndices(), clickedIdx) < 0) { corpusList.setSelectedIndex(clickedIdx); } showCorpusListContextMenu(e.getPoint()); } } }); final DragSource corpusDragSource = new DragSource(); corpusDragSource.createDefaultDragGestureRecognizer(corpusList, DnDConstants.ACTION_COPY, (event) -> { final List<ProjectPath> paths = new ArrayList<>(); for (String corpus : getSelectedCorpora()) { final ProjectPath corpusPath = new ProjectPath(getProject(), corpus, null); paths.add(corpusPath); } final ProjectPathTransferable transferable = new ProjectPathTransferable(paths); event.startDrag(DragSource.DefaultCopyDrop, transferable); }); corpusList.setDragEnabled(true); corpusList.setTransferHandler(transferHandler); corpusDetails = new CorpusDetailsPane(getProject()); corpusDetails.setWrapStyleWord(true); corpusDetails.setRows(6); corpusDetails.setLineWrap(true); corpusDetails.setBackground(Color.white); corpusDetails.setOpaque(true); JScrollPane corpusDetailsScroller = new JScrollPane(corpusDetails); sessionList = new JList<String>(); newSessionButton = createNewSessionButton(); createSessionButton = createSessionButton(); sessionModel = new SessionListModel(getProject()); sessionList.setModel(sessionModel); sessionList.setCellRenderer(new SessionListCellRenderer()); sessionList.setVisibleRowCount(20); sessionList.addListSelectionListener(e -> { if (sessionList.getSelectedValue() != null && !e.getValueIsAdjusting()) { String corpus = getSelectedCorpus(); String session = getSelectedSessionName(); sessionDetails.setSession(corpus, session); } }); sessionList.addMouseListener(new MouseInputAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == 1) { // get the clicked item int clickedItem = sessionList.locationToIndex(e.getPoint()); if (sessionList.getModel().getElementAt(clickedItem) == null) return; final String session = sessionList.getModel().getElementAt(clickedItem).toString(); final String corpus = ((SessionListModel) sessionList.getModel()).getCorpus(); msgPanel.reset(); msgPanel.setMessageLabel("Opening '" + corpus + "." + session + "'"); msgPanel.setIndeterminate(true); msgPanel.repaint(); SwingUtilities.invokeLater(() -> { final ActionEvent ae = new ActionEvent(sessionList, -1, "openSession"); (new OpenSessionAction(ProjectWindow.this, corpus, session)).actionPerformed(ae); msgPanel.setIndeterminate(false); }); } } @Override public void mousePressed(MouseEvent e) { doPopup(e); } @Override public void mouseReleased(MouseEvent e) { doPopup(e); } public void doPopup(MouseEvent e) { if (e.isPopupTrigger()) { int clickedIdx = sessionList.locationToIndex(e.getPoint()); if (clickedIdx >= 0 && Arrays.binarySearch(sessionList.getSelectedIndices(), clickedIdx) < 0) { sessionList.setSelectedIndex(clickedIdx); } showSessionListContextMenu(e.getPoint()); } } }); sessionList.setDragEnabled(true); sessionList.setTransferHandler(transferHandler); final DragSource sessionDragSource = new DragSource(); sessionDragSource.createDefaultDragGestureRecognizer(sessionList, DnDConstants.ACTION_COPY, (event) -> { final List<ProjectPath> paths = new ArrayList<>(); final String corpus = getSelectedCorpus(); if (corpus == null) return; for (String session : getSelectedSessionNames()) { final ProjectPath sessionPath = new ProjectPath(getProject(), corpus, session); paths.add(sessionPath); } final ProjectPathTransferable transferable = new ProjectPathTransferable(paths); event.startDrag(DragSource.DefaultCopyDrop, transferable); }); sessionDetails = new SessionDetailsPane(getProject()); sessionDetails.setLineWrap(true); sessionDetails.setRows(6); sessionDetails.setWrapStyleWord(true); sessionDetails.setBackground(Color.white); sessionDetails.setOpaque(true); JScrollPane sessionDetailsScroller = new JScrollPane(sessionDetails); JScrollPane corpusScroller = new JScrollPane(corpusList); JScrollPane sessionScroller = new JScrollPane(sessionList); blindModeBox = new JCheckBox("Blind transcription"); blindModeBox.setSelected(false); msgPanel = new StatusPanel(); corpusPanel = new JPanel(new BorderLayout()); corpusPanel.add(newCorpusButton, BorderLayout.NORTH); corpusPanel.add(corpusScroller, BorderLayout.CENTER); corpusPanel.add(corpusDetailsScroller, BorderLayout.SOUTH); sessionPanel = new JPanel(new BorderLayout()); sessionPanel.add(newSessionButton, BorderLayout.NORTH); sessionPanel.add(sessionScroller, BorderLayout.CENTER); sessionPanel.add(sessionDetailsScroller, BorderLayout.SOUTH); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(corpusPanel); splitPane.setRightComponent(sessionPanel); splitPane.setResizeWeight(0.5); // invoke later SwingUtilities.invokeLater(() -> { splitPane.setDividerLocation(0.5); }); // the frame layout String projectName = null; projectName = getProject().getName(); DialogHeader header = new DialogHeader(projectName, StringUtils.abbreviate(projectLoadPath, 80)); add(header, BorderLayout.NORTH); CellConstraints cc = new CellConstraints(); final JPanel topPanel = new JPanel(new FormLayout("pref, fill:pref:grow, right:pref", "pref")); topPanel.add(msgPanel, cc.xy(1, 1)); topPanel.add(blindModeBox, cc.xy(3, 1)); add(splitPane, BorderLayout.CENTER); add(topPanel, BorderLayout.SOUTH); // if no corpora are currently available, 'prompt' the user to create a new one if (getProject().getCorpora().size() == 0) { SwingUtilities.invokeLater(() -> { onSwapNewAndCreateCorpus(newCorpusButton); }); } else { SwingUtilities.invokeLater(() -> { corpusList.setSelectedIndex(0); }); } }