List of usage examples for javax.swing JFileChooser getSelectedFile
public File getSelectedFile()
From source file:net.sf.profiler4j.console.Console.java
public void openProject() { if (client.isConnected()) { int ret = JOptionPane.showConfirmDialog(mainFrame, "Proceed and disconnect?", "Open Profiling Project", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) { return; }/*from w w w . ja v a2 s. c o m*/ } if (checkUnsavedChanges()) { return; } if (client.isConnected()) { disconnect(); if (client.isConnected()) { return; } } JFileChooser fc = new JFileChooser(lastDir); fc.addChoosableFileFilter(projectFilter); if (fc.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { File selFile = fc.getSelectedFile(); SAXBuilder builder = new SAXBuilder(); Document doc = null; try { doc = builder.build(selFile); } catch (JDOMException e) { error("XML Error", e); } catch (IOException e) { error("I/O Error", e); } if (doc != null) { Project p = new Project(); Element el = doc.getRootElement(); p.setHostname(el.getChildText("Host")); p.setPort(Integer.parseInt(el.getChildText("Port"))); Element rulesEl = el.getChild("Rules"); p.setAccess(Rule.AccessOption.valueOf(rulesEl.getAttributeValue("access"))); p.setBeanprops(Boolean.parseBoolean(rulesEl.getAttributeValue("beanProps"))); p.getRules().clear(); for (Iterator i = rulesEl.getChildren("Rule").iterator(); i.hasNext();) { Element r = (Element) i.next(); Rule rule = new Rule(r.getText(), Rule.Action.valueOf(r.getAttributeValue("action"))); p.getRules().add(rule); } // Backwards compatible way to read the export pattern // If it is not there, we leave the defaults as they are, // otherwise we set the saved setting. Element export = el.getChild(PROJECT_XML_ELEMENT__EXPORT_PATTERN); if (null != export) { String enabled = export.getAttributeValue(PROJECT_XML_ATTRIBUTE__ENABLED); p.setExportAutomaticallyEnabled(Boolean.valueOf(enabled)); p.setExportPattern(export.getAttributeValue(PROJECT_XML_ATTRIBUTE__PATTERN)); } p.setFile(selFile); p.clearChanged(); this.project = p; lastDir = selFile.getParentFile(); } } }
From source file:jhplot.HPlotChart.java
/** * Exports the image to some graphic format. *//*from ww w . j a va2 s.c o m*/ protected void exportImage() { JFrame jm = getFrame(); JFileChooser fileChooser = jhplot.gui.CommonGUI.openImageFileChooser(jm); if (fileChooser.showDialog(jm, "Save As") == 0) { final File scriptFile = fileChooser.getSelectedFile(); if (scriptFile == null) return; else if (scriptFile.exists()) { int res = JOptionPane.showConfirmDialog(jm, "The file exists. Do you want to overwrite the file?", "", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) return; } String mess = "write image file .."; JHPlot.showStatusBarText(mess); Thread t = new Thread(mess) { public void run() { export(scriptFile.getAbsolutePath()); }; }; t.start(); } }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Get")) { if (lstHybris.getSelectedIndex() >= 0) { try { System.out.println("Retrieving " + lstHybris.getSelectedValue() + "..."); byte[] retrieved = cm.hybris.get(lstHybris.getSelectedValue()); if (retrieved != null) { JFileChooser fc = new JFileChooser( System.getProperty("user.home") + File.separator + "Desktop"); fc.setSelectedFile(new File("RETRIEVED_" + lstHybris.getSelectedValue())); int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileUtils.writeByteArrayToFile(file, retrieved); System.out.println("Saved: " + file.getName() + "."); }/*from ww w. j a v a2 s . c o m*/ } else JOptionPane.showMessageDialog(frame, "Hybris could not download the file.", "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Put")) { JFileChooser fc = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop"); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println("Putting: " + file.getName() + "."); byte[] array; try { array = FileUtils.readFileToByteArray(file); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.HYBRIS, file.getName(), array)) .start(); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Delete")) { if (lstHybris.getSelectedIndex() >= 0) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, lstHybris.getSelectedValue(), null)).start(); System.out.println("Removed " + lstHybris.getSelectedValue() + " from Hybris."); } } }
From source file:it.unibas.spicygui.controllo.datasource.ActionAddTargetInstanceXml.java
@Override public void performAction() { JFileChooser chooser = vista.getFileChooserApriXML(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); InstancesTopComponent viewInstancesTopComponent = scenario.getInstancesTopComponent(); File file;/*w w w .j av a 2 s.c om*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.LOAD)); if (returnVal == JFileChooser.APPROVE_OPTION) if (scenario.getMappingTask().getSourceProxy().getType().equalsIgnoreCase("XML")) { try { file = chooser.getSelectedFile(); DAOXsd daoXsd = new DAOXsd(); daoXsd.loadInstance(mappingTask.getTargetProxy(), file.getAbsolutePath()); scenario.addTargetInstance(file.getAbsolutePath()); if (!viewInstancesTopComponent.isRipulito()) { //viewInstancesTopComponent.clearTarget(); viewInstancesTopComponent.createTargetInstanceTree(); viewInstancesTopComponent.requestActive(); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.ADD_INSTANCE_OK)); } } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } else { DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.CSV_INST_NOTIF), DialogDescriptor.ERROR_MESSAGE)); } }
From source file:it.unibas.spicygui.controllo.datasource.ActionAddSourceInstanceXml.java
@Override public void performAction() { JFileChooser chooser = vista.getFileChooserApriXML(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); InstancesTopComponent viewInstancesTopComponent = scenario.getInstancesTopComponent(); File file;/*from w w w . j ava 2s. co m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.LOAD)); if (returnVal == JFileChooser.APPROVE_OPTION) if (scenario.getMappingTask().getSourceProxy().getType().equalsIgnoreCase("XML")) { try { file = chooser.getSelectedFile(); DAOXsd daoXsd = new DAOXsd(); daoXsd.loadInstance(mappingTask.getSourceProxy(), file.getAbsolutePath()); scenario.addSourceInstance(file.getAbsolutePath()); if (!viewInstancesTopComponent.isRipulito()) { viewInstancesTopComponent.clearSource(); viewInstancesTopComponent.createSourceInstanceTree(); viewInstancesTopComponent.requestActive(); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.ADD_INSTANCE_OK)); } } catch (DAOException ex) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.OPEN_ERROR) + " : " + ex.getMessage(), DialogDescriptor.ERROR_MESSAGE)); logger.error(ex); } } else { DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.CSV_INST_NOTIF), DialogDescriptor.ERROR_MESSAGE)); } }
From source file:be.fedict.eid.tsl.tool.TslTool.java
@Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (EXIT_ACTION_COMMAND.equals(command)) { System.exit(0);/*from w ww. j a v a2 s . c om*/ } else if (OPEN_ACTION_COMMAND.equals(command)) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open TSL"); int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { displayTsl(fileChooser.getSelectedFile()); } } else if (ABOUT_ACTION_COMMAND.equals(command)) { JOptionPane.showMessageDialog(this, "eID TSL Tool\n" + "Copyright (C) 2009-2013 FedICT\n" + "http://code.google.com/p/eid-tsl/", "About", JOptionPane.INFORMATION_MESSAGE); } else if (CLOSE_ACTION_COMMAND.equals(command)) { if (this.activeTslInternalFrame.getTrustServiceList().hasChanged()) { int result = JOptionPane.showConfirmDialog(this, "TSL has been changed.\n" + "Save the TSL?", "Save", JOptionPane.YES_NO_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == result) { return; } if (JOptionPane.YES_OPTION == result) { try { this.activeTslInternalFrame.save(); } catch (IOException e) { LOG.error("IO error: " + e.getMessage(), e); } } } try { this.activeTslInternalFrame.setClosed(true); } catch (PropertyVetoException e) { LOG.warn("property veto error: " + e.getMessage(), e); } } else if (SIGN_ACTION_COMMAND.equals(command)) { LOG.debug("sign"); TrustServiceList trustServiceList = this.activeTslInternalFrame.getTrustServiceList(); if (trustServiceList.hasSignature()) { int confirmResult = JOptionPane.showConfirmDialog(this, "TSL is already signed.\n" + "Resign the TSL?", "Resign", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } SignSelectPkcs11FinishablePanel pkcs11Panel = new SignSelectPkcs11FinishablePanel(); WizardDescriptor wizardDescriptor = new WizardDescriptor( new WizardDescriptor.Panel[] { new SignInitFinishablePanel(), pkcs11Panel, new SignSelectCertificatePanel(pkcs11Panel, trustServiceList), new SignFinishFinishablePanel() }); wizardDescriptor.setTitle("Sign TSL"); wizardDescriptor.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); DialogDisplayer dialogDisplayer = DialogDisplayer.getDefault(); Dialog wizardDialog = dialogDisplayer.createDialog(wizardDescriptor); wizardDialog.setVisible(true); } else if (SAVE_ACTION_COMMAND.equals(command)) { LOG.debug("save"); try { this.activeTslInternalFrame.save(); this.saveMenuItem.setEnabled(false); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } else if (SAVE_AS_ACTION_COMMAND.equals(command)) { LOG.debug("save as"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save As"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File tslFile = fileChooser.getSelectedFile(); if (tslFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + tslFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.saveAs(tslFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } this.saveMenuItem.setEnabled(false); } } else if (EXPORT_ACTION_COMMAND.equals(command)) { LOG.debug("export"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Export to PDF"); int result = fileChooser.showSaveDialog(this); if (JFileChooser.APPROVE_OPTION == result) { File pdfFile = fileChooser.getSelectedFile(); if (pdfFile.exists()) { int confirmResult = JOptionPane.showConfirmDialog(this, "File already exists.\n" + pdfFile.getAbsolutePath() + "\n" + "Overwrite file?", "Overwrite", JOptionPane.OK_CANCEL_OPTION); if (JOptionPane.CANCEL_OPTION == confirmResult) { return; } } try { this.activeTslInternalFrame.export(pdfFile); } catch (IOException e) { LOG.debug("IO error: " + e.getMessage(), e); } } } else if ("TSL-BE-2010-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.FIRST); displayTsl("*TSL-BE-2010-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.SECOND); displayTsl("*TSL-BE-2010-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2010-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2010, Trimester.THIRD); displayTsl("*TSL-BE-2010-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.FIRST); displayTsl("*TSL-BE-2011-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.SECOND); displayTsl("*TSL-BE-2011-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2011-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2011, Trimester.THIRD); displayTsl("*TSL-BE-2011-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.FIRST); displayTsl("*TSL-BE-2012-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.SECOND); displayTsl("*TSL-BE-2012-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2012-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2012, Trimester.THIRD); displayTsl("*TSL-BE-2012-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.FIRST); displayTsl("*TSL-BE-2013-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.SECOND); displayTsl("*TSL-BE-2013-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2013-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2013, Trimester.THIRD); displayTsl("*TSL-BE-2013-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.FIRST); displayTsl("*TSL-BE-2014-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.SECOND); displayTsl("*TSL-BE-2014-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2014-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2014, Trimester.THIRD); displayTsl("*TSL-BE-2014-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T1".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.FIRST); displayTsl("*TSL-BE-2015-T1.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T2".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.SECOND); displayTsl("*TSL-BE-2015-T2.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } else if ("TSL-BE-2015-T3".equals(command)) { TrustServiceList trustServiceList = BelgianTrustServiceListFactory.newInstance(2015, Trimester.THIRD); displayTsl("*TSL-BE-2015-T3.xml", trustServiceList); this.saveMenuItem.setEnabled(false); } }
From source file:com.stanley.captioner.MainFrame.java
private void outputDirectoryButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_outputDirectoryButtonActionPerformed {//GEN-HEADEREND:event_outputDirectoryButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (lastOutputDirectory != null) { fileChooser.setCurrentDirectory(lastOutputDirectory); }// w w w . j a v a 2s . co m int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastOutputDirectory = fileChooser.getCurrentDirectory(); File file = fileChooser.getSelectedFile(); outputDirectoryField.setText(file.getAbsolutePath()); if (videoTable.getRowCount() > 0 && outputDirectoryField.getText().length() > 0) { convertButton.setEnabled(true); } } }
From source file:au.org.ala.delta.editor.ui.ImageDetailsPanel.java
private File getMediaFile(FileFilter filter) { String imagePath = _dataSet.getImagePath(); JFileChooser chooser = new JFileChooser(imagePath); chooser.setFileFilter(filter);/*from w w w. j a v a2s . co m*/ if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File imageFile = chooser.getSelectedFile(); ImageSettings settings = _dataSet.getImageSettings(); if (settings.isOnResourcePath(imageFile)) { String name = imageFile.getName(); boolean exists = false; if (_selectedImage != null) { List<ImageOverlay> existingSounds = _selectedImage.getSounds(); for (ImageOverlay sound : existingSounds) { if (name.equals(sound.overlayText)) { exists = true; break; } } } if (exists) { int result = _messageHelper.confirmDuplicateFileName(); if (result == JOptionPane.YES_OPTION) { imageFile = new File(imageFile.getAbsolutePath()); } else if (result == JOptionPane.NO_OPTION) { return getMediaFile(filter); } else { imageFile = null; } } else { // Turn the file into a relative one. imageFile = new File(name); } } else { // Ask about it or copy it to the image path. int result = _messageHelper.confirmNotOnImagePath(); if (result == JOptionPane.YES_OPTION) { imageFile = new File(imageFile.getAbsolutePath()); } else if (result == JOptionPane.NO_OPTION) { return getMediaFile(filter); } else { imageFile = null; } } return imageFile; } return null; }
From source file:be.ugent.maf.cellmissy.gui.controller.TracksWriterController.java
/** * Choose Directory/* w w w .ja v a 2 s .co m*/ */ private void chooseDirectory() { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select directory to save the files"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(tracksWriterDialog); if (returnVal == JFileChooser.APPROVE_OPTION) { directory = fileChooser.getSelectedFile(); } tracksWriterDialog.getDirectoryTextField().setText(directory.getAbsolutePath()); }
From source file:com.socrata.datasync.ui.MetadataJobTab.java
public void saveJob() { populateJobFromFields();/* www . j a v a 2s . c o m*/ // TODO If an existing file was selected WARN user of overwriting // if first time saving this job: Open dialog box to select "Save as..." location // otherwise save to existing file boolean updateJobCommandTextField = false; String selectedJobFileLocation = jobFileLocation; if (selectedJobFileLocation.equals("")) { JFileChooser savedJobFileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( JOB_FILE_NAME + " (*." + JOB_FILE_EXTENSION + ")", JOB_FILE_EXTENSION); savedJobFileChooser.setFileFilter(filter); int returnVal = savedJobFileChooser.showSaveDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = savedJobFileChooser.getSelectedFile(); selectedJobFileLocation = file.getAbsolutePath(); if (!selectedJobFileLocation.endsWith("." + JOB_FILE_EXTENSION)) { selectedJobFileLocation += "." + JOB_FILE_EXTENSION; } jobFileLocation = selectedJobFileLocation; metadataJob.setPathToSavedFile(selectedJobFileLocation); jobTabTitleLabel.setText(metadataJob.getJobFilename()); updateJobCommandTextField = true; } } // actually save the job file (may overwrite) try { metadataJob.writeToFile(selectedJobFileLocation); // Update job tab title label jobTabTitleLabel.setText(metadataJob.getJobFilename()); // Update the textfield with new command if (updateJobCommandTextField) { String runJobCommand = Utils.getRunJobCommand(metadataJob.getPathToSavedFile()); runCommandTextField.setText(runJobCommand); } } catch (IOException e) { JOptionPane.showMessageDialog(mainFrame, "Error saving " + selectedJobFileLocation + ": " + e.getMessage()); } }