コード例 #1
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();
   }
 }
コード例 #2
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /** This method cannot be called directly. */
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
コード例 #3
0
ファイル: Layout.java プロジェクト: ptrsz/nagyhf
    @Override
    public void actionPerformed(ActionEvent event) {
      String command = event.getActionCommand();
      if (command.equals("add")) {
        MultipleInputDialog inputDialog = new MultipleInputDialog();
        data.add(inputDialog.getDialogCar());

      } else if (command.equals("save")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.SAVE);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileOutputStream fileOut = new FileOutputStream(dir + filename);
          ObjectOutputStream out = new ObjectOutputStream(fileOut);
          out.writeObject(Layout.this.data);
          out.close();
          fileOut.close();
          System.out.println("save OK");
          System.out.println("Kiirva 1/1 adat " + data.get(1).getOne());

        } catch (IOException i) {
          i.printStackTrace();
        }
      } else if (command.equals("load")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.LOAD);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileInputStream fileIn = new FileInputStream(dir + filename);
          ObjectInputStream in = new ObjectInputStream(fileIn);

          Layout.this.data = (ArrayList<Car>) in.readObject();
          dataTable.repaint();

          fileIn.close();
          in.close();

          System.out.println("beolvasva");
          repaint();

          System.out.println("olvasva 1/1 adat data-ban " + data.get(1).getOne());
        } catch (IOException i) {
          i.printStackTrace();
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (command.equals("browse")) {
        FileDialog jf = new FileDialog(Layout.this, "Choose something", FileDialog.LOAD);
        jf.setVisible(true);
      }
    }
コード例 #4
0
  public static File FileSaveDialog(String title) {
    // Open File Dialog:
    FileDialog filedialog = new FileDialog((Frame) null, title, FileDialog.SAVE);
    filedialog.setVisible(true);
    File fileSelected = null;
    try {
      fileSelected = new File(filedialog.getDirectory(), filedialog.getFile());
    } catch (Exception e) {

    }
    return fileSelected;
  }
コード例 #5
0
ファイル: ActionLoadListener.java プロジェクト: Enotkin/test
 /**
  * Чтение таблицы из файла
  *
  * @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");
 }
コード例 #6
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();
    }
  }
コード例 #7
0
ファイル: SelectPathButton.java プロジェクト: ynohtna/FScape
  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();
  }
コード例 #8
0
  /**
   * Prompt the user for a new file to the sketch, then call the other addFile() function to
   * actually add it.
   */
  public void handleAddFile() {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    // if read-only, give an error
    if (isReadOnly(
        BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
      // if the files are read-only, need to first do a "save as".
      Base.showMessage(
          tr("Sketch is Read-Only"),
          tr(
              "Some files are marked \"read-only\", so you'll\n"
                  + "need to re-save the sketch in another location,\n"
                  + "and try again."));
      return;
    }

    // get a dialog, select a file to add to the sketch
    FileDialog fd =
        new FileDialog(
            editor,
            tr("Select an image or other data file to copy to your sketch"),
            FileDialog.LOAD);
    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();
    if (filename == null) return;

    // copy the file into the folder. if people would rather
    // it move instead of copy, they can do it by hand
    File sourceFile = new File(directory, filename);

    // now do the work of adding the file
    boolean result = addFile(sourceFile);

    if (result) {
      editor.statusNotice(tr("One file added to the sketch."));
      PreferencesData.set("last.folder", sourceFile.getAbsolutePath());
    }
  }
コード例 #9
0
ファイル: PathogenFrame.java プロジェクト: stevenhwu/ABI
  protected void doExportData() {
    FileDialog dialog = new FileDialog(this, "Export Data File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      Writer writer = null;
      try {
        writer = new PrintWriter(file);
        treesPanel.writeDataFile(writer);
        writer.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing data file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
コード例 #10
0
ファイル: PathogenFrame.java プロジェクト: stevenhwu/ABI
  private void doExportTimeTree() {
    FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      PrintStream ps = null;
      try {
        ps = new PrintStream(file);
        writeTimeTreeFile(ps);
        ps.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing tree file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
コード例 #11
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Checks whether the given window is either a FileDialog, or contains a JFileChooser component.
   * If so, its current directory is stored in the given properties.
   *
   * @param aNamespace the name space to use;
   * @param aProperties the properties to store the found directory in;
   * @param aWindow the window to check for.
   */
  private static void loadFileDialogState(final Preferences aProperties, final Window aWindow) {
    final String propKey = "lastDirectory";

    if (aWindow instanceof FileDialog) {
      final String dir = aProperties.get(propKey, null);
      if (dir != null) {
        ((FileDialog) aWindow).setDirectory(dir);
      }
    } else if (aWindow instanceof JDialog) {
      final Container contentPane = ((JDialog) aWindow).getContentPane();
      final JFileChooser fileChooser =
          (JFileChooser) findComponent(contentPane, JFileChooser.class);
      if (fileChooser != null) {
        final String dir = aProperties.get(propKey, null);
        if (dir != null) {
          fileChooser.setCurrentDirectory(new File(dir));
        }
      }
    }
  }
コード例 #12
0
  /** Handle ItemEvents. */
  public void itemStateChanged(ItemEvent e) {

    final String dialog_title = ResourceHandler.getMessage("template_dialog.title");

    Component target = (Component) e.getSource();

    if (target == recursiveCheckBox) {
      converter.setRecurse(recursiveCheckBox.isSelected());
    } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) {
      converter.setStaticVersioning(staticVersioningRadioButton.isSelected());
    } else if (target == templateCh
        && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected

      // Get the current template selection
      String choiceStr = (String) templateCh.getSelectedItem();

      // If the user chooses 'other', display a file dialog to allow
      // them to select a template file.
      if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) {
        String templatePath = null;
        FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD);
        fd.show();

        // Capture the path entered, if any.
        if (fd.getDirectory() != null && fd.getFile() != null) {
          templatePath = fd.getDirectory() + fd.getFile();
        }

        // If the template file is valid add it and select it.
        if (templatePath != null && setTemplateFile(templatePath)) {
          if (!templateCh.testIfInList(templatePath)) {
            templateCh.addItem(templatePath);
          }
          templateCh.select(templatePath);
        } else {
          templateCh.select(templateCh.getPreviousSelection());
        }
        fd.dispose();
      } else {
        templateCh.select(choiceStr);
      }
    }
  }
コード例 #13
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Shows a file-open selection dialog for the given working directory.
   *
   * @param aOwner the owning window to show the dialog in;
   * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code>
   *     .
   * @return the selected file, or <code>null</code> if the user aborted the dialog.
   */
  public static final File showFileOpenDialog(
      final Window aOwner,
      final String aCurrentDirectory,
      final javax.swing.filechooser.FileFilter... aFileFilters) {
    if (HostUtils.isMacOS()) {
      final FileDialog dialog;
      if (aOwner instanceof Dialog) {
        dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD);
      } else {
        dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD);
      }
      dialog.setDirectory(aCurrentDirectory);

      if ((aFileFilters != null) && (aFileFilters.length > 0)) {
        dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters));
      }

      try {
        dialog.setVisible(true);
        final String selectedFile = dialog.getFile();
        return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile);
      } finally {
        dialog.dispose();
      }
    } else {
      final JFileChooser dialog = new JFileChooser();
      dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory));

      for (javax.swing.filechooser.FileFilter filter : aFileFilters) {
        dialog.addChoosableFileFilter(filter);
      }

      File result = null;
      if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) {
        result = dialog.getSelectedFile();
      }

      return result;
    }
  }
コード例 #14
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }
コード例 #15
0
  paintboard1(String s) {
    super(s);
    addMouseMotionListener(this);
    addMouseListener(this);

    paintInfo = new Vector();

    /* 各工具按钮及选择项 */
    // 颜色选择
    ColChoice = new Choice();
    ColChoice.add("black");
    ColChoice.add("red");
    ColChoice.add("blue");
    ColChoice.add("green");
    ColChoice.addItemListener(this);
    // 画笔大小选择
    SizeChoice = new Choice();
    SizeChoice.add("1");
    SizeChoice.add("3");
    SizeChoice.add("5");
    SizeChoice.add("7");
    SizeChoice.add("9");
    SizeChoice.addItemListener(this);
    // 橡皮大小选择
    EraserChoice = new Choice();
    EraserChoice.add("5");
    EraserChoice.add("9");
    EraserChoice.add("13");
    EraserChoice.add("17");
    EraserChoice.addItemListener(this);
    // //////////////////////////////////////////////////
    toolPanel = new Panel();

    clear = new Button("清除");
    eraser = new Button("橡皮");
    pen = new Button("画笔");
    drLine = new Button("画直线");
    drCircle = new Button("画圆形");
    drRect = new Button("画矩形");

    openPic = new Button("打开图画");
    savePic = new Button("保存图画");

    colchooser = new Button("显示调色板");

    // 各组件事件监听
    clear.addActionListener(this);
    eraser.addActionListener(this);
    pen.addActionListener(this);
    drLine.addActionListener(this);
    drCircle.addActionListener(this);
    drRect.addActionListener(this);
    openPic.addActionListener(this);
    savePic.addActionListener(this);
    colchooser.addActionListener(this);

    颜色 = new Label("画笔颜色", Label.CENTER);
    大小B = new Label("画笔大小", Label.CENTER);
    大小E = new Label("橡皮大小", Label.CENTER);
    // 面板添加组件
    toolPanel.add(openPic);
    toolPanel.add(savePic);

    toolPanel.add(pen);
    toolPanel.add(drLine);
    toolPanel.add(drCircle);
    toolPanel.add(drRect);

    toolPanel.add(颜色);
    toolPanel.add(ColChoice);
    toolPanel.add(大小B);
    toolPanel.add(SizeChoice);
    toolPanel.add(colchooser);

    toolPanel.add(eraser);
    toolPanel.add(大小E);
    toolPanel.add(EraserChoice);

    toolPanel.add(clear);
    // 工具面板到APPLET面板
    add(toolPanel, BorderLayout.NORTH);

    setBounds(230, 50, 900, 650);
    setVisible(true);
    validate();
    // dialog for save and load

    openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD);
    openPicture.setVisible(false);
    savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE);
    savePicture.setVisible(false);

    openPicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            openPicture.setVisible(false);
          }
        });

    savePicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            savePicture.setVisible(false);
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
コード例 #16
0
ファイル: TV.java プロジェクト: bibhutibhusan89/Jafun
  /** Construct the TV object - that is, the main GUI for the program */
  public TV(JFrame f, TD mod) {
    super();
    frm = f;
    theTD = mod;
    JButton b;

    // Build the GUI

    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.getAccessibleContext().setAccessibleName("File Toolbar");
    toolBar.addSeparator();
    b = addTool(toolBar, "Cut");
    b = addTool(toolBar, "Copy");
    b = addTool(toolBar, "Paste");
    toolBar.addSeparator();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.FALSE);

    // The Slider
    numSlider = new JSlider(JSlider.HORIZONTAL, 1, 40, 1);
    numSlider.setPaintTicks(true);
    numSlider.setPaintLabels(false);
    numSlider.setMajorTickSpacing(10);
    numSlider.setMinorTickSpacing(2);
    numSlider.setExtent(1);
    numSlider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent ce) {
            // System.out.println("CHANGE: " + ce);
            setQNumber(((JSlider) (ce.getSource())).getValue());
          }
        });
    numSlider.setToolTipText("Slide to select question by number");
    toolBar.add(numSlider);

    // The Question# textfield
    toolBar.add(numTF = new JTextField("01"));
    numTF.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String num = ((JTextField) e.getSource()).getText();
            int n = Integer.parseInt(num.trim());
            setQNumber(n);
          }
        });
    numTF.setToolTipText("Type number to select question by number");

    // The First Button
    b = addTool(toolBar, "First");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setQNumber(1);
          }
        });

    // The Previous Button
    b = addTool(toolBar, "Previous");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (getQNumber() <= 1) return;
            setQNumber(getQNumber() - 1);
          }
        });

    // The Next Button
    b = addTool(toolBar, "Next");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (getQNumber() >= getNumQuestions()) return;
            setQNumber(getQNumber() + 1);
          }
        });

    // The "Last" Button
    b = addTool(toolBar, "Last");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setQNumber(getNumQuestions());
          }
        });

    add(BorderLayout.NORTH, toolBar);

    // Rest is a panel to hold the questions, one at a time.
    questionsPanel = new JPanel();
    questionsPanel.setLayout(myCardLayout = new CardLayout());

    add(BorderLayout.SOUTH, questionsPanel);

    fc = new FileDialog(frm);
    fc.setFilenameFilter(
        new FilenameFilter() {
          public boolean accept(File ff, String fname) {
            // System.out.println("accept("+fname+")");
            // XXX TODO list of extentions, from properties.
            return fname.endsWith(".xam");
          }
        });
    TV.centre(fc);
  }
コード例 #17
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;
  }