@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); dlg.setVisible(true); }
/** Loads a playlist. */ public void importM3U(Playlist playlist) { File parentFile = FileChooserHandler.getLastInputDirectory(); if (parentFile == null) parentFile = CommonUtils.getCurrentDirectory(); final File selFile = FileChooserHandler.getInputFile( GUIMediator.getAppFrame(), I18nMarker.marktr("Open Playlist (.m3u)"), parentFile, new PlaylistListFileFilter()); // nothing selected? exit. if (selFile == null || !selFile.isFile()) return; String path = selFile.getPath(); try { path = FileUtils.getCanonicalPath(selFile); } catch (IOException ignored) { // LOG.warn("unable to get canonical path for file: " + selFile, ignored); } // create a new thread off of the event queue to process reading the files from // disk loadM3U(playlist, selFile, path); }
/** Saves a playlist. */ public void exportM3U(Playlist playlist) { if (playlist == null) { return; } String suggestedName = CommonUtils.convertFileName(playlist.getName()); // get the user to select a new one.... avoid FrostWire installation folder. File suggested; File suggestedDirectory = FileChooserHandler.getLastInputDirectory(); if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) { suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop"); } suggested = new File(suggestedDirectory, suggestedName + ".m3u"); File selFile = FileChooserHandler.getSaveAsFile( GUIMediator.getAppFrame(), I18nMarker.marktr("Save Playlist As"), suggested, new PlaylistListFileFilter()); // didn't select a file? nothing we can do. if (selFile == null) { return; } // if the file already exists and not the one just opened, ask if it should be // overwritten. // TODO: this should be handled in the jfilechooser if (selFile.exists()) { DialogOption choice = GUIMediator.showYesNoMessage( I18n.tr( "Warning: a file with the name {0} already exists in the folder. Overwrite this file?", selFile.getName()), QuestionsHandler.PLAYLIST_OVERWRITE_OK, DialogOption.NO); if (choice != DialogOption.YES) return; } String path = selFile.getPath(); try { path = FileUtils.getCanonicalPath(selFile); } catch (IOException ignored) { // LOG.warn("unable to get canonical path for file: " + selFile, ignored); } // force m3u on the end. if (!path.toLowerCase().endsWith(".m3u")) path += ".m3u"; // create a new thread to handle saving the playlist to disk saveM3U(playlist, path); }
private static void closeCurrentSearchTab(KeyEvent e) { if (e.getSource() instanceof Component) { Window eventParentWindow = SwingUtilities.getWindowAncestor((Component) e.getSource()); if (GUIMediator.getAppFrame().equals(eventParentWindow)) { SearchDownloadTab searchTab = (SearchDownloadTab) GUIMediator.instance().getTab(Tabs.SEARCH); if (searchTab.getComponent().isVisible()) { SearchMediator.getSearchResultDisplayer().closeCurrentTab(); } } } }
public void actionPerformed(ActionEvent e) { Playlist selectedPlaylist = getSelectedPlaylist(); if (selectedPlaylist != null) { int showConfirmDialog = JOptionPane.showConfirmDialog( GUIMediator.getAppFrame(), I18n.tr( "Are you sure you want to delete the playlist?\n(No files will be deleted)"), I18n.tr("Are you sure?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (showConfirmDialog != JOptionPane.YES_OPTION) { return; } selectedPlaylist.delete(); _model.removeElement(_list.getSelectedValue()); LibraryMediator.instance().clearLibraryTable(); } }
/** * The constructor create all of the options windows and their components. * * @param treeManager the <tt>OptionsTreeManager</tt> instance to use for constructing the main * panels and adding elements * @param paneManager the <tt>OptionsPaneManager</tt> instance to use for constructing the main * panels and adding elements */ public OptionsConstructor( final OptionsTreeManager treeManager, final OptionsPaneManager paneManager) { TREE_MANAGER = treeManager; PANE_MANAGER = paneManager; final String title = I18n.tr("Options"); final boolean shouldBeModal = !OSUtils.isMacOSX(); DIALOG = new JDialog(GUIMediator.getAppFrame(), title, shouldBeModal); DIALOG.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); GUIUtils.addHideAction((JComponent) DIALOG.getContentPane()); if (UISettings.UI_OPTIONS_DIALOG_HEIGHT.getValue() < UISettings.UI_OPTIONS_DIALOG_HEIGHT.getDefaultValue()) { UISettings.UI_OPTIONS_DIALOG_HEIGHT.revertToDefault(); } if (UISettings.UI_OPTIONS_DIALOG_WIDTH.getValue() < UISettings.UI_OPTIONS_DIALOG_WIDTH.getDefaultValue()) { UISettings.UI_OPTIONS_DIALOG_WIDTH.revertToDefault(); } DialogSizeSettingUpdater.install( DIALOG, UISettings.UI_OPTIONS_DIALOG_WIDTH, UISettings.UI_OPTIONS_DIALOG_HEIGHT); // most Mac users expect changes to be saved when the window // is closed, so save them DIALOG.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { DialogOption answer = null; if (OptionsMediator.instance().isDirty()) { answer = GUIMediator.showYesNoCancelMessage( I18n.tr( "You have made changes to some of FrostWire's settings. Would you like to save these changes?")); if (answer == DialogOption.YES) { OptionsMediator.instance().applyOptions(); SettingsGroupManager.instance().save(); } } if (answer != DialogOption.CANCEL) { DIALOG.dispose(); OptionsMediator.instance().disposeOptions(); } } catch (IOException ioe) { // nothing we should do here. a message should // have been displayed to the user with more // information } } }); PaddedPanel mainPanel = new PaddedPanel(); Box splitBox = new Box(BoxLayout.X_AXIS); BoxPanel treePanel = new BoxPanel(BoxLayout.Y_AXIS); BoxPanel filterPanel = new BoxPanel(BoxLayout.X_AXIS); treePanel.add(filterPanel); filterTextField = new SearchField(); filterTextField.setPrompt(I18n.tr("Search here")); filterTextField.setMinimumSize(new Dimension(100, 27)); filterTextField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filter(); } }); filterPanel.add(filterTextField); filterPanel.add(Box.createHorizontalStrut(2)); treePanel.add(Box.createVerticalStrut(3)); Component treeComponent = TREE_MANAGER.getComponent(); treePanel.add(treeComponent); Component paneComponent = PANE_MANAGER.getComponent(); splitBox.add(treePanel); splitBox.add(paneComponent); mainPanel.add(splitBox); mainPanel.add(Box.createVerticalStrut(17)); mainPanel.add(new OptionsButtonPanel().getComponent()); DIALOG.getContentPane().add(mainPanel); OptionsTreeNode node = initializePanels(); PANE_MANAGER.show(node); }
private void copyPlaylistFilesToFolder(Playlist playlist) { if (playlist == null || playlist.getItems().isEmpty()) { return; } File suggestedDirectory = FileChooserHandler.getLastInputDirectory(); if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) { suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop"); } final File selFolder = FileChooserHandler.getSaveAsDir( GUIMediator.getAppFrame(), I18nMarker.marktr("Where do you want the playlist files copied to?"), suggestedDirectory); if (selFolder == null) { return; } // let's make a copy of the list in case the playlist will be modified during the copying. final List<PlaylistItem> playlistItems = new ArrayList<>(playlist.getItems()); BackgroundExecutorService.schedule( new Thread("Library-copy-playlist-files") { @Override public void run() { int n = 0; int total = playlistItems.size(); String targetName = selFolder.getName(); for (PlaylistItem item : playlistItems) { File f = new File(item.getFilePath()); if (f.isFile() && f.exists() && f.canRead()) { try { Path source = f.toPath(); Path target = FileSystems.getDefault().getPath(selFolder.getAbsolutePath(), f.getName()); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); n++; // invoked on UI thread later String status = String.format("Copied %d of %d to %s", n, total, targetName); LibraryMediator.instance().getLibrarySearch().pushStatus(status); } catch (IOException e) { e.printStackTrace(); } } } GUIMediator.launchExplorer(selFolder); // and clear the output try { Thread.sleep(2000); LibraryMediator.instance().getLibrarySearch().pushStatus(""); } catch (InterruptedException e) { } } }); }
public BasicNotifier() { notificationWindow = new NotificationWindow(GUIMediator.getAppFrame()); notificationWindow.setLocationOffset(new Dimension(1, 1)); notificationWindow.setTitle("LimeWire"); notificationWindow.setIcon(GUIMediator.getThemeImage("limeicon.gif")); }