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 org.vectomatic.client.rep.RepApplication;
21  import org.vectomatic.common.model.Shape;
22  import org.vectomatic.common.model.geometry.Ellipse;
23  import org.vectomatic.common.model.geometry.Path;
24  import org.vectomatic.common.model.geometry.Polyline;
25  import org.vectomatic.common.model.geometry.Rect;
26  
27  /**
28   * Command to add a new shape to the model
29   */
30  public class NewShapeCommand extends CommandBase {
31  	private Shape _shape;
32  
33  	public NewShapeCommand(RepApplication app, Shape shape) {
34  		super(app);
35  		_shape = shape;
36  	}
37  	
38  	public String getDescription() {
39  		if (_shape instanceof Ellipse) {
40  			return _app.getConstants().newEllipseCommand();
41  		} else if (_shape instanceof Rect) {
42  			return _app.getConstants().newRectCommand();
43  		} else if (_shape instanceof Polyline) {
44  			return _app.getConstants().newPolylineCommand();
45  		} else if (_shape instanceof Path) {
46  			return _app.getConstants().newPathCommand();			
47  		}
48  		throw new IllegalStateException();
49  	}
50  	
51  	public void unexecute() {
52  		_app.getModel().removeShape(_shape);
53  		_app.getModel().fireModelHasChanged();
54  	}
55  	
56  	public void execute() {
57  		_app.getModel().addShape(_shape);
58  		_app.getModel().fireModelHasChanged();
59  	}
60  }