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:com.alvermont.terraj.util.ui.JNLPFileChooser.java
/** * Carry out the file save dialog/*from w w w . j a va 2 s .c om*/ * * @param parent The parent for the dialog * @return The result of the user selection */ public int showSaveDialog(Component parent) { // if (chooser != null) // { int option = chooser.showSaveDialog(parent); if (option == JFileChooser.APPROVE_OPTION) { File target = addExtension(chooser.getSelectedFile()); fileContents = new MyFileContents(target); } else { fileContents = null; } // } // else // { // // NOTE: we use the FileOpenService here instead of FileSaveService // // because I couldn't get the latter to work. I just got // // StreamClosed exceptions thrown all the time. // FileOpenService fos; // // try // { // fos = (FileOpenService) ServiceManager.lookup( // "javax.jnlp.FileOpenService"); // // try // { // String[] extensions = new String[defaultExtensions.size()]; // // defaultExtensions.toArray(extensions); // // fileContents = fos.openFileDialog(null, extensions); // } // catch (IOException ex) // { // log.error("IOException in open file selection", ex); // // return JFileChooser.ERROR_OPTION; // } // } // catch (UnavailableServiceException e) // { // // we assume that JNLP is not available and some other security manager // // related reason applies // log.error( // "Couldn't create a file selector or lookup JNLP service", e); // // throw new SecurityException( // "Could not create file selector or use JNLP service", e); // } // } if (fileContents != null) { return JFileChooser.APPROVE_OPTION; } else { return JFileChooser.CANCEL_OPTION; } }
From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java
/** * This method initializes jExaminarButton * /*from w ww. ja v a 2 s . co m*/ * @return javax.swing.JButton */ private JButton getJExaminarButton() { if (jExaminarButton == null) { jExaminarButton = new JButton(); jExaminarButton.setText(I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_10)); jExaminarButton.setPreferredSize(new Dimension(90, 20)); jExaminarButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final JFileChooser libreria = new JFileChooser(); libreria.setDialogTitle(I18n.getResource(LIBRERIAXADES_VALIDARTARJETA_TEXTO_11)); int returnVal = libreria.showOpenDialog(jPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { jLibreriaTextField.setText(libreria.getSelectedFile().toString()); } } }); } return jExaminarButton; }
From source file:com.opendoorlogistics.studio.scripts.editor.ScriptEditor.java
protected SimpleAction createSaveScriptAsAction() { return new SimpleAction("Save as", "Save script as", "document-save-as-2-16x16.png") { @Override//from ww w .ja v a2 s .co m public void actionPerformed(ActionEvent e) { validateScriptData(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter( AppConstants.ORG_NAME + " script (" + ScriptConstants.FILE_EXT.toLowerCase() + ")", ScriptConstants.FILE_EXT)); File file = ScriptEditor.this.file; if (file == null) { file = createDefaultFilename(); } if (file == null) { file = PreferencesManager.getSingleton().getScriptsDirectory(); } // ensure absolute if (file != null) { file = file.getAbsoluteFile(); } // ensure have filename if (file != null && file.isDirectory()) { file = new File(file, createDefaultPathlessFilename()); } if (file != null) { chooser.setCurrentDirectory(file.getParentFile()); chooser.setSelectedFile(file); } if (chooser.showSaveDialog(ScriptEditor.this) == JFileChooser.APPROVE_OPTION) { save(chooser.getSelectedFile()); } } }; }
From source file:id.co.nlp.MachineTranslationAPP.FormTraining.java
private void dictTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dictTextFieldActionPerformed this.fileChooser.setFileFilter(new FileOpenFilter("xml", "Data Latih BP")); if (this.fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {//from w w w . j ava2s .c om this.dictFile = this.fileChooser.getSelectedFile().getCanonicalPath(); this.dictTextField.setText(this.dictFile); } catch (IOException ex) { Logger.getLogger(FormTraining.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
private void importMarketLogs() { File inputDir = null;/*from w w w. j a v a 2s . c o m*/ if (appConfigProvider.getAppConfig().hasLastMarketLogImportDirectory()) { inputDir = appConfigProvider.getAppConfig().getLastMarketLogImportDirectory(); if (!inputDir.exists() || !inputDir.isDirectory()) { inputDir = null; } } final JFileChooser chooser = inputDir != null ? new JFileChooser(inputDir) : new JFileChooser(); chooser.setFileHidingEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(true); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File[] files = chooser.getSelectedFiles(); if (!ArrayUtils.isEmpty(files)) { appConfigProvider.getAppConfig().setLastMarketLogImportDirectory(files[0].getParentFile()); try { appConfigProvider.save(); } catch (IOException e) { log.error("importMarketLogs(): Failed to save configuration", e); } importMarketLogs(files); } } }
From source file:bridge.toolkit.ControllerJFrame.java
private void OutputDirectoryBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { OutputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = OutputFileChooser.showOpenDialog(ControllerJFrame.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = OutputFileChooser.getSelectedFile(); OutputDirectoryField.setText(file.getAbsolutePath()); }/* www. j av a2 s.co m*/ }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSavePatchAs(SpinCADPatch p) { // Create a file chooser String savedPath = prefs.get("MRUPatchFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Files", "spcd"); fc.setFileFilter(filter);// w w w .j ava 2 s. c om fc.setSelectedFile(new File(p.patchFileName)); int returnVal = fc.showSaveDialog(new JFrame()); // need to process user canceling box right here if (returnVal == JFileChooser.APPROVE_OPTION) { // In response to a button click: File fileToBeSaved = fc.getSelectedFile(); if (!fileToBeSaved.getAbsolutePath().endsWith(".spcd")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spcd"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame = new JFrame(); n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { try { String filePath = fileToBeSaved.getPath(); String fileName = fileToBeSaved.getName(); p.patchFileName = fileName; fileSavePatch(p); recentPatchFileList.add(fileToBeSaved); saveMRUPatchFolder(filePath); } catch (Exception e) { // thrown over in SpinCADFile.java e.printStackTrace(); SpinCADDialogs.MessageBox("File save failed!", "look at stack trace for info"); } finally { p.setChanged(false); } } } }
From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java
/** * Suche einen Platz und den Namen frs Logfile Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * /*from w ww . j a v a 2 s. com*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.08.2012 */ private void chooseLogFile() { JFileChooser fileChooser; int retVal; // // Einen Dateiauswahldialog Creieren // fileChooser = new JFileChooser(); fileChooser.setLocale(Locale.getDefault()); fileChooser.setDialogTitle(fileChooserLogTitle); fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG); fileChooser.setApproveButtonToolTipText(approveLogButtonTooltip); // das existierende Logfile voreinstellen fileChooser.setSelectedFile(SpxPcloggerProgramConfig.logFile); retVal = fileChooser.showDialog(this, approveLogButtonText); // Mal sehen, was der User gewollt hat if (retVal == JFileChooser.APPROVE_OPTION) { // Ja, ich wollte das so // nach dem nchsten Programmstart dieses File anlegen/nutzen logfileNameTextField.setText(fileChooser.getSelectedFile().getAbsolutePath()); wasChangedParameter = true; lg.debug("select <" + fileChooser.getSelectedFile().getName() + "> as new logfile after restart."); } }
From source file:id.co.nlp.MachineTranslationAPP.FormTraining.java
private void dictButtonCorpusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dictButtonCorpusActionPerformed if (this.fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {// w ww .j a va2 s . c o m this.dictFile = this.fileChooser.getSelectedFile().getCanonicalPath(); this.dictTextField.setText(this.dictFile); } catch (IOException ex) { Logger.getLogger(FormTraining.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveBtnActionPerformed try {/*from www. j a v a2s.co m*/ JFileChooser fileChooser = new JFileChooser(); int checker = fileChooser.showOpenDialog(null); if (checker == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String message = "The selected file already exists.\nOverwrite?"; if (!selectedFile.exists() || JOptionPane.showConfirmDialog(this, message, "Save result", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { if (!FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase(FILE_EXT_ZIP)) { selectedFile = new File(selectedFile.getAbsoluteFile() + "." + FILE_EXT_ZIP); } btnController.save(selectedFile); // default title and icon JOptionPane.showMessageDialog(this, "Result has been saved to filesystem."); } } } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Fehler beim Schreiben", JOptionPane.ERROR_MESSAGE); logger.warn(e, e); } catch (Exception e) { e.printStackTrace(); } }