1 3 package org.objectweb.fractal.swing; 4 5 import org.objectweb.fractal.api.control.BindingController; 6 7 import java.util.Map ; 8 import java.util.HashMap ; 9 import java.util.TreeMap ; 10 import java.util.Iterator ; 11 12 import javax.swing.Action ; 13 import javax.swing.JComponent ; 14 15 public class JToolBarImpl 16 extends javax.swing.JToolBar 17 implements JToolBarItf, JToolBarAttributes, BindingController 18 { 19 20 public final static String ACTIONS_BINDING = "actions"; 22 private Map actions = new TreeMap (); 23 private Map components = new HashMap (); 24 25 public JToolBarImpl () { 26 super(); 27 } 28 public JToolBarImpl (int arg0) { 29 super(arg0); 30 } 31 public JToolBarImpl (String arg0) { 32 super(arg0); 33 } 34 public JToolBarImpl (String arg0, int arg1) { 35 super(arg0,arg1); 36 } 37 38 public String [] listFc () { 39 return (String [])actions.keySet().toArray(new String [actions.size()]); 40 } 41 42 public Object lookupFc (String clientItfName) { 43 if (clientItfName.startsWith(ACTIONS_BINDING)) { 45 return actions.get(clientItfName); 46 } 47 return null; 48 } 49 50 public void bindFc (String clientItfName, Object serverItf) { 51 if (clientItfName.startsWith(ACTIONS_BINDING)) { 53 removeAll(); 54 actions.put(clientItfName, serverItf); 55 Iterator i = actions.entrySet().iterator(); 56 while (i.hasNext()) { 57 Map.Entry e = (Map.Entry )i.next(); 58 Object o = e.getValue(); 59 if (o instanceof JSeparatorItf) { 60 addSeparator(); 61 } else if (o instanceof JComponent ) { 62 add((JComponent )o); 63 } else { 64 add((Action )o); 65 } 66 components.put((String )e.getKey(), getComponent(getComponentCount()-1)); 67 } 68 } 69 } 70 71 public void unbindFc (String clientItfName) { 72 if (clientItfName.startsWith(ACTIONS_BINDING)) { 74 actions.remove(clientItfName); 75 remove((java.awt.Component )components.remove(clientItfName)); 76 } 77 } 78 79 } 80 | Popular Tags |