Example usage for java.awt.dnd DnDConstants ACTION_COPY

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

Introduction

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

Prototype

int ACTION_COPY

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

Click Source Link

Document

An int representing a "copy" action.

Usage

From source file:org.jas.dnd.MultiLayerDropTargetListener.java

@Override
public void dragOver(DropTargetDragEvent dtde) {
    initializeTransferable(dtde.getTransferable(), false);
    getDragAction().setLocation(dtde.getLocation());
    if (getDragAction().validate(dtde.getLocation())) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY);
    } else {/*from  ww  w.  j  a va  2 s.  c  om*/
        dtde.rejectDrag();
    }
}

From source file:org.jas.dnd.MultiLayerDropTargetListener.java

@Override
public void drop(final DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    initializeTransferable(dtde.getTransferable(), true);
    boolean success = getDragAction().drop(dtde.getLocation());
    if (success) {
        log.info("drop success");
    }//from w  w w  . j  a va 2s  . c  om
    lastDropSuccess = success;
}

From source file:FileTreeDropTarget.java

protected void transferDirectory(int action, File srcDir, File targetDirectory,
        FileTree.FileTreeNode targetNode) {
    DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " directory "
            + srcDir.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath());

    // Do not copy a directory into itself or 
    // a subdirectory of itself.
    File parentDir = targetDirectory;
    while (parentDir != null) {
        if (parentDir.equals(srcDir)) {
            DnDUtils.debugPrintln("-- SUPPRESSED");
            return;
        }/*www.j  av  a 2  s.  c  om*/
        parentDir = parentDir.getParentFile();
    }

    // Copy the directory itself, then its contents

    // Create a File entry for the target
    String name = srcDir.getName();
    File newDir = new File(targetDirectory, name);
    if (newDir.exists()) {
        // Already exists - is it the same directory?
        if (newDir.equals(srcDir)) {
            // Exactly the same file - ignore
            return;
        }
    } else {
        // Directory does not exist - create it
        if (newDir.mkdir() == false) {
            // Failed to create - abandon this directory
            JOptionPane.showMessageDialog(tree,
                    "Failed to create target directory\n  " + newDir.getAbsolutePath(),
                    "Directory creation Failed", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    // Add a node for the new directory
    if (targetNode != null) {
        targetNode = tree.addNode(targetNode, name);
    }

    // Now copy the directory content.
    File[] files = srcDir.listFiles();
    for (int i = 0; i < files.length; i++) {
        File f = files[i];
        if (f.isFile()) {
            transferFile(action, f, newDir, targetNode);
        } else if (f.isDirectory()) {
            transferDirectory(action, f, newDir, targetNode);
        }
    }

    // Remove the source directory after moving
    if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) {
        srcDir.delete();
    }
}

From source file:javazoom.jlgui.player.amp.Player.java

/**
 * Constructor.//from  ww w .  j a  v a2  s. com
 */
public Player(String Skin, Frame top) {
    super(top);
    topFrame = top;

    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Init player applet.//from ww  w.  j  a  v  a2s  .c om
 */
public void initPlayer(String Skin) {
    // Config feature.
    config = Config.getInstance();
    config.load(initConfig);
    OrigineX = config.getXLocation();
    OrigineY = config.getYLocation();

    // Get screen size
    try {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dimension = toolkit.getScreenSize();
        screenWidth = dimension.width;
        screenHeight = dimension.height;
    } catch (Exception e) {
    }

    // Minimize/Maximize/Icon features.
    //topFrame.addWindowListener(this);
    topFrame.setLocation(OrigineX, OrigineY);
    topFrame.setSize(0, 0);
    // Polis : Comment out to fix a bug under XWindow
    //topFrame.setResizable(false);
    ClassLoader cl = this.getClass().getClassLoader();
    URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif");
    if (iconURL != null) {
        ImageIcon jlguiIcon = new ImageIcon(iconURL);
        //topFrame.setIconImage(jlguiIcon.getImage());
    }
    topFrame.show();

    // DnD feature.
    DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true);

    // Playlist feature.
    boolean playlistfound = false;
    if ((initSong != null) && (!initSong.equals("")))
        playlistfound = loadPlaylist(initSong);
    else
        playlistfound = loadPlaylist(config.getPlaylistFilename());

    // Load skin specified in args
    if (Skin != null) {
        thePath = Skin;
        log.info("Load default skin from " + thePath);
        loadSkin(thePath);
        config.setDefaultSkin(thePath);
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        //ClassLoader cl = this.getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        loadSkin(sis);
    }

    // Go to playlist begining if needed.
    if ((playlist != null) && (playlistfound == true)) {
        if (playlist.getPlaylistSize() > 0)
            acNext.fireEvent();
    }

    // Display the whole
    hide();
    show();
    repaint();
}

From source file:at.becast.youploader.gui.FrmMain.java

public void initMainTab() {
    cmbCategory = new JComboBox<Categories>();
    cmbCategory.setModel(new DefaultComboBoxModel<Categories>(Categories.values()));
    SideBar sideBar = new SideBar(SideBar.SideBarMode.TOP_LEVEL, true, 300, true);
    ss1 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Settings"), new EditPanel(this),
            new ImageIcon(getClass().getResource("/pencil.png")));
    ss2 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Playlists"), new PlaylistPanel(this),
            new ImageIcon(getClass().getResource("/layers.png")));
    ss3 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Monetisation"), new MonetPanel(),
            new ImageIcon(getClass().getResource("/money.png")));
    sideBar.addSection(ss1, false);//  www .  j  a va2 s  .co m
    sideBar.addSection(ss2);
    sideBar.addSection(ss3);
    JPanel mainTab = new JPanel();
    JPanel panel = new JPanel();
    GroupLayout mainTabLayout = new GroupLayout(mainTab);
    mainTabLayout.setHorizontalGroup(mainTabLayout.createParallelGroup(Alignment.TRAILING)
            .addGroup(mainTabLayout.createSequentialGroup()
                    .addComponent(panel, GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)));
    mainTabLayout.setVerticalGroup(mainTabLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(panel, GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
            .addGroup(mainTabLayout.createSequentialGroup()
                    .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE).addContainerGap()));
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { ColumnSpec.decode("2px"), FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("20px:grow"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
                    ColumnSpec.decode("23px"), ColumnSpec.decode("33px"), FormSpecs.UNRELATED_GAP_COLSPEC,
                    ColumnSpec.decode("61px"), FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("24px"), ColumnSpec.decode("28px"), ColumnSpec.decode("40px"),
                    ColumnSpec.decode("36px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("28px"),
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("58px"), },
            new RowSpec[] { RowSpec.decode("2px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    RowSpec.decode("64dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    RowSpec.decode("max(64dlu;default)"), FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("25px"), FormSpecs.PARAGRAPH_GAP_ROWSPEC,
                    RowSpec.decode("24px"), RowSpec.decode("23px"), }));

    lbltitlelenght = new JLabel("(0/100)");
    panel.add(lbltitlelenght, "14, 6, 3, 1, right, top");

    txtTitle = new JTextField();
    contextMenu.add(txtTitle);
    panel.add(txtTitle, "3, 7, 14, 1, fill, fill");
    txtTitle.setColumns(10);
    txtTitle.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblCategory = new JLabel(LANG.getString("frmMain.Category"));
    panel.add(lblCategory, "3, 9, 4, 1, left, bottom");
    panel.add(cmbCategory, "3, 10, 14, 1, fill, fill");

    JLabel lblDescription = new JLabel(LANG.getString("frmMain.Description"));
    panel.add(lblDescription, "3, 12, 4, 1, left, bottom");

    lblDesclenght = new JLabel("(0/5000)");
    panel.add(lblDesclenght, "14, 12, 3, 1, right, bottom");

    JScrollPane DescriptionScrollPane = new JScrollPane();
    panel.add(DescriptionScrollPane, "3, 13, 14, 1, fill, fill");

    txtDescription = new JTextArea();
    contextMenu.add(txtDescription);
    txtDescription.setFont(new Font("SansSerif", Font.PLAIN, 13));
    DescriptionScrollPane.setViewportView(txtDescription);
    txtDescription.setWrapStyleWord(true);
    txtDescription.setLineWrap(true);
    txtDescription.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblTags = new JLabel(LANG.getString("frmMain.Tags"));
    panel.add(lblTags, "3, 15, 4, 1, left, bottom");

    lblTagslenght = new JLabel("(0/500)");
    panel.add(lblTagslenght, "14, 15, 3, 1, right, top");

    JScrollPane TagScrollPane = new JScrollPane();
    panel.add(TagScrollPane, "3, 16, 14, 1, fill, fill");

    txtTags = new JTextArea();
    contextMenu.add(txtTags);
    txtTags.setFont(new Font("SansSerif", Font.PLAIN, 13));
    TagScrollPane.setViewportView(txtTags);
    txtTags.setWrapStyleWord(true);
    txtTags.setLineWrap(true);
    txtTags.setBorder(BorderFactory.createEtchedBorder());
    txtTags.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblAccount = new JLabel(LANG.getString("frmMain.Account"));
    panel.add(lblAccount, "3, 18, 4, 1, left, bottom");
    cmbAccount = new JComboBox<AccountType>();
    panel.add(getCmbAccount(), "3, 19, 14, 1, fill, fill");
    cmbAccount.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            changeUser();
        }
    });
    btnAddToQueue = new JButton(LANG.getString("frmMain.addtoQueue"));
    btnAddToQueue.setEnabled(false);
    panel.add(btnAddToQueue, "3, 21, 6, 1, fill, fill");
    btnAddToQueue.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            queueButton();
        }
    });
    JLabel lblSelectVideo = new JLabel();
    panel.add(lblSelectVideo, "3, 3, 4, 1, left, bottom");

    lblSelectVideo.setText(LANG.getString("frmMain.selectVideoFile"));
    cmbFile = new JComboBox<String>();
    cmbFile.setDropTarget(new DropTarget() {
        private static final long serialVersionUID = 8809983794742040683L;

        public synchronized void drop(DropTargetDropEvent evt) {
            try {
                evt.acceptDrop(DnDConstants.ACTION_COPY);
                @SuppressWarnings("unchecked")
                List<File> droppedFiles = (List<File>) evt.getTransferable()
                        .getTransferData(DataFlavor.javaFileListFlavor);
                for (File file : droppedFiles) {
                    cmbFile.removeAllItems();
                    cmbFile.addItem(file.getAbsolutePath());
                }
            } catch (Exception ex) {
                LOG.error("Error dropping video file", ex);
            }
        }
    });
    panel.add(cmbFile, "3, 4, 14, 1, fill, fill");
    JButton btnSelectMovie = new JButton();
    btnSelectMovie.setToolTipText("Select Video File");
    panel.add(btnSelectMovie, "18, 4, center, top");
    btnSelectMovie.setIcon(new ImageIcon(getClass().getResource("/film_add.png")));

    JLabel lblTitle = new JLabel(LANG.getString("frmMain.Title"));
    panel.add(lblTitle, "3, 6, 4, 1, left, bottom");

    JButton btnReset = new JButton(LANG.getString("frmMain.Reset"));
    btnReset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            resetEdit();
        }
    });
    panel.add(btnReset, "11, 21, 6, 1, fill, fill");
    btnSelectMovie.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            EditPanel edit = (EditPanel) ss1.contentPane;
            NativeJFileChooser chooser;
            if (edit.getTxtStartDir() != null && !edit.getTxtStartDir().equals("")) {
                chooser = new NativeJFileChooser(edit.getTxtStartDir().getText().trim());
            } else {
                chooser = new NativeJFileChooser();
            }
            int returnVal = chooser.showOpenDialog((Component) self);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                cmbFile.removeAllItems();
                cmbFile.addItem(chooser.getSelectedFile().getAbsolutePath().toString());
            }
        }
    });
    mainTab.setLayout(mainTabLayout);
    mainTab.revalidate();
    mainTab.repaint();
    TabbedPane.addTab(LANG.getString("frmMain.Tabs.VideoSettings"), mainTab);
}

From source file:DragDropTreeExample.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 ww  . j av a 2s  .  c o  m*/
    } 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:net.sf.nmedit.jtheme.component.JTModuleContainer.java

public void copyMoveModules(DropTargetDropEvent dtde) {
    DataFlavor chosen = PDragDrop.ModuleSelectionFlavor;
    Transferable transfer = dtde.getTransferable();
    Object data = null;//  w w  w  .j  a v  a2  s. c o m

    try {
        // Get the data
        data = transfer.getTransferData(chosen);

        dtde.acceptDrop(dtde.getDropAction()
                & (DnDConstants.ACTION_MOVE | DnDConstants.ACTION_COPY | DnDConstants.ACTION_LINK));
    } catch (Throwable t) {
        if (log.isWarnEnabled()) {
            log.warn("copyMoveModules(DropTargetDropEvent=" + dtde + ") failed", t);
        }
        dtde.dropComplete(false);
        return;
    }

    if (data != null && data instanceof PModuleTransferData) {
        // Cast the data and create a nice module.
        PModuleTransferData tdata = ((PModuleTransferData) data);
        boolean isSamePatch = false;
        if (tdata.getSourcePatch() == getModuleContainer().getPatch())
            isSamePatch = true;

        //Point p = dtde.getLocation();

        int action = dtde.getDropAction();

        if ((action & DnDConstants.ACTION_MOVE) != 0 && isSamePatch) {
            MoveOperation op = tdata.getSourceModuleContainer().createMoveOperation();
            op.setDestination(getModuleContainer());
            executeOperationOnSelection(tdata, dtde.getLocation(), op);
        } else {
            copyModules(tdata, dtde.getLocation(), ((dtde.getDropAction() & DnDConstants.ACTION_LINK) != 0));
        }

    }
    dtde.dropComplete(true);
}

From source file:com.ftb2om2.view.MultiplePane.java

private String getDragAndDropPath(DropTargetDropEvent evt) throws IOException, UnsupportedFlavorException {
    evt.acceptDrop(DnDConstants.ACTION_COPY);
    List<File> droppedFile = (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
    return droppedFile.get(0).getAbsolutePath();
}

From source file:com.ftb2om2.view.MultiplePane.java

private void difficultyTableDragAndDrop(DropTargetDropEvent evt) {
    try {//from   ww  w .  jav a  2s .c  om
        DefaultTableModel model = (DefaultTableModel) difficultyTable.getModel();
        evt.acceptDrop(DnDConstants.ACTION_COPY);
        List<File> droppedFile = (List<File>) evt.getTransferable()
                .getTransferData(DataFlavor.javaFileListFlavor);
        droppedFile.forEach(file -> model.addRow(
                new Object[] { file.getName(), file.getPath(), FilenameUtils.getBaseName(file.getPath()) }));
    } catch (Exception ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.INFO, null, ex);
    }
}