amber.client.panel
Class PMenu

java.lang.Object
  |
  +--amber.client.panel.BaseControl
        |
        +--amber.client.panel.PMenu
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.ComponentListener, java.util.EventListener, java.awt.event.FocusListener, java.awt.event.ItemListener, java.awt.event.KeyListener, MbInterface, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, RContainer, java.awt.event.TextListener, java.awt.event.WindowListener

public class PMenu
extends BaseControl
implements RContainer

Extension to BaseControl that presents the user with a menu system. In Java 1.1 Menu bars can only be attached to frames however pop up menus can be attached to any component. In a similar way to a panel this control acts as a holding area for a number of components. Unlike a Panel the menu items are not derived from BaseControl class. The system adds the menus using a parent/child relationship. Internally however the hierarchy is flattened into a simple list which contains a relationship between the visual object handle and the Amber ID of the control. When a packet comes into the menu the system identifies the corresponding MenuComponent and performs the operation on it. Events fired by the MenuComponent are handled in the normal way however the ID of the object is altered to point to the ID of the corresponding MenuComponent. Each MenuComponent held in the Menu has a unique ID in a similar way to the normal Remote Components. The menu itself has an ID which is used for messaging to the panel itself. As this appears to be a series of normal components to the server it is important that none of the ID's interfere with the those of any other component or subcomponent.

See Also:
ApplicationHandler, ComponentHandler, BaseComponent, BaseControl

Field Summary
static byte Add
          Adds a MenuComponent to the menu.
static byte AddShortCut
          Adds a key short cut for the MenuItem in the menu.
static byte GetCheckState
          Returns the state of a CheckMenuItem in the menu.
static byte GetCheckStateResponse
          Return packet ID containing the state of a CheckMenuItem in the menu.
static byte GetLabel
          Returns the label of a MenuComponent in the menu.
static byte GetLabelResponse
          Return packet ID containing the label of a MenuComponent in the menu.
static byte Insert
          Inserts a MenuComponent to the parent menu at the specified location.
protected  java.util.Vector itemHandle
           
protected  java.util.Vector itemId
           
static int Menu
          Constant defining a type of possible menu.
static int MenuBar
           
static int MenuCheckOff
           
static int MenuCheckOn
           
static int MenuItem
           
static int MenuTear
           
static int PopupMenu
          Constant defining the type of base menu.
static byte Remove
          Removes a MenuComponent from the menu.
static byte RemoveAll
          Removes all MenuComponent from the menu.
static byte RemoveBarShortCut
          Removes a specified key short cut from the MenuItem in the MenuBar.
static byte RemoveShortCut
          Removes a key short cut from the MenuItem in the menu.
static byte SetCheckState
          Returns the check state of a CheckMenuItem in the menu.
static byte SetEnabled
          Set the menu item to enable/disable.
static byte SetLabel
          Sets the label for a MenuComponent in the menu.
static byte ShowMenu
          Shows the Menu at the specified location relative to the parent.
 
Fields inherited from class amber.client.panel.BaseControl
dataDecoder, dataEncoder, encoderBytes, eventEnabled, mainEventHandler, nonVisualObject, panelParent, visualObject
 
Constructor Summary
PMenu()
           
 
Method Summary
 void addComponent(Packet packet)
          This function is used to add a component to the panel.
 void addListeners(BaseComponent listener)
          Add in the listener handlers to the input object.
protected  java.awt.MenuItem createItem(int type, java.lang.String name)
          This function creates a MenuItem as specified by the input parameters.
protected  java.awt.MenuComponent findItemById(int id)
          This function is used to find the menu component to alter.
 java.awt.Container getContainer()
          This function returns the container which holds the child objects.
 short getIdFromInternalObject(java.lang.Object source)
          This function returns the ID of an object given the corresponding Visual Object returns -1 if no match.
 void init(RContainer mainParent, int[] characteristics, java.lang.String parameters)
          This is the main initialisation function for this class.
 void internalProcessPacket(Packet packet)
          This function is to directly process the commands.
 boolean isMyId(int id)
          This function returns true if the id handed to it is to be handled here.
 void parseParameters(java.lang.String parameter)
           
protected  void performOperation(Packet packet, java.awt.MenuComponent item)
          This is the function which performs the operation on the specified MenuComponent.
 void processPacket(Packet packet)
          This routine contains the logic to parse a packet and perform actions based on the packet's contents.
 void removeAllComponents()
          This function is used to remove all sub components from the menu.
 void removeComponent(Packet packet)
          This function is used to remove a component from the panel.
 void setComponentBounds(Packet packet)
          This function sets the location or size of the component.
 void setDisplay(java.awt.Component display)
          This defines the new visual object to display the menu on.
 
Methods inherited from class amber.client.panel.BaseControl
actionPerformed, canAdd, componentHidden, componentMoved, componentResized, componentShown, createDataInput, displayMessage, findBaseComponent, focusGained, focusLost, forwardPacket, getDataInput, getId, getImage, getNonVisualObject, getParent, getVisualObject, isEventEnabled, itemStateChanged, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, setEnabled, setId, setMessageBoxReturn, setParent, setVisible, textValueChanged, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface amber.client.RContainer
findBaseComponent, forwardPacket, getId, getNonVisualObject, getVisualObject, setEnabled, setVisible
 

Field Detail

Add

public static final byte Add
Adds a MenuComponent to the menu. The parameters are: int type, int newId, String name The type ID is one of the type constants.

Insert

public static final byte Insert
Inserts a MenuComponent to the parent menu at the specified location. The parameters are: int type, int newId, int location, String name The type ID is one of the type constants.

Remove

public static final byte Remove
Removes a MenuComponent from the menu. The parameters are: int id

AddShortCut

public static final byte AddShortCut
Adds a key short cut for the MenuItem in the menu. The parameters are: int keyCode, boolean useShift

RemoveShortCut

public static final byte RemoveShortCut
Removes a key short cut from the MenuItem in the menu.

SetLabel

public static final byte SetLabel
Sets the label for a MenuComponent in the menu. The parameters are: String label

GetLabel

public static final byte GetLabel
Returns the label of a MenuComponent in the menu.

GetLabelResponse

public static final byte GetLabelResponse
Return packet ID containing the label of a MenuComponent in the menu. The parameter is: String label

SetCheckState

public static final byte SetCheckState
Returns the check state of a CheckMenuItem in the menu.

GetCheckState

public static final byte GetCheckState
Returns the state of a CheckMenuItem in the menu.

GetCheckStateResponse

public static final byte GetCheckStateResponse
Return packet ID containing the state of a CheckMenuItem in the menu. The parameter is: boolean state

ShowMenu

public static final byte ShowMenu
Shows the Menu at the specified location relative to the parent. The parameters are: int x, int y

RemoveAll

public static final byte RemoveAll
Removes all MenuComponent from the menu.

SetEnabled

public static final byte SetEnabled
Set the menu item to enable/disable. The parameters are: boolean state

RemoveBarShortCut

public static final byte RemoveBarShortCut
Removes a specified key short cut from the MenuItem in the MenuBar. The parameters are: int keyCode, boolean useShift

Menu

public static final int Menu
Constant defining a type of possible menu.

MenuTear

public static final int MenuTear

MenuItem

public static final int MenuItem

MenuCheckOff

public static final int MenuCheckOff

MenuCheckOn

public static final int MenuCheckOn

PopupMenu

public static final int PopupMenu
Constant defining the type of base menu.

MenuBar

public static final int MenuBar

itemId

protected java.util.Vector itemId

itemHandle

protected java.util.Vector itemHandle
Constructor Detail

PMenu

public PMenu()
Method Detail

init

public void init(RContainer mainParent,
                 int[] characteristics,
                 java.lang.String parameters)
This is the main initialisation function for this class. This is needed as the way we instantiate these classes mandates that only the default constructor can be used. For this reason we must have a separate initialisation function.
Overrides:
init in class BaseControl
Parameters:
mainParent - RContainer handle to the panel this is a component of.
characteristics - int [6] containing information useful to the component in the order ID, eventMask, x, y, w, h.
parameters - String containing any required parameters separated by '|'

parseParameters

public void parseParameters(java.lang.String parameter)
Overrides:
parseParameters in class BaseControl

addListeners

public void addListeners(BaseComponent listener)
Add in the listener handlers to the input object. We do not call the super class as the standard component events are not supported by these objects.
Overrides:
addListeners in class BaseControl

findItemById

protected java.awt.MenuComponent findItemById(int id)
This function is used to find the menu component to alter.
Parameters:
id - int containing the Amber ID of the MenuComponent to find.
Returns:
MenuComponent which matches the ID or null if no such control.

processPacket

public void processPacket(Packet packet)
This routine contains the logic to parse a packet and perform actions based on the packet's contents. In this class, does basic common tasks that all applets must implement. Override in the derived classes to do the magic.
Specified by:
processPacket in interface RContainer
Overrides:
processPacket in class BaseControl
Following copied from interface: amber.client.RContainer
Parameters:
packet - Incoming Packet containing the command and all required parameters.

internalProcessPacket

public void internalProcessPacket(Packet packet)
This function is to directly process the commands. No redirection will take place and the destination ID is considered irrelevant.
Specified by:
internalProcessPacket in interface RContainer
Parameters:
packet - Incoming Packet containing the command and all required parameters.

setDisplay

public void setDisplay(java.awt.Component display)
This defines the new visual object to display the menu on. If set to null then the default behaviour occurs which is to use the parent.

createItem

protected java.awt.MenuItem createItem(int type,
                                       java.lang.String name)
This function creates a MenuItem as specified by the input parameters.
Parameters:
type - int containing the MenuItem type to create.
name - String containing the name of the component.
Returns:
created MenuItem.

addComponent

public void addComponent(Packet packet)
This function is used to add a component to the panel. Packet structure: int id, int eventmask, int x, int y, int w, int h, string class, string parameters
Specified by:
addComponent in interface RContainer
Parameters:
packet - Packet containing the required information.

removeComponent

public void removeComponent(Packet packet)
This function is used to remove a component from the panel. Packet structure: int id
Specified by:
removeComponent in interface RContainer
Parameters:
packet - Packet containing the required information.

setComponentBounds

public void setComponentBounds(Packet packet)
This function sets the location or size of the component. Packet structure: int id, int type, int x (width), int y (height), (int width, int height) bracketed objects optional types which are dependant on the type field. In this object the function does nothing.
Specified by:
setComponentBounds in interface RContainer
Parameters:
packet - Packet containing the required information.

removeAllComponents

public void removeAllComponents()
This function is used to remove all sub components from the menu.
Specified by:
removeAllComponents in interface RContainer

performOperation

protected void performOperation(Packet packet,
                                java.awt.MenuComponent item)
This is the function which performs the operation on the specified MenuComponent.
Parameters:
packet - The Packet containing the command to respond to.
item - The MenuComponent to perform the operation on.

isMyId

public boolean isMyId(int id)
This function returns true if the id handed to it is to be handled here.
Specified by:
isMyId in interface RContainer
Overrides:
isMyId in class BaseControl
Parameters:
id - int containing the ID to check for.
Returns:
boolean true if this component handles this ID.

getIdFromInternalObject

public short getIdFromInternalObject(java.lang.Object source)
This function returns the ID of an object given the corresponding Visual Object returns -1 if no match. This function overrides the default function in BaseControl to allow the concept of child objects.
Overrides:
getIdFromInternalObject in class BaseControl
Parameters:
source - Object handle to the object which fired the event.
Returns:
short containing the ID of the corresponding Panel or -1 if this component is not contained here.
See Also:
BaseControl

getContainer

public java.awt.Container getContainer()
This function returns the container which holds the child objects. In this case there is no real container.
Specified by:
getContainer in interface RContainer
Returns:
Container which holds the child objects.


Copyright © 2002 Clearfield Research Ltd. All Rights Reserved.