View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.client.rep.command;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.vectomatic.client.rep.RepApplication;
24  import org.vectomatic.common.model.Shape;
25  
26  /**
27   * Command to paste a shape from the model
28   */
29  public class PasteCommand extends CommandBase {
30  	private List<Shape> _shapes;
31  
32  	public PasteCommand(RepApplication app, List<Shape> clonedShapes) {
33  		super(app);
34  		_shapes = new ArrayList<Shape>(clonedShapes);
35  	}
36  
37  	public String getDescription() {
38  		return _app.getConstants().pasteCommand();
39  	}
40  	
41  	public void execute() {
42  		for (int i = 0, size = _shapes.size(); i < size; i++) {
43  			Shape shape = _shapes.get(i);
44  			_app.getModel().addShape(shape);
45  		}
46  		_app.getModel().fireModelHasChanged();
47  		_app.getSelection().select(_shapes);
48  	}
49  
50  	public void unexecute() {
51  		for (int i = 0, size = _shapes.size(); i < size; i++) {
52  			Shape shape = _shapes.get(i);
53  			_app.getModel().removeShape(shape);
54  		}
55  		_app.getModel().fireModelHasChanged();
56  		_app.getSelection().select(new ArrayList<Shape>());
57  	}
58  }