1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import org.objectweb.jac.aspects.gui.*; 21 import java.io.PrintWriter ; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.Vector ; 25 26 public class ToolBar extends AbstractView implements MenuView, HTMLViewer, MenuListener { 27 28 HashMap map = new HashMap (); 30 Vector keys = new Vector (); 32 33 public ToolBar(ViewFactory factory, DisplayContext context) { 34 super(factory,context); 35 } 36 37 39 public void addSubMenu(String label, String icon, MenuView submenu) { 40 } 41 42 public void addAction(String label, String icon, Callback callback) { 43 if (!map.containsKey(label)) { 44 keys.add(label); 45 map.put(label,new MenuItem(label,icon,callback)); 46 } 47 } 48 49 public void addSeparator() { 50 } 51 52 String position; 53 54 58 public String getPosition() { 59 return position; 60 } 61 62 66 public void setPosition(String v) { 67 this.position = v; 68 } 69 70 72 public void genHTML(PrintWriter out) { 73 out.println("<div class=\"toolBar\">"); 74 Iterator i = keys.iterator(); 75 while (i.hasNext()) { 76 String key = (String )i.next(); 77 Object item = map.get(key); 78 if (item instanceof MenuItem) { 79 out.print("<a HREF=\""+eventURL("onMenuClick")+ 80 "&item="+key+"\">"); 81 if (((MenuItem)item).icon!=null) 82 out.print(iconElement(((MenuItem)item).icon,"")); 83 else 84 out.println(key); 85 out.println("</a>"); 86 } 87 } 88 out.println("</div>"); 89 } 90 91 93 public void onMenuClick(String key) { 94 try { 95 MenuItem item = (MenuItem)map.get(key); 96 if (item.callback!=null) 97 EventHandler.get().onInvoke( 98 context, 99 new InvokeEvent(this,null,item.callback.getMethod())); 100 else 101 context.getDisplay().refresh(); 102 } catch (Exception e) { 103 context.getDisplay().showError("Menu error",e.toString()); 104 } 105 } 106 } 107 | Popular Tags |