/** Launches the associated applications for each selected file in the library if it can. */ void launch(boolean playAudio) { int[] rows = TABLE.getSelectedRows(); if (rows.length == 0) { return; } File selectedFile = DATA_MODEL.getFile(rows[0]); if (OSUtils.isWindows()) { if (selectedFile.isDirectory()) { GUIMediator.launchExplorer(selectedFile); return; } else if (!MediaPlayer.isPlayableFile(selectedFile)) { String extension = FilenameUtils.getExtension(selectedFile.getName()); if (extension != null && extension.equals("torrent")) { GUIMediator.instance().openTorrentFile(selectedFile, true); } else { GUIMediator.launchFile(selectedFile); } return; } } LaunchableProvider[] providers = new LaunchableProvider[rows.length]; boolean stopAudio = false; for (int i = 0; i < rows.length; i++) { try { MediaType mt = MediaType.getMediaTypeForExtension( FilenameUtils.getExtension(DATA_MODEL.getFile(rows[i]).getName())); if (mt.equals(MediaType.getVideoMediaType())) { stopAudio = true; } } catch (Throwable e) { // ignore } providers[i] = new FileProvider(DATA_MODEL.getFile(rows[i])); } if (stopAudio || !playAudio) { MediaPlayer.instance().stop(); } if (playAudio) { GUILauncher.launch(providers); UXStats.instance() .log(stopAudio ? UXAction.LIBRARY_VIDEO_PLAY : UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE); } else { GUIMediator.launchFile(selectedFile); } }
@Override public void actionPerformed(ActionEvent arg0) { File selectedFile = DATA_MODEL.getFile(TABLE.getSelectedRow()); // can't create torrents out of empty folders. if (selectedFile.isDirectory() && selectedFile.listFiles().length == 0) { JOptionPane.showMessageDialog( null, I18n.tr("The folder you selected is empty."), I18n.tr("Invalid Folder"), JOptionPane.ERROR_MESSAGE); return; } // can't create torrents if the folder/file can't be read if (!selectedFile.canRead()) { JOptionPane.showMessageDialog( null, I18n.tr("Error: You can't read on that file/folder."), I18n.tr("Error"), JOptionPane.ERROR_MESSAGE); return; } CreateTorrentDialog dlg = new CreateTorrentDialog(GUIMediator.getAppFrame()); dlg.setChosenContent( selectedFile, selectedFile.isFile() ? JFileChooser.FILES_ONLY : JFileChooser.DIRECTORIES_ONLY); dlg.setVisible(true); }
private List<File> getSelectedFiles() { int[] rows = TABLE.getSelectedRows(); List<File> files = new ArrayList<File>(rows.length); for (int i = 0; i < rows.length; i++) { int index = rows[i]; // current index to add File file = DATA_MODEL.getFile(index); files.add(file); } return files; }
@Override public void actionPerformed(ActionEvent e) { int[] rows = TABLE.getSelectedRows(); List<File> files = new ArrayList<File>(); for (int i = 0; i < rows.length; i++) { int index = rows[i]; // current index to add File file = DATA_MODEL.getFile(index); files.add(file); } iTunesMediator.instance().scanForSongs(files.toArray(new File[0])); }
private boolean areAllSelectedFilesMP4s() { boolean selectionIsAllMP4 = true; int[] selectedRows = TABLE.getSelectedRows(); for (int i : selectedRows) { if (!DATA_MODEL.getFile(i).getAbsolutePath().toLowerCase().endsWith("mp4")) { selectionIsAllMP4 = false; break; } } return selectionIsAllMP4; }
/** * Override the default removal so we can actually stop sharing and delete the file. Deletes the * selected rows in the table. CAUTION: THIS WILL DELETE THE FILE FROM THE DISK. */ public void removeSelection() { int[] rows = TABLE.getSelectedRows(); if (rows.length == 0) return; if (TABLE.isEditing()) { TableCellEditor editor = TABLE.getCellEditor(); editor.cancelCellEditing(); } List<File> files = new ArrayList<File>(rows.length); // sort row indices and go backwards so list indices don't change when // removing the files from the model list Arrays.sort(rows); for (int i = rows.length - 1; i >= 0; i--) { File file = DATA_MODEL.getFile(rows[i]); files.add(file); } CheckBoxListPanel<File> listPanel = new CheckBoxListPanel<File>(files, new FileTextProvider(), true); listPanel.getList().setVisibleRowCount(4); // display list of files that should be deleted Object[] message = new Object[] { new MultiLineLabel( I18n.tr( "Are you sure you want to delete the selected file(s), thus removing it from your computer?"), 400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP), listPanel, Box.createVerticalStrut(ButtonRow.BUTTON_SEP) }; // get platform dependent options which are displayed as buttons in the dialog Object[] removeOptions = createRemoveOptions(); int option = JOptionPane.showOptionDialog( MessageService.getParentComponent(), message, I18n.tr("Message"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, removeOptions, removeOptions[0] /* default option */); if (option == removeOptions.length - 1 /* "cancel" option index */ || option == JOptionPane.CLOSED_OPTION) { return; } // remove still selected files List<File> selected = listPanel.getSelectedElements(); List<String> undeletedFileNames = new ArrayList<String>(); boolean somethingWasRemoved = false; for (File file : selected) { // stop seeding if seeding BittorrentDownload dm = null; if ((dm = TorrentUtil.getDownloadManager(file)) != null) { dm.setDeleteDataWhenRemove(false); dm.setDeleteTorrentWhenRemove(false); BTDownloadMediator.instance().remove(dm); } // close media player if still playing if (MediaPlayer.instance().isThisBeingPlayed(file)) { MediaPlayer.instance().stop(); MPlayerMediator.instance().showPlayerWindow(false); } // removeOptions > 2 => OS offers trash options boolean removed = FileUtils.delete( file, removeOptions.length > 2 && option == 0 /* "move to trash" option index */); if (removed) { somethingWasRemoved = true; DATA_MODEL.remove(DATA_MODEL.getRow(file)); } else { undeletedFileNames.add(getCompleteFileName(file)); } } clearSelection(); if (somethingWasRemoved) { LibraryMediator.instance().getLibraryExplorer().refreshSelection(true); } if (undeletedFileNames.isEmpty()) { return; } // display list of files that could not be deleted message = new Object[] { new MultiLineLabel( I18n.tr( "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."), 400), Box.createVerticalStrut(ButtonRow.BUTTON_SEP), new JScrollPane(createFileList(undeletedFileNames)) }; JOptionPane.showMessageDialog( MessageService.getParentComponent(), message, I18n.tr("Error"), JOptionPane.ERROR_MESSAGE); super.removeSelection(); }
/** * Returns the <tt>File</tt> stored at the specified row in the list. * * @param row the row of the desired <tt>File</tt> instance in the list * @return a <tt>File</tt> instance associated with the specified row in the table */ File getFile(int row) { return DATA_MODEL.getFile(row); }