1 23 24 package org.objectweb.fractal.gui.graph.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 import org.objectweb.fractal.gui.UserData; 28 29 import java.awt.Rectangle ; 30 import java.util.Map ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 37 38 public class BasicDisplay implements Display, BindingController { 39 40 44 45 public final static String DISPLAY_LISTENERS_BINDING = "display-listeners"; 46 47 50 51 public final static String USER_DATA_BINDING = "user-data"; 52 53 56 57 private Map displayListeners; 58 59 62 63 private UserData userData; 64 65 68 69 private Rectangle screenSize; 70 71 74 75 private Rect displayedArea; 76 77 80 81 private boolean isAntialiasing; 82 83 86 87 private int maxDepth; 88 89 92 93 private int displayModeForInterface; 94 95 98 99 public BasicDisplay () { 100 displayedArea = new Rect(0.01, 0.01, 0.99, 0.99); 101 displayListeners = new HashMap (); 102 maxDepth = 2; 103 displayModeForInterface = 0; 104 } 105 106 110 public String [] listFc () { 111 int size = displayListeners.size(); 112 String [] names = new String [size + 1]; 113 displayListeners.keySet().toArray(names); 114 names[size] = USER_DATA_BINDING; 115 return names; 116 } 117 118 public Object lookupFc (final String clientItfName) { 119 if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) { 120 return displayListeners.get(clientItfName); 121 } else if (USER_DATA_BINDING.equals(clientItfName)) { 122 return userData; 123 } 124 return null; 125 } 126 127 public void bindFc ( 128 final String clientItfName, 129 final Object serverItf) 130 { 131 if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) { 132 displayListeners.put(clientItfName, serverItf); 133 } else if (USER_DATA_BINDING.equals(clientItfName)) { 134 userData = (UserData)serverItf; 135 } 136 } 137 138 public void unbindFc (final String clientItfName) { 139 if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) { 140 displayListeners.remove(clientItfName); 141 } else if (USER_DATA_BINDING.equals(clientItfName)) { 142 userData = null; 143 } 144 } 145 146 150 public Rectangle getScreenSize () { 151 return new Rectangle (screenSize); 152 } 153 154 public void setScreenSize (final Rectangle screenSize) { 155 try { 156 userData.setIntData(UserData.CURRENT_WIDTH, screenSize.width); 157 userData.setIntData(UserData.CURRENT_HEIGHT, screenSize.height); 158 } catch (Exception ex) { } 159 this.screenSize = new Rectangle (screenSize); 160 } 161 162 public Rect getDisplayedArea () { 163 return displayedArea; 164 } 165 166 public void setDisplayedArea (final Rect displayedArea) { 167 Rect oldDisplayedArea = this.displayedArea; 168 if (!displayedArea.equals(oldDisplayedArea)) { 169 this.displayedArea = displayedArea; 170 Iterator i = displayListeners.values().iterator(); 171 while (i.hasNext()) { 172 DisplayListener l = (DisplayListener)i.next(); 173 l.displayedAreaChanged(oldDisplayedArea); 174 } 175 } 176 } 177 178 public boolean isAntialiasing () { 179 return isAntialiasing; 180 } 181 182 public void setIsAntialiasing (final boolean isAntialiasing) { 183 if (isAntialiasing != this.isAntialiasing) { 184 this.isAntialiasing = isAntialiasing; 185 Iterator i = displayListeners.values().iterator(); 186 while (i.hasNext()) { 187 DisplayListener l = (DisplayListener)i.next(); 188 l.antialiasingChanged(); 189 } 190 } 191 } 192 193 public int getMaxDepth () { 194 return maxDepth; 195 } 196 197 public void setMaxDepth (final int maxDepth) { 198 if (maxDepth != this.maxDepth) { 199 this.maxDepth = maxDepth; 200 Iterator i = displayListeners.values().iterator(); 201 while (i.hasNext()) { 202 DisplayListener l = (DisplayListener)i.next(); 203 l.maxDepthChanged(); 204 try { 205 userData.setIntData(UserData.CURRENT_DEPTH, maxDepth); 206 } catch (Exception ex) { } 207 } 208 } 209 } 210 211 public int getItfNameDisplayMode () { 212 return displayModeForInterface; 213 } 214 215 public void setItfNameDisplayMode () { 216 displayModeForInterface++; 217 if (displayModeForInterface > 2) displayModeForInterface = 0; 218 Iterator i = displayListeners.values().iterator(); 219 while (i.hasNext()) { 220 DisplayListener l = (DisplayListener)i.next(); 221 l.itfNameDisplayModeChanged(); 222 } 223 } 224 } 225 | Popular Tags |