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 net.refractions.udig.core.IProvider;
18: import net.refractions.udig.project.ui.IAnimation;
19: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
20:
21: /**
22: * Provides framework for commands that run an unknown length of
23: * time.
24: *
25: * @author jones
26: * @since 1.1.0
27: */
28: public abstract class AbstractLongRunningAnimation extends
29: AbstractDrawCommand implements IAnimation {
30: protected int maxSize;
31: protected int frame;
32: boolean smaller = true;
33: private IProvider<Boolean> isValidProvider;
34:
35: AbstractLongRunningAnimation(int maxSize,
36: IProvider<Boolean> isValidProvider) {
37: frame = maxSize;
38:
39: this .maxSize = maxSize == 0 ? 1 : maxSize;
40: this .isValidProvider = isValidProvider;
41: }
42:
43: public void nextFrame() {
44: if (frame == 1)
45: smaller = false;
46: else if (frame == maxSize - 1)
47: smaller = true;
48:
49: if (smaller)
50: frame--;
51: else
52: frame++;
53:
54: frame = frame % maxSize;
55: }
56:
57: public boolean hasNext() {
58: return isValid();
59: }
60:
61: @Override
62: public boolean isValid() {
63: return super.isValid() && isValidProvider.get();
64: }
65:
66: }
|