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

lphystudio.core.valueeditor.BooleanValueEditor Maven / Gradle / Ivy

The newest version!
package lphystudio.core.valueeditor;

import lphy.core.model.Value;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class BooleanValueEditor extends JTextField {

    private Value value;

    public BooleanValueEditor(Value value)  {

        this.value = value;

        setText(value.value().toString());
        setColumns(12);


        getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                setValue(getText());
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                setValue(getText());

            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                setValue(getText());
            }

            void setValue(String text) {
                try {
                    Boolean n = Boolean.parseBoolean(getText());
                    value.setValue(n);
                    //message.setText("");
                } catch (NumberFormatException ne) {
                    //message.setText("'" + textField.getText() + "' is not a double.");
                }

            }
        });

        //add(message);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy