List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
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 w w. jav a 2 s . 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 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(//from www. j av a 2 s . c o m fileNameWithOutExt + "_filtered." + FilenameUtils.getExtension(selectedFile.getName())); } 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 ww w.j a v a 2 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
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);//from w w w . j a v a 2 s . c o m jfc.setFileFilter(filter); 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:vista.promocion.DiagPromocion.java
private void importar() { JFileChooser jChooser = new JFileChooser(System.getProperty("user.dir")); FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos Excel", "xls"); jChooser.setFileFilter(filter); jChooser.showOpenDialog(this); File file = jChooser.getSelectedFile(); if (file == null || !file.getName().endsWith("xls")) { JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error", JOptionPane.ERROR_MESSAGE); } else {// w ww. j a v a 2 s. com leerDatosExcel(file); List<Integer> columnasNoEditables = new ArrayList<>(); columnasNoEditables.add(0); columnasNoEditables.add(1); columnasNoEditables.add(2); ModeloTablaNoEditable model = new ModeloTablaNoEditable(data, headers, columnasNoEditables); tbArticulos.setModel(model); } }