KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > pos > component > Operator


1 /*
2  * $Id: Operator.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.pos.component;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.Font JavaDoc;
29 import java.awt.Component JavaDoc;
30 import java.text.SimpleDateFormat JavaDoc;
31 import java.util.Date JavaDoc;
32 import javax.swing.BorderFactory JavaDoc;
33 import javax.swing.border.Border JavaDoc;
34 import javax.swing.border.TitledBorder JavaDoc;
35 import java.util.Locale JavaDoc;
36
37 import net.xoetrope.xui.style.XStyle;
38 import net.xoetrope.xui.XProjectManager;
39 import net.xoetrope.swing.XEdit;
40 import net.xoetrope.swing.XPanel;
41
42 import org.ofbiz.pos.screen.PosScreen;
43 import org.ofbiz.pos.PosTransaction;
44 import org.ofbiz.base.util.UtilFormatOut;
45 import org.ofbiz.base.util.UtilProperties;
46
47 /**
48  *
49  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
50  * @version $Rev: 5462 $
51  * @since Aug 24, 2004
52  */

53 public class Operator {
54
55     public static final String JavaDoc module = Operator.class.getName();
56     public static final String JavaDoc style = "operTitle";
57
58     public static final String JavaDoc[] OPER_TOTAL = { "oper_total", "TOTAL" };
59     public static final String JavaDoc[] OPER_DATE = { "oper_date", "DATE" };
60     public static final String JavaDoc[] OPER_EMPL = { "oper_empl", "EMPL" };
61     public static final String JavaDoc[] OPER_TXID = { "oper_txid", "TXID" };
62     public static final String JavaDoc[] OPER_DRWR = { "oper_drwr", "DRAWER" };
63     
64     public static SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc(UtilProperties.getMessage("pos","DateFormat",Locale.getDefault()));
65     protected Component JavaDoc[] operatorField = null;
66     protected XStyle titleStyle = null;
67     protected XPanel operPanel = null;
68     
69     private Locale JavaDoc defaultLocale = Locale.getDefault();
70    
71
72     public Operator(PosScreen page) {
73         this.titleStyle = XProjectManager.getStyleManager().getStyle(style);
74         this.operPanel = (XPanel) page.findComponent("oper_panel");
75         this.operatorField = operPanel.getComponents();
76         this.operPanel.setVisible(false);
77         this.refresh();
78     }
79
80     public void setLock(boolean lock) {
81         operPanel.setVisible(!lock);
82     }
83
84     public void refresh() {
85         for (int i = 0; i < operatorField.length; i++) {
86             if (operatorField[i] instanceof XEdit) {
87                 this.setupField((XEdit) operatorField[i]);
88                 this.setFieldValue((XEdit) operatorField[i]);
89             }
90         }
91     }
92
93     protected void setupField(XEdit field) {
94         Color JavaDoc titleColor = titleStyle.getStyleAsColor(XStyle.COLOR_FORE);
95         String JavaDoc fontName = titleStyle.getStyleAsString(XStyle.FONT_FACE);
96         int fontStyle = titleStyle.getStyleAsInt(XStyle.FONT_WEIGHT);
97         int fontSize = titleStyle.getStyleAsInt(XStyle.FONT_SIZE);
98         Font JavaDoc titleFont = new Font JavaDoc(fontName, fontStyle, fontSize);
99
100         Border JavaDoc base = BorderFactory.createEtchedBorder();
101         TitledBorder JavaDoc border = BorderFactory.createTitledBorder(base, this.getFieldTitle(field.getName()),
102                 TitledBorder.LEFT, TitledBorder.TOP, titleFont, titleColor);
103         field.setBorder(border);
104         field.setOpaque(true);
105         field.setEditable(false);
106     }
107
108     protected void setFieldValue(XEdit field) {
109         PosTransaction trans = null;
110         if (operPanel.isVisible()) {
111             trans = PosTransaction.getCurrentTx(PosScreen.currentScreen.getSession());
112         }
113
114         String JavaDoc fieldName = field.getName();
115         if (OPER_TOTAL[0].equals(fieldName)) {
116             String JavaDoc total = "0.00";
117             if (trans != null) {
118                 total = UtilFormatOut.formatPrice(trans.getTotalDue());
119             }
120             field.setText(total);
121         } else if (OPER_DATE[0].equals(fieldName)) {
122             field.setText(sdf.format(new Date JavaDoc()));
123         } else if (OPER_EMPL[0].equals(fieldName)) {
124             String JavaDoc userId = "NA";
125             if (trans != null) {
126                 userId = PosScreen.currentScreen.getSession().getUserId();
127             }
128             field.setText(userId);
129         } else if (OPER_TXID[0].equals(fieldName)) {
130             String JavaDoc txId = "NA";
131             if (trans != null) {
132                 txId = trans.getTransactionId();
133             }
134             field.setText(txId);
135         } else if (OPER_DRWR[0].equals(fieldName)) {
136             String JavaDoc drawer = "0";
137             if (trans != null) {
138                 drawer = "" + trans.getDrawerNumber();
139             }
140             field.setText(drawer);
141         }
142     }
143
144     protected String JavaDoc getFieldTitle(String JavaDoc fieldName) {
145         if (OPER_TOTAL[0].equals(fieldName)) {
146             return UtilProperties.getMessage("pos","TOTAL",defaultLocale);
147         } else if (OPER_DATE[0].equals(fieldName)) {
148             return UtilProperties.getMessage("pos","DATE",defaultLocale);
149         } else if (OPER_EMPL[0].equals(fieldName)) {
150             return UtilProperties.getMessage("pos","EMPL",defaultLocale);
151         } else if (OPER_TXID[0].equals(fieldName)) {
152             return UtilProperties.getMessage("pos","TXID",defaultLocale);
153         } else if (OPER_DRWR[0].equals(fieldName)) {
154             return UtilProperties.getMessage("pos","DRWR",defaultLocale);
155         }
156         return "";
157     }
158
159 }
Popular Tags