1 7 8 package java.awt.image.renderable; 9 import java.awt.image.RenderedImage ; 10 import java.io.Serializable ; 11 import java.util.Vector ; 12 13 77 public class ParameterBlock implements Cloneable , Serializable { 78 79 protected Vector <Object > sources = new Vector <Object >(); 80 81 82 protected Vector <Object > parameters = new Vector <Object >(); 83 84 85 public ParameterBlock() {} 86 87 92 public ParameterBlock(Vector <Object > sources) { 93 setSources(sources); 94 } 95 96 103 public ParameterBlock(Vector <Object > sources, 104 Vector <Object > parameters) 105 { 106 setSources(sources); 107 setParameters(parameters); 108 } 109 110 117 public Object shallowClone() { 118 try { 119 return super.clone(); 120 } catch (Exception e) { 121 return null; 123 } 124 } 125 126 136 public Object clone() { 137 ParameterBlock theClone; 138 139 try { 140 theClone = (ParameterBlock ) super.clone(); 141 } catch (Exception e) { 142 return null; 144 } 145 146 if (sources != null) { 147 theClone.setSources((Vector )sources.clone()); 148 } 149 if (parameters != null) { 150 theClone.setParameters((Vector )parameters.clone()); 151 } 152 return (Object ) theClone; 153 } 154 155 164 public ParameterBlock addSource(Object source) { 165 sources.addElement(source); 166 return this; 167 } 168 169 179 public Object getSource(int index) { 180 return sources.elementAt(index); 181 } 182 183 196 public ParameterBlock setSource(Object source, int index) { 197 int oldSize = sources.size(); 198 int newSize = index + 1; 199 if (oldSize < newSize) { 200 sources.setSize(newSize); 201 } 202 sources.setElementAt(source, index); 203 return this; 204 } 205 206 216 public RenderedImage getRenderedSource(int index) { 217 return (RenderedImage ) sources.elementAt(index); 218 } 219 220 230 public RenderableImage getRenderableSource(int index) { 231 return (RenderableImage ) sources.elementAt(index); 232 } 233 234 239 public int getNumSources() { 240 return sources.size(); 241 } 242 243 248 public Vector <Object > getSources() { 249 return sources; 250 } 251 252 257 public void setSources(Vector <Object > sources) { 258 this.sources = sources; 259 } 260 261 262 public void removeSources() { 263 sources = new Vector (); 264 } 265 266 271 public int getNumParameters() { 272 return parameters.size(); 273 } 274 275 280 public Vector <Object > getParameters() { 281 return parameters; 282 } 283 284 290 public void setParameters(Vector <Object > parameters) { 291 this.parameters = parameters; 292 } 293 294 295 public void removeParameters() { 296 parameters = new Vector (); 297 } 298 299 306 public ParameterBlock add(Object obj) { 307 parameters.addElement(obj); 308 return this; 309 } 310 311 318 public ParameterBlock add(byte b) { 319 return add(new Byte (b)); 320 } 321 322 329 public ParameterBlock add(char c) { 330 return add(new Character (c)); 331 } 332 333 340 public ParameterBlock add(short s) { 341 return add(new Short (s)); 342 } 343 344 351 public ParameterBlock add(int i) { 352 return add(new Integer (i)); 353 } 354 355 362 public ParameterBlock add(long l) { 363 return add(new Long (l)); 364 } 365 366 373 public ParameterBlock add(float f) { 374 return add(new Float (f)); 375 } 376 377 384 public ParameterBlock add(double d) { 385 return add(new Double (d)); 386 } 387 388 400 public ParameterBlock set(Object obj, int index) { 401 int oldSize = parameters.size(); 402 int newSize = index + 1; 403 if (oldSize < newSize) { 404 parameters.setSize(newSize); 405 } 406 parameters.setElementAt(obj, index); 407 return this; 408 } 409 410 422 public ParameterBlock set(byte b, int index) { 423 return set(new Byte (b), index); 424 } 425 426 438 public ParameterBlock set(char c, int index) { 439 return set(new Character (c), index); 440 } 441 442 454 public ParameterBlock set(short s, int index) { 455 return set(new Short (s), index); 456 } 457 458 470 public ParameterBlock set(int i, int index) { 471 return set(new Integer (i), index); 472 } 473 474 486 public ParameterBlock set(long l, int index) { 487 return set(new Long (l), index); 488 } 489 490 502 public ParameterBlock set(float f, int index) { 503 return set(new Float (f), index); 504 } 505 506 518 public ParameterBlock set(double d, int index) { 519 return set(new Double (d), index); 520 } 521 522 530 public Object getObjectParameter(int index) { 531 return parameters.elementAt(index); 532 } 533 534 550 public byte getByteParameter(int index) { 551 return ((Byte )parameters.elementAt(index)).byteValue(); 552 } 553 554 570 public char getCharParameter(int index) { 571 return ((Character )parameters.elementAt(index)).charValue(); 572 } 573 574 590 public short getShortParameter(int index) { 591 return ((Short )parameters.elementAt(index)).shortValue(); 592 } 593 594 610 public int getIntParameter(int index) { 611 return ((Integer )parameters.elementAt(index)).intValue(); 612 } 613 614 630 public long getLongParameter(int index) { 631 return ((Long )parameters.elementAt(index)).longValue(); 632 } 633 634 650 public float getFloatParameter(int index) { 651 return ((Float )parameters.elementAt(index)).floatValue(); 652 } 653 654 670 public double getDoubleParameter(int index) { 671 return ((Double )parameters.elementAt(index)).doubleValue(); 672 } 673 674 679 public Class [] getParamClasses() { 680 int numParams = getNumParameters(); 681 Class [] classes = new Class [numParams]; 682 int i; 683 684 for (i = 0; i < numParams; i++) { 685 Object obj = getObjectParameter(i); 686 if (obj instanceof Byte ) { 687 classes[i] = byte.class; 688 } else if (obj instanceof Character ) { 689 classes[i] = char.class; 690 } else if (obj instanceof Short ) { 691 classes[i] = short.class; 692 } else if (obj instanceof Integer ) { 693 classes[i] = int.class; 694 } else if (obj instanceof Long ) { 695 classes[i] = long.class; 696 } else if (obj instanceof Float ) { 697 classes[i] = float.class; 698 } else if (obj instanceof Double ) { 699 classes[i] = double.class; 700 } else { 701 classes[i] = obj.getClass(); 702 } 703 } 704 705 return classes; 706 } 707 } 708 | Popular Tags |