Revision 41400 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

View differences:

DefaultSymbologySwingManager.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
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 10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
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 15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
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.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.symbology.swing.impl;
25 24

  
25
import java.util.ArrayList;
26
import java.util.Collections;
27
import java.util.HashMap;
28
import java.util.Iterator;
26 29
import java.util.List;
30
import java.util.Map;
31
import java.util.logging.Level;
27 32

  
28 33
import org.gvsig.app.gui.styling.SymbolEditor;
34
import org.gvsig.app.gui.styling.TypeSymbolEditor;
35
import org.gvsig.app.project.documents.view.legend.gui.ILabelingStrategyPanel;
36
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
37
import org.gvsig.fmap.geom.type.GeometryType;
38
import org.gvsig.fmap.mapcontext.layers.FLayer;
39
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
29 40
import org.gvsig.gui.ColorTablePainter;
30 41
import org.gvsig.gui.ColorTablesFactory;
31 42
import org.gvsig.gui.DefaultColorTablesFactory;
......
33 44
import org.gvsig.symbology.SymbologyManager;
34 45
import org.gvsig.symbology.swing.SymbologySwingManager;
35 46
import org.gvsig.symbology.swing.SymbologyWindowManager;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.i18n.I18nManager;
49
import org.slf4j.Logger;
50
import org.slf4j.LoggerFactory;
36 51

  
37 52
/**
38 53
 * Default implementation of the {@link SymbologySwingManager}.
39
 * 
54
 *
40 55
 * @author gvSIG Team
41 56
 * @version $Id$
42 57
 */
43 58
public class DefaultSymbologySwingManager implements
44
    SymbologySwingManager {
59
        SymbologySwingManager {
45 60

  
61
    private static final Logger logger = LoggerFactory.getLogger(DefaultSymbologySwingManager.class);
62

  
46 63
    private SymbologyManager manager;
47
    // private I18nManager i18nmanager = null;
64
    private I18nManager i18nmanager = null;
48 65
    private SymbologyWindowManager windowManager;
49 66
    private ColorTablesFactory colorTablesFactory;
50 67

  
68
    private static Map<Integer, List<Class<? extends TypeSymbolEditor>>> symbolEditorRegistry;
69
    private List<Class<? extends ILegendPanel>> legendEditorRegistry = null;
70
    private List<Class<? extends ILabelingStrategyPanel>> labelingEditorRegistry = null;
71

  
51 72
    public DefaultSymbologySwingManager() {
52 73
        this.manager = SymbologyLocator.getSymbologyManager();
53
        // this.i18nmanager = ToolsLocator.getI18nManager();
54 74
        this.windowManager = new DefaultSymbologyWindowManager();
55
        colorTablesFactory = new DefaultColorTablesFactory();
75
        this.colorTablesFactory = new DefaultColorTablesFactory();
76

  
77
        this.legendEditorRegistry = new ArrayList<Class<? extends ILegendPanel>>();
78
        this.labelingEditorRegistry = new ArrayList<Class<? extends ILabelingStrategyPanel>>();
56 79
    }
57 80

  
58 81
    public SymbologyManager getManager() {
......
60 83
    }
61 84

  
62 85
    public String getTranslation(String key) {
63
        // TODO: add I18nManager usage when org.gvsig.tools.lib 2.1.0 becomes
64
        // available
65
        // return this.i18nmanager.getTranslation(key);
66
        return key;
86
        if (this.i18nmanager == null) {
87
            this.i18nmanager = ToolsLocator.getI18nManager();
88
        }
89
        return this.i18nmanager.getTranslation(key);
67 90
    }
68 91

  
69 92
    public void registerWindowManager(SymbologyWindowManager manager) {
......
73 96
    public SymbologyWindowManager getWindowManager() {
74 97
        return this.windowManager;
75 98
    }
76
    
77
	@SuppressWarnings("rawtypes")
78
	public void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) {
79
		SymbolEditor.addSymbolEditorPanel(abstractTypeSymbolEditorPanelClass, shapeType);
80
	}
81 99

  
82
	public void setColorTablesFactory(ColorTablesFactory factory) {
83
		colorTablesFactory = factory;
84
	}
100
    public void setColorTablesFactory(ColorTablesFactory factory) {
101
        colorTablesFactory = factory;
102
    }
85 103

  
86
	public List<ColorTablePainter> createColorTables() {
87
		if (colorTablesFactory != null){
88
		    return colorTablesFactory.createColorTables();
89
		}
90
		return null;
91
	}
92
	
93
	public ColorTablesFactory getColorTablesFactory() {
94
		return this.colorTablesFactory;
95
	}
104
    public List<ColorTablePainter> createColorTables() {
105
        if (colorTablesFactory != null) {
106
            return colorTablesFactory.createColorTables();
107
        }
108
        return null;
109
    }
110

  
111
    public ColorTablesFactory getColorTablesFactory() {
112
        return this.colorTablesFactory;
113
    }
114

  
115
    /**
116
     * @deprecated use registerTypeSymbolEditor
117
     */
118
    public void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) {
119
        Class<? extends TypeSymbolEditor> symbolEditor = abstractTypeSymbolEditorPanelClass;
120
        this.registerSymbolEditor(symbolEditor, shapeType);
121
    }
122

  
123
    public void registerSymbolEditor(Class<? extends TypeSymbolEditor> symbolEditor, int shapeType) {
124
        if (symbolEditorRegistry == null) {
125
            symbolEditorRegistry = new HashMap<Integer, List<Class<? extends TypeSymbolEditor>>>();
126
        }
127

  
128
        Integer key = new Integer(shapeType);
129
        List<Class<? extends TypeSymbolEditor>> l = symbolEditorRegistry.get(key);
130
        if (l == null) {
131
            l = new ArrayList<Class<? extends TypeSymbolEditor>>();
132
        }
133
        l.add(symbolEditor);
134

  
135
        symbolEditorRegistry.put(key, l);
136
    }
137

  
138
    public List<Class<? extends TypeSymbolEditor>> getSymbolEditorClassesByGeometryType(GeometryType geometryType) {
139
        if (symbolEditorRegistry == null) {
140
            return Collections.emptyList();
141
        }
142
        Iterator it = symbolEditorRegistry.keySet().iterator();
143
        while (it.hasNext()) {
144
            int currentType = (Integer) it.next();
145
            if (geometryType.isTypeOf(currentType)) {
146
                return (List) symbolEditorRegistry.get(currentType);
147
            }
148
        }
149
        return Collections.emptyList();
150
    }
151

  
152
    public void registerLegendEditor(Class<? extends ILegendPanel> legendEditor) {
153
        if (this.legendEditorRegistry == null) {
154
            this.legendEditorRegistry = new ArrayList<Class<? extends ILegendPanel>>();
155
        }
156
        if (!this.legendEditorRegistry.contains(legendEditor)) {
157
            this.legendEditorRegistry.add(legendEditor);
158
        }
159
    }
160

  
161
    public List<Class<? extends ILegendPanel>> getLegendEditorClasses() {
162
        return Collections.unmodifiableList(this.legendEditorRegistry);
163
    }
164

  
165
    public List<ILegendPanel> getLegendEditors(FLayer layer) {
166
        List<ILegendPanel> editors = new ArrayList<ILegendPanel>();
167
        Class<? extends ILegendPanel> legendEditorClass = null;
168
        ILegendPanel editor = null;
169

  
170
        for (int i = 0; i < legendEditorRegistry.size(); i++) {
171
            legendEditorClass = legendEditorRegistry.get(i);
172
            try {
173
                editor = null;
174
                editor = (ILegendPanel) legendEditorClass.newInstance();
175
            } catch (Exception e) {
176
                logger.info("Unable to instantiate legend editor.", e);
177
            }
178
            if (editor != null && editor.isSuitableFor(layer)) {
179
                editors.add(editor);
180
            }
181
        }
182
        return editors;
183
    }
184

  
185
    public void registerLabelingEditor(Class<? extends ILabelingStrategyPanel> labelingEditor) {
186
        if (!this.labelingEditorRegistry.contains(labelingEditor)) {
187
            this.labelingEditorRegistry.add(labelingEditor);
188
        }
189
    }
190

  
191
    public List<ILabelingStrategyPanel> getLabelingEditors() {
192
        List<ILabelingStrategyPanel> labelingEditors = new ArrayList<ILabelingStrategyPanel>();
193
        Iterator<Class<? extends ILabelingStrategyPanel>> it = this.labelingEditorRegistry.iterator();
194
        while (it.hasNext()) {
195
            Class<? extends ILabelingStrategyPanel> labelingEditorClass = it.next();
196
            try {
197
                ILabelingStrategyPanel labelingEditor = labelingEditorClass.newInstance();
198
                labelingEditors.add(labelingEditor);
199
            } catch (Exception ex) {
200
                String msg = "Can't create the labeling editor associated to '"+labelingEditorClass.getName()+"'.";
201
                logger.warn(msg,ex);
202
                throw new RuntimeException(msg,ex);
203
            }
204
        }
205
        return labelingEditors;
206
    }
207

  
96 208
}

Also available in: Unified diff