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:PersistentFrameTest.java
public void load() { // show file chooser dialog int r = chooser.showOpenDialog(null); // if file selected, open if(r == JFileChooser.APPROVE_OPTION) {//from ww w . ja v a2s .c o m try { File file = chooser.getSelectedFile(); XMLDecoder decoder = new XMLDecoder(new FileInputStream(file)); decoder.readObject(); decoder.close(); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:gui.menubar.SaveCommand.java
/** * Passes the file to the LevelSaver, first ensuring it has the correct * file type suffix./*from w w w . j a v a2 s .c om*/ */ @Override public void execute() { fileChooser.setCurrentDirectory(new File(SAVE_FILE_LOCATION)); fileChooser.setFileFilter(new XmlFileFilter()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); if (selectedFile != null) { if (FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase("xml")) { levelSaver.save(level, selectedFile); } else { selectedFile = new File(selectedFile.getParentFile(), FilenameUtils.getBaseName(selectedFile.getName()) + ".xml"); levelSaver.save(level, selectedFile); } } } }
From source file:org.pgptool.gui.ui.tools.browsefs.MultipleFilesChooserDialog.java
/** * Blocking call to browse for files/*from w w w. ja v a 2 s . c om*/ * * @return null if nothing was chosen, or array of files chosen otherwise */ public File[] askUserForMultipleFiles() { JFileChooser ofd = buildFileChooserDialog(); int result = ofd.showOpenDialog(optionalParent); if (result != JFileChooser.APPROVE_OPTION) { handleFilesWereChosen(null); return null; } File[] retFile = ofd.getSelectedFiles(); if (retFile == null || retFile.length == 0) { handleFilesWereChosen(null); return null; } handleFilesWereChosen(retFile); configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(retFile[0].getAbsolutePath())); return retFile; }
From source file:lince.controladores.exportar.AbrirExportarHoisan.java
@Override public void execute() { if (fc == null) { fc = new JFileChooser(); //Add a custom file filter and disable the default fc.addChoosableFileFilter(new FiltroArchivos("mdb", ResourceBundleHelper.getI18NLabel("HOISAN"))); fc.setAcceptAllFileFilterUsed(false); }//w w w . ja v a 2 s. com //Show it. int returnVal = fc.showDialog(LinceFrame.getInstance(), ResourceBundleHelper.getI18NLabel("actions.export.Hoisan.confirm")); //Process the results. if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.warn("Init export to Hoisan file: " + file.getName() + "."); HoisanTool hoisan = new HoisanTool(); String result = hoisan.exportFile(file); String message = ResourceBundleHelper.getI18NLabel( StringUtils.isEmpty(result) ? "action.result.export.ok" : "action.result.export.fail"); if (StringUtils.isNotEmpty(result)) { message = message + "\n" + result; } JOptionPane.showMessageDialog(LinceFrame.getInstance(), message); } else { log.warn("Hoisan export cancelled by user."); } //Reset the file chooser for the next time it's shown. fc.setSelectedFile(null); }
From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsdChooser = new JFileChooser(); xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsdChooser.getSelectedFile(); if (isXSD(file)) { XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName()); int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) { errorMessage();/*www.j av a2s. c o m*/ } else { if (saveXsd(file, xsdInfoQueryComponent.getName(), false, xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) { JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName()); newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { errorMessage(); } } } } else { errorMessage(); } } }
From source file:it.unibas.spicygui.controllo.tree.ActionExportQuery.java
public void actionPerformed(ActionEvent e) { this.executeInjection(); JFileChooser chooser = vista.getFileChooserSalvaFileGenerico(); File file;/*w w w.j av a 2s. c o m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT)); if (returnVal == JFileChooser.APPROVE_OPTION) { FileWriter writer = null; try { file = chooser.getSelectedFile(); writer = new FileWriter(file); writer.write(this.textArea.getText()); writer.flush(); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.EXPORT_OK)); } catch (IOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } finally { try { writer.close(); } catch (IOException ex) { } } } }
From source file:com.moneydance.modules.features.importlist.io.DefaultDirectoryChooser.java
@Override void chooseBaseDirectory() { final JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(this.getLocalizable().getDirectoryChooserTitle()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // disable the "All files" option. fileChooser.setAcceptAllFileFilterUsed(false); try {//from www . j a v a 2 s .c om fileChooser.setCurrentDirectory(FileUtils.getUserDirectory()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); fileChooser.setCurrentDirectory(parentDirectory); } if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } this.getPrefs().setBaseDirectory(fileChooser.getSelectedFile().getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:com.swg.parse.docx.OpenWord.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setAcceptAllFileFilterUsed(false); //this authorize only .docx selection fc.addChoosableFileFilter(new DocxFileFilter()); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }//from w ww .j av a 2 s . co m int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); String zipFilePath = "C:\\Users\\KXK3\\Documents\\ZipTest\\test.zip"; String destDirectory = "C:\\Users\\KXK3\\Documents\\ZipTest\\temp"; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(selectedFile, zip); unzipper.UnzipUtility(zip, directory); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\KXK3\\Documents\\ZipTest\\Pictures\\" + fil.getName())); } zip.delete(); FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = selectedFile.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content; String POIContent; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, selectedFile.getAbsolutePath(), version, 1); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } } else { //do nothing } }
From source file:com.anrisoftware.prefdialog.miscswing.filechoosers.OpenFileDialogModel.java
@Override public void openDialog(Component parent) throws PropertyVetoException { int result = chooser.showOpenDialog(parent); if (result == JFileChooser.APPROVE_OPTION) { setFileFilter(chooser.getFileFilter()); setFile(chooser.getSelectedFile()); } else {/*from www . ja v a2 s .c o m*/ setFileFilter(null); setFile(null); } }
From source file:de.burrotinto.jKabel.dbauswahlAS.DBAuswahlAAS.java
private String choosePath(String pfad) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(pfad)); chooser.setDialogTitle("DB Pfad"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); return chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION ? null : chooser.getSelectedFile().getPath() + File.separator; }