1 25 package org.ofbiz.pos.component; 26 27 import java.awt.Color ; 28 import java.awt.Font ; 29 import java.awt.Component ; 30 import java.text.SimpleDateFormat ; 31 import java.util.Date ; 32 import javax.swing.BorderFactory ; 33 import javax.swing.border.Border ; 34 import javax.swing.border.TitledBorder ; 35 import java.util.Locale ; 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 53 public class Operator { 54 55 public static final String module = Operator.class.getName(); 56 public static final String style = "operTitle"; 57 58 public static final String [] OPER_TOTAL = { "oper_total", "TOTAL" }; 59 public static final String [] OPER_DATE = { "oper_date", "DATE" }; 60 public static final String [] OPER_EMPL = { "oper_empl", "EMPL" }; 61 public static final String [] OPER_TXID = { "oper_txid", "TXID" }; 62 public static final String [] OPER_DRWR = { "oper_drwr", "DRAWER" }; 63 64 public static SimpleDateFormat sdf = new SimpleDateFormat (UtilProperties.getMessage("pos","DateFormat",Locale.getDefault())); 65 protected Component [] operatorField = null; 66 protected XStyle titleStyle = null; 67 protected XPanel operPanel = null; 68 69 private Locale 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 titleColor = titleStyle.getStyleAsColor(XStyle.COLOR_FORE); 95 String fontName = titleStyle.getStyleAsString(XStyle.FONT_FACE); 96 int fontStyle = titleStyle.getStyleAsInt(XStyle.FONT_WEIGHT); 97 int fontSize = titleStyle.getStyleAsInt(XStyle.FONT_SIZE); 98 Font titleFont = new Font (fontName, fontStyle, fontSize); 99 100 Border base = BorderFactory.createEtchedBorder(); 101 TitledBorder 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 fieldName = field.getName(); 115 if (OPER_TOTAL[0].equals(fieldName)) { 116 String 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 ())); 123 } else if (OPER_EMPL[0].equals(fieldName)) { 124 String 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 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 drawer = "0"; 137 if (trans != null) { 138 drawer = "" + trans.getDrawerNumber(); 139 } 140 field.setText(drawer); 141 } 142 } 143 144 protected String getFieldTitle(String 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 |