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

The following are Jave code examples for showing how to use setCurrentDirectory() 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.
+ Save this method
Example 1
Project: Install_Builder_Universal   File: SaveFile.java   View Source Code Vote up 6 votes
public void save(final JPanel panel) {
	JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    chooser.setDialogTitle("Choose Directory To Save To");
    //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setApproveButtonText("Save");
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
      dir = chooser.getSelectedFile().toString();
    } else {
      System.err.println("Could not open Dir");
      return;
    }
}
 
Example 2
Project: incubator-netbeans   File: TemplateSelector.java   View Source Code Vote up 6 votes
private File selectFile(int dialogType, String approveButtonText) {
        JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(TemplateSelector.class, "ACSD_SelectTemplate")/*, defaultDir*/);// NOI18N
        fileChooser.setDialogTitle(NbBundle.getMessage(TemplateSelector.class, "CTL_SelectTemplate"));// NOI18N
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setDialogType(dialogType);

        File file = getTemplateFile();

//        if(file.isFile() && dialogType == JFileChooser.OPEN_DIALOG) {
//            fileChooser.setSelectedFile(file);
//        } else {
//            fileChooser.setCurrentDirectory(file.isFile() ? file.getParentFile() : file);
//        }
        if(file.isFile() ) {
            fileChooser.setSelectedFile(file);
        } else {
            fileChooser.setCurrentDirectory(file);
        }

        fileChooser.showDialog(getPanel(), approveButtonText);
        File f = fileChooser.getSelectedFile();
        return f;
    }
 
Example 3
Project: applecommander   File: SwingAppleCommander.java   View Source Code Vote up 6 votes
/**
 * Open a file.
 */
protected void openFile() {
	JFileChooser jc = new JFileChooser();
	String pathName = userPreferences.getDiskImageDirectory();
	if (null == pathName) {
		pathName = ""; //$NON-NLS-1$
		}
	jc.setCurrentDirectory(new File(pathName));
	EmulatorFileFilter ff = new EmulatorFileFilter();
	jc.setFileFilter(ff);
	int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
	if (rc == 0) {
		userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
		UserPreferences.getInstance().save();
		addDiskExplorerTab(jc.getSelectedFile());
	}
}
 
Example 4
Project: jaer   File: StereoCalibrationDualViewFilter.java   View Source Code 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 5
Project: AppleCommander   File: SwingAppleCommander.java   View Source Code Vote up 6 votes
/**
 * Open a file.
 */
protected void openFile() {
	JFileChooser jc = new JFileChooser();
	String pathName = userPreferences.getDiskImageDirectory();
	if (null == pathName) {
		pathName = ""; //$NON-NLS-1$
		}
	jc.setCurrentDirectory(new File(pathName));
	EmulatorFileFilter ff = new EmulatorFileFilter();
	jc.setFileFilter(ff);
	int rc = jc.showDialog(this, textBundle.get("Open")); //$NON-NLS-1$
	if (rc == 0) {
		userPreferences.setDiskImageDirectory(jc.getSelectedFile().getParent());
		UserPreferences.getInstance().save();
		addDiskExplorerTab(jc.getSelectedFile());
	}
}
 
Example 6
Project: Dahlem_SER316   File: SetApplicationPanel.java   View Source Code Vote up 5 votes
void selectAppBrowseB_actionPerformed(ActionEvent e) {
// Fix until Sun's JVM supports more locales...
UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");

JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(Local.getString("Path to executable"));
chooser.setFileHidingEnabled(false);
chooser.setAcceptAllFileFilterUsed(true);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (System.getProperty("os.name").startsWith("Win")) {
    chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.EXE));
    chooser.setCurrentDirectory(new File("C:\\Program Files"));
}
chooser.setPreferredSize(new Dimension(550, 375));
/*
    java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_IMPORT_FILE");
    if (lastSel != null)
        chooser.setCurrentDirectory(lastSel);
*/
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
    applicationField.setText(chooser.getSelectedFile().getPath());
}
 
Example 7
Project: jaer   File: TrackDefineFilter.java   View Source Code Vote up 5 votes
/**
 * Saves the extracted track to an external file.
 */
public void doSaveTrack() {
    if (extractedTrack == null) {
        // No track defined
        return;
    }

    final JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(getLastFilePrefs());  // defaults to startup runtime folder
    fc.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory()
                    || f.getName().toLowerCase().endsWith(".track");
        }

        @Override
        public String getDescription() {
            return "Track files";
        }
    });

    final int[] state = new int[1];
    state[0] = Integer.MIN_VALUE;

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            fc.setSelectedFile(new File("test.track"));
            state[0] = fc.showSaveDialog(chip.getAeViewer() != null && chip.getAeViewer().getFilterFrame() != null ? chip.getAeViewer().getFilterFrame() : null);
            if (state[0] == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if(!file.getName().endsWith(".track")) {
                    String newName=file.getPath()+".track";
                    file=new File(newName);
                }
                putLastFilePrefs(file);

                try {
                    saveTrackToFile(file);
                } catch (IOException ex) {
                    log.warning("couldn't save track to file, caught: " + ex);
                    JOptionPane.showMessageDialog(fc, "couldn't save track to file, caught: " + ex, "Saving track failed", JOptionPane.WARNING_MESSAGE);
                }
            } else {
                log.info("Cancelled saving!");
            }
        }
    });
}
 
Example 8
Project: VASSAL-src   File: SavedGameUpdaterDialog.java   View Source Code Vote up 5 votes
public SavedGameUpdaterDialog(Frame owner) throws HeadlessException {
  super(owner, false);
  setTitle("Update Saved Games");
  initComponents();
  fc = new JFileChooser();
  fc.setCurrentDirectory(GameModule.getGameModule().getFileChooser().getCurrentDirectory());
}
 
Example 9
Project: Dahlem_SER316   File: FileExportDialog.java   View Source Code Vote up 5 votes
private void browseTemplate() {
	JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Select file"));
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (templF.getText().length() >0)
    	chooser.setCurrentDirectory(new java.io.File(templF.getText()));
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
    	templF.setText(chooser.getSelectedFile().getPath());
}
 
Example 10
Project: ProyectoPacientes   File: JDIngresarPaciente.java   View Source Code Vote up 5 votes
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    JFileChooser NuevoF = new JFileChooser();
    NuevoF.setDialogTitle("Seleccione una Imagen");
    File ruta = new File("C:/Imagenes");
    NuevoF.setCurrentDirectory(ruta);
    int ventana = NuevoF.showOpenDialog(null);
    if(ventana == JFileChooser.APPROVE_OPTION)
    {
        File Foto= NuevoF.getSelectedFile();
        txtNombImg.setText(String.valueOf(Foto));
    }
}
 
Example 11
Project: sumo   File: SavePanel.java   View Source Code Vote up 5 votes
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String filename = null;
    for (ILayer l : LayerManager.getIstanceManager().getLayers().keySet()) {
        if (l instanceof ImageLayer & l.isActive()) {
            filename = ((ImageLayer) l).getName();
            break;
        }
    }
    filename = jTextField1.getText();
    //System.out.println(filename);
    JFileChooser fd = new JFileChooser();
    if(!"".equalsIgnoreCase(filename)&&filename!=null){
    	File f=new File(filename);
    	if(f.getParentFile()!=null && f.getParentFile().exists())
    		fd.setCurrentDirectory(f.getParentFile());
    	
    	fd.setSelectedFile(f);
    }
    int returnVal = fd.showOpenDialog(Frame.getFrames()[0]);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            jTextField1.setText(fd.getSelectedFile().getCanonicalPath());
        } catch (IOException ex) {
        	logger.error(ex.getMessage(),ex);
        }
    }
}
 
Example 12
Project: incubator-netbeans   File: ImportDiffAction.java   View Source Code Vote up 4 votes
private static void importDiff(VCSContext ctx) {
    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(NbBundle.getMessage(ImportDiffAction.class, "ACSD_ImportBrowseFolder"), null);   // NO I18N
    fileChooser.setDialogTitle(NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title"));                                            // NO I18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setApproveButtonMnemonic(NbBundle.getMessage(ImportDiffAction.class, "Import").charAt(0));                      // NO I18N
    fileChooser.setApproveButtonText(NbBundle.getMessage(ImportDiffAction.class, "Import"));                                        // NO I18N
    fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
    JPanel panel = new JPanel();
    final JRadioButton asPatch = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_PatchOption")); //NOI18N
    org.openide.awt.Mnemonics.setLocalizedText(asPatch, asPatch.getText()); // NOI18N
    final JRadioButton asBundle = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_BundleOption")); //NOI18N
    org.openide.awt.Mnemonics.setLocalizedText(asBundle, asBundle.getText()); // NOI18N
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(asBundle);
    buttonGroup.add(asPatch);
    asPatch.setSelected(true);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(asPatch);
    panel.add(asBundle);
    fileChooser.setAccessory(panel);

    DialogDescriptor dd = new DialogDescriptor(fileChooser, NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title"));              // NO I18N
    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();

                HgModuleConfig.getDefault().setImportFolder(patchFile.getParent());
                RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
                ImportDiffProgressSupport.Kind kind;
                if (asBundle.isSelected()) {
                    kind = ImportDiffProgressSupport.Kind.BUNDLE;
                } else if (asPatch.isSelected()) {
                    kind = ImportDiffProgressSupport.Kind.PATCH;
                } else {
                    kind = null;
                }
                HgProgressSupport support = new ImportDiffProgressSupport(root, patchFile, true, kind);
                support.start(rp, root, org.openide.util.NbBundle.getMessage(ImportDiffAction.class, "LBL_ImportDiff_Progress")); // NOI18N
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);
}
 
Example 13
Project: SER316-Aachen   File: EditTypeDialog.java   View Source Code Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 14
Project: jaer   File: StereoCalibrationDualViewFilter.java   View Source Code 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 15
Project: SER316-Dresden   File: EditTypeDialog.java   View Source Code Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("/ui/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 16
Project: jaer   File: SingleOrStereoCameraCalibration.java   View Source Code 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 17
Project: jaer   File: NetController.java   View Source Code Vote up 4 votes
public void loadState()
  {
      JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory( new File( "./") );
      if ( chooser.showSaveDialog( null ) != JFileChooser.APPROVE_OPTION ) {
	return;
}

      File file=chooser.getSelectedFile();

      if (file==null) {
	return;
}


      loadState(file);


  }
 
Example 18
Project: incubator-netbeans   File: J2SEPlatformCustomizer.java   View Source Code 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 19
Project: jaer   File: MotionViewer.java   View Source Code Vote up 4 votes
/** called when user asks to open data file file dialog */
        public void openInputFileDialog() {
//        try{Thread.currentThread().sleep(200);}catch(InterruptedException e){}
            float oldScale = chipCanvas.getScale();
            fileChooser = new JFileChooser();
//            new TypeAheadSelector(fileChooser);
            //com.sun.java.plaf.windows.WindowsFileChooserUI;
//            fileChooser.addKeyListener(new KeyAdapter() {
//                public void keyTyped(KeyEvent e){
//                    System.out.println("keycode="+e.getKeyCode());
//                }
//            });
//            System.out.println("fileChooser.getUIClassID()="+fileChooser.getUIClassID());
//            KeyListener[] keyListeners=fileChooser.getKeyListeners();
//            ChipDataFilePreview preview=new ChipDataFilePreview(fileChooser,chip); // from book swing hacks
//            new FileDeleter(fileChooser,preview);
//            fileChooser.addPropertyChangeListener(preview);
//            fileChooser.setAccessory(preview);
            String lastFilePath = prefs.get("MotionViewer.lastFile", ""); // get the last folder
            lastFile = new File(lastFilePath);
//            fileChooser.setFileFilter(datFileFilter);
            DATFileFilter datFileFilter = new DATFileFilter();
            fileChooser.addChoosableFileFilter(datFileFilter);
            fileChooser.setCurrentDirectory(lastFile); // sets the working directory of the chooser
//            boolean wasPaused=isPaused();
            setPaused(true);
            int retValue = fileChooser.showOpenDialog(MotionViewer.this);
            if (retValue == JFileChooser.APPROVE_OPTION) {
                try {
                    lastFile = fileChooser.getSelectedFile();
                    if (lastFile != null) {
                        recentFiles.addFile(lastFile);
                    }
                    startPlayback(lastFile);
                } catch (FileNotFoundException fnf) {
                    fnf.printStackTrace();
//                exceptionOccurred(fnf,this);
                }
            }
            fileChooser = null;
//            chipCanvas.setScale(oldScale); // restore persistent scale so that we don't get tiny size on next startup
            setPaused(false);
        }
 
Example 20
Project: komodoGUI   File: WalletOperations.java   View Source Code Vote up 4 votes
public void exportWalletPrivateKeys()
{
	// TODO: Will need corrections once encryption is reenabled!!!

	try
	{
		this.issueBackupDirectoryWarning();

		JFileChooser fileChooser = new JFileChooser();
		fileChooser.setDialogTitle("Export wallet private keys to file...");
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.setCurrentDirectory(OSUtil.getUserHomeDirectory());

		int result = fileChooser.showSaveDialog(this.parent);

		if (result != JFileChooser.APPROVE_OPTION)
		{
		    return;
		}

		File f = fileChooser.getSelectedFile();

		Cursor oldCursor = this.parent.getCursor();
		try
		{
			this.parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

			this.clientCaller.exportWallet(f.getName());

			this.parent.setCursor(oldCursor);
		} catch (WalletCallException wce)
		{
			this.parent.setCursor(oldCursor);
			wce.printStackTrace();

			JOptionPane.showMessageDialog(
				this.parent,
				"An unexpected error occurred while exporting wallet private keys!" +
				"\n" + wce.getMessage().replace(",", ",\n"),
				"Error in exporting wallet private keys...", JOptionPane.ERROR_MESSAGE);
			return;
		}

		JOptionPane.showMessageDialog(
			this.parent,
			"The wallet private keys have been exported successfully to file:\n" +
			f.getName() + "\n" +
			"in the backup directory provided to zcashd (-exportdir=<dir>).\n" +
			"You need to protect this file from unauthorized access. Anyone who\n" +
			"has access to the private keys can spend the ZCash balance!",
			"Wallet private key export...", JOptionPane.INFORMATION_MESSAGE);

	} catch (Exception e)
	{
		this.errorReporter.reportError(e, false);
	}
}