001package jmri.jmrix.mrc.swing;
002
003import javax.swing.Icon;
004import jmri.jmrix.mrc.MrcSystemConnectionMemo;
005import jmri.util.swing.JmriPanel;
006import jmri.util.swing.WindowInterface;
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009
010/**
011 * Action to create and load a JmriPanel from just its name.
012 *
013 * @author Bob Jacobsen Copyright (C) 2010 Copied from nce.swing
014 * @author Ken Cameron 2014
015 * @author Kevin Dickerson 2014
016 */
017public class MrcNamedPaneAction extends jmri.util.swing.JmriNamedPaneAction {
018
019    /**
020     * Enhanced constructor for placing the pane in various GUIs
021     * @param s human readable panel name
022     * @param wi window to contain panel
023     * @param paneClass class name for panel. must be subclass of JmriPanel
024     * @param memo system connection memo
025     */
026    public MrcNamedPaneAction(String s, WindowInterface wi, String paneClass, MrcSystemConnectionMemo memo) {
027        super(s, wi, paneClass);
028        this.memo = memo;
029    }
030
031    public MrcNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, MrcSystemConnectionMemo memo) {
032        super(s, i, wi, paneClass);
033        this.memo = memo;
034    }
035
036    MrcSystemConnectionMemo memo;
037
038    @Override
039    public JmriPanel makePanel() {
040        JmriPanel p = super.makePanel();
041        if (p == null) {
042            return null;
043        }
044
045        try {
046            ((MrcPanelInterface) p).initComponents(memo);
047            return p;
048        } catch (Exception ex) {
049            log.warn("could not init pane class: {}", paneClass, ex);
050        }
051
052        return p;
053    }
054
055    private final static Logger log = LoggerFactory.getLogger(MrcNamedPaneAction.class);
056}
057
058