Example usage for java.awt.dnd DropTargetDropEvent getTransferable

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

Introduction

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

Prototype


public Transferable getTransferable() 

Source Link

Document

This method returns the Transferable object associated with the drop.

Usage

From source file:com.mirth.connect.client.ui.components.MirthTree.java

public void drop(DropTargetDropEvent dtde) {
    if (parent.currentContentPage != parent.channelEditPanel.transformerPane) {
        return;//from  w  w w . j  ava2  s  . c  om
    }

    try {
        TreeNode selectedNode = (TreeNode) this.getLastSelectedPathComponent();

        if (selectedNode == null) {
            return;
        }

        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        Transferable tr = dtde.getTransferable();

        if (supportedDropFlavor == TreeTransferable.MAPPER_DATA_FLAVOR) {
            Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
            MapperDropData data = (MapperDropData) transferData;

            parent.channelEditPanel.transformerPane.addNewStep(
                    constructMessageBuilderStepName(data.getNode(), selectedNode),
                    constructPath(selectedNode, prefix, suffix).toString(), data.getMapping(),
                    TransformerPane.MESSAGE_BUILDER);
        } else if (supportedDropFlavor == TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR) {
            Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR);
            MessageBuilderDropData data = (MessageBuilderDropData) transferData;
            parent.channelEditPanel.transformerPane.addNewStep(
                    constructMessageBuilderStepName(selectedNode, data.getNode()), data.getMessageSegment(),
                    constructPath(selectedNode, prefix, suffix).toString(), TransformerPane.MESSAGE_BUILDER);
        } else {
            dtde.rejectDrop();
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }

}

From source file:com.qspin.qtaste.ui.TestCaseTree.java

public void drop(DropTargetDropEvent dtde) {
    //try/*from   w ww.j a  v a  2  s.c om*/
    {
        try {
            TCTreeNode tcTreeNode = (TCTreeNode) dtde.getTransferable().getTransferData(localObjectFlavor);
            Point dropPoint = dtde.getLocation();
            // int index = locationToIndex (dropPoint);
            TreePath path = getPathForLocation(dropPoint.x, dropPoint.y);
            Object targetNode = path.getLastPathComponent();
            if (targetNode instanceof TCTreeNode) {
                // rename the dragged dir into the new target one
                TCTreeNode tcTargetNode = (TCTreeNode) targetNode;
                FileNode fn = (FileNode) tcTargetNode.getUserObject();
                if (fn.isTestcaseDir()) {
                    dtde.rejectDrop();
                    return;
                }

                FileNode draggedFileNode = (FileNode) tcTreeNode.getUserObject();
                draggedFileNode.getFile()
                        .renameTo(new File(fn.getFile() + "/" + draggedFileNode.getFile().getName()));
                // update target tree

                testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                TCTreeNode parentTreeNode = (TCTreeNode) tcTargetNode.getParent();
                if (parentTreeNode != null) {
                    parentTreeNode.removeAllChildren();
                    FileNode parentFileNode = (FileNode) parentTreeNode.getUserObject();
                    addTreeToDir(parentFileNode.getFile(), parentTreeNode);
                    ((DefaultTreeModel) getModel()).reload(parentTreeNode);
                } else {
                    tcTargetNode.removeAllChildren();
                    FileNode targetFileNode = (FileNode) tcTargetNode.getUserObject();
                    addTreeToDir(targetFileNode.getFile(), tcTargetNode);
                    ((DefaultTreeModel) getModel()).reload(tcTargetNode);
                }
                // update source tree
                parentTreeNode = (TCTreeNode) tcTreeNode.getParent();
                if (parentTreeNode != null) {
                    parentTreeNode.removeAllChildren();
                    FileNode parentFileNode = (FileNode) parentTreeNode.getUserObject();
                    addTreeToDir(parentFileNode.getFile(), parentTreeNode);
                    ((DefaultTreeModel) getModel()).reload(parentTreeNode);
                } else {
                    tcTreeNode.removeAllChildren();
                    FileNode targetFileNode = (FileNode) tcTreeNode.getUserObject();
                    addTreeToDir(targetFileNode.getFile(), tcTreeNode);
                    ((DefaultTreeModel) getModel()).reload(tcTreeNode);
                }
                testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                dtde.getDropTargetContext().dropComplete(true);
            } else {
                dtde.rejectDrop();
            }
        } catch (UnsupportedFlavorException ex) {
            logger.error(ex.getMessage());
        } catch (IOException ex) {
            logger.error(ex.getMessage());
        }

    }
}

From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java

@Override
public void drop(@Nonnull final DropTargetDropEvent dtde) {

    dtde.acceptDrop(DnDConstants.ACTION_MOVE);
    File detectedFileObject = null;

    for (final DataFlavor df : dtde.getCurrentDataFlavors()) {
        final Class<?> representation = df.getRepresentationClass();
        if (FileTransferable.class.isAssignableFrom(representation)) {
            final FileTransferable t = (FileTransferable) dtde.getTransferable();
            final List<File> listOfFiles = t.getFiles();
            detectedFileObject = listOfFiles.isEmpty() ? null : listOfFiles.get(0);
            break;
        } else if (df.isFlavorJavaFileListType()) {
            try {
                final List list = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                if (list != null && !list.isEmpty()) {
                    detectedFileObject = (File) list.get(0);
                }//  w  ww  . j  a  v  a2 s. c  o m
                break;
            } catch (Exception ex) {
                LOGGER.error("Can't extract file from DnD", ex);
            }
        }
    }

    if (detectedFileObject != null) {
        addFileToElement(detectedFileObject, this.mindMapPanel.findTopicUnderPoint(dtde.getLocation()));
    }
}

From source file:ScribbleDragAndDrop.java

/**
 * This is the key method of DropTargetListener. It is invoked when the user
 * drops something on us.//from   w w w .j av  a  2  s  .  c  o  m
 */
public void drop(DropTargetDropEvent e) {
    this.setBorder(normalBorder); // Restore the default border

    // First, check whether we understand the data that was dropped.
    // If we supports our data flavors, accept the drop, otherwise reject.
    if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor)
            || e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        e.rejectDrop();
        return;
    }

    // We've accepted the drop, so now we attempt to get the dropped data
    // from the Transferable object.
    Transferable t = e.getTransferable(); // Holds the dropped data
    Scribble droppedScribble; // This will hold the Scribble object

    // First, try to get the data directly as a scribble object
    try {
        droppedScribble = (Scribble) t.getTransferData(Scribble.scribbleDataFlavor);
    } catch (Exception ex) { // unsupported flavor, IO exception, etc.
        // If that doesn't work, try to get it as a String and parse it
        try {
            String s = (String) t.getTransferData(DataFlavor.stringFlavor);
            droppedScribble = Scribble.parse(s);
        } catch (Exception ex2) {
            // If we still couldn't get the data, tell the system we failed
            e.dropComplete(false);
            return;
        }
    }

    // If we get here, we've got the Scribble object
    Point p = e.getLocation(); // Where did the drop happen?
    droppedScribble.translate(p.getX(), p.getY()); // Move it there
    scribbles.add(droppedScribble); // add to display list
    repaint(); // ask for redraw
    e.dropComplete(true); // signal success!
}

From source file:DragDropTreeExample.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();
        boolean dropSucceeded = false;

        try {//from   w  ww.ja v  a  2 s.c  o m
            tree.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            // Save the user's selections
            saveTreeSelection();

            dropSucceeded = dropFile(dtde.getDropAction(), transferable, dtde.getLocation());

            DnDUtils.debugPrintln("Drop completed, success: " + dropSucceeded);
        } catch (Exception e) {
            DnDUtils.debugPrintln("Exception while handling drop " + e);
        } finally {
            tree.setCursor(Cursor.getDefaultCursor());

            // Restore the user's selections
            restoreTreeSelection();
            dtde.dropComplete(dropSucceeded);
        }
    } else {
        DnDUtils.debugPrintln("Drop target rejected drop");
        dtde.dropComplete(false);
    }
}

From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java

public void drop(DropTargetDropEvent dtde) {
    try {//from  w ww .  j a va  2 s. c  om
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        Transferable tr = dtde.getTransferable();

        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();

            if (fileList.size() == 1) {
                File file = (File) iterator.next();
                importFilter(parent.readFileToString(file));
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) {
            Object transferData = tr.getTransferData(TreeTransferable.RULE_DATA_FLAVOR);

            if (transferData instanceof RuleDropData) {
                RuleDropData data = (RuleDropData) transferData;
                addNewRule(MirthTree.constructNodeDescription(data.getNode()), data.getMapping());
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java

public void drop(DropTargetDropEvent dtde) {
    try {// w  w w.java2s .c  om
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<File> iterator = fileList.iterator();

            if (fileList.size() == 1) {
                File file = (File) iterator.next();
                importTransformer(parent.readFileToString(file));
            }
        } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR)
                || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            Object mapperTransferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
            Object messageBuilderTransferData = tr
                    .getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR);

            if (mapperTransferData != null && !parent.isAcceleratorKeyPressed()) {
                Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
                MapperDropData data = (MapperDropData) transferData;
                addNewStep(data.getVariable(), data.getVariable(), data.getMapping(), MAPPER);
            } else if (mapperTransferData != null && parent.isAcceleratorKeyPressed()) {
                Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR);
                MapperDropData data2 = (MapperDropData) transferData;
                MessageBuilderDropData data = new MessageBuilderDropData(data2.getNode(),
                        MirthTree.constructPath(data2.getNode().getParent(), "msg", "").toString(), "");
                addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()),
                        data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER);
            } else if (messageBuilderTransferData != null) {
                Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR);
                MessageBuilderDropData data = (MessageBuilderDropData) transferData;
                addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()),
                        data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER);
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java

public void drop(DropTargetDropEvent evt) {
    logger.debug("=-> drop");

    try {/*from  w  ww.  jav  a2 s . c  om*/
        Transferable t = evt.getTransferable();

        if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            logger.debug(" Accepting 'string' data flavor...");
            evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
            String s = (String) t.getTransferData(DataFlavor.stringFlavor);
            evt.getDropTargetContext().dropComplete(true);

            logger.debug("DnD: '" + s + "'");
            if (s != null) {
                int indexOf = s.indexOf("\n");
                if (indexOf != -1) {
                    dragAndDropReference = new DragAndDropReference(s.substring(indexOf + 1),
                            s.substring(0, indexOf), DragAndDropReference.BROWSER_LINK);
                } else {
                    dragAndDropReference = new DragAndDropReference(s, DragAndDropReference.BROWSER_LINK);
                }
            }
        } else {
            if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                logger.debug(" Accepting 'file list' data flavor...");
                evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                List<Object> list = (List<Object>) t.getTransferData(DataFlavor.javaFileListFlavor);
                if (list != null) {
                    Iterator<Object> iterator = list.iterator();
                    while (iterator.hasNext()) {
                        Object next = iterator.next();
                        if (next instanceof File) {
                            logger.debug(" DnD file: " + next);
                            dragAndDropReference = new DragAndDropReference(((File) next).getAbsolutePath(),
                                    DragAndDropReference.EXPLORER_LINK);
                        }
                    }
                }
            } else {
                logger.debug("DnD rejected! ");
                dragAndDropReference = null;

                // DataFlavor[] dfs=t.getTransferDataFlavors();
                // for (int i = 0; i < dfs.length; i++) {
                // logger.debug(" "+i+" ... "+dfs[i].getMimeType());
                // logger.debug(" "+i+" ...
                // "+dfs[i].getDefaultRepresentationClassAsString());
                // logger.debug(" "+i+" ...
                // "+dfs[i].getHumanPresentableName());
                // }
            }
        }
    } catch (Exception e) {
        logger.debug("Drag&Drop error:", e);
        dragAndDropReference = null;
    }

    OutlineJPanel.getInstance().enableDisableAttachToolbarButton();

    if (dragAndDropReference != null) {
        JOptionPane.showMessageDialog(this,
                "Dropped local/web resource reference stored! Use \n'clip' icon from Notebook outline toolbar to attach it.",
                "Drag&Drop Info", JOptionPane.INFORMATION_MESSAGE);

        dragAndDropReference.debug();
    }
    logger.debug("<-= drop");
}

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);//from www .j a  v  a 2s  .  c  o  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:com.SE.myPlayer.MusicPlayerGUI.java

public void tableReferesh(JTable songData_Table, String tableName, String columName) {
        int emptyResultSet = 0;

        try {/*  w ww.j a v a2s .  c o  m*/
            con = db.getCon();
            stmt = con.createStatement();
            ResultSet rs;

            switch (tableName) {
            case "library":
                rs = stmt.executeQuery("select * from library order by " + columName + "");
                break;
            case "playlist":
                rs = stmt.executeQuery("select * from library order by " + columName + "");
                break;
            default:
                rs = stmt.executeQuery(
                        "Select library.id_songs, library.song_location, library.song_name, library.song_album, library.song_artist, library.genre, library.year, library.time, library.comment from playlist INNER JOIN library ON library.id_songs = playlist.id_songs AND playlist.playlist_name = '"
                                + tableName + "' order by " + columName + "");
                break;
            }

            DefaultTableModel myModel = new DefaultTableModel() {

                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };

            String[] songsColumnsName = { "Location", "Name", "Album", "Artist", "Genre", "Year", "Time",
                    "Comment" };
            myModel.setColumnIdentifiers(songsColumnsName);

            ResultSetMetaData rsmd = rs.getMetaData();
            int colNumbers = rsmd.getColumnCount();

            Object[] objects = new Object[colNumbers];

            while (rs.next()) {
                emptyResultSet = 1;
                for (int i = 0; i < colNumbers - 1; i++) {
                    objects[i] = rs.getObject(i + 2);
                }
                myModel.addRow(objects);
            }

            if (emptyResultSet == 0) {
                myModel.addRow(objects);
            }

            songData_Table.setModel(myModel);

            rs = stmt.executeQuery("select col_name from col_name where col_status = 0");

            while (rs.next()) {
                songData_Table.removeColumn(songData_Table.getColumn(rs.getString(1)));
            }

            songData_Table.getTableHeader().removeMouseListener(ma);
            songData_Table.getTableHeader().addMouseListener(ma);
            songData_Table.setDragEnabled(true);
            songData_Table.setDropTarget(new DropTarget() {
                @Override
                public synchronized void drop(DropTargetDropEvent dtde) {

                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                    Transferable t = dtde.getTransferable();

                    try {
                        if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                            Object fileList = t.getTransferData(DataFlavor.javaFileListFlavor);
                            String files = fileList.toString();
                            finalString = convertFileString(files);
                            if (dropControl == 0 && lastOpen.equals("library")) {
                                songAddDB(finalString);
                            } else if (dropControl == 0 && !lastOpen.equals("library")) {
                                songAddPlaylistFromLibrary(lastOpen, finalString);
                                getSongTable(lastOpen);
                            } else {
                                songAddPlaylistFromLibrary(tableName, finalString);
                            }
                        } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                            Object fileList = t.getTransferData(DataFlavor.stringFlavor);
                            String fileListString = fileList.toString();

                            fileListString = Arrays.toString(fileListString.split("\\n"));

                            String[] splitLocations = fileListString.split(",\\s");

                            for (int i = 0; i < splitLocations.length; i++) {
                                if (i == 0) {
                                    splitLocations[i] = splitLocations[i].substring(1,
                                            splitLocations[i].indexOf(".mp3") + 4);
                                } else {
                                    splitLocations[i] = splitLocations[i].substring(0,
                                            splitLocations[i].indexOf(".mp3") + 4);
                                }
                            }

                            for (int i = 0; i < splitLocations.length; i++) {
                                splitLocations[i] = sd.getLocations(splitLocations[i]);
                            }
                            finalString = Arrays.asList(splitLocations);
                            if (dropControl == 0 && lastOpen.equals("library")) {
                                songAddDB(finalString);
                            } else if (dropControl == 0 && !lastOpen.equals("library")) {
                                songAddPlaylistFromLibrary(lastOpen, finalString);
                                getSongTable(lastOpen);
                            } else {
                                songAddPlaylistFromLibrary(tableName, finalString);
                            }
                        }
                    } catch (UnsupportedFlavorException | IOException | InvalidDataException
                            | UnsupportedTagException ex) {
                        System.out.println("Error in second drop flavour............" + ex);
                    }
                }
            });

            if (con != null) {
                stmt.close();
                con.close();
            }
        } catch (SQLException e) {
            System.out.println("Error in Stmt " + e);
        }
    }