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

Quick Search    Search Deep

Source code: com/globalretailtech/pos/gui/OperDisplay4C.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.gui;
21  
22  import java.awt.*;
23  import java.awt.event.*;
24  import javax.swing.*;
25  import javax.swing.border.*;
26  import java.util.Hashtable;
27  import javax.swing.ImageIcon;
28  
29  import com.globalretailtech.util.*;
30  import com.globalretailtech.pos.context.*;
31  import com.globalretailtech.pos.events.*;
32  import com.globalretailtech.pos.ej.*;
33  import com.globalretailtech.pos.devices.*;
34  
35  /**
36   * An invoice display. Contains a header field
37   * for transaction information, #, pos #, employee
38   * and date. Implements JTable to display transaction
39   * detail that includes quantity, item (sku number), 
40   * a long description and price. (Need to figure out how
41   * to merge this with OperDisplay.)
42   *
43   * @author  Quentin Olson
44   * @see PosTicket
45   */
46  public class OperDisplay4C extends JPanel implements PosTicket
47  {
48  
49      /** Line up directive */
50      public static final int UP = 1;
51      /** Line down directive */
52      public static final int DOWN = 2;
53      /** Top of reciept directive */
54      public static final int TOP = 3;
55      /** Bottom of receipt directive */
56      public static final int BOTTOM = 4;
57  
58      // fonts
59      private Font operReceiptFont;
60      private Font headerFont;
61      private Font headerTitleFont;
62      private int operReceiptFontSize;
63      private int headerFontSize;
64      private int headerTitleFontSize;
65  
66      // table panel size
67  
68      private int height;
69      private int width;
70  
71      // receipt table widths and height
72  
73      private int qtyWidth;
74      private int itemWidth;
75      private int descWidth;
76      private int valueWidth;
77      private int rowHeight;
78      private int tableRows;
79  
80      // Visual elements
81  
82      private JScrollPane scrollpane;
83      private JViewport viewport;
84      private static JTable table;
85      private int row;
86      private int rowStep;
87  
88      private tableModel dataModel;
89  
90      private OperReceiptField trx;
91      private OperReceiptField pos;
92      private OperReceiptField emp;
93      private OperReceiptField date;
94  
95  
96      // Table column indexes
97  
98      private static int QTY = 0;
99      private static int ITEM = 1;
100     private static int DESC = 2;
101     private static int VALUE = 3;
102 
103     private static int COLS = 4;
104 
105 
106     // the literals from pos config
107 
108     private PosParameters posParameters;
109 
110     /**
111      * Initialize with the current literals and paramaters.
112      */
113     public OperDisplay4C ()
114     {
115         super();
116     }
117     public boolean isOpen ()
118     {
119         return true;
120     }
121     /**
122      * Read the properties file for format information.
123      * Create the panels and setup the layout. Add the
124      * fields to the layout.
125      */
126     public void init (PosParameters params, int w, int h)
127     {
128 
129         setLayout (new BorderLayout ());
130         width = w;
131         height = h;
132         posParameters = params;
133 
134         ShareProperties p = new ShareProperties (this.getClass ().getName ());
135 
136         if (p.Found ())
137         {
138             operReceiptFontSize = Integer.valueOf (p.getProperty ("OperReceiptFontSize", "10")).intValue ();
139             operReceiptFont = new Font (p.getProperty ("OperReceiptFont", "Courier"), Font.PLAIN, operReceiptFontSize);
140             headerFontSize = Integer.valueOf (p.getProperty ("HeaderFontSize", "10")).intValue ();
141             headerFont = new Font (p.getProperty ("HeaderFont", "Courier"), Font.PLAIN, headerFontSize);
142             headerTitleFontSize = Integer.valueOf (p.getProperty ("HeaderTitleFontSize", "10")).intValue ();
143             headerTitleFont = new Font (p.getProperty ("HeaderTitleFont", "Courier"), Font.PLAIN, headerTitleFontSize);
144 
145             rowHeight= Integer.valueOf (p.getProperty ("RowHeight", "20")).intValue ();
146             qtyWidth= Integer.valueOf (p.getProperty ("QtyWidth", "5")).intValue ();
147             itemWidth= Integer.valueOf (p.getProperty ("ItemWidth", "12")).intValue ();
148             descWidth= Integer.valueOf (p.getProperty ("DescWidth", "32")).intValue ();
149             valueWidth= Integer.valueOf (p.getProperty ("ValueWidth", "5")).intValue ();
150 
151             tableRows= Integer.valueOf (p.getProperty ("TableRows", "200")).intValue ();
152         }
153         else
154         {
155             // big trouble here...
156             Log.fatal ("Properties not found for OperDisplay4C");
157             return;
158         }
159 
160         JPanel headerpanel = new JPanel (new BorderLayout ());
161         headerpanel.setBorder (new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.LOWERED));
162 
163         // add the store, transaction info panels to the header panel, using a gridbag
164 
165         GridBagLayout layout = new GridBagLayout ();
166         GridBagConstraints c = new GridBagConstraints ();
167         c.fill = GridBagConstraints.BOTH;
168         c.weightx = 0.5;
169         c.weighty = 1.0;
170         JPanel trxInfo   = new JPanel (layout);   // transaction information panel
171         trxInfo.setBackground (new Color (0xFFF8C6));
172 
173         // fill out the transaction info panel, set constraints x, y, height, width
174 
175         trxInfo.add (setConstraints (trx = new OperReceiptField (posParameters.getString ("TrxTag"), 8),
176                                      layout,
177                                      c,
178                                      0, 0, 1, 1));
179 
180         trxInfo.add (setConstraints (pos = new OperReceiptField (posParameters.getString ("PosTag"), 8),
181                                      layout,
182                                      c,
183                                      1, 0, 1, 1));
184 
185         trxInfo.add (setConstraints (emp = new OperReceiptField (posParameters.getString ("EmpTag"), 8),
186                                      layout,
187                                      c,
188                                      2, 0, 1, 1));
189 
190         trxInfo.add (setConstraints (date = new OperReceiptField (posParameters.getString ("DateTag"), 8),
191                                      layout,
192                                      c,
193                                      3, 0, 1, 1));
194 
195         trxInfo.add (setConstraints (new NavButton ("../share/top.gif", TOP),
196                                      layout,
197                                      c,
198                                      0, 1, 1, 1));
199 
200         trxInfo.add (setConstraints (new NavButton ("../share/up.gif", UP),
201                                      layout,
202                                      c,
203                                      1, 1, 1, 1));
204 
205         trxInfo.add (setConstraints (new NavButton ("../share/down.gif", DOWN),
206                                      layout,
207                                      c,
208                                      2, 1, 1, 1));
209 
210         trxInfo.add (setConstraints (new NavButton ("../share/bottom.gif", BOTTOM),
211                                      layout,
212                                      c,
213                                      3, 1, 1, 1));
214 
215         // add the transaction area
216 
217         headerpanel.add (trxInfo);
218 
219         // Done with header stuff, set up the item sale section
220 
221         table = new JTable (dataModel = new tableModel (tableRows));
222         table.setFont (operReceiptFont);
223         table.setBackground (new Color (0xFFF8C6));
224         table.setRowHeight (rowHeight);
225 
226         javax.swing.table.TableColumn col = null;
227         table.setBorder (new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.LOWERED));
228 
229         col = table.getColumnModel ().getColumn (QTY);
230         col.setPreferredWidth (qtyWidth);
231         col.setMaxWidth (qtyWidth);
232         col.setMinWidth (qtyWidth);
233 
234         col = table.getColumnModel ().getColumn (ITEM);
235         col.setPreferredWidth (itemWidth);
236         col.setMaxWidth (itemWidth);
237         col.setMinWidth (itemWidth);
238 
239         col = table.getColumnModel ().getColumn (DESC);
240         col.setPreferredWidth (descWidth);
241         col.setMaxWidth (descWidth);
242         col.setMinWidth (descWidth);
243 
244         col = table.getColumnModel ().getColumn (VALUE);
245         col.setPreferredWidth (valueWidth);
246         col.setMaxWidth (valueWidth);
247         col.setMinWidth (valueWidth);
248 
249         scrollpane = new JScrollPane (table);
250         scrollpane.setVerticalScrollBarPolicy (JScrollPane.VERTICAL_SCROLLBAR_NEVER);  // we'll use our own buttons instead.
251 
252         viewport = scrollpane.getViewport ();
253 
254         // set the size of the whole thing here.
255 
256         scrollpane.setPreferredSize (new Dimension (width, height));
257 
258         add (headerpanel, BorderLayout.NORTH);
259         add (scrollpane, BorderLayout.SOUTH);
260         row = rowStep= 0;
261     }
262 
263 
264     /**
265      * PosTicket abstract implementations 
266      */
267 
268     /** Character width of quantity column. */
269     public int getQtyWidth ()
270     {
271         return 3;
272     }
273     /** Character width of item/sku column. */
274     public int getItemWidth ()
275     {
276         return 2 * (itemWidth / operReceiptFontSize) - 3;
277     }
278     /** Character width of description column. */
279     public int getItemDescWidth ()
280     {
281         return 2 * (descWidth / operReceiptFontSize) - 3;
282     }
283     /** Character width of price/amount column. */
284     public int getAmountWidth ()
285     {
286         return 2 * (valueWidth / operReceiptFontSize) - 3;
287     }
288     /** Number of columns in the table */
289     public int getColumns ()
290     {
291         return 4;
292     }
293     /** Return the graphical component */
294     public Component getGui ()
295     {
296         return this;
297     }
298     /** Set the transaction number. */
299     public void setTrxNo (String value)
300     {
301         trx.setText (value);
302     }
303     /** Set the POS number */
304     public void setPosNo (String value)
305     {
306         pos.setText (value);
307     }
308     /** Set the operator/user ID. */
309     public void setOperator (String value)
310     {
311         emp.setText (value);
312     }
313     /** Set the date field. */
314     public void setDate (String value)
315     { }
316     /** Set the quantity field. */
317     public void setQty (String value)
318     {
319         dataModel.setValueAt (value, row, QTY);
320     }
321     /** Set the item/sku field. */
322     public void setItem (String value)
323     {
324         dataModel.setValueAt (value, row, ITEM);
325     }
326     /** Set the description field. */
327     public void setDesc (String value)
328     {
329         dataModel.setValueAt (value, row, DESC);
330     }
331     /**Set the amount/price field. */
332     public void setAmount (String value)
333     {
334         dataModel.setValueAt (value, row, VALUE);
335     }
336     /**
337      *Print an enpty line, cr/lf.
338      */
339     public void println ()
340     {
341         row++;
342         rowStep = row;
343         makeRowVisible(table, row);
344     }
345 
346     /**
347      * Print a string and a cr/lf
348      */
349     public void println (String value)
350     {
351         setDesc (value);
352         row++;
353         rowStep = row;
354         makeRowVisible(table, row);
355     }
356 
357     /**
358      * Print the header for this class
359      */
360     public void printHeader ()
361     {}
362     /**
363      * Print the trailer for this class.
364      */
365     public void printTrailer ()
366     {}
367 
368     /**
369      * The clear opperation for this class, 
370      * clear each row in the table, set
371      * current row to 0 and move to the 
372      * top of the table.
373      */
374     public void clear ()
375     {
376 
377         for (int i=0;i<dataModel.getRowCount ();i++)
378         {
379 
380             dataModel.setValueAt (new String (""), i, QTY);
381             dataModel.setValueAt (new String (""), i, ITEM);
382             dataModel.setValueAt (new String (""), i, DESC);
383             dataModel.setValueAt (new String (""), i, VALUE);
384         }
385         row = rowStep = 0;
386         makeRowVisible(table, row);
387     }
388     public void clearln ()
389     { }
390 
391     /**
392      * The table implementation.
393      */
394     private class tableModel extends javax.swing.table.AbstractTableModel
395     {
396 
397         private int rows;
398 
399         public tableModel (int r)
400         {
401             rows = r;
402             rowData = new Object [rows][COLS];
403         };
404 
405         private String [] colunmNames = {"Qty", "Item", "Desc.", "Price"};
406         private Object [][] rowData;
407 
408         public String getColumnName (int col)
409         {
410             return colunmNames [col];
411         }
412         public int getRowCount ()
413         {
414             return rows;
415         }
416         public int getColumnCount ()
417         {
418             return COLS;
419         }
420         public Object getValueAt (int row, int column)
421         {
422             return rowData [row][column];
423         }
424         public boolean isCellEditable (int row, int column)
425         {
426             return false;
427         }
428         public void setValueAt (Object value, int row, int column)
429         {
430             rowData [row][column] = value;
431             fireTableCellUpdated (row, column);
432         }
433     }
434 
435     /**
436      * Private method to set GridBagConstraints.
437      */
438     private Component setConstraints (Component c,
439                                       GridBagLayout layout,
440                                       GridBagConstraints constraints,
441                                       int x,
442                                       int y,
443                                       int height,
444                                       int width)
445     {
446 
447         constraints.gridx = x;
448         constraints.gridy = y;
449         constraints.gridheight = height;
450         constraints.gridwidth = width;
451         layout.setConstraints (c, constraints);
452 
453         return c;
454     }
455 
456     /**
457      * Class to manage labels.
458      */
459     private class OperReceiptLabel extends JLabel
460     {
461 
462         public OperReceiptLabel(String text)
463         {
464             super (text);
465             setAlignmentX (RIGHT_ALIGNMENT);
466             setFont (headerFont);
467             setOpaque (true);
468             setForeground (Color.black);
469             setBackground (new Color (0xFFF8C6));
470         }
471     }
472 
473     /**
474      * Class to manage named text fields.
475      */
476     private class OperReceiptField extends JTextField
477     {
478 
479         public OperReceiptField (String title, int len)
480         {
481             super (len);
482             setOpaque (true);
483             setFont (headerFont);
484             setBackground (new Color (0xFFF8C6));
485             Border base = BorderFactory.createEtchedBorder ();
486             TitledBorder border = BorderFactory.createTitledBorder (base,
487                                   title,
488                                   TitledBorder.LEFT,
489                                   TitledBorder.TOP,
490                                   headerTitleFont,
491                                   Color.black);
492 
493             setBorder(border);
494             setForeground (Color.black);
495         }
496     }
497 
498     /**
499      * Class for implementing navigation buttons.
500      */
501     private class NavButton extends JButton
502     {
503 
504         private int directive;
505         public int directive ()
506         {
507             return directive;
508         }
509 
510         public NavButton (String img, int value)
511         {
512 
513             super (new ImageIcon (img));
514             directive = value;
515             addActionListener (new NavAction ());
516         }
517     }
518 
519     /**
520      * Class for implementing navigation actions.
521      */
522     class NavAction implements ActionListener
523     {
524 
525         public NavAction ()
526         { }
527 
528         public void actionPerformed (ActionEvent e)
529         {
530 
531             NavButton button = (NavButton) e.getSource ();
532 
533             switch (button.directive ())
534             {
535             case UP:
536 
537                 if (rowStep > 0)
538                 {
539                     rowStep --;
540                     makeRowVisible (table, rowStep);
541                 }
542 
543                 break;
544             case DOWN:
545 
546                 if (rowStep < row)
547                 {
548                     rowStep ++;
549                     makeRowVisible (table, rowStep);
550                 }
551                 break;
552             case TOP:
553                 makeRowVisible (table, 0);
554                 break;
555             case BOTTOM:
556                 makeRowVisible (table, row);
557                 break;
558             }
559         }
560     }
561 
562     /**
563      * Method to scroll to the specified row.
564      */
565     public static void makeRowVisible(JTable table, int visibleRow)
566     {
567         if (table.getColumnCount() == 0)
568             return;
569 
570         if (visibleRow < 0 || visibleRow >= table.getRowCount())
571         {
572             throw new IllegalArgumentException(String.valueOf(visibleRow));
573         }
574 
575         Rectangle visible = table.getVisibleRect();
576         Rectangle cell = table.getCellRect(visibleRow, 0, true);
577 
578         if (cell.y < visible.y)
579         {
580             visible.y = cell.y;
581             table.scrollRectToVisible(visible);
582         }
583         else if (cell.y + cell.height > visible.y + visible.height)
584         {
585             visible.y = cell.y + cell.height - visible.height;
586             table.scrollRectToVisible(visible);
587         }
588     }
589 
590     public void addSelectableItem (EjLine value)
591     { }
592     public int getTotalWidth ()
593     {
594         return 0;
595     }
596 }
597 
598 /**
599  * $Log: OperDisplay4C.java,v $
600  * Revision 1.1.1.1  2001/08/13 22:19:07  qolson
601  * Initial Checkin 0.2-2
602  *
603  *
604  */