HowTo's - Display: MenuSheet

Define a MenuSheet

Description:
A MenuSheet displays a menu, either as a JMenuBar, a JMenu or a JPopUpMenu .
It is important to know that a MenuSheet can be displayed in both ways, horizontally and vertically. In the first case you see the added MenuSheetItems as dropdownmenus (like File, Edit, Help) or submenus (like About) and in the other case as the menuItems in the submenus (like new, load, save).
You can define MenuSheets wherever you need them / want them to be. But in most cases you might want them to be just a Menubar at top of the Shop window or the ones of the SalesPoints. To put them right where they belong, you overwrite the method getDefaultMenuSheet() of your SalesPoint or the createMenuSheet() method of your Shop.
As mentioned above, the MenuItems or MenuSheets contained by the first defined MenuSheet will be displayed horizontally. All the other MenuSheets and Items appear in the dropdown menu of the first MenuSheet. You can "group" the Items with MenuSheetSeparators.

Used classes:

Related topics:

ToDo:

  1. Locate the method where you want to define the MenuSheet. In this case a SalesPoint is chosen and its getDefaultMenuSheet() method overwritten.
  2. Create the top-level MenuSheet, it's the one that will be displayed horizontally and where all other MenuSheets in this case will be added to.
  3. Create another MenuSheet, it will the dropdown menu of the currently defined horizontal MenuSheet.
  4. Create one MenuSheetItem, name it and add the Action that should be performed when the item is clicked.
    Add the MenuSheetItem to the dropdown menu.
  5. Create a MenuSheetSeperator and add it to the menu.
  6. Create and add another MenuSheetItem to the menu.
  7. Add the newly created dropdown menu to the horizontal menu.
  8. Return the horizontal menu.
  9. Note: You can nest as many MenuSheets as you like and create really complex MenuSheet structures.

Example Source Code:

1
    public MenuSheet getDefaultMenuSheet()
    {
			
        2
        MenuSheet msMenu = new MenuSheet("HorizontalMenuSheet");
			
        3
        MenuSheet msSubMenu = new MenuSheet("myMenu");
			
        4
        MenuSheetItem msiSubItem1 = new MenuSheetItem("Perform an action",
                new DisplayCustomAction());
        msSubMenu.add(msiSubItem1);
			
        5
        MenuSheetSeparator mssSeperator = new MenuSheetSeparator();
        msSubMenu.add(mssSeperator);
			
        6
        MenuSheetItem msiSubItem2 = new MenuSheetItem("Perform another action",
                new DisplayCustomAction());
        msSubMenu.add(msiSubItem2);
			
        // add as many MenuSheetItems or MenuSheet as you like
        .
        .
        .
        
        7
        msMenu.add(msSubMenu);
			
        8
        return msSubMenu;
			
    }
		

Back to:


Define a MenuSheet with JComponents

Description:
If you want to improve the look of your menu, feel free to use JComponents. For further explanations on JComponents in menus "Using Swing Components" of java.sun.com.
Adding JComponents to a MenuSheet is not as easy as adding framework MenuItems, because you can only add MenuSheetObjects with the add method. To add a JComponent anyway, you have to acces the JMenuBar in which the MenuSheet is being displayed by calling the getMenuBar() method. To this you add the JMenu with all the JMenuItems like CheckBoxes or RadioButtons added to it and which you initialize before.

Used classes:

Related topics:

ToDo:

  1. Locate the method where you want to define the MenuSheet. In this case a new method getJComponentMenuSheet() was created.
  2. Create the top-level MenuSheet, the one that is displayed horizontally.
  3. Initialize a JMenu using the javax.swing package.
  4. Initialize chosen JMenuItems and add them to the JMenu. Refer to "Using Swing Components" about possible item types.
    In this case a JCheckBoxMenuItem and a JRadioButtonMenuItem where added.
  5. Get the JMenuBar of the top-level MenuSheet and add the newly created JMenu to it.
  6. Finally return the MenuSheet.

Example Source Code:

1
    public MenuSheet getJComponentMenuSheet()
    {
			
        2
        MenuSheet msMenu = new MenuSheet("JComponentMenu");
			
        3
        JMenu jmMenu = new JMenu("JMenuItems");
			
        4
        JCheckBoxMenuItem jcbItem1 = new JCheckBoxMenuItem("JCheckBox");
        jmMenu.add(jcbItem1);
        JRadioButtonMenuItem jrbmItem2 = new JRadioButtonMenuItem("JRadioButtonMenuItem");
        jmMenu.add(jrbmItem2);
			
        5
        msMenu.getMenuBar().add(jmMenu);
			
        6
        return msMenu;
    }
		

Back to:


Define a MenuSheet for a Shop

Description:
Menus are essential for users interacting with an application. To create a menu in a Shop you will need to redefine the method createShopMenuSheet() of your instance of Shop.

Used classes:

Related topics:

ToDo:

  1. In your Shop class create the method createShopMenuSheet().
  2. Create your desired MenuSheet and return it. Therefore refer to Define a MenuSheet.

Example Source Code:

1
public class DisplayShop extends Shop
{
			
    .
    .
    .
			
    public MenuSheet createShopMenuSheet()
    {
			
        2
        MenuSheet msMenu = new MenuSheet("ShopMenu");
			
        // add your MenuSheets and MenuSheetItems as needed
            
        .
        .
        .
            
        return msMenu;
    }
            
    .
    .
    .
            
}
		

Back to:


Define a MenuSheet for a SalesPoint

Description:
Normally you display a SalesPoint in a new window. To add a menu to it, you simply have to redefine the method getDefaultMenuSheet() of your instance of SalesPoint.

Used classes:

Related topics:

ToDo:

  1. In your SalesPoint class create the method getDefaultFormSheet().
  2. Create your desired MenuSheet and return it. Therefore refer to Define a MenuSheet.

Example Source Code:

1
public class DisplaySalesPoint extends SalesPoint
{
			
    .
    .
    .
			
    public MenuSheet getDefaultMenuSheet()
    {
			
        2
        MenuSheet msMenu = new MenuSheet("HorizontalMenuSheet");
			
        // add your MenuSheets and MenuSheetItems as needed
            
        .
        .
        .
            
        return msSubMenu;
    }
            
    .
    .
    .
            
}
		

Back to:


Define a StatusMenuSheet for a SalesPoint

Description:
SalesPoints are being displayed in a separate window but also have a StatusDisplay at the Shop, which is the TabbedPane in the Shop's Frame, labled the name of the SalesPoint. By bringing it on top, it shows what is defined as the StatusDisplay in your SalesPoint instance and also adds the Menu defined as StatusMenuSheet in the SalesPoint instance to the Shop's MenuSheet. By default, both, the StatusFormSheet and the StatusMenuSheet are empty.
Feel free to use the StatusDisplay and MenuSheet, which are equally handled to the DefaultFormSheet and the DefaultMenuSheet except that due to the strong division of the Shop and it's SalesPoints it is not possible to have processes running on it. You may trigger a Processes on it, but they will always be displayed by the SalesPoint's window. Therefor a more suitable name would be "Statical Display".

Used classes:

Related topics:

ToDo:

  1. In your SalesPoint class create the method getDefaultStatusMenuSheet().
  2. Create your desired MenuSheet and return it. Therefore refer to Define a MenuSheet.

Example Source Code:

1
public class DisplaySalesPoint extends SalesPoint
{
			
    .
    .
    .
			
    public MenuSheet getDefaultStatusMenuSheet()
    {
			
        2
        MenuSheet msMenu = new MenuSheet("StatusMenu");
			
        // add your MenuSheets and MenuSheetItems as needed
            
        .
        .
        .
            
        return msMenu;
    }
            
    .
    .
    .
            
}
		

Back to:


Alter a Shop's MenuSheet during runtime

Description:
Sometimes there are reasons to change a Shop's MenuSheet during runtime. But in the class Shop a method setMenuSheet(MenuSheet ms) like the one in the class SalesPoint doesn't exists. This makes it a little more complicate. It is necessary to get the Shop's frame, which is actually a MultiWindow. The class MultiWindow provides the necessary public void setMenuSheet(MenuSheet newMenuSheet) method.
Like this it is possible to change the MenuSheet, whenever wanted.

Used classes:

Related topics:

ToDo:

  1. Get the Shop's frame, while casting it as a MultiWindow.
  2. Create the new MenuSheet for the Shop.
    (See also: Define a MenuSheet).
  3. Set the new MenuSheet on the MultiWindow.

Example Source Code:

 
    1
        DisplayShop displayShop = new DisplayShop();
        MultiWindow multiWindow = (MultiWindow) displayShop.getShopFrame();
			
    2
        MenuSheet menuShop = super.createShopMenuSheet();
        // get the first menu bar
        MenuSheet menuBar = (MenuSheet)menuShop.getTaggedItem(SHOP_MENU_TAG, false);
        // create new MenuSheetItem
        MenuSheetItem menuItemNew = new MenuSheetItem("Important", "Important_TAG",
                new sale.Action()
                {
                   public void doAction (SaleProcess p, SalesPoint sp)
                   {
                      System.out.println("very important action!");
                   }
                });
        // add it to the MenuSheet
        menuBar.add(menuItemNew);
			
    3
        multiWindow.setMenuSheet(menuShop);
		

Back to:


previous Display: FormSheetDisplay: LogFile Management next


Valid HTML 4.01!