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