Java Code Examples for javax.swing.JFileChooser#setSelectedFile()

The following examples show how to use javax.swing.JFileChooser#setSelectedFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
private void changeFile(String id) {
	DownloadEntry ent = XDMApp.getInstance().getEntry(id);
	if (ent == null)
		return;
	if (ent.getState() == XDMConstants.FINISHED) {
		return;
	}
	JFileChooser jfc = new JFileChooser();
	jfc.setSelectedFile(
			new File(XDMApp.getInstance().getOutputFolder(id), XDMApp.getInstance().getOutputFile(id, false)));
	if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
		File f = jfc.getSelectedFile();
		ent.setFolder(f.getParent());
		ent.setFile(f.getName());
		XDMApp.getInstance().fileNameChanged(id);
	}
}
 
Example 2
Source File: AddServerLocationVisualPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JFileChooser getJFileChooser() {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
    chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
    chooser.setMultiSelectionEnabled(false);
    chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N

    chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N

    // set the current directory
    chooser.setSelectedFile(new File(locationTextField.getText().trim()));

    return chooser;
}
 
Example 3
Source File: ProjectProblemsProviders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
@NonNull
@NbBundle.Messages({
    "LBL_BrokenLinksCustomizer_Resolve_File=Browse \"{0}\""
})
public Future<ProjectProblemsProvider.Result> resolve() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setDialogTitle(LBL_BrokenLinksCustomizer_Resolve_File(getDisplayId(type, id)));
    if (lastSelectedFile != null) {
        chooser.setSelectedFile(lastSelectedFile);
    }
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        updateReference(chooser.getSelectedFile());
        lastSelectedFile = chooser.getSelectedFile();
        resolved = ProjectProblemsProvider.Status.RESOLVED;
    }
    return new Done(ProjectProblemsProvider.Result.create(resolved));
}
 
Example 4
Source File: MainINSECTForm.java    From Ngram-Graphs with Apache License 2.0 6 votes vote down vote up
private void DataDirEdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DataDirEdActionPerformed
    // Select a dir
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory((DataDirEd.getText().length() == 0) ? new java.io.File(".") : new java.io.File(DataDirEd.getText()));
    fc.setSelectedFile(fc.getCurrentDirectory());
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int iRet = fc.showOpenDialog(this);
    if (iRet == JFileChooser.APPROVE_OPTION)
    {
        DataDirEd.setText(fc.getSelectedFile().getAbsolutePath());
        
        // Get categories from disk
        INSECTFileDB fdData= new INSECTFileDB("", DataDirEd.getText());
        Iterator iIter = Arrays.asList(fdData.getObjectList(INSECTMemoryDB.CATEGORY_TYPE)).iterator();
        while (iIter.hasNext()) {
            String sObjectName = (String)iIter.next();
            DataRepository.saveObject((NamedDocumentNGramGraph)fdData.loadObject(sObjectName,
                    INSECTMemoryDB.CATEGORY_TYPE), sObjectName, INSECTMemoryDB.CATEGORY_TYPE);
        }
        // Inform Categorizer
        CategoryDecider.setRepository(DataRepository);
        
        UpdateCategoriesByUIValues();
    }
}
 
Example 5
Source File: RemoteRepository.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void onBrowse() {
    String path = settingsPanel.txtIdentityFile.getText();
    if (path.isEmpty()) {
        path = getDefaultIdentityFilePath();
    }
    File file = new File(path);
    JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Descritpion"), //NOI18N
            path.isEmpty() ? null : file.getParentFile());
    if (!path.isEmpty()) {
        fileChooser.setSelectedFile(file);
    }
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setDialogTitle(NbBundle.getMessage(RemoteRepositoryPanel.class, "RepositoryPanel.IdentityFile.FileChooser.Title")); //NOI18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    if (JFileChooser.APPROVE_OPTION == fileChooser.showDialog(panel, null)) {
        File f = fileChooser.getSelectedFile();
        settingsPanel.txtIdentityFile.setText(f.getAbsolutePath());
    }
}
 
Example 6
Source File: CakePHP3NewProjectPanelVisual.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select Project Location");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists()) {
                chooser.setSelectedFile(f);
            }
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
        }
        panel.fireChangeEvent();
    }

}
 
Example 7
Source File: NBProjectGeneratorsPanelVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    String command = evt.getActionCommand();
    if ("BROWSE".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
        chooser.setDialogTitle("Select Project Location");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = this.projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists()) {
                chooser.setSelectedFile(f);
            }
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath());
        }
        panel.fireChangeEvent();
    }

}
 
Example 8
Source File: PanelProjectLocationVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void browseLocationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationJButtonActionPerformed
            JFileChooser chooser = new JFileChooser ();
            FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
            chooser.setDialogTitle(NbBundle.getMessage(PanelProjectLocationVisual.class,"GetProjectLocationPanel.FileChooserTitle"));
            chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
            String path = projectLocationTextField.getText().trim();
            if (path.length() > 0) {
                File f = new File (path);
                if (f.exists ()) {
                    chooser.setSelectedFile(f);
                }
            }
            if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this))) { //NOI18N
                File projectDir = chooser.getSelectedFile();
                projectLocationTextField.setText( projectDir.getAbsolutePath() );
            }   
}
 
Example 9
Source File: CustomizerRun.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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(uiProperties.getProject().getProjectDirectory()).getAbsolutePath();
    }
    chooser.setSelectedFile(new File(workDir));
    chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        jTextWorkingDirectory.setText(file.getAbsolutePath());
    }
}
 
Example 10
Source File: SwingClientApplication.java    From chipster with MIT License 6 votes vote down vote up
/**
 * Opens JFileChooser to ask location for the export, then calls
 * exportDataDirectory to do the job.
 * 
 * @param data
 * @throws MicroarrayException
 * @throws IOException
 */
public void exportFolder(DataFolder data) throws MicroarrayException, IOException {

	File file = new File(data.getName().replace(" ", "_"));
	// file.mkdirs();

	JFileChooser fc = getImportExportDirChooser();
	fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	fc.setSelectedFile(file);

	logger.debug("Exporting File: " + fc.getSelectedFile().getAbsolutePath());

	int ret = fc.showSaveDialog(getMainFrame());

	if (ret == JFileChooser.APPROVE_OPTION) {
		File selected = new File(fc.getSelectedFile().getAbsolutePath() + File.separator + file.getName());
		selected.mkdirs();
		exportDataFolder(data, selected);
	}
}
 
Example 11
Source File: MaskFormActions.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void exportSelectedMasks() {
    final Mask[] masks = getMaskForm().getSelectedMasks();
    if (masks.length == 0) {
        return;
    }

    Document document = new Document(new Element(DimapProductConstants.TAG_MASKS));
    boolean[] masksExported = addContent(masks, document);
    boolean dialogApproved = false;
    if (hasAtLeastOneMaskExported(masksExported)) {
        final JFileChooser fileChooser = new SnapFileChooser();
        fileChooser.setDialogTitle(ACTION_NAME);
        final FileFilter fileFilter = new SnapFileFilter("XML", ".xml", "XML files (*.xml)");
        fileChooser.setFileFilter(fileFilter);
        final File targetDirectory = getDirectory();
        fileChooser.setCurrentDirectory(targetDirectory);
        fileChooser.setSelectedFile(new File(targetDirectory, masks[0].getName()));
        final int result = fileChooser.showSaveDialog(SwingUtilities.getWindowAncestor(maskTopComponent));
        dialogApproved = result == JFileChooser.APPROVE_OPTION;
        if (dialogApproved) {
            File file = fileChooser.getSelectedFile();
            if (file != null) {
                if (Boolean.TRUE.equals(Dialogs.requestOverwriteDecision(ACTION_NAME, file))) {
                    setDirectory(file.getAbsoluteFile().getParentFile());
                    file = FileUtils.ensureExtension(file, ".xml");
                    writeXml(file, document);
                }
            }
        }
    }
    boolean allExportsFailed = countFailedMasks(masksExported) == masksExported.length;
    if (dialogApproved || allExportsFailed) {
        showUserFeedback(masks, masksExported);
    }
}
 
Example 12
Source File: RemoteSessionChooserFactory.java    From chipster with MIT License 5 votes vote down vote up
public JFileChooser getExampleSessionChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
	JFileChooser exampleSessionFileChooser = populateFileChooserFromServer(false);
	exampleSessionFileChooser.setSelectedFile(new File("session"));
	ServerFileUtils.hideJFileChooserButtons(exampleSessionFileChooser);
	exampleSessionFileChooser.setPreferredSize(new Dimension(800, 600));

	ServerFileSystemView view = (ServerFileSystemView) exampleSessionFileChooser.getFileSystemView();
	exampleSessionFileChooser.setCurrentDirectory(view.getExampleSessionDir());				
	
	return exampleSessionFileChooser;
}
 
Example 13
Source File: BiomeExporterDialog.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
private Path getExportPath() {
	Path file = null;

	JFileChooser fileChooser = new JFileChooser();
	fileChooser.setFileFilter(new PNGFileFilter());
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setSelectedFile(Paths.get(pathField.getText()).toAbsolutePath().toFile());
	if (fileChooser.showDialog(dialog, "Confirm") == JFileChooser.APPROVE_OPTION) {
		file = Actions.appendFileExtensionIfNecessary(fileChooser.getSelectedFile().toPath(), "png");
	}

	return file;
}
 
Example 14
Source File: InstallPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void jButtonHomeBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHomeBrowseActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setSelectedFile(new File(jTextFieldHomeDir.getText().trim()));
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        jTextFieldHomeDir.setText(chooser.getSelectedFile().getAbsolutePath());
        fireChange();
    }
}
 
Example 15
Source File: ZipDialog.java    From Compressor with GNU General Public License v2.0 5 votes vote down vote up
private void onCompressFile(Compressor c) {
	File f = getSelectedArchiverFile(null);
	if (f == null) {
		return;
	}
	FileNameExtensionFilter filter = c.getFileFilter();
	String ext = "." + filter.getExtensions()[0];
	String destpath = f.getName() + ext;
	JFileChooser s = new JFileChooser(".");
	s.addChoosableFileFilter(filter);
	s.setSelectedFile(new File(destpath));
	int returnVal = s.showSaveDialog(this);
	if (returnVal != JFileChooser.APPROVE_OPTION) {
		return;
	}
	File ff = s.getSelectedFile();
	destpath = ff.getAbsolutePath();
	if (!filter.accept(ff)) {// 确保一定有后缀
		destpath += ext;
	}

	try {
		c.doCompress(f, destpath);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 16
Source File: SnapshotsSupport.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Saves the snapshot to a used-defined file (opens Save File dialog with defined caption).
 * 
 * @param snapshot Snapshot to be saved.
 * @param dialogTitle Save File dialog caption.
 */
public void saveAs(final Snapshot snapshot, String dialogTitle) {
    final File file = snapshot.getFile();
    if (file == null) {
        ProfilerDialogs.displayError(NbBundle.getMessage(SnapshotsSupport.class, "LBL_CannotSave"));  // NOI18N
    } else {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(dialogTitle);
        chooser.setSelectedFile(new File(snapshot.getFile().getName()));
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setFileFilter(snapshot.getCategory().getFileFilter());
//        chooser.setFileView(category.getFileView());
        if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
            String categorySuffix = snapshot.getCategory().getSuffix();
            String filePath = chooser.getSelectedFile().getAbsolutePath();
            if (!filePath.endsWith(categorySuffix)) filePath += categorySuffix;
            final File copy = new File(filePath);
            VisualVM.getInstance().runTask(new Runnable() {
                public void run() {
                    ProgressHandle pHandle = null;
                    try {
                        pHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(SnapshotsSupport.class, "LBL_Saving",DataSourceDescriptorFactory.getDescriptor(snapshot).getName()));  // NOI18N
                        pHandle.setInitialDelay(0);
                        pHandle.start();
                        Utils.copyFile(file, copy);
                    } finally {
                        final ProgressHandle pHandleF = pHandle;
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() { if (pHandleF != null) pHandleF.finish(); }
                        });
                    }
                }
            });
        }
    }
}
 
Example 17
Source File: SaveAction.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	if (globals.get(Traits.class).isAvailable("4.0.x")) {
		JFileChooser jfc = new JFileChooser();
		String fn = MessageFormat.format(
				Messages.getString("SaveAction.filename"), seq);
		jfc.setSelectedFile(new File(dir, fn));
		FileNameExtensionFilter fileFilter = new FileNameExtensionFilter(
				Messages.getString("SaveAction.types"), "png");
		jfc.setFileFilter(fileFilter);
		jfc.setFileFilter(new FileNameExtensionFilter(Messages
				.getString("SaveAction.filetype"), "png"));
		int ret = jfc.showSaveDialog(panel);
		if (ret == JFileChooser.APPROVE_OPTION) {
			try {
				ImageIO.write(panel.getImage(), "png", jfc.getSelectedFile());
				seq++;
			}
			catch (Exception exp) {
				exp.printStackTrace();
			}
		}
	}
	else {
		globals.get(LifecycleManager.class).sendBusMessage(new JTextField());
	}
}
 
Example 18
Source File: DerbyPropertiesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(null);
        chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
        String location = getInstallLocation();
        if (location.length() > 0) {
            chooser.setSelectedFile(new File(location));
        } else {
            chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); // NOI18N
        }
        if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
            return;
        }
        setInstallLocation(chooser.getSelectedFile().getAbsolutePath());
}
 
Example 19
Source File: AutoSummENGGui.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
/** Select the directory of the model summaries. */
private void BrowseModelDirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseModelDirBtnActionPerformed
    // Select a dir
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory((ModelsRootDirEdt.getText().length() == 0) ? 
        new java.io.File(".") : new java.io.File(ModelsRootDirEdt.getText()));
    fc.setSelectedFile(fc.getCurrentDirectory());
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int iRet = fc.showOpenDialog(this);
    if (iRet == JFileChooser.APPROVE_OPTION)
    {
        ModelsRootDirEdt.setText(fc.getSelectedFile().getAbsolutePath());
    }
}
 
Example 20
Source File: BasicProjectInfoPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void browseProjectLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectLocationActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
        chooser.setSelectedFile(getProjectLocation());
    } else {
        chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
    }
    chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Location"));  //NOI18N
    if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File projectLoc = FileUtil.normalizeFile(chooser.getSelectedFile());
        projectLocation.setText(projectLoc.getAbsolutePath());
    }
}