001package jmri.jmrix.zimo.swing; 002 003import java.util.Arrays; 004import java.util.HashSet; 005import java.util.Set; 006import javax.swing.Icon; 007import jmri.SystemConnectionMemo; 008import jmri.jmrix.swing.SystemConnectionAction; 009import jmri.jmrix.zimo.Mx1SystemConnectionMemo; 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 nce.swing 019 * @author Ken Cameron 2014 020 * @author Kevin Dickerson 2014 021 */ 022public class Mx1NamedPaneAction extends jmri.util.swing.JmriNamedPaneAction implements SystemConnectionAction<Mx1SystemConnectionMemo> { 023 024 /** 025 * Create a Mx1NamedPane associated with the given window. 026 * 027 * @param s the name of the panel 028 * @param wi the window to associate the pane with 029 * @param paneClass the class to use for the panel 030 * @param memo the MX1 connection 031 */ 032 public Mx1NamedPaneAction(String s, WindowInterface wi, String paneClass, Mx1SystemConnectionMemo memo) { 033 super(s, wi, paneClass); 034 this.memo = memo; 035 } 036 037 public Mx1NamedPaneAction(String s, Icon i, WindowInterface wi, String paneClass, Mx1SystemConnectionMemo memo) { 038 super(s, i, wi, paneClass); 039 this.memo = memo; 040 } 041 042 Mx1SystemConnectionMemo memo; 043 044 @Override 045 public JmriPanel makePanel() { 046 JmriPanel p = super.makePanel(); 047 if (p == null) { 048 return null; 049 } 050 051 try { 052 ((Mx1PanelInterface) p).initComponents(memo); 053 return p; 054 } catch (Exception ex) { 055 log.warn("could not init pane class: {} due to {}", paneClass, ex, ex); 056 } 057 058 return p; 059 } 060 061 @Override 062 public Mx1SystemConnectionMemo getSystemConnectionMemo() { 063 return memo; 064 } 065 066 @Override 067 public void setSystemConnectionMemo(Mx1SystemConnectionMemo memo) { 068 this.memo = memo; 069 } 070 071 @Override 072 public Set<Class<? extends SystemConnectionMemo>> getSystemConnectionMemoClasses() { 073 return new HashSet<>(Arrays.asList(Mx1SystemConnectionMemo.class)); 074 } 075 076 private final static Logger log = LoggerFactory.getLogger(Mx1NamedPaneAction.class); 077}