public LanguageWindow() { super(GUIMediator.getAppFrame()); this.currentLocale = GUIMediator.getLocale(); initializeWindow(); Font font = new Font("Dialog", Font.PLAIN, 11); Locale[] locales = LanguageUtils.getLocales(font); mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); getContentPane().add(mainPanel, BorderLayout.CENTER); initializeContent(locales); initializeButtons(); initializeWindow(); updateLabels(currentLocale); pack(); if (getWidth() < MIN_DIALOG_WIDTH) { setSize(350, getHeight()); } }
// inherit doc comment public void updateTheme() { setContentAreaFilled(false); setBorderPainted(ThemeSettings.isNativeOSXTheme()); setRolloverEnabled(true); setIcon(GUIMediator.getThemeImage(UP_NAME)); setHorizontalAlignment(SwingConstants.CENTER); setPressedIcon(GUIMediator.getThemeImage(DOWN_NAME)); setPreferredSize(new Dimension(getIcon().getIconWidth(), getIcon().getIconHeight())); setMargin(new Insets(0, 0, 0, 0)); setToolTipText(TIP_TEXT); }
/** 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); }
/** * The implementation that the other methods delegate to. This provides the caller with all * available options for customizing the <tt>JFileChooser</tt> instance. If a <tt>FileDialog</tt> * is displayed instead of a <tt>JFileChooser</tt> (on OS X, for example), most or all of these * options have no effect. * * @param parent the <tt>Component</tt> that should be the dialog's parent * @param titleKey the key for the locale-specific string to use for the file dialog title * @param approveKey the key for the locale-specific string to use for the approve button text * @param directory the directory to open the dialog to * @param mode the "mode" to open the <tt>JFileChooser</tt> in from the <tt>JFileChooser</tt> * class, such as <tt>JFileChooser.DIRECTORIES_ONLY</tt> * @param option the option to look for in the return code, such as * <tt>JFileChooser.APPROVE_OPTION</tt> * @param allowMultiSelect true if the chooser allows multiple files to be chosen * @param filter the <tt>FileFilter</tt> instance for customizing the files that are displayed -- * if this is null, no filter is used * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a file was not selected * correctly */ public static List<File> getInput( Component parent, String titleKey, String approveKey, File directory, int mode, int option, boolean allowMultiSelect, final FileFilter filter) { if (!OSUtils.isAnyMac()) { JFileChooser fileChooser = getDirectoryChooser(titleKey, approveKey, directory, mode, filter); fileChooser.setMultiSelectionEnabled(allowMultiSelect); try { if (fileChooser.showOpenDialog(parent) != option) return null; } catch (NullPointerException npe) { // ignore NPE. can't do anything with it ... return null; } if (allowMultiSelect) { File[] chosen = fileChooser.getSelectedFiles(); if (chosen.length > 0) setLastInputDirectory(chosen[0]); return Arrays.asList(chosen); } else { File chosen = fileChooser.getSelectedFile(); setLastInputDirectory(chosen); return Collections.singletonList(chosen); } } else { FileDialog dialog; if (mode == JFileChooser.DIRECTORIES_ONLY) dialog = MacUtils.getFolderDialog(); else dialog = new FileDialog(GUIMediator.getAppFrame(), ""); dialog.setTitle(I18n.tr(titleKey)); if (filter != null) { FilenameFilter f = new FilenameFilter() { public boolean accept(File dir, String name) { return filter.accept(new File(dir, name)); } }; dialog.setFilenameFilter(f); } dialog.setVisible(true); String dirStr = dialog.getDirectory(); String fileStr = dialog.getFile(); if ((dirStr == null) || (fileStr == null)) return null; setLastInputDirectory(new File(dirStr)); // if the filter didn't work, pretend that the person picked // nothing File f = new File(dirStr, fileStr); if (filter != null && !filter.accept(f)) return null; return Collections.singletonList(f); } }
/** * Shows the file of the specified file name, throwing a <tt>NullPointerExeption</tt> if the file * could not be found in the com/limegroup/gnutella/gui/resources directory. * * @param FILE_NAME the name of the file to load into the scrolling pane * @throws <tt>NullPointerExeption</tt> if the attempt to load the file fails */ public void showFile(String FILE_NAME) { URL url = GUIMediator.getURLResource(FILE_NAME); if (url == null) { throw new NullPointerException("FILE COULD NOT BE LOADED"); } try { EDITOR_PANE.setPage(url); } catch (IOException ioe) { throw new NullPointerException("FILE COULD NOT BE LOADED"); } }
public void actionPerformed(ActionEvent ae) { int[] sel = TABLE.getSelectedRows(); if (sel.length == 0) { return; } File selectedFile = getFile(sel[0]); if (selectedFile.isFile() && selectedFile.getParentFile() != null) { GUIMediator.launchExplorer(selectedFile); } }
/** * Opens a dialog asking the user to choose a file which is is used for saving to. * * @param parent the parent component the dialog is centered on * @param titleKey the key for the locale-specific string to use for the file dialog title * @param suggestedFile the suggested file for saving * @param the filter to use for what's shown. * @return the file or <code>null</code> when the user cancelled the dialog */ public static File getSaveAsFile( Component parent, String titleKey, File suggestedFile, final FileFilter filter) { if (OSUtils.isAnyMac()) { FileDialog dialog = new FileDialog(GUIMediator.getAppFrame(), I18n.tr(titleKey), FileDialog.SAVE); dialog.setDirectory(suggestedFile.getParent()); dialog.setFile(suggestedFile.getName()); if (filter != null) { FilenameFilter f = new FilenameFilter() { public boolean accept(File dir, String name) { return filter.accept(new File(dir, name)); } }; dialog.setFilenameFilter(f); } dialog.setVisible(true); String dir = dialog.getDirectory(); setLastInputDirectory(new File(dir)); String file = dialog.getFile(); if (dir != null && file != null) { if (suggestedFile != null) { String suggestedFileExtension = FileUtils.getFileExtension(suggestedFile); String newFileExtension = FileUtils.getFileExtension(file); if (newFileExtension == null && suggestedFileExtension != null) { file = file + "." + suggestedFileExtension; } } File f = new File(dir, file); if (filter != null && !filter.accept(f)) return null; else return f; } else { return null; } } else { JFileChooser chooser = getDirectoryChooser(titleKey, null, null, JFileChooser.FILES_ONLY, filter); chooser.setSelectedFile(suggestedFile); int ret = chooser.showSaveDialog(parent); File file = chooser.getSelectedFile(); setLastInputDirectory(file); return ret != JFileChooser.APPROVE_OPTION ? null : file; } }
private void switchLanguage(Locale locale, boolean showLanguageInStatusBar) { // if the selected locale is less specific than the default locale (e.g. // has no country or variant set), retain these properties, unless the user // specifically did not want to select the default locale if (!defaultLocaleSelectable && LanguageUtils.matchesDefaultLocale(locale)) { locale = Locale.getDefault(); } if (!locale.equals(GUIMediator.getLocale())) { LanguageUtils.setLocale(locale); GUIMediator.instance().getStatusLine().updateLanguage(); String message = I18n.trl("LimeWire must be restarted for the new language to take effect.", locale); GUIMediator.showMessage(message); } StatusBarSettings.LANGUAGE_DISPLAY_ENABLED.setValue(showLanguageInStatusBar); if (LanguageUtils.isEnglishLocale(locale)) { StatusBarSettings.LANGUAGE_DISPLAY_ENGLISH_ENABLED.setValue(showLanguageInStatusBar); } GUIMediator.instance().getStatusLine().refresh(); dispose(); }
private void updateDemuxingStatus( final File demuxed, final int totalDemuxed, final boolean demuxSuccess) { GUIMediator.safeInvokeAndWait( new Runnable() { @Override public void run() { LibraryExplorer explorer = LibraryMediator.instance().getLibraryExplorer(); explorer.enqueueRunnable( new Runnable() { @Override public void run() { if (demuxSuccess) { add(demuxed, 0); update(demuxed); LibraryMediator.instance() .getLibrarySearch() .pushStatus( I18n.tr("Finished") + " " + demuxedFiles.size() + " " + I18n.tr("out of") + " " + totalDemuxed + ". Extracting audio..."); System.out.println( "Finished" + demuxedFiles.size() + " out of " + totalDemuxed + ". Extracting audio..."); } else { LibraryMediator.instance() .getLibrarySearch() .pushStatus( I18n.tr("Could not extract audio from") + " " + demuxed.getName()); } } }); explorer.executePendingRunnables(); } }); }
public static File getSaveAsDir( Component parent, String titleKey, File suggestedFile, final FileFilter filter) { if (OSUtils.isAnyMac()) { FileDialog dialog = new FileDialog(GUIMediator.getAppFrame(), I18n.tr(titleKey), FileDialog.SAVE); dialog.setDirectory(suggestedFile.getParent()); dialog.setFile(suggestedFile.getName()); if (filter != null) { FilenameFilter f = new FilenameFilter() { public boolean accept(File dir, String name) { return filter.accept(new File(dir, name)); } }; dialog.setFilenameFilter(f); } dialog.setVisible(true); String dir = dialog.getDirectory(); setLastInputDirectory(new File(dir)); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (dir != null) { File f = new File(dir); if (filter != null && !filter.accept(f)) { return null; } else { return f; } } else { return null; } } else { JFileChooser chooser = getDirectoryChooser(titleKey, null, null, JFileChooser.DIRECTORIES_ONLY, filter); chooser.setSelectedFile(suggestedFile); int ret = chooser.showSaveDialog(parent); File file = chooser.getSelectedFile(); setLastInputDirectory(file); return ret != JFileChooser.APPROVE_OPTION ? null : file; } }
/** * Displays a directory chooser to the user and returns the selected <tt>File</tt>. This uses the * main application frame as the parent component. * * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a directory was not selected * correctly */ public static File getInputDirectory() { return getInputDirectory(GUIMediator.getAppFrame()); }
/** * Displays a file chooser to the user and returns the selected <tt>File</tt>. This uses the main * application frame as the parent component. * * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a file was not selected * correctly */ public static List<File> getMultiInputFile() { return getMultiInputFile(GUIMediator.getAppFrame()); }
/** * Displays a file chooser to the user and returns the selected <tt>File</tt>. This uses the main * application frame as the parent component. * * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a file was not selected * correctly */ public static File getInputFile() { return getInputFile(GUIMediator.getAppFrame()); }