1 23 package org.objectweb.clif.scenario.util.isac.loadprofile; 24 25 import java.util.Enumeration ; 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 29 import org.apache.log4j.Category; 30 import org.eclipse.jface.wizard.WizardDialog; 31 import org.eclipse.swt.graphics.Color; 32 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 33 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.GroupDescriptionWizard; 34 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.LoadDrawingEditor; 35 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.Size; 36 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 37 38 44 public class LoadProfileManager { 45 static Category cat = Category.getInstance(LoadProfileManager.class 47 .getName()); 48 private static LoadProfileManager instance = null; 50 private Hashtable groups; 52 private LoadDrawingEditor loadDrawingEditor; 54 private ScenarioGUIEditor window; 56 57 60 private LoadProfileManager() { 61 this.groups = new Hashtable (); 62 } 63 64 69 public static LoadProfileManager getInstance() { 70 if (instance == null) 71 instance = new LoadProfileManager(); 72 return instance; 73 } 74 75 78 public void createNewLoadProfile() { 79 this.groups.clear(); 81 this.loadDrawingEditor.setSelectedGroup(null) ; 83 } 84 85 89 95 public void changeBehaviorId(String oldId, String newId) { 96 boolean flag = false ; 98 Enumeration e = this.getElements() ; 99 while (e.hasMoreElements()) { 101 GroupDescription gd = (GroupDescription)e.nextElement() ; 103 if (gd.getBehaviorId().equals(oldId)) { 104 gd.setBehaviorId(newId) ; 105 flag = true ; 106 } 107 } 108 if (flag) { 110 if (loadDrawingEditor != null) { 111 this.loadDrawingEditor.setSelectedGroup(this.loadDrawingEditor.getGroupDescriptionSelected()) ; 113 } 114 } 115 } 116 117 121 public Enumeration getElements() { 122 return this.groups.elements() ; 123 } 124 125 131 public void addGroupDescription(GroupDescription gd) { 132 if (this.groups.containsKey(gd.getGroupId())) 134 return; 135 this.groups.put(gd.getGroupId(), gd); 137 } 138 139 144 public void addRampDescriptionToGroup(RampDescription rd, String groupId) { 145 if (!this.groups.containsKey(groupId)) { 147 return ; 149 } 150 ((GroupDescription)this.groups.get(groupId)).addRamp(rd) ; 152 } 153 154 160 public void removeGroupDescription(GroupDescription gd) { 161 if (this.groups.containsKey(gd.getGroupId())) { 163 this.groups.remove(gd.getGroupId()); 164 } 165 } 166 167 176 public RampDescription getRampDescriptionOfGroup(String rampId, 177 String groupId) { 178 if (this.groups.containsKey(groupId)) 180 return ((GroupDescription) this.groups.get(groupId)).getRampDescription(rampId); 181 return null; 182 } 183 184 190 public Enumeration getElementsOfGroup(String groupId) { 191 if (this.groups.containsKey(groupId)) 193 return ((GroupDescription) this.groups.get(groupId)).getElements(); 194 return null; 195 } 196 197 203 public void removeRampDescription(String rampId) { 204 if (rampId == null) 205 return; 206 Enumeration e = this.groups.elements(); 208 while (e.hasMoreElements()) { 209 ((GroupDescription) e.nextElement()).removeRampDescription(rampId); 210 } 211 } 212 213 221 public void removeRampDescriptionOfGroup(RampDescription rd, String groupId) { 222 cat.warn("REMOVE RAMP DESCRIPTION"); 223 if (this.groups.containsKey(groupId)) { 225 ((GroupDescription) this.groups.get(groupId)) 226 .removeRampDescription(rd); 227 } 228 } 229 230 236 public void removeRampDescriptionOfGroup(String rampId, String groupId) { 237 if (this.groups.containsKey(groupId)) { 239 ((GroupDescription) this.groups.get(groupId)) 240 .removeRampDescription(rampId); 241 } 242 } 243 244 249 public String rampIdGenerator() { 250 Vector ids = new Vector (); 252 Enumeration e = this.groups.elements(); 253 while (e.hasMoreElements()) 254 ids.addAll(((GroupDescription) e.nextElement()) 255 .getRampDescriptionIds()); 256 int intId = ids.size(); 258 while (ids.contains("r" + Integer.toString(intId))) 259 intId++; 260 return "r" + Integer.toString(intId); 261 } 262 263 268 public String groupIdGenerator() { 269 int intId = this.groups.size(); 270 while (this.groups.containsKey("g" + Integer.toString(intId))) 271 intId++; 272 return "g" + Integer.toString(intId); 273 } 274 275 279 283 public Color getDefaultColor() { 284 return LoadDrawingEditor.defaultColor ; 285 } 286 287 290 public void editGroupSelectedDescription() { 291 Vector ids = TreeManager.getTreeManager(null).getBehaviorsIds(); 293 GroupDescriptionWizard wizard = new GroupDescriptionWizard( 295 this.loadDrawingEditor.getGroupDescriptionSelected(), ids); 296 WizardDialog dialog = new WizardDialog(this.loadDrawingEditor 297 .getParent().getShell(), wizard); 298 int erno = dialog.open(); 299 this.loadDrawingEditor.setSelectedGroup(this.loadDrawingEditor 301 .getGroupDescriptionSelected()); 302 } 303 304 public void setScale(Size scaleSize) { 305 this.loadDrawingEditor.setScale(scaleSize) ; 306 } 307 308 312 public void notifySelectionChangedInDrawable(GroupDescription gd) { 313 } 315 316 322 public void setDrawablePart(LoadDrawingEditor lde) { 323 this.loadDrawingEditor = lde; 324 } 325 } | Popular Tags |