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(); } } } }
private void browseAction() { if (selectedPath == null) { selectedPath = System.getenv("ROPE_SOURCES_DIR"); if (selectedPath != null) { File dir = new File(selectedPath); if (!dir.exists() || !dir.isDirectory()) { String message = String.format( "The sources path set in environment variable ROPE_SOURCES_DIR is not avaliable.\n%s", selectedPath); JOptionPane.showMessageDialog(null, message, "ROPE", JOptionPane.WARNING_MESSAGE); selectedPath = null; } else { System.out.println("Source folder path set from ROPE_SOURCES_DIR: " + selectedPath); } } if (selectedPath == null) { selectedPath = System.getProperty("user.dir"); System.out.println("Source folder path set to current directory: " + selectedPath); } } Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>(); 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[] {".lst"}, "List files (*.lst)")); filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)")); RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters); chooser.setDialogTitle("Source document selection"); chooser.setFileFilter(filters.firstElement()); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); File file = chooser.open(this, fileText); if (file != null) { if (loadSourceFile(file)) { mainFrame.showExecWindow(baseName); } } }