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

import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
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;


/**
 * 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 {
    public Collection<JMenuItem> createMenus(BreakpointManager bpm) {
        SeparatorFactory sepFac = new SeparatorFactory("de.renew.gui.net");
        List<JMenuItem> result = new ArrayList<>();
        result.add(new CommandMenuItem(new SplitCommand("Split transition/place")));
        result.add(new CommandMenuItem(new CoarseCommand("Coarsen subnet")));
        result.add(sepFac.createSeparator());

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

        traceMenu.add(CommandApi.createChangeAttributeCommand("on", "TraceMode", Boolean.TRUE));
        traceMenu.add(CommandApi.createChangeAttributeCommand("off", "TraceMode", Boolean.FALSE));
        result.add(traceMenu);

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

        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "highlight only", "MarkingAppearance", PlaceFigure.HIGHLIGHT));
        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "Cardinality", "MarkingAppearance", PlaceFigure.CARDINALITY));
        markingMenu.add(
            CommandApi
                .createChangeAttributeCommand("Tokens", "MarkingAppearance", PlaceFigure.TOKENS));
        markingMenu.add(
            CommandApi.createChangeAttributeCommand(
                "expanded Tokens", "MarkingAppearance", PlaceFigure.EXPANDED_TOKENS));
        result.add(markingMenu);
        result.add(bpm.getNetMenu());
        result.add(sepFac.createSeparator());

        result.add(new CommandMenuItem(new SetIconFigureCommand("Set Selection as Icon")));
        result.add(new CommandMenuItem(new HighlightAssociateCommand("Associate Highlight")));
        result.add(new CommandMenuItem(new HighlightSelectCommand("Select Highlight(s)")));
        result.add(new CommandMenuItem(new HighlightUnassociateCommand("Unassociate Highlight")));
        result.add(sepFac.createSeparator());

        result.add(new CommandMenuItem(new Command("Syntax Check") {
            @Override
            public void execute() {
                CPNApplication ca = GuiPlugin.getCurrent().getGui();
                ca.syntaxCheck();
            }
        }, KeyEvent.VK_S,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + InputEvent.ALT_DOWN_MASK));

        result.add(
            new CommandMenuItem(
                new LayoutCheckCommand("Layout check"), KeyEvent.VK_L,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + InputEvent.ALT_DOWN_MASK));

        return result;
    }
}