Source code: com/globalretailtech/pos/events/PosDialogEvent.java
1 /*
2 * Copyright (C) 2001 Global Retail Technology, LLC
3 * <http://www.globalretailtech.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package com.globalretailtech.pos.events;
21
22 import com.globalretailtech.util.Log;
23 import com.globalretailtech.pos.context.*;
24
25 /**
26 * POS dialog event super class. This class is extended
27 * by any POS event or EJ line that wishes to move the user
28 * through a series of prompts. Has it's own stack of
29 * states to manage this.
30 *
31 * @author Quentin Olson
32 */
33
34 public abstract class PosDialogEvent extends PosEvent
35 {
36
37 private PosStateStack statestack;
38
39 /** Current state on top of stack (peek) */
40 public int state ()
41 {
42 return statestack.state ();
43 }
44 /** Pop the top and return it. */
45 public int popState ()
46 {
47 return statestack.popState ();
48 }
49 /** Push a state on the stack */
50 public void pushState (int value)
51 {
52 statestack.pushState (value);
53 }
54 /** Return the entire state stack. */
55 public PosStateStack states ()
56 {
57 return statestack;
58 }
59 /**
60 * Used when loading events (loadDialog) to determine if
61 * states need to be pushed also.
62 */
63 public boolean isDialog ()
64 {
65 return true;
66 }
67
68 /**
69 * Constructor calls superclass constructor and
70 * creates a state stack.
71 */
72 public PosDialogEvent ()
73 {
74 super ();
75 statestack = new PosStateStack ();
76 }
77
78 /**
79 * Constructor calls superclass constructor,
80 * creates a state stack and pushes an initial event.
81 */
82 public PosDialogEvent (int state)
83 {
84 super ();
85 statestack = new PosStateStack ();
86 statestack.pushState (state);
87 }
88
89 /**
90 * Finds the next event or dialog state and engages it.
91 */
92 public void nextDialogEvent ()
93 {
94
95 PosEvent nextEvent = null;
96 if (states ().pendingSize () > 1)
97 {
98 states ().popState ();
99 nextEvent = this; // recursion!!
100 }
101 else
102 {
103 nextEvent = context ().eventStack ().popEvent ();
104 }
105
106 try
107 {
108 nextEvent.engage (0);
109 }
110 catch (PosException e)
111 {
112 Log.warning ("PosException in nextDialogEvent");
113 Log.warning (e.toString ());
114 }
115 }
116
117 /**
118 * Pushes a new event on, note that it also pops the current
119 */
120 public void pushUserEvent (int id)
121 {
122
123 states ().popState ();
124 states ().pushState (id);
125 }
126 }
127
128 /**
129 * $Log: PosDialogEvent.java,v $
130 * Revision 1.1.1.1 2001/08/13 22:17:15 qolson
131 * Initial Checkin 0.2-2
132 *
133 *
134 */