001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.pos.component;
019:
020: import java.awt.Color;
021: import java.awt.Font;
022: import java.awt.Component;
023: import java.text.SimpleDateFormat;
024: import java.util.Date;
025: import javax.swing.BorderFactory;
026: import javax.swing.border.Border;
027: import javax.swing.border.TitledBorder;
028: import java.util.Locale;
029:
030: import net.xoetrope.xui.style.XStyle;
031: import net.xoetrope.xui.XProjectManager;
032: import net.xoetrope.swing.XEdit;
033: import net.xoetrope.swing.XPanel;
034:
035: import org.ofbiz.pos.screen.PosScreen;
036: import org.ofbiz.pos.PosTransaction;
037: import org.ofbiz.base.util.UtilFormatOut;
038: import org.ofbiz.base.util.UtilProperties;
039:
040: public class Operator {
041:
042: public static final String module = Operator.class.getName();
043: public static final String style = "operTitle";
044:
045: public static final String[] OPER_TOTAL = { "oper_total", "TOTAL" };
046: public static final String[] OPER_DATE = { "oper_date", "DATE" };
047: public static final String[] OPER_EMPL = { "oper_empl", "EMPL" };
048: public static final String[] OPER_TXID = { "oper_txid", "TXID" };
049: public static final String[] OPER_DRWR = { "oper_drwr", "DRAWER" };
050:
051: public static SimpleDateFormat sdf = new SimpleDateFormat(
052: UtilProperties.getMessage("pos", "DateFormat", Locale
053: .getDefault()));
054: protected Component[] operatorField = null;
055: protected XStyle titleStyle = null;
056: protected XPanel operPanel = null;
057:
058: private Locale defaultLocale = Locale.getDefault();
059:
060: public Operator(PosScreen page) {
061: this .titleStyle = XProjectManager.getStyleManager().getStyle(
062: style);
063: this .operPanel = (XPanel) page.findComponent("oper_panel");
064: this .operatorField = operPanel.getComponents();
065: this .operPanel.setVisible(false);
066: this .refresh();
067: }
068:
069: public void setLock(boolean lock) {
070: operPanel.setVisible(!lock);
071: }
072:
073: public void refresh() {
074: for (int i = 0; i < operatorField.length; i++) {
075: if (operatorField[i] instanceof XEdit) {
076: this .setupField((XEdit) operatorField[i]);
077: this .setFieldValue((XEdit) operatorField[i]);
078: }
079: }
080: }
081:
082: protected void setupField(XEdit field) {
083: Color titleColor = titleStyle
084: .getStyleAsColor(XStyle.COLOR_FORE);
085: String fontName = titleStyle.getStyleAsString(XStyle.FONT_FACE);
086: int fontStyle = titleStyle.getStyleAsInt(XStyle.FONT_WEIGHT);
087: int fontSize = titleStyle.getStyleAsInt(XStyle.FONT_SIZE);
088: Font titleFont = new Font(fontName, fontStyle, fontSize);
089:
090: Border base = BorderFactory.createEtchedBorder();
091: TitledBorder border = BorderFactory.createTitledBorder(base,
092: this .getFieldTitle(field.getName()), TitledBorder.LEFT,
093: TitledBorder.TOP, titleFont, titleColor);
094: field.setBorder(border);
095: field.setOpaque(true);
096: field.setEditable(false);
097: }
098:
099: protected void setFieldValue(XEdit field) {
100: PosTransaction trans = null;
101: if (operPanel.isVisible()) {
102: trans = PosTransaction.getCurrentTx(PosScreen.currentScreen
103: .getSession());
104: }
105:
106: String fieldName = field.getName();
107: if (OPER_TOTAL[0].equals(fieldName)) {
108: String total = "0.00";
109: if (trans != null) {
110: total = UtilFormatOut.formatPrice(trans.getTotalDue());
111: }
112: field.setText(total);
113: } else if (OPER_DATE[0].equals(fieldName)) {
114: field.setText(sdf.format(new Date()));
115: } else if (OPER_EMPL[0].equals(fieldName)) {
116: String userId = "NA";
117: if (trans != null) {
118: userId = PosScreen.currentScreen.getSession()
119: .getUserId();
120: }
121: field.setText(userId);
122: } else if (OPER_TXID[0].equals(fieldName)) {
123: String txId = "NA";
124: if (trans != null) {
125: txId = trans.getTransactionId();
126: }
127: field.setText(txId);
128: } else if (OPER_DRWR[0].equals(fieldName)) {
129: String drawer = "0";
130: if (trans != null) {
131: drawer = "" + trans.getDrawerNumber();
132: }
133: field.setText(drawer);
134: }
135: }
136:
137: protected String getFieldTitle(String fieldName) {
138: if (OPER_TOTAL[0].equals(fieldName)) {
139: return UtilProperties.getMessage("pos", "TOTAL",
140: defaultLocale);
141: } else if (OPER_DATE[0].equals(fieldName)) {
142: return UtilProperties.getMessage("pos", "DATE",
143: defaultLocale);
144: } else if (OPER_EMPL[0].equals(fieldName)) {
145: return UtilProperties.getMessage("pos", "EMPL",
146: defaultLocale);
147: } else if (OPER_TXID[0].equals(fieldName)) {
148: return UtilProperties.getMessage("pos", "TXID",
149: defaultLocale);
150: } else if (OPER_DRWR[0].equals(fieldName)) {
151: return UtilProperties.getMessage("pos", "DRWR",
152: defaultLocale);
153: }
154: return "";
155: }
156:
157: }
|