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

tfw.swing.event.SetEnabledFactory Maven / Gradle / Ivy

Go to download

The FrameWork for building highly scalable and maintainable applications

The newest version!
package tfw.swing.event;

import java.awt.Component;
import java.awt.EventQueue;
import tfw.check.Argument;
import tfw.tsm.Commit;
import tfw.tsm.Initiator;
import tfw.tsm.ecd.BooleanECD;
import tfw.tsm.ecd.ObjectECD;

public class SetEnabledFactory {
    private SetEnabledFactory() {}

    public static Commit create(String name, BooleanECD enabledECD, Component component, Initiator[] initiators) {
        Argument.assertNotNull(name, "name");
        Argument.assertNotNull(enabledECD, "enabledECD");
        Argument.assertNotNull(component, "component");

        return new ComponentSetEnabledCommit(name, enabledECD, component, initiators);
    }

    private static class ComponentSetEnabledCommit extends Commit {
        private final BooleanECD enabledECD;
        private final Component component;

        public ComponentSetEnabledCommit(
                String name, BooleanECD enabledECD, Component component, Initiator[] initiators) {
            super("SetEnabledCommit[" + name + "]", new ObjectECD[] {enabledECD}, null, initiators);

            this.enabledECD = enabledECD;
            this.component = component;
        }

        @Override
        protected void commit() {
            final boolean enabled = (Boolean) get(enabledECD);

            EventQueue.invokeLater(() -> component.setEnabled(enabled));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy