jaxx.demo.fun.CalculatorDemo Maven / Gradle / Ivy
package jaxx.demo.fun;
/*-
* #%L
* JAXX :: Demo
* %%
* Copyright (C) 2008 - 2017 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import jaxx.demo.DemoPanel;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObjectDescriptor;
import jaxx.runtime.JAXXUtil;
import jaxx.runtime.binding.DefaultJAXXBinding;
import jaxx.runtime.swing.Table;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.nuiton.i18n.I18n.t;
public class CalculatorDemo extends DemoPanel {
/*-----------------------------------------------------------------------*/
/*------------------ Constants for all public bindings ------------------*/
/*-----------------------------------------------------------------------*/
public static final String BINDING_DISPLAY_TEXT = "display.text";
/*-----------------------------------------------------------------------*/
/*------------------------- Other static fields -------------------------*/
/*-----------------------------------------------------------------------*/
private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAKWUTU8TQRjHp4UWCipqI6CCKUI8mS2iKKYEQZAoKWqEA7HGOLs7liHT3WFnFpaL8SP4EfTuxcSbJ+PBswcvxq9gjAevxmemL0t1uyXZHnabeZ7/73nJzv/tD5QRHprYwUFgeL4jaY0Ya0tbWw/MHWLJFSIsj3Lpeqj+S6VRuoIG7da5kGiyUlbyYkNeXHZr3HWIc0hdKqMBIQ8YEduESInG2xWWEMWNVrgUcN9rUltNRVFf//qZfmW/fJNGKODQ3QiMUuimCifpLaM0tSU6DZX2cJFhpwpteNSpQr/H1dkyw0LcxzWyi16gvjLKcuwBTKKLRx9ZM7Q+4BINTq2QmvsQO4RNSzSmm7XhxHjuO8YyZpbPMKhVEudalpUoS5wqdYhEFzrl39EJoaJvahObjECJ0bZ9iH2YztAxlZkLBTYVnOED2IYaPGhkrpWxSZjKGWqlpiyJ8m1Jt30pXUdnSZSxGMFeMzlt6UIjkcEs2fUxE4cT+l1OPDVRC2DfaAPYtEplGJyLC97sHOzlzO9W+FocezYueL1zsF/4pvSwJbsUvxLHn4kLXo0pXvOZpJwddCk+HbM4QatOrLzHdmVnfdame9Qm0QQPnW/7XMEYjNAYwpubqqCM58MxfN+V/73kEYTqLjL6j4sooI7+Gc5//fD9/WrTOvJQ+0xk6iHngyvNPdWspKr0UN03fElZcR3zUgXlBGFgm9oWxyIa22iEoTmod0rJDSU37mKxDYhM37ePn4affelB6VU0wFxsr2KVfw/l5LYHW3CZHfBbi7qjY/v98DypeoO1wt114RqiE/M2lrhgUseGu7kQwBLGIpbQ6sTMff6d33i32FxECho72zE9XEbmMcpSh4HraBdtGGSkaw5yQXzbDY0wyhpT6j3AGxa2qZ9bUZP2ShLo76sS+Or1RDet/j3VjHxXhjo2wejm6/0XsATTN31JFqKJw0cjqkc1mnAuMWE8MaGQmDCZmHApMeFyYkIxMWEmMWE2MWEuMaGUmLCQmLCUmLCSmLCWmLAOhL+ohMxISQsAAA==";
private static final Log log = LogFactory.getLog(CalculatorDemo.class);
private static final long serialVersionUID = 1L;
/*-----------------------------------------------------------------------*/
/*--------------------------- Internal states ---------------------------*/
/*-----------------------------------------------------------------------*/
private boolean allComponentsCreated;
/*-----------------------------------------------------------------------*/
/*------------------------ Protected components ------------------------*/
/*-----------------------------------------------------------------------*/
protected JButton c;
protected JButton ce;
protected JButton d0;
protected JButton d1;
protected JButton d2;
protected JButton d3;
protected JButton d4;
protected JButton d5;
protected JButton d6;
protected JButton d7;
protected JButton d8;
protected JButton d9;
protected JLabel display;
protected JButton divide;
protected JButton dot;
protected CalculatorEngine engine;
protected JButton equals;
protected JButton multiply;
protected JButton plus;
protected JButton sign;
protected JButton subtract;
/*-----------------------------------------------------------------------*/
/*------------------------- Private components -------------------------*/
/*-----------------------------------------------------------------------*/
private CalculatorDemo $DemoPanel0 = this;
private Table $Table0;
/*-----------------------------------------------------------------------*/
/*---------------------- Raw body code from script ----------------------*/
/*-----------------------------------------------------------------------*/
@Override
protected String[] getSources() {
return addDefaultSources( "CalculatorEngine.java" );
}
/*-----------------------------------------------------------------------*/
/*---------------------------- Constructors ----------------------------*/
/*-----------------------------------------------------------------------*/
public CalculatorDemo(LayoutManager param0, boolean param1) {
super(param0 ,param1);
$initialize();
}
public CalculatorDemo(JAXXContext param0, LayoutManager param1, boolean param2) {
super(param0 ,param1 ,param2);
$initialize();
}
public CalculatorDemo(LayoutManager param0) {
super(param0);
$initialize();
}
public CalculatorDemo(JAXXContext param0, LayoutManager param1) {
super(param0 ,param1);
$initialize();
}
public CalculatorDemo() {
$initialize();
}
public CalculatorDemo(JAXXContext param0) {
super(param0);
$initialize();
}
public CalculatorDemo(boolean param0) {
super(param0);
$initialize();
}
public CalculatorDemo(JAXXContext param0, boolean param1) {
super(param0 ,param1);
$initialize();
}
/*-----------------------------------------------------------------------*/
/*--------------------------- Statics methods ---------------------------*/
/*-----------------------------------------------------------------------*/
public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
}
/*-----------------------------------------------------------------------*/
/*---------------------------- Event methods ----------------------------*/
/*-----------------------------------------------------------------------*/
public void doActionPerformed__on__c(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.clear();
}
public void doActionPerformed__on__ce(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.clearEntry();
}
public void doActionPerformed__on__d0(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(0);
}
public void doActionPerformed__on__d1(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(1);
}
public void doActionPerformed__on__d2(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(2);
}
public void doActionPerformed__on__d3(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(3);
}
public void doActionPerformed__on__d4(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(4);
}
public void doActionPerformed__on__d5(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(5);
}
public void doActionPerformed__on__d6(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(6);
}
public void doActionPerformed__on__d7(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(7);
}
public void doActionPerformed__on__d8(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(8);
}
public void doActionPerformed__on__d9(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.digit(9);
}
public void doActionPerformed__on__divide(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.divide();
}
public void doActionPerformed__on__dot(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.dot();
}
public void doActionPerformed__on__equals(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.equal();
}
public void doActionPerformed__on__multiply(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.multiply();
}
public void doActionPerformed__on__plus(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.add();
}
public void doActionPerformed__on__sign(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.toggleSign();
}
public void doActionPerformed__on__subtract(ActionEvent event) {
if (log.isDebugEnabled()) {
log.debug(event);
}
engine.subtract();
}
/*-----------------------------------------------------------------------*/
/*----------------------- Public acessor methods -----------------------*/
/*-----------------------------------------------------------------------*/
public JButton getC() {
return c;
}
public JButton getCe() {
return ce;
}
public JButton getD0() {
return d0;
}
public JButton getD1() {
return d1;
}
public JButton getD2() {
return d2;
}
public JButton getD3() {
return d3;
}
public JButton getD4() {
return d4;
}
public JButton getD5() {
return d5;
}
public JButton getD6() {
return d6;
}
public JButton getD7() {
return d7;
}
public JButton getD8() {
return d8;
}
public JButton getD9() {
return d9;
}
public JLabel getDisplay() {
return display;
}
public JButton getDivide() {
return divide;
}
public JButton getDot() {
return dot;
}
public CalculatorEngine getEngine() {
return engine;
}
public JButton getEquals() {
return equals;
}
public JButton getMultiply() {
return multiply;
}
public JButton getPlus() {
return plus;
}
public JButton getSign() {
return sign;
}
public JButton getSubtract() {
return subtract;
}
/*-----------------------------------------------------------------------*/
/*--------------------- Protected acessors methods ---------------------*/
/*-----------------------------------------------------------------------*/
protected Table get$Table0() {
return $Table0;
}
/*-----------------------------------------------------------------------*/
/*--------------------- Components creation methods ---------------------*/
/*-----------------------------------------------------------------------*/
protected void createC() {
$objectMap.put("c", c = new JButton());
c.setName("c");
c.setText(t("C"));
c.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__c"));
}
protected void createCe() {
$objectMap.put("ce", ce = new JButton());
ce.setName("ce");
ce.setText(t("CE"));
ce.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__ce"));
}
protected void createD0() {
$objectMap.put("d0", d0 = new JButton());
d0.setName("d0");
d0.setText(t("0"));
d0.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d0"));
}
protected void createD1() {
$objectMap.put("d1", d1 = new JButton());
d1.setName("d1");
d1.setText(t("1"));
d1.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d1"));
}
protected void createD2() {
$objectMap.put("d2", d2 = new JButton());
d2.setName("d2");
d2.setText(t("2"));
d2.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d2"));
}
protected void createD3() {
$objectMap.put("d3", d3 = new JButton());
d3.setName("d3");
d3.setText(t("3"));
d3.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d3"));
}
protected void createD4() {
$objectMap.put("d4", d4 = new JButton());
d4.setName("d4");
d4.setText(t("4"));
d4.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d4"));
}
protected void createD5() {
$objectMap.put("d5", d5 = new JButton());
d5.setName("d5");
d5.setText(t("5"));
d5.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d5"));
}
protected void createD6() {
$objectMap.put("d6", d6 = new JButton());
d6.setName("d6");
d6.setText(t("6"));
d6.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d6"));
}
protected void createD7() {
$objectMap.put("d7", d7 = new JButton());
d7.setName("d7");
d7.setText(t("7"));
d7.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d7"));
}
protected void createD8() {
$objectMap.put("d8", d8 = new JButton());
d8.setName("d8");
d8.setText(t("8"));
d8.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d8"));
}
protected void createD9() {
$objectMap.put("d9", d9 = new JButton());
d9.setName("d9");
d9.setText(t("9"));
d9.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__d9"));
}
protected void createDisplay() {
$objectMap.put("display", display = new JLabel());
display.setName("display");
}
protected void createDivide() {
$objectMap.put("divide", divide = new JButton());
divide.setName("divide");
divide.setText(t("\u00f7"));
divide.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__divide"));
}
protected void createDot() {
$objectMap.put("dot", dot = new JButton());
dot.setName("dot");
dot.setText(t("."));
dot.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__dot"));
}
protected void createEngine() {
$objectMap.put("engine", engine = new CalculatorEngine());
}
protected void createEquals() {
$objectMap.put("equals", equals = new JButton());
equals.setName("equals");
equals.setText(t("="));
equals.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__equals"));
}
protected void createMultiply() {
$objectMap.put("multiply", multiply = new JButton());
multiply.setName("multiply");
multiply.setText(t("x"));
multiply.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__multiply"));
}
protected void createPlus() {
$objectMap.put("plus", plus = new JButton());
plus.setName("plus");
plus.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__plus"));
}
protected void createSign() {
$objectMap.put("sign", sign = new JButton());
sign.setName("sign");
sign.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__sign"));
}
protected void createSubtract() {
$objectMap.put("subtract", subtract = new JButton());
subtract.setName("subtract");
subtract.setText(t("-"));
subtract.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__subtract"));
}
/*-----------------------------------------------------------------------*/
/*------------------------ Internal jaxx methods ------------------------*/
/*-----------------------------------------------------------------------*/
private void $completeSetup() {
allComponentsCreated = true;
if (log.isDebugEnabled()) {
log.debug(this);
}
// inline complete setup of $DemoPanel0
add($Table0);
// inline complete setup of $Table0
$Table0.add(display, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(c, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(ce, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(equals, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d7, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d8, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d9, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(plus, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d5, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d6, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(subtract, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d1, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d2, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d3, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(multiply, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(d0, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(sign, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(dot, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
$Table0.add(divide, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
// apply 1 data bindings
JAXXUtil.applyDataBinding(this, $bindings.keySet());
}
private void $initialize() {
if (allComponentsCreated) {
return;
}
if (log.isDebugEnabled()) {
log.debug(this);
}
$objectMap.put("$DemoPanel0", $DemoPanel0);
createEngine();
// inline creation of $Table0
$objectMap.put("$Table0", $Table0 = new Table());
$Table0.setName("$Table0");
createDisplay();
createC();
createCe();
createEquals();
createD7();
createD8();
createD9();
createPlus();
createD4();
createD5();
createD6();
createSubtract();
createD1();
createD2();
createD3();
createMultiply();
createD0();
createSign();
createDot();
createDivide();
// inline creation of $DemoPanel0
setName("$DemoPanel0");
setLayout(new BorderLayout());
plus.setText("+");sign.setText("+/-");// registers 1 data bindings
$registerDefaultBindings();
$completeSetup();
}
private void $registerDefaultBindings() {
// register 1 data bindings
registerDataBinding(new DefaultJAXXBinding(this, BINDING_DISPLAY_TEXT, true) {
@Override
public void applyDataBinding() {
if (engine != null) {
engine.addPropertyChangeListener("displayText", this);
}
}
@Override
public void processDataBinding() {
if (engine != null) {
display.setText(t(engine.getDisplayText()));
}
}
@Override
public void removeDataBinding() {
if (engine != null) {
engine.removePropertyChangeListener("displayText", this);
}
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy