001 /* 002 Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui.web; 019 020 import java.io.IOException; 021 import java.io.PrintWriter; 022 import java.util.Iterator; 023 import org.objectweb.jac.aspects.gui.*; 024 import org.objectweb.jac.aspects.gui.Menu; 025 import org.objectweb.jac.util.ExtArrays; 026 027 public class MenuBar extends AbstractMenu implements MenuView, HTMLViewer { 028 029 public MenuBar(ViewFactory factory, DisplayContext context) { 030 super(factory,context); 031 } 032 033 // HTMLViewer interface 034 public void genHTML(PrintWriter out) throws IOException { 035 if (message!=null) { 036 String msg = (String)message.invoke(null,ExtArrays.emptyObjectArray); 037 out.println("<div class=\"message\">"+msg+"</div>"); 038 } 039 if (position.equals(Menu.TOP)) { 040 out.println("<div class=\"menuBarT\">"); 041 } else if (position.equals(Menu.BOTTOM)) { 042 out.println("<div class=\"menuBarB\">"); 043 } else if (position.equals(Menu.LEFT)) { 044 out.println("<div class=\"menuBarL\">"); 045 } else if (position.equals(Menu.RIGHT)) { 046 out.println("<div class=\"menuBarR\">"); 047 } 048 Iterator i = keys.iterator(); 049 while (i.hasNext()) { 050 String key = (String)i.next(); 051 Object item = map.get(key); 052 if (item instanceof MenuView) { 053 out.println(key); 054 ((MenuView)item).setPosition(position); 055 ((HTMLViewer)item).genHTML(out); 056 } else { 057 out.print("<div><a href=\""+eventURL("onMenuClick")+ 058 "&item="+key+"\">"); 059 if (((MenuItem)item).icon!=null) 060 out.print(iconElement(((MenuItem)item).icon,"")); 061 out.println(key+"</a></div>"); 062 } 063 } 064 out.println("</div>"); 065 } 066 }