001package jmri.jmrit.dispatcher;
002
003import java.awt.event.ActionEvent;
004import javax.swing.AbstractAction;
005import jmri.InstanceManager;
006
007/**
008 * Swing action to create and register a DispatcherFrame
009 *
010 * @author Dave Duchamp Copyright (C) 2008
011 */
012public class DispatcherAction extends AbstractAction {
013
014    public DispatcherAction(String s) {
015        super(s);
016    }
017
018    public DispatcherAction() {
019        this(Bundle.getMessage("TitleDispatcher"));
020    }
021
022    DispatcherFrame f = null;
023
024    @Override
025    public void actionPerformed(ActionEvent e) {
026        // check that Transits have been defined and are available
027        if (InstanceManager.getDefault(jmri.TransitManager.class).getNamedBeanSet().size() == 0) {
028            // Inform the user that there are no Transits available, and don't open the window
029            jmri.util.swing.JmriJOptionPane.showMessageDialog(null, Bundle.getMessage("NoTransitsMessage"));
030            return;
031        }
032        // create a Dispatcher window or activate the existing one
033        if (f == null) {
034            f = InstanceManager.getDefault(DispatcherFrame.class);
035            jmri.util.ThreadingUtil.newThread(new Runnable() {
036                @Override
037                public void run() {
038                    f.loadAtStartup();
039                }
040            }).start();
041        }
042        f.setVisible(true);
043    }
044
045}