home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.InconsistencyException;
- import netscape.util.Vector;
-
- public class Timer implements EventProcessor, EventFilter {
- EventLoop eventLoop;
- Target target;
- String command;
- Object data;
- long timeStamp;
- int initialDelay;
- int delay;
- boolean repeats;
- boolean coalesce;
- boolean removeEvents;
- long expirationTime;
- Timer nextTimer;
- boolean running;
-
- public Timer(EventLoop var1, Target var2, String var3, int var4) {
- this.repeats = true;
- this.coalesce = true;
- if (var1 == null) {
- throw new InconsistencyException("eventLoop parameter is null");
- } else {
- this.eventLoop = var1;
- this.target = var2;
- this.command = var3;
- this.setDelay(var4);
- this.setInitialDelay(var4);
- }
- }
-
- public Timer(Target var1, String var2, int var3) {
- this(Application.application().eventLoop(), var1, var2, var3);
- }
-
- TimerQueue timerQueue() {
- return Application.application().timerQueue();
- }
-
- public EventLoop eventLoop() {
- return this.eventLoop;
- }
-
- public void setTarget(Target var1) {
- this.target = var1;
- }
-
- public Target target() {
- return this.target;
- }
-
- public void setCommand(String var1) {
- this.command = var1;
- }
-
- public String command() {
- return this.command;
- }
-
- public void setData(Object var1) {
- this.data = var1;
- }
-
- public Object data() {
- return this.data;
- }
-
- public void setDelay(int var1) {
- if (var1 < 0) {
- throw new InconsistencyException("Invalid initial delay: " + var1);
- } else {
- this.delay = var1;
- if (this.isRunning()) {
- TimerQueue var2 = this.timerQueue();
- var2.removeTimer(this);
- this.removeEvents();
- var2.addTimer(this, System.currentTimeMillis() + (long)var1);
- }
-
- }
- }
-
- public int delay() {
- return this.delay;
- }
-
- public void setInitialDelay(int var1) {
- if (var1 < 0) {
- throw new InconsistencyException("Invalid initial delay: " + var1);
- } else {
- this.initialDelay = var1;
- }
- }
-
- public int initialDelay() {
- return this.initialDelay;
- }
-
- public void setRepeats(boolean var1) {
- this.repeats = var1;
- }
-
- public boolean repeats() {
- return this.repeats;
- }
-
- public long timeStamp() {
- return this.timeStamp;
- }
-
- public void setCoalesce(boolean var1) {
- this.coalesce = var1;
- }
-
- public boolean doesCoalesce() {
- return this.coalesce;
- }
-
- public void start() {
- this.timerQueue().addTimer(this, System.currentTimeMillis() + (long)this.initialDelay());
- }
-
- public boolean isRunning() {
- return this.timerQueue().containsTimer(this);
- }
-
- public void stop() {
- this.timerQueue().removeTimer(this);
- this.removeEvents();
- }
-
- synchronized void removeEvents() {
- this.removeEvents = true;
- this.eventLoop.filterEvents(this);
- }
-
- synchronized boolean peekEvent() {
- this.removeEvents = false;
- return this.eventLoop.filterEvents(this) != null;
- }
-
- public Object filterEvents(Vector var1) {
- int var2 = var1.count();
-
- while(var2-- > 0) {
- Event var3 = (Event)var1.elementAt(var2);
- if (var3.processor() == this) {
- if (!this.removeEvents) {
- return var3;
- }
-
- var1.removeElementAt(var2);
- }
- }
-
- return null;
- }
-
- public void processEvent(Event var1) {
- this.timeStamp = var1.timeStamp;
- if (this.target != null) {
- this.target.performCommand(this.command, this.data);
- }
-
- }
-
- public String toString() {
- return "Timer {target = " + this.target + "; command = " + this.command + "; delay = " + this.delay + "; initialDelay = " + this.initialDelay + "; repeats = " + this.repeats + "}";
- }
-
- void post(long var1) {
- if (!this.coalesce || !this.peekEvent()) {
- Event var3 = new Event(var1);
- var3.setProcessor(this);
- this.eventLoop.addEvent(var3);
- }
-
- }
- }
-