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.CertificatePropertiesDialog.java
private void export(X509Certificate x509c) { try {//from ww w. j av a 2s . c o 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.CreateNewPresentation.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Vedio files", "avi", "mov", "3gp", "mp4", "mpg"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { filePath = chooser.getSelectedFile().getPath(); if (FilenameUtils.getExtension(filePath).equals("avi") || FilenameUtils.getExtension(filePath).equals("mov") || FilenameUtils.getExtension(filePath).equals("3gp") || FilenameUtils.getExtension(filePath).equals("mp4") || FilenameUtils.getExtension(filePath).equals("txt")) { fileName = chooser.getSelectedFile().getName(); BufferedImage img = null; size = (chooser.getSelectedFile().length()) / 1024; ok_button.setEnabled(true);/* ww w .j a v a2 s . c o m*/ newFileName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(fileName); File newFile = new File(Configuration.presentationFolder + newFileName); try { FileUtils.copyFile(chooser.getSelectedFile(), newFile); } catch (Exception e) { System.out.println(e); } } else { JOptionPane.showMessageDialog(rootPane, "Please choose a vedio presentation"); return; } } }
From source file:view.CreateOrganization.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getPath(); System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName()); BufferedImage img = null; try {//from w w w.j av a 2s. c om img = ImageIO.read(new File(path)); Image scaledInstance = img.getScaledInstance(jLabel7.getWidth(), jLabel7.getHeight(), Image.SCALE_SMOOTH); ImageIcon imageIcon = new ImageIcon(scaledInstance); jLabel7.setIcon(imageIcon); organisationIconName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(path); FileUtils.copyFile(chooser.getSelectedFile(), new File(Configuration.organisationImages + organisationIconName)); } catch (IOException e) { e.printStackTrace(); } size = (chooser.getSelectedFile().length()) / 1024; System.out.println("path " + path + " size " + size); } }
From source file:View.EmbedFile.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getPath(); jLabel2.setText(chooser.getSelectedFile().getName()); String masterKeyBackUpName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(chooser.getSelectedFile().getPath()); String masterKeyBackUpLocation = Configuration.masterPoolLocation + masterKeyBackUpName; masterFileName = masterKeyBackUpName; try {/*from w w w . j ava 2s. c om*/ FileUtils.copyFile(chooser.getSelectedFile(), new File(masterKeyBackUpLocation)); } catch (Exception e) { e.printStackTrace(); } System.out.println("You chose to open this file: " + path); BufferedImage img = null; try { img = ImageIO.read(new File(path)); Image scaledInstance = img.getScaledInstance(jLabel2.getWidth(), jLabel2.getHeight(), Image.SCALE_SMOOTH); ImageIcon imageIcon = new ImageIcon(scaledInstance); jLabel2.setIcon(imageIcon); analyze_master_file_button.setEnabled(true); } catch (IOException e) { e.printStackTrace(); } long size = (chooser.getSelectedFile().length()) / 1024; Dbcon dbcon = new Dbcon(); int ins = dbcon.insert( "insert into tbl_encryption_log(user_id,master_file,master_file_size,encryption_type)values('" + Login.logged_in_user_id + "','" + path + "','" + size + "',1)"); if (ins > 0) { ResultSet rs = dbcon.select("select max(process_id) from tbl_encryption_log"); try { if (rs.next()) { System.out.println(rs.getString(1)); EmbedFile.process_id = Integer.parseInt(rs.getString(1)); System.out.println(EmbedFile.process_id); } } catch (SQLException ex) { ex.printStackTrace(); } } } }
From source file:View.EmbedMessage.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getPath(); try {/*from www .j av a 2 s . c o m*/ String masterKeyBackUpName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(chooser.getSelectedFile().getPath()); String masterKeyBackUpLocation = Configuration.masterPoolLocation + masterKeyBackUpName; masterFileName = masterKeyBackUpName; FileUtils.copyFile(chooser.getSelectedFile(), new File(masterKeyBackUpLocation)); image_name.setText(chooser.getSelectedFile().getName()); System.out.println("You chose to open this file: " + path); BufferedImage img = null; try { img = ImageIO.read(new File(path)); Image scaledInstance = img.getScaledInstance(image_Label.getWidth(), image_Label.getHeight(), Image.SCALE_SMOOTH); ImageIcon imageIcon = new ImageIcon(scaledInstance); image_Label.setIcon(imageIcon); } catch (IOException e) { e.printStackTrace(); } long size = (chooser.getSelectedFile().length()) / 1024; Dbcon dbcon = new Dbcon(); int ins = dbcon .insert("insert into tbl_encryption_log(user_id,master_file,master_file_size)values('" + Login.logged_in_user_id + "','" + masterKeyBackUpName + "','" + size + "')"); if (ins > 0) { ResultSet rs = dbcon.select("select max(process_id) from tbl_encryption_log"); try { if (rs.next()) { System.out.println(rs.getString(1)); EmbedMessage.process_id = Integer.parseInt(rs.getString(1)); System.out.println(EmbedMessage.process_id); analyze_button.setEnabled(true); } } catch (SQLException ex) { ex.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:View.Home.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Vedio files", "avi", "mov", "3gp", "mp4", "mpg"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { coverFile = chooser.getSelectedFile(); path = chooser.getSelectedFile().getPath(); if (FilenameUtils.getExtension(path).equals("avi") || FilenameUtils.getExtension(path).equals("mov") || FilenameUtils.getExtension(path).equals("3gp") || FilenameUtils.getExtension(path).equals("mp4") || FilenameUtils.getExtension(path).equals("mpg")) { } else {//from ww w . j a v a2 s .c o m JOptionPane.showMessageDialog(rootPane, "Please choose a video file"); return; } jLabel10.setText(chooser.getSelectedFile().getName()); name = chooser.getSelectedFile().getName(); System.out.println("You chose to open this file: " + path); size = (chooser.getSelectedFile().length()) / 1024; jLabel8.setVisible(true); file_name_label.setVisible(true); file_size_label.setVisible(true); jLabel24.setVisible(true); file_format_text.setVisible(true); jLabel25.setVisible(true); next_button.setEnabled(true); file_name_label.setText(name); file_size_label.setText(size + " Kb"); file_format_text.setText(FilenameUtils.getExtension(path)); try { Configuration.setDefaultFileIcon(chooser.getSelectedFile(), jLabel10); } catch (Exception e) { e.printStackTrace(); } } }
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 ww w .j a va 2s.co 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.ManageOrganization.java
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { chooser.getSelectedFile().getPath(); System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName()); BufferedImage img = null; try {//from w ww . ja v a 2s . c o m img = ImageIO.read(new File(chooser.getSelectedFile().getPath())); Image scaledInstance = img.getScaledInstance(organisation_logo_label.getWidth(), organisation_logo_label.getHeight(), Image.SCALE_SMOOTH); ImageIcon imageIcon = new ImageIcon(scaledInstance); organisation_logo_label.setIcon(imageIcon); organisationIconName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(chooser.getSelectedFile().getPath()); FileUtils.copyFile(chooser.getSelectedFile(), new File(Configuration.organisationImages + organisationIconName)); } catch (IOException e) { e.printStackTrace(); } long size = (chooser.getSelectedFile().length()) / 1024; } }
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 w w. ja v a2 s.c o m 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.VideoPublisherGUI.java
/** * Initialize the contents of the frame. *//*from w w w . j a v a2 s .c om*/ private void initialize() { frmBlackvidPubsubber = new JFrame(); frmBlackvidPubsubber.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // unpublish everything videoPublisher.cleanup(); // then disconnect... client.disconnect(); } }); frmBlackvidPubsubber.setTitle("BlackVid Publisher"); frmBlackvidPubsubber.setBounds(100, 100, 450, 300); frmBlackvidPubsubber.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmBlackvidPubsubber.getContentPane().setLayout(new BorderLayout(0, 0)); final JPanel panel = new JPanel(); frmBlackvidPubsubber.getContentPane().add(panel, BorderLayout.SOUTH); panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton publishButton = new JButton("publish video"); publishButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // Open file dialog JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Video Files", "mov", "mpg", "mkv", "mp4", "avi", "mpeg"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(frmBlackvidPubsubber); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out .println("You chose to open this file: " + chooser.getSelectedFile().getAbsolutePath()); } try { // publish the event. Under root for now... String newPubIDString = rootGenerator.getNextID(chooser.getSelectedFile().getAbsolutePath(), IDStrategy.RANDOM); videoPublisher.publishVideo(newPubIDString, chooser.getSelectedFile().getAbsolutePath()); populatePublishList(); } catch (DecoderException e) { // Report the failed event. JOptionPane.showConfirmDialog(panel, "Could Not Publish the Video..."); e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); panel.add(publishButton); JButton unpublishButton = new JButton("unpublish"); unpublishButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // unpublish a video. // check something has been selected String selected = getList().getSelectedItem(); if (selected != null) { // get the rid String rid = ridMappings.get(selected); //unpublish by rid ByteIdentifier vidID; try { videoPublisher.unpublishVideo(rid); } catch (DecoderException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } populatePublishList(); } } }); JButton btnPublishStream = new JButton("publish stream"); btnPublishStream.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String httpStr = JOptionPane.showInputDialog("Please enter URL of media stream."); System.out.println(httpStr); try { // publish the event. Under root for now... String newPubIDString = rootGenerator.getNextID(httpStr, IDStrategy.RANDOM); videoPublisher.publishVideo(newPubIDString, httpStr); populatePublishList(); } catch (DecoderException e2) { // Report the failed event. JOptionPane.showConfirmDialog(panel, "Could Not Publish the Media..."); e2.printStackTrace(); } catch (NoSuchAlgorithmException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } catch (UnsupportedEncodingException e4) { // TODO Auto-generated catch block e4.printStackTrace(); } } }); panel.add(btnPublishStream); panel.add(unpublishButton); list = new List(); frmBlackvidPubsubber.getContentPane().add(list, BorderLayout.CENTER); JPanel panel_1 = new JPanel(); frmBlackvidPubsubber.getContentPane().add(panel_1, BorderLayout.NORTH); panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); }