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  /**
21   * Controller to respond to requests to resize the drawing
22   */
23  import org.vectomatic.client.rep.RepApplication;
24  import org.vectomatic.client.rep.command.ICommand;
25  import org.vectomatic.client.rep.command.ResizeDrawingCommand;
26  import org.vectomatic.client.rep.view.DrawingView;
27  import org.vectomatic.common.rpc.Representation;
28  
29  import com.google.gwt.user.client.ui.MenuItem;
30  
31  public class ResizeController extends ControllerBase {
32  	private RepresentationController _repController;
33  	private ResizeDrawingPanel _panel;
34  	
35  	public ResizeController(RepApplication app, RepresentationController repController) {
36  		super(app);
37  		_repController = repController;
38  		_panel = new ResizeDrawingPanel(this);
39  	}
40  	
41  	@Override
42  	public void activate(DrawingView view) {
43  		Representation rep = _repController.getCurrentRep();
44  		_panel.show(rep.getWidth(), rep.getHeight());
45  	}
46  	
47  	public MenuItem getResizeMenuItem(DrawingView view) {
48  		return new ControllerContextItem(view, _app.getConstants().resizeDrawingCommand(), this);
49  	}
50  
51  	public void resize(int width, int height) {
52  		Representation rep = _repController.getCurrentRep();
53  		if (rep.getWidth() != width || rep.getHeight() != height) {
54  			ICommand command = new ResizeDrawingCommand(_app, _repController, width, height);
55  			command.execute();
56  			_app.getHistory().addCommand(command);
57  		}
58  	}
59  
60  }