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 change the order of the shapes in the display list
28   */
29  public class ChangeOrderingCommand extends CommandBase {
30  	public static final int BRING_TO_FRONT = 0;
31  	public static final int SEND_TO_BACK = 1;
32  	public static final int BRING_FORWARD = 2;
33  	public static final int SEND_BACKWARD = 3;
34  	private int _direction;
35  	private List<Shape> _shapes;
36  	private List<Float> _orders;
37  	
38  	public ChangeOrderingCommand(RepApplication app, int direction) {
39  		super(app);
40  		_direction = direction;
41  		_shapes = new ArrayList<Shape>(_app.getSelection().getSelectedShapes());
42  	}
43  
44  	public void execute() {
45  		switch(_direction) {
46  			case BRING_TO_FRONT:
47  				_orders = _app.getModel().bringToFront(_shapes);
48  				break;
49  			case SEND_TO_BACK:
50  				_orders = _app.getModel().sendToBack(_shapes);
51  				break;
52  			case BRING_FORWARD:
53  				_orders = _app.getModel().bringForward(_shapes);
54  				break;
55  			case SEND_BACKWARD:
56  				_orders = _app.getModel().sendBackward(_shapes);
57  				break;
58  		}
59  	}
60  
61  	public String getDescription() {
62  		String description = null;
63  		switch(_direction) {
64  			case BRING_TO_FRONT:
65  				description = _app.getConstants().bringToFrontCommand();
66  				break;
67  			case SEND_TO_BACK:
68  				description = _app.getConstants().sendToBackCommand();
69  				break;
70  			case BRING_FORWARD:
71  				description = _app.getConstants().bringForwardCommand();
72  				break;
73  			case SEND_BACKWARD:
74  				description = _app.getConstants().sendBackwardCommand();
75  				break;
76  		}
77  		return description;
78  	}
79  
80  	public void unexecute() {
81  		_app.getModel().reorder(_shapes, _orders);
82  	}
83  }