示例#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
  protected void showFileChooser() {
    File p;
    FileDialog fDlg;
    String fDir, fFile; // , fPath;
    //		int			i;
    Component win;

    for (win = this; !(win instanceof Frame); ) {
      win = SwingUtilities.getWindowAncestor(win);
      if (win == null) return;
    }

    p = getPath();
    switch (type & PathField.TYPE_BASICMASK) {
      case PathField.TYPE_INPUTFILE:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.LOAD);
        break;
      case PathField.TYPE_OUTPUTFILE:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE);
        break;
      case PathField.TYPE_FOLDER:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE);
        // fDlg = new FolderDialog( (Frame) win, dlgTxt );
        break;
      default:
        fDlg = null;
        assert false : (type & PathField.TYPE_BASICMASK);
        break;
    }
    if (p != null) {
      fDlg.setFile(p.getName());
      fDlg.setDirectory(p.getParent());
    }
    if (filter != null) {
      fDlg.setFilenameFilter(filter);
    }
    showDialog(fDlg);
    fDir = fDlg.getDirectory();
    fFile = fDlg.getFile();

    if (((type & PathField.TYPE_BASICMASK) != PathField.TYPE_FOLDER) && (fDir == null)) {
      fDir = "";
    }

    if ((fFile != null) && (fDir != null)) {

      if ((type & PathField.TYPE_BASICMASK) == PathField.TYPE_FOLDER) {
        p = new File(fDir);
      } else {
        p = new File(fDir + fFile);
      }
      setPathAndDispatchEvent(p);
    }

    fDlg.dispose();
  }
示例#3
0
 /**
  * Чтение таблицы из файла
  *
  * @param e
  */
 public void actionPerformed(ActionEvent e) {
   load.setVisible(true);
   String fileName = load.getDirectory() + load.getFile();
   try {
     if (load.getFile() == null) {
       throw new NullFileException();
     }
     Load load = new Load();
     load.LoadXML(fileName, masters, records);
   } catch (NullFileException ex) {
     JOptionPane.showMessageDialog(carsList, ex.getMessage());
   }
   load.setFile("*.xml");
 }
示例#4
0
  /**
   * Handles 'Save As' for a sketch.
   *
   * <p>This basically just duplicates the current sketch folder to a new location, and then calls
   * 'Save'. (needs to take the current state of the open files and save them to the new folder..
   * but not save over the old versions for the old sketch..)
   *
   * <p>Also removes the previously-generated .class and .jar files, because they can cause trouble.
   */
  protected boolean saveAs() throws IOException {
    // get new name for folder
    FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())
        || isUntitled()) {
      // default to the sketchbook folder
      fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
    } else {
      // default to the parent folder of where this was
      // on macs a .getParentFile() method is required

      fd.setDirectory(sketch.getFolder().getParentFile().getAbsolutePath());
    }
    String oldName = sketch.getName();
    fd.setFile(oldName);

    fd.setVisible(true);
    String newParentDir = fd.getDirectory();
    String newName = fd.getFile();

    // user canceled selection
    if (newName == null) return false;
    newName = SketchController.checkName(newName);

    File newFolder = new File(newParentDir, newName);

    // check if the paths are identical
    if (newFolder.equals(sketch.getFolder())) {
      // just use "save" here instead, because the user will have received a
      // message (from the operating system) about "do you want to replace?"
      return save();
    }

    // check to see if the user is trying to save this sketch inside itself
    try {
      String newPath = newFolder.getCanonicalPath() + File.separator;
      String oldPath = sketch.getFolder().getCanonicalPath() + File.separator;

      if (newPath.indexOf(oldPath) == 0) {
        Base.showWarning(
            tr("How very Borges of you"),
            tr(
                "You cannot save the sketch into a folder\n"
                    + "inside itself. This would go on forever."),
            null);
        return false;
      }
    } catch (IOException e) {
      // ignore
    }

    // if the new folder already exists, then need to remove
    // its contents before copying everything over
    // (user will have already been warned)
    if (newFolder.exists()) {
      FileUtils.recursiveDelete(newFolder);
    }
    // in fact, you can't do this on windows because the file dialog
    // will instead put you inside the folder, but it happens on osx a lot.

    try {
      sketch.saveAs(newFolder);
    } catch (IOException e) {
      // This does not pass on e, to prevent showing a backtrace for "normal"
      // errors.
      Base.showWarning(tr("Error"), e.getMessage(), null);
    }
    // Name changed, rebuild the sketch menus
    // editor.sketchbook.rebuildMenusAsync();
    editor.base.rebuildSketchbookMenus();
    editor.header.rebuild();

    // Make sure that it's not an untitled sketch
    setUntitled(false);

    // let Editor know that the save was successful
    return true;
  }