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 @ 43326
History | View | Annotate | Download (6.21 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 |
*/
|
53 |
public abstract class AbstractLegend implements ILegend { |
54 |
|
55 |
public static final String LEGEND_PERSISTENCE_DEFINITION_NAME = "Legend"; |
56 |
|
57 |
private static final Logger LOG = |
58 |
LoggerFactory.getLogger(AbstractLegend.class); |
59 |
|
60 |
/**
|
61 |
* List of LegendContentsChangedListener.
|
62 |
*/
|
63 |
private final List<LegendContentsChangedListener> listeners = new ArrayList<>(); |
64 |
|
65 |
private final BaseWeakReferencingObservable delegateDrawingObservable = new BaseWeakReferencingObservable(); |
66 |
|
67 |
private final MapContextManager manager = MapContextLocator.getMapContextManager(); |
68 |
|
69 |
public MapContextManager getManager() {
|
70 |
return manager;
|
71 |
} |
72 |
|
73 |
public SymbolManager getSymbolManager() {
|
74 |
return manager.getSymbolManager();
|
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void addLegendListener(LegendContentsChangedListener listener) { |
79 |
if (listener != null && !listeners.contains(listener)) { |
80 |
listeners.add(listener); |
81 |
} |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
86 |
listeners.remove(listener); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
91 |
|
92 |
for (int i = 0; i < listeners.size(); i++) { |
93 |
((LegendContentsChangedListener) listeners.get(i)) |
94 |
.symbolChanged(event); |
95 |
} |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public LegendContentsChangedListener[] getListeners() { |
100 |
return (LegendContentsChangedListener[]) listeners |
101 |
.toArray(new LegendContentsChangedListener[listeners.size()]);
|
102 |
} |
103 |
|
104 |
public void addDrawingObserver(Observer observer) { |
105 |
delegateDrawingObservable.addObserver(observer); |
106 |
} |
107 |
|
108 |
public void deleteDrawingObserver(Observer observer) { |
109 |
delegateDrawingObservable.deleteObserver(observer); |
110 |
} |
111 |
|
112 |
public void deleteDrawingObservers() { |
113 |
delegateDrawingObservable.deleteObservers(); |
114 |
} |
115 |
|
116 |
public void addObserver(Reference<Observer> ref) { |
117 |
delegateDrawingObservable.addObserver(ref); |
118 |
} |
119 |
|
120 |
public void beginComplexNotification() { |
121 |
delegateDrawingObservable.beginComplexNotification(); |
122 |
} |
123 |
|
124 |
public int countObservers() { |
125 |
return delegateDrawingObservable.countObservers();
|
126 |
} |
127 |
|
128 |
public void deleteObserver(Reference<Observer> ref) { |
129 |
delegateDrawingObservable.deleteObserver(ref); |
130 |
} |
131 |
|
132 |
public void disableNotifications() { |
133 |
delegateDrawingObservable.disableNotifications(); |
134 |
} |
135 |
|
136 |
public void enableNotifications() { |
137 |
delegateDrawingObservable.enableNotifications(); |
138 |
} |
139 |
|
140 |
public void endComplexNotification() { |
141 |
delegateDrawingObservable.endComplexNotification(); |
142 |
} |
143 |
|
144 |
public boolean inComplex() { |
145 |
return delegateDrawingObservable.inComplex();
|
146 |
} |
147 |
|
148 |
public boolean isEnabledNotifications() { |
149 |
return delegateDrawingObservable.isEnabledNotifications();
|
150 |
} |
151 |
|
152 |
public void notifyObservers() { |
153 |
delegateDrawingObservable.notifyObservers(); |
154 |
} |
155 |
|
156 |
public void notifyObservers(Object arg) { |
157 |
delegateDrawingObservable.notifyObservers(arg); |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public ILegend cloneLegend() {
|
162 |
try {
|
163 |
return (ILegend) clone();
|
164 |
} catch (CloneNotSupportedException e) { |
165 |
LOG.error("Error creating the clone of the legend: " + this, e); |
166 |
} |
167 |
return null; |
168 |
} |
169 |
|
170 |
@Override
|
171 |
public Object clone() throws CloneNotSupportedException { |
172 |
AbstractLegend legendClone = (AbstractLegend) super.clone();
|
173 |
|
174 |
return legendClone;
|
175 |
} |
176 |
|
177 |
@Override
|
178 |
public void loadFromState(PersistentState state) |
179 |
throws PersistenceException {
|
180 |
// Do nothing
|
181 |
} |
182 |
|
183 |
@Override
|
184 |
public void saveToState(PersistentState state) throws PersistenceException { |
185 |
// Do nothing
|
186 |
} |
187 |
|
188 |
public static class RegisterPersistence implements Callable { |
189 |
|
190 |
@Override
|
191 |
public Object call() throws Exception { |
192 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
193 |
if( manager.getDefinition(LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
194 |
@SuppressWarnings("unused") |
195 |
DynStruct definition = manager.addDefinition( |
196 |
AbstractLegend.class, |
197 |
LEGEND_PERSISTENCE_DEFINITION_NAME, |
198 |
LEGEND_PERSISTENCE_DEFINITION_NAME + " persistence definition",
|
199 |
null,
|
200 |
null
|
201 |
); |
202 |
} |
203 |
return Boolean.TRUE; |
204 |
} |
205 |
|
206 |
} |
207 |
|
208 |
} |