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 JPanelImpl 14 extends javax.swing.JPanel 15 implements JPanelItf, JPanelAttributes, 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 JPanelImpl (java.awt.LayoutManager arg0, boolean arg1) { 31 super(arg0,arg1); 32 } 33 public JPanelImpl (java.awt.LayoutManager arg0) { 34 super(arg0); 35 } 36 public JPanelImpl (boolean arg0) { 37 super(arg0); 38 } 39 public JPanelImpl () { 40 super(); 41 } 42 43 public String [] listFc () { 44 int s = components.size(); 45 String [] result = (String [])components.keySet().toArray(new String [s + 6]); 46 result[s] = LEFT_COMPONENT_BINDING; 47 result[s+1] = TOP_COMPONENT_BINDING; 48 result[s+2] = RIGHT_COMPONENT_BINDING; 49 result[s+3] = BOTTOM_COMPONENT_BINDING; 50 result[s+4] = CENTER_COMPONENT_BINDING; 51 result[s+5] = LAYOUT_BINDING; 52 return result; 53 } 54 55 public Object lookupFc (String clientItfName) { 56 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 58 return left; 59 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 60 return top; 61 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 62 return right; 63 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 64 return bottom; 65 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 66 return center; 67 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 68 return components.get(clientItfName); 69 } else if (clientItfName.equals(LAYOUT_BINDING)) { 70 return layout; 71 } 72 return null; 73 } 74 75 public void bindFc (String clientItfName, Object serverItf) { 76 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 78 left = (JComponent )serverItf; 79 super.add(left, "West"); 80 validate(); 81 repaint(); 82 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 83 top = (JComponent )serverItf; 84 super.add(top, "North"); 85 validate(); 86 repaint(); 87 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 88 right = (JComponent )serverItf; 89 super.add(right, "East"); 90 validate(); 91 repaint(); 92 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 93 bottom = (JComponent )serverItf; 94 super.add(bottom, "South"); 95 validate(); 96 repaint(); 97 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 98 center = (JComponent )serverItf; 99 super.add(center, "Center"); 100 validate(); 101 repaint(); 102 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 103 components.put(clientItfName, serverItf); 104 super.add((java.awt.Component )serverItf); 105 validate(); 106 repaint(); 107 } else if (clientItfName.equals(LAYOUT_BINDING)) { 108 layout = (java.awt.LayoutManager )serverItf; 109 super.setLayout(layout); 110 validate(); 111 repaint(); 112 } 113 } 114 115 public void unbindFc (String clientItfName) { 116 if (clientItfName.equals(LEFT_COMPONENT_BINDING)) { 118 super.remove(left); 119 validate(); 120 repaint(); 121 left = null; 122 } if (clientItfName.equals(TOP_COMPONENT_BINDING)) { 123 super.remove(top); 124 validate(); 125 repaint(); 126 top = null; 127 } if (clientItfName.equals(RIGHT_COMPONENT_BINDING)) { 128 super.remove(right); 129 validate(); 130 repaint(); 131 right = null; 132 } if (clientItfName.equals(BOTTOM_COMPONENT_BINDING)) { 133 super.remove(bottom); 134 validate(); 135 repaint(); 136 bottom = null; 137 } if (clientItfName.equals(CENTER_COMPONENT_BINDING)) { 138 super.remove(center); 139 validate(); 140 repaint(); 141 center = null; 142 } else if (clientItfName.startsWith(COMPONENTS_BINDING)) { 143 Component c = (Component )components.get(clientItfName); 144 super.remove(c); 145 validate(); 146 repaint(); 147 } else if (clientItfName.equals(LAYOUT_BINDING)) { 148 layout = null; 149 } 150 } 151 152 } 153 | Popular Tags |