1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d.action;
21
22
23 import java.util.Vector;
24 import camera3d.GUIControl;
25 import camera3d.J3DBase;
26
27
28 /***
29 * @author Fábio Roberto de Miranda
30 * @version 1.0
31 */
32 public class ActionExecutor extends Thread {
33
34 private final ActionQueue queue;
35 private final ActionQueue outputQueue; // A queue to which already processed instructions are sent.
36 private final J3DBase base;
37 private GUIControl guiControl;
38 boolean keepRunning = true;
39
40 /*** Maximum number of actions which can be undone */
41 private int undoLimit = 10;
42
43 /***
44 * Creates ActionExecutor, given ActionQueues and J3DBase object to act upon.
45 * @param queue provides actions yet to be executed.
46 * @param outputQueue destination of already executed actions.
47 * @param base access point to Java 3D tree affected by actions.
48 * @throws IllegalArgumentException if any input parameter is null.
49 */
50 public ActionExecutor(ActionQueue queue, ActionQueue outputQueue, J3DBase base){
51 if(queue == null) throw new IllegalArgumentException("Input queue is null");
52 if(outputQueue == null) throw new IllegalArgumentException("Output queue is null");
53 if(base == null) throw new IllegalArgumentException("J3DBase object is null");
54 this.queue = queue;
55 this.outputQueue = outputQueue;
56 this.base = base;
57 }
58
59 /***
60 * Creates ActionExecutor, given ActionQueues, GUIControl and J3DBase objects to act upon.
61 * @param queue provides actions yet to be executed.
62 * @param outputQueue destination of already executed actions.
63 * @param base access point to Java 3D tree affected by actions.
64 * @param guiControl access point to some resources used by actions.
65 * @throws IllegalArgumentException if any input parameter is null.
66 */
67 public ActionExecutor(ActionQueue queue, ActionQueue outputQueue, J3DBase base, GUIControl guiControl){
68 this(queue, outputQueue, base);
69 if(guiControl == null) throw new IllegalArgumentException("GUIControl object is null");
70 this.guiControl = guiControl;
71 guiControl.setActionExecutor(this);
72 }
73
74
75 public void run(){
76 while(keepRunning){
77 debugln("Popping queue");
78 VcAction action = queue.pop();
79 debugln("Object:"+action);
80 interpretAction(action, outputQueue);
81 }
82 }
83
84 public void interpretAction(VcAction action, ActionQueue outputQueue){
85 if (action!=null){
86 action.doAction(this);
87 } else {
88 debugln("ActionExecutor:A null action was found in the queue");
89 }
90 if(action.isUndoable()){
91 while(outputQueue.size()>=undoLimit) outputQueue.pop();
92 outputQueue.push(action);
93 }
94 }
95
96 public J3DBase getJ3DBase(){
97 return this.base;
98 }
99
100 public GUIControl getGUIControl(){
101 return this.guiControl;
102 }
103
104 public void stopRun(){
105 this.keepRunning = false;
106 }
107
108 public void debugln(String s){
109 if (GUIControl.debugflag){
110 System.out.println(s);
111 }
112 }
113
114 public void setUndoLimit(int limit){
115 this.undoLimit = limit;
116 }
117
118 public int getUndoLimit(){
119 return this.undoLimit;
120 }
121
122
123 }
This page was automatically generated by Maven