Java Code Examples for javax.swing.JFileChooser.APPROVE_OPTION

The following are Jave code examples for showing how to use APPROVE_OPTION 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: Websocket-Smart-Card-Signer   File: SignUI.java   View Source Code Vote up 7 votes
public static List<Data> showFileSelection() throws Exception{
    List<Data> ret = new ArrayList<Data>();
    
    JFileChooser jfc = new JFileChooser();
    jfc.setMultiSelectionEnabled(true);
    
    jfc.setDialogTitle("Choose the files to sign");
    SignUtils.playBeeps(1);
    if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
        return null;
    
    File[] choosedFileList = jfc.getSelectedFiles();
    for(File file:choosedFileList){
        String id = file.getAbsolutePath();
        byte[] fileContent = IOUtils.readFile(file);
        ret.add(new Data(id, fileContent));
    }
    return ret;
}
 
Example 2
Project: incubator-netbeans   File: ConfigurationLinuxPanel.java   View Source Code Vote up 6 votes
private void certBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_certBrowseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String text = UiUtils.getValue(certTextField);
    if (text != null) {
        chooser.setSelectedFile(new File(text));
    }
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        certTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 3
Project: jaer   File: CochleaSVMTwoEars.java   View Source Code Vote up 6 votes
public void doLoadDataSetAndTrainSVM() {                          //trains a SVM based on a prerecorded training file
    prob = null;
    prob2 = null;
    try {
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);  //choose a training data set
        chooser.setMultiSelectionEnabled(false);
        state = chooser.showOpenDialog(null);
        if (state == JFileChooser.APPROVE_OPTION) {
            int extInd = chooser.getSelectedFile().getCanonicalPath().lastIndexOf(".txt");
            String base = chooser.getSelectedFile().getCanonicalPath();
            if (extInd > 0) {
                base = chooser.getSelectedFile().getCanonicalPath().substring(0, extInd);   //ensure that the selected training file is a .txt file 
            }
            String filePath = String.format(base + ".txt");
            loadTrainingSet(filePath);                                                          //load the training data in a new problem
            log.info("Opened training data file: " + filePath);
            trainSVM(prob, param);
        }
    } catch (IOException e) {
        log.warning(e.toString());
    }
}
 
Example 4
Project: sumo   File: AddVectorConsoleAction.java   View Source Code Vote up 6 votes
/**
 *
 * @param args
 */
private GeometryImage loadGml() {
	GeometryImage positions =null;
	try{
     int returnVal = fd.showOpenDialog(null);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
             lastDirectory = fd.getSelectedFile().getParent();
             ImageLayer l=LayerManager.getIstanceManager().getCurrentImageLayer();

        		GmlIO gmlIO=new GmlIO(fd.getSelectedFile(),(SarImageReader)l.getImageReader());
                positions = gmlIO.readLayer();
                if (positions.getProjection() != null) {
                	positions = GeometryImage.createImageProjected(positions, ((ImageLayer) l).getImageReader().getGeoTransform(), positions.getProjection());
                }
     }
 } catch (Exception ex) {
     logger.error(ex.getMessage(), ex);
     return null;
 }
	return positions;
}
 
Example 5
Project: jaer   File: SingleOrStereoCameraCalibration.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 6
Project: school-game   File: DialogEditor.java   View Source Code Vote up 6 votes
private void loadLevel()
{
    JFileChooser chooser = new JFileChooser(lastDir == null ? PathHelper.getDialogDirIfFound() : lastDir);
    chooser.addChoosableFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION)
    {
        saveButton.setEnabled(false);
        replaceView(createLevelPanel);
        level = null;
        File selectedFile = chooser.getSelectedFile();
        try {
            level = DialogDataHelper.getDialogRoot(selectedFile);
            lastDir = selectedFile.getParentFile();
            saveButton.setEnabled(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Beim Laden ist ein Fehler aufgetreten!\n" + e.getMessage(), "Fehler!", JOptionPane.OK_OPTION);
        }
        rebuildTree();
    }
}
 
Example 7
Project: incubator-netbeans   File: PanelProjectLocationVisual.java   View Source Code Vote up 6 votes
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction
    String command = evt.getActionCommand();
    
    if ("BROWSE".equals(command)) { //NOI18N
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(NbBundle.getMessage(PanelProjectLocationVisual.class,"LBL_NWP1_SelectProjectLocation")); //NOI18N
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = 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(projectDir.getAbsolutePath());
        }            
        panel.fireChangeEvent();
    }
}
 
Example 8
Project: incubator-netbeans   File: LocalDownloadSupport.java   View Source Code Vote up 6 votes
public boolean chooseNbmFiles () {
    JFileChooser chooser = new JFileChooser ();
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter (NBM_FILE_FILTER);
    chooser.addChoosableFileFilter (OSGI_BUNDLE_FILTER);
    chooser.setFileFilter (NBM_FILE_FILTER);
    chooser.setMultiSelectionEnabled (true);
    chooser.setFileHidingEnabled (false);
    chooser.setDialogTitle (NbBundle.getMessage(LocalDownloadSupport.class, "CTL_FileChooser_Title"));

    File dir = getDefaultDir ();
    if (dir != null && dir.exists ()) {
        chooser.setCurrentDirectory (dir);
    }

    Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
    if (chooser.showOpenDialog (parent) == JFileChooser.APPROVE_OPTION) {
        synchronized (LocalDownloadSupport.class) {
            getPreferences ().put (LOCAL_DOWNLOAD_DIRECTORY_KEY, chooser.getCurrentDirectory ().getAbsolutePath ());
            fileList.addFiles (chooser.getSelectedFiles ());
            addUpdateUnits (chooser.getSelectedFiles ());
        }
        return true;
    }
    return false;
}
 
Example 9
Project: incubator-netbeans   File: PanelProjectLocationExtSrc.java   View Source Code Vote up 6 votes
private void browseProjectLocation(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectLocation
    // TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(NbBundle.getMessage(PanelSourceFolders.class, "LBL_NWP1_SelectProjectLocation")); // NOI18N
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    String path = this.projectLocation.getText();
    if (path.length() > 0) {
        File f = new File(path);
        File owner = f.getParentFile();
        if (owner.exists()) {
            chooser.setCurrentDirectory(owner);
        }
        if (f.exists()) {
            chooser.setSelectedFile(f);
        }
    }
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        if (file != null) {
            this.projectLocation.setText(FileUtil.normalizeFile(file).getAbsolutePath());
        }
    }
}
 
Example 10
Project: Logisim   File: ProjectLibraryActions.java   View Source Code Vote up 5 votes
public static void doLoadLogisimLibrary(Project proj) {
	Loader loader = proj.getLogisimFile().getLoader();
	JFileChooser chooser = loader.createChooser();
	chooser.setDialogTitle(Strings.get("loadLogisimDialogTitle"));
	chooser.setFileFilter(Loader.LOGISIM_FILTER);
	int check = chooser.showOpenDialog(proj.getFrame());
	if (check == JFileChooser.APPROVE_OPTION) {
		File f = chooser.getSelectedFile();
		Library lib = loader.loadLogisimLibrary(f);
		if (lib != null) {
			proj.doAction(LogisimFileActions.loadLibrary(lib));
		}
	}
}
 
Example 11
Project: sstore-soft   File: AbstractViewer.java   View Source Code Vote up 5 votes
/**
 * 
 * @param title
 * @param dir
 * @param filter
 * @return
 * @throws Exception
 */
protected String showLoadDialog(String title, String dir, IOFileFilter filter) throws Exception {
    JFileChooser chooser = new JFileChooser(dir);
    chooser.setFileFilter(filter);
    chooser.setDialogTitle(title);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return (chooser.getSelectedFile().toString());
    }
    return (null);
}
 
Example 12
Project: incubator-netbeans   File: DictionaryInstallerPanel.java   View Source Code Vote up 5 votes
private void bBrowseActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBrowseActionPerformed
    JFileChooser filechooser = new JFileChooser (tDictionary.getText ());
    int ret = filechooser.showOpenDialog (null);
    if (ret == JFileChooser.APPROVE_OPTION)
        tDictionary.setText (filechooser.getSelectedFile ().getAbsolutePath ());
}
 
Example 13
Project: ramus   File: ExcelPlugin.java   View Source Code Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            if (f.isFile()) {
                return f.getName().toLowerCase().endsWith(".xls");
            }
            return true;
        }

        @Override
        public String getDescription() {
            return "*.xls";
        }

    });
    int r = chooser.showOpenDialog(framework.getMainFrame());
    if (r == JFileChooser.APPROVE_OPTION) {
        Importer importer = new Importer(framework, tableView
                .getComponent().getRowSet(), ExcelPlugin.this);
        try {
            importer.importFromFile(chooser.getSelectedFile());
        } catch (IOException e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(framework.getMainFrame(), e1
                    .getLocalizedMessage());
        }
    }
}
 
Example 14
Project: iTrace-Archive   File: OldXMLBasicFixationFilter.java   View Source Code Vote up 5 votes
@Override
public File[] filterUI() {
	JFileChooser chooser = new JFileChooser();
	FileNameExtensionFilter filter = new FileNameExtensionFilter(
			"XML Files", "xml");
	chooser.setFileFilter(filter);
	chooser.setMultiSelectionEnabled(true);
	int returnVal = chooser.showOpenDialog(null);
	if(returnVal == JFileChooser.APPROVE_OPTION) {
		return chooser.getSelectedFiles();
	} else {
		return null;
	}
}
 
Example 15
Project: incubator-netbeans   File: UpdateEclipseReferencePanel.java   View Source Code Vote up 5 votes
private void browseWorkspaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseWorkspaceButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(UpdateEclipseReferencePanel.class, "TITLE_Select_Eclipse_Workspace"));
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        eclipseWorkspaceTextField.setText(file.getAbsolutePath());
    }
}
 
Example 16
Project: Equella   File: CLAConfigPanel.java   View Source Code Vote up 5 votes
void uploadFile()
{
	JFileChooser chooser = new JFileChooser();
	chooser.setFileFilter(new FileFilter()
	{
		@Override
		public String getDescription()
		{
			return getString("agreement.filefilter"); //$NON-NLS-1$
		}

		@Override
		public boolean accept(File f)
		{
			if( f.isDirectory() )
			{
				return true;
			}
			String name = f.toString().toLowerCase();
			return name.endsWith(".zip") || name.endsWith(".htm") || name.endsWith(".html") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				|| name.endsWith(".xsl") || name.endsWith(".xslt"); //$NON-NLS-1$ //$NON-NLS-2$
		}
	});

	final int returnVal = chooser.showOpenDialog(this);
	if( returnVal == JFileChooser.APPROVE_OPTION )
	{
		File selectedFile = chooser.getSelectedFile();
		if( selectedFile.getName().toLowerCase().endsWith(".zip") ) //$NON-NLS-1$
		{
			doZipUpload(selectedFile);
		}
		else
		{
			doSimpleUpload(selectedFile);
		}
	}
}
 
Example 17
Project: Wilmersdorf_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 18
Project: revature-automation-framework-remastered   File: UploadPanel.java   View Source Code Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
	
	//Get return value
	int returnVal = fc.showOpenDialog(fc);
	//If success then get file
	if(returnVal == JFileChooser.APPROVE_OPTION) {
		//Should be data excel file
		File dataExcelFile = fc.getSelectedFile();
		runPanel.setDataExcelFile(dataExcelFile);
	}	
}
 
Example 19
Project: incubator-netbeans   File: DerbyPropertiesPanel.java   View Source Code Vote up 5 votes
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 20
Project: Dahlem_SER316   File: EditorPanel.java   View Source Code Vote up 4 votes
void importB_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"));

	JFileChooser chooser = new JFileChooser();
	chooser.setFileHidingEnabled(false);
	chooser.setDialogTitle(Local.getString("Insert file"));
	chooser.setAcceptAllFileFilterUsed(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
	chooser.setPreferredSize(new Dimension(550, 375));
	String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
	if (lastSel != null)
		chooser.setCurrentDirectory(new java.io.File(lastSel));
	if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
		return;

	Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
			.getPath());

	File f = chooser.getSelectedFile();
	new HTMLFileImport(f, editor);
}