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 org.vectomatic.client.rep.RepApplication;
21  import org.vectomatic.client.rep.command.CommandHistory;
22  import org.vectomatic.client.rep.events.ICommandHistoryListener;
23  import org.vectomatic.client.rep.view.DrawingView;
24  import org.vectomatic.common.rpc.Representation;
25  
26  /**
27   * Controller to respond to open / save requests. Not active
28   * in the present version (no server side yet)
29   */
30  public class RepresentationController extends ControllerBase implements ICommandHistoryListener {
31  	private Representation _representation;
32  	private boolean _persisted;
33  	private ControllerPushButton _saveButton;
34  
35  	public RepresentationController(RepApplication app) {
36  		super(app);
37  		_app.getHistory().addCommandHistoryListener(this);
38  		
39  		_representation = new Representation(Representation.DEFAULT_DRAWING_WIDTH, Representation.DEFAULT_DRAWING_HEIGHT, "");
40  		
41  		_saveButton = new ControllerPushButton(_app.getView(), _app.getIcons().saveIcon().createImage(), _app.getIcons().saveDisabledIcon().createImage(), _app.getConstants().saveCommand(), new ControllerBase(_app) {
42  			@Override
43  			public void activate(DrawingView view) {
44  				save();
45  			}
46  		}); 
47  				
48  		refresh();
49  	}
50  	
51  	public void commandHistoryChange(CommandHistory commandHistory) {
52  		refresh();	
53  	}
54  	
55  	private void refresh() {
56  		_saveButton.setEnabled(_persisted && _app.getHistory().needsSaving());
57  	}
58  	
59  	public void open() {
60  	}
61  	
62  	public void save() {
63  	}
64  	
65  	public ControllerPushButton getSaveButton() {
66  		return _saveButton;
67  	}
68  
69  	public Representation getCurrentRep() {
70  		return _representation;
71  	}
72  	
73  }