org.salespointframework.core
Class MenuSheet

java.lang.Object
  extended by org.salespointframework.core.MenuSheetObject
      extended by org.salespointframework.core.MenuSheet

public class MenuSheet
extends MenuSheetObject

A MenuSheet consisting of MenuSheetObjects.

MenuSheets represent menus, abstracting from the form they are being displayed in. A MenuSheet could be displayed as a JMenuBar as well as a JMenu or JPopUpMenu. Independently of this it will always behave in the same way from the point of view of the applicion developer.

Since:
v1.0
Version:
2.0 20/05/1999
Author:
Steffen Zschaler

Field Summary
private static int DEFAULT_IMAGE
           
private static int DISABLED_IMAGE
           
private static int DISABLED_SELECTED_IMAGE
           
static java.lang.String HELP_MENU_TAG
          A tag that will identify the help menu, should this MenuSheet be displayed as a JMenuBar.
protected  javax.swing.ImageIcon[] m_aiImages
          The Images associated with the icons of this MenuSheet( [0]:DefaultImage, [1]:PressedImage, [2]:DisabledImage, [3]:PressedDiabledImage ).
protected  char m_cMnemonic
          The Mnemonic of this MenuSheet.
protected  javax.swing.JMenuBar m_jmbBarPeer
          The JMenuBar peer, if any.
protected  javax.swing.JMenu m_jmPeer
          The JMenu peer, if any.
protected  java.util.LinkedList<MenuSheetObject> m_lmsoItems
          The items of this MenuSheet.
protected  MenuSheet m_msMerged
          The MenuSheet that has been merged into this one, if any.
protected  MenuSheet m_msMergeParent
          The MenuSheet into which this MenuSheet was merged, if any.
protected  int m_nMergedAt
          The peer index at which the merged menu was inserted.
private  java.lang.Object m_oPeerLock
          The monitor used to synchronize access to the peers.
protected  java.lang.String m_sMergedBefore
          The tag before which the merged menu was inserted.
protected  java.lang.String m_sToolTip
          The ToolTip of this MenuSheet.
private static int SELECTED_IMAGE
           
 
Fields inherited from class org.salespointframework.core.MenuSheetObject
m_msParent, m_pAttached, m_spAttached
 
Constructor Summary
MenuSheet(java.lang.String sCaption)
          Creates a new MenuSheet with caption and a default tag.
MenuSheet(java.lang.String sCaption, java.lang.String sTag)
          Creates a new MenuSheet with caption and tag.
MenuSheet(java.lang.String sCaption, java.lang.String sTag, char cMnemonic)
          Creates a new MenuSheet with caption, tag and mnemonic.
 
Method Summary
 void add(MenuSheetObject mso)
          Adds a MenuSheetObject to the end of this MenuSheet.
 SaleProcess attach(SaleProcess p)
          Attach a SaleProcess to this MenuSheet.
 SalesPoint attach(SalesPoint sp)
          Attach a SalesPoint to this MenuSheet.
 javax.swing.ImageIcon getDefaultIcon()
          Get the default icon of this MenuSheet.
 javax.swing.ImageIcon getDisabledIcon()
          Get the disabled item of this MenuSheet.
 javax.swing.ImageIcon getDisabledSelectedIcon()
          Get the disabled selected item of this MenuSheet.
 javax.swing.JMenuBar getMenuBar()
          Return the JMenuBar peer.
 javax.swing.JMenu getMenuPeer()
          For MenuSheets there is no difference between JMenuItem and JMenu peer, they are both JMenus.
 char getMnemonic()
          Get the Mnemonic of this MenuSheet.
 javax.swing.JMenuItem getPeer()
          The JMenuItem peer of a MenuSheet is, of course, a JMenu.
protected  java.lang.Object getPeerLock()
          Return the monitor used to synchronized access to the peers.
 javax.swing.ImageIcon getSelectedIcon()
          Get the selected icon of this MenuSheet.
 MenuSheetObject getTaggedItem(java.lang.String sTag, boolean fTopLevelOnly)
          Get a MenuSheetObject by its tag.
 java.lang.String getToolTipText()
          Get the ToolTip of this MenuSheet.
 java.util.Iterator<MenuSheetObject> iterator()
          Return a fail-fast, readonly iterator of the items in this MenuSheet.
(package private)  void mergedAdd(MenuSheetObject mso, int nIndex)
          Internal method used for updating merged peers correctly.
(package private)  void mergedRemove(MenuSheetObject mso)
          Internal method used to properly update merged peers.
 javax.swing.JMenuBar mergePeers(MenuSheet msToMerge, java.lang.String sBeforeTag)
          Merges the peers of two MenuSheets.
(package private)  javax.swing.JMenuBar remergePeers()
          Internal method used for proper merging of peers.
 MenuSheetObject remove(MenuSheetObject msoRemove)
          Remove a MenuSheetObject from the MenuSheet.
 MenuSheetObject remove(java.lang.String sTag)
          Remove a tagged top level item from the MenuSheet.
 void setCaption(java.lang.String sCaption)
          Set the caption of this MenuSheet.
 void setDefaultIcon(javax.swing.ImageIcon iiImageIcon)
          Set the default icon of this MenuSheet.
 void setDisabledIcon(javax.swing.ImageIcon iiImageIcon)
          Set the disabled icon of this MenuSheet.
 void setDisabledSelectedIcon(javax.swing.ImageIcon iiImageIcon)
          Set the disabled selected icon of this MenuSheet.
private  void setIcon(javax.swing.ImageIcon iiImageIcon, int nIndex)
           
(package private)  void setMergeParent(MenuSheet msMergeParent)
          Internal method used when merging peers.
 void setMnemonic(char cMnemonic)
          Set the mnemonic of this MenuSheet.
 void setSelectedIcon(javax.swing.ImageIcon iiImageIcon)
          Set the selected icon of this MenuSheet.
 void setToolTipText(java.lang.String s)
          Set the ToolTip of this MenuSheet.
 void setVisible(boolean fVisible)
          Mark this MenuSheet, all its descendants and merged peer MenuSheets visible or invisible.
 
Methods inherited from class org.salespointframework.core.MenuSheetObject
detachSaleProcess, detachSalesPoint, equals, getCaption, getParent, getTag, getTaggedItem, isSeparator, isVisible, setParent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_jmPeer

protected transient javax.swing.JMenu m_jmPeer
The JMenu peer, if any.


m_jmbBarPeer

protected transient javax.swing.JMenuBar m_jmbBarPeer
The JMenuBar peer, if any.


m_oPeerLock

private transient java.lang.Object m_oPeerLock
The monitor used to synchronize access to the peers.


m_msMerged

protected MenuSheet m_msMerged
The MenuSheet that has been merged into this one, if any.


m_sMergedBefore

protected java.lang.String m_sMergedBefore
The tag before which the merged menu was inserted.


m_nMergedAt

protected int m_nMergedAt
The peer index at which the merged menu was inserted.


m_msMergeParent

protected MenuSheet m_msMergeParent
The MenuSheet into which this MenuSheet was merged, if any.


m_lmsoItems

protected java.util.LinkedList<MenuSheetObject> m_lmsoItems
The items of this MenuSheet.


m_aiImages

protected javax.swing.ImageIcon[] m_aiImages
The Images associated with the icons of this MenuSheet( [0]:DefaultImage, [1]:PressedImage, [2]:DisabledImage, [3]:PressedDiabledImage ).


m_cMnemonic

protected char m_cMnemonic
The Mnemonic of this MenuSheet.


m_sToolTip

protected java.lang.String m_sToolTip
The ToolTip of this MenuSheet.


HELP_MENU_TAG

public static final java.lang.String HELP_MENU_TAG
A tag that will identify the help menu, should this MenuSheet be displayed as a JMenuBar.

See Also:
Constant Field Values

DEFAULT_IMAGE

private static final int DEFAULT_IMAGE
See Also:
Constant Field Values

SELECTED_IMAGE

private static final int SELECTED_IMAGE
See Also:
Constant Field Values

DISABLED_IMAGE

private static final int DISABLED_IMAGE
See Also:
Constant Field Values

DISABLED_SELECTED_IMAGE

private static final int DISABLED_SELECTED_IMAGE
See Also:
Constant Field Values
Constructor Detail

MenuSheet

public MenuSheet(java.lang.String sCaption,
                 java.lang.String sTag,
                 char cMnemonic)
Creates a new MenuSheet with caption, tag and mnemonic.

Parameters:
sCaption - the caption of the new MenuSheet.
sTag - the tag of the new MenuSheet. If null a default tag will be created.
cMnemonic - the mnemonic of the new MenuSheet.

MenuSheet

public MenuSheet(java.lang.String sCaption,
                 java.lang.String sTag)
Creates a new MenuSheet with caption and tag.

Parameters:
sCaption - the caption of the new MenuSheet.
sTag - the tag of the new MenuSheet. If null a default tag will be created.

MenuSheet

public MenuSheet(java.lang.String sCaption)
Creates a new MenuSheet with caption and a default tag.

Parameters:
sCaption - the caption of the new MenuSheet.
Method Detail

getPeerLock

protected final java.lang.Object getPeerLock()
Return the monitor used to synchronized access to the peers.


setIcon

private void setIcon(javax.swing.ImageIcon iiImageIcon,
                     int nIndex)

add

public void add(MenuSheetObject mso)
Adds a MenuSheetObject to the end of this MenuSheet.

Should the MenuSheet currently be displayed, the new item will be displayed as well.

Parameters:
mso - the new MenuSheetObject.

mergedAdd

void mergedAdd(MenuSheetObject mso,
               int nIndex)
Internal method used for updating merged peers correctly.

Parameters:
mso - the MenuSheet that was added in the merged MenuSheet.
nIndex - the peer index at which the element was added into the merged MenuSheet.

remove

public MenuSheetObject remove(java.lang.String sTag)
Remove a tagged top level item from the MenuSheet.

If an item with the given tag is found among the top level items of this MenuSheet, it is removed and the removed item is returned. Otherwise, the call is ignored.

If the MenuSheet is currently on display, the peer will reflect the changes.

Parameters:
sTag - the tag of the item to be removed.
Returns:
the removed item

remove

public MenuSheetObject remove(MenuSheetObject msoRemove)
Remove a MenuSheetObject from the MenuSheet.

If the MenuSheet is currently on display, the peer will reflect the changes.

Parameters:
msoRemove - the MenuSheetObject to be removed.
Returns:
the removed MenuSheetObject.

mergedRemove

void mergedRemove(MenuSheetObject mso)
Internal method used to properly update merged peers.

Parameters:
mso - the MenuSheetObject that was removed from the merged MenuSheet.

iterator

public java.util.Iterator<MenuSheetObject> iterator()
Return a fail-fast, readonly iterator of the items in this MenuSheet.

Fail-fast means, that this iterator will throw a ConcurrentModificationException when a structural change occured to the underlying MenuSheet.

Also, the remove() method will throw an UnsupportedOperationException, as this is a readonly iterator.

See Also:
ConcurrentModificationException

setMergeParent

void setMergeParent(MenuSheet msMergeParent)
Internal method used when merging peers.


mergePeers

public final javax.swing.JMenuBar mergePeers(MenuSheet msToMerge,
                                             java.lang.String sBeforeTag)
Merges the peers of two MenuSheets. If a MenuSheet is already merged into this one, it will be removed and marked invisible.

The peers of the top level MenuSheetObjects of the given MenuSheet are merged into the JMenuBar peer of this MenuSheet. They will be inserted into the JMenuBar peer before the MenuSheetpObject with the given tag. If no such MenuSheetObject can be found in the MenuSheet they are appended to the end of the peer.

Merging can always only result in a JMenuBar peer. A JMenu peer cannot be merged. However, merging can be nested. I.e. it is legal, to merge a MenuSheet, into whose peer another MenuSheet's peer has been merged, into a third MenuSheet.

Although the peers of the two MenuSheets are merged, they stay independent with respect to anything else. The MenuSheetObjects of the merged MenuSheet can still only be accessed through that MenuSheet and vice-vera. Also, the attached SalesPoint and SaleProcess stay independent.

For merging to function correctly, you must set the created JMenuBar in your JFrame. Something like this will do the trick:

   setJMenuBar (ms.mergePeers (msToMerge, "MERGE_BEFORE_THIS"));
 

This method is usually not called directly.

Parameters:
msToMerge - the MenuSheet to be merged into this one.
sBeforeTag - before which tag to merge in the MenuSheet.

remergePeers

javax.swing.JMenuBar remergePeers()
Internal method used for proper merging of peers.


getTaggedItem

public MenuSheetObject getTaggedItem(java.lang.String sTag,
                                     boolean fTopLevelOnly)
Get a MenuSheetObject by its tag.

This will iterate over all MenuSheetObjects in this MenuSheet and return the first one, that has the given tag.

Overrides:
getTaggedItem in class MenuSheetObject
Parameters:
sTag - the tag to search for.
fTopLevelOnly - if true, only the direct elements in this MenuSheet are searched.
Returns:
the first MenuSheetObject that has the given tag, if any.
Throws:
java.util.ConcurrentModificationException - if the structure of the MenuSheet changed during the search.

attach

public SalesPoint attach(SalesPoint sp)
Attach a SalesPoint to this MenuSheet.

Overrides:
attach in class MenuSheetObject
Parameters:
sp - the SalesPoint to be attached.
Returns:
the previously attached SalesPoint, if any.

attach

public SaleProcess attach(SaleProcess p)
Attach a SaleProcess to this MenuSheet.

Overrides:
attach in class MenuSheetObject
Parameters:
p - the process to be attached.
Returns:
the previously attached process, if any.

setVisible

public void setVisible(boolean fVisible)
Mark this MenuSheet, all its descendants and merged peer MenuSheets visible or invisible.

Overrides:
setVisible in class MenuSheetObject
Parameters:
fVisible - the visibility state of the MenuSheetObject.

setCaption

public void setCaption(java.lang.String sCaption)
Set the caption of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Overrides:
setCaption in class MenuSheetObject
Parameters:
sCaption - the new caption.

setMnemonic

public void setMnemonic(char cMnemonic)
Set the mnemonic of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
cMnemonic - the new mnemonic.

setToolTipText

public void setToolTipText(java.lang.String s)
Set the ToolTip of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
s - the new ToolTip-Text.

setDefaultIcon

public void setDefaultIcon(javax.swing.ImageIcon iiImageIcon)
Set the default icon of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
iiImageIcon - the new icon.

setSelectedIcon

public void setSelectedIcon(javax.swing.ImageIcon iiImageIcon)
Set the selected icon of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
iiImageIcon - the new icon.

setDisabledIcon

public void setDisabledIcon(javax.swing.ImageIcon iiImageIcon)
Set the disabled icon of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
iiImageIcon - the new icon.

setDisabledSelectedIcon

public void setDisabledSelectedIcon(javax.swing.ImageIcon iiImageIcon)
Set the disabled selected icon of this MenuSheet.

If there is a peer it will reflect the changes immediately.

Parameters:
iiImageIcon - the new icon.

getPeer

public javax.swing.JMenuItem getPeer()
The JMenuItem peer of a MenuSheet is, of course, a JMenu.

Specified by:
getPeer in class MenuSheetObject

getMenuPeer

public javax.swing.JMenu getMenuPeer()
For MenuSheets there is no difference between JMenuItem and JMenu peer, they are both JMenus.

Specified by:
getMenuPeer in class MenuSheetObject

getMenuBar

public javax.swing.JMenuBar getMenuBar()
Return the JMenuBar peer.

For a MenuSheet there is a special peer: the JMenuBar peer. All items of this MenuSheet will present their JMenu peer in the JMenuBar. Only MenuSheetSeparators are not displayed in a JMenuBar representation. Merged peers are only displayed in the JMenuBar representation.


getMnemonic

public char getMnemonic()
Get the Mnemonic of this MenuSheet.

Returns:
the mnemonic of this MenuSheet.

getToolTipText

public java.lang.String getToolTipText()
Get the ToolTip of this MenuSheet.

Returns:
the ToolTip-String of this MenuSheet.

getDefaultIcon

public javax.swing.ImageIcon getDefaultIcon()
Get the default icon of this MenuSheet.

Returns:
the default icon of this MenuSheet.

getSelectedIcon

public javax.swing.ImageIcon getSelectedIcon()
Get the selected icon of this MenuSheet.

Returns:
the pressed icon of this MenuSheet.

getDisabledIcon

public javax.swing.ImageIcon getDisabledIcon()
Get the disabled item of this MenuSheet.

Returns:
the disabled icon of this MenuSheet.

getDisabledSelectedIcon

public javax.swing.ImageIcon getDisabledSelectedIcon()
Get the disabled selected item of this MenuSheet.

Returns:
the disabled selected icon of this MenuSheet.