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