JavaView® v2.00.008

jv.objectGui
Class PsMethodMenu

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--jv.objectGui.PsMethodMenu
All Implemented Interfaces:
java.awt.event.ActionListener, java.lang.Cloneable, java.util.Collection, java.util.EventListener, java.awt.event.ItemListener, java.util.List, PsUpdateIf, java.io.Serializable
Direct Known Subclasses:
PgGeometry_Menu, PgPointSet_Menu

public abstract class PsMethodMenu
extends java.util.Vector
implements java.awt.event.ActionListener, java.awt.event.ItemListener, PsUpdateIf

Add specific menu items to 'method' menu in control panel to invoke methods from menu. For example, each geometry may have a menu class derived this class which adds additional menu items and sub menus. When the geometry is the current geometry in the viewer, then its set of method menus is added to the menu bar of the control window.

Each geometry may add a set of menu items to submenus of the 'method' menu.

Usage:
In the init() method add new menu entries as follows:

	addMenu("Menu-Name");
	addMenuItem("Menu-Name", "Menu-Item-Name");	
 
The submenu is created if it does not exist. Catch menu events in the applyMethod(String name) using:
	if (name.equals("Menu-Item-Name"))
		// invoke method related with "Menu-Item-Name".
 
An application can be seen in PgGeometry_Menu.

Version:
01.01.01, 2.50 revised (kp) Implement PsUpdateIf to allow update if object has changed.
18.07.99, 2.00 revised (kp) Method calls changed and PsMenu replaced with standard java.awt.Menu.
00.00.98, 1.00 created (kp)
Author:
Konrad Polthier
See Also:
PgGeometry_Menu, Serialized Form

Field Summary
protected  java.lang.String m_language
          Language used for text on this panel during construction.
protected  java.lang.String m_name
          Name of current object, need not be unique.
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
PsMethodMenu()
          Constructor assigns the current language.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Handle events related with menu items.
 java.awt.Menu addMenu(java.lang.String aLabel)
          Create a new menu with given name, or return existing menu.
 java.awt.Menu addMenu(java.lang.String parentLabel, java.lang.String aLabel)
          Create a new menu with given name, or return existing menu.
 java.awt.MenuItem addMenuItem(java.lang.String menuName, java.lang.String itemName)
          Create a new menuItem with given name.
 java.awt.CheckboxMenuItem addMenuItem(java.lang.String menuName, java.lang.String itemName, boolean state)
          Create a new checkboxMenuItem with given name.
 boolean applyMethod(java.lang.String method)
          Invoke action determined by current string.
 java.lang.Object clone()
          Duplicate menu by recursively cloning all instance variables except inspector panels and lists of registered listeners.
 PsUpdateIf getFather()
          Get unique parent of an object.
static int getIndexOfMethod(java.lang.String[] aMethodList, java.lang.String aMethod)
          Returns the index of a given method name in the array of method names.
 java.lang.String getLanguage()
          Get language used in this panel.
 java.awt.Menu getMenu(java.lang.String aLabel)
          Get a menu with given name.
 java.awt.MenuItem getMenuItem(java.lang.String menuName, java.lang.String itemName)
          Get a menuItem with given name.
 java.lang.String getName()
          Get name identifying the object.
 boolean hasMenu(java.lang.String aLabel)
          Check existence of a menu with given name.
 boolean hasMenuItem(java.lang.String menuName, java.lang.String itemName)
          Check existence of a menuItem with given name.
 void init(PsObject anObject)
          Register the target geometry, and subclasses should register all menu items and submenus.
 void itemStateChanged(java.awt.event.ItemEvent event)
          Handle events related with checkbox menu items.
 void removeMenu(java.lang.String aLabel)
          Remove menu with given name.
 void removeMenuItem(java.lang.String menuName, java.lang.String itemName)
          Remove menuItem with given name.
 void setName(java.lang.String aName)
          Set name identifying the object.
 void setParent(PsUpdateIf aParent)
          Set parent to receive update methods.
 boolean update(java.lang.Object event)
          Update this menu if the parent object has changed.
 
Methods inherited from class java.util.Vector
add, add, addAll, addAll, addElement, capacity, clear, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

m_name

protected java.lang.String m_name
Name of current object, need not be unique.
See Also:
getName(), setName(java.lang.String)

m_language

protected java.lang.String m_language
Language used for text on this panel during construction. This reference is used to decide if panel is out of date when language changes.
See Also:
getLanguage()
Constructor Detail

PsMethodMenu

public PsMethodMenu()
Constructor assigns the current language.
Method Detail

init

public void init(PsObject anObject)
Register the target geometry, and subclasses should register all menu items and submenus.
Parameters:
argument - used by subclasses to specify object on which action shall be executed.

getFather

public PsUpdateIf getFather()
Get unique parent of an object. It was necessary to rename the method since Java 1.1. added a method getParent() to its classes.
Specified by:
getFather in interface PsUpdateIf
See Also:
PsUpdateIf, PsObject.update(Object), PsObject.setParent(PsUpdateIf)

setParent

public void setParent(PsUpdateIf aParent)
Set parent to receive update methods.
Specified by:
setParent in interface PsUpdateIf
See Also:
PsUpdateIf, PsObject.update(Object), PsObject.getFather()

setName

public void setName(java.lang.String aName)
Set name identifying the object. Should be chosen unique.

getName

public java.lang.String getName()
Get name identifying the object.
Specified by:
getName in interface PsUpdateIf

update

public boolean update(java.lang.Object event)
Update this menu if the parent object has changed. This method checks whether update is issued from parent. Subclasses may add functionality, for example, to set the state if CheckboxMenuItems.
Specified by:
update in interface PsUpdateIf
See Also:
PsObject.setParent(PsUpdateIf), PsObject.getFather(), #addUpdateListener(PsUpdateIf)

clone

public java.lang.Object clone()
Duplicate menu by recursively cloning all instance variables except inspector panels and lists of registered listeners.

After cloning the init() method must be called to register the target geometry. The pointers to registered menu items are all removed, and in the latter call to init() recomputed.

Overrides:
clone in class java.util.Vector

getLanguage

public java.lang.String getLanguage()
Get language used in this panel.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Handle events related with menu items. Invoke method determined by current string and return true if event handled. Otherwise return false to give subclasses a chance to handle the event.
Specified by:
actionPerformed in interface java.awt.event.ActionListener

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent event)
Handle events related with checkbox menu items. Might be called by checkbox menu items; method does nothing, all action must be done by subclass.
Specified by:
itemStateChanged in interface java.awt.event.ItemListener

applyMethod

public boolean applyMethod(java.lang.String method)
Invoke action determined by current string. This method returns false, and should be overwritten by subclasses.

getMenu

public java.awt.Menu getMenu(java.lang.String aLabel)
Get a menu with given name. Return menu if menu exists.

hasMenu

public boolean hasMenu(java.lang.String aLabel)
Check existence of a menu with given name. Return true if menu exists.

addMenu

public java.awt.Menu addMenu(java.lang.String aLabel)
Create a new menu with given name, or return existing menu. If menu already exists, just return it, else return new menu.

addMenu

public java.awt.Menu addMenu(java.lang.String parentLabel,
                             java.lang.String aLabel)
Create a new menu with given name, or return existing menu. If menu already exists, just return it, else return new menu.

removeMenu

public void removeMenu(java.lang.String aLabel)
Remove menu with given name.

getIndexOfMethod

public static int getIndexOfMethod(java.lang.String[] aMethodList,
                                   java.lang.String aMethod)
Returns the index of a given method name in the array of method names. Methods are identified by indices in a string array rather than by a string.

getMenuItem

public java.awt.MenuItem getMenuItem(java.lang.String menuName,
                                     java.lang.String itemName)
Get a menuItem with given name. Return menuItem if menuItem exists.

hasMenuItem

public boolean hasMenuItem(java.lang.String menuName,
                           java.lang.String itemName)
Check existence of a menuItem with given name. Return true if menuItem exists.

addMenuItem

public java.awt.MenuItem addMenuItem(java.lang.String menuName,
                                     java.lang.String itemName)
Create a new menuItem with given name. Return new menuItem if menuItem is created.

addMenuItem

public java.awt.CheckboxMenuItem addMenuItem(java.lang.String menuName,
                                             java.lang.String itemName,
                                             boolean state)
Create a new checkboxMenuItem with given name. Return new menuItem if menuItem is created.

removeMenuItem

public void removeMenuItem(java.lang.String menuName,
                           java.lang.String itemName)
Remove menuItem with given name.

JavaView® v2.00.008

The software JavaView® is copyright protected. All Rights Reserved.