List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
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 w ww. j a v a 2s .co m*/ 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.OpenFolderAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }//from w ww. j ava 2 s .c om int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); JFrame jf = new JFrame("Progress Bar"); Container Jcontent = jf.getContentPane(); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(0); progressBar.setStringPainted(true); Jcontent.add(progressBar, BorderLayout.NORTH); jf.setSize(300, 60); jf.setVisible(true); //we needed a new thread for a functional progress bar on the JFrame new Thread(new Runnable() { public void run() { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; FileFilter fileFilter = new WildcardFileFilter("*.docx"); File[] files = selectedFile.listFiles(fileFilter); double cnt = 0, cnt2 = 0; //number of how many .docx is in the folder for (File f : files) { if (!f.getAbsolutePath().contains("~")) cnt2++; } for (File f : files) { cnt++; pathToTxtFile = f.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); //---------------------------------------------------- String zipFilePath = "C:\\Users\\fja2\\Desktop\\junk\\Test\\test.zip"; String destDirectory = "C:\\Users\\fja2\\Desktop\\junk\\Test " + cnt; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(f, zip); unzipper.UnzipUtility(zip, directory); zip.delete(); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\PXT1\\Desktop\\test\\Pictures\\" + f.getName() + "\\" + fil.getName())); } 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 = f.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, f.getAbsolutePath(), version, (int) cnt); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } double tempProg = (cnt / cnt2) * 100; progressBar.setValue((int) tempProg); System.gc(); } } else { //do nothing } } }).start(); System.gc(); }
From source file:PeerPanel.java
private void saveLocationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveLocationButtonActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setCurrentDirectory(saveDirectory); jfc.setMultiSelectionEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { saveDirectory = jfc.getSelectedFile(); saveLocationDisplay.setText(saveDirectory.getAbsolutePath()); }/*from www . ja va2 s . c o m*/ }
From source file:it.unibo.alchemist.boundary.gui.Perspective.java
private void openFile() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);//from w w w. ja v a 2 s . c o m fc.setFileFilter(FILE_FILTER); fc.setCurrentDirectory(currentDirectory); final int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { fileToLoad = fc.getSelectedFile(); currentDirectory = fc.getSelectedFile().getParentFile(); if (fileToLoad.exists()) { status.setText(getString("ready_to_process") + " " + fileToLoad.getAbsolutePath()); status.setOK(); if (sim != null) { sim.addCommand(new Engine.StateCommand<T>().stop().build()); } bar.setFileOK(true); } else { status.setText(FILE_NOT_VALID + " " + fileToLoad.getAbsolutePath()); status.setNo(); bar.setFileOK(false); } } }
From source file:edu.synth.SynthHelper.java
public String openDialogFileChooser(String path, boolean dirOnly, String name, String button, String filterType) {/*from www . j a v a 2 s. c om*/ JFileChooser fileOpen = new JFileChooser(); if (!path.isEmpty()) fileOpen.setCurrentDirectory(new File(path)); else fileOpen.setCurrentDirectory(new File(".")); if (dirOnly) fileOpen.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); else { fileOpen.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); switch (filterType) { case "abn": FileFilter filter = new FileNameExtensionFilter("*.abn - Abundances file", "abn"); fileOpen.setFileFilter(filter); break; case "model": filter = new FileNameExtensionFilter("*.atl - Kurucz's format model file", "atl"); fileOpen.setFileFilter(filter); break; case "lns": filter = new FileNameExtensionFilter("*.lns - Lines file", "lns"); fileOpen.setFileFilter(filter); break; } } fileOpen.setDialogTitle(name); fileOpen.setApproveButtonText(button); int returnVal = fileOpen.showOpenDialog(fileOpen); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedPath = fileOpen.getSelectedFile(); if (selectedPath != null) return selectedPath.getAbsolutePath(); } return ""; }
From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java
private void exportPressed() { File chosenFile = null;/* w w w . j a va 2s . c o m*/ FileWriter fw = null; String title; if (cert != null) { title = res.getString("DViewCertCsrPem.ExportPemCertificate.Title"); } else { title = res.getString("DViewCertCsrPem.ExportPemCsr.Title"); } try { String certPem = jtaPem.getText(); JFileChooser chooser = FileChooserFactory.getX509FileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DViewCertCsrPem.ChooseExportFile.button")); if (rtnValue != JFileChooser.APPROVE_OPTION) { return; } chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); if (chosenFile.isFile()) { String message = MessageFormat.format(res.getString("DViewCertCsrPem.OverWriteFile.message"), chosenFile); int selected = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION); if (selected != JOptionPane.YES_OPTION) { return; } } fw = new FileWriter(chosenFile); fw.write(certPem); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DViewCertCsrPem.NoWriteFile.message"), chosenFile), title, JOptionPane.WARNING_MESSAGE); return; } catch (Exception ex) { DError.displayError(this, ex); return; } finally { IOUtils.closeQuietly(fw); } JOptionPane.showMessageDialog(this, res.getString("DViewCertCsrPem.ExportPemCertificateSuccessful.message"), title, JOptionPane.INFORMATION_MESSAGE); }
From source file:net.lldp.checksims.ui.results.ScrollViewer.java
/** * Create a scroll viewer from a sortable Matrix Viewer * @param results the sortableMatrix to view * @param toRevalidate frame to revalidate sometimes */// www . j av a 2 s. c om public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) { resultsView = new JScrollPane(results); setBackground(Color.black); resultsView.addComponentListener(new ComponentListener() { @Override public void componentHidden(ComponentEvent arg0) { } @Override public void componentMoved(ComponentEvent arg0) { } @Override public void componentResized(ComponentEvent ce) { Dimension size = ce.getComponent().getSize(); results.padToSize(size); } @Override public void componentShown(ComponentEvent arg0) { } }); resultsView.getViewport().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Rectangle r = resultsView.getViewport().getViewRect(); results.setViewAt(r); } }); resultsView.setBackground(Color.black); sidebar = new JPanel(); setPreferredSize(new Dimension(900, 631)); setMinimumSize(new Dimension(900, 631)); sidebar.setPreferredSize(new Dimension(200, 631)); sidebar.setMaximumSize(new Dimension(200, 3000)); resultsView.setMinimumSize(new Dimension(700, 631)); resultsView.setPreferredSize(new Dimension(700, 631)); sidebar.setBackground(Color.GRAY); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); this.add(sidebar); this.add(resultsView); resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); resultsView.getVerticalScrollBar().setUnitIncrement(16); resultsView.getHorizontalScrollBar().setUnitIncrement(16); Integer[] presetThresholds = { 80, 60, 40, 20, 0 }; JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds); threshHold.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { Integer item = (Integer) event.getItem(); results.updateThreshold(item / 100.0); toRevalidate.revalidate(); toRevalidate.repaint(); } } }); threshHold.setSelectedIndex(0); results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0); JTextField student1 = new JTextField(15); JTextField student2 = new JTextField(15); KeyListener search = new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { results.highlightMatching(student1.getText(), student2.getText()); toRevalidate.revalidate(); toRevalidate.repaint(); } @Override public void keyTyped(KeyEvent e) { } }; student1.addKeyListener(search); student2.addKeyListener(search); Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance() .getSupportedImplementations(); JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet)); JButton exportAsSave = new JButton("Save"); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle("Save results"); exportAsSave.addActionListener(ae -> { MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem(); int err = fc.showDialog(toRevalidate, "Save"); if (err == JFileChooser.APPROVE_OPTION) { try { FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix)); } catch (InternalAlgorithmError | IOException e1) { // TODO log / show error } } }); JPanel thresholdLabel = new JPanel(); JPanel studentSearchLabel = new JPanel(); JPanel fileOutputLabel = new JPanel(); thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold")); studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search")); fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results")); thresholdLabel.add(threshHold); studentSearchLabel.add(student1); studentSearchLabel.add(student2); fileOutputLabel.add(exportAs); fileOutputLabel.add(exportAsSave); studentSearchLabel.setPreferredSize(new Dimension(200, 100)); studentSearchLabel.setMinimumSize(new Dimension(200, 100)); thresholdLabel.setPreferredSize(new Dimension(200, 100)); thresholdLabel.setMinimumSize(new Dimension(200, 100)); fileOutputLabel.setPreferredSize(new Dimension(200, 100)); fileOutputLabel.setMinimumSize(new Dimension(200, 100)); sidebar.setMaximumSize(new Dimension(200, 4000)); sidebar.add(thresholdLabel); sidebar.add(studentSearchLabel); sidebar.add(fileOutputLabel); }
From source file:com.sec.ose.osi.ui.frm.main.manage.FileBrowser.java
public void actionPerformed(ActionEvent e) { JFCFolderExplorer explorer = JFCFolderExplorer.getInstance(); JFileChooser chooser = explorer.getJFileChooser(); String sFileLoc = getFileLocation(); if ((sFileLoc == null) || (sFileLoc.length() == 0)) { chooser.setCurrentDirectory(new java.io.File(sDefaultPath)); } else {// www. j a va2s. co m chooser.setCurrentDirectory(new java.io.File(sFileLoc)); } int result = explorer.showBrowser(frmOwner); String path = ""; if (result == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); if (projectInfo != null) projectInfo.setSourcePath(path); setFileLocation(path); if (projectModel != null) projectModel.forceRefreshTable(); } if (sFileLoc == null || !sFileLoc.equals(path)) { log.debug("}}}}}}BEFORE{{{{{{ project status will change ---> " + projectInfo.getProjectName() + " : " + IdentifiedController.getProjectStatus(projectInfo.getProjectName()) + " : " + projectInfo.isSourcePathChange()); projectInfo.setSourcePathChange(true); projectInfo.setAnalyzeTarget(true); projectModel.setProjectAnalysisStatus(projectInfo.getProjectName(), ProjectAnalysisInfo.STATUS_READY); IdentifiedController.setProjectStatus(projectInfo.getProjectName(), AnalysisMonitorThread.STATUS_READY); log.debug("}}}}}}AFTER{{{{{{ project status changed ---> " + projectInfo.getProjectName() + " : " + IdentifiedController.getProjectStatus(projectInfo.getProjectName()) + " : " + projectInfo.isSourcePathChange()); } else { projectInfo.setSourcePathChange(false); } }
From source file:it.isislab.dmason.util.SystemManagement.Worker.WorkerUpdater.java
public File showFileChooser() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(FTP_HOME)); int n = fileChooser.showOpenDialog(WorkerUpdater.this); if (n == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); } else//from ww w.j a v a 2 s .c o m return null; }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private JFileChooser createFileChoser() { JFileChooser fileChooser = new JFileChooser(); // Set the text of the button fileChooser.setApproveButtonText("Import"); // Set the tool tip fileChooser.setApproveButtonToolTipText("Import configuration file"); //Filter .json files FileFilter filter = new FileNameExtensionFilter(".json files", "json"); fileChooser.setFileFilter(filter);// w w w. j a v a 2 s .co m fileChooser.setCurrentDirectory(new File(local_path)); return fileChooser; }