001package jmri.jmrit.logixng.actions.swing;
002
003import java.util.List;
004
005import javax.annotation.CheckForNull;
006import javax.annotation.Nonnull;
007import javax.swing.*;
008
009import jmri.InstanceManager;
010import jmri.jmrit.logixng.Base;
011import jmri.jmrit.logixng.DigitalActionManager;
012import jmri.jmrit.logixng.MaleSocket;
013import jmri.jmrit.logixng.actions.RunOnce;
014
015/**
016 * Configures an RunOnce object with a Swing JPanel.
017 *
018 * @author Daniel Bergqvist Copyright 2022
019 */
020public class RunOnceSwing extends AbstractDigitalActionSwing {
021
022    @Override
023    protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) {
024        if ((object != null) && !(object instanceof RunOnce)) {
025            throw new IllegalArgumentException("object must be an RunOnce but is a: "+object.getClass().getName());
026        }
027
028        panel = new JPanel();
029    }
030
031    /** {@inheritDoc} */
032    @Override
033    public boolean validate(@Nonnull List<String> errorMessages) {
034        return true;
035    }
036
037    /** {@inheritDoc} */
038    @Override
039    public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) {
040        RunOnce action = new RunOnce(systemName, userName);
041        updateObject(action);
042        return InstanceManager.getDefault(DigitalActionManager.class).registerAction(action);
043    }
044
045    /** {@inheritDoc} */
046    @Override
047    public void updateObject(@Nonnull Base object) {
048        if (!(object instanceof RunOnce)) {
049            throw new IllegalArgumentException("object must be an RunOnce but is a: "+object.getClass().getName());
050        }
051    }
052
053    /** {@inheritDoc} */
054    @Override
055    public String toString() {
056        return Bundle.getMessage("RunOnce_Short");
057    }
058
059    @Override
060    public void dispose() {
061    }
062
063}