View Javadoc

1   /**********************************************
2    * Copyright (C) 2011, 2012 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.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.vectomatic.svg.edit.client.command.edit.EditCircleGeometryManipulator;
25  import org.vectomatic.svg.edit.client.command.edit.EditEllipseGeometryManipulator;
26  import org.vectomatic.svg.edit.client.command.edit.EditImageGeometryManipulator;
27  import org.vectomatic.svg.edit.client.command.edit.EditLineGeometryManipulator;
28  import org.vectomatic.svg.edit.client.command.edit.EditManipulatorBase;
29  import org.vectomatic.svg.edit.client.command.edit.EditPathGeometryManipulator;
30  import org.vectomatic.svg.edit.client.command.edit.EditRectGeometryManipulator;
31  import org.vectomatic.svg.edit.client.command.edit.EditSVGPointsManipulator;
32  import org.vectomatic.svg.edit.client.command.edit.EditUseGeometryManipulator;
33  import org.vectomatic.svg.edit.client.command.edit.EditViewBoxGeometryManipulator;
34  import org.vectomatic.svg.edit.client.model.MetaModel;
35  import org.vectomatic.svg.edit.client.model.ModelCategory;
36  import org.vectomatic.svg.edit.client.model.ModelConstants;
37  import org.vectomatic.svg.edit.client.model.svg.SVGCircleElementModel;
38  import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
39  import org.vectomatic.svg.edit.client.model.svg.SVGEllipseElementModel;
40  import org.vectomatic.svg.edit.client.model.svg.SVGImageElementModel;
41  import org.vectomatic.svg.edit.client.model.svg.SVGLineElementModel;
42  import org.vectomatic.svg.edit.client.model.svg.SVGPathElementModel;
43  import org.vectomatic.svg.edit.client.model.svg.SVGPolygonElementModel;
44  import org.vectomatic.svg.edit.client.model.svg.SVGPolylineElementModel;
45  import org.vectomatic.svg.edit.client.model.svg.SVGRectElementModel;
46  import org.vectomatic.svg.edit.client.model.svg.SVGUseElementModel;
47  import org.vectomatic.svg.edit.client.model.svg.SVGViewBoxElementModel;
48  
49  /**
50   * Class to edit the attributes belonging to the geometry model category
51   * @author laaglu
52   */
53  public class EditGeometryCommandFactory extends ManipulatorCommandFactoryBase {
54  	@SuppressWarnings("serial")
55  	public static final IFactoryInstantiator<EditGeometryCommandFactory> INSTANTIATOR = new FactoryInstantiatorBase<EditGeometryCommandFactory>(ModelConstants.INSTANCE.editGeometryCmdFactory(), ModelConstants.INSTANCE.editGeometryCmdFactoryDesc()) {
56  		@Override
57  		public EditGeometryCommandFactory create() {
58  			return new EditGeometryCommandFactory();
59  		}
60  	};
61  	protected static Map<MetaModel<?>, EditManipulatorBase> metaModelToManipulator;
62  	
63  	public EditGeometryCommandFactory() {
64  		ModelConstants constants = ModelConstants.INSTANCE;
65  		state1 = constants.editGeometryCmdFactory1();
66  		state2 = constants.editGeometryCmdFactory2();
67  		filter = new IModelFilter() {
68  			@Override
69  			public boolean accept(List<SVGElementModel> models) {
70  				return models.size() == 1 && models.get(0).getMetaModel().getCategory(ModelCategory.GEOMETRY) != null;
71  			}			
72  		};
73  	}
74  	
75  	@Override
76  	public IFactoryInstantiator<?> getInstantiator() {
77  		return INSTANTIATOR;
78  	}
79  
80  	@Override
81  	protected ICommand createCommand(SVGElementModel model, Map<String, Object> changes) {
82  		return new GenericEditCommand(this, model, changes, ModelConstants.INSTANCE.editGeometryCmd());
83  	}
84  	
85  	@Override
86  	protected EditManipulatorBase getManipulator(SVGElementModel model) {
87  		if (metaModelToManipulator == null) {
88  			metaModelToManipulator = new HashMap<MetaModel<?>, EditManipulatorBase>();
89  			metaModelToManipulator.put(SVGLineElementModel.getLineElementMetaModel(), new EditLineGeometryManipulator());
90  			metaModelToManipulator.put(SVGCircleElementModel.getCircleElementMetaModel(), new EditCircleGeometryManipulator());
91  			metaModelToManipulator.put(SVGEllipseElementModel.getEllipseElementMetaModel(), new EditEllipseGeometryManipulator());
92  			metaModelToManipulator.put(SVGRectElementModel.getRectElementMetaModel(), new EditRectGeometryManipulator());
93  			metaModelToManipulator.put(SVGPolygonElementModel.getPolygonElementMetaModel(), new EditSVGPointsManipulator());
94  			metaModelToManipulator.put(SVGPolylineElementModel.getPolylineElementMetaModel(), new EditSVGPointsManipulator());
95  			metaModelToManipulator.put(SVGViewBoxElementModel.getViewBoxElementMetaModel(), new EditViewBoxGeometryManipulator());
96  			metaModelToManipulator.put(SVGPathElementModel.getPathElementMetaModel(), new EditPathGeometryManipulator());
97  			metaModelToManipulator.put(SVGPathElementModel.getPathElementMetaModel(), new EditPathGeometryManipulator());
98  			metaModelToManipulator.put(SVGImageElementModel.getImageElementMetaModel(), new EditImageGeometryManipulator());
99  			metaModelToManipulator.put(SVGUseElementModel.getUseElementMetaModel(), new EditUseGeometryManipulator());
100 		}
101 		MetaModel<?> metaModel = model.getMetaModel();
102 		assert(metaModel != null);
103 		return metaModelToManipulator.get(metaModel);
104 	}
105 }