List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:net.pandoragames.far.ui.swing.menu.FileMenu.java
private void init(final Localizer localizer, final ComponentRepository componentRepository) { // Import//from w ww. ja v a 2 s .c o m JMenuItem importMenu = new JMenuItem(localizer.localize("label.import")); importMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(config.getFileListExportDirectory()); fileChooser.setDialogTitle(localizer.localize("label.select-import-file")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fileChooser.showOpenDialog(FileMenu.this); if (returnVal == JFileChooser.APPROVE_OPTION) { Runnable fileImporter = new ImportAction(fileChooser.getSelectedFile(), localizer, componentRepository.getOperationCallBackListener(), config.isWindows()); Thread thread = new Thread(fileImporter); thread.setDaemon(true); thread.start(); } } }); this.add(importMenu); // Export export = new JMenuItem(localizer.localize("label.export")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportFileListDialog dialog = new ExportFileListDialog(mainFrame, tableModel, config); dialog.pack(); dialog.setVisible(true); } }); this.add(export); // seperator this.addSeparator(); // Edit edit = new JMenuItem(localizer.localize("label.edit")); edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileEditor editor = new FileEditor(mainFrame, tableModel.getSelectedRows().get(0), config); editor.pack(); editor.setVisible(true); } }); this.add(edit); // View JMenuItem view = new JMenuItem(viewAction); this.add(view); // Preview JMenuItem preview = new JMenuItem(previewAction); this.add(preview); // Info info = new JMenuItem(localizer.localize("label.info")); info.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { InfoView infoView = new InfoView(mainFrame, tableModel.getSelectedRows().get(0), config, repository); infoView.pack(); infoView.setVisible(true); } }); this.add(info); // seperator this.addSeparator(); // copy copy = new JMenuItem(localizer.localize("menu.copy")); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.copyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(copy); // tree copy treeCopy = new JMenuItem(localizer.localize("menu.treeCopy")); treeCopy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.treeCopyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(treeCopy); // move move = new JMenuItem(localizer.localize("menu.move")); move.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.moveDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(move); // delete delete = new JMenuItem(localizer.localize("menu.delete")); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.deleteDialog(tableModel, findForm.getBaseDirectory(), errorSink, config, mainFrame); } }); this.add(delete); // rename rename = new JMenuItem(localizer.localize("menu.rename-dialog")); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowIndex = tableModel.getRowIndex(tableModel.getSelectedRows().get(0)); FileOperationDialog.renameDialog(rowIndex, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(rename); }
From source file:gov.nij.er.ui.EntityResolutionDemo.java
private void loadParameters() { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new SerializedParameterFileFilter()); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {/*from w w w . jav a 2 s. c o m*/ loadParameters(file); } catch (Exception e) { e.printStackTrace(); } } }
From source file:gui.InboxPanel.java
private void openDecryptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDecryptButtonActionPerformed // TODO add your handling code here: JFileChooser chooser = new JFileChooser(); int retrieval = chooser.showOpenDialog(null); if (retrieval == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); Path path = Paths.get(file.getAbsolutePath()); try {// w w w. ja v a 2 s.c o m key = Files.readAllBytes(path); keyDecryptTextField.setText(key.toString()); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Choose the directory and load its data into a given JTree. * * @param dataTree// w ww .ja v a 2 s . c om */ private void chooseDirectoryAndLoadData() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Please select a root folder containing your files"); // allow for directories only fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // removing "All Files" option from FileType fileChooser.setAcceptAllFileFilterUsed(false); int returnVal = fileChooser.showOpenDialog(cellCoordController.getCellCoordFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { // the directory for the data directory = fileChooser.getSelectedFile(); try { loadDataIntoTree(); } catch (LoadDirectoryException ex) { LOG.error(ex.getMessage()); cellCoordController.showMessage(ex.getMessage(), "wrong directory structure error", JOptionPane.ERROR_MESSAGE); } } else { cellCoordController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:com.stanley.captioner.MainFrame.java
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed {//GEN-HEADEREND:event_addButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg"); fileChooser.setFileFilter(filter);/*from w w w . j ava 2s .c o m*/ if (lastAddDirectory != null) { fileChooser.setCurrentDirectory(lastAddDirectory); } int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastAddDirectory = fileChooser.getCurrentDirectory(); DefaultTableModel model = (DefaultTableModel) videoTable.getModel(); File files[] = fileChooser.getSelectedFiles(); for (File file : files) { boolean alreadyExists = false; for (int i = model.getRowCount() - 1; i >= 0; i--) { String path = (String) model.getValueAt(i, 0); if (file.getAbsolutePath().equals(path)) { alreadyExists = true; } } if (!alreadyExists) { model.addRow(getVideoInfo(file)); } } } }
From source file:com.josue.tileset.editor.Editor.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("Image file", "png")); fileDialog.showOpenDialog(null); inputFile = fileDialog.getSelectedFile(); if (inputFile != null) { loadFile(inputFile);//from ww w .j a v a 2s .com } }
From source file:VentanaPrincipal.java
private void descargarFichero() throws IOException { String directorio = lblRuta.getText(); cliente.changeWorkingDirectory(directorio); JFileChooser chooser = new JFileChooser(); cliente.enterLocalPassiveMode();//from w ww.j av a 2s . c o m cliente.setFileType(FTP.BINARY_FILE_TYPE); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(chooser.getSelectedFile().getAbsolutePath() + "/" + listFicheros .getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-")))); if (cliente.retrieveFile( listFicheros.getSelectedItem().substring(0, listFicheros.getSelectedItem().lastIndexOf("-")), out)) lblMens.setText("Descargado correctamente "); else lblMens.setText("No se ha podido descargar"); out.close(); } }
From source file:datavis.Gui.java
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed //The action to select a file //By opening a pop-up containing a file browser javax.swing.JFileChooser choose = new javax.swing.JFileChooser(); choose.showOpenDialog(null); File f = choose.getSelectedFile(); String fileHandle = f.getAbsolutePath(); System.out.println(fileHandle); // jComboBox1.removeAllItems(); // jComboBox2.removeAllItems(); // jComboBox3.removeAllItems(); try {/*from w w w. ja va 2s . co m*/ dataset = new DataList_PWL_SURGE_ATP_WTP_WSD_BPR(fileHandle); } catch (UnsupportedEncodingException ex) { JOptionPane.showMessageDialog(null, "The data file you selected is not supported."); return; } //Set the text of the button to the file handle absolute pathname button1.setLabel(fileHandle); //update all graphs updateGraphs_pieChart(dataset, true); updateGraphs_barGraph(dataset, true); updateGraphs_lineGraph(dataset, true); //get the drop down menu items from the dataset class String sampleTypes[] = dataset.getDropMenu(); //fill the node text area with all the node information jTextArea1.setText(dataset.toString()); jTextArea1.setCaretPosition(0); //fill the status text area with station and developer info jTextArea2.setText(dataset.getStationInfo() + displayDevelopers); jTextArea2.setCaretPosition(0); //clear the combobox for (int i = 0; i < jComboBox1.getItemCount(); i++) { jComboBox1.remove(i); jComboBox2.remove(i); jComboBox3.remove(i); } //Add each sample type to the drop-down combobox for (int i = 0; i < sampleTypes.length; i++) { jComboBox1.addItem(sampleTypes[i]); jComboBox2.addItem(sampleTypes[i]); jComboBox3.addItem(sampleTypes[i]); } }
From source file:gui.InboxPanel.java
private void openVerifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVerifyButtonActionPerformed JFileChooser chooser = new JFileChooser(); int retrieval = chooser.showOpenDialog(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Public file", "pub"); chooser.setFileFilter(filter);/*from www . j ava 2s. c o m*/ if (retrieval == JFileChooser.APPROVE_OPTION) { FileInputStream fis = null; try { File file = chooser.getSelectedFile(); Path path = Paths.get(file.getAbsolutePath()); fis = new FileInputStream(file); //Construct BufferedReader from InputStreamReader BufferedReader br = new BufferedReader(new InputStreamReader(fis)); try { String x = br.readLine(); String y = br.readLine(); publickey = new BigPoint(new BigInteger(x), new BigInteger(y)); System.out.println("Public key : " + publickey.getX() + publickey.getY()); br.close(); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fis.close(); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:MyFormApp.java
private void AddbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddbuttonMouseClicked // TODO add your handling code here: //? ?/*from www . j av a2 s. c om*/ JFileChooser fileChooser = new JFileChooser(); //? fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("PDF Documents", "pdf"));//?pdf fileChooser.setAcceptAllFileFilterUsed(false); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) {//???? File selectedFile = fileChooser.getSelectedFile(); try { pdfToimage(selectedFile); //??? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(selectedFile.getName()); //?? File source = new File("" + selectedFile); File dest = new File(PATH + selectedFile.getName()); //copy file conventional way using Stream long start = System.nanoTime(); //copy files using apache commons io start = System.nanoTime(); int a = i + 1; String imagename = FilenameUtils.removeExtension(selectedFile.getName()); model.addElement(new Book(selectedFile.getName(), "" + a, imagename, PATH)); //list i = i + 1; jList2.setModel(model); jList2.setCellRenderer(new BookRenderer()); try { copyFileUsingApacheCommonsIO(source, dest); //? } catch (IOException ex) { Logger.getLogger(MyFormApp.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Time taken by Apache Commons IO Copy = " + (System.nanoTime() - start)); } }