Example usage for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE

List of usage examples for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE

Introduction

In this page you can find the example usage for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE.

Prototype

int ACTION_COPY_OR_MOVE

To view the source code for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE.

Click Source Link

Document

An int representing a "copy" or "move" action.

Usage

From source file:FileTreeDragSource.java

public FileTreeDragSource(FileTree tree) {
    this.tree = tree;

    // Use the default DragSource
    DragSource dragSource = DragSource.getDefaultDragSource();

    // Create a DragGestureRecognizer and
    // register as the listener
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_COPY_OR_MOVE, this);
}

From source file:EditorDropTarget4.java

public EditorDropTarget4(JEditorPane pane) {
    this.pane = pane;

    // Listen for changes in the enabled property
    pane.addPropertyChangeListener(this);

    // Save the JEditorPane's background color
    backgroundColor = pane.getBackground();

    // Create the DropTarget and register
    // it with the JEditorPane.
    dropTarget = new DropTarget(pane, DnDConstants.ACTION_COPY_OR_MOVE, this, pane.isEnabled(), null);
}

From source file:TreeDragTest.java

public TreeDragTest() {
    super("Rearrangeable Tree");
    setSize(300, 200);//from  w  w  w  . j  a v a 2 s  . c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // If you want autoscrolling, use this line:
    tree = new AutoScrollingJTree();
    // Otherwise, use this line:
    //tree = new JTree();
    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);

    // If we only support move operations...
    //ds = new TreeDragSource(tree, DnDConstants.ACTION_MOVE);
    ds = new TreeDragSource(tree, DnDConstants.ACTION_COPY_OR_MOVE);
    dt = new TreeDropTarget(tree);
    setVisible(true);
}

From source file:DropTest2.java

public void drop(DropTargetDropEvent dtde) {
    try {//from w ww. j a v  a2  s .  c  om
        // Ok, get the dropped object and try to figure out what it is
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            System.out.println("Possible flavor: " + flavors[i].getMimeType());
            // Check for file lists specifically
            if (flavors[i].isFlavorJavaFileListType()) {
                // Great! Accept copy drops...
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                ta.setText("Successful file list drop.\n\n");

                // And add the list of file names to our text area
                java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
                for (int j = 0; j < list.size(); j++) {
                    ta.append(list.get(j) + "\n");
                }

                // If we made it this far, everything worked.
                dtde.dropComplete(true);
                return;
            }
            // Ok, is it another Java object?
            else if (flavors[i].isFlavorSerializedObjectType()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                ta.setText("Successful text drop.\n\n");
                Object o = tr.getTransferData(flavors[i]);
                ta.append("Object: " + o);
                dtde.dropComplete(true);
                return;
            }
            // How about an input stream?
            else if (flavors[i].isRepresentationClassInputStream()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                ta.setText("Successful text drop.\n\n");
                ta.read(new InputStreamReader((InputStream) tr.getTransferData(flavors[i])),
                        "from system clipboard");
                dtde.dropComplete(true);
                return;
            }
        }
        // Hmm, the user must not have dropped a file list
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}

From source file:PanelDropTarget.java

public void drop(DropTargetDropEvent dtde) {
    DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Check the drop action
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
        // Accept the drop and get the transfer data
        dtde.acceptDrop(dtde.getDropAction());
        Transferable transferable = dtde.getTransferable();

        try {/*from  ww  w  . ja v  a2s. co m*/
            boolean result = dropComponent(transferable);

            dtde.dropComplete(result);
            DnDUtils.debugPrintln("Drop completed, success: " + result);
        } catch (Exception e) {
            DnDUtils.debugPrintln("Exception while handling drop " + e);
            dtde.dropComplete(false);
        }
    } else {
        DnDUtils.debugPrintln("Drop target rejected drop");
        dtde.rejectDrop();
    }
}

From source file:TreeTester.java

public DndTree() {
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE,
            new TreeDragGestureListener());
    DropTarget dropTarget = new DropTarget(this, new TreeDropTargetListener());
}

From source file:ColorSource.java

/** Create a new ColorSource object that displays the speciifed color */
public ColorSource(Color color) {
    // Save the color.  Encapsulate it in a Transferable object so that
    // it can be used with cut-and-paste and drag-and-drop
    this.color = color;
    this.tcolor = new TransferableColor(color);

    // Set our default border
    this.setBorder(defaultBorder);

    // Listen for mouse clicks, and copy the color to the clipboard.
    this.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            copy();/* w  w  w. ja  va2  s.c  o  m*/
        }
    });

    // Set up a DragGestureRecognizer that will detect when the user 
    // begins a drag.  When it detects one, it will notify us by calling
    // the dragGestureRecognized() method of the DragGestureListener
    // interface we implement below
    this.dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, // Look for drags on us
            DnDConstants.ACTION_COPY_OR_MOVE, // Recognize these types
            this); // Tell us when recognized
}

From source file:EditorDropTarget.java

public void drop(DropTargetDropEvent dtde) {
    DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Check the drop action
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
        // Accept the drop and get the transfer data
        dtde.acceptDrop(dtde.getDropAction());
        Transferable transferable = dtde.getTransferable();

        try {/*from  w w  w. ja  v a2s  .  c  om*/
            boolean result = dropFile(transferable);

            dtde.dropComplete(result);
            DnDUtils.debugPrintln("Drop completed, success: " + result);
        } catch (Exception e) {
            DnDUtils.debugPrintln("Exception while handling drop " + e);
            dtde.dropComplete(false);
        }
    } else {
        DnDUtils.debugPrintln("Drop target rejected drop");
        dtde.rejectDrop();
    }
}

From source file:TreeTester.java

public DndTree(TreeModel model) {
    super(model);
    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE,
            new TreeDragGestureListener());
    DropTarget dropTarget = new DropTarget(this, new TreeDropTargetListener());
}

From source file:de.tor.tribes.ui.algo.AttackTimePanel.java

/**
 * Creates new form TestPanel//from w  ww .jav  a  2  s .c  o  m
 *
 * @param pListener
 */
public AttackTimePanel(SettingsChangedListener pListener) {
    initComponents();
    mListener = pListener;
    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(jLabel5, DnDConstants.ACTION_COPY_OR_MOVE,
            AttackTimePanel.this);
    dragSource.createDefaultDragGestureRecognizer(jLabel6, DnDConstants.ACTION_COPY_OR_MOVE,
            AttackTimePanel.this);
    DropTarget dropTarget = new DropTarget(this, this);
    jTimeFrameList.setDropTarget(dropTarget);

    jSendTimeFrame.addColorisationListener(new ColorisationListener() {
        @Override
        public void newColors(ColorisationEvent ColorisationEvent_Arg) {
            updatePreview();
        }
    });
    dateTimeField.setActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updatePreview();
        }
    });

    jTimeFrameList.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                deleteSelectedTimeSpan();
            }
        }
    });
    jArriveInPastLabel.setVisible(false);
    maxArriveTimeField.setActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            TimeFrame currentFrame = getTimeFrame();
            if (currentFrame != null) {
                jArriveInPastLabel
                        .setVisible(currentFrame.getArriveRange().getMaximum() < System.currentTimeMillis());
            }
        }
    });
    reset();

    updatePreview();
}