List of usage examples for javax.swing JFileChooser APPROVE_OPTION
int APPROVE_OPTION
To view the source code for javax.swing JFileChooser APPROVE_OPTION.
Click Source Link
From source file:de.peterspan.csv2db.ui.FileSelectionPanel.java
private JButton getSelectCsvSelectButton() { if (selectCsvFileButton == null) { selectCsvFileButton = new JButton(); selectCsvFileButton.setText("Select CSV"); selectCsvFileButton.setIcon(Icons.IC_MIME_CSV_SMALL); selectCsvFileButton.addActionListener(new ActionListener() { @Override//from w ww.j a v a 2s . co m public void actionPerformed(ActionEvent arg0) { JFileChooser fc = getFileChooser(); int returnValue = fc.showDialog(parent, "Select CSV"); if (returnValue == JFileChooser.APPROVE_OPTION) { inputCsvFile = fc.getSelectedFile(); getCsvFilenameTextField().setText(inputCsvFile.getAbsolutePath()); firePropertyChange("csvFileSelected", false, true); } } }); } return selectCsvFileButton; }
From source file:com.stefanbrenner.droplet.ui.actions.SaveFileAction.java
protected void showFileChooser() { int returnVal = fileChooser.showSaveDialog(getFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { // Get the selected file File file = fileChooser.getSelectedFile(); // check if file extension fits if (StringUtils.containsIgnoreCase(file.getName(), ".") //$NON-NLS-1$ && !(StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION))) { JOptionPane.showMessageDialog(getFrame(), Messages.getString("SaveFileAction.extensionNotAllowed"), //$NON-NLS-1$ Messages.getString("SaveFileAction.wrongExtension"), //$NON-NLS-1$ JOptionPane.ERROR_MESSAGE); showFileChooser();/*from w w w .ja va 2s .co m*/ return; } else { // automatically add droplet file extension if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + IDropletContext.DROPLET_FILE_EXTENSION)) { String newPath = StringUtils.join(file.getPath(), "." + IDropletContext.DROPLET_FILE_EXTENSION); file = new File(newPath); } } // check if file already exists if (file.exists()) { int retVal = JOptionPane.showConfirmDialog(getFrame(), Messages.getString("SaveFileAction.overwriteFile"), Messages.getString("SaveFileAction.1"), //$NON-NLS-1$ //$NON-NLS-2$ JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (retVal == JOptionPane.NO_OPTION) { showFileChooser(); return; } } saveFile(file); // set file to context getDropletContext().setFile(file); } }
From source file:SwingWorkerTest.java
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(); add(new JScrollPane(textArea)); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);// ww w . j a v a 2 s. co m JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); }
From source file:net.sf.housekeeper.swing.ExportShoppingListCommand.java
protected void doExecuteCommand() { final int returnVal = chooser.showSaveDialog(getApplicationWindow().getControl()); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = chooser.getSelectedFile(); try {/* w ww . ja v a 2 s . c om*/ importExportController.exportShoppingListAsText(file); final String message = getMessage("exportSuccessful"); getApplicationWindow().getStatusBar().setMessage(message + file); } catch (IOException e) { exception = e; } } }
From source file:de.hstsoft.sdeep.view.MainWindow.java
private void openFileChooser() { final JFileChooser fileChooser = new JFileChooser(new File(".")); int retVal = fileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); openFile(selectedFile);/*from w ww . j a v a 2s . c o m*/ } }
From source file:it.unibas.spicygui.controllo.mapping.ActionExportTgds.java
@Override public void performAction() { Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); JFileChooser chooser = vista.getFileChooserApriTXT(); File file;/*from w ww .java 2 s . c o m*/ continua = true; while (continua) { int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT_TGDS)); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (!file.exists()) { saveTGDs(mappingTask, file); } else { confirmSave(mappingTask, file); } } else { continua = false; } } /* List<FORule> foRules = mappingTask.getMappingData().getSTTgds(); for (FORule foRule : foRules) { System.out.println(foRule.toLogicalString(mappingTask)); }*/ }
From source file:edu.umich.robot.ViewerApplication.java
private Config promptForConfig() { JFileChooser fc = new JFileChooser("config"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt"); fc.setFileFilter(filter);//from w ww .j av a 2s . co m fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { return new ConfigFile(fc.getSelectedFile().getAbsolutePath()); } catch (IOException e) { logger.error(e.getMessage()); } } return null; }
From source file:TextFileHandler.java
public File openFile(String title) { File result = null;/*from www. j a v a 2 s . c om*/ JFileChooser chooser = new JFileChooser(new File(".")); if (title != null) chooser.setDialogTitle(title); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }
From source file:net.sf.jabref.importer.ImportFormats.java
/** * Create an AbstractAction for performing an Import operation. * @param frame The JabRefFrame of this JabRef instance. * @param openInNew Indicate whether the action should open into a new database or * into the currently open one.// w w w . j a v a 2 s.c o m * @return The action. */ public static AbstractAction getImportAction(JabRefFrame frame, boolean openInNew) { class ImportAction extends MnemonicAwareAction { private final JabRefFrame frame; private final boolean openInNew; public ImportAction(JabRefFrame frame, boolean openInNew) { this.frame = frame; this.openInNew = openInNew; putValue(Action.NAME, openInNew ? Localization.menuTitle("Import into new database") : Localization.menuTitle("Import into current database")); putValue(Action.ACCELERATOR_KEY, openInNew ? Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE) : Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE)); } @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = createImportFileChooser( Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)); int result = fileChooser.showOpenDialog(frame); if (result != JFileChooser.APPROVE_OPTION) { return; } File file = fileChooser.getSelectedFile(); if (file == null) { return; } FileFilter ff = fileChooser.getFileFilter(); ImportFormat format = null; if (ff instanceof ImportFileFilter) { format = ((ImportFileFilter) ff).getImportFormat(); } try { if (!file.exists()) { // Warn that the file doesn't exists: JOptionPane.showMessageDialog(frame, Localization.lang("File not found") + ": '" + file.getName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE); return; } ImportMenuItem imi = new ImportMenuItem(frame, openInNew, format); imi.automatedImport(Collections.singletonList(file.getAbsolutePath())); // Make sure we remember which filter was used, to set the default // for next time: if (format == null) { Globals.prefs.put(JabRefPreferences.LAST_USED_IMPORT, "__all"); } else { Globals.prefs.put(JabRefPreferences.LAST_USED_IMPORT, format.getFormatName()); } Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent()); } catch (Exception ex) { LOGGER.warn("Problem with import format", ex); } } } return new ImportAction(frame, openInNew); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopFileMultiUploadField.java
public DesktopFileMultiUploadField() { fileUploading = AppBeans.get(FileUploadingAPI.NAME); final JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); DesktopResources resources = App.getInstance().getResources(); Messages messages = AppBeans.get(Messages.NAME); String caption = messages.getMessage(getClass(), "upload.selectFiles"); impl = new JButton(); impl.setAction(new AbstractAction(caption, resources.getIcon(DEFAULT_ICON)) { @Override//from w w w.j av a 2s . co m public void actionPerformed(ActionEvent e) { if (fileChooser.showOpenDialog(impl) == JFileChooser.APPROVE_OPTION) { processFiles(fileChooser.getSelectedFiles()); } } }); DesktopComponentsHelper.adjustSize(impl); }