Java Code Examples for javax.swing.JFileChooser.setApproveButtonText()

The following are Jave code examples for showing how to use setApproveButtonText() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jaer   File: StereoCalibrationDualViewFilter.java   Source Code and License Vote up 6 votes
synchronized public void doSetPath() {
	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select");
	j.setDialogTitle("Select a folder and base file name for calibration images");
	j.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	//imagesDirPath = j.getSelectedFile().getAbsolutePath();
	dirPath = j.getCurrentDirectory().getPath();
	fileBaseName = j.getSelectedFile().getName();
	if (!fileBaseName.isEmpty()) {
		fileBaseName = "-" + fileBaseName;
	}
	log.log(Level.INFO, "Changed images path to {0}", dirPath);
	putString("dirPath", dirPath);
}
 
Example 2
Project: incubator-netbeans   File: BuildContextVisual.java   Source Code and License Vote up 6 votes
private void buildContextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildContextButtonActionPerformed
    FileChooserBuilder builder = FileChooserBuilder.create(fileSystem);
    JFileChooser fileChooser = builder.createFileChooser();
    fileChooser.setApproveButtonText(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.button")); // NOI18M
    fileChooser.setDialogTitle(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.dialogTitle")); // NOI18M
    fileChooser.setFileSelectionMode(0);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    String buildText = UiUtils.getValue(buildContextTextField);
    if (buildText != null) {
        fileChooser.setSelectedFile(new File(buildText));

    }
    if (fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        buildContextTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 3
Project: jaer   File: SingleCameraCalibration.java   Source Code and License Vote up 6 votes
synchronized public void doLoadCalibration() {
    final JFileChooser j = new JFileChooser();
    j.setCurrentDirectory(new File(dirPath));
    j.setApproveButtonText("Select folder");
    j.setDialogTitle("Select a folder that has XML files storing calibration");
    j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
    j.setApproveButtonText("Select folder");
    j.setApproveButtonToolTipText("Only enabled for a folder that has cameraMatrix.xml and distortionCoefs.xml");
    setButtonState(j, j.getApproveButtonText(), calibrationExists(j.getCurrentDirectory().getPath()));
    j.addPropertyChangeListener(JFileChooser.DIRECTORY_CHANGED_PROPERTY, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent pce) {
            setButtonState(j, j.getApproveButtonText(), calibrationExists(j.getCurrentDirectory().getPath()));
        }
    });
    int ret = j.showOpenDialog(null);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    dirPath = j.getSelectedFile().getPath();
    putString("dirPath", dirPath);

    loadCalibration();
}
 
Example 4
Project: jaer   File: StereoCalibrationDualViewFilter.java   Source Code and License Vote up 6 votes
synchronized public void doSaveCalibration() {
	if (!calibrated) {
		JOptionPane.showMessageDialog(null, "No calibration yet");
		return;
	}
	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select folder");
	j.setDialogTitle("Select a folder to store calibration XML files");
	j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	dirPath = j.getSelectedFile().getPath();
	putString("dirPath", dirPath);
	serializeMat(dirPath, "cameraMatrix", cameraMatrix);
	serializeMat(dirPath, "distortionCoefs", distortionCoefs);
	saved = true;
	generateCalibrationString();
}
 
Example 5
Project: freecol   File: LoadDialog.java   Source Code and License Vote up 5 votes
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 */
public LoadDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setControlButtonsAreShown(true);
    fileChooser.setApproveButtonText(Messages.message("ok"));
    //fileChooser.setCancelButtonText(Messages.message("cancel"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.addActionListener((ActionEvent ae) -> {
            final String cmd = ae.getActionCommand();
            File value = (JFileChooser.APPROVE_SELECTION.equals(cmd))
                ? ((JFileChooser)ae.getSource()).getSelectedFile()
                : cancelFile;
            setValue(value);
        });

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 6
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License Vote up 5 votes
private void prepareFileChooser(JFileChooser chooser) {
    chooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY
            : filesOnly ? JFileChooser.FILES_ONLY :
            JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileHidingEnabled(fileHiding);
    chooser.setControlButtonsAreShown(controlButtonsShown);
    chooser.setAcceptAllFileFilterUsed(useAcceptAllFileFilter);
    if (title != null) {
        chooser.setDialogTitle(title);
    }
    if (approveText != null) {
        chooser.setApproveButtonText(approveText);
    }
    if (badger != null) {
        chooser.setFileView(new CustomFileView(new BadgeIconProvider(badger),
                chooser.getFileSystemView()));
    }
    if (PREVENT_SYMLINK_TRAVERSAL) {
        FileUtil.preventFileChooserSymlinkTraversal(chooser,
                chooser.getCurrentDirectory());
    }
    if (filter != null) {
        chooser.setFileFilter(filter);
    }
    if (aDescription != null) {
        chooser.getAccessibleContext().setAccessibleDescription(aDescription);
    }
    if (!filters.isEmpty()) {
        for (FileFilter f : filters) {
            chooser.addChoosableFileFilter(f);
        }
    }
}
 
Example 7
Project: FreeCol   File: LoadDialog.java   Source Code and License Vote up 5 votes
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 */
public LoadDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setControlButtonsAreShown(true);
    fileChooser.setApproveButtonText(Messages.message("ok"));
    //fileChooser.setCancelButtonText(Messages.message("cancel"));
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.addActionListener((ActionEvent ae) -> {
            final String cmd = ae.getActionCommand();
            File value = (JFileChooser.APPROVE_SELECTION.equals(cmd))
                ? ((JFileChooser)ae.getSource()).getSelectedFile()
                : cancelFile;
            setValue(value);
        });

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
 
Example 8
Project: jaer   File: CypressFX2EEPROM.java   Source Code and License Vote up 5 votes
private void chooseCPLDFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseCPLDFileButtonActionPerformed
        JFileChooser chooser = new JFileChooser(prefs.get("CypressFX2EEPROM_CPLD.filepath", ""));
//        JFileChooser chooser=new JFileChooser();
        FileFilter filter = new FileFilter() {

            @Override
			public boolean accept(File f) {
                if (f.getName().toLowerCase().endsWith(".xsvf") || f.isDirectory()) {
                    return true;
                } else {
                    return false;
                }
            }

            @Override
			public String getDescription() {
                return "Firmware download file for CPLD (.xsvf)";
            }
        };
        chooser.setFileFilter(filter);
        chooser.setApproveButtonText("Choose");
        chooser.setToolTipText("Choose a CPLD download file");
        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            try {
                log.info("You chose this file: " + file.getCanonicalFile());
                this.CPLDfilenameField.setText(file.getCanonicalPath());
                this.CPLDfilenameField.setToolTipText(file.getCanonicalPath());
                prefs.put("CypressFX2EEPROM_CPLD.filename", file.getCanonicalPath());
                prefs.put("CypressFX2EEPROM_CPLD.filepath", file.getCanonicalPath());
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, ex);
            }
        }
    }
 
Example 9
Project: incubator-netbeans   File: J2SEPlatformCustomizer.java   Source Code and License Vote up 4 votes
private static boolean select(
    final PathModel model,
    final File[] currentDir,
    final Component parentComponent) {
    final JFileChooser chooser = new JFileChooser ();
    chooser.setMultiSelectionEnabled (true);
    String title = null;
    String message = null;
    String approveButtonName = null;
    String approveButtonNameMne = null;
    if (model.type == SOURCES) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Sources");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenSources");
    } else if (model.type == JAVADOC) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Javadoc");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenJavadoc");
    }
    chooser.setDialogTitle(title);
    chooser.setApproveButtonText(approveButtonName);
    chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    if (Utilities.isMac()) {
        //New JDKs and JREs are bundled into package, allow JFileChooser to navigate in
        chooser.putClientProperty("JFileChooser.packageIsTraversable", "always");   //NOI18N
    }
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter (new ArchiveFileFilter(message,new String[] {"ZIP","JAR"}));   //NOI18N
    if (currentDir[0] != null) {
        chooser.setCurrentDirectory(currentDir[0]);
    }
    if (chooser.showOpenDialog(parentComponent) == JFileChooser.APPROVE_OPTION) {
        File[] fs = chooser.getSelectedFiles();
        boolean addingFailed = false;
        for (File f : fs) {
            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
            // E.g. for /foo/src it returns /foo/src/src
            // Try to convert it back by removing last invalid name component
            if (!f.exists()) {
                File parent = f.getParentFile();
                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
                    f = parent;
                }
            }
            if (f.exists()) {
                addingFailed|=!model.addPath (f);
            }
        }
        if (addingFailed) {
            new NotifyDescriptor.Message (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_CanNotAddResolve"),
                    NotifyDescriptor.ERROR_MESSAGE);
        }
        currentDir[0] = FileUtil.normalizeFile(chooser.getCurrentDirectory());
        return true;
    }
    return false;
}
 
Example 10
Project: incubator-netbeans   File: J2SEVolumeCustomizer.java   Source Code and License Vote up 4 votes
private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setAcceptAllFileFilterUsed(false);
    if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_CLASSPATH)) {
        chooser.setMultiSelectionEnabled (true);
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenClasses"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Classpath"),new String[] {"ZIP","JAR"}));   //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectCP"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectCP").charAt(0));
    }
    else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_JAVADOC)) {
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenJavadoc"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Javadoc"),new String[] {"ZIP","JAR"}));     //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectJD"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectJD").charAt(0));
    }
    else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_SRC)) {
        chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenSources"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
                J2SEVolumeCustomizer.class,"TXT_Sources"),new String[] {"ZIP","JAR"}));     //NOI18N
        chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectSRC"));
        chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectSRC").charAt(0));
    }
    if (lastFolder != null) {
        chooser.setCurrentDirectory (lastFolder);
    }
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            lastFolder = chooser.getCurrentDirectory();
            if (chooser.isMultiSelectionEnabled()) {
                addFiles (chooser.getSelectedFiles());
            }
            else {
                final File selectedFile = chooser.getSelectedFile();                    
                addFiles (new File[] {selectedFile});
            }
        } catch (MalformedURLException mue) {
            Exceptions.printStackTrace(mue);
        }
    }
}
 
Example 11
Project: incubator-netbeans   File: ProjectChooserAccessory.java   Source Code and License Vote up 4 votes
/** Factory method for project chooser
 */
public static JFileChooser createProjectChooser( boolean defaultAccessory ) {

    ProjectManager.getDefault().clearNonProjectCache(); // #41882

    OpenProjectListSettings opls = OpenProjectListSettings.getInstance();
    JFileChooser chooser = new ProjectFileChooser();
    chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );

    if ("GTK".equals(javax.swing.UIManager.getLookAndFeel().getID())) { // NOI18N
        // see BugTraq #5027268
        chooser.putClientProperty("GTKFileChooser.showDirectoryIcons", Boolean.TRUE); // NOI18N
        //chooser.putClientProperty("GTKFileChooser.showFileIcons", Boolean.TRUE); // NOI18N
    }

    chooser.setApproveButtonText( NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonText" ) ); // NOI18N
    chooser.setApproveButtonMnemonic( NbBundle.getMessage( ProjectChooserAccessory.class, "MNM_PrjChooser_ApproveButtonText" ).charAt (0) ); // NOI18N
    chooser.setApproveButtonToolTipText (NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonTooltipText")); // NOI18N
    // chooser.setMultiSelectionEnabled( true );
    chooser.setDialogTitle( NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_Title" ) ); // NOI18N
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter( ProjectDirFilter.INSTANCE );

    // A11Y
    chooser.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectChooserAccessory"));
    chooser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectChooserAccessory"));


    if ( defaultAccessory ) {
        chooser.setAccessory(new ProjectChooserAccessory(chooser, opls.isOpenSubprojects()));
    }

    File currDir = null;
    String dir = opls.getLastOpenProjectDir();
    if ( dir != null ) {
        File d = new File( dir );
        if ( d.exists() && d.isDirectory() ) {
            currDir = d;
        }
    }

    FileUtil.preventFileChooserSymlinkTraversal(chooser, currDir);
    new ProjectFileView(chooser);

    return chooser;

}
 
Example 12
Project: incubator-netbeans   File: AntArtifactChooser.java   Source Code and License Vote up 4 votes
/** Shows dialog with the artifact chooser 
 * @return null if canceled selected jars if some jars selected
 */
static AntArtifactItem[] showDialog( String[] artifactTypes, Project master, Component parent ) {
    
    JFileChooser chooser = ProjectChooser.projectChooser();
    chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
    chooser.setApproveButtonText( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_SelectProject" ) ); // NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (AntArtifactChooser.class,"AD_AACH_SelectProject"));
    AntArtifactChooser accessory = new AntArtifactChooser( artifactTypes, chooser );
    chooser.setAccessory( accessory );
    chooser.setPreferredSize( new Dimension( 650, 380 ) );        
    File defaultFolder = null;
    FileObject defFo = master.getProjectDirectory();
    if (defFo != null) {
        defFo = defFo.getParent();
        if (defFo != null) {
            defaultFolder = FileUtil.toFile(defFo);
        }
    }
    chooser.setCurrentDirectory (getLastUsedArtifactFolder(defaultFolder));

    int option = chooser.showOpenDialog( parent ); // Show the chooser
          
    if ( option == JFileChooser.APPROVE_OPTION ) {

        File dir = chooser.getSelectedFile();
        dir = FileUtil.normalizeFile (dir);
        Project selectedProject = accessory.getProject( dir );

        if ( selectedProject == null ) {
            return null;
        }
        
        if ( selectedProject.getProjectDirectory().equals( master.getProjectDirectory() ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_RefToItself" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }
        
        if ( ProjectUtils.hasSubprojectCycles( master, selectedProject ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }

        boolean noSuitableOutput = true;
        for (String type : artifactTypes) {
            if (AntArtifactQuery.findArtifactsByType(selectedProject, type).length > 0) {
                noSuitableOutput = false;
                break;
            }
        }
        if (noSuitableOutput) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    NbBundle.getMessage (AntArtifactChooser.class,"MSG_NO_JAR_OUTPUT")));
            return null;
        }
        
        setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
        
        Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
        int count = 0;
        for(int i = 0; i < tmp.length; i++) {
            if (accessory.jListArtifacts.isSelectedIndex(i)) {
                tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
                count++;
            }
        }
        AntArtifactItem artifactItems[] = new AntArtifactItem[count];
        System.arraycopy(tmp, 0, artifactItems, 0, count);
        return artifactItems;
    }
    else {
        return null; 
    }
            
}
 
Example 13
Project: incubator-netbeans   File: SvnProperties.java   Source Code and License Vote up 4 votes
public void loadFromFile() {
    final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(SvnProperties.class, "ACSD_Properties"));
    chooser.setDialogTitle(NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title"));
    chooser.setMultiSelectionEnabled(false);
    javax.swing.filechooser.FileFilter[] fileFilters = chooser.getChoosableFileFilters();
    for (int i = 0; i < fileFilters.length; i++) {
        javax.swing.filechooser.FileFilter fileFilter = fileFilters[i];
        chooser.removeChoosableFileFilter(fileFilter);
    }

    chooser.setCurrentDirectory(roots[0].getParentFile()); // NOI18N
    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.exists();
        }
        @Override
        public String getDescription() {
            return "";
        }
    });

    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setApproveButtonMnemonic(NbBundle.getMessage(SvnProperties.class, "MNE_LoadValue").charAt(0));
    chooser.setApproveButtonText(NbBundle.getMessage(SvnProperties.class, "CTL_LoadValue"));
    DialogDescriptor dd = new DialogDescriptor(chooser, NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title"));
    dd.setOptions(new Object[0]);
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);

    chooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                File source = chooser.getSelectedFile();

                if (Utils.isFileContentText(source)) {
                    if (source.canRead()) {
                        StringWriter sw = new StringWriter();
                        try {
                            Utils.copyStreamsCloseAll(sw, new FileReader(source));
                            panel.txtAreaValue.setText(sw.toString());
                        } catch (IOException ex) {
                            Subversion.LOG.log(Level.SEVERE, null, ex);
                        }
                    }
                } else {
                    handleBinaryFile(source);
                }
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);

}
 
Example 14
Project: incubator-netbeans   File: PatchAction.java   Source Code and License Vote up 4 votes
private File getPatchFor(FileObject fo) {
       JFileChooser chooser = new JFileChooser();
       String patchDirPath = DiffModuleConfig.getDefault().getPreferences().get(PREF_RECENT_PATCH_PATH, System.getProperty("user.home"));
       File patchDir = new File(patchDirPath);
       while (!patchDir.isDirectory()) {
           patchDir = patchDir.getParentFile();
           if (patchDir == null) {
               patchDir = new File(System.getProperty("user.home"));
               break;
           }
       }
       FileUtil.preventFileChooserSymlinkTraversal(chooser, patchDir);
       chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
       String title = NbBundle.getMessage(PatchAction.class,
           (fo.isData()) ? "TITLE_SelectPatchForFile"
                         : "TITLE_SelectPatchForFolder", fo.getNameExt());
       chooser.setDialogTitle(title);

       // setup filters, default one filters patch files
       FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
           @Override
           public boolean accept(File f) {
               return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory();  // NOI18N
           }
           @Override
           public String getDescription() {
               return NbBundle.getMessage(PatchAction.class, "CTL_PatchDialog_FileFilter");
           }
       };
       chooser.addChoosableFileFilter(patchFilter);
       chooser.setFileFilter(patchFilter);

       chooser.setApproveButtonText(NbBundle.getMessage(PatchAction.class, "BTN_Patch"));
       chooser.setApproveButtonMnemonic(NbBundle.getMessage(PatchAction.class, "BTN_Patch_mnc").charAt(0));
       chooser.setApproveButtonToolTipText(NbBundle.getMessage(PatchAction.class, "BTN_Patch_tooltip"));
       HelpCtx ctx = new HelpCtx(PatchAction.class.getName());
       DialogDescriptor descriptor = new DialogDescriptor( chooser, title, true, new Object[0], null, 0, ctx, null );
       final Dialog dialog = DialogDisplayer.getDefault().createDialog( descriptor );
       dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PatchAction.class, "ACSD_PatchDialog"));

       ChooserListener listener = new PatchAction.ChooserListener(dialog,chooser);
chooser.addActionListener(listener);
       dialog.setVisible(true);

       File selectedFile = listener.getFile();
       if (selectedFile != null) {
           DiffModuleConfig.getDefault().getPreferences().put(PREF_RECENT_PATCH_PATH, selectedFile.getParentFile().getAbsolutePath());
       }
       return selectedFile;
   }
 
Example 15
Project: incubator-netbeans   File: ResultsManager.java   Source Code and License Vote up 4 votes
public void exportSnapshots(final FileObject[] selectedSnapshots) {
    assert (selectedSnapshots != null);
    assert (selectedSnapshots.length > 0);

    final String[] fileName = new String[1], fileExt = new String[1];
    final FileObject[] dir = new FileObject[1];
    if (selectedSnapshots.length == 1) {
        SelectedFile sf = selectSnapshotTargetFile(selectedSnapshots[0].getName(),
                            selectedSnapshots[0].getExt().equals(HEAPDUMP_EXTENSION));

        if ((sf != null) && checkFileExists(sf)) {
            fileName[0] = sf.fileName;
            fileExt[0] = sf.fileExt;
            dir[0] = sf.folder;
        } else { // dialog cancelled by the user
            return;
        }
    } else {
        JFileChooser chooser = new JFileChooser();

        if (exportDir != null) {
            chooser.setCurrentDirectory(exportDir);
        }

        chooser.setDialogTitle(Bundle.ResultsManager_SelectDirDialogCaption());
        chooser.setApproveButtonText(Bundle.ResultsManager_SaveButtonName());
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);

        if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();

            if (!file.exists()) {
                if (!ProfilerDialogs.displayConfirmation(
                        Bundle.ResultsManager_DirectoryDoesntExistMsg(), 
                        Bundle.ResultsManager_DirectoryDoesntExistCaption())) {
                    return; // cancelled by the user
                }

                file.mkdir();
            }

            exportDir = file;

            dir[0] = FileUtil.toFileObject(FileUtil.normalizeFile(file));
        } else { // dialog cancelled
            return;
        }
    }
    final ProgressHandle ph = ProgressHandle.createHandle(Bundle.MSG_SavingSnapshots());
    ph.setInitialDelay(500);
    ph.start();
    ProfilerUtils.runInProfilerRequestProcessor(new Runnable() {
        @Override
        public void run() {
            try {
                for (int i = 0; i < selectedSnapshots.length; i++) {
                    exportSnapshot(selectedSnapshots[i], dir[0], fileName[0] != null ? fileName[0] : selectedSnapshots[i].getName(), fileExt[0] != null ? fileExt[0] : selectedSnapshots[i].getExt());
                }
            } finally {
                ph.finish();
            }
        }
    });
}
 
Example 16
Project: incubator-netbeans   File: ResultsManager.java   Source Code and License Vote up 4 votes
SelectedFile selectSnapshotTargetFile(final String defaultName, final boolean heapdump) {
    String targetName;
    FileObject targetDir;

    // 1. let the user choose file or directory
    JFileChooser chooser = new JFileChooser();

    if (exportDir != null) {
        chooser.setCurrentDirectory(exportDir);
    }

    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle(Bundle.ResultsManager_SelectFileOrDirDialogCaption());
    chooser.setApproveButtonText(Bundle.ResultsManager_SaveButtonName());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.isDirectory() || f.getName().endsWith("." + (heapdump ? HEAPDUMP_EXTENSION : SNAPSHOT_EXTENSION)); //NOI18N
            }

            public String getDescription() {
                if (heapdump) {
                    return Bundle.ResultsManager_ProfilerHeapdumpFileFilter(HEAPDUMP_EXTENSION);
                }
                return Bundle.ResultsManager_ProfilerSnapshotFileFilter(SNAPSHOT_EXTENSION);
            }
        });

    if (chooser.showSaveDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) {
        return null; // cancelled by the user
    }

    // 2. process both cases and extract file name and extension to use
    File file = chooser.getSelectedFile();
    String targetExt = heapdump ? HEAPDUMP_EXTENSION : SNAPSHOT_EXTENSION;

    if (file.isDirectory()) { // save to selected directory under default name
        exportDir = chooser.getCurrentDirectory();
        targetDir = FileUtil.toFileObject(FileUtil.normalizeFile(file));
        targetName = defaultName;
    } else { // save to selected file
        exportDir = chooser.getCurrentDirectory();

        targetDir = FileUtil.toFileObject(FileUtil.normalizeFile(exportDir));

        String fName = file.getName();

        // divide the file name into name and extension
        int idx = fName.lastIndexOf('.'); // NOI18N

        if (idx == -1) { // no extension
            targetName = fName;

            // extension will be used from source file
        } else { // extension exists
            if (heapdump || fName.endsWith("." + targetExt)) { // NOI18N
                targetName = fName.substring(0, idx);
                targetExt = fName.substring(idx + 1);
            } else {
                targetName = fName;
            }
        }
    }

    // 3. return a newly created FileObject
    return new SelectedFile(targetDir, targetName, targetExt);
}
 
Example 17
Project: incubator-netbeans   File: ApplyDiffPatchAction.java   Source Code and License Vote up 4 votes
@Override
protected void performContextAction(Node[] nodes) {
    VCSContext ctx = HgUtils.getCurrentContext(nodes);
    final File roots[] = HgUtils.getActionRoots(ctx);
    if (roots == null || roots.length == 0) {
        return;
    }
    final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);

    final JFileChooser fileChooser = new AccessibleJFileChooser(Bundle.ACSD_ApplyDiffPatchBrowseFolder(), null);
    fileChooser.setDialogTitle(Bundle.ApplyDiffPatchBrowse_title());
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setApproveButtonMnemonic(Bundle.ApplyDiffPatch_Apply().charAt(0));
    fileChooser.setApproveButtonText(Bundle.ApplyDiffPatch_Apply());
    fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
    // setup filters, default one filters patch files
    FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory();  // NOI18N
        }
        @Override
        public String getDescription() {
            return Bundle.CTL_PatchDialog_FileFilter();
        }
    };
    fileChooser.addChoosableFileFilter(patchFilter);
    fileChooser.setFileFilter(patchFilter);

    DialogDescriptor dd = new DialogDescriptor(fileChooser, Bundle.ApplyDiffPatchBrowse_title());
    dd.setOptions(new Object[0]);
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    
    fileChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                final File patchFile = fileChooser.getSelectedFile();
                final RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
                new HgProgressSupport() {

                    @Override
                    protected void perform () {
                        if (isNetBeansPatch(patchFile)) {
                            PatchAction.performPatch(patchFile, roots[0]);
                        } else {
                            new ImportDiffAction.ImportDiffProgressSupport(root, patchFile, false, ImportDiffAction.ImportDiffProgressSupport.Kind.PATCH)
                                    .start(rp, root, Bundle.MSG_ApplyDiffPatch_importingPatch());
                        }
                    }
                }.start(rp, root, Bundle.MSG_ApplyDiffPatch_checkingFile());
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);
}
 
Example 18
Project: jaer   File: SingleOrStereoCameraCalibration.java   Source Code and License Vote up 4 votes
synchronized public void doSaveImagePointsForStereoCalibration() {
	//allImagePoints.resize(imageCounter)


	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select folder");
	j.setDialogTitle("Select a folder to store calibration XML files");
	j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	dirPath = j.getSelectedFile().getPath();
	putString("dirPath", dirPath);

	serializeMatVector(dirPath, "allImagePoints", allImagePoints);
	log.info("***********succeed serialisation allImagePoints***********");

	serializeMatVector(dirPath, "allObjectPoints", allObjectPoints);
	log.info("***********succeed serialisation allObjectPoints***********");
	saved = true;
	generateCalibrationString();

	try
	{
		File fac = new File("previousImageCounter.txt");
		if (!fac.exists())
		{
			fac.createNewFile();
		}
		System.out.println("\n----------------------------------");
		System.out.println("The file has been created.");
		System.out.println("------------------------------------");

		FileWriter wr = new FileWriter(fac);

		log.info(Integer.toString(imageCounter));
		wr.write(Integer.toString(imageCounter));

		wr.close();
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}

}
 
Example 19
Project: jaer   File: StereoCalibrationDualViewFilter.java   Source Code and License Vote up 4 votes
synchronized public void doSaveImagePointsForStereoCalibration() {
	//allImagePoints.resize(imageCounter)


	JFileChooser j = new JFileChooser();
	j.setCurrentDirectory(new File(dirPath));
	j.setApproveButtonText("Select folder");
	j.setDialogTitle("Select a folder to store calibration XML files");
	j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
	int ret = j.showSaveDialog(null);
	if (ret != JFileChooser.APPROVE_OPTION) {
		return;
	}
	dirPath = j.getSelectedFile().getPath();
	putString("dirPath", dirPath);

	serializeMatVector(dirPath, "allImagePoints", allImagePoints);
	log.info("***********succeed serialisation allImagePoints***********");

	serializeMatVector(dirPath, "allObjectPoints", allObjectPoints);
	log.info("***********succeed serialisation allObjectPoints***********");
	saved = true;
	generateCalibrationString();

	try
	{
		File fac = new File("previousImageCounter.txt");
		if (!fac.exists())
		{
			fac.createNewFile();
		}
		System.out.println("\n----------------------------------");
		System.out.println("The file has been created.");
		System.out.println("------------------------------------");

		FileWriter wr = new FileWriter(fac);

		log.info(Integer.toString(imageCounter));
		wr.write(Integer.toString(imageCounter));

		wr.close();
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}

}
 
Example 20
Project: jaer   File: CypressFX2EEPROM.java   Source Code and License Vote up 4 votes
private void chooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileButtonActionPerformed
        String defaultPath = System.getProperty("user.dir") + File.separatorChar + "devices/firmware/CypressFX2";
        String startDir = prefs.get("CypressFX2EEPROM.filepath", defaultPath);
        JFileChooser chooser = new JFileChooser(startDir);
//        JFileChooser chooser=new JFileChooser();
        FileFilter filter = new FileFilter() {

            @Override
			public boolean accept(File f) {
                //if(f.getName().toLowerCase().endsWith(".iic") || f.getName().toLowerCase().endsWith(".hex") || f.isDirectory())
                if (f.getName().toLowerCase().endsWith(".iic") || f.getName().toLowerCase().endsWith(".bix") || f.getName().toLowerCase().endsWith(".hex") || f.isDirectory()) // hex download stopped working, only accept iic for the moment
                {
                    return true;
                } else {
                    return false;
                }
            }

            @Override
			public String getDescription() {
                return "Binary IIC format firmware download file for Cypress FX2";
            }
        };
        chooser.setFileFilter(filter);
        chooser.setApproveButtonText("Choose");
        chooser.setToolTipText("Choose a binary download file (they are in the source path, e.g. ch/unizh/ini/caviar/hardwareinterface/usb)");
        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            try {
                log.info("You chose this file: " + file.getCanonicalFile());
                filenameTextField.setText(file.getCanonicalPath());
                filenameTextField.setToolTipText(file.getCanonicalPath());
                prefs.put("CypressFX2EEPROM.filename", file.getCanonicalPath());
                prefs.put("CypressFX2EEPROM.filepath", file.getCanonicalPath());
                setEEPROMRAMRadioButtonsAccordingToFileType(file);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, ex);
            }
        }
    }