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:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java
/** * Browse button action perform function for jcardSimFilePath. * * @param e ActionEvent object//from ww w . jav a 2s . co m */ private void browseButton3ActionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setCurrentDirectory(new File("/home")); int result = jFileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = jFileChooser.getSelectedFile(); jcardSimFilePath = selectedFile.getPath(); simOutputPathTextField.setText(""); simOutputPathTextField.setText(jcardSimFilePath); log.debug("Selected file: " + jcardSimFilePath); } else if (!simOutputPathTextField.getText().equals("")) { log.debug("Selected file: " + jcardSimFilePath); } else { JOptionPane.showMessageDialog(this.mainFrame, "Please suggest where the similarity output file path is not selected", "file is not selected", JOptionPane.ERROR_MESSAGE); } }
From source file:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java
/** * Load button's actionPerformed function to load the list of words to find nearest words * against all the words in the list loaded. * * @param e ActionEvent object/*from w w w. j av a 2 s.c om*/ */ private void loadListButtonActionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setCurrentDirectory(new File("/home")); int result = jFileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = jFileChooser.getSelectedFile(); listOfwordsFilePath = selectedFile.getPath(); File f = new File(listOfwordsFilePath); try { if (f.exists()) { BufferedReader br = new BufferedReader(new FileReader(listOfwordsFilePath)); String line; List<String> lines = new ArrayList<String>(); DefaultListModel model = new DefaultListModel(); while ((line = br.readLine()) != null) { // process the line. lines.add(line); model.addElement(line); log.debug(line); } wordList.setModel(model); wordList.updateUI(); } else { log.debug("Creating file, wordOfList doesn't exist"); } } catch (IOException e1) { log.debug("creating/loading file exception"); e1.printStackTrace(); } log.debug("Selected file: " + listOfwordsFilePath); } else { JOptionPane.showMessageDialog(this.mainFrame, "Please suggest where the listOfWords.txt text file is", "file is not selected", JOptionPane.ERROR_MESSAGE); } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Exports the results to a file/* w w w.j a v a2s. c o m*/ * * @param model * The model for the current results * @param fileType * The export file type */ private void chooseFileForSave(TableModel model, int fileType) { final JFileChooser chooser = new JFileChooser(); int returnVal; chooser.setDialogTitle(Resources.getString("dlgSaveDataTitle")); chooser.setApproveButtonText(Resources.getString("dlgSaveDataButton")); chooser.setApproveButtonMnemonic(Resources.getChar("dlgSaveDataButtonMnemonic")); if (latestFileDirectory != null) { if (latestFileDirectory.isDirectory()) { chooser.setCurrentDirectory(latestFileDirectory); } else if (latestFileDirectory.getParentFile().isDirectory()) { chooser.setCurrentDirectory(latestFileDirectory.getParentFile()); } } returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { latestFileDirectory = chooser.getSelectedFile().getParentFile(); switch (fileType) { case FILE_EXPORT_CSV: saveResultAsCSV(model, chooser.getSelectedFile().getAbsoluteFile()); break; case FILE_EXPORT_TRIPLES: saveResultsAsTriples(model, chooser.getSelectedFile().getAbsoluteFile()); break; default: throw new IllegalArgumentException("Unknown file type mode for export: " + fileType); } } }
From source file:view.CertificateManagementDialog.java
private void loadCustomKeystore() { JFileChooser jfc = new JFileChooser(); File path;/*from w w w. j a va 2s . c o m*/ if (lastOpened == null) { path = new File(System.getProperty("user.home")); } else { if (lastOpened.exists()) { path = lastOpened; } else { path = new File(System.getProperty("user.home")); } } jfc.setCurrentDirectory(path); boolean validKeystore = false; while (!validKeystore) { int ret = jfc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { lastOpened = jfc.getSelectedFile(); KeyStore ks = isValidKeystore(lastOpened, true); if (ks != null) { validKeystore = true; refresh(ks); } } else if (ret == JFileChooser.CANCEL_OPTION) { break; } } if (validKeystore) { tfCustomKeystore.setText(lastOpened.getAbsolutePath()); } }
From source file:view.MainWindow.java
private void menuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemOpenActionPerformed JFileChooser jfc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.pdfDocuments") + " (*.pdf)", "pdf"); File path;//from w ww . j a va 2s.c o m if (lastOpenedFilePath == null) { path = new File(System.getProperty("user.home")); } else { path = lastOpenedFilePath; } jfc.setCurrentDirectory(path); jfc.setFileFilter(filter); int ret = jfc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); try { if (loadPdf(file, true)) { lastOpenedFilePath = file; } } catch (Exception e) { controller.Logger.getLogger().addEntry(e); } } }
From source file:view.WorkspacePanel.java
private void signDocument(Document document, boolean ocsp, boolean timestamp) { try {//from w ww . j a v a 2 s.c om if (tempCCAlias.getMainCertificate().getPublicKey().equals( CCInstance.getInstance().loadKeyStoreAndAliases().get(0).getMainCertificate().getPublicKey())) { try { String path1 = document.getDocumentLocation(); String path2 = null; if (path1.endsWith(".pdf")) { path2 = path1.substring(0, path1.length() - 4).concat("(aCCinado).pdf"); } JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("btn.saveAs")); if (null != path2) { boolean validPath = false; FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.pdfDocuments") + " (*.pdf)", "pdf"); fileChooser.setFileFilter(pdfFilter); File preferedFile = new File(path2); fileChooser.setCurrentDirectory(preferedFile); fileChooser.setSelectedFile(preferedFile); while (!validPath) { int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.CANCEL_OPTION) { return; } if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); if (new File(dest).exists()) { String msg = Bundle.getBundle().getString("msg.fileExists"); Object[] options = { Bundle.getBundle().getString("opt.replace"), Bundle.getBundle().getString("opt.chooseNewPath"), Bundle.getBundle().getString("btn.cancel") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { validPath = true; } else if (opt == JOptionPane.CANCEL_OPTION) { return; } } else { validPath = true; } signatureSettings.setOcspClient(ocsp); signatureSettings.setTimestamp(timestamp); if (validPath) { if (!CCInstance.getInstance().signPdf(document.getDocumentLocation(), dest, signatureSettings, null)) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("unknownErrorLog"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); return; } status = Status.READY; ArrayList<File> list = new ArrayList<>(); list.add(new File(document.getDocumentLocation())); int tempPage = imagePanel.getPageNumber(); mainWindow.closeDocuments(list, false); mainWindow.loadPdf(new File(dest), false); hideRightPanel(); imagePanel.setPageNumber(tempPage); JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("label.signatureOk"), "", JOptionPane.INFORMATION_MESSAGE); break; } } } } return; } catch (IOException ex) { if (ex instanceof FileNotFoundException) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.keystoreFileNotFound"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); } else if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("outputFileError"))) { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.failedCreateOutputFile"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); signDocument(document, ocsp, timestamp); } else { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("unknownErrorLog"), Bundle.getBundle().getString("label.signatureFailed"), JOptionPane.ERROR_MESSAGE); controller.Logger.getLogger().addEntry(ex); } } catch (DocumentException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | HeadlessException | CertificateException | KeyStoreException ex) { controller.Logger.getLogger().addEntry(ex); } catch (SignatureFailedException ex) { if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("timestampFailed"))) { String msg = Bundle.getBundle().getString("msg.timestampFailedNoInternet"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { signDocument(document, false, false); } } else { controller.Logger.getLogger().addEntry(ex); } } return; } else { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); } } catch (LibraryNotLoadedException | KeyStoreNotLoadedException | CertificateException | KeyStoreException | LibraryNotFoundException | AliasException ex) { controller.Logger.getLogger().addEntry(ex); } JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); }
From source file:view.WorkspacePanel.java
public void signBatch(CCSignatureSettings settings) { ArrayList<File> toSignList = mainWindow.getOpenedFiles(); try {//w ww.j a va 2 s.c om if (tempCCAlias.getMainCertificate().getPublicKey().equals( CCInstance.getInstance().loadKeyStoreAndAliases().get(0).getMainCertificate().getPublicKey())) { String dest = null; Object[] options = { Bundle.getBundle().getString("opt.saveInOriginalFolder"), Bundle.getBundle().getString("msg.choosePath"), Bundle.getBundle().getString("btn.cancel") }; int i = JOptionPane.showOptionDialog(null, Bundle.getBundle().getString("msg.chooseSignedPath"), "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (i == 1) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(Bundle.getBundle().getString("btn.choosePath")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { dest = chooser.getSelectedFile().getAbsolutePath(); } else { return; } } else if (i == 2) { return; } MultipleSignDialog msd = new MultipleSignDialog(mainWindow, true, toSignList, settings, dest); msd.setLocationRelativeTo(null); msd.setVisible(true); ArrayList<File> signedDocsList = msd.getSignedDocsList(); if (!signedDocsList.isEmpty()) { removeTempSignature(); clearSignatureFields(); hideRightPanel(); status = Status.READY; mainWindow.closeDocuments(mainWindow.getOpenedFiles(), false); for (File f : signedDocsList) { mainWindow.loadPdf(f, false); } } return; } else { JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); } } catch (LibraryNotLoadedException | KeyStoreNotLoadedException | CertificateException | KeyStoreException | LibraryNotFoundException | AliasException ex) { controller.Logger.getLogger().addEntry(ex); } JOptionPane.showMessageDialog(mainWindow, Bundle.getBundle().getString("msg.smartcardRemovedOrChanged"), WordUtils.capitalize(Bundle.getBundle().getString("error")), JOptionPane.ERROR_MESSAGE); }
From source file:view.WorkspacePanel.java
private void btnAddBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddBackgroundActionPerformed if (tempSignature.getImageLocation() == null) { JFileChooser jfc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.imageFiles"), "png", "jpg"); File path = new File(System.getProperty("user.home")); jfc.setCurrentDirectory(path); jfc.setFileFilter(filter);//from ww w . j a v a2s. c o m int ret = jfc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { String file = jfc.getSelectedFile().getAbsolutePath(); try { tempSignature.setImageLocation(file); btnAddBackground.setText(Bundle.getBundle().getString("btn.removeBackgroud")); } catch (Exception e) { controller.Logger.getLogger().addEntry(e); } } } else { tempSignature.setImageLocation(null); btnAddBackground.setText(Bundle.getBundle().getString("btn.addBackgroud")); } tempSignature.repaint(); }
From source file:xmv.solutions.commons.ExcelFile.java
/** * Open a filechooser that finds ExcelFiles * * @param startPath starting with path startPath * @return FilePath//ww w. ja v a 2 s.co m */ public static ExcelFile openFileChooser(String startPath) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(startPath)); // Remove all FileFilters FileFilter[] filters = fc.getChoosableFileFilters(); for (int i = 0; i < filters.length; i++) { fc.removeChoosableFileFilter(filters[i]); } fc.addChoosableFileFilter(new ExcelFileFilter()); // In response to a button click: int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getAbsolutePath(); return new ExcelFile(path); } return null; }
From source file:zsk.JFCMainClient.java
/** * process events of ActionListener//from ww w .ja va2s. c o m * */ public void actionPerformed(final ActionEvent e) { if (e.getSource().equals(frame.textinputfield)) { if (!e.getActionCommand().equals("")) { if (e.getActionCommand().matches(szYTREGEX)) addYTURLToList(e.getActionCommand()); else { addTextToConsole(e.getActionCommand()); cli(e.getActionCommand().toLowerCase()); } } synchronized (frame.textinputfield) { frame.textinputfield.setText(""); } return; } // let the user choose another dir if (e.getSource().equals(frame.directorybutton)) { debugoutput("frame.directorybutton"); JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); synchronized (frame.directorytextfield) { // we have to set current directory here because it gets lost when fc is lost fc.setCurrentDirectory(new File(frame.directorytextfield.getText())); } debugoutput("current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { return; } String snewdirectory = fc.getSelectedFile().getAbsolutePath(); // append file.seperator if last character is not file.seperator (the user choosed a directory other than root) snewdirectory.concat(snewdirectory.endsWith(System.getProperty("file.separator")) ? "" : System.getProperty("file.separator")); File ftest = new File(snewdirectory); if (ftest.exists()) { if (ftest.isDirectory()) { synchronized (frame.directorytextfield) { frame.directorytextfield.setText(snewdirectory); } config.setProperty("savefolder", snewdirectory); debugoutput("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); output("new current dir: ".concat(fc.getCurrentDirectory().getAbsolutePath())); } else { output("not a directory: ".concat(snewdirectory)); } } else { output("directory does not exist: ".concat(snewdirectory)); } return; } // let the user choose another download resolution if (e.getActionCommand().equals(JFCMainClient.frame.hdbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.stdbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.ldbutton.getActionCommand())) { debugoutput("trying: ".concat(e.getActionCommand())); output("trying: ".concat(e.getActionCommand().toUpperCase())); return; } // let the user choose another video format if (e.getActionCommand().equals(JFCMainClient.frame.mpgbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.flvbutton.getActionCommand()) || e.getActionCommand().equals(JFCMainClient.frame.webmbutton.getActionCommand())) { debugoutput("trying: ".concat(e.getActionCommand())); output("trying: ".concat(e.getActionCommand().toUpperCase() .concat(" ".concat(isgerman() ? "(Dateien werden immer nach MIME-Typ benannt!)" : "(files will always be named according to MIME type!)")))); return; } if (e.getActionCommand().equals("quit")) { addTextToConsole(isgerman() ? "Programmende ausgewhlt - beende DownloadThreads, Vorgang kann eine Weile dauern!" : "quit requested - signaling donwload threads to terminate, this may take a while!"); // seems to have to effect: //JFCMainClient.frame.repaint(); JFCMainClient.shutdownAppl(); return; } debugoutput("unknown action. ".concat(e.getSource().toString())); output("unbekannte Aktion"); }