1 23 24 package org.objectweb.fractal.gui.graph.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.Component; 29 import org.objectweb.fractal.gui.Constants; 30 31 import java.util.Map ; 32 import java.util.WeakHashMap ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.awt.Color ; 36 37 40 41 public class BasicGraphModel implements GraphModel, BindingController { 42 43 47 48 public final static String GRAPH_MODEL_LISTENERS_BINDING = 49 "graph-model-listeners"; 50 51 54 55 private Map listeners; 56 57 60 61 private Map colors; 62 63 66 67 private Map positions; 68 69 72 73 public BasicGraphModel () { 74 colors = new WeakHashMap (); 75 positions = new WeakHashMap (); 76 listeners = new HashMap (); 77 } 78 79 83 public String [] listFc () { 84 return (String [])listeners.keySet().toArray(new String [listeners.size()]); 85 } 86 87 public Object lookupFc (final String clientItfName) { 88 if (clientItfName.startsWith(GRAPH_MODEL_LISTENERS_BINDING)) { 89 return listeners.get(clientItfName); 90 } 91 return null; 92 } 93 94 public void bindFc ( 95 final String clientItfName, 96 final Object serverItf) 97 { 98 if (clientItfName.startsWith(GRAPH_MODEL_LISTENERS_BINDING)) { 99 listeners.put(clientItfName, serverItf); 100 } 101 } 102 103 public void unbindFc (final String clientItfName) { 104 if (clientItfName.startsWith(GRAPH_MODEL_LISTENERS_BINDING)) { 105 listeners.remove(clientItfName); 106 } 107 } 108 109 113 public Color getComponentColor (Component component) { 114 Color c = (Color )colors.get(component); 115 if (c == null) { 116 c = Constants.COMPONENT_COLOR; 117 colors.put(component, c); 118 } 119 return c; 120 } 121 122 public void setComponentColor (Component component, Color color) { 123 Color oldColor = getComponentColor(component); 124 if (!color.equals(oldColor)) { 125 colors.put(component, color); 126 Iterator i = listeners.values().iterator(); 127 while (i.hasNext()) { 128 GraphModelListener l = (GraphModelListener)i.next(); 129 l.componentColorChanged(component, oldColor); 130 } 131 } 132 } 133 134 public Rect getComponentPosition (final Component component) { 135 Rect result = (Rect)positions.get(component); 136 if (result == null) { 137 result = new Rect(0.1, 0.1, 0.9, 0.9); 138 positions.put(component, result); 139 } 140 return result; 141 } 142 143 public void setComponentPosition ( 144 final Component component, 145 final Rect position) 146 { 147 Rect oldPosition = getComponentPosition(component); 148 if (!position.equals(oldPosition)) { 149 positions.put(component, position); 150 Iterator i = listeners.values().iterator(); 151 while (i.hasNext()) { 152 GraphModelListener l = (GraphModelListener)i.next(); 153 l.componentPositionChanged(component, oldPosition); 154 } 155 } 156 } 157 } 158 | Popular Tags |