001package jmri.jmrix.ecos.swing;
002
003import java.util.Arrays;
004import java.util.HashSet;
005import java.util.Set;
006import javax.swing.Icon;
007import jmri.SystemConnectionMemo;
008import jmri.jmrix.ecos.EcosSystemConnectionMemo;
009import jmri.jmrix.swing.SystemConnectionNamedPaneAction;
010import jmri.util.swing.JmriPanel;
011import jmri.util.swing.WindowInterface;
012import org.slf4j.Logger;
013import org.slf4j.LoggerFactory;
014
015/**
016 * Action to create and load a JmriPanel from just its name.
017 *
018 * @author Bob Jacobsen Copyright (C) 2010
019 */
020public class EcosNamedPaneAction extends SystemConnectionNamedPaneAction<EcosSystemConnectionMemo> {
021
022    /**
023     * Enhanced constructor for placing the pane in various GUIs.
024     * @param s action title string.
025     * @param wi window interface.
026     * @param paneClass pane class string.
027     * @param memo system connection.
028     */
029    public EcosNamedPaneAction(String s, WindowInterface wi, String paneClass, EcosSystemConnectionMemo memo) {
030        super(s, wi, paneClass, memo);
031        this.memo = memo;
032    }
033
034    public EcosNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, EcosSystemConnectionMemo memo) {
035        super(s, i, wi, paneClass, memo);
036        this.memo = memo;
037    }
038
039    @Override
040    public JmriPanel makePanel() {
041        JmriPanel p = super.makePanel();
042        if (p == null) {
043            return null;
044        }
045
046        try {
047            ((EcosPanelInterface) p).initComponents(memo);
048            return p;
049        } catch (Exception ex) {
050            log.warn("could not init pane class: {}", paneClass, ex);
051        }
052
053        return p;
054    }
055
056    private final static Logger log = LoggerFactory.getLogger(EcosNamedPaneAction.class);
057
058    @Override
059    public Set<Class<? extends SystemConnectionMemo>> getSystemConnectionMemoClasses() {
060        return new HashSet<>(Arrays.asList(EcosSystemConnectionMemo.class));
061    }
062
063}