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