use of org.compiere.model.MPOSKey in project lar_361 by comitsrl.
the class PosKeyPanel method createCard.
/**
* @return
*/
private CPanel createCard(int C_POSKeyLayout_ID) {
// already added
if (keymap.containsKey(C_POSKeyLayout_ID)) {
return null;
}
CPanel card = new CPanel();
card.setLayout(new MigLayout("fill, ins 0"));
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();
}
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);
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
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());
Icon icon = image.getIcon();
button.setIcon(icon);
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;
}
Aggregations