001package jmri.jmrix.can.swing;
002
003import javax.swing.Icon;
004import jmri.jmrix.can.CanSystemConnectionMemo;
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) 2012
014 */
015public class CanNamedPaneAction extends jmri.util.swing.JmriNamedPaneAction {
016
017    /**
018     * Enhanced constructor for placing the pane in various GUIs.
019     * @param s Window Name
020     * @param wi JmriJFrameInterface
021     * @param paneClass Name of class to open
022     * @param memo System Connection
023     */
024    public CanNamedPaneAction(String s, WindowInterface wi, String paneClass, CanSystemConnectionMemo memo) {
025        super(s, wi, paneClass);
026        this.memo = memo;
027    }
028
029    /**
030     * Enhanced constructor for placing the pane in various GUIs.
031     * @param s Window Name
032     * @param i Icon to display
033     * @param wi JmriJFrameInterface
034     * @param paneClass Name of class to open
035     * @param memo System Connection
036     */
037    public CanNamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, CanSystemConnectionMemo memo) {
038        super(s, i, wi, paneClass);
039        this.memo = memo;
040    }
041
042    CanSystemConnectionMemo memo;
043
044    /**
045     * Makes Panel and calls initComponents
046     * {@inheritDoc}
047     */
048    @Override
049    public JmriPanel makePanel() {
050        JmriPanel p = super.makePanel();
051        if (p == null) {
052            return null;
053        }
054
055        try {
056            ((CanPanelInterface) p).initComponents(memo);
057            return p;
058        } catch (Exception ex) {
059            log.warn("could not init pane class: {}", paneClass, ex);
060        }
061
062        return p;
063    }
064
065    private final static Logger log = LoggerFactory.getLogger(CanNamedPaneAction.class);
066
067}