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