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

jaxx.demo.component.swing.JPasswordFieldDemo 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 - 2018 Ultreia.io
 * %%
 * 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.LayoutManager;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
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.HBox;
import jaxx.runtime.swing.VBox;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.nuiton.i18n.I18n.t;

public class JPasswordFieldDemo extends DemoPanel {

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

    private static final String BINDING_$JLABEL1_TEXT = "$JLabel1.text";

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

    private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAKVUTU9TQRS9rbRQPkSoIihGFKIxMa8aNyYQBCENkqJEEkPsxmlnQodMZ8aZefBwYfwJ/gTduzFx58q4cO3CjfEvGOPCrXFm+voFD21iF/PaO+ecOXfeuX3zHTJawaVdFEWBCrmhdRKsL29vP6jskqpZJbqqqDRCQeOTSkO6DEO4VdcGZsslRy/E9MKKqEvBCe9gz5dgUJsDRnSNEGPgQjejqnVhq7U9H8lQNVVbppJUX/38kX6JX7xOA0TSusvaVmb+xWp30leCNMUGxu1Je6jAEN+xNhTlO9bviKutMKT1fVQnT+E59JcgK5GyYgYu996y1/D8SBoYmlsldbGJOGE3DFz3ZrGtBNWmRKD3rYNgfdPS9oXCRUoYdiQpvUzWQHbu0V0RWf7ZrmYbRLflcLkO+Nrx8LUYPtyCD8ytl1DF+xt3lxA1HfmqA422sTJ2aeBcF7bL/SFOrH/T/T4dn63gfJc5G4mgHYn2O0uVIaNCWzYwWT6aood2q5GfyUP5cYJ+9/dE/sv7b++KnaE5kwjtyLx9mVIJSZSh7ujRRmJCQ1lhA8n5MuQ0YXZg/EBMJxjbiretOXvemKMHjh6sIV2zEpn+rx8+Tjz5fALSRRhkAuEicvh7kDM1ZW9BMBzJO0ve0fD+gF1POW8G8jWh6DPBDWLLjO7wug/o+ALljHIyg4xNdCU0ZDGytzKdcCsta5Xcp1/5rbdLzZtJWadTx8Lbt5N5DNnGaX6g4llJHKAhqUmIRXsmkqYk5Z4jMs77Rb/OJrU+tudeSLWjcQe9EoXucdV34L5d61lwgLlgFoUycHIBI4NmKpRjG+jFZM18D5p9hkR/89WLxhimWjJ0QPAGt/8EnFb/S9CVb7vlVrLClFX4A6Oq+jMaBgAA";
    private static final Log log = LogFactory.getLog(JPasswordFieldDemo.class);
    private static final long serialVersionUID = 1L;

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

    private boolean allComponentsCreated;

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

    protected JPasswordField password;

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

    private JPasswordFieldDemo $DemoPanel0 = this;
    private HBox $HBox0;
    private JLabel $JLabel0;
    private JLabel $JLabel1;
    private VBox $VBox0;

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

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

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

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

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

    public JPasswordFieldDemo() {
        $initialize();
    }

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

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

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

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

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

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

    public JPasswordField getPassword() {
        return password;
    }

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

    protected HBox get$HBox0() {
        return $HBox0;
    }

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

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

    protected VBox get$VBox0() {
        return $VBox0;
    }

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

    protected void createPassword() {
        $objectMap.put("password", password = new JPasswordField());
        
        password.setName("password");
        password.setColumns(15);
    }

    /*-----------------------------------------------------------------------*/
    /*------------------------ Internal jaxx methods ------------------------*/
    /*-----------------------------------------------------------------------*/

    private void $completeSetup() {
        allComponentsCreated = true;
        if (log.isDebugEnabled()) {
            log.debug(this);
        }
        // inline complete setup of $DemoPanel0
        add($VBox0);
        // inline complete setup of $VBox0
        $VBox0.add($HBox0);
        $VBox0.add($JLabel1);
        // inline complete setup of $HBox0
        $HBox0.add($JLabel0);
        $HBox0.add(password);
        
        // apply 1 data bindings
        JAXXUtil.applyDataBinding(this, $bindings.keySet());
        
        // apply 1 property setters
        $JLabel0.setLabelFor(password);
    }

    private void $initialize() {
        if (allComponentsCreated) {
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug(this);
        }
        $objectMap.put("$DemoPanel0", $DemoPanel0);
        // inline creation of $VBox0
        $objectMap.put("$VBox0", $VBox0 = new VBox());
        
        $VBox0.setName("$VBox0");
        $VBox0.setHorizontalAlignment(0);
        $VBox0.setVerticalAlignment(0);
        // inline creation of $HBox0
        $objectMap.put("$HBox0", $HBox0 = new HBox());
        
        $HBox0.setName("$HBox0");
        // inline creation of $JLabel0
        $objectMap.put("$JLabel0", $JLabel0 = new JLabel());
        
        $JLabel0.setName("$JLabel0");
        $JLabel0.setText(t("Password:"));
        $JLabel0.setDisplayedMnemonic(80);
        createPassword();
        // inline creation of $JLabel1
        $objectMap.put("$JLabel1", $JLabel1 = new JLabel());
        
        $JLabel1.setName("$JLabel1");
        // inline creation of $DemoPanel0
        setName("$DemoPanel0");
        
        // registers 1 data bindings
        $registerDefaultBindings();
        $completeSetup();
    }

    private void $registerDefaultBindings() {
        // register 1 data bindings
        registerDataBinding(new DefaultJAXXBinding(this, BINDING_$JLABEL1_TEXT, true) {
        
            @Override
            public void applyDataBinding() {
                if (password != null) {
                    $bindingSources.put("password.getDocument()", password.getDocument());
                    password.getDocument().addDocumentListener( JAXXUtil.getEventListener(DocumentListener.class, this, "$pr$u0"));
                    password.addPropertyChangeListener("document", JAXXUtil.getDataBindingUpdateListener(jaxx.demo.component.swing.JPasswordFieldDemo.this, BINDING_$JLABEL1_TEXT));
                }
            }
        
            @Override
            public void processDataBinding() {
                if (password != null) {
                    $JLabel1.setText(t("You entered: " + (new String(password.getPassword()))));
                }
            }
        
            @Override
            public void removeDataBinding() {
                if (password != null) {
                    Document $target = (Document) $bindingSources.remove("password.getDocument()");
                    if ($target != null) {
                        $target.removeDocumentListener( JAXXUtil.getEventListener(DocumentListener.class, this, "$pr$u0"));
                    }
                    password.removePropertyChangeListener("document", JAXXUtil.getDataBindingUpdateListener(jaxx.demo.component.swing.JPasswordFieldDemo.this, BINDING_$JLABEL1_TEXT));
                }
            }
        
            public void $pr$u0(DocumentEvent event) {
                if (log.isDebugEnabled()) {
                    log.debug(event);
                }
                propertyChange(null);
            }
        });
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy