Home about services products contact login
   com.smardec.asc

Advanced Swing Components

  animatepanel
  autocomplete
  dropdown
  filechooser
  fontchooser
  gradient
  hyperlink
  outlookpanel
  outlookpanel.renderers
  quick
  rotate
  sliderpanel
  spantable
  splashscreen
  statusbar
  table
  table.renderers
  table.wrappers
  tree
  treetable
  util
  xmlbars
  xmlbars.menubar
  xmlbars.toolbar
  xmlbars.toolbar.layouts
com.smardec.asc.xmlbars
Class MenuToolBarManager

java.lang.Object
|
+--com.smardec.asc.xmlbars.MenuToolBarManager

public class MenuToolBarManager
extends java.lang.Object

MenuToolBarManager builds menus and toolbars using the information from the xml. It also supports enabling/disabling actions or group of actions, getting menus, toolbars and actions by id.

Sample usage:


   MenuToolBarManager menuToolBarManager = new MenuToolBarManager(getClass().getClassLoader().getResourceAsStream("com/smardec/demo/asc/menutoolbar.xml"));
   menuToolBarManager.buildMenuAndToolbar();

   JMenuBar jMenuBarXml = menuToolBarManager.getMenuBarById("MenuBar.Main");
   if (jMenuBarXml != null)
       setJMenuBar(jMenuBarXml);

   JAscToolBar jAscToolBarMain = menuToolBarManager.getToolBarById("ToolBar.Main");
   if (jAscToolBarMain != null)
       getContentPane().add(jAscToolBarMain, ToolbarDockLayout.North);
   
Xml file has the following structure:
 <!--
     The menutoolbar element is the root element of the menutoolbar.xml file.
     It contains all the information used by com.smardec.asc.xmlbars.MenuToolBarManager
     to build menus and toolbars.
     -->
 <!ELEMENT menutoolbar (actions, menubars, popups, toolbars)>

 <!--
     The actions element contains information about the actions.
     -->
 <!ELEMENT actions (action+)>
 <!--
     'icon-base-path' action's base path, used with 'icon' and 'large-icon'
     to complete icon's path in action element.
     -->
 <!ATTLIST actions icon-base-path  CDATA   #IMPLIED >

 <!--
     The action element describes action that is used for menu items and toolbar buttons.
     -->
 <!ELEMENT action EMPTY>
 <!--
     'id'            unique action id
     'class'         action's class derived from com.smardec.asc.xmlbars.BasicAction
                     that represents the action
     'text'          action's text, used for menu items and toolbar buttons,
                     overrides the corresponding attribute of the action
     'mnemonic'      action's mnemonic, used for menu items,
                     overrides the corresponding attribute of the action
     'keystroke'     action's keystroke, used for menu items,
                     overrides the corresponding attribute of the action
     'icon',         action's icon used for menu items and toolbar buttons,
                     overrides the corresponding attribute of the action
     'large-icon'    action's large icon, used for toolbar buttons,
                     overrides the corresponding attribute of the action
     'tooltip',      action's tooltip, used for menu items and toolbar buttons,
                     overrides the corresponding attribute of the action
     'enabled',      action's status, used to enable/disable action,
                     overrides the corresponding attribute of the action
     'group-id',     action's group id, used to manage group of actions,
                     overrides the corresponding attribute of the action
     -->
 <!ATTLIST action
     id          CDATA   #REQUIRED
     class       CDATA   #REQUIRED
     text        CDATA   #IMPLIED
     mnemonic    CDATA   #IMPLIED
     keystroke   CDATA   #IMPLIED
     icon        CDATA   #IMPLIED
     large-icon  CDATA   #IMPLIED
     tooltip     CDATA   #IMPLIED
     enabled     CDATA   #IMPLIED
     group-id    CDATA   #IMPLIED
 >

 <!--
     The menubars element contains information about the menubars.
     -->
 <!ELEMENT menubars (menubar)>
 <!--
     The menubar element contains information about the menubar.
     -->
 <!ELEMENT menubar (items)>
 <!--
     'id'    unique menubar id
     -->
 <!ATTLIST menubar id CDATA #REQUIRED>

 <!--
     The popups element contains information about the popup menus.
     -->
 <!ELEMENT popups (popupmenu)>
 <!--
     The popupmenu element contains information about the popup menu.
     -->
 <!ELEMENT popupmenu (items)>
 <!--
     'id'    unique popup menu id
     -->
 <!ATTLIST popupmenu id CDATA #REQUIRED >

 <!--
     The toolbars element contains information about the toolbars.
     -->
 <!ELEMENT toolbars (toolbar)>
 <!--
     The toolbar element contains information about the toolbar.
     -->
 <!ELEMENT toolbar (items)>
 <!--
     'id'            unique toolbar id
     'orientation'   specifies toolbar's orientation
     'floatable'     specifies toolbar's floatable property
     'button-size'   specifies toolbar's button size in pixels
     -->
 <!ATTLIST toolbar
     id              CDATA                       #REQUIRED
     name        	 CDATA   					 #IMPLIED
     orientation     (horizontal | vertical)     #IMPLIED
     floatable       (yes | true | no | false)   #IMPLIED
     button-size     CDATA                       #IMPLIED
 >

 <!--
     The items element contains information about the menu toolbar items.
     -->
 <!ELEMENT items (menu | item | separator)+>

 <!--
     The menu element contains information about the menu.
     -->
 <!ELEMENT menu (items?)>
 <!--
     'id'        unique menu id
     'text'      specifies menu's text
     'mnemonic'  specifies menu's keyboard mnemonic
     'class'     class derived from javax.swing.JMenu that represents the menu with its
                 items and submenus, used to create dynamic menus like look&feel menu
     -->
 <!ATTLIST menu
     id          CDATA   #REQUIRED
     text        CDATA   #IMPLIED
     mnemonic    CDATA   #IMPLIED
     class       CDATA   #IMPLIED
 >

 <!--
     The item element contains information about the menu or toolbar item.
     -->
 <!ELEMENT item EMPTY>
 <!--
     'action-id'     specifies action for the item
     'type'          type of menu or toolbar item, 'AscCheckBox', 'AscRadioButton'
                     and 'IconicCheckBox' can be used for menu items, 'ToggleButton'
                     can be used for toolbar items
     'button-group'  specifies multiple-exclusion scope for radio button menu items
                     or toggle toolbar buttons
     -->
 <!ATTLIST item
     action-id       CDATA                                                           #REQUIRED
     type            (AscCheckBox | AscRadioButton |
                         IconicCheckBox | ToggleButton)  #IMPLIED
     button-group    CDATA                                                           #IMPLIED
 >

 <!--
     The separator element specifies separator for menu and toolbar items.
     -->
 <!ELEMENT separator EMPTY>
 


Constructor Summary
MenuToolBarManager(java.io.InputStream inputStream)
Creates new MenuToolBarManager given the InputStream to read from.
MenuToolBarManager(java.lang.String menuToolBarFileName)
Creates new MenuToolBarManager given the name of the xml file to read from.
Method Summary
void buildMenuAndToolbar()
Builds menus and toolbars using specified data.
BasicAction getActionById(java.lang.String actionId)
Returns BasicAction object with specified action id actionId.
java.util.Vector getActionsByGroupId(java.lang.String groupId)
Returns Vector of BasicAction objects with specified id groupId.
javax.swing.JMenuBar getMenuBarById(java.lang.String menubarId)
Returns JMenuBar object with specified menu bar id menubarId.
javax.swing.JMenu getMenuById(java.lang.String menuId)
Returns JMenu object with specified menu id menuId.
javax.swing.JPopupMenu getPopupMenuById(java.lang.String popupMenuId)
Returns JPopupMenu object with specified popup menu id popupMenuId.
JAscToolBar getToolBarById(java.lang.String toolbarId)
Returns JAscToolBar object with specified ToolBar id toolbarId.
boolean isUseSmallToolBarIcons()
Idicates which icons MenuToolBarManager uses to create toolbar.
void setGroupEnabled(java.lang.String groupId, boolean newValue)
Enables or disables actions with specified groupId.
void setUseSmallToolBarIcons(boolean useSmallToolBarIcons)
Specifies which icons MenuToolBarManager uses to create toolbar.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail
MenuToolBarManager
public MenuToolBarManager(java.lang.String menuToolBarFileName) throws java.lang.Exception

Creates new MenuToolBarManager given the name of the xml file to read from.

Parameters:
menuToolBarFileName - xml file name to read data from
Throws:
java.lang.Exception - if failed to read file

MenuToolBarManager
public MenuToolBarManager(java.io.InputStream inputStream) throws java.lang.Exception
Creates new MenuToolBarManager given the InputStream to read from.

Parameters:
inputStream - InputStream to read from
Throws:
java.lang.Exception - if failed to read stream
Method Detail
buildMenuAndToolbar
public void buildMenuAndToolbar() throws java.lang.Exception
Builds menus and toolbars using specified data.

Throws:
java.lang.Exception - if failed to build
See Also:
setUseSmallToolBarIcons(boolean)

getMenuBarById
public javax.swing.JMenuBar getMenuBarById(java.lang.String menubarId)
Returns JMenuBar object with specified menu bar id menubarId.

Parameters:
menubarId - id of JMenuBar
Returns:
JMenuBar object with specified menu bar id menubarId.

getPopupMenuById
public javax.swing.JPopupMenu getPopupMenuById(java.lang.String popupMenuId)
Returns JPopupMenu object with specified popup menu id popupMenuId.

Parameters:
popupMenuId - id of JPopupMenu
Returns:
JPopupMenu object with specified popup menu id popupMenuId.

getMenuById
public javax.swing.JMenu getMenuById(java.lang.String menuId)
Returns JMenu object with specified menu id menuId.

Parameters:
menuId - id of JMenu
Returns:
JMenu object with specified menu id menuId.

getToolBarById
public JAscToolBar getToolBarById(java.lang.String toolbarId)
Returns JAscToolBar object with specified ToolBar id toolbarId.

Parameters:
toolbarId - id of JAscToolBar
Returns:
JAscToolBar object with specified ToolBar id toolbarId.

getActionById
public BasicAction getActionById(java.lang.String actionId)
Returns BasicAction object with specified action id actionId.

Parameters:
actionId - id of BasicAction
Returns:
BasicAction object with specified action id actionId.

getActionsByGroupId
public java.util.Vector getActionsByGroupId(java.lang.String groupId)
Returns Vector of BasicAction objects with specified id groupId.

Parameters:
groupId - id of actions' group
Returns:
Vector of BasicAction objects with specified id groupId.

setGroupEnabled
public void setGroupEnabled(java.lang.String groupId, boolean newValue)
Enables or disables actions with specified groupId.

Parameters:
groupId - group id to enable or disable
newValue - true to enable the actions with id groupId, false to disable them

isUseSmallToolBarIcons
public boolean isUseSmallToolBarIcons()
Idicates which icons MenuToolBarManager uses to create toolbar. The default value is false. The default is false.

Returns:
true if MenuToolBarManager uses small icons, false - large icons.

setUseSmallToolBarIcons
public void setUseSmallToolBarIcons(boolean useSmallToolBarIcons)
Specifies which icons MenuToolBarManager uses to create toolbar. The default value is false.
Note: this method should be ivoked prior to buildMenuAndToolbar() The default is false.

Parameters:
useSmallToolBarIcons - to use small icons, false otherwise
Home about services products contact login