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.awt.Component ; 10 11 import javax.swing.JComponent ; 12 13 public class ContainerImpl 14 extends java.awt.Container 15 implements ContainerItf, ContainerAttributes, BindingController 16 { 17 18 public final static String LEFT_COMPONENT_BINDING = "left-component"; 20 public final static String TOP_COMPONENT_BINDING = "top-component"; 21 public final static String RIGHT_COMPONENT_BINDING = "right-component"; 22 public final static String BOTTOM_COMPONENT_BINDING = "bottom-component"; 23 public final static String CENTER_COMPONENT_BINDING = "center-component"; 24 public final static String COMPONENTS_BINDING = "components"; 25 public final static String LAYOUT_BINDING = "layout"; 26 private JComponent left, top, right, bottom, center; 27 private Map components = new HashMap (); 28 private java.awt.LayoutManager layout; 29 30 public ContainerImpl () { 31 super(); 32 } 33 34 public String [] listFc () { 35 int s = components.size(); 36 String [] result = (String [])components.keySet().toArray(new String [s + 6]); 37 result[s] = LEFT_COMPONENT_BINDING; 38 result[s+1] = TOP_COMPONENT_BINDING; 39 result[s+2] = RIGHT_COMPONENT_BINDING; 40 result[s+3] = BOTTOM_COMPONENT_BINDING; 41 result[s+4] = CENTER_COMPONENT_BINDING; 42 result[s+5] = LAYOUT_BINDING; 43 return result; 44 } 45 46 public Object lookupFc (String clientItfName) { 47 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 49 return left; 50 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 51 return top; 52 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 53 return right; 54 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 55 return bottom; 56 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 57 return center; 58 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 59 return components.get(clientItfName); 60 } else if (clientItfName.equals(LAYOUT_BINDING)) { 61 return layout; 62 } 63 return null; 64 } 65 66 public void bindFc (String clientItfName, Object serverItf) { 67 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 69 left = (JComponent )serverItf; 70 super.add(left, "West"); 71 validate(); 72 repaint(); 73 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 74 top = (JComponent )serverItf; 75 super.add(top, "North"); 76 validate(); 77 repaint(); 78 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 79 right = (JComponent )serverItf; 80 super.add(right, "East"); 81 validate(); 82 repaint(); 83 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 84 bottom = (JComponent )serverItf; 85 super.add(bottom, "South"); 86 validate(); 87 repaint(); 88 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 89 center = (JComponent )serverItf; 90 super.add(center, "Center"); 91 validate(); 92 repaint(); 93 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 94 components.put(clientItfName, serverItf); 95 super.add((java.awt.Component )serverItf); 96 validate(); 97 repaint(); 98 } else if (clientItfName.equals(LAYOUT_BINDING)) { 99 layout = (java.awt.LayoutManager )serverItf; 100 super.setLayout(layout); 101 validate(); 102 repaint(); 103 } 104 } 105 106 public void unbindFc (String clientItfName) { 107 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 109 super.remove(left); 110 validate(); 111 repaint(); 112 left = null; 113 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 114 super.remove(top); 115 validate(); 116 repaint(); 117 top = null; 118 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 119 super.remove(right); 120 validate(); 121 repaint(); 122 right = null; 123 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 124 super.remove(bottom); 125 validate(); 126 repaint(); 127 bottom = null; 128 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 129 super.remove(center); 130 validate(); 131 repaint(); 132 center = null; 133 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 134 Component c = (Component )components.get(clientItfName); 135 super.remove(c); 136 validate(); 137 repaint(); 138 } else if (clientItfName.equals(LAYOUT_BINDING)) { 139 layout = null; 140 } 141 } 142 143 } 144 | Popular Tags |