package e4s.tutorial; import e4s.html.*; import e4s.html.navigation.E4Menu; import e4s.html.navigation.E4MenuFrameset; import e4s.servlet.E4ModuleImplementation; /** * Style examples for menus. * * {@tutorial Example_MenuStyles} */ public class Example_MenuStyles extends E4ModuleImplementation { public static E4Method start = null; public static E4Method choose = null; public static E4Method menu = null; public static E4Method functionA = null; public static E4Method functionB = null; public static E4Method functionC = null; private final static String PARAM_MENU_STYLE = "MSTYLE"; private final static int MENU_STYLES[] = { E4Menu.MENU_STYLE_IMAGES_A, E4Menu.MENU_STYLE_IMAGES_B1, E4Menu.MENU_STYLE_IMAGES_B2, E4Menu.MENU_STYLE_IMAGES_B3, E4Menu.MENU_STYLE_IMAGES_B4, E4Menu.MENU_STYLE_IMAGES_C1, E4Menu.MENU_STYLE_IMAGES_C2, E4Menu.MENU_STYLE_IMAGES_C3, E4Menu.MENU_STYLE_IMAGES_D1, E4Menu.MENU_STYLE_IMAGES_D2, E4Menu.MENU_STYLE_IMAGES_E1 }; private final static String MENU_NAMES[] = { "A", "B1", "B2", "B3", "B4", "C1", "C2", "C3", "D1", "D2", "E1" }; private final static E4FrameName FRAME_MENU = E4FrameName.ANY(); public void start( HTML html, E4CgiParams params ) throws Exception { FRAMESET frameset = html.FRAMESET(FRAMESET._FRAMESET_COLS); FRAME fChoose = frameset.FRAME(200); fChoose.setUrl(choose); FRAME fMenu = frameset.FRAME(FRAME_MENU, "*"); fMenu.setUrl(menu); } /** * Choose a style for the menu */ public void choose( HTML html, E4CgiParams params ) throws Exception { html.print("Choose a style:"); html.P(); for( int i = 0; i < MENU_STYLES.length; i++ ) { A href = html.A(menu); href.addParameter(PARAM_MENU_STYLE,MENU_STYLES[i]); href.setTarget(FRAME_MENU); href.print("Style " + MENU_NAMES[i]); html.BR(); } } public void menu( HTML html, E4CgiParams params ) throws Exception { int style = params.getInt(PARAM_MENU_STYLE); if (style == -1) style = E4Menu.MENU_STYLE_IMAGES_A; E4MenuFrameset mFrameset = html.MenuFrameset("MENUEXAMPLE.3",style,getServlet()); // mFrameset.setColorBaseline(E4Color.Soft(E4Color.RED,0.5f)); // add a menu item, remember the created ID of this item (which propably might be 1) // and mark it as the active menu item int id = mFrameset.addMenuItem( "Function A",new A(functionA)); mFrameset.changeActive(id); // add other menu items mFrameset.addMenuItem( "Function B",functionB); mFrameset.addMenuItem( "Function C",functionC); } public void functionA( HTML html ) { html.println("-- A --"); } public void functionB( HTML html ) { html.println("-- B --"); } public void functionC( HTML html ) { html.println("-- C --"); } // public void menuExampleSimpleVert( HTML html ) // throws Exception // { // int style = E4Menu.MENU_STYLE_DIRECTION_VERTICAL | E4Menu.MENU_STYLE_REPRESENTATION_TEXT; // // E4MenuFrameset mFrameset = html.MenuFrameset("MENUEXAMPLE",style,getServlet()); // mFrameset.setColorBaseline(E4Color.Soft(E4Color.RED,0.5f)); // // // add a menu item, remember the created ID of this item (which propably might be 1) // // and mark it as the active menu item // int id = mFrameset.addMenuItem( "Function - A",functionA); // mFrameset.changeActive(id); // // // add another menu item // mFrameset.addMenuItem( "Function - B",functionB); // mFrameset.addMenuItem( "C",functionC); // mFrameset.addMenuItem( "List",Example_SortedList.startList); // mFrameset.addMenuItem( "Tree",Example_Tree.treeExampleB); // mFrameset.addMenuItem( "Menu",subMenu); // } // public void menuExampleVertical( HTML html ) // { // int style = E4Menu.MENU_STYLE_DIRECTION_VERTICAL // | E4Menu.MENU_STYLE_REPRESENTATION_GRAFICAL; // // E4MenuFrameset mFrameset = html.MenuFrameset("MENUEXAMPLE",style,getServlet()); // // // add two menu items, but do not mark any of them as active // mFrameset.addMenuItem( "Function - A",new A(functionA)); // mFrameset.addMenuItem( "Function - B",new A(functionB)); // } }