001package jmri.jmrix.bidib.swing;
002
003import javax.swing.Icon;
004import jmri.jmrix.bidib.BiDiBSystemConnectionMemo;
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
014 * @author Matthew Harris Copyright (C) 2011
015 * @since 2.11.4
016 * @author Eckart Meyer Copyright (C) 2020
017 */
018public class BiDiBNamedPaneAction extends jmri.util.swing.JmriNamedPaneAction {
019
020    /**
021     * Enhanced constructor for placing the pane in various GUIs
022     * @param s Name
023     * @param wi Window context
024     * @param paneClass class to instantiate
025     * @param memo Source of stuff
026     */
027    public BiDiBNamedPaneAction(String s, WindowInterface wi, String paneClass, BiDiBSystemConnectionMemo memo) {
028        super(s, wi, paneClass);
029        this.memo = memo;
030    }
031
032    public BiDiBNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, BiDiBSystemConnectionMemo memo) {
033        super(s, i, wi, paneClass);
034        this.memo = memo;
035    }
036
037    BiDiBSystemConnectionMemo memo;
038
039    @Override
040    public JmriPanel makePanel() {
041        JmriPanel p = super.makePanel();
042        if (p == null) {
043            return null;
044        }
045
046        try {
047            ((BiDiBPanelInterface) 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 static final Logger log = LoggerFactory.getLogger(BiDiBNamedPaneAction.class);
057
058}