1 23 package org.objectweb.clif.scenario.util.isac.loadprofile; 24 25 import java.util.Enumeration ; 26 import java.util.Vector ; 27 28 import org.apache.log4j.Category; 29 import org.eclipse.swt.graphics.Color; 30 31 38 public class GroupDescription { 39 static Category cat = Category 41 .getInstance(GroupDescription.class.getName()); 42 43 private String behaviorId; 45 46 private Color curveColor; 47 48 private String groupId; 49 50 private Vector ramps; 51 52 private boolean updated; 53 54 private boolean forceStop ; 55 56 public static final int END = -1; 57 58 62 68 public GroupDescription(String id) { 69 this.groupId = id; 70 this.behaviorId = null; 71 this.curveColor = null; 72 this.ramps = new Vector (); 73 this.forceStop = true ; 74 } 75 76 86 public GroupDescription(String id, String behaviorId, Color c, 87 Vector subCurves, boolean forceStop) { 88 this.groupId = id; 89 this.behaviorId = behaviorId; 90 this.curveColor = c; 91 this.ramps = subCurves; 92 this.forceStop = forceStop ; 93 } 94 95 99 105 public void addPoint(Point p) { 106 if (this.ramps.size() == 0) 108 return; 109 int number = -1; 111 for (int i = 0; i < this.ramps.size(); i++) { 113 RampDescription temp = (RampDescription) this.ramps.elementAt(i); 114 if (p.x > temp.getStart().x && p.x < temp.getEnd().x) { 115 number = i; 116 break; 117 } 118 } 119 if (number != -1) { 121 RampDescription rampContaining = (RampDescription) this.ramps 123 .elementAt(number); 124 String rampId = LoadProfileManager.getInstance().rampIdGenerator(); 126 RampDescription rd = new RampDescription(rampId, rampContaining 127 .getType(), rampContaining.getStart(), p, new Point(-1, -1)); 128 rampContaining.setStart(p); 130 this.ramps.add(number, rd); 132 } 133 else { 135 RampDescription first = (RampDescription) this.ramps.elementAt(0); 137 if (p.x < first.getStart().x) { 138 String rampId = LoadProfileManager.getInstance() 140 .rampIdGenerator(); 141 RampDescription newOne = new RampDescription(rampId, first 142 .getType(), p, (Point) first.getStart().clone(), 143 new Point(-1, -1)); 144 this.ramps.add(0, newOne); 146 return; 147 } 148 RampDescription last = (RampDescription) this.ramps 150 .elementAt(this.ramps.size() - 1); 151 if (p.x > last.getEnd().x) { 152 String rampId = LoadProfileManager.getInstance() 154 .rampIdGenerator(); 155 RampDescription newOne = new RampDescription(rampId, last 156 .getType(), (Point) last.getEnd().clone(), p, 157 new Point(-1, -1)); 158 this.ramps.add(newOne); 160 return; 161 } 162 } 163 } 164 165 173 public void deletePoint(Point p) { 174 if (this.ramps.size() == 0) 176 return; 177 int number = -1; 179 if (this.ramps.size() == 1) { 181 this.ramps.clear(); 182 return; 183 } 184 if (((RampDescription) this.ramps.elementAt(0)).getStart().equals(p)) { 186 this.ramps.remove(0); 187 return; 188 } 189 if (((RampDescription) this.ramps.elementAt(this.ramps.size() - 1)) 191 .getEnd().equals(p)) { 192 this.ramps.remove(this.ramps.size() - 1); 193 return; 194 } 195 for (int i = 1; i < this.ramps.size(); i++) { 197 RampDescription temp = (RampDescription) this.ramps.elementAt(i); 198 if (p.x == temp.getStart().x && p.y == temp.getStart().y) { 199 number = i; 200 break; 201 } 202 } 203 RampDescription rdNumber = (RampDescription) this.ramps 206 .elementAt(number); 207 RampDescription rdNumberMinusOne = (RampDescription) this.ramps 208 .elementAt(number - 1); 209 rdNumberMinusOne.setEnd((Point) rdNumber.getEnd().clone()); 210 this.ramps.remove(number); 212 } 213 214 221 public boolean addRamp(RampDescription rd) { 222 this.ramps.add(rd); 225 return false; 226 } 227 228 236 public GroupDescription clone(String id) { 237 GroupDescription clone = null; 238 if (id == null) 239 clone = new GroupDescription(this.groupId); 240 else 241 clone = new GroupDescription(id); 242 clone.setBehaviorId(this.behaviorId); 244 clone.setCurveColor(this.curveColor); 245 clone.setRamps((Vector ) this.ramps.clone()); 246 return clone; 247 } 248 249 258 public Point rampsWhichContains(Point p) { 259 if (this.ramps.size() == 0) 261 return null; 262 RampDescription curve = (RampDescription) this.ramps.elementAt(0); 264 if (curve.getStart().equals(p)) 265 return new Point(-1, 0); 266 for (int i = 0; i < this.ramps.size(); i++) { 269 RampDescription tempDesc = (RampDescription) this.ramps 270 .elementAt(i); 271 if (tempDesc.getEnd().equals(p)) { 272 if (this.ramps.size() - 1 == i) 275 return new Point(i, -1); 276 else 277 return new Point(i, i + 1); 278 } 279 } 280 return null; 283 } 284 285 293 public RampDescription getRampDescription(String rampId) { 294 for (int i = 0; i < this.ramps.size(); i++) { 296 if (((RampDescription) this.ramps.elementAt(i)).getRampId().equals( 297 rampId)) 298 return (RampDescription) this.ramps.elementAt(i); 299 } 300 return null; 302 } 303 304 309 public Enumeration getElements() { 310 return this.ramps.elements(); 311 } 312 313 319 public void removeRampDescription(String rampId) { 320 int number = -1; 321 for (int i = 0; i < this.ramps.size(); i++) { 323 if (((RampDescription) this.ramps.elementAt(i)).getRampId().equals( 324 rampId)) 325 number = i; 326 } 327 if (number != -1) { 329 this.ramps.remove(number); 330 } 331 } 332 333 339 public void removeRampDescription(RampDescription rd) { 340 if (this.ramps.contains(rd)) 342 this.ramps.remove(rd); 343 } 344 345 350 public Vector getRampDescriptionIds() { 351 Vector result = new Vector (); 352 for (int i = 0; i < this.ramps.size(); i++) 354 result.add(((RampDescription) this.ramps.elementAt(i)).getRampId()); 355 return result; 356 } 357 358 363 public void updateRampDescription() { 364 for (int i = 0; i < this.ramps.size(); i++) 365 ((RampDescription) this.ramps.elementAt(i)).updateRampData(); 366 } 367 368 377 public long getVirtualUserNumber(int x) { 378 int result = END; 379 int number = -1; 381 for (int i = 0; i < this.ramps.size(); i++) { 382 RampDescription temp = (RampDescription) this.ramps.elementAt(i); 383 if (x <= temp.getEnd().x) { 384 result = 0; 385 if (x >= temp.getStart().x) { 386 number = i; 387 break; 388 } 389 } 390 } 391 if (number != -1) { 392 RampDescription rampContaining = (RampDescription) this.ramps 393 .elementAt(number); 394 if (x == rampContaining.getStart().x) { 395 result = rampContaining.getStart().y; 396 } else if (x == rampContaining.getEnd().x) { 397 result = rampContaining.getEnd().y; 398 } else { 399 result = rampContaining.getCorrespondingY(x); 400 } 401 402 } 403 return result; 404 } 405 406 410 413 public String getBehaviorId() { 414 return behaviorId; 415 } 416 417 420 public Color getCurveColor() { 421 return curveColor; 422 } 423 424 428 public void setBehaviorId(String behaviorId) { 429 this.behaviorId = behaviorId; 430 } 431 432 436 public void setCurveColor(Color curveColor) { 437 this.curveColor = curveColor; 438 } 439 440 443 public String getGroupId() { 444 return groupId; 445 } 446 447 450 public Vector getRamps() { 451 return ramps; 452 } 453 454 458 public void setRamps(Vector ramps) { 459 this.ramps = ramps; 460 } 461 462 465 public boolean isForceStop() { 466 return forceStop; 467 } 468 471 public void setForceStop(boolean forceStop) { 472 this.forceStop = forceStop; 473 } 474 475 479 public String toString() { 480 String result = ""; 481 for (int i = 0; i < ramps.size(); i++) { 482 result = result.concat(((RampDescription) ramps.elementAt(i)) 483 .toString()); 484 } 485 return result; 486 } 487 } | Popular Tags |