001package jmri.jmrix.tams.swing;
002
003import java.util.Arrays;
004import java.util.HashSet;
005import java.util.Set;
006import javax.swing.Icon;
007import jmri.SystemConnectionMemo;
008import jmri.jmrix.swing.SystemConnectionAction;
009import jmri.jmrix.tams.TamsSystemConnectionMemo;
010import jmri.util.swing.JmriNamedPaneAction;
011import jmri.util.swing.JmriPanel;
012import jmri.util.swing.WindowInterface;
013
014/**
015 * Action to create and load a JmriPanel from just its name.
016 *
017 * Based on work by Bob Jacobsen
018 *
019 * @author Kevin Dickerson Copyright (C) 2012
020 */
021public class TamsNamedPaneAction extends JmriNamedPaneAction implements SystemConnectionAction<TamsSystemConnectionMemo> {
022
023    /**
024     * Enhanced constructor for placing the pane in various GUIs.
025     * @param s action name.
026     * @param wi window interface in use.
027     * @param paneClass pane class.
028     * @param memo system connection.
029     */
030    public TamsNamedPaneAction(String s, WindowInterface wi, String paneClass, TamsSystemConnectionMemo memo) {
031        super(s, wi, paneClass);
032        this.memo = memo;
033    }
034
035    /**
036     * Enhanced constructor for placing the pane in various GUIs.
037     * @param s action name.
038     * @param i icon to use
039     * @param wi window interface in use.
040     * @param paneClass pane class.
041     * @param memo system connection.
042     */
043    public TamsNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, TamsSystemConnectionMemo memo) {
044        super(s, i, wi, paneClass);
045        this.memo = memo;
046    }
047
048    TamsSystemConnectionMemo memo;
049
050    @Override
051    public JmriPanel makePanel() {
052        JmriPanel p = super.makePanel();
053        if (p == null) {
054            return null;
055        }
056
057        ((TamsPanelInterface) p).initComponents(memo);
058        return p;
059    }
060
061    @Override
062    public TamsSystemConnectionMemo getSystemConnectionMemo() {
063        return memo;
064    }
065
066    @Override
067    public void setSystemConnectionMemo(TamsSystemConnectionMemo memo) {
068        this.memo = memo;
069    }
070
071    @Override
072    public Set<Class<? extends SystemConnectionMemo>> getSystemConnectionMemoClasses() {
073        return new HashSet<>(Arrays.asList(TamsSystemConnectionMemo.class));
074    }
075
076    // private final static Logger log = LoggerFactory.getLogger(TamsNamedPaneAction.class);
077}