001package apps;
002
003import java.awt.event.ActionEvent;
004import javax.swing.Icon;
005import jmri.util.swing.JmriAbstractAction;
006import jmri.util.swing.JmriPanel;
007import jmri.util.swing.WindowInterface;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * Simple AbstractAction class that can be invoked to restart JMRI
013 * <hr>
014 * This file is part of JMRI.
015 * <p>
016 * JMRI is free software; you can redistribute it and/or modify it under the
017 * terms of version 2 of the GNU General Public License as published by the Free
018 * Software Foundation. See the "COPYING" file for a copy of this license.
019 * <p>
020 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
022 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
023 *
024 * @author Matthew Harris Copyright (C) 2011
025 */
026public class RestartAction extends JmriAbstractAction {
027
028    public RestartAction(String s, WindowInterface wi) {
029        super(s, wi);
030    }
031
032    public RestartAction(String s, Icon i, WindowInterface wi) {
033        super(s, i, wi);
034    }
035
036    public RestartAction() {
037        super(Bundle.getMessage("RestartAction")); // NOI18N
038    }
039
040    @Override
041    public void actionPerformed(ActionEvent e) {
042
043        log.debug("Source: {}; class: {}", e.getSource().toString(), e.getSource().getClass().getName());
044
045        // Don't actually do this if launched as a start-up action
046        // as we'll be in an endless loop
047        if (!e.getSource().toString().equals("prefs")) {
048            Apps.handleRestart();
049        } else {
050            log.warn("RestartAction called in error - this should not be done...");
051        }
052    }
053
054    // never invoked, because we overrode actionPerformed above
055    @Override
056    public JmriPanel makePanel() {
057        throw new IllegalArgumentException("Should not be invoked");
058    }
059
060    private static final Logger log = LoggerFactory.getLogger(RestartAction.class);
061
062}