Example usage for java.awt.dnd DnDConstants ACTION_LINK

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

Introduction

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

Prototype

int ACTION_LINK

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

Click Source Link

Document

An int representing a "link" action.

Usage

From source file:net.sf.jabref.gui.fieldeditors.FileListEditorTransferHandler.java

/**
 * Overridden to indicate which types of drags are supported (only LINK + COPY).
 * COPY is supported as no support disables CTRL+C (copy of text)
 *//*from w w w. j  a  v  a2 s.co  m*/
@Override
public int getSourceActions(JComponent c) {
    return DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY;
}

From source file:HostPanel.java

/**
 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
 *//*w w w.j a va  2 s .  com*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    dropTargetScroll = new javax.swing.JScrollPane();
    dropTargetArea = new javax.swing.JTextArea();
    dropTargetTitle = new javax.swing.JLabel();
    globalProgress = new javax.swing.JProgressBar();
    currentProgress = new javax.swing.JProgressBar();
    transferButton = new javax.swing.JButton();
    dropTargetValue = new javax.swing.JLabel();
    dropTargetClear = new javax.swing.JLabel();
    statusDisplay1 = new javax.swing.JLabel();
    statusDisplay2 = new javax.swing.JLabel();

    setFocusable(false);

    dropTargetScroll.setFocusable(false);

    dropTargetArea.setDropTarget(new DropTarget() {
        @Override
        public synchronized void drop(DropTargetDropEvent evt) {
            if (transfer == null || transfer.isDone()) {
                evt.acceptDrop(DnDConstants.ACTION_LINK);
                Transferable transferable = evt.getTransferable();

                try {
                    if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                        ProcessDropTarget pdt = new ProcessDropTarget(
                                (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor));
                        pdt.execute();
                    }
                } catch (UnsupportedFlavorException | IOException ex) {
                    Logger.getLogger(HostPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    dropTargetArea.setEditable(false);
    dropTargetArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
    dropTargetArea.setFocusable(false);
    dropTargetScroll.setViewportView(dropTargetArea);

    dropTargetTitle.setText("Drag files to host onto box below");
    dropTargetTitle.setFocusable(false);

    globalProgress.setFocusable(false);
    globalProgress.setRequestFocusEnabled(false);
    globalProgress.setStringPainted(true);

    currentProgress.setFocusable(false);
    currentProgress.setRequestFocusEnabled(false);
    currentProgress.setStringPainted(true);

    transferButton.setText("Host");
    transferButton.setActionCommand("host");
    transferButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            transferButtonActionPerformed(evt);
        }
    });

    dropTargetValue.setText("Files to Share: 0");
    dropTargetValue.setFocusable(false);

    dropTargetClear.setText("Clear");
    dropTargetClear.setFocusable(false);
    dropTargetClear.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseReleased(java.awt.event.MouseEvent evt) {
            dropTargetClearMouseReleased(evt);
        }
    });

    statusDisplay1.setText("");

    statusDisplay2.setText("");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dropTargetScroll)
                            .addGroup(layout.createSequentialGroup().addGroup(
                                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(globalProgress, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    165, Short.MAX_VALUE)
                                            .addComponent(currentProgress, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(statusDisplay1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    359, Short.MAX_VALUE)
                                            .addComponent(statusDisplay2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(18, 18, 18)
                                    .addComponent(transferButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
                                            javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup().addComponent(dropTargetTitle)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(dropTargetValue, javax.swing.GroupLayout.PREFERRED_SIZE, 136,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18).addComponent(dropTargetClear)))
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(dropTargetTitle).addComponent(dropTargetValue)
                            .addComponent(dropTargetClear))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(dropTargetScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup().addGroup(layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(currentProgress, javax.swing.GroupLayout.PREFERRED_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(statusDisplay1))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(globalProgress,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(statusDisplay2)))
                            .addComponent(transferButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap()));
}

From source file:net.sf.jabref.groups.EntryTableTransferHandler.java

/**
 * Overridden to indicate which types of drags are supported (only LINK).
 *//* w w w  .j  a  va2 s  .  co m*/
@Override
public int getSourceActions(JComponent c) {
    return DnDConstants.ACTION_LINK;
}

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 . c o  m*/

    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:net.sf.jabref.groups.EntryTableTransferHandler.java

@Override
public void exportAsDrag(JComponent comp, InputEvent e, int action) {
    if (e instanceof MouseEvent) {
        int columnIndex = entryTable.columnAtPoint(((MouseEvent) e).getPoint());
        int modelIndex = entryTable.getColumnModel().getColumn(columnIndex).getModelIndex();
        if (entryTable.isFileColumn(modelIndex)) {
            LOGGER.info("Dragging file");
            draggingFile = true;/*from   www. j a  v a 2  s  .c  o m*/
        }
    }
    super.exportAsDrag(comp, e, DnDConstants.ACTION_LINK);
}

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;/*from  w  ww .  j a v a  2s  . co  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:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Setup the drop target for channel subscription via drag-and-drop.
 *
 * @since  1.2//from w  ww  . j av a 2 s. c o m
 */
void initDropTarget() {
    new DropTarget(component, DnDConstants.ACTION_LINK, this);
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent e) {
    try {//  ww w. j ava2s .  c  o m
        int dropAction = e.getDropAction();
        if (dropAction == DnDConstants.ACTION_LINK) {
            DataFlavor channelListDataFlavor = new ChannelListDataFlavor();
            Transferable tr = e.getTransferable();
            if (e.isDataFlavorSupported(channelListDataFlavor)) {
                e.acceptDrop(DnDConstants.ACTION_LINK);
                e.dropComplete(true);

                final List<String> channels = (List) tr.getTransferData(channelListDataFlavor);

                new Thread() {
                    public void run() {
                        for (int i = 0; i < channels.size(); i++) {
                            String channel = channels.get(i);
                            boolean status;
                            if (supportsMultipleChannels()) {
                                status = addChannel(channel);
                            } else {
                                status = setChannel(channel);
                            }

                            if (!status) {
                                // TODO display an error in the UI
                            }
                        }
                    }
                }.start();
            } else {
                e.rejectDrop();
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedFlavorException ufe) {
        ufe.printStackTrace();
    }
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

/**
 * an overridden method from//from  w w w .  j  av  a  2 s  . co  m
 * 
 * @see org.rdv.datapanel.AbstractDataPanel for the
 * @see DropTargetListener interface
 */
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent e) {
    try {
        int dropAction = e.getDropAction();
        if (dropAction == DnDConstants.ACTION_LINK) {
            DataFlavor channelListDataFlavor = new ChannelListDataFlavor();
            Transferable tr = e.getTransferable();
            if (e.isDataFlavorSupported(channelListDataFlavor)) {
                e.acceptDrop(DnDConstants.ACTION_LINK);
                e.dropComplete(true);

                // calculate which table the x coordinate of the mouse
                // corresponds to
                double clickX = e.getLocation().getX(); // get the mouse x
                // coordinate
                int compWidth = dataComponent.getWidth(); // gets the
                // width of this
                // component
                final int tableNum = (int) (clickX * columnGroupCount / compWidth);

                final List<String> channels = (List) tr.getTransferData(channelListDataFlavor);

                new Thread() {
                    public void run() {
                        for (int i = 0; i < channels.size(); i++) {
                            String channel = channels.get(i);
                            boolean status;
                            if (supportsMultipleChannels()) {
                                status = addChannel(channel, tableNum);
                            } else {
                                status = setChannel(channel);
                            }

                            if (!status) {
                                // TODO display an error in the UI
                            }
                        }
                    }
                }.start();
            } else {
                e.rejectDrop();
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedFlavorException ufe) {
        ufe.printStackTrace();
    }
}

From source file:org.rdv.ui.ChannelListPanel.java

/**
 * Create the channel tree panel.//  w  ww. j a va 2  s. c om
 * 
 * @return  the component containing the channel tree
 */
private JComponent createTreePanel() {
    treeModel = new ChannelTreeModel();
    treeModel.addPropertyChangeListener(new FilterPropertyChangeListener());

    tree = new JTree(treeModel);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setExpandsSelectedPaths(true);
    tree.setCellRenderer(new ChannelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addTreeSelectionListener(new ChannelTreeSelectionListener());
    tree.addMouseListener(new ChannelTreeMouseListener());
    tree.setBorder(new EmptyBorder(0, 5, 5, 5));

    JScrollPane treeView = new JScrollPane(tree);
    treeView.setBorder(null);
    treeView.setViewportBorder(null);

    tree.setDragEnabled(true);
    tree.setTransferHandler(new ChannelTransferHandler());

    DragSource dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_LINK,
            new ChannelDragGestureListener());

    return treeView;
}