001package jmri.jmrit.display;
002
003import java.awt.event.ActionEvent;
004import javax.swing.AbstractAction;
005
006import jmri.util.swing.JmriJOptionPane;
007
008/**
009 * Start a Panel Editor or a Layout Editor for a new Panel.
010 * <p>
011 * Uses the individual LayoutEditorAction or PanelEditorAction to start the
012 * editors, to ensure consistent operation.
013 *
014 * @author Dave Duchamp Copyright (C) 2007
015 * @author Bob Jacobsen Copyright (C) 2008
016 * @author Egbert Broerse Copyright (C) 2017
017 */
018public class NewPanelAction extends AbstractAction {
019
020    public NewPanelAction(String s) {
021        super(s);
022    }
023
024    public NewPanelAction() {
025        this(Bundle.getMessage("MenuItemNew"));
026    }
027
028    @Override
029    public void actionPerformed(ActionEvent e) {
030        // allow user to choose a panel editor
031        int response = JmriJOptionPane.showOptionDialog(null,
032                Bundle.getMessage("ChoiceText1") + "\n" + Bundle.getMessage("ChoiceText2") + "\n"
033                + Bundle.getMessage("ChoiceText3") + "\n" + Bundle.getMessage("ChoiceText4") + "\n"
034                        + Bundle.getMessage("ChoiceText5"),
035                Bundle.getMessage("ChooseEditor"),
036                JmriJOptionPane.DEFAULT_OPTION, JmriJOptionPane.QUESTION_MESSAGE, null,
037                new Object[]{Bundle.getMessage("SwitchboardEditor"), Bundle.getMessage("LayoutEditor"),
038                        Bundle.getMessage("ControlPanelEditor"), Bundle.getMessage("PanelEditor"),
039                        Bundle.getMessage("ButtonCancel")},
040                Bundle.getMessage("PanelEditor")); // title
041        switch (response) {
042            case 3: // PanelEditor
043                new jmri.jmrit.display.panelEditor.PanelEditorAction().actionPerformed(null);
044                break;
045            case 2: // ControlPanelEditor
046                new jmri.jmrit.display.controlPanelEditor.ControlPanelEditorAction().actionPerformed(null);
047                break;
048            case 1: // LayoutEditor
049                new jmri.jmrit.display.layoutEditor.LayoutEditorAction().actionPerformed(null);
050                break;
051            case 0: // SwitchboardEditor
052                new jmri.jmrit.display.switchboardEditor.SwitchboardEditorAction().actionPerformed(null);
053                break;
054            case JmriJOptionPane.CLOSED_OPTION: // Dialog closed
055            default:
056                break;
057        }
058    }
059
060}