if (edit) {
Object[] options = {"Save", "No Save", "Return"};
int n = JOptionPane.showOptionDialog(this, "Do you want to save changes ?", "Question",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
if (n == 0) {// save
saveFile();
edit = false;
} else if (n == 1) {
edit = false;
openFile();
}
}
else{
openFile();
}
}
/*
* NOTE: because we are OPENing a file, we call showOpenDialog~ if
* the user clicked OK, we have "APPROVE_OPTION" so we want to open
* the file
*/
if (option == JFileChooser.APPROVE_OPTION) {
FEdit.clear(textArea); // clear the TextArea before applying the file contents
try {
File openFile = open.getSelectedFile();
setTitle(openFile.getName() + " | " + SimpleJavaTextEditor.NAME);
Scanner scan = new Scanner(new FileReader(openFile.getPath()));
while (scan.hasNext()) {
textArea.append(scan.nextLine() + "\n");
}
enableAutoComplete(openFile);
} catch (Exception ex) { // catch any exceptions, and...
// ...write to the debug console
System.err.println(ex.getMessage());
}
}
}