/*
 * EditSomeXML is a graphical XML editor
 *
 * Copyright (C) 2014  David Jackson
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package editor.menubar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import xml.Element;
import editor.menubar.actionlisteners.MoveUpDownActionListener;
import editor.menubar.actionlisteners.NewElementActionListener;
import editor.menubar.actionlisteners.RedoActionListener;
import editor.menubar.actionlisteners.UndoActionListener;
import editor.views.CloneElementView;
import editor.views.DeleteElementView;
import editor.views.ElementTreeView;
import editor.views.MirrorElementView;

/**
 * This is the "Edit" menu of the menu bar
 */
public class EditMenu extends JMenu {
    public EditMenu(final ElementTreeView elementTreeView) {
        setText("Edit");

        Element root = elementTreeView.getRoot();
        JMenuItem undoItem = new JMenuItem("Undo");
        undoItem.addActionListener(new UndoActionListener(root));
        add(undoItem);
        
        JMenuItem redoItem = new JMenuItem("Redo");
        redoItem.addActionListener(new RedoActionListener(root));
        add(redoItem);
        
        addSeparator();

        JMenuItem newElementItem = new JMenuItem("New Child Element...");
        NewElementActionListener listener;
        listener = new NewElementActionListener(elementTreeView);
        newElementItem.addActionListener(listener);
        add(newElementItem);

        JMenuItem cloneElementItem = new JMenuItem("Clone Element...");
        cloneElementItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new CloneElementView(elementTreeView);
            }
        });
        add(cloneElementItem);

        JMenuItem mirrorItem = new JMenuItem("Mirror Element...");
        mirrorItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new MirrorElementView(elementTreeView);
            }
        });
        add(mirrorItem);

        JMenuItem deleteItem = new JMenuItem("Delete Element...");
        deleteItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DeleteElementView(elementTreeView);
            }
        });
        add(deleteItem);
        
        addSeparator();
        
        MoveUpDownActionListener moveUpDownListener;
        moveUpDownListener = new MoveUpDownActionListener(elementTreeView);
        
        JMenuItem moveUpItem = new JMenuItem("Move Up");
        moveUpItem.setActionCommand("MOVE_UP");
        moveUpItem.addActionListener(moveUpDownListener);
        add(moveUpItem);
        
        JMenuItem moveDownItem = new JMenuItem("Move Down");
        moveDownItem.setActionCommand("MOVE_DOWN");
        moveDownItem.addActionListener(moveUpDownListener);
        add(moveDownItem);
    }
}

@@ -755,24 +755,43 @@
 r.menubar;%0A%0A
+import java.awt.*;%0A
 import java.
@@ -875,43 +875,9 @@
 ing.
-JMenu;%0Aimport javax.swing.JMenuItem
+*
 ;%0A%0Ai
@@ -1583,344 +1583,899 @@
     
-undoItem.addActionListener(new UndoActionListener(root));%0A        add(undoItem);%0A        %0A        JMenuItem redoItem = new JMenuItem(%22Redo%22);%0A        redoItem.addActionListener(new RedoActionListener(root));%0A        add(redoItem);%0A        %0A        addSeparator();%0A%0A        JMenuItem newElementItem = new JMenuItem(%22New Child Element...%22
+KeyStroke undoShortcut = KeyStroke.getKeyStroke('Z',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        undoItem.setAccelerator(undoShortcut);%0A        undoItem.addActionListener(new UndoActionListener(root));%0A        add(undoItem);%0A        %0A        JMenuItem redoItem = new JMenuItem(%22Redo%22);%0A        KeyStroke redoShortcut = KeyStroke.getKeyStroke('Y',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        redoItem.setAccelerator(redoShortcut);%0A        redoItem.addActionListener(new RedoActionListener(root));%0A        add(redoItem);%0A        %0A        addSeparator();%0A%0A        JMenuItem newElementItem = new JMenuItem(%22New Child Element...%22);%0A        KeyStroke newElementShortcut = KeyStroke.getKeyStroke('E',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        newElementItem.setAccelerator(newElementShortcut
 );%0A 
@@ -2728,32 +2728,221 @@
 e Element...%22);%0A
+        KeyStroke cloneShortcut = KeyStroke.getKeyStroke('L',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        cloneElementItem.setAccelerator(cloneShortcut);%0A
         cloneEle
@@ -3252,32 +3252,217 @@
 r Element...%22);%0A
+        KeyStroke mirrorShortcut = KeyStroke.getKeyStroke('M',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        mirrorItem.setAccelerator(mirrorShortcut);%0A
         mirrorIt
@@ -3761,32 +3761,217 @@
 e Element...%22);%0A
+        KeyStroke deleteShortcut = KeyStroke.getKeyStroke('D',%0A                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());%0A        deleteItem.setAccelerator(deleteShortcut);%0A
         deleteIt

Add shortcuts to Edit menu