: Download: FAQ: Licensing: Support: Contact ME
LwVCL Home
Introduction
Overview
Screen Shots
On-line Demos
Requirements
Further Plans
Docs
Tutorial
How-to (PDF)
API
FAQ
Download
Latest version

Home > J2SE > API

Overview  Package   Class  Tree  Deprecated  Index  Help 

org.zaval.lw
Class LwMenu

java.lang.Object
  |
  +--org.zaval.lw.LwCanvas
        |
        +--org.zaval.lw.LwPanel
              |
              +--org.zaval.lw.LwAList
                    |
                    +--org.zaval.lw.LwCompList
                          |
                          +--org.zaval.lw.LwMenu
All Implemented Interfaces:
java.util.EventListener, Layoutable, LayoutContainer, LwComponent, LwComposite, LwContainer, LwFocusListener, LwKeyListener, LwLayout, LwMouseListener, LwMouseMotionListener, PosInfo, PosListener, ScrollObj, Validationable

public class LwMenu
extends LwCompList
implements LwLayout

This is popup menu component. The component extends the combo list component functionality. The component feature are listed below:

  • It is possible to use any lightweight component as the menu item.
  • It is possible to define an item as the decorative. In this case the item cannot be selected. As rule, popup menu uses a line separator as the decorative element. The library has the LwLine component for this purpose.
  • It is possible to specify a sub popup menu for any menu item. Use the setSubMenu method.
  • The component creates special wrapper container for all added items. It means an added item cannot be fetched by the get method of the component. Use the fetchContentComp method for this purpose.
  • To add checked or radio group items you should use LwCheckbox component as the list item. For example:
         ...
         // create popup menu with the checked item
         LwMenu menu = new LwMenu();
         menu.add(new LwCheckbox("Checked Item", LwCheckbox.CHECK));
         ...
         // create popup menu with the radio group items
         LwCheckbox r1 = new LwCheckbox("Radio Item 1", LwCheckbox.RADIO);
         LwCheckbox r2 = new LwCheckbox("Radio Item 2", LwCheckbox.RADIO);
         LwCheckbox r2 = new LwCheckbox("Radio Item 3", LwCheckbox.RADIO);
         LwGroup    g  = new LwGroup();
         r1.setSwitchManager(g);
         r2.setSwitchManager(g);
         r3.setSwitchManager(g);
         menu.add(r1);
         menu.add(r2);
         menu.add(r3);
         ...
         
  • To listen whenever a menu item has been selected use addSelectionListener and removeSelectionListener methods. You can delegate the menu events to the parent menu or an owner menu bar. It is useful in a case if you want to have the event handling in one place. Use the delegateEvent method for this purpose.


Fields inherited from class org.zaval.lw.LwAList
controller, dx, dy, POS_COLOR, SEL_COLOR, selectedIndex
 
Fields inherited from class org.zaval.lw.LwPanel
children
 
Fields inherited from class org.zaval.lw.LwCanvas
bits, bottom, height, isValidValue, left, parent, psHeight, psWidth, right, skins, temporary, top, width, x, y
 
Constructor Summary
LwMenu()
          Constructs a popup menu component.
LwMenu(int key)
          Constructs a popup menu component with the given id.
 
Method Summary
 void addItem(LwComponent c, boolean b)
          Adds the given menu item component with the given selectable flag The selectable flag says if the item can be selected or it is just a decorative element (like a line separator).
 void addItem(LwComponent c, LwComponent icon)
          Adds the given menu item with the specified icon component.
 java.awt.Dimension calcPreferredSize(LayoutContainer target)
          Calculates the preferred size dimension for the layout container.
 boolean canHaveFocus()
          Specifies if the component can have focus.
 void componentAdded(java.lang.Object id, Layoutable lw, int index)
          Invoked when the specified layoutable component was added to the layout container (that uses the layout manager).
 void componentRemoved(Layoutable lw, int index)
          Invoked when the specified layoutable component was removed from the layout container, that uses the layout manager.
protected  LwPanel createItem(LwComponent c)
          Creates and returns the wrapper item component with the given item component.
 void delegateEvent(boolean b)
          Sets the selection events delegation model.
protected  void drawPosMarker(java.awt.Graphics g, int x, int y, int w, int h)
          Invoked to paint the list position marker for the specified rectangular area.
 Layoutable fetchContentComp(int index)
          Gets the original item component for the given menu item.
protected  LwLayout getDefaultLayout()
          Gets the default layout manager that is set with the container during initialization.
 int getKey()
          Gets the popup menu id.
 LwMenu getSubMenu(int index)
          Gets the sub menu for the given menu item.
 void insert(int i, LwComponent c, boolean b)
          Inserts the given menu item component at the specified index and the given selectable flag The selectable flag says if the item can be selected or it is just a decorative element (like a line separator).
 void insert(int i, java.lang.Object o, LwComponent c)
          Inserts the specified lightweight component with the specified constraints as a child of this container at the specified position in the container list.
 void keyPressed(LwKeyEvent e)
          Invoked when a key has been pressed.
 void layout(LayoutContainer target)
          Lays out the child layoutable components inside the layout container.
 void mouseExited(LwMouseEvent e)
          Invoked when the mouse exits a light weight component.
protected  void perform(java.lang.Object src, java.lang.Object data)
          Creates and fires the selection event.
protected  void recalc()
          Invoked with validate method only if the component is not valid.
 void remove(int i)
          Removes the component, specified by the index, from this container.
 void removeAll()
          Removes all child components from this container.
 void select(int index)
          Selects the item by the specified index.
 void setIndents(int left, int right)
          Sets the popup menu items left and right indents.
 void setSubMenu(int index, LwMenu menu)
          Sets the specified popup menu as a sub menu for the given menu item.
 
Methods inherited from class org.zaval.lw.LwCompList
catchInput, drawSelMarker, focusGained, focusLost, getItem, getItemIdxAt, getItemView, getItemX, getItemY, getLayoutOffset, insertItem, itemCount, itemH, itemW, maxItemSize, posChanged, removeAllItems, removeItem, setLwLayout, setPosController, setSOLocation
 
Methods inherited from class org.zaval.lw.LwAList
addItem, addSelectionListener, correctPM, endDragged, getColor, getItemGaps, getItemH, getItemW, getLines, getLineSize, getMaxOffset, getPosController, getSelected, getSelectedIndex, getSOLocation, getSOSize, isComboMode, isSelected, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseMoved, mousePressed, mouseReleased, moveContent, notifyScrollMan, pageSize, paintOnTop, removeSelectionListener, repaint, setColor, setScrollMan, startDragged
 
Methods inherited from class org.zaval.lw.LwPanel
add, add, calcPreferredSize, count, get, getLwComponentAt, getLwLayout, getPreferredSize, indexOf, insert, invalidate, isInvalidatedByChild, laidout, remove, setBackground, setOpaque, setSize, toFront, updateCashedPs, validate
 
Methods inherited from class org.zaval.lw.LwCanvas
calcInsets, customize, cvp, getBackground, getBottom, getBounds, getHeight, getInsets, getLeft, getLocation, getLwParent, getOrigin, getPSImpl, getRight, getSize, getTop, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isValid, isVisible, paint, repaint, repaint, repaint, requestFocus, setEnabled, setInsets, setLocation, setLwParent, setPSSize, setViewMan, setVisible, update, viewManChanged, vrp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.zaval.lw.LwContainer
add, add, getLwLayout, indexOf, isInvalidatedByChild, paintOnTop
 
Methods inherited from interface org.zaval.lw.LwComponent
getBackground, getLwComponentAt, getLwParent, getOrigin, getViewMan, getVisiblePart, isEnabled, isOpaque, paint, repaint, repaint, repaint, setBackground, setEnabled, setInsets, setLwParent, setOpaque, setViewMan, setVisible, update
 
Methods inherited from interface org.zaval.lw.Layoutable
getBounds, getHeight, getInsets, getLocation, getPreferredSize, getSize, getWidth, getX, getY, isVisible, setLocation, setSize
 
Methods inherited from interface org.zaval.util.Validationable
invalidate, isValid, validate
 
Methods inherited from interface org.zaval.lw.LayoutContainer
count, get
 

Constructor Detail

LwMenu

public LwMenu()
Constructs a popup menu component.

LwMenu

public LwMenu(int key)
Constructs a popup menu component with the given id. The id can be used to identify the popup menu (for example in a case when the selection events are delegated to the parent menu or menu bar).
Parameters:
key - the given menu popup id.
Method Detail

getKey

public int getKey()
Gets the popup menu id.
Returns:
a popup menu id.

setIndents

public void setIndents(int left,
                       int right)
Sets the popup menu items left and right indents. The indents specify extra area size from the right and left borders.
Parameters:
left - the left indent.
right - the right indent.

delegateEvent

public void delegateEvent(boolean b)
Sets the selection events delegation model. There are two ways to perform the events:
  • Delegate the event to the selection listeners list.
  • Don't delegate the event to the selection listeners list and send it to the parent (popup menu or menu bar) to resolve the event destination.
Parameters:
b - the specified delegation model. Use true as the argument value to prevent sending the selection events to the registered listeners and send the events to the parent.

insert

public void insert(int i,
                   java.lang.Object o,
                   LwComponent c)
Description copied from interface: LwContainer
Inserts the specified lightweight component with the specified constraints as a child of this container at the specified position in the container list. The method should call the componentAdded method its layout manager to inform the layout manager that the new child has been added with the given constraints.
Overrides:
insert in class LwCompList
Following copied from interface: org.zaval.lw.LwContainer
Parameters:
i - the position in the container list at which to insert the component.
s - the object expressing layout constraints for this.
c - the lightweight component to be added.

insert

public void insert(int i,
                   LwComponent c,
                   boolean b)
Inserts the given menu item component at the specified index and the given selectable flag The selectable flag says if the item can be selected or it is just a decorative element (like a line separator).
Parameters:
i - the specified item index where to insert the new item.
c - the specified item component.
b - use true as the argument value if the item cannot be selected.

addItem

public void addItem(LwComponent c,
                    boolean b)
Adds the given menu item component with the given selectable flag The selectable flag says if the item can be selected or it is just a decorative element (like a line separator).
Parameters:
c - the specified item component.
b - the given selectable flag. Use true if the item cannot be selected.

addItem

public void addItem(LwComponent c,
                    LwComponent icon)
Adds the given menu item with the specified icon component.
Parameters:
c - the specified item component.
icon - the specified icon component.

removeAll

public void removeAll()
Description copied from interface: LwContainer
Removes all child components from this container. The layout manager of this container should be informed by calling the componentRemoved method of the manager for every child component that has been removed.
Overrides:
removeAll in class LwCompList

remove

public void remove(int i)
Description copied from interface: LwContainer
Removes the component, specified by the index, from this container. The layout manager of this container should be informed by calling the componentRemoved method of the manager.
Overrides:
remove in class LwCompList
Following copied from interface: org.zaval.lw.LwContainer
Parameters:
i - the index of the component to be removed.

setSubMenu

public void setSubMenu(int index,
                       LwMenu menu)
Sets the specified popup menu as a sub menu for the given menu item.
Parameters:
index - the menu item index for what the sub menu is set.
menu - the specified popup sub menu.

getSubMenu

public LwMenu getSubMenu(int index)
Gets the sub menu for the given menu item.
Parameters:
index - the menu item index.
Returns:
a sub menu for the given menu item.

select

public void select(int index)
Description copied from class: LwAList
Selects the item by the specified index.
Overrides:
select in class LwAList
Following copied from class: org.zaval.lw.LwAList
Parameters:
index - the specified item index.

componentAdded

public void componentAdded(java.lang.Object id,
                           Layoutable lw,
                           int index)
Description copied from interface: LwLayout
Invoked when the specified layoutable component was added to the layout container (that uses the layout manager). The specified constraints, layoutable component and child index are passed as arguments into the method.
Specified by:
componentAdded in interface LwLayout
Following copied from interface: org.zaval.lw.LwLayout
Parameters:
id - the layoutable component constraints.
lw - the layoutable component that has been added.
index - the child index.

componentRemoved

public void componentRemoved(Layoutable lw,
                             int index)
Description copied from interface: LwLayout
Invoked when the specified layoutable component was removed from the layout container, that uses the layout manager.
Specified by:
componentRemoved in interface LwLayout
Following copied from interface: org.zaval.lw.LwLayout
Parameters:
lw - the layoutable component that has been removed.
index - the child component index.

calcPreferredSize

public java.awt.Dimension calcPreferredSize(LayoutContainer target)
Description copied from interface: LwLayout
Calculates the preferred size dimension for the layout container. The method has to calculate "pure" preferred size, it means that container insets should not be taken into account.
Specified by:
calcPreferredSize in interface LwLayout
Following copied from interface: org.zaval.lw.LwLayout
Parameters:
target - the layout container.
Returns:
a "pure" preferred size.

layout

public void layout(LayoutContainer target)
Description copied from interface: LwLayout
Lays out the child layoutable components inside the layout container.
Specified by:
layout in interface LwLayout
Following copied from interface: org.zaval.lw.LwLayout
Parameters:
target - the layout container.

drawPosMarker

protected void drawPosMarker(java.awt.Graphics g,
                             int x,
                             int y,
                             int w,
                             int h)
Description copied from class: LwAList
Invoked to paint the list position marker for the specified rectangular area.
Overrides:
drawPosMarker in class LwAList
Following copied from class: org.zaval.lw.LwAList
Parameters:
g - the graphics context to be used for painting.
x - the x coordinate of the rectangular area.
y - the y coordinate of the rectangular area.
w - the width of the rectangular area.
h - the height of the rectangular area.

canHaveFocus

public boolean canHaveFocus()
Description copied from interface: LwComponent
Specifies if the component can have focus.
Overrides:
canHaveFocus in class LwAList
Following copied from interface: org.zaval.lw.LwComponent
Returns:
true if the component can have the focus.

mouseExited

public void mouseExited(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse exits a light weight component.
Overrides:
mouseExited in class LwAList
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

fetchContentComp

public Layoutable fetchContentComp(int index)
Gets the original item component for the given menu item. The popup menu component uses a special wrapper component for its item. It means if you add a component as a menu item you cannot get it by the get method, the method will return the wrapper component. To get your original added component use this method.
Parameters:
index - the menu item index.
Returns:
an original item component.

keyPressed

public void keyPressed(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been pressed.
Overrides:
keyPressed in class LwAList
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

getDefaultLayout

protected LwLayout getDefaultLayout()
Description copied from class: LwPanel
Gets the default layout manager that is set with the container during initialization. This implementation of the method returns LwRastLayout as the default layout manager, the layout manager is got as a static object by "def.lay" key.
Overrides:
getDefaultLayout in class LwCompList
Following copied from class: org.zaval.lw.LwPanel
Returns:
a layout manager.

createItem

protected LwPanel createItem(LwComponent c)
Creates and returns the wrapper item component with the given item component. The method is used whenever the new item component is going to be added.
Parameters:
c - the menu item component.
Returns:
an item wrapper component.

recalc

protected void recalc()
Description copied from class: LwCanvas
Invoked with validate method only if the component is not valid. The method should be overridden to calculate metrical characteristics of the component to minimize computation time of the preferred size for the component. For example, you can calculate a preferred size inside the method and just return it by calcPreferredSize method.
Overrides:
recalc in class LwCompList

perform

protected void perform(java.lang.Object src,
                       java.lang.Object data)
Description copied from class: LwAList
Creates and fires the selection event.
Overrides:
perform in class LwAList
Following copied from class: org.zaval.lw.LwAList
Parameters:
src - the specified source of the event.
data - the specified event related data.


: up