List of usage examples for javax.swing JFileChooser setDialogTitle
@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle)
JFileChooser
window's title bar. From source file:verdandi.ui.ProjectViewerPanel.java
private void importProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get("import.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setDialogTitle(RB.getString("projectviewer.import.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;//from ww w . j a va 2s. co m } File importFile = chooser.getSelectedFile(); prefs.put("import.dir", importFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } ObjectInputStream projectsIn = null; try { setCursor(CURSOR_WAIT); projectsIn = new ObjectInputStream(new FileInputStream(importFile)); Object o = projectsIn.readObject(); if (!(o instanceof Collection)) { LOG.error("The file does not contain a valid verdandi project list"); return; } Collection<?> importcoll = (Collection<?>) o; @SuppressWarnings("unchecked") List<CostUnit> projects = (List<CostUnit>) o; new ProjectImporter(projects).start(); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("No verdandi project list?", e); } catch (ClassNotFoundException e) { LOG.error("", e); } finally { setCursor(CURSOR_DEFAULT); if (projectsIn != null) { try { projectsIn.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } }
From source file:verdandi.ui.ProjectViewerPanel.java
private void exportProjects() { Preferences prefs = Preferences.userNodeForPackage(getClass()); File exportDir = new File(prefs.get("export.dir", System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(exportDir); chooser.setDialogTitle(RB.getString("projectviewer.export.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return;//w ww. j av a 2 s.co m } int[] selectedProjects = projectTable.getSelectedRows(); if (selectedProjects.length == 0) { LOG.debug("NO row selected"); return; } List<CostUnit> projectsToExport = new ArrayList<CostUnit>(); for (int i = 0; i < selectedProjects.length; i++) { // int selModel = projectTable.getFilters().convertRowIndexToModel( // selectedProjects[i]); int selModel = selectedProjects[i]; CostUnit p = tableModel.getProject(selModel); LOG.debug("Adding project to export list: " + p); projectsToExport.add(p); } File exportFile = chooser.getSelectedFile(); LOG.debug("Exporting projects to " + exportFile.getAbsolutePath()); ObjectOutputStream listOut = null; try { listOut = new ObjectOutputStream(new FileOutputStream(exportFile)); listOut.writeObject(projectsToExport); } catch (FileNotFoundException e) { LOG.error("", e); } catch (IOException e) { LOG.error("", e); } finally { if (listOut != null) { try { listOut.close(); } catch (Throwable t) { LOG.error("Cannot close stream: ", t); } } } prefs.put("export.dir", exportFile.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } }
From source file:view.CertificatePropertiesDialog.java
private void export(X509Certificate x509c) { try {// w ww. jav a 2 s. co m JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("title.saveAs")); FileNameExtensionFilter cerFilter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.certificateFiles") + " (*.cer)", "cer"); fileChooser.setFileFilter(cerFilter); File preferedFile = new File(getCertificateCN(x509c) + ".cer"); fileChooser.setSelectedFile(preferedFile); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); File file = new File(dest); byte[] buf = x509c.getEncoded(); FileOutputStream os = new FileOutputStream(file); os.write(buf); os.close(); Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write(new sun.misc.BASE64Encoder().encode(buf)); JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certSuccessfullyExported"), "", JOptionPane.INFORMATION_MESSAGE); } } catch (CertificateEncodingException ex) { JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certExportFailed") + "\n" + Bundle.getBundle().getString("certInvalidEncoding"), "", JOptionPane.ERROR_MESSAGE); //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certExportFailed") + "\n" + Bundle.getBundle().getString("noWritePermissions"), "", JOptionPane.ERROR_MESSAGE); //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex); export(x509c); } catch (IOException ex) { JOptionPane.showMessageDialog(this, Bundle.getBundle().getString("certExportFailed") + "\n" + Bundle.getBundle().getString("errorCreatingOutputFile"), "", JOptionPane.ERROR_MESSAGE); //Logger.getLogger(CertificatePropertiesDialog.class.getName()).log(Level.SEVERE, null, ex); export(x509c); } }
From source file:view.MultipleValidationDialog.java
private void writeToFile(String str) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(Bundle.getBundle().getString("title.saveAs")); boolean validPath = false; FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter( Bundle.getBundle().getString("filter.textFiles") + " (*.txt)", "txt"); fileChooser.setFileFilter(pdfFilter); File preferedFile = new File(Bundle.getBundle().getString("validationReport") + ".txt"); fileChooser.setSelectedFile(preferedFile); while (!validPath) { int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.CANCEL_OPTION) { return; }//from w ww .ja va 2 s. c om if (userSelection == JFileChooser.APPROVE_OPTION) { String dest = fileChooser.getSelectedFile().getAbsolutePath(); if (new File(dest).exists()) { String msg = Bundle.getBundle().getString("msg.reportFileNameAlreadyExists"); Object[] options = { Bundle.getBundle().getString("btn.overwrite"), Bundle.getBundle().getString("btn.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; } if (validPath) { try (PrintStream out = new PrintStream(new FileOutputStream(dest))) { out.print(str); JOptionPane.showMessageDialog(null, Bundle.getBundle().getString("msg.reportSavedSuccessfully"), "", JOptionPane.INFORMATION_MESSAGE); } catch (FileNotFoundException ex) { controller.Logger.getLogger().addEntry(ex); JOptionPane.showMessageDialog(null, Bundle.getBundle().getString("msg.reportSaveFailed"), "", JOptionPane.ERROR_MESSAGE); } break; } } } }
From source file:view.ViewFiltrar.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed JFileChooser chooserDiretorio = new JFileChooser(ViewPrincipal.ROOTWOKSPACE); chooserDiretorio.setFileFilter(filter); chooserDiretorio.setDialogTitle("Escolha o arquivo que deseja importar."); resultado = chooserDiretorio.showOpenDialog(getParent()); if (resultado == JFileChooser.APPROVE_OPTION) { File selectedFile = chooserDiretorio.getSelectedFile(); jTextFieldInputFile.setText(selectedFile.getName()); String fileNameWithOutExt = FilenameUtils.removeExtension(selectedFile.getName()); jTextFieldOutputFile//w ww . j av a 2s .c o m .setText(fileNameWithOutExt + "_trimmed." + FilenameUtils.getExtension(selectedFile.getName())); } else if (resultado == JFileChooser.CANCEL_OPTION) System.out.println("Cancelado."); }
From source file:view.ViewFiltrar.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed JFileChooser chooserDiretorio = new JFileChooser(ViewPrincipal.ROOTWOKSPACE); chooserDiretorio.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooserDiretorio.setDialogTitle("Escolha o diretrio de saida."); resultado = chooserDiretorio.showOpenDialog(getParent()); if (resultado == JFileChooser.APPROVE_OPTION) { String path = chooserDiretorio.getSelectedFile().getPath(); jTextFieldOutputDirectory.setText(path); } else if (resultado == JFileChooser.CANCEL_OPTION) System.out.println("Cancelado."); }
From source file:view.ViewFiltrar.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed JFileChooser chooserDiretorio = new JFileChooser(ViewPrincipal.ROOTWOKSPACE); chooserDiretorio.setFileFilter(filter); chooserDiretorio.setDialogTitle("Escolha o arquivo que deseja importar."); resultado = chooserDiretorio.showOpenDialog(getParent()); if (resultado == JFileChooser.APPROVE_OPTION) { File selectedFile = chooserDiretorio.getSelectedFile(); jTextFieldInputFileFiltragem.setText(selectedFile.getName()); String fileNameWithOutExt = FilenameUtils.removeExtension(selectedFile.getName()); jTextField4.setText(/* ww w . j a v a2s .c o m*/ fileNameWithOutExt + "_filtered." + FilenameUtils.getExtension(selectedFile.getName())); } else if (resultado == JFileChooser.CANCEL_OPTION) System.out.println("Cancelado."); }
From source file:view.ViewFiltrar.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed JFileChooser chooserDiretorio = new JFileChooser(ViewPrincipal.ROOTWOKSPACE); chooserDiretorio.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooserDiretorio.setDialogTitle("Escolha o diretrio de saida."); resultado = chooserDiretorio.showOpenDialog(getParent()); if (resultado == JFileChooser.APPROVE_OPTION) { String path = chooserDiretorio.getSelectedFile().getPath(); jTextFieldOutputDiretorioFiltragem.setText(path); } else if (resultado == JFileChooser.CANCEL_OPTION) System.out.println("Cancelado."); }
From source file:view.WorkspacePanel.java
private void signDocument(Document document, boolean ocsp, boolean timestamp) { try {//from w ww .j a v a2 s. c o m 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 {/*from w ww . j a va 2 s .c o m*/ 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); }