tfw.swing.event.SetEnabledFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tfw Show documentation
Show all versions of tfw Show documentation
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));
}
}
}