1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.client.rep.controller;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.vectomatic.client.rep.RepApplication;
24 import org.vectomatic.client.rep.command.CutCommand;
25 import org.vectomatic.client.rep.events.IShapeSelectionListener;
26 import org.vectomatic.client.rep.view.DrawingView;
27 import org.vectomatic.common.model.CloneShapeVisitor;
28 import org.vectomatic.common.model.Shape;
29
30
31
32
33
34 public class CutController extends ControllerBase implements IShapeSelectionListener {
35 private ControllerMenuItem _cutMenuItem;
36 private CloneShapeVisitor _cloner;
37
38 public CutController(RepApplication app) {
39 super(app);
40 _app.getSelection().addShapeSelectionListener(this);
41 _cutMenuItem = new ControllerMenuItem(_app.getView(), app.getConstants().cutCommand(), this);
42 _cloner = new CloneShapeVisitor();
43 selectionChanged(_app.getSelection());
44 }
45
46 @Override
47 public void activate(DrawingView view) {
48
49 List<Shape> selectedShapes = _app.getSelection().getSelectedShapes();
50 List<Shape> clonedShapes = new ArrayList<Shape>();
51 for (int i = 0, size = selectedShapes.size(); i < size; i++) {
52 Shape shape = selectedShapes.get(i);
53 shape.acceptVisitor(_cloner);
54 clonedShapes.add(_cloner.getClone());
55 }
56 _app.getClipboard().setContent(clonedShapes);
57
58
59 CutCommand cutCommand = new CutCommand(_app);
60
61
62 cutCommand.execute();
63 _app.getHistory().addCommand(cutCommand);
64 }
65
66 public ControllerMenuItem getCutMenuItem() {
67 return _cutMenuItem;
68 }
69
70 public void selectionChanged(ShapeSelection selection) {
71 _cutMenuItem.setEnabled(_app.getSelection().getSelectedShapes().size() > 0);
72 }
73 }