001package jmri.jmrix.nce.swing;
002
003import java.util.Arrays;
004import java.util.HashSet;
005import java.util.Set;
006import javax.swing.Icon;
007import jmri.SystemConnectionMemo;
008import jmri.jmrix.nce.NceSystemConnectionMemo;
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 Copied from LocoNet
019 * @author kcameron
020 */
021public class NceNamedPaneAction extends SystemConnectionNamedPaneAction<NceSystemConnectionMemo> {
022
023    /**
024     * Enhanced constructor for placing the pane in various GUIs.
025     *
026     * @param s Human readable panel name
027     * @param wi window to place the new panel
028     * @param paneClass name of panel class, should be subclass of JmriPanel
029     * @param memo system connection memo
030     */
031    public NceNamedPaneAction(String s, WindowInterface wi, String paneClass, NceSystemConnectionMemo memo) {
032        super(s, wi, paneClass, memo);
033    }
034
035    public NceNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, NceSystemConnectionMemo memo) {
036        super(s, i, wi, paneClass, 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            ((NcePanelInterface) p).initComponents(memo);
048            return p;
049        } catch (Exception ex) {
050            log.warn("could not init pane class: {}", paneClass, ex); // NOI18N
051        }
052
053        return p;
054    }
055
056    @Override
057    public Set<Class<? extends SystemConnectionMemo>> getSystemConnectionMemoClasses() {
058        return new HashSet<>(Arrays.asList(NceSystemConnectionMemo.class));
059    }
060
061    private final static Logger log = LoggerFactory.getLogger(NceNamedPaneAction.class);
062
063}