001package jmri.jmrix.swing;
002
003import javax.swing.Icon;
004import jmri.jmrix.DefaultSystemConnectionMemo;
005import jmri.util.swing.JmriNamedPaneAction;
006import jmri.util.swing.WindowInterface;
007
008/**
009 * {@link JmriNamedPaneAction} that implements {@link SystemConnectionAction}.
010 * 
011 * @author Randall Wood Copyright 2020
012 * @param <M> the supported subclass of {@link jmri.SystemConnectionMemo}
013 */
014public abstract class SystemConnectionNamedPaneAction<M extends DefaultSystemConnectionMemo> extends JmriNamedPaneAction implements SystemConnectionAction<M> {
015
016    protected M memo;
017
018    public SystemConnectionNamedPaneAction(String s, String paneClass, M memo) {
019        super(s, paneClass);
020        this.memo = memo;
021    }
022
023    public SystemConnectionNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, M memo) {
024        super(s, i, wi, paneClass);
025        this.memo = memo;
026    }
027    
028    public SystemConnectionNamedPaneAction(String s, WindowInterface wi, String paneClass, M memo) {
029        super(s, wi, paneClass);
030        this.memo = memo;
031    }
032
033    /**
034     * {@inheritDoc}
035     */
036    @Override
037    public M getSystemConnectionMemo() {
038        return memo;
039    }
040
041    /**
042     * {@inheritDoc}
043     */
044    @Override
045    public void setSystemConnectionMemo(M memo) {
046        if (getSystemConnectionMemoClasses().stream().anyMatch(memo.getClass()::isAssignableFrom)) {
047            this.memo = memo;
048        } else {
049            throw new IllegalArgumentException(memo.getClass() + " is not valid for " + this.getClass());
050        }
051    }
052}