List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser()
JFileChooser
pointing to the user's default directory. From source file:MessageDigestTest.java
/** * Loads a file and computes its message digest. *///from w ww . ja v a 2 s. c o m public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { try { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name)); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java
private void browseSelected() { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (userPreferences != null) { File currentDir = new File(userPreferences.get("currentDirectory", "")); if (currentDir.exists()) { chooser.setCurrentDirectory(currentDir); }/*from w ww .j a v a 2 s . c o m*/ } if (chooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { if (userPreferences != null) { userPreferences.put("currentDirectory", chooser.getCurrentDirectory().getPath()); } fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithChart.java
/** * Add two new menu items to the popup menu, for saving to TSV and CSV files *///w w w .ja va 2 s.c om protected void initPopupMenu() { addSeparatorToPopupMenu(); //TSV JMenuItem saveTSVMenuItem = new JMenuItem(TextProvider.getText("SAVE_DATA_AS_TSV")); saveTSVMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fc = new JFileChooser(); int chooserStatus = fc.showOpenDialog(PanelWithChart.this); //if user didn't hit OK, ignore if (chooserStatus != JFileChooser.APPROVE_OPTION) return; File outFile = fc.getSelectedFile(); saveChartDataToTSV(outFile); } }); addItemToPopupMenu(saveTSVMenuItem); //CSV JMenuItem saveCSVMenuItem = new JMenuItem(TextProvider.getText("SAVE_DATA_AS_CSV")); saveCSVMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser wfc = new JFileChooser(); int chooserStatus = wfc.showOpenDialog(PanelWithChart.this); //if user didn't hit OK, ignore if (chooserStatus != JFileChooser.APPROVE_OPTION) return; File outFile = wfc.getSelectedFile(); saveChartDataToCSV(outFile); } }); addItemToPopupMenu(saveCSVMenuItem); }
From source file:de.erdesignerng.visual.editor.openxavaexport.OpenXavaExportEditor.java
private void commandChooseSrcDirectory() { JFileChooser theChooser = new JFileChooser(); theChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (theChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File theBaseDirectory = theChooser.getSelectedFile(); editingView.getSrcDirectory().setText(theBaseDirectory.toString()); }/*w w w. j a v a2s. co m*/ }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java
/** * Private methods/*w ww . j a v a2 s. c o m*/ */ //init view private void initDataLoadingPanel() { dataLoadingPanel = new DRDataLoadingPanel(); /** * Action Listeners. */ //Popup file selector and import and parse the file dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment"); // to select only appropriate files fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } int index = f.getName().lastIndexOf("."); String extension = f.getName().substring(index + 1); return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv") || extension.equals("tsv"); } @Override public String getDescription() { return (".xls, .xlsx, .csv and .tsv files"); } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(dataLoadingPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = fileChooser.getSelectedFile(); // // create and execute a new swing worker with the selected file for the import // ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile); // importExperimentSwingWorker.execute(); parseDRFile(chosenFile); if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) { dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath()); doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true); } } else { JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } } }); dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { doseResponseController.setLogTransform(true); } else { doseResponseController.setLogTransform(false); } } }); }
From source file:ch.tatool.app.export.FileDataExporter.java
private String getStorageDirectory(Component parentFrame) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override//from www . ja va 2 s. co m public String getDescription() { return "CSV (*.csv)"; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String extension = getExtension(f); if (extension != null) { if (extension.equals("csv")) { return true; } else { return false; } } return false; } }); chooser.setAcceptAllFileFilterUsed(false); // chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); int returnVal = chooser.showSaveDialog(parentFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); String filename = ""; if (f == null) { throw new RuntimeException(); } String extension = getExtension(f); if (extension == null || !getExtension(f).equals("csv")) { filename = f + ".csv"; } else { filename = f.getPath(); } return filename; } else { return null; } }
From source file:com.nubits.nubot.launch.toolkit.LaunchUI.java
private JFileChooser createFileChoser() { JFileChooser fileChooser = new JFileChooser(); // Set the text of the button fileChooser.setApproveButtonText("Import"); // Set the tool tip fileChooser.setApproveButtonToolTipText("Import configuration file"); //Filter .json files FileFilter filter = new FileNameExtensionFilter(".json files", "json"); fileChooser.setFileFilter(filter);//from w w w. j a v a 2s .co m fileChooser.setCurrentDirectory(new File(local_path)); return fileChooser; }
From source file:presenter.MainPresenter.java
@Override public void loadMovementsequenceFromFile(ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showOpenDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); try {/* w ww. j a v a2 s. co m*/ this.movSeq = new Movementsequence(new Scanner(file).useDelimiter("\\A").next()); this.emissionsequenceModel = new EmissionsequenceModel(this.movSeq); this.displayStatus("File was read successfully!"); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java
/** Creates new form WelcomePanel */ public PanelRevocationData(String title, Frame container, ControllerPanelRevocationData cpatp) { this.title = title; initComponents();/*from w w w .ja va2s . c o m*/ checkEditableTextBox(textbox_rev_issuer); checkEditableTextBox(textbox_rev_reason); checkFormattedTextBoxIsEmpty(textbox_revoked_since_datetime); checkFormattedTextBoxIsEmpty(textbox_revoked_since_time); checkEditableTextBox(textbox_notification_email); checkEditableTextBox(textbox_revoked_aucap_issuer); checkFormattedTextBoxIsEmpty(textbox_revoked_aucap_issue_datetime); checkFormattedTextBoxIsEmpty(textbox_revoked_aucap_issue_time); checkEditableTextBox(textbox_revoked_aucap_id); checkEditableTextBox(textbox_revoked_aucap_version); myContainer = container; dialog_revoked_since_date = new DateChooserDialog("Starting revocation date", myContainer, true); dialog_revoked_since_date.setLocale(Locale.UK); dialog_revoked_aucap_issue_date = new DateChooserDialog("Revoked capability issue date", myContainer, true); dialog_revoked_aucap_issue_date.setLocale(Locale.UK); filterAssertion = new FilterXML("Access Rights Capability"); auCapTokenChooser = new JFileChooser(); auCapTokenChooser.setFileFilter(filterAssertion); auCapTokenChooser.setMultiSelectionEnabled(false); //init file chooser if (currentAuCapTokenPath == null) { auCapTokenChooser.setCurrentDirectory(new File(".")); } else { auCapTokenChooser.setCurrentDirectory(currentAuCapTokenPath); } }
From source file:my.grafos.Maquina.java
static void abrirGrafo() throws FileNotFoundException, IOException, ClassNotFoundException { /* FileInputStream fis = new FileInputStream("d:\\t.xml"); ObjectInputStream ois = new ObjectInputStream(fis); ArrayList<Aresta> leituraListaistaArestas = (ArrayList<Aresta>) ois.readObject(); ois.close();//from w w w . java 2 s . co m Fabrica.listaArestas = leituraListaistaArestas; */ a = 0; final JFileChooser fc = new JFileChooser(); //Handle open button action. int returnVal = fc.showOpenDialog(null); File file = fc.getSelectedFile(); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); //This is where a real application would open the file. System.out.println("Opening: " + file.getName() + "." + "\n"); } else { System.out.println("Open command cancelled by user." + "\n"); } StringBuilder arestaBuilder = new StringBuilder(); StringBuilder verticeBuilder = new StringBuilder(); String line; try { InputStream inputstream = new BufferedInputStream(new FileInputStream(file.getPath())); BufferedReader r = new BufferedReader(new InputStreamReader(inputstream)); while ((line = r.readLine()) != null && !line.contains("</list>")) { arestaBuilder.append(line); arestaBuilder.append("\n"); } arestaBuilder.append("</list>"); verticeBuilder.append("<list>\n"); while ((line = r.readLine()) != null) { verticeBuilder.append(line); verticeBuilder.append("\n"); } } catch (IOException e) { } Fabrica.xmlA = arestaBuilder.toString(); Fabrica.xmlV = verticeBuilder.toString(); Fabrica.listaArestas = (ArrayList<Aresta>) xstream.fromXML(xmlA); Fabrica.listaVertices = (ArrayList<Vertice>) xstream.fromXML(xmlV); }