Class AbstractPage

All Implemented Interfaces:
Laziness, ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
AbstractDialogPage

public abstract class AbstractPage extends JPanel implements Laziness
AbstractPage is an abstract base class that provides functionality to defer populating a JPanel object until it is actually viewed. This is very useful when using CardLayout and tab panel views which have several pages. Delaying the construction means it will start up fast. Sometimes delay means never.

If subclasses choose to override any of the following methods, it is their responsibility to ensure their overridden methods call the parent's method first. The methods are:

  • public void paint (Graphics)
  • public void paintComponents(Graphics)
  • public void paintAll (Graphics)
  • public void repaint ()
  • public void repaint (long)
  • public void repaint (int, int, int, int)
  • public void repaint (long, int, int, int, int)
  • public void update (Graphics)

By default, if any of the methods is called, the panel will be populated. However user can setInvokeCondition() to customize when the panel be populated. See javadoc of setInvokeContion() for details.

The idea of the lazy panel is from an article on JavaWorld at http://www.javaworld.com/javatips/jw-javatip90_p.html. The credit should be given to Mark Roulo. We modified the code he provided in the article to add additional things as we need. Things added are

  • Added setInvokeCondition()
  • Added addPageListener(), removePageListener() etc so that subclass can fire PageEvent
See Also:
  • Field Details

    • INVOKE_ON_ALL

      public static int INVOKE_ON_ALL
      Used by setInvokeCondition(). This value means initialize will be called in all paint/repaint/update methods.
    • INVOKE_ON_NONE

      public static int INVOKE_ON_NONE
      Used by setInvokeCondition(). This value means initialize will not be called. You have to call it manually.
    • INVOKE_ON_PAINT

      public static int INVOKE_ON_PAINT
      Used by setInvokeCondition(). This value means initialize will be called with paint() is called.
    • INVOKE_ON_REPAINT

      public static int INVOKE_ON_REPAINT
      Used by setInvokeCondition(). This value means initialize will be called with repaint() is called.
    • INVOKE_ON_UPDATE

      public static int INVOKE_ON_UPDATE
      Used by setInvokeCondition(). This value means initialize will be called with update() is called.
    • INVOKE_ON_VALIDATE

      public static int INVOKE_ON_VALIDATE
      Used by setInvokeCondition(). This value means initialize will be called with invalidate(), revalidate() is called.
    • _pageEvent

      protected transient PageEvent _pageEvent
      Only one DataChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".
  • Constructor Details

    • AbstractPage

      protected AbstractPage()
      Creates an AbstractPage.
  • Method Details

    • getInvokeCondition

      public int getInvokeCondition()
      Gets the invoke condition. Invoke condition defines how lazy the page is. By default, the lazyInitialize() will be called on any update, paint or repaint method. However you can change the invoke condition to INVOKE_ON_PAINT. If so, lazyInitialize() will be called only when paint() method is called. You can even set the invoke condition to INVOKE_ON_NONE. If so, you will be responsible to call lazyInitialize() since none of those methods methods mentioned above will call lazyInitialize().
      Returns:
      the invocation condition
    • setInvokeCondition

      public void setInvokeCondition(int invokeCondition)
      Sets the invoke condition.
      Parameters:
      invokeCondition - the invoke condition.
    • invalidate

      public void invalidate()
      Overrides:
      invalidate in class Container
    • revalidate

      public void revalidate()
      Overrides:
      revalidate in class JComponent
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • paintAll

      public void paintAll(Graphics g)
      Overrides:
      paintAll in class Component
    • paintComponents

      public void paintComponents(Graphics g)
      Overrides:
      paintComponents in class Container
    • repaint

      public void repaint()
      Overrides:
      repaint in class Component
    • repaint

      public void repaint(long l)
      Overrides:
      repaint in class Component
    • repaint

      public void repaint(int i1, int i2, int i3, int i4)
      Overrides:
      repaint in class Component
    • repaint

      public void repaint(long l, int i1, int i2, int i3, int i4)
      Overrides:
      repaint in class JComponent
    • update

      public void update(Graphics g)
      Overrides:
      update in class JComponent
    • initialize

      public final void initialize()
      Force the lazyInitialize() method implemented in the child class to be called. If this method is called more than once on a given object, all calls but the first do nothing.
    • reset

      public void reset()
      Resets the page which will result all child components being removed and the method initialize() being invoked again.
      Since:
      3.2.2
    • addPageListener

      public void addPageListener(PageListener l)
      Adds a PageListener to the page.
      Parameters:
      l - the PageListener to be added
    • removePageListener

      public void removePageListener(PageListener l)
      Removes a PageListener from the page.
      Parameters:
      l - the PageListener to be removed
    • getPageListeners

      public PageListener[] getPageListeners()
      Returns an array of all the PageListeners added to this Page with addPageListener .
      Returns:
      all of the PageListeners added, or an empty array if no listeners have been added
    • firePageEvent

      public void firePageEvent(int id)
      Runs each PageListener's pageEventFired method.
      Parameters:
      id - event id.
    • firePageEvent

      public void firePageEvent(Object source, int id)
      Runs each PageListener's pageEventFired method.
      Parameters:
      source - of this event
      id - event id.
    • setAllowClosing

      public void setAllowClosing(boolean allowClosing)
      Sets allow closing. If true, the document cannot be closed. user can change the value in documentClosing() to prevent document from being closed.
      Parameters:
      allowClosing - true or false.
    • allowClosing

      public boolean allowClosing()
      Allow this document closing. By default it return true. User can override this method to return based on condition. A typical user case is: add a DocumentComponentListener. In documentComponentClosing, make this method return to false to prevent it from being closed.
      Returns:
      whether allow closing