Revision 6287 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.fmap.mapcontext.raster/org.gvsig.fmap.mapcontext.raster.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/impl/DefaultRasterLayer.java
DefaultRasterLayer.java | ||
---|---|---|
23 | 23 |
package org.gvsig.fmap.mapcontext.raster.impl; |
24 | 24 |
|
25 | 25 |
import java.awt.Graphics2D; |
26 |
import java.awt.image.BandCombineOp; |
|
26 | 27 |
import java.awt.image.BufferedImage; |
27 | 28 |
import java.util.Observable; |
28 | 29 |
import java.util.Observer; |
... | ... | |
42 | 43 |
import org.gvsig.fmap.geom.GeometryManager; |
43 | 44 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
44 | 45 |
import org.gvsig.fmap.geom.primitive.Envelope; |
46 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
47 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
45 | 48 |
import org.gvsig.fmap.mapcontext.ViewPort; |
49 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
|
46 | 50 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
47 | 51 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
48 | 52 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
49 | 53 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLegendChangedListener; |
54 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
55 |
import org.gvsig.fmap.mapcontext.rendering.legend.IRasterLegend; |
|
56 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
50 | 57 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
|
52 | 58 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
54 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
55 | 59 |
import org.gvsig.metadata.exceptions.MetadataException; |
60 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
|
61 |
import org.gvsig.raster.lib.legend.api.ColorInterpretation; |
|
56 | 62 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
63 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
|
64 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
|
57 | 65 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.evaluator.Evaluator; |
|
59 | 66 |
import org.gvsig.tools.exception.BaseException; |
60 | 67 |
import org.gvsig.tools.task.Cancellable; |
61 | 68 |
import org.gvsig.tools.task.SimpleTaskStatus; |
... | ... | |
83 | 90 |
* Creates a new DefaultRasterLayer |
84 | 91 |
* @param store |
85 | 92 |
* @param legend |
93 |
* @throws |
|
86 | 94 |
*/ |
95 |
public DefaultRasterLayer() throws LoadLayerException{ |
|
96 |
super(); |
|
97 |
// MapContextManager mapContextManager |
|
98 |
// = MapContextLocator.getMapContextManager(); |
|
99 |
//Set the legend |
|
100 |
// IRasterLegend legend |
|
101 |
// = (IRasterLegend) mapContextManager.getLegend(store); |
|
102 |
|
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Creates a new DefaultRasterLayer |
|
107 |
* @param store |
|
108 |
* @param legend |
|
109 |
*/ |
|
87 | 110 |
public DefaultRasterLayer(RasterStore store, RasterLegend legend){ |
88 | 111 |
super(); |
89 | 112 |
this.store=store; |
90 | 113 |
this.legend=legend; |
91 | 114 |
} |
92 | 115 |
|
116 |
|
|
117 |
public void setLegend(RasterLegend legend) throws LegendLayerException { |
|
118 |
if (this.legend == legend) { |
|
119 |
return; |
|
120 |
} |
|
121 |
if (this.legend != null && this.legend.equals(legend)) { |
|
122 |
return; |
|
123 |
} |
|
124 |
RasterLegend oldLegend = this.legend; |
|
125 |
this.legend = legend; |
|
126 |
if (oldLegend != null) { |
|
127 |
//oldLegend.removeLegendListener( this); |
|
128 |
//oldLegend.deleteDrawingObserver(this); |
|
129 |
} |
|
130 |
if (legend != null) { |
|
131 |
//this.legend.addDrawingObserver(this); |
|
132 |
//this.legend.addLegendListener( this); |
|
133 |
} |
|
134 |
// LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, this.legend); |
|
135 |
// e.setLayer(this); |
|
136 |
updateDrawVersion(); |
|
137 |
// callLegendChanged(e); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* Devuelve la Leyenda de la capa. |
|
142 |
* |
|
143 |
* @return Leyenda. |
|
144 |
*/ |
|
145 |
public RasterLegend getLegend() { |
|
146 |
|
|
147 |
return legend; |
|
148 |
} |
|
149 |
|
|
93 | 150 |
@Override |
94 | 151 |
public DataStore getDataStore() { |
95 | 152 |
return this.store; |
... | ... | |
101 | 158 |
throw new LoadLayerException("Store already created"); |
102 | 159 |
}else{ |
103 | 160 |
this.store=(RasterStore)dataStore; |
161 |
if(legend==null){ |
|
162 |
RasterLegendManager legendManager = |
|
163 |
RasterLegendLocator.getRasterLegendManager(); |
|
164 |
int bandCount; |
|
165 |
try { |
|
166 |
bandCount = store.getRasterSet().getBandCount(); |
|
167 |
} catch (DataException e) { |
|
168 |
throw new LegendLayerException(this.getName()); |
|
169 |
} |
|
170 |
|
|
171 |
String colors; |
|
172 |
switch (bandCount) { |
|
173 |
case 1: |
|
174 |
colors = ColorInterpretation.GRAYSCALE; |
|
175 |
break; |
|
176 |
case 3: |
|
177 |
colors = ColorInterpretation.RGB; |
|
178 |
break; |
|
179 |
case 4: |
|
180 |
colors = ColorInterpretation.ARGB; |
|
181 |
break; |
|
182 |
default: |
|
183 |
colors = ColorInterpretation.RGB; |
|
184 |
break; |
|
185 |
} |
|
186 |
if (bandCount == 3) { |
|
187 |
|
|
188 |
} |
|
189 |
ColorInterpretation colorInterpretation = |
|
190 |
legendManager.createColorInterpretation(colors); |
|
191 |
RasterLegend legend = |
|
192 |
legendManager.createLegend(colorInterpretation); |
|
193 |
|
|
194 |
if (legend == null) { |
|
195 |
throw new LegendLayerException(this.getName()); |
|
196 |
} |
|
197 |
|
|
198 |
this.setLegend(legend); |
|
199 |
} |
|
104 | 200 |
} |
105 | 201 |
} |
106 | 202 |
|
... | ... | |
159 | 255 |
TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
160 | 256 |
SimpleTaskStatus taskStatus = manager.createDefaultSimpleTaskStatus("Draw "+getDataStore().getName()); |
161 | 257 |
|
162 |
legend.draw(g, getRasterStore().getRasterSet(rasterQuery), viewPort, taskStatus);
|
|
258 |
((RasterLegend) legend).draw(g, getRasterStore().getRasterSet(rasterQuery), viewPort, taskStatus);
|
|
163 | 259 |
|
164 | 260 |
logger.debug("Layer " + this.getName() + " drawn in " |
165 | 261 |
+ (System.currentTimeMillis() - tini) + " milliseconds."); |
Also available in: Unified diff