001package jmri.jmrit.display.switchboardEditor;
002
003import java.awt.event.ActionEvent;
004
005import javax.swing.AbstractAction;
006
007import jmri.InstanceManager;
008import jmri.jmrit.display.EditorManager;
009import jmri.util.JmriJFrame;
010
011/**
012 * Start a SwitchboardEditor.
013 *
014 * @author Bob Jacobsen Copyright (C) 2002
015 * @see jmri.jmrit.display.switchboardEditor.SwitchboardEditor
016 */
017public class SwitchboardEditorAction extends AbstractAction {
018
019    public SwitchboardEditorAction(String s) {
020        super(s);
021    }
022
023    public SwitchboardEditorAction() {
024        this("New Switchboard");
025    } // NO I18N
026
027    @Override
028    public void actionPerformed(ActionEvent e) {
029        String name = Bundle.getMessage("SwitchboardDefaultName", "");
030        for (int i = 2; i < 100; i++) {
031            if (JmriJFrame.getFrame(name) != null) {
032                name = Bundle.getMessage("SwitchboardDefaultName", " " + i);
033            }
034        }
035        SwitchboardEditor frame = new SwitchboardEditor(name);
036        InstanceManager.getDefault(EditorManager.class).add(frame);
037        frame.setLocation(570, 20); // position Editor
038
039        frame.setTitle();
040        frame.initView();
041
042        frame.pack();
043        frame.setVisible(true);
044        frame.newPanelDefaults();
045    }
046
047}