Skip to content
Snippets Groups Projects
Commit e2dd3bd9 authored by Victor Peyrade-Mathon's avatar Victor Peyrade-Mathon
Browse files

Claire CAUSSE [:sparkles: Ajout CTRL+Z (et bouton retour)]

parent 4e19236a
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package shukan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Stack;
/** Shukan controller
......@@ -15,6 +16,7 @@ public class ShukanController
private ShukanViewBar bar;
/** Controlled application data. */
private ShukanData data;
private Stack<Integer> actionStack;
/** Constructs a event handler.
* @param canvas display area.
......@@ -23,6 +25,7 @@ public class ShukanController
this.canvas = canvas;
this.bar = bar;
this.data = data;
this.actionStack = new Stack<>();
}
......@@ -53,6 +56,13 @@ public class ShukanController
{
switch (e.getKeyCode ())
{
case KeyEvent.VK_Z :
if (pressed && e.isControlDown ())
{
int lastAction = actionStack.pop();
revertAction(lastAction);
}
break;
case KeyEvent.VK_Q :
case KeyEvent.VK_ESCAPE :
if (! pressed)
......@@ -90,7 +100,34 @@ public class ShukanController
}
}
private void revertAction(int action)
{
switch (action)
{
case 0:
canvas.deleteActivity();
canvas.repaint();
break;
case 1:
System.out.println("revert delete activity");
break;
case 2:
data.followRight();
canvas.repaint();
break;
case 3:
data.followLeft();
canvas.repaint();
break;
case 4:
data.exchangeExtremes ();
canvas.repaint ();
break;
case 5:
data.toggleCursus(false);
canvas.repaint();
}
}
/** Invoked when a key has been typed.
* Implementation from KeyListener.
......@@ -199,37 +236,47 @@ public class ShukanController
* @param e detected action event
* */
public void actionPerformed(ActionEvent e){
if (e.getSource()== bar.buttons[0])
if (e.getSource()== bar.buttons[0]) {
canvas.saveData ();
else if (e.getSource()== bar.buttons[1])
System.out.println("back");
}
else if (e.getSource()== bar.buttons[1]) {
int lastAction = actionStack.pop();
revertAction(lastAction);
}
else if (e.getSource()==bar.buttons[2])
{
canvas.newActivity();
canvas.repaint();
actionStack.push(0);
}
else if (e.getSource()==bar.buttons[3])
{
canvas.deleteActivity();
actionStack.push(1);
}
else if (e.getSource()==bar.buttons[3]) canvas.deleteActivity();
else if (e.getSource()==bar.buttons[4]) {if (data.followLeft ()) canvas.repaint ();}
else if (e.getSource()==bar.buttons[4]) {if (data.followLeft ()) {canvas.repaint (); actionStack.push(2);}}
else if (e.getSource()==bar.buttons[5]) {if (data.followRight ()) canvas.repaint ();}
else if (e.getSource()==bar.buttons[5]) {if (data.followRight ()) {canvas.repaint (); actionStack.push(3);}}
else if (e.getSource()== bar.buttons[6])
{
data.exchangeExtremes ();
canvas.repaint ();
actionStack.push(4);
}
else if (e.getSource()== bar.buttons[7])
{
data.toggleCursus(false);
canvas.repaint();
actionStack.push(5);
}
//if (data.followRight ()) canvas.repaint ();
else if (e.getSource()==bar.buttons[8])
new ShukanTex (data);
else if (e.getSource()==bar.buttons[9]){
EventQueue.invokeLater(() -> {
ShukanParameters myParameters = new ShukanParameters("Changer de thème", canvas);
myParameters.setSize(300, 300);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment