Package org.one.stone.soup.javascript.helper

Source Code of org.one.stone.soup.javascript.helper.FileChooser

package org.one.stone.soup.javascript.helper;

import java.io.File;

import javax.swing.JFileChooser;

public class FileChooser {

  public static File currentPath;
 
  public static String chooseFileToOpen() {
    JFileChooser fileChooser = new JFileChooser();
    if(currentPath!=null) {
      fileChooser.setCurrentDirectory(currentPath);
    }

    int result = fileChooser.showOpenDialog(null);
    fileChooser.setVisible(true);
   
    if(result == JFileChooser.APPROVE_OPTION) {
      currentPath = fileChooser.getCurrentDirectory();
      return fileChooser.getSelectedFile().getAbsolutePath();
    } else {
      return null;
    }
  }
 
  public static String chooseFileToSave() {
    JFileChooser fileChooser = new JFileChooser();
    if(currentPath!=null) {
      fileChooser.setCurrentDirectory(currentPath);
    }

    int result = fileChooser.showSaveDialog(null);
    fileChooser.setVisible(true);
   
    if(result == JFileChooser.APPROVE_OPTION) {
      currentPath = fileChooser.getCurrentDirectory();
      return fileChooser.getSelectedFile().getAbsolutePath();
    } else {
      return null;
    }
  }
 
  public static String chooseFile(String actionText) {
    JFileChooser fileChooser = new JFileChooser();
    if(currentPath!=null) {
      fileChooser.setCurrentDirectory(currentPath);
    }

    int result = fileChooser.showDialog(null,actionText);
    fileChooser.setVisible(true);
   
    if(result == JFileChooser.APPROVE_OPTION) {
      currentPath = fileChooser.getCurrentDirectory();
      return fileChooser.getSelectedFile().getAbsolutePath();
    } else {
      return null;
    }
  }
}
TOP

Related Classes of org.one.stone.soup.javascript.helper.FileChooser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.