Ejemplo n.º 1
0
  // $$ modif from Oury
  private static JFileChooser getFileChooser(Component owner, int mode) {
    JFileChooser chooser = null;
    String last = /*Jext*/ AbstractEditorPanel.getProperty("lastdir." + mode);
    if (last == null) last = /*Jext*/ AbstractEditorPanel.getHomeDirectory();

    if (owner instanceof AbstractEditorPanel) {
      chooser = ((/*Jext*/ AbstractEditorPanel) owner).getFileChooser(mode);
      if (
      /*Jext*/ AbstractEditorPanel.getBooleanProperty("editor.dirDefaultDialog")
          && mode != SCRIPT) {
        String file =
            ((AbstractEditorPanel) owner)
                // $$ from Seb [[
                // .getTextArea()
                // $$ from Seb ]]
                .getCurrentFile();
        if (file != null) chooser.setCurrentDirectory(new File(file));
      } else chooser.setCurrentDirectory(new File(last));
    } else {
      chooser = new JFileChooser(last);
      if (mode == SAVE) chooser.setDialogType(JFileChooser.SAVE_DIALOG);
      else chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    }

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileHidingEnabled(true);

    return chooser;
  }
Ejemplo n.º 2
0
  public static File startFileChooser(Component component, File selectedFile) {
    // Create a file chooser
    final JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileHidingEnabled(true);
    fc.setAcceptAllFileFilterUsed(false);
    if (selectedFile != null) fc.setSelectedFile(selectedFile);
    fc.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(final File file) {
            if (file.isDirectory()) return true;
            String ext = Utils.getExtension(file);
            if (ext != null && ext.equals(Utils.XLS)) {
              return true;
            }
            return false;
          }

          @Override
          public String getDescription() {
            return "Excel *.xls";
          }
        });
    // In response to a button click:
    final int returnVal = fc.showOpenDialog(component);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      // This is where a real application would open the file.
      Log.d("Opening: " + file.getName() + ".");
      return file;
    } else {
      Log.d("Open command cancelled by user.");
    }
    return null;
  }
Ejemplo n.º 3
0
  /** Called for button presses and checkbox toggles. */
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    // the source of the event is the add files button
    // so we need to let the user add some files!
    if (src == addFiles) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser = new JFileChooser((new File("")).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(true);
      myTempFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to add files if the
      // user selected any in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the files the user selected
        File[] selectedFiles = myTempFileChooser.getSelectedFiles();

        // pull the files into the list
        changeFilesInList.importFileData(list, selectedFiles);
      }
    }

    // the source of the event was the process button
    else if (src == process) {
      if (((DefaultListModel) list.getModel()).size() == 0) return;

      setComponentsEnabled(false);
      final ThumbMaker tm = this;
      Thread t =
          new Thread(
              new Runnable() {
                public void run() {
                  tm.process();
                  setComponentsEnabled(true);
                }
              });
      t.start();

      // because we can't do it on quit, we are going to save
      // all the preference values when the user processes a set
      // of images
      savePreferences();
    }

    // the source of the event was the remove button
    else if (src == remove) {
      DefaultListModel model = (DefaultListModel) list.getModel();
      while (true) {
        int ndx = list.getSelectedIndex();
        if (ndx < 0) break;
        model.removeElementAt(ndx);
      }
    }

    // the source of the event was the preserve aspect check box
    else if (src == aspect) {
      boolean b = aspect.isSelected();
      colorLabel.setEnabled(b);
      colorBox.setEnabled(b);
      redLabel.setEnabled(b);
      red.setEnabled(b);
      redValue.setEnabled(b);
      greenLabel.setEnabled(b);
      green.setEnabled(b);
      greenValue.setEnabled(b);
      blueLabel.setEnabled(b);
      blue.setEnabled(b);
      blueValue.setEnabled(b);
    }

    // the source of the event is the "..." button,
    // we need to let the user select a destination file
    else if (src == dotDotDot) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser =
          new JFileChooser(new File(output.getText()).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(false);
      myTempFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to set the directory if the
      // user selected one in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the file the user selected
        File selectedFile = myTempFileChooser.getSelectedFile();

        // stuff the file path into the text field
        output.setText(selectedFile.getAbsolutePath());
      }
    }
  }