001package jmri.jmrix.lenz.swing; 002 003import java.util.Arrays; 004import java.util.HashSet; 005import java.util.Set; 006import javax.annotation.CheckForNull; 007import javax.annotation.Nonnull; 008import javax.swing.AbstractAction; 009import jmri.SystemConnectionMemo; 010import jmri.jmrix.lenz.XNetSystemConnectionMemo; 011 012/** 013 * Abstract action to create and register a swing object for XpressNet systems. 014 * 015 * @author Paul Bender Copyright (C) 2016 016 */ 017public abstract class AbstractXPressNetAction extends AbstractAction implements jmri.jmrix.swing.SystemConnectionAction<XNetSystemConnectionMemo> { 018 019 protected XNetSystemConnectionMemo _memo; 020 021 public AbstractXPressNetAction(String s, jmri.jmrix.lenz.XNetSystemConnectionMemo memo) { 022 super(s); 023 _memo = memo; 024 } 025 026 public AbstractXPressNetAction(jmri.jmrix.lenz.XNetSystemConnectionMemo memo) { 027 this(Bundle.getMessage("MenuItemLI101ConfigurationManager"), memo); 028 } 029 030 /** 031 * Get the {@link SystemConnectionMemo} this action is bound to. 032 * 033 * @return the SystemConnectionMemo or null if not bound 034 */ 035 @CheckForNull 036 @Override 037 public XNetSystemConnectionMemo getSystemConnectionMemo(){ 038 return _memo; 039 } 040 041 /** 042 * Set the {@link SystemConnectionMemo} this action is bound to. 043 * <p> 044 * Implementing classes may throw an IllegalArgumentException if the 045 * implementing class requires a specific subclass of SystemConnectionMemo. 046 * 047 * @param memo the SystemConnectionMemo 048 * @throws IllegalArgumentException if the SystemConnectionMemo is invalid 049 */ 050 @Override 051 public void setSystemConnectionMemo(@Nonnull XNetSystemConnectionMemo memo) { 052 if(memo == null) { 053 throw new IllegalArgumentException("Attempt to set null system connection"); 054 } 055 _memo = memo; 056 } 057 058 /** 059 * Get a list of {@link SystemConnectionMemo} subclasses that the 060 * implementing class accepts. 061 * <p> 062 * If the implementing class is a subclass of a class that does accept 063 * SystemConnectionMemos, but the implementing class does not accept any, 064 * return an empty array instead of null. 065 * 066 * @return Set of SystemConnectionMemo subclasses or empty array. 067 */ 068 @Nonnull 069 @Override 070 public Set<Class<? extends SystemConnectionMemo>> getSystemConnectionMemoClasses(){ 071 return new HashSet<>(Arrays.asList(XNetSystemConnectionMemo.class)); 072 } 073 074}