GUI Commands User GuideVersion 2.1 |
||
File CommandsGUI Commands provides standard command implementations for opening and saving files as well
as a recent files group. These commands perform a lot of the grunt work associated with opening
and saving files by displaying the file chooser and checking if the file already exists. The
RecentFileList makes it easy to display the list of recently opened files and provides convenience
methods for storing the list in a AbstractFileOpenCommandThe following shows a basic implementation of a file open command:
public class OpenCommand extends AbstractFileOpenCommand
{
public OpenCommand()
{
super("open");
}
/**
* Invoked after the user has selected
* the file in the JFileChooser
*/
public void performOpen(File[] files)
{
...open the file
}
}
AbstractSaveAsCommandA basic implementation of a "save as" command:
public class SaveAsCommand extends AbstractSaveAsCommand
{
public SaveAsCommand()
{
super("save-as");
}
/**
* Invoked after the user has selected the
* file in the JFileChooser and confirmed
* overwrite if the file already exists
*/
public void performSave(File file)
{
...save the file
}
}
You can control the dialog shown to users when the selected file already exists by
defining the properties
save-as@face.text=Save _As
save-as@properties[overwriteTitle]=Are you sure?
save-as@properties[overwriteMessage]=\
The file ''{0}'' exists, \
do you want to overwrite it?
If you need more control you can override the |
||