001package jmri.jmrit.z21server;
002
003import java.awt.event.ActionEvent;
004import javax.swing.AbstractAction;
005import jmri.util.JmriJFrame;
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * Called from a menu to display the Turnout Number Mapping Window.
011 * 
012 * @author Eckart Meyer Copyright (C) 2025
013 * 
014 * Derived from jmri.jmrit.withrottle.ControllerFilterAction.
015 */
016public class NumberMapAction extends AbstractAction {
017
018/**
019 * Constructor.
020 * If none of the supported managers exist, disable the action instance.
021 * Called when building the menu.
022 * 
023 * @param name - the menu entry
024 */
025    @SuppressWarnings("unchecked")
026    public NumberMapAction(String name) {
027        super(name);
028        boolean mgrFound = false;
029        for (Class<?> clazz : jmri.jmrit.z21server.TurnoutNumberMapHandler.getManagerClassList()) {
030            if (jmri.InstanceManager.getNullableDefault(clazz) != null) {
031                mgrFound = true;
032            }
033        }
034        if (!mgrFound) {
035            setEnabled(false);
036        }
037    }
038
039    public NumberMapAction() {
040        this(Bundle.getMessage("MenuMenuNumberMap"));
041    }
042
043    public String getName() {
044        return "jmri.jmrit.z21server.NumberMapFrame";
045    }
046
047    @Override
048    public void actionPerformed(ActionEvent ae) {
049        JmriJFrame frame = new NumberMapFrame();
050        try {
051            frame.initComponents();
052            frame.setVisible(true);
053        } catch (Exception ex) {
054            log.error("Could not create Number Map frame");
055        }
056
057    }
058
059    private final static Logger log = LoggerFactory.getLogger(NumberMapAction.class);
060
061}