Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.simscomputing.util
Class MruMenuManager  view MruMenuManager download MruMenuManager.java

java.lang.Object
  extended bycom.simscomputing.util.MruMenuManager
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class MruMenuManager
extends java.lang.Object
implements java.awt.event.ActionListener

Works with a JMenu to manipulate most recently used items. This works to achieve the effect found in many popular software products: keeping track of the items that a user has chosen most recently for easy retrieval. When constructed with an ApplicationProperties object, MruMenuManager will load and store these mru items for persistence between client sessions.


Field Summary
private  java.util.List mruItems
           
private  java.util.List mruListeners
           
private  javax.swing.JMenu mruMenu
           
private  int mruSize
           
private  ApplicationProperties properties
           
private  java.lang.String propertyPrefix
           
private  int startIndex
           
 
Constructor Summary
MruMenuManager(javax.swing.JMenu mruMenu, int startMenuIndex, int mruSize)
          Constructs a new MruMenuManager with no persistence capability
MruMenuManager(javax.swing.JMenu mruMenu, int startMenuIndex, int mruSize, ApplicationProperties appProperties, java.lang.String propertyPrefix)
          Constructs a new MruMenuManager with the specified parameters.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Implementation of the ActionListener interface.
 void addActionListener(java.awt.event.ActionListener listener)
          Adds an ActionListener to a private list.
 void addMruItem(java.lang.String itemToAdd)
          Adds a new mru item to the mru list.
 void addMruItem(java.lang.String itemToAdd, boolean refreshImmediately)
          Adds a new mru item to the mru list.
 void loadMruItems()
          Loads mru items from the ApplicationProperties object.
 void removeActionListener(java.awt.event.ActionListener listener)
          Removes the specified ActionListener from the list.
private  void resetMenu(int oldSize)
           
 void storeMruItems()
          Stores the mru items in the ApplicationProperties object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startIndex

private int startIndex

mruMenu

private javax.swing.JMenu mruMenu

mruSize

private int mruSize

mruItems

private java.util.List mruItems

mruListeners

private java.util.List mruListeners

properties

private ApplicationProperties properties

propertyPrefix

private java.lang.String propertyPrefix
Constructor Detail

MruMenuManager

public MruMenuManager(javax.swing.JMenu mruMenu,
                      int startMenuIndex,
                      int mruSize)
Constructs a new MruMenuManager with no persistence capability


MruMenuManager

public MruMenuManager(javax.swing.JMenu mruMenu,
                      int startMenuIndex,
                      int mruSize,
                      ApplicationProperties appProperties,
                      java.lang.String propertyPrefix)
Constructs a new MruMenuManager with the specified parameters. This constructor will go ahead and load the menu items present in the ApplicationProperties object. If no ApplicationProperties object is passed in, the load operation will be skipped.

Method Detail

addMruItem

public void addMruItem(java.lang.String itemToAdd)
Adds a new mru item to the mru list. If the item to add is already being displayed, it will not be repeated. If, by adding this item, the mru size defined in the constructor will be exceeded, this method will remove the last item in the list to make room. The new item will be added to the top of the list. The menu refresh will happen immediately.


addMruItem

public void addMruItem(java.lang.String itemToAdd,
                       boolean refreshImmediately)
Adds a new mru item to the mru list. If the item to add is already being displayed, it will not be repeated. If, by adding this item, the mru size defined in the constructor will be exceeded, this method will remove the last item in the list to make room. The new item will be added to the top of the list. The JMenu will only be refreshed if refreshImmediately has been set to true.


addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Adds an ActionListener to a private list. When ActionEvents are received from mru JMenuItems, all ActionListeners in this list will be notified.


removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Removes the specified ActionListener from the list.


resetMenu

private void resetMenu(int oldSize)

storeMruItems

public void storeMruItems()
Stores the mru items in the ApplicationProperties object. Note that this will not physically persist the items. The ApplicationProperties object will physically persist the data to disk when the storeProperties method is called on it. If no ApplicationProperties object was set during construction this method will not do anything.


loadMruItems

public void loadMruItems()
Loads mru items from the ApplicationProperties object. This method is called during construction of the MruMenuManager object. If no ApplicationProperties object was passed in during construction, this method will not do anything.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Implementation of the ActionListener interface. The MruMenuManager will catch events from all mru items it creates and subsequently broadcast them to all ActionListeners attached to it.

Specified by:
actionPerformed in interface java.awt.event.ActionListener