All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaxx.demo.component.swing.JComboBoxDemo Maven / Gradle / Ivy

There is a newer version: 3.0-alpha-6
Show newest version
package jaxx.demo.component.swing;

/*-
 * #%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.GridBagConstraints;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
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.Item;
import jaxx.runtime.swing.JAXXComboBox;
import jaxx.runtime.swing.Table;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.nuiton.i18n.I18n.n;
import static org.nuiton.i18n.I18n.t;

public class JComboBoxDemo extends DemoPanel {

    /*-----------------------------------------------------------------------*/
    /*--------------- Constants for all none public bindings  ---------------*/
    /*-----------------------------------------------------------------------*/

    private static final String BINDING_$JBUTTON0_TEXT = "$JButton0.text";
    private static final String BINDING_$JBUTTON1_TEXT = "$JButton1.text";

    /*-----------------------------------------------------------------------*/
    /*------------------------- Other static fields -------------------------*/
    /*-----------------------------------------------------------------------*/

    private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAI1Uz08TURCeVtpSigo0FAiooE08mGwF48FAEIE00tQfEQ/EXnzbfYEl293n7qysF+Of4J+gdy8m3jwZD549eDH+C8Z48Gqc97a7ZetC28O2nZnvm2+m3/TdT8h5LiwdsiDQXN9Gs8O1xp29vQf6IW/jNvfarinQcSF8ZbKQbUHJiOMewpVWU8JrXXhty+kIx+b2MfRqE8Y8fGFx74BzRLiQRLQ9r7Ybp1cD4bsRaywqjfXN71/Z18art1mAQJC6Eo2yOAjVm2SkCVnTQJiiTs9ZzWL2PslwTXuf9J6VsS2Led591uHP4CUUmpAXzCUyhMvDj6w4FD4QCKXqNu84D5nNresIV5VYgyJaO6LQvCNSoDWIU3c2nUDWC6EY8giF6mOmW5yws4lBQ5DKycpiDBitNppMV92m5EhBxK+ismg8rh2XlFFfhEspHaQ3oookuFhtbPqIjk2dyolOYThZHclalt8n+3LtWMJ0gmhAY8U1k0zmqzvIOyRpJmUYmRJ9pYpkqT+6EkVdmE8QkXW1nnV73sq0IOf6FKYfqvW/2x9RKvT5bJ/PJaHK/q2Uv3388aEembtAvadTS4/dJplOuI7gLpqy9fnQ2T6aVu0eE6stKHrcosNWh7uQImy3myZx1G9SwjUJ1+4y74AocoXvnz5Xnn49A9k6jFkOM+pM1u9AEQ9c2oJjGYG4vaEUjR+N0nNCakMYQR7Q5UytmbZl2nyRIZ2a7iNfD2gNCylriLXoxS9/yrvvN6JVZEja3InlvXXknkA+7KYuvXvEqZddEh73Dad3rGnnm5HvE6JrjmvqWUubdZQbJka3uBL48u2GEi4/3VQ85YE8MryMcG7NYMgWddM2yLTr6WyV4dhO0TM3FMOtUxjmh9hMruMY4d/OCYMMJokHOYHhIjH8AwF4zVzYBgAA";
    private static final Log log = LogFactory.getLog(JComboBoxDemo.class);
    private static final long serialVersionUID = 1L;

    /*-----------------------------------------------------------------------*/
    /*--------------------------- Internal states ---------------------------*/
    /*-----------------------------------------------------------------------*/

    private boolean allComponentsCreated;

    /*-----------------------------------------------------------------------*/
    /*------------------------ Protected components  ------------------------*/
    /*-----------------------------------------------------------------------*/

    protected JComboBox comboBox;
    protected JAXXComboBox jaxxComboBox;

    /*-----------------------------------------------------------------------*/
    /*------------------------- Private components  -------------------------*/
    /*-----------------------------------------------------------------------*/

    private JComboBoxDemo $DemoPanel0 = this;
    private Item $Item0;
    private Item $Item1;
    private Item $Item2;
    private JButton $JButton0;
    private JButton $JButton1;
    private JLabel $JLabel0;
    private JLabel $JLabel1;
    private Table $Table0;

    /*-----------------------------------------------------------------------*/
    /*---------------------- Raw body code from script ----------------------*/
    /*-----------------------------------------------------------------------*/

    private void $afterCompleteSetup() {
        jaxxComboBox.setSelectedIndex(0);
    }

    /*-----------------------------------------------------------------------*/
    /*---------------------------- Constructors  ----------------------------*/
    /*-----------------------------------------------------------------------*/

    public JComboBoxDemo(LayoutManager param0, boolean param1) {
        super(param0 ,param1);
        $initialize();
    }

    public JComboBoxDemo(JAXXContext param0, LayoutManager param1, boolean param2) {
        super(param0 ,param1 ,param2);
        $initialize();
    }

    public JComboBoxDemo(LayoutManager param0) {
        super(param0);
        $initialize();
    }

    public JComboBoxDemo(JAXXContext param0, LayoutManager param1) {
        super(param0 ,param1);
        $initialize();
    }

    public JComboBoxDemo() {
        $initialize();
    }

    public JComboBoxDemo(JAXXContext param0) {
        super(param0);
        $initialize();
    }

    public JComboBoxDemo(boolean param0) {
        super(param0);
        $initialize();
    }

    public JComboBoxDemo(JAXXContext param0, boolean param1) {
        super(param0 ,param1);
        $initialize();
    }

    /*-----------------------------------------------------------------------*/
    /*--------------------------- Statics methods ---------------------------*/
    /*-----------------------------------------------------------------------*/

    public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
        return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
    }

    /*-----------------------------------------------------------------------*/
    /*----------------------- Public acessor methods  -----------------------*/
    /*-----------------------------------------------------------------------*/

    public JComboBox getComboBox() {
        return comboBox;
    }

    public JAXXComboBox getJaxxComboBox() {
        return jaxxComboBox;
    }

    /*-----------------------------------------------------------------------*/
    /*--------------------- Protected acessors methods  ---------------------*/
    /*-----------------------------------------------------------------------*/

    protected Item get$Item0() {
        return $Item0;
    }

    protected Item get$Item1() {
        return $Item1;
    }

    protected Item get$Item2() {
        return $Item2;
    }

    protected JButton get$JButton0() {
        return $JButton0;
    }

    protected JButton get$JButton1() {
        return $JButton1;
    }

    protected JLabel get$JLabel0() {
        return $JLabel0;
    }

    protected JLabel get$JLabel1() {
        return $JLabel1;
    }

    protected Table get$Table0() {
        return $Table0;
    }

    /*-----------------------------------------------------------------------*/
    /*--------------------- Components creation methods ---------------------*/
    /*-----------------------------------------------------------------------*/

    protected void addChildrenToJaxxComboBox() {
        if (!allComponentsCreated) {
            return;
        }
        java.util.List jaxxComboBox$items = new java.util.ArrayList();
        jaxxComboBox$items.add($Item0);
        jaxxComboBox$items.add($Item1);
        jaxxComboBox$items.add($Item2);
        jaxxComboBox.setItems(jaxxComboBox$items);
    }

    protected void createComboBox() {
        $objectMap.put("comboBox", comboBox = new JComboBox());
        
        comboBox.setName("comboBox");
        comboBox.setEditable(true);
    }

    protected void createJaxxComboBox() {
        $objectMap.put("jaxxComboBox", jaxxComboBox = new JAXXComboBox());
        
        jaxxComboBox.setName("jaxxComboBox");
        jaxxComboBox.setEditable(true);
    }

    /*-----------------------------------------------------------------------*/
    /*------------------------ 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($JLabel0, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        $Table0.add(jaxxComboBox, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        $Table0.add($JButton0, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        $Table0.add($JLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        $Table0.add(comboBox, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        $Table0.add($JButton1, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, 10, 0, new Insets(3, 3, 3, 3), 0, 0));
        addChildrenToJaxxComboBox();
        
        // apply 2 data bindings
        JAXXUtil.applyDataBinding(this, $bindings.keySet());
        
        // apply 4 property setters
        $Item0.setValue(t("OK"));
        $Item1.setValue(t("Cancel"));
        $Item2.setValue(t("Help"));
        comboBox.setModel(new  DefaultComboBoxModel(new Object[]{n("OK"),n("Cancel"),n("Help")}));
        $afterCompleteSetup();
    }

    private void $initialize() {
        if (allComponentsCreated) {
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug(this);
        }
        $objectMap.put("$DemoPanel0", $DemoPanel0);
        // inline creation of $Table0
        $objectMap.put("$Table0", $Table0 = new Table());
        
        $Table0.setName("$Table0");
        // inline creation of $JLabel0
        $objectMap.put("$JLabel0", $JLabel0 = new JLabel());
        
        $JLabel0.setName("$JLabel0");
        $JLabel0.setText(t("Button label:"));
        createJaxxComboBox();
        // inline creation of $JButton0
        $objectMap.put("$JButton0", $JButton0 = new JButton());
        
        $JButton0.setName("$JButton0");
        // inline creation of $JLabel1
        $objectMap.put("$JLabel1", $JLabel1 = new JLabel());
        
        $JLabel1.setName("$JLabel1");
        $JLabel1.setText(t("Button label:"));
        createComboBox();
        // inline creation of $JButton1
        $objectMap.put("$JButton1", $JButton1 = new JButton());
        
        $JButton1.setName("$JButton1");
        // inline creation of $Item0
        $objectMap.put("$Item0", $Item0 = new Item("$Item0", null, "", true));
        // inline creation of $Item1
        $objectMap.put("$Item1", $Item1 = new Item("$Item1", null, "", false));
        // inline creation of $Item2
        $objectMap.put("$Item2", $Item2 = new Item("$Item2", null, "", false));
        // inline creation of $DemoPanel0
        setName("$DemoPanel0");
        
        // registers 2 data bindings
        $registerDefaultBindings();
        $completeSetup();
    }

    private void $registerDefaultBindings() {
        // register 2 data bindings
        registerDataBinding(new DefaultJAXXBinding(this, BINDING_$JBUTTON0_TEXT, true) {
        
            @Override
            public void applyDataBinding() {
                if (jaxxComboBox != null) {
                    $bindingSources.put("jaxxComboBox", jaxxComboBox);
                    jaxxComboBox.addItemListener( JAXXUtil.getEventListener(ItemListener.class, this, "$pr$u0"));
                }
            }
        
            @Override
            public void processDataBinding() {
                if (jaxxComboBox != null) {
                    $JButton0.setText(t(String.valueOf(jaxxComboBox.getSelectedItem())));
                }
            }
        
            @Override
            public void removeDataBinding() {
                if (jaxxComboBox != null) {
                    JAXXComboBox $target = (JAXXComboBox) $bindingSources.remove("jaxxComboBox");
                    if ($target != null) {
                        $target.removeItemListener( JAXXUtil.getEventListener(ItemListener.class, this, "$pr$u0"));
                    }
                }
            }
        
            public void $pr$u0(ItemEvent event) {
                if (log.isDebugEnabled()) {
                    log.debug(event);
                }
                propertyChange(null);
            }
        });
        registerDataBinding(new DefaultJAXXBinding(this, BINDING_$JBUTTON1_TEXT, true) {
        
            @Override
            public void applyDataBinding() {
                if (comboBox != null) {
                    $bindingSources.put("comboBox", comboBox);
                    comboBox.addItemListener( JAXXUtil.getEventListener(ItemListener.class, this, "$pr$u1"));
                }
            }
        
            @Override
            public void processDataBinding() {
                if (comboBox != null) {
                    $JButton1.setText(t(comboBox.getSelectedItem()+""));
                }
            }
        
            @Override
            public void removeDataBinding() {
                if (comboBox != null) {
                    JComboBox $target = (JComboBox) $bindingSources.remove("comboBox");
                    if ($target != null) {
                        $target.removeItemListener( JAXXUtil.getEventListener(ItemListener.class, this, "$pr$u1"));
                    }
                }
            }
        
            public void $pr$u1(ItemEvent event) {
                if (log.isDebugEnabled()) {
                    log.debug(event);
                }
                propertyChange(null);
            }
        });
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy