KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > AbstractMenu


1 /*
2   Copyright (C) 2001 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.web;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Vector JavaDoc;
22 import org.apache.log4j.Logger;
23 import org.objectweb.jac.aspects.gui.*;
24
25 public abstract class AbstractMenu extends AbstractView
26     implements MenuView, HTMLViewer, MenuListener
27 {
28     static Logger logger = Logger.getLogger("gui.menu");
29     static Logger loggerEvents = Logger.getLogger("gui.events");
30
31     // key -> [ callback | Menu | null ]
32
HashMap JavaDoc map = new HashMap JavaDoc();
33     // item order
34
Vector JavaDoc keys = new Vector JavaDoc();
35
36     public AbstractMenu(ViewFactory factory, DisplayContext context) {
37         super(factory,context);
38     }
39
40     // MenuView interface
41

42     public void addSubMenu(String JavaDoc label, String JavaDoc icon, MenuView submenu) {
43         if (!map.containsKey(label)) {
44             logger.debug(this+".addSubMenu "+label+" -> "+submenu);
45             keys.add(label);
46             map.put(label,submenu);
47         }
48     }
49
50     public void addAction(String JavaDoc label, String JavaDoc icon, Callback callback) {
51         if (!map.containsKey(label)) {
52             logger.debug(this+".addAction "+label+" -> "+callback);
53             keys.add(label);
54             map.put(label,new MenuItem(label,icon,callback));
55         }
56     }
57
58     public void addSeparator() {
59     }
60    
61     String JavaDoc position = org.objectweb.jac.aspects.gui.Menu.LEFT;
62    
63     /**
64      * Get the value of position.
65      * @return value of position.
66      */

67     public String JavaDoc getPosition() {
68         return position;
69     }
70    
71     /**
72      * Set the value of position.
73      * @param v Value to assign to position.
74      */

75     public void setPosition(String JavaDoc v) {
76         this.position = v;
77         if (position==null)
78             position = org.objectweb.jac.aspects.gui.Menu.LEFT;
79     }
80
81     // MenuListener interface
82

83     public void onMenuClick(String JavaDoc key) {
84         try {
85             loggerEvents.debug(this+".onMenuClick `"+key+"'");
86             MenuItem item = (MenuItem)map.get(key);
87             if (item!=null && item.callback!=null)
88                 EventHandler.get().onInvoke(
89                     context,
90                     new InvokeEvent(this,
91                                     item.callback.getObject(),
92                                     item.callback.getMethod(),
93                                     item.callback.getParameters()),
94                     true,
95                     null,null);
96             else {
97                 loggerEvents.debug(" No item("+item+") or callback("+
98                           (item==null?"":""+item.callback)+") is null");
99                 context.getDisplay().refresh();
100             }
101         } catch (Exception JavaDoc e) {
102             context.getDisplay().showError("Menu error","onMenuClick "+key+": "+
103                                            e.toString()+"<br><pre>"+map+"</pre>");
104             logger.error("onMenuClick "+key,e);
105         }
106     }
107 }
108
Popular Tags