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.holycityaudio.SpinCAD.SpinCADFile.java
public SpinCADPatch fileOpenHex() { loadRecentHexFileList();/*from w ww .j av a 2s .c o m*/ final String newline = "\n"; SpinCADPatch p = new SpinCADPatch(); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Hex Files", "hex"); fc.setFileFilter(filter); fc.setAccessory(recentHexFileList); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fc.showOpenDialog(new JFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { String filePath = null; File file = fc.getSelectedFile(); System.out.println("Opening: " + file.getName() + "." + newline); filePath = file.getPath(); try { p = fileReadHex(filePath); } catch (Exception e) { e.printStackTrace(); SpinCADDialogs.MessageBox("Hex File open failed!", "That's not supposed to happen!"); } finally { saveMRUHexFolder(filePath); recentHexFileList.add(file); String fileName = file.getName(); p.patchFileName = fileName; p.cb.setFileName(fileName); p.isHexFile = true; p.setChanged(false); } } else { System.out.println("Open command cancelled by user." + newline); } saveRecentHexFileList(); return p; }
From source file:ihm.mainActivity.java
private void openMenuItemMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openMenuItemMousePressed // TODO add your handling code here: int open = fileChooser.showOpenDialog(this); if (open == JFileChooser.APPROVE_OPTION) { System.out.print(fileChooser.getSelectedFile().getAbsolutePath()); try {/*ww w . j a va 2 s .c o m*/ csv = new CSVtoObject(fileChooser.getSelectedFile().getAbsolutePath(), dataList); } catch (IOException | ParseException ex) { Logger.getLogger(mainActivity.class.getName()).log(Level.SEVERE, null, ex); } //System.out.print(dataList); } else { System.out.print("FAILURE"); } }
From source file:com.floreantpos.ui.model.MenuItemForm.java
protected void doSelectImageFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow()); if (option == JFileChooser.APPROVE_OPTION) { File imageFile = fileChooser.getSelectedFile(); try {/*from w w w . j av a 2 s. c om*/ byte[] itemImage = FileUtils.readFileToByteArray(imageFile); int imageSize = itemImage.length / 1024; if (imageSize > 20) { POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$ itemImage = null; return; } ImageIcon imageIcon = new ImageIcon( new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH)); lblImagePreview.setIcon(imageIcon); MenuItem menuItem = (MenuItem) getBean(); menuItem.setImageData(itemImage); } catch (IOException e) { PosLog.error(getClass(), e); } } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobCleanDirectory.java
private List<File> getFileList() { ArrayList<File> files = new ArrayList<File>(); String pathToCheck = ""; // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;//from w w w . j a v a 2s . c om // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser.setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and cleanup files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else if (ImageCaptureProperties.getPathBelowBase(startPoint).trim().length() == 0) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") which is the base image directory."); String message = "Can only scan and cleanup files in a selected directory within the base directory (" + base + ").\nYou must select some subdirectory within the base directory to cleanup."; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Cleanup image base directory.", JOptionPane.YES_NO_OPTION); } else { if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); // retrieve a list of image records in the selected directory ICImageLifeCycle ils = new ICImageLifeCycle(); List<ICImage> images = ils.findAllInDir(pathToCheck); Iterator<ICImage> iter = images.iterator(); while (iter.hasNext()) { ICImage image = iter.next(); File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); files.add(imageFile); counter.incrementFilesSeen(); } } } } log.debug("Found " + files.size() + " Image files in directory to check."); return files; }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX:/*from w w w.j av a 2 s.com*/ System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:dev.agustin.serializer.MainWindow.java
private void load3dFile() { int state = getJFileChooser().showOpenDialog(this); if (state == JFileChooser.APPROVE_OPTION) { File f = getJFileChooser().getSelectedFile(); try {//from w w w . j ava 2 s . co m BufferedReader br = new BufferedReader(new FileReader(f)); String fileExtension = FilenameUtils.getExtension(f.getName()); this.saveDirectory = FilenameUtils.getPath(f.getPath()); if (fileExtension.compareToIgnoreCase("3ds") == 0) { //3ds file, load in the engine try { this.objectArray = Loader.load3DS(f.getCanonicalPath(), 1); } catch (Exception ex) { System.out.print(ex.getMessage()); } } else if (fileExtension.compareToIgnoreCase("obj") == 0) { //obj file try { String mtlFile = f.getCanonicalPath().replace(".obj", ".mtl"); this.objectArray = Loader.loadOBJ(f.getCanonicalPath(), mtlFile, 1); } catch (Exception ex) { System.out.println("ERROR LOADING MATERIAL! trying without material"); System.out.print(ex.getMessage()); try { this.objectArray = Loader.loadOBJ(f.getCanonicalPath(), null, 1); } catch (Exception ex2) { System.out.println("Error loading object, aborting."); System.out.print(ex.getMessage()); } } } else { System.out.println("Error loading file " + f.getName() + " not a 3D Studio (.3DS) file"); } br.close(); setTitle(title); hasChanged = false; System.out.println("Now dumping textures names:"); Enumeration<String> textures = TextureManager.getInstance().getNames(); while (textures.hasMoreElements()) { System.out.println(textures.nextElement()); } System.out.println("Done."); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:com.compomics.colims.client.controller.admin.FastaDbSaveUpdateController.java
@Override @PostConstruct// w w w. j a v a 2s. com public void init() { //register to event bus eventBus.register(this); fastaDbSaveUpdatePanel = fastaDbManagementController.getFastaDbManagementDialog() .getFastaDbSaveUpdatePanel(); headerParseRuleAdditionDialog = new HeaderParseRuleAdditionDialog( fastaDbManagementController.getFastaDbManagementDialog(), true); taxonomyBindingList = ObservableCollections.observableList(new ArrayList<>()); taxonomyBindingList.add(TAXONOMY_CV_PARAM_NONE); taxonomyBindingList.addAll(cvParamService.findByCvParamByClass(TaxonomyCvParam.class)); //init binding bindingGroup = new BindingGroup(); JComboBoxBinding taxonomyComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, taxonomyBindingList, fastaDbSaveUpdatePanel.getTaxomomyComboBox()); bindingGroup.addBinding(taxonomyComboBoxBinding); headerParseRuleBindingList = ObservableCollections.observableList(new ArrayList<>()); try { config = PropertiesUtil.parsePropertiesFile("config/header-parse-rule.properties"); } catch (IOException | ConfigurationException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillHeaderParseRuleComboBox(); JComboBoxBinding parseRuleComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, headerParseRuleBindingList, fastaDbSaveUpdatePanel.getHeaderParseRuleComboBox()); bindingGroup.addBinding(parseRuleComboBoxBinding); databaseBindingList = ObservableCollections.observableList(new ArrayList<>()); Properties allProperties = new Properties(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { allProperties.load(loader.getResourceAsStream("config/embl-ebi-database.properties")); databaseSet = new TreeSet(allProperties.keySet()); } catch (IOException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillDatabaseComboBox(); JComboBoxBinding databaseComboBoxBinding = SwingBindings.createJComboBoxBinding( AutoBinding.UpdateStrategy.READ_WRITE, databaseBindingList, fastaDbSaveUpdatePanel.getDatabaseComboBox()); bindingGroup.addBinding(databaseComboBoxBinding); bindingGroup.bind(); //init FASTA file selection //disable select multiple files fastaDbSaveUpdatePanel.getFastaFileChooser().setMultiSelectionEnabled(false); //set FASTA file filter fastaDbSaveUpdatePanel.getFastaFileChooser().setFileFilter(new FastaFileFilter()); //add listeners fastaDbSaveUpdatePanel.getBrowseTaxonomyButton().addActionListener(e -> { List<CvParam> cvParams = cvParamService.findByCvParamByClass(TaxonomyCvParam.class); //update the CV param list cvParamManagementController.updateDialog("FASTA DB taxonomy", TaxonomyCvParam.class, PRESELECTED_ONTOLOGY_NAMESPACES, cvParams); cvParamManagementController.showView(); }); fastaDbSaveUpdatePanel.getBrowseHeaderParseRuleButtton().addActionListener(l -> { headerParseRuleAdditionDialog.getParseRuleTextField().setText(""); headerParseRuleAdditionDialog.getDescriptionTextField().setText(""); GuiUtils.centerDialogOnComponent(fastaDbSaveUpdatePanel, headerParseRuleAdditionDialog); headerParseRuleAdditionDialog.setVisible(true); }); headerParseRuleAdditionDialog.getSaveParseRuleButton().addActionListener(l -> { try { config = PropertiesUtil.addProperty(config, headerParseRuleAdditionDialog.getDescriptionTextField().getText(), headerParseRuleAdditionDialog.getParseRuleTextField().getText()); } catch (ConfigurationException | IOException ex) { java.util.logging.Logger.getLogger(FastaDbSaveUpdateController.class.getName()).log(Level.SEVERE, null, ex); } fillHeaderParseRuleComboBox(); headerParseRuleAdditionDialog.dispose(); }); fastaDbSaveUpdatePanel.getBrowseFastaButton().addActionListener(e -> { //in response to the button click, show open dialog int returnVal = fastaDbSaveUpdatePanel.getFastaFileChooser().showOpenDialog(fastaDbSaveUpdatePanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File fastaFile = fastaDbSaveUpdatePanel.getFastaFileChooser().getSelectedFile(); //show FASTA file name and path in textfields fastaDbSaveUpdatePanel.getFileNameTextField().setText(fastaFile.getName()); fastaDbSaveUpdatePanel.getFilePathTextField().setText(fastaFile.getAbsolutePath()); } }); fastaDbSaveUpdatePanel.getSaveOrUpdateButton().addActionListener(e -> { //validate FASTA DB updateFastaToEdit(); List<String> validationMessages = GuiUtils.validateEntity(fastaDbToEdit); if (validationMessages.isEmpty()) { if (fastaDbToEdit.getId() != null) { fastaDbToEdit = fastaDbService.merge(fastaDbToEdit); fastaDbManagementController.updateFastaDb(); } else { fastaDbService.persist(fastaDbToEdit); fastaDbManagementController.addFastaDb(fastaDbToEdit); } fastaDbSaveUpdatePanel.getNameTextField().setEnabled(false); fastaDbSaveUpdatePanel.getSaveOrUpdateButton().setText("update"); fastaDbSaveUpdatePanel.getFastaDbStateInfoLabel().setText(""); saveUpdate = true; MessageEvent messageEvent = new MessageEvent("Fasta DB store confirmation", "Fasta DB " + fastaDbToEdit.getName() + " was stored successfully!", JOptionPane.INFORMATION_MESSAGE); eventBus.post(messageEvent); fastaDbManagementController.showOverviewPanel(); } else { MessageEvent messageEvent = new MessageEvent("Validation failure", validationMessages, JOptionPane.WARNING_MESSAGE); eventBus.post(messageEvent); } }); fastaDbSaveUpdatePanel.getBackButton().addActionListener(e -> { if (!saveUpdate) { fastaDbManagementController.setSelectedFasta(-1); } saveUpdate = false; fastaDbManagementController.showOverviewPanel(); }); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createImportButton() { JButton b = new JButton(new AbstractAction(null, UIAgent.getInstance().getIcon(UIAgent.ICON_IMPORT_24)) { private static final long serialVersionUID = 985413615438877711L; @Override/* w w w . j a v a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { JFileChooser ch = new JFileChooser(); ch.setFileFilter(new ExtensionFilter("xls", "Excel File")); int i = ch.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { DiveProfileExcelParser p = new DiveProfileExcelParser(); try { File f = ch.getSelectedFile(); DiveProfile dp = p.read(f); I18nResourceManager i18n = I18nResourceManager.sharedInstance(); int yes = JOptionPane.showConfirmDialog(DiveProfileGraphicDetailPanel.this, i18n.getString("overwritte.diveprofile.confirm"), i18n.getString("confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (yes == JOptionPane.YES_OPTION) { currentDive.setDiveProfile(dp); setDiveProfile(dp, currentDive); logBookManagerFacade.setDiveChanged(currentDive); } } catch (IOException e1) { ExceptionDialog.showDialog(e1, DiveProfileGraphicDetailPanel.this); LOGGER.error(e1.getMessage()); } } } }); b.setToolTipText("Import"); return b; }
From source file:it.unibas.spicygui.controllo.file.ActionOpenMappingTask.java
@Override public void performAction() { this.executeInjection(); JFileChooser chooser = vista.getFileChooserApriXMLAndTGD(); File file;/*from www.ja v a2 s . c o m*/ int returnVal = chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()); Scenario scenario = null; if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); String fileAbsoluteFile = file.getPath(); scenario = openCompositionFile(fileAbsoluteFile, file, true); MappingTask mappingTask = scenario.getMappingTask(); File f = chooser.getSelectedFile(); FileObject fo = FileUtil.toFileObject(f); // TGDDataObject dobj = null; try { TGDEditorSupport tGDEditorSupport = new TGDEditorSupport(fo); // dobj = tGDEditorSupport.getDataObject(); tGDEditorSupport.open(); //giannisk scenario.setTGDEditor(tGDEditorSupport); scenario.getMappingTaskTopComponent().requestActive(); // dobj = DataObject.find(fo); } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } //if (dobj != null){ // OpenCookie lc = (OpenCookie)dobj.getCookie(OpenCookie.class); // if (lc == null) {/* cannot do it */ return;} // lc.open(); //// Line l = lc.getLineSet().getOriginal(lineNumber); //// l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS); //} //try { // Editor.getDefaultLocale(). //// new ROEditor(fo).open(); // // new TGDEditorSupport(fo).edit(); // //// DataObject dataObject = new ROEditor(fo).getDataObject(); //// //// EditorCookie cookie = (EditorCookie)dataObject.getCookie(EditorCookie.class); //// cookie.open(); // // System.out.println("eseguito"); //} catch (DataObjectNotFoundException e) { // e.printStackTrace(); //} // if (!(mappingTask.getSourceProxy() instanceof ConstantDataSourceProxy)) { // Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); scenario.setCompositionTopComponent(new CompositionTopComponent(scenario)); actionComposition.performAction(); } } }
From source file:it.ferogrammer.ui.MainAppFrame.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed if (jPanel2.getComponentCount() == 1 && (jPanel2.getComponent(0) instanceof ElectropherogramChartPanel)) { ElectropherogramChartPanel chartPanel = (ElectropherogramChartPanel) jPanel2.getComponent(0); final JFileChooser fc = new JFileChooser(); // fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(chartPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (!file.getName().endsWith(".png")) { int extindex = file.getPath().indexOf('.') == -1 ? file.getPath().length() : file.getPath().indexOf('.'); file = new File(file.getPath().substring(0, extindex) + ".png"); }/*from w w w. ja v a2s . co m*/ try { ChartUtilities.saveChartAsPNG(file, chartPanel.getChart(), chartPanel.getWidth(), chartPanel.getHeight()); } catch (IOException ex) { JOptionPane op = new JOptionPane(); op.showMessageDialog(jPanel2, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane op = new JOptionPane(); op.showMessageDialog(jPanel2, "Cannot export image", "Error", JOptionPane.ERROR_MESSAGE); } }