Package javax.swing

Examples of javax.swing.JFileChooser


     * look for a valid Java properties file.
     *
     * @return properties object with selected file contents.
     */
    public static Properties promptUserForProperties() {
        JFileChooser fileChooser = new JFileChooser();
        int retvalue = fileChooser.showOpenDialog(null);
        Properties props = new Properties();
        if (retvalue != JFileChooser.APPROVE_OPTION) {
            return props;
        }
        try {
            FileInputStream inputStream = new FileInputStream(fileChooser.getSelectedFile());
            props.load(inputStream);
            return props;
        } catch (Exception ioe) {
            System.err.println("PropUtils.promptUserForProperties: Exception reading properties file.");
            System.err.println(ioe.getMessage());
View Full Code Here


     * This is called when you should ask the user for a source file to read.
     *
     * @return a file to read or null to cancel.
     */
    public File promptForFile(FileFilter fileFilter) {
        JFileChooser chooser = new JFileChooser();
        chooser.addChoosableFileFilter(fileFilter);

        if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) {
            return null;
        }

        return chooser.getSelectedFile();
    }
View Full Code Here

   *
   */

  private static final int FILEFIELDSIZE = 20;
  private JComponent createComponents() {
    sourcefc = new JFileChooser();
    sourcefc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    targetfc = new JFileChooser();
    targetfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    GridBagConstraints constraint;

    JPanel pane = new JPanel();
View Full Code Here

        });

        _openFileChooser = new JMenuItem("Add Shape File");
        _openFileChooser.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setFileFilter(new EsriFilter());
                int returnVal = fileChooser.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    try {
                        File shp = fileChooser.getSelectedFile();
                        String s = shp.getCanonicalPath();
                        int pos1 = s.lastIndexOf('.');
                        String name = s.substring(0, pos1);
                        File shx = new File(s.substring(0, pos1) + ".shx");
                        File dbf = new File(s.substring(0, pos1) + ".dbf");
                        EsriLayer layer = new EsriLayer(name, dbf.toURL(), shp.toURL(), shx.toURL());
                        _layerHandler.addLayer(layer);
                    } catch (Exception exception) {
                        System.out.println(exception);
                    }
                }
            }
        });

        _exit = new JMenuItem("Exit");
        _exit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        _saveFileChooser = new JMenuItem("Save File");
        _saveFileChooser.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                EsriLayer layer = pickEsriLayer();
                if (layer != null) {
                    JFileChooser fileChooser = new JFileChooser();
                    fileChooser.setFileFilter(new EsriFilter());
                    int returnVal = fileChooser.showSaveDialog(null);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        try {
                            File file = fileChooser.getSelectedFile();
                            String path = file.getCanonicalPath();
                            EsriGraphicList list = layer.getEsriGraphicList();

                            ShpOutputStream pos = new ShpOutputStream(new FileOutputStream(path
                                    + ".shp"));
View Full Code Here

     * This is called when you should ask the user for a source file to read.
     *
     * @return a file to read or null to cancel.
     */
    public File promptForFile(FileFilter fileFilter) {
        JFileChooser chooser = new JFileChooser();
        chooser.addChoosableFileFilter(fileFilter);

        if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION) {
            return null;
        }

        return chooser.getSelectedFile();
    }
View Full Code Here

    File file;
    File path;
    String jobName = getJobName();

    if (fileChooser == null) {
      fileChooser = new JFileChooser();
      fileChooser.setMultiSelectionEnabled(false);
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    }

    // Make sure job name is not blank
View Full Code Here

        // window,
        // or we could simply select the new images and scroll the list to make
        // those images visible.
        File startingPoint = new File(Environment.get("lastchosendirectory",
                System.getProperty("user.home")));
        JFileChooser chooser = new JFileChooser(startingPoint);
        String title = i18n.get(ImageTileLayer.class,
                "addImagesWindowTitle",
                "Add Images");
        chooser.setDialogTitle(title);
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        chooser.setFileFilter(new ImageLoaderFileFilter(imageReaderLoaders));
        String acceptButtonText = i18n.get(ImageTileLayer.class,
                "acceptButtonText",
                "Add");
        int state = chooser.showDialog(null, acceptButtonText);

        try {
            // only bother trying to read the file if there is one
            // for some reason, the APPROVE_OPTION said it was a
            // boolean during compile and didn't work in this next
            // statement
            if ((state != JFileChooser.CANCEL_OPTION)
                    && (state != JFileChooser.ERROR_OPTION)) {

                String newFile = chooser.getSelectedFile().getCanonicalPath();

                int dirIndex = newFile.lastIndexOf(File.separator);
                if (dirIndex >= 0) {
                    // store the selected file for later
                    Environment.set("lastchosendirectory", newFile.substring(0,
View Full Code Here

  }

  void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();
    for(int i = 0; i < saveContributors.size(); i++)
    {
      fileChooser.addChoosableFileFilter((JRSaveContributor)saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor))
    {
      fileChooser.setFileFilter(lastSaveContributor);
    }
    else if (saveContributors.size() > 0)
    {
      fileChooser.setFileFilter((JRSaveContributor)saveContributors.get(0));
    }
   
    if (lastFolder != null)
    {
      fileChooser.setCurrentDirectory(lastFolder);
    }
   
    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION)
    {
      FileFilter fileFilter = fileChooser.getFileFilter();
      File file = fileChooser.getSelectedFile();
     
      lastFolder = file.getParentFile();

      JRSaveContributor contributor = null;
View Full Code Here

    setSize(600, 480);
  }
 
  public boolean show(UserProperties up){
    if(chooser==null){
      chooser=new JFileChooser(up.getFile().getParentFile());
    }
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    try{
      up.store(baos,"");
    } catch(IOException ioe){
View Full Code Here

     */
    private void browseAction(){
        //Retrieve previous opened DIR in userProperties.
        String folder = Viewer.instance.userProperties.getProperty(Viewer.PROPERTY_FOLDER, "");
        //Show a JFileChooser and fill the textField using the result.
        JFileChooser chooser = null;
        //Use the saved properties FOLDER to open the JFileChooser in the previous opened folder.
        if(folder != null && !folder.equals("")){
            chooser = new JFileChooser(folder);
        }else{
            //If folder was not set, use default home folder.
            chooser = new JFileChooser();
        }
        chooser.setFileFilter(new LoggingFileFilter(getFileExtensions(),Viewer.instance.getString("fileDescription")));
        //show the fileChooser.
        int result = chooser.showDialog(Viewer.instance, Viewer.instance.getString(type+"Action"));
        //check validation status of the JFileChooser.
        if(result == JFileChooser.APPROVE_OPTION){
            jTextFieldFile.setText(chooser.getSelectedFile().getPath());
        }//if no file has been selected, do nothing.
    }
View Full Code Here

TOP

Related Classes of javax.swing.JFileChooser

Copyright © 2018 www.massapicom. 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.