| This is a very simple example of a SingleFrameApplication that
loads and saves a single text document. Although it does not
possess all of the usual trappings of a single-document app,
like versioning or support for undo/redo, it does serve
to highlight how to use actions, resources, and tasks.
This file contains the main class of the application. It extends the
Swing Application Framework's
SingleFrameApplication class
and therefore takes care or simplifies things like
loading resources and saving the session state.
This class calls the
DocumentEditorView class, which
contains the code for constructing the user interface and
the application logic.
The application's state is defined by two read-only bound properties:
- File
DocumentEditorApp.getFile file
-
- The current text File being edited.
- boolean
modified.isModified
-
- True if the current file needs to be saved.
These properties are updated when the user interacts with the
application. They can be used as binding sources, to monitor
the application's state.
This application defines a small set of actions for opening
and saving files:
DocumentEditorApp.open open ,
DocumentEditorApp.save save ,
and
DocumentEditorApp.saveAs saveAs . It inherits
cut/copy/paste/delete ProxyActions from the
Application class. The ProxyActions perform their
action not on the component they're bound to (menu items and
toolbar buttons), but on the component that currently
has the keyboard focus. Their enabled state tracks the
selection value of the component with the keyboard focus,
as well as the contents of the system clipboard.
The action code that reads and writes files, runs asynchronously
on background threads. The
DocumentEditorApp.open open ,
DocumentEditorApp.save save ,
and
DocumentEditorApp.saveAs saveAs actions all return a Task object which
encapsulates the work that will be done on a background thread.
The
DocumentEditorApp.showAboutBox showAboutBox and
DocumentEditorApp.closeAboutBox closeAboutBox actions do their work
synchronously.
Warning: this application is intended as a simple
example, not as a robust text editor. Read it, don't use it.
|