Java Code Examples for org.openide.filesystems.FileChooserBuilder#setFilesOnly()

The following examples show how to use org.openide.filesystems.FileChooserBuilder#setFilesOnly() . 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: RequireJsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private File browseAction(String dirKey, String title, boolean filesOnly, File workDir) {
    FileChooserBuilder builder = new FileChooserBuilder(dirKey)
            .setTitle(title);
    if (workDir != null) {
        builder.setDefaultWorkingDirectory(workDir)
                .forceUseOfDefaultWorkingDirectory(true);
    }
    if (filesOnly) {
        builder.setFilesOnly(true);
    } 
    File selectedFile = builder.showOpenDialog();
    if (selectedFile != null) {
        return FileUtil.normalizeFile(selectedFile);
    }
    return null;
}
 
Example 2
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static File browseAction(String dirKey, String title, boolean filesOnly, File workDir) {
    FileChooserBuilder builder = new FileChooserBuilder(dirKey)
            .setTitle(title);
    if (workDir != null) {
        builder.setDefaultWorkingDirectory(workDir)
                .forceUseOfDefaultWorkingDirectory(true);
    }
    if (filesOnly) {
        builder.setFilesOnly(true);
    } else {
        builder.setDirectoriesOnly(true);
    }
    File selectedFile = builder.showOpenDialog();
    if (selectedFile != null) {
        return FileUtil.normalizeFile(selectedFile);
    }
    return null;
}
 
Example 3
Source File: OpenFileAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and initializes a file chooser.
 *
 * @return  the initialized file chooser
 */
protected JFileChooser prepareFileChooser() {
    FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
    fcb.setSelectionApprover(new OpenFileSelectionApprover());
    fcb.setFilesOnly(true);
    fcb.addDefaultFileFilters();
    for (OpenFileDialogFilter filter :
            Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
        fcb.addFileFilter(filter);
    }
    JFileChooser chooser = fcb.createFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.getCurrentDirectory().listFiles(); //preload
    chooser.setCurrentDirectory(getCurrentDirectory());
    if (currentFileFilter != null) {
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            if (currentFileFilter.equals(ff.getDescription())) {
                chooser.setFileFilter(ff);
                break;
            }
        }
    }
    HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
    return chooser;
}
 
Example 4
Source File: CreateAvdVisualPanel1.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void importProfileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importProfileButtonActionPerformed
    // TODO add your handling code here:
    FileChooserBuilder builder = new FileChooserBuilder("android-devices");
    builder.setFilesOnly(true);
    builder.setFileFilter(new FileNameExtensionFilter("Android devide definition", "xml", "XML"));
    File[] files = builder.showMultiOpenDialog();
    if (files != null) {
        for (File file : files) {
            try {
                Table<String, String, Device> devices = DeviceParser.parse(file);
                Map<String, Map<String, Device>> rowMap = devices.rowMap();
                rowMap.values().stream().forEach((t) -> {
                    t.values().stream().forEach((d) -> {
                        Device device = AvdHwProfile.showDeviceProfiler(d, deviceManager, false);
                        if (device != null) {
                            deviceManager.addUserDevice(d);
                        }
                    });
                });
            } catch (Exception ex) {
                NotifyDescriptor nd = new NotifyDescriptor.Message("Error while parsing Android device definition!", NotifyDescriptor.ERROR_MESSAGE);
                DialogDisplayer.getDefault().notifyLater(nd);
            }
        }
        deviceManager.saveUserDevices();
        refreshDevices();
    }
}
 
Example 5
Source File: CreateAvdVisualPanel3.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void sdcardSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sdcardSelectActionPerformed
    // TODO add your handling code here:
    FileChooserBuilder builder = new FileChooserBuilder(CreateAvdVisualPanel3.class);
    builder.setFilesOnly(true);
    File sdcardImage = builder.showOpenDialog();
    if (sdcardImage != null && sdcardImage.exists()) {
        try (FileImageInputStream fi = new FileImageInputStream(sdcardImage)) {
            byte[] boot = new byte[3];
            fi.read(boot);
            if (boot[0] == ((byte) 0xeb) && boot[1] == ((byte) 0x5a) && boot[2] == ((byte) 0x90)) {
                sdcardPath.setText(sdcardImage.getAbsolutePath());
            } else {
                NotifyDescriptor nd = new NotifyDescriptor.Confirmation("<html>"
                        + "Signature of selected file does not match Android SD Card image.<br/>"
                        + "Are you sure you want to use the selected file?", "SD Card image problem...",
                        NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
                Object notify = DialogDisplayer.getDefault().notify(nd);
                if (NotifyDescriptor.YES_OPTION.equals(notify)) {
                    sdcardPath.setText(sdcardImage.getAbsolutePath());
                }
            }

        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }

    }
}
 
Example 6
Source File: SaveAsAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    Node node = activatedNodes[0];
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if (fo != null) {
        FileChooserBuilder builder = new FileChooserBuilder(SaveAsAction.class);
        builder.setDirectoriesOnly(false);
        builder.setApproveText("Save");
        builder.setControlButtonsAreShown(true);
        builder.setTitle("Save As...");
        builder.setFilesOnly(true);
        builder.setFileFilter(new FileNameExtensionFilter(fo.getExt(), fo.getExt()));
        JFileChooser chooser = builder.createFileChooser();
        chooser.setSelectedFile(new File(fo.getNameExt()));
        int resp = chooser.showSaveDialog(findDialogParent());
        if (JFileChooser.APPROVE_OPTION == resp) {
            File saveFile = chooser.getSelectedFile();
            if (saveFile != null) {
                try {
                    saveFile.getParentFile().mkdirs();
                    FileObject dfo = FileUtil.toFileObject(saveFile.getParentFile());
                    if (dfo == null) {
                        NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to Save file!", NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notifyLater(nd);
                        return;
                    }
                    if (saveFile.exists()) {
                        saveFile.delete();
                    }
                    fo.copy(dfo, saveFile.getName(), "");
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
Example 7
Source File: ImportVisualPanel2.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void selectFile() {
    FileChooserBuilder builder = new FileChooserBuilder(this.getClass());
    builder.setFilesOnly(true);
    builder.setTitle("Select Asset File");
    File[] file = builder.showMultiOpenDialog();
    if (file != null) {
        for (int i = 0; i < file.length; i++) {
            File file1 = file[i];
            FileDescription description = AssetPackLoader.getFileDescription(file1);
            description.setPath(pathString());
            list.add(description);
        }
        updateList();
    }
}