View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal 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   * svgreal 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 svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.command;
19  
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.vectomatic.svg.edit.client.command.edit.EditManipulatorBase;
24  import org.vectomatic.svg.edit.client.command.edit.EditTransformManipulator;
25  import org.vectomatic.svg.edit.client.model.ModelCategory;
26  import org.vectomatic.svg.edit.client.model.ModelConstants;
27  import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
28  
29  /**
30   * Command factory to record changes in the svg transform attribute of an element.
31   * @author laaglu
32   */
33  public class EditTransformCommandFactory extends ManipulatorCommandFactoryBase {
34  	@SuppressWarnings("serial")
35  	public static final IFactoryInstantiator<EditTransformCommandFactory> INSTANTIATOR = new FactoryInstantiatorBase<EditTransformCommandFactory>(ModelConstants.INSTANCE.transformCmdFactory(), ModelConstants.INSTANCE.transformCmdFactoryDesc()) {
36  		@Override
37  		public EditTransformCommandFactory create() {
38  			return new EditTransformCommandFactory();
39  		}
40  	};
41  	
42  	public EditTransformCommandFactory() {
43  		ModelConstants constants = ModelConstants.INSTANCE;
44  		state1 = constants.transformCmdFactory1();
45  		state2 = constants.transformCmdFactory2();
46  		filter = new IModelFilter() {
47  
48  			@Override
49  			public boolean accept(List<SVGElementModel> models) {
50  				return models.size() == 1 && models.get(0).getMetaModel().getCategory(ModelCategory.TRANSFORM) != null;
51  			}			
52  		};
53  	}
54  
55  	@Override
56  	public IFactoryInstantiator<?> getInstantiator() {
57  		return INSTANTIATOR;
58  	}
59  
60  	@Override
61  	protected ICommand createCommand(SVGElementModel model, Map<String, Object> changes) {
62  		return new EditTransformCommand(this, model, changes);
63  	}
64  	@Override
65  	protected EditManipulatorBase getManipulator(SVGElementModel model) {
66  		return EditTransformManipulator.INSTANCE;
67  	}
68  
69  }