@Override
 public void setSelectedIndex(int ind) {
   super.setSelectedIndex(ind);
   editor.setText(getItemAt(ind).toString());
   editor.setSelectionEnd(caretPos + editor.getText().length());
   editor.moveCaretPosition(caretPos);
 }
Beispiel #2
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }