/** Call this to browse for a custom gradle executor. */ private void browseForCustomGradleExecutor() { File startingDirectory = new File(SystemProperties.getInstance().getUserHome()); File currentFile = gradlePluginLord.getCustomGradleExecutor(); if (currentFile != null) { startingDirectory = currentFile.getAbsoluteFile(); } else { if (gradlePluginLord.getCurrentDirectory() != null) { startingDirectory = gradlePluginLord.getCurrentDirectory(); } } JFileChooser chooser = new JFileChooser(startingDirectory); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); File file = null; if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (file != null) { setCustomGradleExecutor(file); } else { // if they canceled, and they have no custom gradle executor specified, then we must // clear things // This will reset the UI back to 'not using a custom executor'. We can't have them check the // field and not have a value here. if (gradlePluginLord.getCustomGradleExecutor() == null) { setCustomGradleExecutor(null); } } }
private void jMenuItemImportActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemImportActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); // now select the file if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { // add code here to allow selection of a document class DocumentClassDialog d = DocumentClassDialog.showClassDialog(this, this.theProject); DocumentClass selectedClass = d.getSelectedDocumentClass(); File[] selected = jfc.getSelectedFiles(); for (int i = 0; i < selected.length; i++) { theProject.addNewDocument(selected[i], 1.0f, selected[i].toString(), selectedClass); } docFrameTableModel.fireTableDataChanged(); lastPath = new File(jfc.getSelectedFile().getPath()); } } // GEN-LAST:event_jMenuItemImportActionPerformed
/** * Display a file chooser dialog box. * * @param owner <code>Component</code> which 'owns' the dialog * @param mode Can be either <code>OPEN</code>, <code>SCRIPT</code> or <code>SAVE</code> * @return The path to selected file, null otherwise */ public static String chooseFile(Component owner, int mode) { JFileChooser chooser = getFileChooser(owner, mode); chooser.setMultiSelectionEnabled(false); if (chooser.showDialog(owner, null) == JFileChooser.APPROVE_OPTION) { /*Jext*/ AbstractEditorPanel.setProperty( "lastdir." + mode, chooser.getSelectedFile().getParent()); return chooser.getSelectedFile().getAbsolutePath(); } else owner.repaint(); return null; }
/** Browses for a file using the text value from the text field as the current value. */ private File browseForDirectory(File initialFile) { if (initialFile == null) { initialFile = SystemProperties.getInstance().getCurrentDir(); } JFileChooser chooser = new JFileChooser(initialFile); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); File file = null; if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } return file; }
private void jButtonWorkingDirectoryBrowseActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); String workDir = jTextWorkingDirectory.getText(); if (workDir.equals("")) { workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); } chooser.setSelectedFile(new File(workDir)); chooser.setDialogTitle( NbBundle.getMessage( CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { // NOI18N File file = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextWorkingDirectory.setText(file.getAbsolutePath()); } } // GEN-LAST:event_jButtonWorkingDirectoryBrowseActionPerformed
private ObjectOutputStream getObjectOutputStream() { File f = new File("."); String loadDirectory = f.getAbsolutePath(); JFileChooser chooser = new JFileChooser(loadDirectory); chooser.setDialogTitle("Save Generation File As..."); chooser.setMultiSelectionEnabled(false); int result = chooser.showSaveDialog(this); File selectedFile = chooser.getSelectedFile(); if (result == JFileChooser.APPROVE_OPTION) { try { FileOutputStream fileStream = new FileOutputStream(selectedFile.getPath()); ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); return objectStream; } catch (IOException e) { System.err.println(e); } } return null; }
public static void addToPlaylist() { if (logger.isDebugEnabled()) logger.debug("Add to playlist (methode without parameters)."); JFileChooser choixFichier = new JFileChooser(); choixFichier.setFileSelectionMode(JFileChooser.FILES_ONLY); choixFichier.setMultiSelectionEnabled(true); }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }