Example usage for java.awt.dnd DropTargetDropEvent getDropAction

List of usage examples for java.awt.dnd DropTargetDropEvent getDropAction

Introduction

In this page you can find the example usage for java.awt.dnd DropTargetDropEvent getDropAction.

Prototype

public int getDropAction() 

Source Link

Document

This method returns the user drop action.

Usage

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

/**
 * an overridden method from/*from www  . j  ava  2s  .com*/
 * 
 * @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:plugin.notes.gui.NotesTreeNode.java

/**
 * handles a drop of a java file list//from   ww  w.j a  v a 2s.  co  m
 *
 * @param dtde
 *          drop target drop even - a java dile list has been dropped on
 *          something that represents this node.
 * @return returns true if the drop takes place, false if not
 */
public boolean handleDropJavaFileList(DropTargetDropEvent dtde) {
    dtde.acceptDrop(dtde.getDropAction());

    Transferable t = dtde.getTransferable();

    try {
        List fileList = ((List) t.getTransferData(DataFlavor.javaFileListFlavor));

        for (Object aFileList : fileList) {
            File newFile = (File) aFileList;

            if (newFile.exists()) {

                FileUtils.copyFile(newFile,
                        new File(dir.getAbsolutePath() + File.separator + newFile.getName()));
            }
        }
    } catch (Exception e) {
        Logging.errorPrint(e.getMessage(), e);

        return false;
    }

    return true;
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

@Override
public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(dtde.getDropAction());
    File[] files = getDragDropPlugins(dtde.getCurrentDataFlavors(), dtde.getTransferable());

    try {/*w w w  .j av a2 s .  c om*/
        File tmpFile = File.createTempFile("plugins", ".txt");
        StringBuilder alreadyInstalled = new StringBuilder();
        StringBuilder notCompatiblePlugins = new StringBuilder();

        for (File jarFile : files) {
            ClassLoader classLoader = null;

            try {
                URL[] urls = new URL[] { jarFile.toURI().toURL() };
                classLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader());
            } catch (MalformedURLException exc) {

            }

            if (classLoader != null) {
                // Get the plugin name
                String pluginName = jarFile.getName();
                pluginName = pluginName.substring(0, pluginName.length() - 4);

                try {
                    String pluginId = "java." + pluginName.toLowerCase() + "." + pluginName;

                    PluginProxy installedPlugin = PluginProxyManager.getInstance().getPluginForId(pluginId);
                    TvDataServiceProxy service = TvDataServiceProxyManager.getInstance()
                            .findDataServiceById(pluginName.toLowerCase() + '.' + pluginName);

                    Class<?> pluginClass = classLoader.loadClass(pluginName.toLowerCase() + '.' + pluginName);

                    Method getVersion = pluginClass.getMethod("getVersion", new Class[0]);

                    Version version1 = null;
                    try {
                        version1 = (Version) getVersion.invoke(pluginClass, new Object[0]);
                    } catch (Throwable t1) {
                        t1.printStackTrace();
                    }

                    if (installedPlugin != null
                            && (installedPlugin.getInfo().getVersion().compareTo(version1) > 0
                                    || (installedPlugin.getInfo().getVersion().compareTo(version1) == 0
                                            && version1.isStable()))) {
                        alreadyInstalled.append(installedPlugin.getInfo().getName()).append('\n');
                    } else if (service != null && (service.getInfo().getVersion().compareTo(version1) > 0
                            || (service.getInfo().getVersion().compareTo(version1) == 0
                                    && version1.isStable()))) {
                        alreadyInstalled.append(service.getInfo().getName()).append('\n');
                    } else {
                        RandomAccessFile write = new RandomAccessFile(tmpFile, "rw");

                        String versionString = Integer.toString(version1.getMajor()) + '.'
                                + (version1.getMinor() / 10) + (version1.getMinor() % 10) + '.'
                                + version1.getSubMinor();

                        write.seek(write.length());

                        write.writeBytes("[plugin:" + pluginName + "]\n");
                        write.writeBytes("name_en=" + pluginName + "\n");
                        write.writeBytes("filename=" + jarFile.getName() + "\n");
                        write.writeBytes("version=" + versionString + "\n");
                        write.writeBytes("stable=" + version1.isStable() + "\n");
                        write.writeBytes("download=" + jarFile.toURI().toURL() + "\n");
                        write.writeBytes("category=unknown\n");

                        write.close();

                    }
                } catch (Exception e) {
                    notCompatiblePlugins.append(jarFile.getName()).append("\n");
                }
            }
        }

        if (alreadyInstalled.length() > 0) {
            showInfoTextMessage(
                    mLocalizer.msg("update.alreadyInstalled",
                            "The following Plugin in current version are already installed:"),
                    alreadyInstalled.toString(), 400);
        }

        if (notCompatiblePlugins.length() > 0) {
            showInfoTextMessage(
                    mLocalizer.msg("update.noTVBPlugin", "This following files are not TV-Browser Plugins:"),
                    notCompatiblePlugins.toString(), 400);
        }

        if (tmpFile.length() > 0) {
            java.net.URL url = tmpFile.toURI().toURL();
            SoftwareUpdater softwareUpdater = new SoftwareUpdater(url, false, true);
            mSoftwareUpdateItems = softwareUpdater.getAvailableSoftwareUpdateItems();
            dtde.dropComplete(true);

            SoftwareUpdateDlg updateDlg = new SoftwareUpdateDlg(this, false, mSoftwareUpdateItems);
            updateDlg.setVisible(true);
        } else {
            dtde.rejectDrop();
            dtde.dropComplete(false);
        }

        if (!tmpFile.delete()) {
            tmpFile.deleteOnExit();
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:zsk.JFCMainClient.java

/**
 * processing event of dropping a HTTP URL, YT-Video Image or plain text (URL) onto the frame
 * /*  w  w  w. j  a  va2  s.com*/
 * seems not to work with M$-IE (8,9) - what a pity!
 */
public void drop(DropTargetDropEvent dtde) {
    Transferable tr = dtde.getTransferable();
    DataFlavor[] flavors = tr.getTransferDataFlavors();
    DataFlavor fl = null;
    String str = "";

    debugoutput("DataFlavors found: ".concat(Integer.toString(flavors.length)));
    for (int i = 0; i < flavors.length; i++) {
        fl = flavors[i];
        if (fl.isFlavorTextType() /* || fl.isMimeTypeEqual("text/html") || fl.isMimeTypeEqual("application/x-java-url") || fl.isMimeTypeEqual("text/uri-list")*/) {
            try {
                dtde.acceptDrop(dtde.getDropAction());
            } catch (Throwable t) {
            }
            try {
                if (tr.getTransferData(fl) instanceof InputStreamReader) {
                    debugoutput("Text-InputStream");
                    BufferedReader textreader = new BufferedReader((Reader) tr.getTransferData(fl));
                    String sline = "";
                    try {
                        while (sline != null) {
                            sline = textreader.readLine();
                            if (sline != null)
                                str += sline;
                        }
                    } catch (Exception e) {
                    } finally {
                        textreader.close();
                    }
                    str = str.replaceAll("<[^>]*>", ""); // remove HTML tags, especially a hrefs - ignore HTML characters like &szlig; (which are no tags)
                } else if (tr.getTransferData(fl) instanceof InputStream) {
                    debugoutput("Byte-InputStream");
                    InputStream input = new BufferedInputStream((InputStream) tr.getTransferData(fl));
                    int idata = input.read();
                    String sresult = "";
                    while (idata != -1) {
                        if (idata != 0)
                            sresult += new Character((char) idata).toString();
                        idata = input.read();
                    } // while
                    debugoutput("sresult: ".concat(sresult));
                } else {
                    str = tr.getTransferData(fl).toString();
                }
            } catch (IOException ioe) {
            } catch (UnsupportedFlavorException ufe) {
            }

            debugoutput("drop event text: ".concat(str).concat(" (").concat(fl.getMimeType()).concat(") "));
            // insert text into textfield - almost the same as user drops text/url into this field
            // except special characaters -> from http://de.wikipedia.org/wiki/GNU-Projekt (GNU is not Unix)(&bdquo;GNU is not Unix&ldquo;)
            // two drops from same source .. one time in textfield and elsewhere - maybe we change that later?!
            if (str.matches(szYTREGEX.concat("(.*)"))) {
                synchronized (JFCMainClient.frame.textinputfield) {
                    JFCMainClient.frame.textinputfield
                            .setText(str.concat(JFCMainClient.frame.textinputfield.getText()));
                }
                debugoutput("breaking for-loop with str: ".concat(str));
                break;
            }
        } else {
            String sv = "drop event unknown type: ".concat(fl.getHumanPresentableName());
            //output(sv);
            debugoutput(sv);
        }
    } // for

    dtde.dropComplete(true);
}