Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/globalretailtech/pos/events/NumKey.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 java.util.Vector;
23  import com.globalretailtech.util.*;
24  import com.globalretailtech.data.*;
25  import com.globalretailtech.pos.ej.*;
26  import com.globalretailtech.pos.context.*;
27  import com.globalretailtech.pos.gui.*;
28  import com.globalretailtech.pos.events.PosEvent;
29  import com.globalretailtech.pos.devices.OperPrompt;
30  
31  /**
32   * Handles number key input. Add to the input buffer. Also
33   * checks for length of the input buffer if it matches a mask, do an item lookup (needs to 
34   * be parameterized in the property file.) (not implemented)
35   *
36   * @author  Quentin Olson
37   */
38  public class NumKey extends PosEvent
39  {
40  
41  
42      private String promptText;
43      private String numText;
44  
45      /** Prompt text for dialogs */
46      public String promptText ()
47      {
48          return promptText;
49      }
50      /** Number text for dialogs */
51      public String numText ()
52      {
53          return numText;
54      }
55  
56      /** Simple constructor for dynamic load */
57      public NumKey ()
58      {}
59  
60      /**
61       * If the input is >= 0, assume valid number is entered.
62       * Else look at the current PosEvent and figure out what to do:
63       * <ul>
64       * <li>Logon, get the prompt text from that event</li>
65       * <li>EjCheckTender, get the prompt text from that event</li>
66       * </ul>
67       * etc.
68       */
69      public void engage (int value)
70      {
71  
72          if (value >= 0)
73          {
74              context ().addToInput (value);
75          }
76  
77          PosEvent currEvent = context ().eventStack ().event ();
78  
79          if (currEvent instanceof Weight)
80          {
81              Weight weight = (Weight) currEvent;
82              weight.setWeight (context ().inputDouble ());
83          }
84  
85          if (currEvent instanceof ItemPriceAdjust)
86          {
87              ItemPriceAdjust itemPriceAdjust = (ItemPriceAdjust) currEvent;
88              itemPriceAdjust.setPrice (context ().inputDouble ());
89          }
90  
91          // format a number prompt with masking
92  
93          if (currEvent instanceof PosNumberDialog)
94          {
95  
96              PosNumberDialog numberDialog = (PosNumberDialog) currEvent;
97              promptText = numberDialog.promptText ();
98  
99              numText = context ().inputLine ();
100 
101             switch (numberDialog.type ())
102             {
103 
104             case PosNumberDialog.CLEAR:
105                 break;
106             case PosNumberDialog.MASK:
107                 StringBuffer tmp = new StringBuffer ();
108                 for (int i=0;i<numText.length (); i++)
109                 {
110                     tmp.append ("*");
111                 }
112                 numText = tmp.toString ();
113                 break;
114             case PosNumberDialog.DECIMAL:
115 
116                 double decimal = context ().inputDouble () / 100.0;
117                 numText = Double.toString (decimal);
118                 break;
119             case PosNumberDialog.CURRENCY:
120                 numText = Format.toMoney (Double.toString (context ().inputDouble ()), Application.locale ());
121                 break;
122             default:
123                 break;
124             }
125 
126             if (currEvent instanceof CustMain)
127             {
128                 CustMain cust = (CustMain) currEvent;
129                 cust.setInputText (numText);
130             }
131         }
132 
133         // Convert it to be displayed as currency
134         else if (currEvent instanceof EjLine)
135         {
136 
137             EjLine line = (EjLine) currEvent;
138             promptText = line.prompt ();
139             if (line.numberType () == EjLine.AMOUNT)
140             {
141                 numText = Format.toMoney (Double.toString (context ().inputDouble ()), Application.locale ());
142             }
143             else
144             {
145                 numText = context ().inputLine ();
146             }
147         }
148         else
149         {
150             promptText = "";
151             numText = context ().inputLine ();
152         }
153         context ().operPrompt().update (this);
154 
155     }
156 
157     /** Validate transistions state */
158     public boolean validTransition (String event)
159     {
160         return true;
161     }
162     /**
163      * Erase the last char on the input line
164      */
165     public void clear ()
166     {
167         context ().eraseLast ();
168         engage (-1);
169     }
170 
171     private static String eventname = "NumKey";
172     /** Return staic name. */
173     public String toString ()
174     {
175         return eventname;
176     }
177     /** Return staic name. */
178     public static String eventName ()
179     {
180         return eventname;
181     }
182 }
183 
184 /**
185  * $Log: NumKey.java,v $
186  * Revision 1.1.1.1  2001/08/13 22:17:14  qolson
187  * Initial Checkin 0.2-2
188  *
189  *
190  */