Package nodebox.client.port

Source Code of nodebox.client.port.ToggleControl

package nodebox.client.port;

import nodebox.node.Port;
import nodebox.ui.NButton;

import java.awt.*;

public class ToggleControl extends AbstractPortControl {

    private NButton checkBox;

    public ToggleControl(String nodePath, Port port) {
        super(nodePath, port);
        setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
        checkBox = new NButton(NButton.Mode.CHECK, port.getDisplayLabel());
        checkBox.setActionMethod(this, "toggle");
        add(checkBox);
        setValueForControl(port.getValue());
        setPreferredSize(new Dimension(120, 30));
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        checkBox.setEnabled(enabled);
    }

    public void setValueForControl(Object v) {
        if (v == null) return;
        boolean value = (Boolean) v;
        checkBox.setChecked(value);
    }

    public void toggle() {
        setPortValue(checkBox.isChecked());
    }

}
TOP

Related Classes of nodebox.client.port.ToggleControl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.