List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser()
JFileChooser
pointing to the user's default directory. From source file:com.dfki.av.sudplan.vis.wiz.DataSourceSelectionPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser jfc = new JFileChooser(); jfc.addChoosableFileFilter(new FileNameExtensionFilter("ESRI Shapfile (*.shp)", "shp", "Shp", "SHP")); jfc.addChoosableFileFilter(new FileNameExtensionFilter("Zip file (*.zip)", "zip", "ZIP", "Zip")); XMLConfiguration xmlConfig = Configuration.getXMLConfiguration(); String path = xmlConfig.getString("sudplan3D.working.dir"); File dir;//from w w w.j ava 2 s. c om if (path != null) { dir = new File(path); if (dir.exists()) { jfc.setCurrentDirectory(dir); } } int retValue = jfc.showOpenDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if (f != null) { jLabel1.setText(f.getAbsolutePath()); file = f; } } else { if (log.isDebugEnabled()) { log.debug("No shp file selected."); } } dir = jfc.getCurrentDirectory(); path = dir.getAbsolutePath(); xmlConfig.setProperty("sudplan3D.working.dir", path); }
From source file:com.sciaps.utils.Util.java
public static ArrayList<SpectrumShotItem> readCSVFile() { ArrayList<SpectrumShotItem> shotItems = new ArrayList<SpectrumShotItem>(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("CSV files", "csv", "CSV")); int retrival = chooser.showOpenDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { ProgressStatusPanel progressbar = new ProgressStatusPanel(); final CustomDialog progressDialog = new CustomDialog(Constants.MAIN_FRAME, "Importing CSV file", progressbar, CustomDialog.NONE_OPTION); progressDialog.setSize(400, 100); SwingUtilities.invokeLater(new Runnable() { @Override//from w ww. ja v a 2s.c o m public void run() { progressDialog.setVisible(true); } }); try { FileReader fr = new FileReader(chooser.getSelectedFile()); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { shotItems.add(packSpectrumShotItem(line)); } br.close(); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Exception: " + ex.getMessage()); } progressDialog.dispose(); } return shotItems; }
From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java
@Override public void actionPerformed(final ActionEvent event) { super.actionPerformed(event); final String command = event.getActionCommand(); if ("SAVE_EMF".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EMF Image", "EMF"); chooser.setFileFilter(filter);//from w w w . j a va 2 s. c o m int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".emf")) file += ".emf"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EMF); new Thread(SI).start(); } } if ("SAVE_EPS".equals(command)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("EPS Image", "EPS"); chooser.setFileFilter(filter); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getPath(); if (!file.toLowerCase().endsWith(".eps")) file += ".eps"; int width = (int) this.getSize().getWidth(); int height = (int) this.getSize().getHeight(); // Save image SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EPS); new Thread(SI).start(); } } }
From source file:Simulator.java
private void init() { setSize(400, 400);/*from w ww . jav a 2 s . co m*/ treeMap = new JMapViewerTree("Zones"); // Listen to the map viewer for user operations so components will // receive events and update map().addJMVListener(this); setLayout(new BorderLayout()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); JPanel panel = new JPanel(new BorderLayout()); JPanel panelTop = new JPanel(); JPanel panelBottom = new JPanel(); JPanel helpPanel = new JPanel(); mperpLabelName = new JLabel("Meters/Pixels: "); mperpLabelValue = new JLabel(String.format("%s", map().getMeterPerPixel())); zoomLabel = new JLabel("Zoom: "); zoomValue = new JLabel(String.format("%s", map().getZoom())); add(panel, BorderLayout.NORTH); add(helpPanel, BorderLayout.SOUTH); panel.add(panelTop, BorderLayout.NORTH); panel.add(panelBottom, BorderLayout.SOUTH); JLabel helpLabel = new JLabel( "Use right mouse button to move,\n " + "left double click or mouse wheel to zoom."); helpPanel.add(helpLabel); JButton button = new JButton("Fit GPS Markers"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setDisplayToFitMapMarkers(); } }); panelBottom.add(button); JButton openButton = new JButton("Open GPS File"); openButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser openFileDlg = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text"); openFileDlg.setFileFilter(filter); if (openFileDlg.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File file = openFileDlg.getSelectedFile(); //This is where a real application would open the file. System.out.println("Opening: " + file.getAbsolutePath() + "."); plotPoints(file.getAbsolutePath()); } else { System.out.println("Open command cancelled by user."); } } }); panelBottom.add(openButton); final JCheckBox showMapMarker = new JCheckBox("Map markers visible"); showMapMarker.setSelected(map().getMapMarkersVisible()); showMapMarker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { map().setMapMarkerVisible(showMapMarker.isSelected()); } }); panelBottom.add(showMapMarker); panelTop.add(zoomLabel); panelTop.add(zoomValue); panelTop.add(mperpLabelName); panelTop.add(mperpLabelValue); add(treeMap, BorderLayout.CENTER); }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
private void save(int port, boolean followRedirecs, String outputFile, Set<ConfigInclusionExclusionRule> inclusions, Set<ConfigInclusionExclusionRule> exclusions, Set<ConfigInclusionExclusionRule> bodyInclusions, Set<ConfigInclusionExclusionRule> bodyExclusions, String configFileName) {/*from www. ja v a 2 s .c om*/ String fileName = ""; if (StringUtils.isEmpty(configFileName)) { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showSaveDialog = fileChooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getName(); if (!selectedFile.endsWith(".xml")) { selectedFile = selectedFile + ".xml"; } fileName = fileChooser.getSelectedFile().getParent() + "/" + selectedFile; configHandler.setConfigFile(fileName); } else { return; } } else { fileName = configFileName; } CommonsProxyConfiguration.save(port, followRedirecs, outputFile, inclusions, exclusions, bodyInclusions, bodyExclusions, fileName); getProxyConfigPanel().update(); configHandler.setConfigFile(fileName); }
From source file:ca.licef.lompad.Classification.java
public static File doImportFile(Component parent) { JFileChooser chooser = new JFileChooser(); if (Preferences.getInstance().getPrevClassifDir() != null) chooser.setCurrentDirectory(Preferences.getInstance().getPrevClassifDir()); int returnVal = chooser.showOpenDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { try {//from w w w .j a v a 2 s . co m Preferences.getInstance().setPrevClassifDir(chooser.getCurrentDirectory()); } catch (Exception e) { e.printStackTrace(); } try { File skosInputFile = chooser.getSelectedFile(); File tmpFile = null; String xml = IOUtil.readStringFromFile(chooser.getSelectedFile()); String rootTagName = XMLUtil.getRootTagName(xml); if (rootTagName != null) { String[] array = StringUtil.split(rootTagName, ':'); rootTagName = array[array.length - 1].toLowerCase(); } boolean isVdexFile = (rootTagName != null && "vdex".equals(rootTagName)); if (isVdexFile) { String xsltFile = "/xslt/convertVDEXToSKOS.xsl"; StreamSource xslt = new StreamSource(Util.class.getResourceAsStream(xsltFile)); StreamSource xmlSource = new StreamSource(new BufferedReader(new StringReader(xml))); Node skosNode = XMLUtil.applyXslToDocument2(xslt, xmlSource, null, null, null); tmpFile = File.createTempFile("lompad", "inputSkos"); Writer tmpFileWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(tmpFile, false), "UTF-8")); try { XMLUtil.serialize(skosNode, false, tmpFileWriter); } finally { if (tmpFileWriter != null) tmpFileWriter.close(); } skosInputFile = tmpFile; } Classification classif = new Classification(skosInputFile); classif.initModel(true); String uri = classif.getConceptSchemeUri(); if (uri == null) throw new Exception("ConceptScheme's URI not found."); String sha1 = DigestUtils.shaHex(uri); File localFile = new File(Util.getClassificationFolder(), sha1 + ".rdf"); classif.dumpModelToRdf(localFile); if (tmpFile != null) tmpFile.delete(); return (localFile); } catch (Exception e) { e.printStackTrace(); String msg = "classifImportFailed"; if ("Classification identifier not found.".equals(e.getMessage())) msg = "classifIdentifierNotFound"; JDialogAlert dialog = new JDialogAlert(Util.getTopJFrame((Container) parent), "titleErr", msg); dialog.setSize(320, 140); dialog.setVisible(true); return (null); } } else return (null); }
From source file:model.settings.ReadSettings.java
/** * checks whether program information on current workspace exist. * @return if workspace is now set.//from w ww. j av a2 s . c o m */ public static String install() { boolean installed = false; String wsLocation = ""; /* * does program root directory exist? */ if (new File(PROGRAM_LOCATION).exists()) { //try to read try { wsLocation = readFromFile(PROGRAM_SETTINGS_LOCATION); installed = new File(wsLocation).exists(); if (!installed) { wsLocation = ""; } } catch (FileNotFoundException e) { System.out.println("file not found " + e); showErrorMessage(); } catch (IOException e) { System.out.println("io" + e); showErrorMessage(); } } //if settings not found. if (!installed) { new File(PROGRAM_LOCATION).mkdir(); try { //create new file chooser JFileChooser jc = new JFileChooser(); //sets the text and language of all the components in JFileChooser UIManager.put("FileChooser.openDialogTitleText", "Open"); UIManager.put("FileChooser.lookInLabelText", "LookIn"); UIManager.put("FileChooser.openButtonText", "Open"); UIManager.put("FileChooser.cancelButtonText", "Cancel"); UIManager.put("FileChooser.fileNameLabelText", "FileName"); UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles"); UIManager.put("FileChooser.openButtonToolTipText", "OpenSelectedFile"); UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel"); UIManager.put("FileChooser.fileNameHeaderText", "FileName"); UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel"); UIManager.put("FileChooser.homeFolderToolTipText", "Desktop"); UIManager.put("FileChooser.newFolderToolTipText", "CreateNewFolder"); UIManager.put("FileChooser.listViewButtonToolTipText", "List"); UIManager.put("FileChooser.newFolderButtonText", "CreateNewFolder"); UIManager.put("FileChooser.renameFileButtonText", "RenameFile"); UIManager.put("FileChooser.deleteFileButtonText", "DeleteFile"); UIManager.put("FileChooser.filterLabelText", "TypeFiles"); UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details"); UIManager.put("FileChooser.fileSizeHeaderText", "Size"); UIManager.put("FileChooser.fileDateHeaderText", "DateModified"); SwingUtilities.updateComponentTreeUI(jc); jc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jc.setMultiSelectionEnabled(false); final String informationMsg = "Please select the workspace folder. \n" + "By default, the new files are saved in there. \n\n" + "Is changed simply by using the Save-As option.\n" + "If no folder is specified, the default worspace folder \n" + "is the home directory of the current user."; final int response = JOptionPane.showConfirmDialog(jc, informationMsg, "Select workspace folder", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); final String defaultSaveLocation = System.getProperty("user.home") + System.getProperty("file.separator"); File f; if (response != JOptionPane.NO_OPTION) { //fetch selected file f = jc.getSelectedFile(); jc.showDialog(null, "select"); } else { f = new File(defaultSaveLocation); } printInformation(); if (f == null) { f = new File(defaultSaveLocation); } //if file selected if (f != null) { //if the file exists if (f.exists()) { writeToFile(PROGRAM_SETTINGS_LOCATION, ID_PROGRAM_LOCATION + "\n" + f.getAbsolutePath()); } else { //open message dialog JOptionPane.showConfirmDialog(null, "Folder does " + "not exist", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } //recall install return install(); } } catch (IOException e) { System.out.println(e); JOptionPane.showConfirmDialog(null, "An exception occured." + " Try again later.", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } } if (System.getProperty("os.name").equals("Mac OS X")) { installOSX(); } else if (System.getProperty("os.name").equals("Linux")) { installLinux(); } else if (System.getProperty("os.name").equals("Windows")) { installWindows(); } return wsLocation; }
From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java
protected void exportSelectedRows() { final JFileChooser chooser = new JFileChooser(); for (final int row : this.table.getSelectedRows()) { final boolean cancel = this.exportDocument(chooser, row); if (cancel) { break; }/*from w ww .j a v a 2s . c o m*/ } this.refreshContents(); }
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
private boolean chooseDirectory(JTextField textField) { JFileChooser fileOpen = new JFileChooser(); fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileOpen.showOpenDialog(this); boolean directoryChoosed = false; if (fileOpen.getSelectedFile() != null) { File directory = new File(fileOpen.getSelectedFile().getAbsolutePath()); textField.setText(directory.getPath()); resultFiles = getFilesOnDirectory(directory); directoryChoosed = true;/*w w w.jav a 2 s.co m*/ } // Codigo para Mac OSX // FileDialog fileopen = new FileDialog(this, "Open Results Directory", FileDialog.LOAD); // fileopen.setModalityType(ModalityType.DOCUMENT_MODAL); // // System.setProperty("apple.awt.fileDialogForDirectories", "true"); // fileopen.setVisible(true); // System.setProperty("apple.awt.fileDialogForDirectories", "false"); // // if (fileopen.getFile() != null) { // File directory = new File(fileopen.getDirectory(), fileopen.getFile()); // textField.setText(directory.getPath()); // // resultFiles = getFilesOnDirectory(directory); // // List<File> foundFiles = ; // // for (File file : foundFiles) { // // if (file.getName().endsWith(".txt")) { // // resultFiles.add(file); // // } // // } // directoryChoosed = true; // } return directoryChoosed; }
From source file:edu.gcsc.vrl.jfreechart.JFExport.java
/** * Show dialog for exporting JFreechart object. *//*from w ww . java2 s. c o m*/ public void openExportDialog(JFreeChart jfreechart) { JFileChooser chooser = new JFileChooser(); String path0; File file; chooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Files", "pdf")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG Files", "jpg")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("PNG Files", "png")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("EPS Files", "eps")); chooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG Files", "svg")); chooser.setFileFilter(new FileNameExtensionFilter("PDF Files", "pdf")); int returnVal = chooser.showSaveDialog(null); String fd = chooser.getFileFilter().getDescription(); // Get selected FileFilter String filter_extension = null; if (fd.equals("PNG Files")) { filter_extension = "png"; } if (fd.equals("SVG Files")) { filter_extension = "svg"; } if (fd.equals("JPEG Files")) { filter_extension = "jpg"; } if (fd.equals("PDF Files")) { filter_extension = "pdf"; } if (fd.equals("EPS Files")) { filter_extension = "eps"; } // Cancel if (returnVal == JFileChooser.CANCEL_OPTION) { return; } // OK if (returnVal == JFileChooser.APPROVE_OPTION) { path0 = chooser.getSelectedFile().getAbsolutePath(); //System.out.println(path0); try { file = new File(path0); // Get extension (if any) String ext = JFUtils.getExtension(file); // No extension -> use selected Filter if (ext == null) { file = new File(path0 + "." + filter_extension); ext = filter_extension; } // File exists - overwrite ? if (file.exists()) { Object[] options = { "OK", "CANCEL" }; int answer = JOptionPane.showOptionDialog(null, "File exists - Overwrite ?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (answer != JOptionPane.YES_OPTION) { return; } //System.out.println(answer+""); } // Export file export(file, jfreechart); } catch (Exception f) { // I/O - Error } } }