Java Reference
In-Depth Information
files.removeChoosableFileFilter(sketchFilter); // Removes our
filter
This would remove the filter you have defined for Sketcher files.
Implementing the Save As Operation
For Save As operations, you always want to display a save dialog, regardless of whether the file has been
saved before, and ignoring the state of the sketchChanged flag. Apart from that and some cosmetic dif-
ferences in the dialog itself, the operation is very similar to the Save menu item event handling. With the
showDialog() method that you have added to the SketcherFrame class, the implementation becomes quite
easy.
TRY IT OUT: File Save As Operations
You can do the trivial bit first. The code in the else if block in the actionPerformed() method in the
FileAction class for this operation is:
else if(this == saveAsAction) {
saveAsOperation();
return;
}
Directory "Sketcher 2 with Save As capability"
Now the bit with more meat — the implementation of the saveAsOperation() method in the Sketch-
erFrame class:
private void saveAsOperation() {
Path file = showDialog("Save Sketch As",
"Save",
"Save the sketch",
sketchFilter,
currentSketchFile == null ?
Paths.get(DEFAULT_FILENAME):
currentSketchFile);
if(file == null) {
// No file
selected...
return;
// ...so we
Search WWH ::




Custom Search