List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createSaveButton() { JButton save = new JButton("Save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PersistentLayout pl = (PersistentLayout) vv.getGraphLayout(); try { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new LayoutFileFilter()); int result = chooser.showSaveDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".layout")) { absolutePath += ".layout"; }// w w w . j ava2s .com pl.persist(absolutePath); } } catch (IOException e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error saving layout: " + e1.getMessage()); } } }); return save; }
From source file:io.heming.accountbook.ui.MainFrame.java
private void importRecords() { final JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.addChoosableFileFilter(new AbbFileFilter()); chooser.setAcceptAllFileFilterUsed(false); int value = chooser.showOpenDialog(this); if (value == JFileChooser.APPROVE_OPTION) { // ?//from w w w.j av a2 s . c om disableAllControls(); new Thread() { @Override public void run() { try { statusLabel.setIcon(new ImageIcon(getClass().getResource("loader.gif"))); setStatusText("?..."); FacadeUtil.shutdown(); File file = chooser.getSelectedFile(); setStatusText("??..."); FileUtils.cleanDirectory(new File(Constants.DATA_DIR)); setStatusText("??..."); ZIPUtil.decompress(file, new File(Constants.HOME_DIR)); setStatusText("?..."); FacadeUtil.restart(); // ?? setStatusText("????..."); categories = categoryFacade.listBySale(); // ???? setStatusText("?..."); searchRecords(); enableAllControls(); setStatusText(""); statusLabel.setIcon(new ImageIcon(getClass().getResource("stopped-loader.png"))); JOptionPane.showMessageDialog(MainFrame.this, "???", "?", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(MainFrame.this, e.getMessage(), "", JOptionPane.ERROR_MESSAGE); } } }.start(); } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createLoadButton() { JButton load = new JButton("Load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PersistentLayout pl = (PersistentLayout) vv.getGraphLayout(); try { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new LayoutFileFilter()); int result = chooser.showOpenDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".layout")) { absolutePath += ".layout"; }/* w w w . ja v a 2 s . c om*/ pl.restore(absolutePath); vv.repaint(); } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error restoring layout: " + e1.getMessage()); } } }); return load; }
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void cmdDatadirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDatadirActionPerformed try {//w ww. j a va 2 s . com JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("Eligir ubicacin de la base de datos."); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { txtDatadir.setText(chooser.getSelectedFile().getPath()); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:lejos.pc.charting.LogChartFrame.java
private void selectFolderButton_actionPerformed(ActionEvent e) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser jfc = new JFileChooser(new File(FQPathTextArea.getText(), "")); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Select"); jfc.setDialogTitle("Select Directory"); jfc.setDialogType(JFileChooser.OPEN_DIALOG); this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); int returnVal = jfc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { FQPathTextArea.setText(getCanonicalName(jfc.getSelectedFile())); jfc.setCurrentDirectory(jfc.getSelectedFile()); System.out.println("folder set to \"" + getCanonicalName(jfc.getSelectedFile()) + "\""); }//from w ww .j a va 2s . c o m }
From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java
protected JFileChooser initFileChooser() { ExtensionFileFilter filter = new ExtensionFileFilter("log,txt", true, true); filter.setDescription("?"); JFileChooser jfc = new JFileChooser(); FileSystemView fsv = FileSystemView.getFileSystemView(); //?/* w w w . j av a 2s . co m*/ jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setDialogTitle("?"); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);//JFileChooser.FILES_AND_DIRECTORIES jfc.setFileFilter(filter); return jfc; }
From source file:base.BasePlayer.AddGenome.java
static void downloadGenome(String urls) { try {/*from w w w.j ava 2 s .c o m*/ URL fastafile = AddGenome.genomeHash.get(urls)[0]; String targetDir = ""; //boolean writable = true; File test = new File(Main.genomeDir.getCanonicalPath() + "/test"); //File f = new File(Main.genomeDir.getCanonicalPath()); if (test.mkdir()) { /*if(fastafile.getFile().contains("GRCh38")) { if((test.getFreeSpace()/1048576) < (60000000000L/1048576)) { Main.showError("Sorry, you need more than 60GB of disk space to install GRCh38.\nGRCh38 FASTA file size is ~50GB uncompressed.\nThis drive has " +test.getFreeSpace()/1048576/1000 +"GB.", "Note"); test.delete(); return; } } else*/ if ((test.getFreeSpace() / 1048576) < (5000000000L / 1048576)) { Main.showError("Sorry, you need more than 5GB of disk space.\nThis drive has " + test.getFreeSpace() / 1048576 / 1000 + "GB.", "Note"); test.delete(); return; } test.delete(); targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/"; File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile())); URL gfffile = AddGenome.genomeHash.get(urls)[1]; targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/" + FilenameUtils.getName(gfffile.getFile()) + "/"; File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile())); AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls); genomeadd.createGenome = true; genomeadd.execute(); } else { try { JFileChooser chooser = new JFileChooser(); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select a local directory for genome files..."); File outfile = null; while (true) { int returnVal = chooser.showSaveDialog((Component) AddGenome.panel); if (returnVal == JFileChooser.APPROVE_OPTION) { outfile = chooser.getSelectedFile(); File genomedir = new File(outfile.getCanonicalPath() + "/genomes"); if (new File(outfile.getCanonicalPath() + "/genomes").mkdir()) { if (fastafile.getFile().contains("GRCh38")) { if ((outfile.getFreeSpace() / 1048576) < (200000000000L / 1048576)) { Main.showError( "Please, select local drive with more than 60GB of disk space.\nGRCh38 FASTA file is ~50GB uncompressed.\nThis drive has " + outfile.getFreeSpace() / 1048576 / 1000 + "GB.", "Note"); genomedir.delete(); continue; } } else if ((outfile.getFreeSpace() / 1048576) < (5000000000L / 1048576)) { Main.showError( "Please, select local drive with more than 5GB of disk space.\nThis drive has " + outfile.getFreeSpace() / 1048576 / 1000 + "GB.", "Note"); genomedir.delete(); continue; } } else { Main.showError( "No writing permissions for this directory. \nPlease, select new directory for genomes.", "Error"); continue; } /*if (!new File(outfile.getCanonicalPath() +"/genomes").mkdir()) { Main.showError("Could not create genome directory in " +outfile.getCanonicalPath(), "Error"); continue; }*/ break; } if (returnVal == JFileChooser.CANCEL_OPTION) { outfile = null; downloading = false; break; } } if (outfile != null) { Main.genomeDir = new File(outfile.getCanonicalPath() + "/genomes"); genomedirectory.setText(Main.genomeDir.getCanonicalPath()); Main.writeToConfig("genomeDir=" + Main.genomeDir.getCanonicalPath()); targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/"; File fasta = new File(targetDir + FilenameUtils.getName(fastafile.getFile())); URL gfffile = AddGenome.genomeHash.get(urls)[1]; targetDir = Main.genomeDir.getCanonicalPath() + "/" + urls + "/annotation/" + FilenameUtils.getName(gfffile.getFile()) + "/"; File gff = new File(targetDir + FilenameUtils.getName(gfffile.getFile())); AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls); genomeadd.createGenome = true; genomeadd.execute(); } downloading = false; /* new File(outfile.getCanonicalPath() +"/genomes").mkdir(); File fasta = new File(targetDir +FilenameUtils.getName(fastafile.getFile())); URL gfffile= AddGenome.genomeHash.get(urls)[1]; targetDir = AddGenome.userDir +"/genomes/" +urls +"/annotation/" +FilenameUtils.getName(gfffile.getFile()) +"/"; File gff = new File(targetDir +FilenameUtils.getName(gfffile.getFile())); AddGenome.OutputRunner genomeadd = new AddGenome.OutputRunner(urls, fasta, gff, urls); genomeadd.createGenome = true; genomeadd.execute(); */ } catch (Exception ex) { downloading = false; ex.printStackTrace(); } } } catch (Exception e) { downloading = false; e.printStackTrace(); } }
From source file:ca.osmcanada.osvuploadr.JPMain.java
private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed try {/*w w w.java 2 s . c om*/ JFileChooser fc = new JFileChooser(); if (!last_dir.isEmpty()) { fc.setCurrentDirectory(new java.io.File(last_dir)); // start at application current directory } fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { if (fc.getSelectedFiles().length == 1) { int response = JOptionPane.showConfirmDialog(null, new String(r.getString("immediate_sub_folders").getBytes(), "UTF-8"), new String(r.getString("add_subfolders").getBytes(), "UTF-8"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { File folder = fc.getSelectedFile(); listDir.add(folder.getPath()); last_dir = folder.getPath(); } else if (response == JOptionPane.YES_OPTION) { //Get a list of subdirectories String[] subDirs = fc.getSelectedFile().list(new FilenameFilter() { @Override public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); for (String subDir : subDirs) { listDir.add(new File(fc.getSelectedFile() + "/" + subDir).getPath()); } } } else if (fc.getSelectedFiles().length > 1) { File[] folders = fc.getSelectedFiles(); for (File folder : folders) { listDir.add(folder.getPath()); last_dir = folder.getPath(); } } } } catch (UnsupportedEncodingException ex) { } }
From source file:com.nbt.TreeFrame.java
protected JFileChooser createFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileHidingEnabled(false);/*from w w w.ja va 2 s .c om*/ fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); String description = "named binary tag"; FileFilter filter = new FileNameExtensionFilter(description, "mcr", "dat", "dat_old"); fc.setFileFilter(filter); Preferences prefs = getPreferences(); String exportFile = prefs.get(KEY_FILE, null); if (exportFile == null) { File cwd = new File("."); fc.setCurrentDirectory(cwd); } else { File selectedFile = new File(exportFile); fc.setSelectedFile(selectedFile); } return fc; }
From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java
private Set getFiles() { JFileChooser chooser = new JFileChooser(DODDLEConstants.PROJECT_HOME); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int retval = chooser.showOpenDialog(DODDLE_OWL.rootPane); if (retval != JFileChooser.APPROVE_OPTION) { return null; }// w w w .ja va2s .co m File[] files = chooser.getSelectedFiles(); Set fileSet = new TreeSet(); getFiles(files, fileSet); return fileSet; }