/*
 * Created on 28.01.2004
 *
 */
package de.renew.gui;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.JMenuItem;

import CH.ifa.draw.application.DrawApplication;
import CH.ifa.draw.application.MenuManager.SeparatorFactory;
import CH.ifa.draw.util.Command;
import CH.ifa.draw.util.CommandMenu;
import CH.ifa.draw.util.CommandMenuItem;
import de.renew.draw.ui.api.CommandApi;
import de.renew.plugin.PluginProperties;


/**
 * This class creates the Net menu for the Gui plugin.<br>
 * The Net menu contains entries which offer editing functionality
 * for drawings representing Renew nets.
 *
 * @author J&ouml;rn Schumacher
 */
public class NetMenuCreator {

    //Hotkey property names
    public static final String SPLIT_TRANSITION_PLACE_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.splittransitionplace";

    public static final String COARSEN_SUBNET_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.coarsensubnet";

    public static final String TRACE_ON_HOTKEY_PROP_NAME = "de.renew.hotkeymap.gui.traceon";

    public static final String TRACE_OFF_HOTKEY_PROP_NAME = "de.renew.hotkeymap.gui.traceoff";

    public static final String MARKING_HIGHLIGHT_ONLY_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.markinghighlightonly";

    public static final String MARKING_CARDINALITY_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.markingcardinality";

    public static final String MARKING_TOKENS_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.markingtokens";

    public static final String MARKING_EXPANDED_TOKENS_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.markingexpandedtokens";

    public static final String SET_SELECTION_AS_ICON_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.setselectionasicon";

    public static final String ASSOCIATE_HIGHLIGHT_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.associatehighlight";

    public static final String SELECT_HIGHLIGHTS_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.selecthighlights";

    public static final String UNASSOCIATE_HIGHLIGHTS_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.gui.unassociatehighlight";

    public static final String SYNTAX_CHECK_HOTKEY_PROP_NAME = "de.renew.hotkeymap.gui.syntaxcheck";

    public static final String LAYOUT_CHECK_HOTKEY_PROP_NAME = "de.renew.hotkeymap.gui.layoutcheck";

    public Collection<JMenuItem> createMenus(BreakpointManager bpm, PluginProperties plugincfg) {
        SeparatorFactory sepFac = new SeparatorFactory("de.renew.gui.net");
        List<JMenuItem> result = new ArrayList<>();
        PluginProperties prop = PluginProperties.getUserProperties();
        result.add(
            new CommandMenuItem(
                new SplitCommand("Split transition/place"),
                prop.getHotkeyProperty(
                    SPLIT_TRANSITION_PLACE_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(SPLIT_TRANSITION_PLACE_HOTKEY_PROP_NAME))));
        result.add(
            new CommandMenuItem(
                new CoarseCommand("Coarsen subnet"),
                prop.getHotkeyProperty(
                    COARSEN_SUBNET_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(COARSEN_SUBNET_HOTKEY_PROP_NAME))));
        result.add(sepFac.createSeparator());

        CommandMenu traceMenu = DrawApplication.createCommandMenu("Trace");

        traceMenu.add(
            CommandApi.createChangeAttributeCommand("on", "TraceMode", Boolean.TRUE),
            prop.getHotkeyProperty(
                TRACE_ON_HOTKEY_PROP_NAME, plugincfg.getHotkeyProperty(TRACE_ON_HOTKEY_PROP_NAME)));
        traceMenu.add(
            CommandApi.createChangeAttributeCommand("off", "TraceMode", Boolean.FALSE),
            prop.getHotkeyProperty(
                TRACE_OFF_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(TRACE_OFF_HOTKEY_PROP_NAME)));
        result.add(traceMenu);

        CommandMenu markingMenu = DrawApplication.createCommandMenu("Marking");

        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "highlight only", "MarkingAppearance", PlaceFigure.HIGHLIGHT),
            prop.getHotkeyProperty(
                MARKING_HIGHLIGHT_ONLY_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(MARKING_HIGHLIGHT_ONLY_HOTKEY_PROP_NAME)));
        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "Cardinality", "MarkingAppearance", PlaceFigure.CARDINALITY),
            prop.getHotkeyProperty(
                MARKING_CARDINALITY_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(MARKING_CARDINALITY_HOTKEY_PROP_NAME)));
        markingMenu.add(
            CommandApi
                .createChangeAttributeCommand("Tokens", "MarkingAppearance", PlaceFigure.TOKENS),
            prop.getHotkeyProperty(
                MARKING_TOKENS_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(MARKING_TOKENS_HOTKEY_PROP_NAME)));
        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "expanded Tokens", "MarkingAppearance", PlaceFigure.EXPANDED_TOKENS),
            prop.getHotkeyProperty(
                MARKING_EXPANDED_TOKENS_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(MARKING_EXPANDED_TOKENS_HOTKEY_PROP_NAME)));
        result.add(markingMenu);
        result.add(bpm.getNetMenu(plugincfg));
        result.add(sepFac.createSeparator());

        result.add(
            new CommandMenuItem(
                new SetIconFigureCommand("Set Selection as Icon"),
                prop.getHotkeyProperty(
                    SET_SELECTION_AS_ICON_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(SET_SELECTION_AS_ICON_HOTKEY_PROP_NAME))));
        result.add(
            new CommandMenuItem(
                new HighlightAssociateCommand("Associate Highlight"),
                prop.getHotkeyProperty(
                    ASSOCIATE_HIGHLIGHT_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(ASSOCIATE_HIGHLIGHT_HOTKEY_PROP_NAME))));
        result.add(
            new CommandMenuItem(
                new HighlightSelectCommand("Select Highlight(s)"),
                prop.getHotkeyProperty(
                    SELECT_HIGHLIGHTS_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(SELECT_HIGHLIGHTS_HOTKEY_PROP_NAME))));
        result.add(
            new CommandMenuItem(
                new HighlightUnassociateCommand("Unassociate Highlight"),
                prop.getHotkeyProperty(
                    UNASSOCIATE_HIGHLIGHTS_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(UNASSOCIATE_HIGHLIGHTS_HOTKEY_PROP_NAME))));
        result.add(sepFac.createSeparator());

        result.add(new CommandMenuItem(new Command("Syntax Check") {
            @Override
            public void execute() {
                CPNApplication ca = GuiPlugin.getCurrent().getGui();
                ca.syntaxCheck();
            }
        }, prop.getHotkeyProperty(
            SYNTAX_CHECK_HOTKEY_PROP_NAME,
            plugincfg.getHotkeyProperty(SYNTAX_CHECK_HOTKEY_PROP_NAME))));

        result.add(
            new CommandMenuItem(
                new LayoutCheckCommand("Layout Check"),
                prop.getHotkeyProperty(
                    LAYOUT_CHECK_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(LAYOUT_CHECK_HOTKEY_PROP_NAME))));

        return result;
    }
}