1
2 package hep.wired.edit;
3
4 import java.awt.Shape;
5
6 /***
7 * Base class for an animated single edit. This class contains a shape to be animated in a
8 * certain number of frames, and handles the animation.
9 *
10 * @author Mark Donszelmann
11 * @version $Id: AnimatedWiredEdit.java 256 2004-06-07 23:31:10Z duns $
12 */
13 public abstract class AnimatedWiredEdit extends WiredEdit {
14
15 private Shape initialShape;
16 private Shape[] shapes;
17
18 /***
19 * Creates an animated edit with zero frames and no shape.
20 */
21 public AnimatedWiredEdit() {
22 this(null, 0);
23 }
24
25 /***
26 * Creates an animated edit with given initial shape and number of frames.
27 */
28 public AnimatedWiredEdit(Shape initialShape, int frames) {
29 super(frames);
30 this.initialShape = initialShape;
31 shapes = null;
32 }
33
34 /***
35 * Returns the initial shape.
36 */
37 protected Shape getShape() {
38 return initialShape;
39 }
40
41 /***
42 * Returns an array of 'frames' shapes deformed from the given initial shape.
43 */
44 protected Shape[] getShapes(Shape initialShape, int frames) {
45 return null;
46 }
47
48 /***
49 * Starts the animation by calling getShapes() to get the set of 'framed' shapes.
50 * The plot is set into fast mode.
51 */
52 protected void startAnimation(boolean redo) {
53 if (shapes == null) shapes = getShapes(initialShape, getFrames());
54 getRecordPlot().getGraphicsPanel().setFastMode(true);
55 }
56
57 /***
58 * Shows frameNo in the plot by drawing its shape.
59 */
60 protected void showAnimation(int frameNo) {
61 getRecordPlot().drawShape(shapes[frameNo]);
62 }
63
64 /***
65 * Ends the animation by removing the last drawn shape from the plot and
66 * changing the plot to normal mode again.
67 */
68 protected void endAnimation() {
69 getRecordPlot().getGraphicsPanel().setFastMode(false);
70 getRecordPlot().drawShape(null);
71 }
72
73 /***
74 * Returns a string representation of the edit.
75 */
76 public String toString() {
77 return super.toString()+"; "+getPresentationName();
78 }
79 }