svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / AbstractLegend.java @ 40560
History | View | Annotate | Download (6.7 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
|
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.
|
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.
|
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.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
25 |
|
26 |
import java.lang.ref.Reference; |
27 |
import java.util.ArrayList; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
31 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.dynobject.DynStruct; |
38 |
import org.gvsig.tools.observer.Observer; |
39 |
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable; |
40 |
import org.gvsig.tools.persistence.PersistenceManager; |
41 |
import org.gvsig.tools.persistence.PersistentState; |
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
43 |
import org.gvsig.tools.util.Callable; |
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
/**
|
48 |
* Abstract class that implements the interface for legends.It is considered as
|
49 |
* the father of all XXXLegends and will implement all the methods that these
|
50 |
* classes had not developed.
|
51 |
*
|
52 |
* @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
|
53 |
* @author 2008 - pepe vidal salvador - jose.vidal.salvador@iver.es
|
54 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
55 |
*/
|
56 |
public abstract class AbstractLegend implements ILegend { |
57 |
|
58 |
public static final String LEGEND_PERSISTENCE_DEFINITION_NAME = "Legend"; |
59 |
|
60 |
// private static final String FIELD_LISTENERS = "listeners";
|
61 |
//
|
62 |
// private static final String FIELD_OBSERVABLE = "observable";
|
63 |
|
64 |
private static final Logger LOG = |
65 |
LoggerFactory.getLogger(AbstractLegend.class); |
66 |
|
67 |
/**
|
68 |
* List of LegendContentsChangedListener.
|
69 |
*/
|
70 |
private List<LegendContentsChangedListener> listeners = |
71 |
new ArrayList<LegendContentsChangedListener>(); |
72 |
|
73 |
private BaseWeakReferencingObservable delegateDrawingObservable =
|
74 |
new BaseWeakReferencingObservable();
|
75 |
|
76 |
private MapContextManager manager = MapContextLocator.getMapContextManager();
|
77 |
|
78 |
public MapContextManager getManager() {
|
79 |
return manager;
|
80 |
} |
81 |
|
82 |
public SymbolManager getSymbolManager() {
|
83 |
return manager.getSymbolManager();
|
84 |
} |
85 |
|
86 |
public void addLegendListener(LegendContentsChangedListener listener) { |
87 |
if (listener != null && !listeners.contains(listener)) |
88 |
listeners.add(listener); |
89 |
} |
90 |
|
91 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
92 |
listeners.remove(listener); |
93 |
} |
94 |
|
95 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
96 |
|
97 |
for (int i = 0; i < listeners.size(); i++) { |
98 |
((LegendContentsChangedListener) listeners.get(i)) |
99 |
.symbolChanged(event); |
100 |
} |
101 |
} |
102 |
|
103 |
public LegendContentsChangedListener[] getListeners() { |
104 |
return (LegendContentsChangedListener[]) listeners |
105 |
.toArray(new LegendContentsChangedListener[listeners.size()]);
|
106 |
} |
107 |
|
108 |
public void addDrawingObserver(Observer observer) { |
109 |
delegateDrawingObservable.addObserver(observer); |
110 |
} |
111 |
|
112 |
public void deleteDrawingObserver(Observer observer) { |
113 |
delegateDrawingObservable.deleteObserver(observer); |
114 |
} |
115 |
|
116 |
public void deleteDrawingObservers() { |
117 |
delegateDrawingObservable.deleteObservers(); |
118 |
} |
119 |
|
120 |
public void addObserver(Reference<Observer> ref) { |
121 |
delegateDrawingObservable.addObserver(ref); |
122 |
} |
123 |
|
124 |
public void beginComplexNotification() { |
125 |
delegateDrawingObservable.beginComplexNotification(); |
126 |
} |
127 |
|
128 |
public int countObservers() { |
129 |
return delegateDrawingObservable.countObservers();
|
130 |
} |
131 |
|
132 |
public void deleteObserver(Reference<Observer> ref) { |
133 |
delegateDrawingObservable.deleteObserver(ref); |
134 |
} |
135 |
|
136 |
public void disableNotifications() { |
137 |
delegateDrawingObservable.disableNotifications(); |
138 |
} |
139 |
|
140 |
public void enableNotifications() { |
141 |
delegateDrawingObservable.enableNotifications(); |
142 |
} |
143 |
|
144 |
public void endComplexNotification() { |
145 |
delegateDrawingObservable.endComplexNotification(); |
146 |
} |
147 |
|
148 |
public boolean inComplex() { |
149 |
return delegateDrawingObservable.inComplex();
|
150 |
} |
151 |
|
152 |
public boolean isEnabledNotifications() { |
153 |
return delegateDrawingObservable.isEnabledNotifications();
|
154 |
} |
155 |
|
156 |
public void notifyObservers() { |
157 |
delegateDrawingObservable.notifyObservers(); |
158 |
} |
159 |
|
160 |
public void notifyObservers(Object arg) { |
161 |
delegateDrawingObservable.notifyObservers(arg); |
162 |
} |
163 |
|
164 |
public ILegend cloneLegend() {
|
165 |
try {
|
166 |
return (ILegend) clone();
|
167 |
} catch (CloneNotSupportedException e) { |
168 |
LOG.error("Error creating the clone of the legend: " + this, e); |
169 |
} |
170 |
return null; |
171 |
} |
172 |
|
173 |
public Object clone() throws CloneNotSupportedException { |
174 |
AbstractLegend legendClone = (AbstractLegend) super.clone();
|
175 |
|
176 |
return legendClone;
|
177 |
} |
178 |
|
179 |
public void loadFromState(PersistentState state) |
180 |
throws PersistenceException {
|
181 |
// Do nothing
|
182 |
} |
183 |
|
184 |
public void saveToState(PersistentState state) throws PersistenceException { |
185 |
// Do nothing
|
186 |
} |
187 |
|
188 |
public static class RegisterPersistence implements Callable { |
189 |
|
190 |
public Object call() throws Exception { |
191 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
192 |
if( manager.getDefinition(LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
193 |
@SuppressWarnings("unused") |
194 |
DynStruct definition = manager.addDefinition( |
195 |
AbstractLegend.class, |
196 |
LEGEND_PERSISTENCE_DEFINITION_NAME, |
197 |
LEGEND_PERSISTENCE_DEFINITION_NAME + " persistence definition",
|
198 |
null,
|
199 |
null
|
200 |
); |
201 |
// // Listeners
|
202 |
// definition.addDynFieldList(FIELD_LISTENERS)
|
203 |
// .setClassOfItems(LegendContentsChangedListener.class);
|
204 |
// // Observable
|
205 |
// definition.addDynFieldObject(FIELD_OBSERVABLE)
|
206 |
// .setClassOfValue(BaseWeakReferencingObservable.class);
|
207 |
} |
208 |
return Boolean.TRUE; |
209 |
} |
210 |
|
211 |
} |
212 |
|
213 |
} |