/*
 * Created on 06.02.2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */

package CH.ifa.draw.standard;

import java.util.Collection;
import java.util.Vector;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import CH.ifa.draw.application.DrawApplication;
import CH.ifa.draw.application.MenuManager.SeparatorFactory;
import CH.ifa.draw.util.CommandMenu;
import CH.ifa.draw.util.CommandMenuItem;
import de.renew.draw.ui.ontology.AbstractCommand;
import de.renew.plugin.PluginProperties;

/**
 * Creates the menus for alignment and spreading.
 *
 * @deprecated This class is not to be used externally and will later be hidden.
 */
@Deprecated(since = "5.0", forRemoval = true)
public class AlignmentMenuCreator {
    //Hotkey property names
    public static final String TOGGLE_SNAP_GRID_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.togglesnaptogrid";
    public static final String SNAP_GRID_NOW_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.snaptogridnow";
    public static final String ALIGN_LEFTS_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.alignlefts";
    public static final String ALIGN_CENTER_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.aligncenters";
    public static final String ALIGN_RIGHT_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.alignrights";
    public static final String ALIGN_TOP_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.aligntops";
    public static final String ALIGN_MIDDLE_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.alignmiddles";
    public static final String ALIGN_BOTTOM_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.alignbottoms";
    public static final String SPREAD_LEFTS_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.spreadlefts";
    public static final String SPREAD_CENTER_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreadcenters";
    public static final String SPREAD_RIGHT_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.spreadrights";
    public static final String SPREAD_HORIZONTAL_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreadhorizontaldistances";
    public static final String SPREAD_TOPS_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.spreadtops";
    public static final String SPREAD_MIDDLE_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreadmiddles";
    public static final String SPREAD_BOTTOMS_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreadbottoms";
    public static final String SPREAD_VERTICAL_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreadverticaldistances";
    public static final String SPREAD_DIAGONAL_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.spreaddiagonal";
    public static final String BRING_TO_FRONT_HOTKEY_PROP_NAME =
        "de.renew.hotkeymap.ch.bringtofront";
    public static final String SEND_TO_BACK_HOTKEY_PROP_NAME = "de.renew.hotkeymap.ch.sendtoback";

    /**
     * Creates the alignment and spread menus using the provided configuration.
     *
     * @param plugincfg the properties to read hotkeys from.
     * @return a collection of menu items.
     */
    public Collection<JMenuItem> createMenus(PluginProperties plugincfg) {
        SeparatorFactory sepFac = new SeparatorFactory("ch.ifa.draw");
        Vector<JMenuItem> result = new Vector<JMenuItem>();

        PluginProperties prop = PluginProperties.getUserProperties();

        result.add(
            createCommandMenu(
                new ToggleGridCommand("Toggle Snap to Grid"),
                prop.getHotkeyProperty(
                    TOGGLE_SNAP_GRID_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(TOGGLE_SNAP_GRID_HOTKEY_PROP_NAME))));
        result.add(
            createCommandMenu(
                new SnapToGridCommand("Snap to Grid now"),
                prop.getHotkeyProperty(
                    SNAP_GRID_NOW_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(SNAP_GRID_NOW_HOTKEY_PROP_NAME))));
        result.add(sepFac.createSeparator());

        CommandMenu alignMenu = DrawApplication.createCommandMenu("Align");
        alignMenu.add(
            new AlignCommand("Lefts", AlignCommand.LEFTS),
            prop.getHotkeyProperty(
                ALIGN_LEFTS_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_LEFTS_HOTKEY_PROP_NAME)));
        alignMenu.add(
            new AlignCommand("Centers", AlignCommand.CENTERS),
            prop.getHotkeyProperty(
                ALIGN_CENTER_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_CENTER_HOTKEY_PROP_NAME)));
        alignMenu.add(
            new AlignCommand("Rights", AlignCommand.RIGHTS),
            prop.getHotkeyProperty(
                ALIGN_RIGHT_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_RIGHT_HOTKEY_PROP_NAME)));
        alignMenu.addSeparator();
        alignMenu.add(
            new AlignCommand("Tops", AlignCommand.TOPS),
            prop.getHotkeyProperty(
                ALIGN_TOP_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_TOP_HOTKEY_PROP_NAME)));
        alignMenu.add(
            new AlignCommand("Middles", AlignCommand.MIDDLES),
            prop.getHotkeyProperty(
                ALIGN_MIDDLE_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_MIDDLE_HOTKEY_PROP_NAME)));
        alignMenu.add(
            new AlignCommand("Bottoms", AlignCommand.BOTTOMS),
            prop.getHotkeyProperty(
                ALIGN_BOTTOM_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(ALIGN_BOTTOM_HOTKEY_PROP_NAME)));
        result.add(alignMenu);
        CommandMenu spreadMenu = DrawApplication.createCommandMenu("Spread");
        spreadMenu.add(
            new SpreadCommand("Lefts", SpreadCommand.LEFTS),
            prop.getHotkeyProperty(
                SPREAD_LEFTS_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_LEFTS_HOTKEY_PROP_NAME)));
        spreadMenu.add(
            new SpreadCommand("Centers", SpreadCommand.CENTERS),
            prop.getHotkeyProperty(
                SPREAD_CENTER_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_CENTER_HOTKEY_PROP_NAME)));
        spreadMenu.add(
            new SpreadCommand("Rights", SpreadCommand.RIGHTS),
            prop.getHotkeyProperty(
                SPREAD_RIGHT_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_RIGHT_HOTKEY_PROP_NAME)));
        spreadMenu.add(
            new SpreadCommand("Distances", SpreadCommand.HORIZONTAL_DISTANCE),
            prop.getHotkeyProperty(SPREAD_HORIZONTAL_HOTKEY_PROP_NAME));
        spreadMenu.addSeparator();
        spreadMenu.add(
            new SpreadCommand("Tops", SpreadCommand.TOPS),
            prop.getHotkeyProperty(
                SPREAD_TOPS_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_TOPS_HOTKEY_PROP_NAME)));
        spreadMenu.add(
            new SpreadCommand("Middles", SpreadCommand.MIDDLES),
            prop.getHotkeyProperty(
                SPREAD_MIDDLE_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_MIDDLE_HOTKEY_PROP_NAME)));
        spreadMenu.add(
            new SpreadCommand("Bottoms", SpreadCommand.BOTTOMS),
            prop.getHotkeyProperty(SPREAD_BOTTOMS_HOTKEY_PROP_NAME));
        spreadMenu.add(
            new SpreadCommand("Distances", SpreadCommand.VERTICAL_DISTANCE),
            prop.getHotkeyProperty(
                SPREAD_VERTICAL_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_VERTICAL_HOTKEY_PROP_NAME)));

        spreadMenu.addSeparator();
        spreadMenu.add(
            new SpreadCommand("Diagonal", SpreadCommand.DIAGONAL_CENTERS),
            prop.getHotkeyProperty(
                SPREAD_DIAGONAL_HOTKEY_PROP_NAME,
                plugincfg.getHotkeyProperty(SPREAD_DIAGONAL_HOTKEY_PROP_NAME)));

        result.add(spreadMenu);

        result.add(
            createCommandMenu(
                new SendToBackCommand("Send to Back"),
                prop.getHotkeyProperty(
                    SEND_TO_BACK_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(SEND_TO_BACK_HOTKEY_PROP_NAME))));
        result.add(
            createCommandMenu(
                new BringToFrontCommand("Bring to Front"),
                prop.getHotkeyProperty(
                    BRING_TO_FRONT_HOTKEY_PROP_NAME,
                    plugincfg.getHotkeyProperty(BRING_TO_FRONT_HOTKEY_PROP_NAME))));
        return result;
    }

    private CommandMenuItem createCommandMenu(AbstractCommand command) {
        return new CommandMenuItem(command);
    }

    private CommandMenuItem createCommandMenu(AbstractCommand command, KeyStroke hotkey) {
        CommandMenuItem item = new CommandMenuItem(command);
        if (hotkey != null) {
            item.setAccelerator(hotkey);
        }
        return item;
    }
}