001package jmri.jmrit.roster.swing;
002
003import java.awt.Dimension;
004import java.awt.event.ActionEvent;
005import javax.swing.Icon;
006import javax.swing.WindowConstants;
007import jmri.InstanceManager;
008import jmri.UserPreferencesManager;
009import jmri.jmrit.roster.rostergroup.RosterGroupSelector;
010import jmri.util.swing.JmriAbstractAction;
011import jmri.util.swing.WindowInterface;
012
013/**
014 * AbstractAction for the RosterFrane so that multiple windows can be opened
015 *
016 * @author Kevin Dickerson Copyright (C) 2011
017 * @author Randall Wood Copyright (C) 2012
018 */
019public class RosterFrameAction extends JmriAbstractAction {
020
021    public RosterFrameAction(String s, WindowInterface wi) {
022        super(s, wi);
023    }
024
025    public RosterFrameAction(String s, WindowInterface wi, boolean allowQuit) {
026        super(s, wi);
027        this.allowQuit = allowQuit;
028    }
029
030    public RosterFrameAction(String s, Icon i, WindowInterface wi) {
031        super(s, i, wi);
032    }
033
034    /**
035     * Default constructor used when instantiating via startup action or button
036     * configured in user preferences
037     */
038    public RosterFrameAction() {
039        super(Bundle.getMessage("RosterFrameAction")); // NOI18N
040        allowQuit = false;
041    }
042
043    /**
044     * Method for opening a new window via the classic JMRI interface.
045     * @param pName action name.
046     * @param allowQuit Set state to either close JMRI or just the roster window.
047     */
048    public RosterFrameAction(String pName, boolean allowQuit) {
049        super(pName);
050        this.allowQuit = allowQuit;
051    }
052
053    boolean allowQuit = true;
054
055    @Override
056    public void actionPerformed(ActionEvent event) {
057        RosterFrame mainFrame = new RosterFrame();
058        UserPreferencesManager p = InstanceManager.getDefault(jmri.UserPreferencesManager.class);
059        if (!p.hasProperties(mainFrame.getWindowFrameRef())) {
060            mainFrame.setSize(new Dimension(1024, 600));
061            mainFrame.setPreferredSize(new Dimension(1024, 600));
062        }
063        if (wi instanceof RosterGroupSelector) {
064            mainFrame.setSelectedRosterGroup(((RosterGroupSelector) wi).getSelectedRosterGroup());
065        }
066        mainFrame.setVisible(true);
067        mainFrame.setAllowQuit(allowQuit);
068        mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
069    }
070
071    // never invoked, because we overrode actionPerformed above
072    @Override
073    public jmri.util.swing.JmriPanel makePanel() {
074        throw new IllegalArgumentException("Should not be invoked");
075    }
076}