コード例 #1
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();
    }
  }
コード例 #2
0
ファイル: GUIImpl.java プロジェクト: rockerdiaz/halfnes
 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();
   }
 }
コード例 #3
0
 public File showFileSaveDialog(Component parent, File defaultFile) {
   FileDialog fileDialog = new FileDialog(getProjectExplorer());
   if (defaultFile != null) {
     fileDialog.setDirectory(defaultFile.getParent());
     fileDialog.setFile(defaultFile.getName());
   }
   fileDialog.setMode(FileDialog.SAVE);
   fileDialog.setVisible(true);
   String filename = fileDialog.getFile();
   return filename != null ? new File(fileDialog.getDirectory(), filename) : null;
 }
コード例 #4
0
 public File showFileOpenDialog(
     Component parent, File defaultDir, File defaultFile, FilenameFilter filter) {
   FileDialog fileDialog = new FileDialog(getProjectExplorer());
   if (defaultFile != null) {
     if (defaultDir != null) fileDialog.setDirectory(defaultDir.getPath());
     fileDialog.setFile(defaultFile.getName());
   }
   if (filter != null) fileDialog.setFilenameFilter(filter);
   fileDialog.setMode(FileDialog.LOAD);
   fileDialog.setVisible(true);
   String filename = fileDialog.getFile();
   return filename != null ? new File(fileDialog.getDirectory(), filename) : null;
 }
コード例 #5
0
  /**
   * Prompts the user to select a file.
   *
   * @param acceptableSuffixes
   * @return
   */
  private File getFileUsingDialog(final String... acceptableSuffixes) {
    // For some strange reason,
    // the only way to get a Mac OS X native-style file dialog
    // is to use an AWT FileDialog instead of a Swing JDialog
    if (GameRunner.isMac()) {
      final FileDialog fileDialog = new FileDialog(MainFrame.getInstance());
      fileDialog.setMode(FileDialog.LOAD);
      fileDialog.setFilenameFilter(
          new FilenameFilter() {
            public boolean accept(final File dir, final String name) {
              if (acceptableSuffixes == null || acceptableSuffixes.length == 0) return true;
              for (final String suffix : acceptableSuffixes) {
                if (name.toLowerCase().endsWith(suffix)) return true;
              }
              return false;
            }
          });
      fileDialog.setVisible(true);
      final String fileName = fileDialog.getFile();
      final String dirName = fileDialog.getDirectory();
      if (fileName == null) return null;
      return new File(dirName, fileName);
    }
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(final File file) {
            if (file == null) return false;
            else if (file.isDirectory()) return true;
            else {
              final String name = file.getAbsolutePath().toLowerCase();
              for (final String suffix : acceptableSuffixes) {
                if (name.endsWith(suffix)) return true;
              }
              return false;
            }
          }

          @Override
          public String getDescription() {
            return Arrays.toString(acceptableSuffixes);
          }
        });
    final int rVal = fileChooser.showOpenDialog(MainFrame.getInstance());
    if (rVal == JFileChooser.APPROVE_OPTION) {
      return fileChooser.getSelectedFile();
    }
    return null;
  }
コード例 #6
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();
     }
   }
 }
コード例 #7
0
  @Override
  public void execute() {

    if (USE_OMETA) {
      try {
        exportWithOmeta();
      } catch (Exception e) {
        e.printStackTrace();
      }
      return;
    }
    try {
      File dir = new File("/Users/josh/projects/Leo/t2");
      File html = new File(dir, "foo.html");
      File templatedir = new File("resources/");
      if (useRandomFile) {

      } else {

        // get a file to write to
        if (document.getExportFile() != null) {
          html = document.getExportFile();
          dir = html.getParentFile();
        } else {
          java.awt.FileDialog fd = new java.awt.FileDialog((Frame) null);
          fd.setMode(FileDialog.SAVE);
          fd.setVisible(true);
          if (fd.getFile() == null) {
            return;
          }
          String filename = fd.getFile();
          if (!filename.toLowerCase().endsWith(".html")) {
            filename += ".html";
          }
          html = new File(fd.getDirectory(), filename);
          dir = html.getParentFile();
        }
      }

      // File file = File.createTempFile("foo",".html");
      // file.deleteOnExit();
      StringWriter treeContent = new StringWriter();
      PrintWriter treeOut = new PrintWriter(treeContent);
      PropWriter treeWriter = new PropWriter(treeOut);
      StringWriter setupContent = new StringWriter();
      for (Layer layer : page.children()) {
        treeWriter.p("//layer");
        treeWriter.indent();
        for (SketchNode node : layer.children()) {
          DynamicNode dnode = (DynamicNode) node;
          exportNode(treeWriter, dnode, true, dir);
          if (node.isVisual() && AminoAdapter.shouldAddToScene(node, document.getBindings())) {
            setupContent.append("root.add(" + node.getId() + ");\n");
          }
          if (AminoAdapter.useSetup(dnode)) {
            setupContent.append(node.getId() + ".setup(root);\n");
          }
          doExtensions(setupContent, dnode);
        }
        treeWriter.outdent();
      }

      for (Binding binding : document.getBindings()) {
        exportBinding(new PrintWriter(setupContent), binding);
      }

      treeOut.close();
      setupContent.close();

      Map<String, String> subs = new HashMap<String, String>();
      subs.put("tree", treeContent.toString());
      subs.put("setup", setupContent.toString());

      if (!html.exists()) {
        StringUtils.applyTemplate(new File(templatedir, "index_template.html"), html, subs);
      }
      File js = new File(dir, "generated.js");
      StringUtils.applyTemplate(new File(templatedir, "generated_template.js"), js, subs);
      StringUtils.copyFile(new File(templatedir, "amino.js"), new File(dir, "amino.js"));
      StringUtils.copyFile(new File(templatedir, "jquery.js"), new File(dir, "jquery.js"));
      StringUtils.copyFile(new File(templatedir, "controls.js"), new File(dir, "controls.js"));

      File trimfile = new File("/Users/josh/");
      String partialPath =
          dir.getAbsolutePath().substring((int) trimfile.getAbsolutePath().length());
      OSUtil.openBrowser("http://localhost/~josh/" + partialPath + "/" + html.getName());

      document.setExportFile(html);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #8
0
ファイル: FileUtil.java プロジェクト: Gambini/gdx-fontpack
  public File browse(
      Component parent,
      BrowseType browseType,
      FileType fileType,
      PrefType prefType,
      boolean dirsOnly,
      String startingDir) {
    init(parent);

    try {
      prefs.sync();
    } catch (BackingStoreException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    File selFile = null;
    if (startingDir != null) {
      File f = new File(startingDir);

      if (f.isFile()) //
      startingDir = f.getParent();
      else {
        if (!f.exists()) f.mkdir();

        if (dirsOnly) { // make parent dir the starting dir, if it exists
          startingDir = f.getParent();
          selFile = f;
        }
      }
    }

    String lastDir =
        startingDir != null && startingDir.length() != 0
            ? startingDir
            : prefs.get("file." + browseType.name() + "." + prefType.name(), null);
    if (lastDir == null) {
      if (prefType == PrefType.FontLoad) {
        lastDir = getBestFontPath();
      } else {
        lastDir = System.getProperty("user.home");
      }
    }

    File lastDirFile = new File(lastDir);
    String lastDirFileName = "";
    if (lastDirFile.exists() && lastDirFile.isFile()) lastDirFileName = lastDirFile.getName();

    File file = null;

    if (useJFileChooser) {
      jFileChooser.setFileFilter(fileType.swingFilter);

      jFileChooser.setCurrentDirectory(new File(lastDir));

      if (selFile != null) jFileChooser.setSelectedFile(selFile);

      jFileChooser.setFileSelectionMode(
          dirsOnly ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_ONLY);
      int a =
          browseType == BrowseType.Open
              ? jFileChooser.showOpenDialog(parent)
              : jFileChooser.showSaveDialog(parent);
      if (a == JFileChooser.APPROVE_OPTION) {
        prefs.put(
            "file." + browseType.name(), jFileChooser.getCurrentDirectory().getAbsolutePath());
        file = jFileChooser.getSelectedFile();
      }
    } else {
      System.setProperty("apple.awt.fileDialogForDirectories", Boolean.toString(dirsOnly));

      fileDialog.setAlwaysOnTop(true);
      fileDialog.setFilenameFilter(fileType.awtFilter);
      fileDialog.setDirectory(lastDir);
      fileDialog.setFile(lastDirFileName);
      fileDialog.setMode(browseType == BrowseType.Open ? FileDialog.LOAD : FileDialog.SAVE);
      fileDialog.setVisible(true);
      String res = fileDialog.getFile();
      if (res != null) {
        File ret = new File(fileDialog.getDirectory(), res);
        File dir = ret;
        if (dir.getParentFile() != null && !dir.isDirectory()) dir = dir.getParentFile();
        prefs.put("file." + browseType.name(), dir.getAbsolutePath());
        file = ret;
      }
    }

    if (file != null) {
      try {
        prefs.flush();
      } catch (BackingStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return file;
  }