List of usage examples for java.awt.dnd DropTarget DropTarget
public DropTarget() throws HeadlessException
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 v a 2 s . c o m*/ @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:com.qspin.qtaste.ui.TestCaseTree.java
public TestCaseTree(TestCasePane testCasePn) { super();//ww w.ja v a2 s .c o m mTestCaseTree = this; this.setCellRenderer(new TestCaseTreeCellRenderer()); testCasePane = testCasePn; testCasePane.setTestCaseTree(this); ToolTipManager.sharedInstance().registerComponent(this); FileNode rootFileNode = createRootFileNode(); TCTreeNode rootNode = new TCTreeNode(rootFileNode, true); DefaultTreeModel tm = new DefaultTreeModel(rootNode); setModel(tm); generateScriptsTree(rootFileNode); TCTreeListener listener = new TCTreeListener(); this.addMouseListener(listener); addTreeWillExpandListener(listener); addTreeSelectionListener(listener); TreeSelectionModel selModel = this.getSelectionModel(); selModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); // drag drop initialization ds = new DragSource(); dt = new DropTarget(); ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); try { dt.setComponent(this); dt.addDropTargetListener(this); } catch (java.util.TooManyListenersException e) { logger.error(e.getMessage()); } }
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 w w w . j av a2 s. 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.ftb2om2.view.MultiplePane.java
private void dragAndDrop() { audioFieldMulti.setDropTarget(new DropTarget() { @Override/* w w w. j a v a 2 s . co m*/ public synchronized void drop(DropTargetDropEvent evt) { audioFieldDragAndDrop(evt); } }); jScrollPane1.setDropTarget(new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent evt) { difficultyTableDragAndDrop(evt); } }); }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
public void tableReferesh(JTable songData_Table, String tableName, String columName) { int emptyResultSet = 0; try {/*from w w w. j ava 2s . c om*/ 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); } }
From source file:se.trixon.pacoma.ui.MainFrame.java
private void initListeners() { mActionManager.addAppListener(new ActionManager.AppListener() { @Override/*from w w w . jav a2 s .c om*/ public void onCancel(ActionEvent actionEvent) { } @Override public void onMenu(ActionEvent actionEvent) { if (actionEvent.getSource() != menuButton) { menuButtonMousePressed(null); } } @Override public void onOptions(ActionEvent actionEvent) { showOptions(); } @Override public void onQuit(ActionEvent actionEvent) { quit(); } @Override public void onRedo(ActionEvent actionEvent) { mCollage.nextHistory(); updateToolButtons(); } @Override public void onStart(ActionEvent actionEvent) { } @Override public void onUndo(ActionEvent actionEvent) { mCollage.prevHistory(); updateToolButtons(); } }); mActionManager.addProfileListener(new ActionManager.ProfileListener() { @Override public void onAdd(ActionEvent actionEvent) { addImages(); } @Override public void onClear(ActionEvent actionEvent) { mCollage.clearFiles(); } @Override public void onClose(ActionEvent actionEvent) { setTitle("pacoma"); mActionManager.setEnabledDocumentActions(false); canvasPanel.close(); } @Override public void onEdit(ActionEvent actionEvent) { editCollage(mCollage); } @Override public void onRegenerate(ActionEvent actionEvent) { //TODO } @Override public void onNew(ActionEvent actionEvent) { editCollage(null); if (mCollage != null && mCollage.getName() != null) { setTitle(mCollage); canvasPanel.open(mCollage); mActionManager.getAction(ActionManager.CLEAR).setEnabled(false); mActionManager.getAction(ActionManager.REGENERATE).setEnabled(false); } } @Override public void onOpen(ActionEvent actionEvent) { initFileDialog(mCollageFileNameExtensionFilter); if (SimpleDialog.openFile()) { try { open(SimpleDialog.getPath()); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onSave(ActionEvent actionEvent) { save(); } @Override public void onSaveAs(ActionEvent actionEvent) { saveAs(); } }); mCollagePropertyChangeListener = () -> { if (mCollage != null) { setTitle(mCollage); mActionManager.getAction(ActionManager.SAVE).setEnabled(true); mActionManager.getAction(ActionManager.CLEAR).setEnabled(mCollage.hasImages()); mActionManager.getAction(ActionManager.REGENERATE).setEnabled(mCollage.hasImages()); } }; mDropTarget = new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension( droppedFile.getName().toLowerCase(Locale.getDefault()), Collage.FILE_EXT)) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); }); switch (droppedFiles.size()) { case 0: Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(), "Not a valid collage file."); break; case 1: open(droppedFiles.getFirst()); break; default: Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(), "Too many files dropped."); break; } } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; canvasPanel.setDropTarget(mDropTarget); }
From source file:se.trixon.pacoma.ui.PagePanel.java
private void init() { mDropTarget = new DropTarget() { @Override/*from w ww .ja va 2 s .co m*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension(droppedFile.getName().toLowerCase(Locale.getDefault()), new String[] { "jpg", "jpeg", "png" })) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); System.out.println("remomve invalid file: " + invalidFile.getAbsolutePath()); }); droppedFiles.forEach((droppedFile) -> { System.out.println("accept: " + droppedFile.getAbsolutePath()); }); mCollage.addFiles(droppedFiles); } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; setDropTarget(mDropTarget); }
From source file:se.trixon.solos.core.panel.NavigatorPanel.java
private void init() { DropTarget dropTarget = new DropTarget() { @Override/* w w w . ja v a 2s. co m*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); File file = droppedFiles.get(0); if (droppedFiles.size() == 1) { if (file.isDirectory()) { setPath(file); } else if (file.isFile()) { setPath(file.getParentFile()); } } else { setPath(file.getParentFile()); } directoryChanged(); } catch (UnsupportedFlavorException | IOException ex) { } } }; textField.setDropTarget(dropTarget); }
From source file:se.trixon.toolbox.geotagger.GeotaggerTopComponent.java
private void init() { openButton.setIcon(Pict.Actions.DOCUMENT_OPEN.get(TOOLBAR_ICON_SIZE)); editToggleButton.setIcon(Pict.Actions.DOCUMENT_EDIT.get(TOOLBAR_ICON_SIZE)); closeButton.setIcon(Pict.Actions.WINDOW_CLOSE.get(TOOLBAR_ICON_SIZE)); closeButton.setEnabled(false);//from w ww . j a va2 s .co m startButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE)); startButton.setToolTipText(Dict.START.getString()); startButton.setEnabled(false); saveLogButton.setIcon(Pict.Actions.DOCUMENT_SAVE.get(ICON_SIZE)); saveLogButton.setEnabled(false); helpButton.setIcon(Pict.Actions.HELP_CONTENTS.get(ICON_SIZE)); helpButton.setToolTipText(Dict.HELP.getString()); DropTarget dropTarget = new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (droppedFiles.get(0).isFile()) { openFile(droppedFiles.get(0)); } } catch (UnsupportedFlavorException | IOException ex) { } } }; scrollPane.setDropTarget(dropTarget); mTableModel = new GeotagTableModel(); table.setModel(mTableModel); mTableRowSorter = new TableRowSorter<>(mTableModel); table.setRowSorter(mTableRowSorter); TableColumnModel columnModel = table.getColumnModel(); NumericTableCellRenderer cooNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 6); NumericTableCellRenderer altNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 4); columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setCellRenderer(cooNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setCellRenderer(cooNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setCellRenderer(altNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_NAME).setPreferredWidth(200); columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setPreferredWidth(100); columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setPreferredWidth(100); columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setPreferredWidth(50); }
From source file:tvbrowser.ui.mainframe.MainFrame.java
private MainFrame() { super(TVBrowser.MAINWINDOW_TITLE); mIsVisible = false;/*from w w w . j av a 2 s . c om*/ mSettingsWillBeOpened = false; mAutoDownloadTimer = -1; mLastTimerMinutesAfterMidnight = -1; mLastAutoUpdateRun = System.currentTimeMillis(); mChannelDateArr = null; mOnAirRowProgramsArr = null; mStatusBar = new StatusBar(); if (OperatingSystem.isMacOs()) { /* create the menu bar for MacOS X */ try { Class<?> impl = Class.forName("tvbrowser.ui.mainframe.macosx.MacOSXMenuBar"); Class<? extends MainFrame> mainFrameClass = this.getClass(); Class<?> jlabelClass = Class.forName("javax.swing.JLabel"); Constructor<?> cons = impl.getConstructor(new Class[] { mainFrameClass, jlabelClass }); mMenuBar = (MenuBar) cons.newInstance(new Object[] { this, mStatusBar.getLabel() }); } catch (Exception e) { if (TVBrowser.isTransportable()) { mLog.info("Using default menu bar (instead of MacOSXMenuBar) for transportable version."); } mLog.warning("Could not instantiate MacOSXMenuBar\n" + e.toString()); if (e.getCause() != null) { StringWriter sw = new StringWriter(); e.getCause().printStackTrace(new PrintWriter(sw)); mLog.warning(sw.toString()); } mMenuBar = new DefaultMenuBar(this, mStatusBar.getLabel()); mLog.info("Using default menu bar"); } } else { mMenuBar = new DefaultMenuBar(this, mStatusBar.getLabel()); } // create content jcontentPane = (JPanel) getContentPane(); jcontentPane.setLayout(new BorderLayout()); JPanel skinPanel = new JPanel(); skinPanel.setLayout(new BorderLayout()); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.setOpaque(false); centerPanel.setBorder(BorderFactory.createEmptyBorder()); mFilterPanel = new FilterPanel(); mFilterPanel.setVisible(false); mTimeChooserPanel = new TimeChooserPanel(this); centerPanel.add(mFilterPanel, BorderLayout.NORTH); Channel[] channelArr = ChannelList.getSubscribedChannels(); int startOfDay = Settings.propProgramTableStartOfDay.getInt(); int endOfDay = Settings.propProgramTableEndOfDay.getInt(); mProgramTableModel = new DefaultProgramTableModel(channelArr, startOfDay, endOfDay); mProgramTableScrollPane = new ProgramTableScrollPane(mProgramTableModel); centerPanel.add(mProgramTableScrollPane); createDateSelector(); skinPanel.add(centerPanel, BorderLayout.CENTER); mChannelChooser = new ChannelChooserPanel(this); /* create structure */ mRootNode = new Node(null); if (Settings.propPluginViewIsLeft.getBoolean()) { mPluginsNode = new Node(mRootNode); } else { mNavigationNode = new Node(mRootNode); } mMainframeNode = new Node(mRootNode); Node programtableNode = new Node(mMainframeNode); if (Settings.propPluginViewIsLeft.getBoolean()) { mNavigationNode = new Node(mMainframeNode); } else { mPluginsNode = new Node(mMainframeNode); } mTimebuttonsNode = new Node(mNavigationNode); mDateChannelNode = new Node(mNavigationNode); mDateNode = new Node(mDateChannelNode); mChannelNode = new Node(mDateChannelNode); mRootNode.setProperty(Settings.propViewRoot); mMainframeNode.setProperty(Settings.propViewMainframe); mNavigationNode.setProperty(Settings.propViewNavigation); mDateChannelNode.setProperty(Settings.propViewDateChannel); /* create views */ programtableNode.setLeaf(skinPanel); this.setShowPluginOverview(Settings.propShowPluginView.getBoolean()); this.setShowTimeButtons(Settings.propShowTimeButtons.getBoolean()); this.setShowDatelist(Settings.propShowDatelist.getBoolean()); this.setShowChannellist(Settings.propShowChannels.getBoolean()); updateToolbar(); dateChanged(new devplugin.Date(), null, null); mCenterComponent = mRootNode.getComponent(); if (mCenterComponent != null) { jcontentPane.add(mCenterComponent, BorderLayout.CENTER); } if (Settings.propIsStatusbarVisible.getBoolean()) { jcontentPane.add(mStatusBar, BorderLayout.SOUTH); } setJMenuBar(mMenuBar); addContextMenuMouseListener(mMenuBar); // set program filter FilterList filterList = FilterList.getInstance(); ProgramFilter filter = filterList.getFilterByName(Settings.propLastUsedFilter.getString()); if (filter == null) { filter = FilterManagerImpl.getInstance().getDefaultFilter(); } setProgramFilter(filter); // set channel group filter String channelGroupName = Settings.propLastUsedChannelGroup.getString(); if (channelGroupName != null) { FilterComponent component = FilterComponentList.getInstance() .getFilterComponentByName(channelGroupName); if (component != null && component instanceof ChannelFilterComponent) { setChannelGroup((ChannelFilterComponent) component); } } addKeyboardAction(); mTimer = new Timer(10000, new ActionListener() { public void actionPerformed(ActionEvent evt) { handleTimerEvent(); } }); mTimer.start(); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); //create the drop target for installation of Plugins with Drag'N'Drop on MainFrame DropTarget target = new DropTarget(); try { target.addDropTargetListener(this); } catch (TooManyListenersException e1) { //ignore } this.setDropTarget(target); }