Пример #1
0
 public void loadROM() {
   FileDialog fileDialog = new FileDialog(this);
   fileDialog.setMode(FileDialog.LOAD);
   fileDialog.setTitle("Select a ROM to load");
   // should open last folder used, and if that doesn't exist, the folder it's running in
   final String path = PrefsSingleton.get().get("filePath", System.getProperty("user.dir", ""));
   final File startDirectory = new File(path);
   if (startDirectory.isDirectory()) {
     fileDialog.setDirectory(path);
   }
   // and if the last path used doesn't exist don't set the directory at all
   // and hopefully the jFileChooser will open somewhere usable
   // on Windows it does - on Mac probably not.
   fileDialog.setFilenameFilter(new NESFileFilter());
   boolean wasInFullScreen = false;
   if (inFullScreen) {
     wasInFullScreen = true;
     // load dialog won't show if we are in full screen, so this fixes for now.
     toggleFullScreen();
   }
   fileDialog.setVisible(true);
   if (fileDialog.getFile() != null) {
     PrefsSingleton.get().put("filePath", fileDialog.getDirectory());
     loadROM(fileDialog.getDirectory() + fileDialog.getFile());
   }
   if (wasInFullScreen) {
     toggleFullScreen();
   }
 }
Пример #2
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Пример #3
0
  /**
   * The implementation that the other methods delegate to. This provides the caller with all
   * available options for customizing the <tt>JFileChooser</tt> instance. If a <tt>FileDialog</tt>
   * is displayed instead of a <tt>JFileChooser</tt> (on OS X, for example), most or all of these
   * options have no effect.
   *
   * @param parent the <tt>Component</tt> that should be the dialog's parent
   * @param titleKey the key for the locale-specific string to use for the file dialog title
   * @param approveKey the key for the locale-specific string to use for the approve button text
   * @param directory the directory to open the dialog to
   * @param mode the "mode" to open the <tt>JFileChooser</tt> in from the <tt>JFileChooser</tt>
   *     class, such as <tt>JFileChooser.DIRECTORIES_ONLY</tt>
   * @param option the option to look for in the return code, such as
   *     <tt>JFileChooser.APPROVE_OPTION</tt>
   * @param allowMultiSelect true if the chooser allows multiple files to be chosen
   * @param filter the <tt>FileFilter</tt> instance for customizing the files that are displayed --
   *     if this is null, no filter is used
   * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a file was not selected
   *     correctly
   */
  public static List<File> getInput(
      Component parent,
      String titleKey,
      String approveKey,
      File directory,
      int mode,
      int option,
      boolean allowMultiSelect,
      final FileFilter filter) {
    if (!OSUtils.isAnyMac()) {
      JFileChooser fileChooser = getDirectoryChooser(titleKey, approveKey, directory, mode, filter);
      fileChooser.setMultiSelectionEnabled(allowMultiSelect);
      try {
        if (fileChooser.showOpenDialog(parent) != option) return null;
      } catch (NullPointerException npe) {
        // ignore NPE.  can't do anything with it ...
        return null;
      }

      if (allowMultiSelect) {
        File[] chosen = fileChooser.getSelectedFiles();
        if (chosen.length > 0) setLastInputDirectory(chosen[0]);
        return Arrays.asList(chosen);
      } else {
        File chosen = fileChooser.getSelectedFile();
        setLastInputDirectory(chosen);
        return Collections.singletonList(chosen);
      }

    } else {
      FileDialog dialog;
      if (mode == JFileChooser.DIRECTORIES_ONLY) dialog = MacUtils.getFolderDialog();
      else dialog = new FileDialog(GUIMediator.getAppFrame(), "");

      dialog.setTitle(I18n.tr(titleKey));
      if (filter != null) {
        FilenameFilter f =
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return filter.accept(new File(dir, name));
              }
            };
        dialog.setFilenameFilter(f);
      }

      dialog.setVisible(true);
      String dirStr = dialog.getDirectory();
      String fileStr = dialog.getFile();
      if ((dirStr == null) || (fileStr == null)) return null;
      setLastInputDirectory(new File(dirStr));
      // if the filter didn't work, pretend that the person picked
      // nothing
      File f = new File(dirStr, fileStr);
      if (filter != null && !filter.accept(f)) return null;

      return Collections.singletonList(f);
    }
  }
Пример #4
0
 @Override
 public void execute() throws Exception {
   FileDialog fd = new FileDialog((Frame) context.getStage().getNativeWindow());
   fd.setMode(FileDialog.LOAD);
   fd.setTitle("Import Other Graphics File");
   fd.setVisible(true);
   if (fd.getFile() != null) {
     File file = new File(fd.getDirectory(), fd.getFile());
     u.p("opening a file" + file);
     try {
       load(file);
       context.main.recentFiles.add(file);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }