svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.impl / src / main / java / org / gvsig / symbology / swing / impl / DefaultSymbologySwingManager.java @ 43215
History | View | Annotate | Download (9.74 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.symbology.swing.impl; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.Collection; |
27 |
import java.util.Collections; |
28 |
import java.util.HashMap; |
29 |
import java.util.Iterator; |
30 |
import java.util.List; |
31 |
import java.util.Map; |
32 |
import org.gvsig.app.gui.labeling.LabelClassEditor; |
33 |
import org.gvsig.app.gui.labeling.LabelClassEditorFactory; |
34 |
|
35 |
import org.gvsig.app.gui.styling.TypeSymbolEditor; |
36 |
import org.gvsig.app.project.documents.view.legend.gui.ILabelingStrategyPanel; |
37 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
39 |
import org.gvsig.fmap.geom.type.GeometryType; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
41 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
42 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClassFactory; |
43 |
import org.gvsig.gui.ColorTablePainter; |
44 |
import org.gvsig.gui.ColorTablesFactory; |
45 |
import org.gvsig.gui.DefaultColorTablesFactory; |
46 |
import org.gvsig.symbology.SymbologyLocator; |
47 |
import org.gvsig.symbology.SymbologyManager; |
48 |
import org.gvsig.symbology.swing.SymbologySwingManager; |
49 |
import org.gvsig.symbology.swing.SymbologyWindowManager; |
50 |
import org.gvsig.tools.ToolsLocator; |
51 |
import org.gvsig.tools.i18n.I18nManager; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
/**
|
56 |
* Default implementation of the {@link SymbologySwingManager}.
|
57 |
*
|
58 |
* @author gvSIG Team
|
59 |
* @version $Id$
|
60 |
*/
|
61 |
public class DefaultSymbologySwingManager implements |
62 |
SymbologySwingManager { |
63 |
|
64 |
private static final Logger logger = LoggerFactory.getLogger(DefaultSymbologySwingManager.class); |
65 |
|
66 |
private SymbologyManager manager;
|
67 |
private I18nManager i18nmanager = null; |
68 |
private SymbologyWindowManager windowManager;
|
69 |
private ColorTablesFactory colorTablesFactory;
|
70 |
|
71 |
private static Map<Integer, List<Class<? extends TypeSymbolEditor>>> symbolEditorRegistry; |
72 |
private List<Class<? extends ILegendPanel>> legendEditorRegistry = null; |
73 |
private List<Class<? extends ILabelingStrategyPanel>> labelingEditorRegistry = null; |
74 |
private Map<String,LabelClassEditorFactory> labelClassEditorFactories = new HashMap<String, LabelClassEditorFactory>(); |
75 |
|
76 |
public DefaultSymbologySwingManager() {
|
77 |
this.manager = SymbologyLocator.getSymbologyManager();
|
78 |
this.windowManager = new DefaultSymbologyWindowManager(); |
79 |
this.colorTablesFactory = new DefaultColorTablesFactory(); |
80 |
|
81 |
this.legendEditorRegistry = new ArrayList<Class<? extends ILegendPanel>>(); |
82 |
this.labelingEditorRegistry = new ArrayList<Class<? extends ILabelingStrategyPanel>>(); |
83 |
} |
84 |
|
85 |
public SymbologyManager getManager() {
|
86 |
return this.manager; |
87 |
} |
88 |
|
89 |
public String getTranslation(String key) { |
90 |
if (this.i18nmanager == null) { |
91 |
this.i18nmanager = ToolsLocator.getI18nManager();
|
92 |
} |
93 |
return this.i18nmanager.getTranslation(key); |
94 |
} |
95 |
|
96 |
public void registerWindowManager(SymbologyWindowManager manager) { |
97 |
this.windowManager = manager;
|
98 |
} |
99 |
|
100 |
public SymbologyWindowManager getWindowManager() {
|
101 |
return this.windowManager; |
102 |
} |
103 |
|
104 |
public void setColorTablesFactory(ColorTablesFactory factory) { |
105 |
colorTablesFactory = factory; |
106 |
} |
107 |
|
108 |
public List<ColorTablePainter> createColorTables() { |
109 |
if (colorTablesFactory != null) { |
110 |
return colorTablesFactory.createColorTables();
|
111 |
} |
112 |
return null; |
113 |
} |
114 |
|
115 |
public ColorTablesFactory getColorTablesFactory() {
|
116 |
return this.colorTablesFactory; |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @deprecated use registerTypeSymbolEditor
|
121 |
*/
|
122 |
public void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) { |
123 |
Class<? extends TypeSymbolEditor> symbolEditor = abstractTypeSymbolEditorPanelClass; |
124 |
this.registerSymbolEditor(symbolEditor, shapeType);
|
125 |
} |
126 |
|
127 |
public void registerSymbolEditor(Class<? extends TypeSymbolEditor> symbolEditor, int shapeType) { |
128 |
if (symbolEditorRegistry == null) { |
129 |
symbolEditorRegistry = new HashMap<Integer, List<Class<? extends TypeSymbolEditor>>>(); |
130 |
} |
131 |
|
132 |
Integer key = new Integer(shapeType); |
133 |
List<Class<? extends TypeSymbolEditor>> l = symbolEditorRegistry.get(key); |
134 |
if (l == null) { |
135 |
l = new ArrayList<Class<? extends TypeSymbolEditor>>(); |
136 |
} |
137 |
l.add(symbolEditor); |
138 |
|
139 |
symbolEditorRegistry.put(key, l); |
140 |
} |
141 |
|
142 |
public List<Class<? extends TypeSymbolEditor>> getSymbolEditorClassesByGeometryType(GeometryType geometryType) { |
143 |
if (symbolEditorRegistry == null) { |
144 |
return Collections.emptyList(); |
145 |
} |
146 |
Iterator it = symbolEditorRegistry.keySet().iterator();
|
147 |
while (it.hasNext()) {
|
148 |
int currentType = (Integer) it.next(); |
149 |
if (geometryType.isTypeOf(currentType)) {
|
150 |
return (List) symbolEditorRegistry.get(currentType); |
151 |
} |
152 |
} |
153 |
return Collections.emptyList(); |
154 |
} |
155 |
|
156 |
public void registerLegendEditor(Class<? extends ILegendPanel> legendEditor) { |
157 |
if (this.legendEditorRegistry == null) { |
158 |
this.legendEditorRegistry = new ArrayList<Class<? extends ILegendPanel>>(); |
159 |
} |
160 |
if (!this.legendEditorRegistry.contains(legendEditor)) { |
161 |
this.legendEditorRegistry.add(legendEditor);
|
162 |
} |
163 |
} |
164 |
|
165 |
public List<Class<? extends ILegendPanel>> getLegendEditorClasses() { |
166 |
return Collections.unmodifiableList(this.legendEditorRegistry); |
167 |
} |
168 |
|
169 |
public List<ILegendPanel> getLegendEditors(FLayer layer) { |
170 |
List<ILegendPanel> editors = new ArrayList<ILegendPanel>(); |
171 |
Class<? extends ILegendPanel> legendEditorClass = null; |
172 |
ILegendPanel editor = null;
|
173 |
|
174 |
for (int i = 0; i < legendEditorRegistry.size(); i++) { |
175 |
legendEditorClass = legendEditorRegistry.get(i); |
176 |
try {
|
177 |
editor = null;
|
178 |
editor = (ILegendPanel) legendEditorClass.newInstance(); |
179 |
} catch (Exception e) { |
180 |
logger.info("Unable to instantiate legend editor.", e);
|
181 |
} |
182 |
if( layer.isAvailable() ) {
|
183 |
if (editor != null && editor.isSuitableFor(layer)) { |
184 |
editors.add(editor); |
185 |
} |
186 |
} else {
|
187 |
try {
|
188 |
if (editor != null && editor.isSuitableFor(layer)) { |
189 |
editors.add(editor); |
190 |
} |
191 |
} catch(Throwable th) { |
192 |
|
193 |
} |
194 |
} |
195 |
} |
196 |
return editors;
|
197 |
} |
198 |
|
199 |
public void registerLabelingEditor(Class<? extends ILabelingStrategyPanel> labelingEditor) { |
200 |
if (!this.labelingEditorRegistry.contains(labelingEditor)) { |
201 |
this.labelingEditorRegistry.add(labelingEditor);
|
202 |
} |
203 |
} |
204 |
|
205 |
public List<ILabelingStrategyPanel> getLabelingEditors() { |
206 |
List<ILabelingStrategyPanel> labelingEditors = new ArrayList<ILabelingStrategyPanel>(); |
207 |
Iterator<Class<? extends ILabelingStrategyPanel>> it = this.labelingEditorRegistry.iterator(); |
208 |
while (it.hasNext()) {
|
209 |
Class<? extends ILabelingStrategyPanel> labelingEditorClass = it.next(); |
210 |
try {
|
211 |
ILabelingStrategyPanel labelingEditor = labelingEditorClass.newInstance(); |
212 |
labelingEditors.add(labelingEditor); |
213 |
} catch (Exception ex) { |
214 |
String msg = "Can't create the labeling editor associated to '"+labelingEditorClass.getName()+"'."; |
215 |
logger.warn(msg,ex); |
216 |
throw new RuntimeException(msg,ex); |
217 |
} |
218 |
} |
219 |
return labelingEditors;
|
220 |
} |
221 |
|
222 |
public void registerLabelClassEditor(LabelClassEditorFactory factory) { |
223 |
this.labelClassEditorFactories.put(factory.getID().toLowerCase(), factory);
|
224 |
} |
225 |
|
226 |
public Collection<LabelClassEditorFactory> getLabelClassEditorFactories() { |
227 |
return Collections.unmodifiableCollection( this.labelClassEditorFactories.values()); |
228 |
} |
229 |
|
230 |
public LabelClassEditorFactory getLabelClassEditorFactory(String id) { |
231 |
if( id==null ) { |
232 |
return null; |
233 |
} |
234 |
return this.labelClassEditorFactories.get(id.toLowerCase()); |
235 |
} |
236 |
|
237 |
public LabelClassEditorFactory getLabelClassEditorFactory(ILabelClass labelClass) {
|
238 |
Iterator<LabelClassEditorFactory> it = this.labelClassEditorFactories.values().iterator(); |
239 |
while( it.hasNext() ) {
|
240 |
LabelClassEditorFactory labelClassEditorFactory = it.next(); |
241 |
if( labelClassEditorFactory!=null && labelClassEditorFactory.accept(labelClass.getClass()) ) { |
242 |
return labelClassEditorFactory;
|
243 |
} |
244 |
} |
245 |
return null; |
246 |
} |
247 |
|
248 |
public LabelClassEditor createLabelClassEditor(ILabelClass labelClass, FeatureStore store) {
|
249 |
LabelClassEditorFactory f = this.getLabelClassEditorFactory(labelClass);
|
250 |
if( f == null ) { |
251 |
return null; |
252 |
} |
253 |
return f.createEditor(labelClass, store);
|
254 |
} |
255 |
|
256 |
} |