Java Code Examples for java.awt.FileDialog#getFiles()

The following examples show how to use java.awt.FileDialog#getFiles() . 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: SparkTransferManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void sendFileTo(ContactItem item) {
    FileDialog fileChooser = getFileChooser(SparkManager.getMainWindow(), Res.getString("title.select.file.to.send"));
    if (defaultDirectory != null)
    {
        fileChooser.setDirectory( defaultDirectory.getAbsolutePath() );
    }
    fileChooser.setVisible(true);

    final File[] files = fileChooser.getFiles();
    if ( files.length == 0) {
        // no selection
        return;
    }

    File file = files[0]; // Single-file selection is used. Using the first array item is safe.

    if (file.exists()) {
        defaultDirectory = file.getParentFile();
        sendFile( file, item.getJid() );
    }

}
 
Example 2
Source File: MainFrame.java    From lizzie with GNU General Public License v3.0 5 votes vote down vote up
public void openFile() {
  JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem");
  FileDialog fileDialog = new FileDialog(this, resourceBundle.getString("LizzieFrame.openFile"));
  fileDialog.setLocationRelativeTo(this);
  fileDialog.setDirectory(filesystem.getString("last-folder"));
  fileDialog.setFile("*.sgf;*.gib;*.SGF;*.GIB");
  fileDialog.setMultipleMode(false);
  fileDialog.setMode(0);
  fileDialog.setVisible(true);
  File[] file = fileDialog.getFiles();
  if (file.length > 0) loadFile(file[0]);
}
 
Example 3
Source File: FileDialogUtils.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Returns files the user selected or an empty array if the user cancelled
 * the dialog.
 */
public static File[] showOpenDialog(Frame f, String title,
		boolean allowMultipleSelection, FilenameFilter filter) {
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.LOAD);
	if (filter != null)
		fd.setFilenameFilter(filter);
	fd.pack();
	fd.setMultipleMode(allowMultipleSelection);
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if (fd.getFile() == null)
		return new File[] {};
	return fd.getFiles();
}
 
Example 4
Source File: MainGui.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
private void loadItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadItemActionPerformed
    FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD);
    fd.setFile("*.xml");
    fd.setVisible(true);
    File[] files = fd.getFiles();
    
    if (files.length > 0) {
        File loadFile = files[0];
        
        try {
            ToolConfiguration currentToolConfig = new ToolConfiguration();
            currentToolConfig.setAttackerConfig(controller.getAttackerConfig());
            currentToolConfig.setAnalyzerConfig(controller.getAnalyzerConfig());
            
            XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, currentToolConfig);
        } catch (XmlPersistenceError ex) {
            Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    /*int returnVal = loadFileChooser.showOpenDialog(this);
            
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File loadFile = loadFileChooser.getSelectedFile();
        try {
            XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, controller.getConfig());
        } catch (XmlPersistenceError ex) {
            Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }*/
}
 
Example 5
Source File: ChatRoomTransferDecorator.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void showFilePicker() {
     SwingWorker worker = new SwingWorker() {
         @Override
public Object construct() {
             try {
                 Thread.sleep(10);
             }
             catch (InterruptedException e1) {
                 Log.error(e1);
             }
             return true;
         }

         @Override
public void finished() {
             FileDialog fileChooser = SparkManager.getTransferManager().getFileChooser(SparkManager.getChatManager().getChatContainer().getChatFrame(), Res.getString("title.select.file.to.send"));
             if (SparkManager.getTransferManager().getDefaultDirectory() != null)
             {
                 fileChooser.setDirectory(SparkManager.getTransferManager().getDefaultDirectory().getAbsolutePath());
             }
             fileChooser.setVisible(true);

             final File[] files = fileChooser.getFiles();
             if ( files.length == 0) {
                 // no selection
                 return;
             }

             File file = files[0]; // Single-file selection is used. Using the first array item is safe.

             if (file.exists()) {
                 SparkManager.getTransferManager().setDefaultDirectory(file.getParentFile());
                 SparkManager.getTransferManager().sendFile(file, ((ChatRoomImpl)chatRoom).getParticipantJID());
             }

         }
     };
     worker.start();
 }