SalesPoint Framework v3.1

sale
Class MenuSheet

java.lang.Object
  extended bysale.MenuSheetObject
      extended bysale.MenuSheet
All Implemented Interfaces:
Serializable

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
Author:
Steffen Zschaler
See Also:
Serialized Form

Field Summary
static String HELP_MENU_TAG
          A tag that will identify the help menu, should this MenuSheet be displayed as a JMenuBar.
protected  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  JMenuBar m_jmbBarPeer
          The JMenuBar peer, if any.
protected  JMenu m_jmPeer
          The JMenu peer, if any.
protected  LinkedList 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.
protected  String m_sMergedBefore
          The tag before which the merged menu was inserted.
protected  String m_sToolTip
          The ToolTip of this MenuSheet.
 
Fields inherited from class sale.MenuSheetObject
m_msParent, m_pAttached, m_spAttached
 
Constructor Summary
MenuSheet(String sCaption)
          Creates a new MenuSheet with caption and a default tag.
MenuSheet(String sCaption, String sTag)
          Creates a new MenuSheet with caption and tag.
MenuSheet(String sCaption, 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.
 ImageIcon getDefaultIcon()
          Get the default icon of this MenuSheet.
 ImageIcon getDisabledIcon()
          Get the disabled item of this MenuSheet.
 ImageIcon getDisabledSelectedIcon()
          Get the disabled selected item of this MenuSheet.
 JMenuBar getMenuBar()
          Return the JMenuBar peer.
 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.
 JMenuItem getPeer()
          The JMenuItem peer of a MenuSheet is, of course, a JMenu.
protected  Object getPeerLock()
          Return the monitor used to synchronized access to the peers.
 ImageIcon getSelectedIcon()
          Get the selected icon of this MenuSheet.
 MenuSheetObject getTaggedItem(String sTag, boolean fTopLevelOnly)
          Get a MenuSheetObject by its tag.
 String getToolTipText()
          Get the ToolTip of this MenuSheet.
 Iterator iterator()
          Return a fail-fast, readonly iterator of the items in this MenuSheet.
 JMenuBar mergePeers(MenuSheet msToMerge, String sBeforeTag)
          Merges the peers of two MenuSheets.
 MenuSheetObject remove(MenuSheetObject msoRemove)
          Remove a MenuSheetObject from the MenuSheet.
 MenuSheetObject remove(String sTag)
          Remove a tagged top level item from the MenuSheet.
 void setCaption(String sCaption)
          Set the caption of this MenuSheet.
 void setDefaultIcon(ImageIcon iiImageIcon)
          Set the default icon of this MenuSheet.
 void setDisabledIcon(ImageIcon iiImageIcon)
          Set the disabled icon of this MenuSheet.
 void setDisabledSelectedIcon(ImageIcon iiImageIcon)
          Set the disabled selected icon of this MenuSheet.
 void setMnemonic(char cMnemonic)
          Set the mnemonic of this MenuSheet.
 void setSelectedIcon(ImageIcon iiImageIcon)
          Set the selected icon of this MenuSheet.
 void setToolTipText(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 sale.MenuSheetObject
detachSaleProcess, detachSalesPoint, equals, getCaption, getParent, getTag, getTaggedItem, isSeparator, isVisible
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_jmPeer

protected transient JMenu m_jmPeer
The JMenu peer, if any.


m_jmbBarPeer

protected transient JMenuBar m_jmbBarPeer
The JMenuBar peer, if any.


m_msMerged

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


m_sMergedBefore

protected 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 LinkedList m_lmsoItems
The items of this MenuSheet.


m_aiImages

protected 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 String m_sToolTip
The ToolTip of this MenuSheet.


HELP_MENU_TAG

public static final 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
Constructor Detail

MenuSheet

public MenuSheet(String sCaption,
                 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(String sCaption,
                 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(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 Object getPeerLock()
Return the monitor used to synchronized access to the peers.

Override:
Never

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.
Override:
Never

remove

public MenuSheetObject remove(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
Override:
Never

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.

Returns:
the removed MenuSheetObject.
Override:
Never

iterator

public Iterator 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
Override:
Never

mergePeers

public final JMenuBar mergePeers(MenuSheet msToMerge,
                                 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.
Override:
Never

getTaggedItem

public MenuSheetObject getTaggedItem(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:
ConcurrentModificationException - if the structure of the MenuSheet changed during the search.
Override:
Never

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.
Override:
Never

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.
Override:
Never

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.
Override:
Never

setCaption

public void setCaption(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.
Override:
Never

setMnemonic

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

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

Override:
Never

setToolTipText

public void setToolTipText(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.
Override:
Never

setDefaultIcon

public void setDefaultIcon(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.
Override:
Never

setSelectedIcon

public void setSelectedIcon(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.
Override:
Never

setDisabledIcon

public void setDisabledIcon(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.
Override:
Never

setDisabledSelectedIcon

public void setDisabledSelectedIcon(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.
Override:
Never

getPeer

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

Specified by:
getPeer in class MenuSheetObject
Override:
Never

getMenuPeer

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

Specified by:
getMenuPeer in class MenuSheetObject
Override:
Never

getMenuBar

public 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.

Override:
Never

getMnemonic

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

Returns:
the mnemonic of this MenuSheet.
Override:
Never

getToolTipText

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

Returns:
the ToolTip-String of this MenuSheet.
Override:
Never

getDefaultIcon

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

Returns:
the default icon of this MenuSheet.
Override:
Never

getSelectedIcon

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

Returns:
the pressed icon of this MenuSheet.
Override:
Never

getDisabledIcon

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

Returns:
the disabled icon of this MenuSheet.
Override:
Never

getDisabledSelectedIcon

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

Returns:
the disabled selected icon of this MenuSheet.
Override:
Never

SalesPoint Framework v3.1