01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.animation;
16:
17: import java.awt.Color;
18: import java.awt.Rectangle;
19: import java.awt.Shape;
20:
21: import net.refractions.udig.core.IProvider;
22: import net.refractions.udig.project.ui.IAnimation;
23: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
24:
25: import org.eclipse.core.runtime.IProgressMonitor;
26:
27: public class GeometryOperationAnimation extends AbstractDrawCommand
28: implements IAnimation {
29:
30: private int frame;
31: private Shape shape;
32: private IProvider<Boolean> stopAnimationProvider;
33:
34: /**
35: * @param currentJavaShape
36: */
37: public GeometryOperationAnimation(Shape currentJavaShape,
38: IProvider<Boolean> stopAnimationProvider) {
39: this .shape = currentJavaShape;
40: this .stopAnimationProvider = stopAnimationProvider;
41: }
42:
43: public short getFrameInterval() {
44: return 100;
45: }
46:
47: public void nextFrame() {
48: frame++;
49: frame = frame % 2;
50: }
51:
52: public boolean hasNext() {
53: return isValid() && stopAnimationProvider.get();
54: }
55:
56: public void run(IProgressMonitor monitor) throws Exception {
57: if (frame == 0) {
58: graphics.setColor(Color.RED);
59: } else {
60: graphics.setColor(Color.BLACK);
61: }
62: graphics.draw(shape);
63: }
64:
65: public Rectangle getValidArea() {
66: return shape.getBounds();
67: }
68: }
|