KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > swing > JMenuImpl


1 // skeleton class automatically generated
2

3 package org.objectweb.fractal.swing;
4
5 import org.objectweb.fractal.api.control.BindingController;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9 import java.util.TreeMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import javax.swing.JMenuItem JavaDoc;
13 import javax.swing.Action JavaDoc;
14 import javax.swing.KeyStroke JavaDoc;
15
16 public class JMenuImpl
17   extends javax.swing.JMenu JavaDoc
18   implements JMenuItf, JMenuAttributes, BindingController
19 {
20
21   // fields manually added
22
public final static String JavaDoc ITEMS_BINDING = "items";
23   private Map JavaDoc actions = new TreeMap JavaDoc();
24   private Map JavaDoc items = new HashMap JavaDoc();
25
26   public JMenuImpl () {
27     super();
28   }
29   public JMenuImpl (java.lang.String JavaDoc arg0) {
30     super(arg0);
31   }
32   public JMenuImpl (javax.swing.Action JavaDoc arg0) {
33     super(arg0);
34   }
35   public JMenuImpl (java.lang.String JavaDoc arg0, boolean arg1) {
36     super(arg0,arg1);
37   }
38
39   public String JavaDoc[] listFc () {
40     return (String JavaDoc[])actions.keySet().toArray(new String JavaDoc[actions.size()]);
41   }
42
43   public Object JavaDoc lookupFc (String JavaDoc clientItfName) {
44     // put your own code here
45
if (clientItfName.startsWith(ITEMS_BINDING)) {
46       return actions.get(clientItfName);
47     }
48     return null;
49   }
50
51   public void bindFc (String JavaDoc clientItfName, Object JavaDoc serverItf) {
52     // put your own code here
53
if (clientItfName.startsWith(ITEMS_BINDING)) {
54       removeAll();
55       actions.put(clientItfName, serverItf);
56       Iterator JavaDoc i = actions.entrySet().iterator();
57       while (i.hasNext()) {
58         Map.Entry JavaDoc e = (Map.Entry JavaDoc)i.next();
59         Object JavaDoc o = e.getValue();
60         if (o instanceof JSeparatorItf) {
61           addSeparator();
62         } else {
63           add((Action JavaDoc)o);
64         }
65         items.put((String JavaDoc)e.getKey(), getItem(getItemCount()-1));
66       }
67     }
68   }
69
70   public void unbindFc (String JavaDoc clientItfName) {
71     // put your own code here
72
if (clientItfName.startsWith(ITEMS_BINDING)) {
73       actions.remove(clientItfName);
74       remove((JMenuItem JavaDoc)items.remove(clientItfName));
75     }
76   }
77
78   // manually added
79
public JMenuItem JavaDoc add (Action JavaDoc a) {
80     JMenuItem JavaDoc item = super.add(a);
81     KeyStroke JavaDoc stroke = (KeyStroke JavaDoc)a.getValue(Action.ACCELERATOR_KEY);
82     if (stroke != null) {
83       item.setAccelerator(stroke);
84     }
85     return item;
86   }
87
88 }
89
Popular Tags