use of org.compiere.model.MPOSKey in project adempiere by adempiere.
the class POSKeyPanel method actionPerformed.
/**
* Action Listener
* @param actionEvent event
*/
public void actionPerformed(ActionEvent actionEvent) {
String action = actionEvent.getActionCommand();
if (action == null || action.length() == 0 || keyMaps == null)
return;
log.info("PosSubFunctionKeys - actionPerformed: " + action);
HashMap<Integer, MPOSKey> currentKeymap = keyMaps.get(currentLayout);
try {
int posKeyId = Integer.parseInt(action);
MPOSKey key = currentKeymap.get(posKeyId);
// switch layout
if (key.getSubKeyLayout_ID() > 0) {
currentLayout = key.getSubKeyLayout_ID();
cardLayout.show(this, Integer.toString(key.getSubKeyLayout_ID()));
} else {
caller.keyReturned(key);
}
} catch (Exception ex) {
log.info("Error : " + ex);
}
}
use of org.compiere.model.MPOSKey in project adempiere by adempiere.
the class POSKeyPanel method createCard.
/**
* @return
*/
private CPanel createCard(int posKeyLayoutId) {
// already added
if (keyMaps.containsKey(posKeyLayoutId)) {
return null;
}
CPanel card = new CPanel();
card.setLayout(new MigLayout("fill, ins 0"));
MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), posKeyLayoutId);
Color stdColor = Color.lightGray;
if (keyLayout.getAD_PrintColor_ID() != 0) {
MPrintColor color = MPrintColor.get(Env.getCtx(), keyLayout.getAD_PrintColor_ID());
stdColor = color.getColor();
}
Font stdFont = AdempierePLAF.getFont_Field();
if (keyLayout.getAD_PrintFont_ID() != 0) {
MPrintFont font = MPrintFont.get(keyLayout.getAD_PrintFont_ID());
stdFont = font.getFont();
}
if (keyLayout.get_ID() == 0)
return null;
MPOSKey[] keys = keyLayout.getKeys(false);
HashMap<Integer, MPOSKey> map = new HashMap<Integer, MPOSKey>(keys.length);
keyMaps.put(posKeyLayoutId, map);
// Min Columns
int COLUMNS = 3;
// Min Rows
int ROWS = 3;
int noKeys = keys.length;
int cols = keyLayout.getColumns();
if (cols == 0)
cols = COLUMNS;
int buttons = 0;
log.fine("PosSubFunctionKeys.init - NoKeys=" + noKeys + ", Cols=" + cols);
// Content
CPanel content = new CPanel(new MigLayout("fill, wrap " + Math.max(cols, 3)));
String buttonSize = "h 50, w 50, growx, growy, sg button,";
for (MPOSKey key : keys) {
if (key.getSubKeyLayout_ID() > 0) {
CPanel subCard = createCard(key.getSubKeyLayout_ID());
if (subCard != null)
add(subCard, Integer.toString(key.getSubKeyLayout_ID()));
}
map.put(key.getC_POSKey_ID(), key);
Color keyColor = stdColor;
Font keyFont = stdFont;
StringBuffer buttonHTML = new StringBuffer("<html><p>");
if (key.getAD_PrintColor_ID() != 0) {
MPrintColor color = MPrintColor.get(Env.getCtx(), key.getAD_PrintColor_ID());
keyColor = color.getColor();
}
if (key.getAD_PrintFont_ID() != 0) {
MPrintFont font = MPrintFont.get(key.getAD_PrintFont_ID());
keyFont = font.getFont();
}
buttonHTML.append(key.getName());
buttonHTML.append("</p></html>");
log.fine("#" + map.size() + " - " + keyColor);
CButton button = new CButton(buttonHTML.toString());
button.setBackground(keyColor);
button.setFont(keyFont);
if (key.getAD_Image_ID() != 0) {
MImage image = MImage.get(Env.getCtx(), key.getAD_Image_ID());
Image img = image.getImage();
// https://github.com/erpcya/AD-POS-WebUI/issues/29
// Change Image Size
Image imgResized = img.getScaledInstance(IMAGE_SIZE, IMAGE_SIZE, Image.SCALE_SMOOTH);
button.setIcon(new ImageIcon(imgResized));
button.setVerticalTextPosition(SwingConstants.BOTTOM);
button.setHorizontalTextPosition(SwingConstants.CENTER);
}
button.setFocusable(false);
if (!key.isActive())
button.setEnabled(false);
button.setActionCommand(String.valueOf(key.getC_POSKey_ID()));
button.addActionListener(this);
String constraints = buttonSize;
int size = 1;
if (key.getSpanX() > 1) {
constraints += "spanx " + key.getSpanX() + ",";
size = key.getSpanX();
}
if (key.getSpanY() > 1) {
constraints += "spany " + key.getSpanY() + ",";
size = size * key.getSpanY();
}
buttons = buttons + size;
content.add(button, constraints);
}
int rows = Math.max((buttons / cols), ROWS);
if (buttons % cols > 0)
rows = rows + 1;
for (int i = buttons; i < rows * cols; i++) {
CButton button = new CButton("");
button.setFocusable(false);
button.setReadWrite(false);
content.add(button, buttonSize);
}
CScrollPane scroll = new CScrollPane(content);
// scroll.setPreferredSize(new Dimension( 600 - 20, 400-20));
card.add(scroll, "growx, growy");
// increase scrollbar width for touchscreen
scroll.getVerticalScrollBar().setPreferredSize(new Dimension(30, 0));
scroll.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 30));
return card;
}
use of org.compiere.model.MPOSKey in project adempiere by adempiere.
the class PosKeyGenerate method doIt.
/**
* Generate keys for each product
*/
@Override
protected String doIt() throws Exception {
if (posKeyLayoutId == 0)
throw new FillMandatoryException("C_POSKeyLayout_ID");
int count = 0;
String where = "";
Object[] params = new Object[] {};
if (productCategoryId > 0) {
where = "M_Product_Category_ID = ? ";
params = new Object[] { productCategoryId };
}
Query query = new Query(getCtx(), MProduct.Table_Name, where, get_TrxName()).setParameters(params).setOnlyActiveRecords(true).setOrderBy("Value");
List<MProduct> products = query.list();
for (MProduct product : products) {
MPOSKey key = new MPOSKey(getCtx(), 0, get_TrxName());
key.setName(product.getName());
key.setM_Product_ID(product.getM_Product_ID());
key.setC_POSKeyLayout_ID(posKeyLayoutId);
key.setSeqNo(count * 10);
key.setQty(Env.ONE);
key.saveEx();
count++;
}
return "@Created@ " + count;
}
use of org.compiere.model.MPOSKey in project adempiere by adempiere.
the class WPOSKeyPanel method createPanel.
/**
* Create Panel
* @param C_POSKeyLayout_ID
* @return
* @return Panel
*/
public Panel createPanel(int C_POSKeyLayout_ID) {
Panel card = new Panel();
card.setWidth("100%");
card.setStyle("overflow:AUTO");
MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), C_POSKeyLayout_ID);
// Removal panel static
card = createButton(C_POSKeyLayout_ID);
panelMap.put(C_POSKeyLayout_ID, card);
if (keyLayout.get_ID() == 0)
return null;
MPOSKey[] keys = keyLayout.getKeys(false);
// Content
for (MPOSKey key : keys) {
if (key.getSubKeyLayout_ID() > 0) {
Panel subcard = new Panel();
subcard = createButton(key.getSubKeyLayout_ID());
panelMap.put(key.getSubKeyLayout_ID(), subcard);
appendChild(subcard);
subcard.setVisible(false);
}
}
return card;
}
use of org.compiere.model.MPOSKey in project adempiere by adempiere.
the class WPOSKeyPanel method createButton.
/**
* Create Buttton For Keyboard
* @param C_POSKeyLayout_ID
* @param m_txtCalc
* @return
* @return Panel
*/
private Panel createButton(int C_POSKeyLayout_ID, String m_txtCalc) {
// already added
if (keymap.containsKey(C_POSKeyLayout_ID)) {
return null;
}
Panel card = new Panel();
MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), C_POSKeyLayout_ID);
Color stdColor = Color.lightGray;
if (keyLayout.getAD_PrintColor_ID() != 0) {
MPrintColor color = MPrintColor.get(Env.getCtx(), keyLayout.getAD_PrintColor_ID());
stdColor = color.getColor();
}
if (keyLayout.get_ID() == 0)
return null;
MPOSKey[] keys = keyLayout.getKeys(false);
HashMap<Integer, MPOSKey> map = new HashMap<Integer, MPOSKey>(keys.length);
keymap.put(C_POSKeyLayout_ID, map);
// Min Columns
int COLUMNS = 3;
// Min Rows
int ROWS = 3;
int noKeys = keys.length;
int cols = keyLayout.getColumns();
if (cols == 0)
cols = COLUMNS;
int buttons = 0;
log.fine("PosSubFunctionKeys.init - NoKeys=" + noKeys + ", Cols=" + cols);
// Content
Panel content = new Panel();
for (MPOSKey key : keys) {
map.put(key.getC_POSKey_ID(), key);
Color keyColor = stdColor;
if (key.getAD_PrintColor_ID() != 0) {
MPrintColor color = MPrintColor.get(Env.getCtx(), key.getAD_PrintColor_ID());
keyColor = color.getColor();
}
log.fine("#" + map.size() + " - " + keyColor);
Panel button = new Panel();
Label label = new Label(key.getName());
label.setStyle("margin: 25px 0px 00px 0px; top:20px; font-size:medium; font-weight: bold;");
label.setHeight("100%");
button.appendChild(label);
button.setClass("z-button");
button.setStyle("float:left; white-space: pre-line;text-align:center; margin:0.4% 1%; Background-color:rgb(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + "); border: 2px outset #CCC; " + "background: -moz-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);" + "background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(247,247,247,1)), color-stop(7%, rgba(255,255,255,0.93)), color-stop(15%, rgba(186,186,186,0.25)), color-stop(100%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1)));" + "background: -webkit-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);");
button.setHeight("55px");
button.setWidth("55px");
button.setAction("onClick : text_action.textEvent('" + m_txtCalc + "', '" + key.getText() + "', '" + this.keyBoardType + "')");
button.setId("" + key.getC_POSKey_ID());
button.addEventListener("onClick", this);
int size = 1;
if (key.getSpanX() > 1) {
size = key.getSpanX();
}
if (key.getSpanY() > 1) {
size = size * key.getSpanY();
}
buttons = buttons + size;
content.appendChild(button);
}
int rows = Math.max((buttons / cols), ROWS);
if (buttons % cols > 0)
rows = rows + 1;
for (int i = buttons; i < rows * cols; i++) {
Panel button = new Panel();
button.setStyle("float:left; text-align:center; margin:0.4% 1%;");
button.setHeight("55px");
button.setWidth("55px");
content.appendChild(button);
}
card.appendChild(content);
return card;
}
Aggregations