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.controller;
19  
20  import java.util.List;
21  
22  import org.vectomatic.client.rep.RepApplication;
23  import org.vectomatic.client.rep.command.UngroupCommand;
24  import org.vectomatic.client.rep.events.IShapeSelectionListener;
25  import org.vectomatic.client.rep.view.DrawingView;
26  import org.vectomatic.common.model.Shape;
27  import org.vectomatic.common.model.geometry.ShapeGroup;
28  
29  import com.google.gwt.user.client.ui.MenuItem;
30  
31  /**
32   * Controller to respond to ungrouping requests and turn
33   * them into UngroupCommand
34   */
35  public class UngroupController extends ControllerBase implements IShapeSelectionListener {
36  	private ControllerMenuItem _ungroupMenuItem;
37  	private ControllerContextItem _ungroupContextItem;
38  
39  	public UngroupController(RepApplication app) {
40  		super(app);
41  		_app.getSelection().addShapeSelectionListener(this);
42  		_ungroupMenuItem = new ControllerMenuItem(_app.getView(), _app.getConstants().ungroupCommand(), this);
43  		_ungroupContextItem = new ControllerContextItem(_app.getView(), _app.getConstants().ungroupCommand(), this);
44  		selectionChanged(_app.getSelection());
45  	}
46  
47  	@Override
48  	public void activate(DrawingView view) {
49  		UngroupCommand ungroupCommand = new UngroupCommand(_app);
50  		ungroupCommand.execute();
51  		_app.getHistory().addCommand(ungroupCommand);
52  	}
53  
54  	public void selectionChanged(ShapeSelection selection) {
55  		List<Shape> selectedShapes = selection.getSelectedShapes();
56  		_ungroupMenuItem.setEnabled(selectedShapes.size() == 1 && (selectedShapes.get(0) instanceof ShapeGroup));
57  	}
58  
59  	public MenuItem getUngroupMenuItem() {
60  		return _ungroupMenuItem;
61  	}
62  
63  	public MenuItem getUngroupContextItem() {
64  		return _ungroupContextItem;
65  	}
66  
67  }