Class AbstractApplication

  • All Implemented Interfaces:
    Application
    Direct Known Subclasses:
    ApplicationTutorial, MDIApplication

    public abstract class AbstractApplication
    extends java.lang.Object
    implements Application
    An abstract implementation of the Application interface. This class implements the common elements of the Application abstraction, and takes care of listener notification for documents and properties. Concrete subclasses will generally override a number of these methods to add their own behavior. Most importantly, this abstract class does not provide any support for creating documents, or managing the views of those documents. For an example of one way of managing the view associated with a document, see MDIApplication.
    Version:
    $Id$
    Author:
    John Reekie
    Pt.AcceptedRating:
    Red
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractApplication​(AppContext context)
      Create an abstract application that resides in the given context (e.g.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.util.Iterator actions()
      Get an iterator over the names of the actions that are contained by this application.
      void addAction​(javax.swing.Action action)
      Add an action to the table of actions.
      void addDocument​(Document d)
      Add a document to the list of documents currently known by this application.
      void addDocumentListener​(javax.swing.event.ListDataListener listener)
      Add a document listener to this application.
      javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu, java.lang.String label, javax.swing.Action action, int mnemonic, java.lang.String tooltip, boolean isEnabled)
      Deprecated.
      Use method in GUIUtilities instead.
      javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu, javax.swing.Action action, int mnemonic, java.lang.String tooltip)
      Deprecated.
      Use method in GUIUtilities instead.
      void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Add a property change listener to this application.
      javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon)
      Deprecated.
      Use method in GUIUtilities instead.
      javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon, boolean isEnabled)
      Deprecated.
      Use method in GUIUtilities instead.
      void addView​(View v)
      Add a view to the list of views currently known by this application.
      void addViewListener​(javax.swing.event.ListDataListener listener)
      Add a view listener to this application.
      boolean closeDocument​(Document d)
      Try to close the given document using the storage policy.
      boolean closeView​(View v)
      Try to close the given view using the storage policy.
      abstract View createView​(Document d)
      Create a view to display the given document.
      java.util.List documentList()
      Get list of all document objects known by this application.
      javax.swing.Action getAction​(java.lang.String name)
      Get an action by name.
      AppContext getAppContext()
      Get the frame that this application draws itself in.
      java.awt.datatransfer.Clipboard getClipboard()
      Get the clipboard object for this application.
      View getCurrentView()
      Get the current view.
      DocumentFactory getDocumentFactory()
      Get the factory that creates new documents
      RelativeBundle getResources()
      Get the resources object.
      StoragePolicy getStoragePolicy()
      Get the storage policy of this application.
      abstract java.lang.String getTitle()
      Get the title of this application
      boolean isVisible()
      Test whether the application frame is visible.
      void removeDocument​(Document d)
      Remove a document from the list of documents currently known by this application, and remove all of the views associated with this document.
      void removeDocumentListener​(javax.swing.event.ListDataListener listener)
      Remove a document list listener from this application.
      void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
      Remove a property change listener from this application.
      void removeView​(View v)
      Remove a view from the list of views currently known by this application.
      void removeViewListener​(javax.swing.event.ListDataListener listener)
      Remove a view list listener from this application.
      protected void setAppContext​(AppContext ac)
      Set the app context that this application draws itself in.
      void setClipboard​(java.awt.datatransfer.Clipboard clipboard)
      Set the clipboard that is used by this application.
      void setCurrentView​(View v)
      Set the given view to be the current view.
      protected void setDocumentFactory​(DocumentFactory df)
      Set the factory that creates new documents for use by subclasses constructors only.
      void setStoragePolicy​(StoragePolicy sp)
      Set the storage policy of this application, for use by subclass constructors only
      void setVisible​(boolean visible)
      Set the visibility of the application's frame
      void showError​(java.lang.String op, java.lang.Exception e)
      Show an error in a dialog box with stack trace.
      java.util.List viewList()
      Get a list of all view objects known by this application.
      java.util.List viewList​(Document d)
      Get a list of all view objects known by this application.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractApplication

        public AbstractApplication​(AppContext context)
        Create an abstract application that resides in the given context (e.g. a frame or an applet).
    • Method Detail

      • actions

        public java.util.Iterator actions()
        Get an iterator over the names of the actions that are contained by this application.
        Specified by:
        actions in interface Application
      • addAction

        public void addAction​(javax.swing.Action action)
        Add an action to the table of actions. Every action known by the application should be added here so it can be retrieved and invoked later.
        Specified by:
        addAction in interface Application
      • addMenuItem

        @Deprecated
        public javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu,
                                                 javax.swing.Action action,
                                                 int mnemonic,
                                                 java.lang.String tooltip)
        Deprecated.
        Use method in GUIUtilities instead.
        Add an action to a menu and return the menu item created. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. (The mnemonic isn't added.) The new menu item is added to the action as the "menuItem" property. The menu item's text is set using the action's name and is enabled by default.
      • addMenuItem

        @Deprecated
        public javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu,
                                                 java.lang.String label,
                                                 javax.swing.Action action,
                                                 int mnemonic,
                                                 java.lang.String tooltip,
                                                 boolean isEnabled)
        Deprecated.
        Use method in GUIUtilities instead.
        Add an action to a menu and return the menu item created. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. (The mnemonic isn't added.) The new menu item is added to the action as the "menuItem" property. The menu item's text is set to be "label", and is disabled or enabled according to "isEnabled."
      • addToolBarButton

        @Deprecated
        public javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                    javax.swing.Action action,
                                                    java.lang.String tooltip,
                                                    javax.swing.Icon icon)
        Deprecated.
        Use method in GUIUtilities instead.
        Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property. The button is enabled by default.
      • addToolBarButton

        @Deprecated
        public javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                    javax.swing.Action action,
                                                    java.lang.String tooltip,
                                                    javax.swing.Icon icon,
                                                    boolean isEnabled)
        Deprecated.
        Use method in GUIUtilities instead.
        Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property.
      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Add a property change listener to this application. Changes to certain elements of the state will cause all registered property listeners to be notified.
        Specified by:
        addPropertyChangeListener in interface Application
      • addDocument

        public void addDocument​(Document d)
        Add a document to the list of documents currently known by this application. Fire a document list event to registered listeners. Throw an exception if the document is already in the list of documents.
        Specified by:
        addDocument in interface Application
      • addView

        public void addView​(View v)
        Add a view to the list of views currently known by this application. Fire a view list event to registered listeners. Throw an exception if the view is already in the list of views.
        Specified by:
        addView in interface Application
      • addDocumentListener

        public void addDocumentListener​(javax.swing.event.ListDataListener listener)
        Add a document listener to this application. The document listener is in fact a ListDataListener, which will be notified with intervalAdded() and intervalRemoved() events when documents are added or removed, and with a contentsChanged() event when the current document is changed.
        Specified by:
        addDocumentListener in interface Application
      • addViewListener

        public void addViewListener​(javax.swing.event.ListDataListener listener)
        Add a view listener to this application. The view listener is in fact a ListDataListener, which will be notified with intervalAdded() and intervalRemoved() events when views are added or removed, and with a contentsChanged() event when the current view is changed.
        Specified by:
        addViewListener in interface Application
      • closeDocument

        public boolean closeDocument​(Document d)
        Try to close the given document using the storage policy.
        Specified by:
        closeDocument in interface Application
      • closeView

        public boolean closeView​(View v)
        Try to close the given view using the storage policy.
        Specified by:
        closeView in interface Application
      • createView

        public abstract View createView​(Document d)
        Create a view to display the given document. The document should already be added to the application. After calling this method, most callers should set this view to be the current view.
        Specified by:
        createView in interface Application
      • documentList

        public java.util.List documentList()
        Get list of all document objects known by this application.
        Specified by:
        documentList in interface Application
      • getAction

        public javax.swing.Action getAction​(java.lang.String name)
        Get an action by name.
        Specified by:
        getAction in interface Application
      • getClipboard

        public java.awt.datatransfer.Clipboard getClipboard()
        Get the clipboard object for this application.
        Specified by:
        getClipboard in interface Application
      • getCurrentView

        public View getCurrentView()
        Get the current view. Generally, this will be the one that is displayed in the window that is top-most in the display.
        Specified by:
        getCurrentView in interface Application
      • getResources

        public RelativeBundle getResources()
        Get the resources object.
      • getTitle

        public abstract java.lang.String getTitle()
        Get the title of this application
        Specified by:
        getTitle in interface Application
      • isVisible

        public boolean isVisible()
        Test whether the application frame is visible. Return false if the application has no frame or if the frame is not visible.
        Specified by:
        isVisible in interface Application
      • removeDocument

        public void removeDocument​(Document d)
        Remove a document from the list of documents currently known by this application, and remove all of the views associated with this document. Fire a list data event to registered document listeners. Throw an exception if the document is not known.
        Specified by:
        removeDocument in interface Application
      • removeView

        public void removeView​(View v)
        Remove a view from the list of views currently known by this application. Fire a list data event to registered view listeners. If the removed view is the current view it is up to the application to decide which view to display next. Throw an exception if the view is not known.
        Specified by:
        removeView in interface Application
      • removeDocumentListener

        public void removeDocumentListener​(javax.swing.event.ListDataListener listener)
        Remove a document list listener from this application.
        Specified by:
        removeDocumentListener in interface Application
      • removeViewListener

        public void removeViewListener​(javax.swing.event.ListDataListener listener)
        Remove a view list listener from this application.
        Specified by:
        removeViewListener in interface Application
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
        Remove a property change listener from this application.
        Specified by:
        removePropertyChangeListener in interface Application
      • setClipboard

        public void setClipboard​(java.awt.datatransfer.Clipboard clipboard)
        Set the clipboard that is used by this application. This is generally used by subclass constructors. To use the system clipboard use something like setClipboard(Toolkit.getDefaultToolkit().getSystemClipboard())
      • setCurrentView

        public void setCurrentView​(View v)
        Set the given view to be the current view. Fire a contentsChanged() event to registered view listeners. Throw an exception if the view is not known.
        Specified by:
        setCurrentView in interface Application
      • setDocumentFactory

        protected void setDocumentFactory​(DocumentFactory df)
        Set the factory that creates new documents for use by subclasses constructors only.
      • setStoragePolicy

        public void setStoragePolicy​(StoragePolicy sp)
        Set the storage policy of this application, for use by subclass constructors only
      • setVisible

        public void setVisible​(boolean visible)
        Set the visibility of the application's frame
        Specified by:
        setVisible in interface Application
      • showError

        public void showError​(java.lang.String op,
                              java.lang.Exception e)
        Show an error in a dialog box with stack trace.
        Specified by:
        showError in interface Application
      • setAppContext

        protected void setAppContext​(AppContext ac)
        Set the app context that this application draws itself in. For use by subclass constructors only.
      • viewList

        public java.util.List viewList()
        Get a list of all view objects known by this application.
        Specified by:
        viewList in interface Application
      • viewList

        public java.util.List viewList​(Document d)
        Get a list of all view objects known by this application.