Floreant POS使用自定义UI样式
public class POSButtonUI extends PlasticButtonUI {
private static final POSButtonUI INSTANCE = new POSButtonUI();
public static ComponentUI createUI(JComponent b) {
return INSTANCE;
}
public void update(Graphics g, JComponent c) {
if (c.isOpaque()) {
AbstractButton b = (AbstractButton) c;
if (isToolBarButton(b)) {
c.setOpaque(false);
} else if (b.isContentAreaFilled()) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
if (is3D(b)) {
Color color1 = c.getBackground();// UIManager.getColor("control");
Color color2 = color1.brighter();
int x = 0;
int y = 0;
int width = c.getWidth();
int height = c.getHeight();
GradientPaint gp = new GradientPaint(x, y, color2, width - 2, height - 2 , color1, true);
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(gp);
g2.fillRect(x, y, width, height);
}
}
}
paint(g, c);
}
}
和PosButton类扩展了JButton:
public class PosButton extends JButton {
public static Border border = new LineBorder(Color.BLACK, 1);
static Insets margin = new Insets(1, 1, 1, 1);
static POSButtonUI ui = new POSButtonUI();
static {
UIManager.put("PosButtonUI", "com.floreantpos.swing.POSButtonUI");
}
public PosButton() {
this(null);
}
public PosButton(String text) {
super(text);
setFont(UIConfig.getButtonFont());
setFocusPainted(false);
setMargin(margin);
}
@Override
public String getUIClassID() {
return "PosButtonUI";
}
}
我不确定我应该尝试在哪个类中添加paintComponent方法,以便在按钮的右上角添加数量通知以添加修饰符,而且我不太确定在哪里在这一点上去。还有一个私人课程" ModifierButton"在修改器面板中
private class ModifierButton extends PosButton implements ActionListener {
private MenuModifier menuModifier;
public ModifierButton(MenuModifier modifier) {
this.menuModifier = modifier;
setText(modifier.getName());
addActionListener(this);
}
void updateView(TicketItemModifier ticketItemModifier) {
if (ticketItemModifier == null || ticketItemModifier.getModifierType() == TicketItemModifier.MODIFIER_NOT_INITIALIZED) {
setBackground(null);
//setIcon(null);
return;
}
if (ticketItemModifier.getModifierType() == TicketItemModifier.NORMAL_MODIFIER) {
//setIcon(normalIcon);
setBackground(Color.GREEN.darker());
} else if (ticketItemModifier.getModifierType() == TicketItemModifier.NO_MODIFIER) {
//setIcon(noIcon);
setBackground(Color.RED.darker());
} else if (ticketItemModifier.getModifierType() == TicketItemModifier.EXTRA_MODIFIER) {
//setIcon(extraIcon);
setBackground(Color.ORANGE);
}
}
public void actionPerformed(ActionEvent e) {
TicketItemModifierGroup ticketItemModifierGroup = parentTicketItem.findTicketItemModifierGroup(menuModifier, true);
int modifierCount = ticketItemModifierGroup.countItems(true);
int maxModifier = ticketItemModifierGroup.getMaxQuantity();
TicketItemModifier ticketItemModifier = ticketItemModifierGroup.findTicketItemModifier(menuModifier);
TicketView ticketView = OrderView.getInstance().getTicketView();
if (ticketItemModifier == null) {
TicketItemModifier m = ticketItemModifierGroup.addTicketItemModifier(menuModifier, modifierCount >= maxModifier ? TicketItemModifier.EXTRA_MODIFIER : TicketItemModifier.NORMAL_MODIFIER);
updateView(m);
ticketView.updateAllView();
ticketView.selectRow(m.getTableRowNum());
return;
}
int modifierType = TicketItemModifier.MODIFIER_NOT_INITIALIZED;
if (ticketItemModifier.getModifierType() != null) {
modifierType = ticketItemModifier.getModifierType().intValue();
}
switch (modifierType) {
case TicketItemModifier.MODIFIER_NOT_INITIALIZED:
ticketItemModifier.setModifierType(TicketItemModifier.NORMAL_MODIFIER);
updateVisualRepresentation();
ticketView.updateAllView();
ticketView.selectRow(ticketItemModifier.getTableRowNum());
break;
case TicketItemModifier.NORMAL_MODIFIER:
case TicketItemModifier.EXTRA_MODIFIER:
ticketItemModifier.setModifierType(TicketItemModifier.NO_MODIFIER);
updateVisualRepresentation();
ticketView.updateAllView();
ticketView.selectRow(ticketItemModifier.getTableRowNum());
break;
case TicketItemModifier.NO_MODIFIER:
ticketItemModifier.setModifierType(TicketItemModifier.MODIFIER_NOT_INITIALIZED);
ticketItemModifierGroup.removeTicketItemModifier(ticketItemModifier);
updateView(ticketItemModifier);
updateVisualRepresentation();
ticketView.updateAllView();
ticketView.selectRow(ticketItemModifier.getTableRowNum() - 1);
break;
}
}
}
我想我的问题是我应该使用我的paint组件方法来更新修饰符中的项目数量。