Revision 33030
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/LayerFactory.java | ||
---|---|---|
147 | 147 |
try{ |
148 | 148 |
Class layerClass = this.getLayerClassFor(dataStore); |
149 | 149 |
if (layerClass == null) { |
150 |
throw new LoadLayerException("No_layer_class_to_use", |
|
151 |
new Exception()); |
|
150 |
throw new CantRetrieveLayerByStoreException(layerName,dataStore.getName()); |
|
152 | 151 |
} |
153 | 152 |
FLayer layer; |
154 | 153 |
try { |
... | ... | |
159 | 158 |
throw new LoadLayerException(layerName, e); |
160 | 159 |
} |
161 | 160 |
|
161 |
layer.setName(layerName); |
|
162 | 162 |
((SingleLayer) layer).setDataStore(dataStore); |
163 |
layer.setName(layerName); |
|
164 | 163 |
IProjection proj = (IProjection)dataStore.getDynValue(FeatureStore.METADATA_CRS); |
165 | 164 |
if (proj != null) { |
166 | 165 |
layer.setProjection(proj); |
167 | 166 |
} |
168 |
|
|
169 |
|
|
170 | 167 |
return layer; |
171 | 168 |
} catch (Exception e) { |
172 | 169 |
throw new LoadLayerException(layerName,e); |
173 | 170 |
} |
174 | 171 |
} |
172 |
|
|
173 |
private class CantRetrieveLayerByStoreException extends LoadLayerException { |
|
175 | 174 |
|
175 |
/** |
|
176 |
* |
|
177 |
*/ |
|
178 |
private static final long serialVersionUID = 1442450896900126712L; |
|
179 |
|
|
180 |
CantRetrieveLayerByStoreException(String layerName, String storeName) { |
|
181 |
super( |
|
182 |
"Can't retrieve the class leyer of %(layer) to use for store %(store).", |
|
183 |
null, |
|
184 |
"_Cant_retrieve_the_class_leyer_of_XlayerX_to_use_for_store_XstoreX", |
|
185 |
serialVersionUID |
|
186 |
); |
|
187 |
setValue("layer", layerName); |
|
188 |
setValue("store", storeName); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
176 | 192 |
} |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java | ||
---|---|---|
68 | 68 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
69 | 69 |
*/ |
70 | 70 |
public class DefaultMapContextManager implements MapContextManager { |
71 |
private static final Logger logger = LoggerFactory.getLogger(MapContextManager.class);
|
|
71 |
private static final Logger LOG = LoggerFactory.getLogger(MapContextManager.class);
|
|
72 | 72 |
|
73 | 73 |
private Class drawerClazz = DefaultMapContextDrawer.class; |
74 | 74 |
|
... | ... | |
220 | 220 |
layer.initialize(projection); |
221 | 221 |
layer.setLegend((IVectorLegend)createLegend(IVectorialUniqueValueLegend.LEGEND_NAME)); |
222 | 222 |
} catch (Exception e) { |
223 |
logger.error("Error initializing the graphics layer", e);
|
|
223 |
LOG.error("Error initializing the graphics layer", e);
|
|
224 | 224 |
} |
225 | 225 |
return layer; |
226 | 226 |
} |
... | ... | |
264 | 264 |
|
265 | 265 |
public IVectorLegend createDefaultVectorLegend(int shapeType) |
266 | 266 |
throws MapContextRuntimeException { |
267 |
Random rand = new Random(); |
|
268 |
|
|
269 |
int numreg = rand.nextInt(255 / 2); |
|
270 |
double div = (1 - rand.nextDouble() * 0.66) * 0.9; |
|
271 |
Color randomColor = new Color(((int) (255 * div + (numreg * rand |
|
272 |
.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
|
273 |
.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
|
274 |
.nextDouble()))) % 255); |
|
275 |
IVectorLegend legend = (IVectorLegend) createLegend(getDefaultVectorLegend()); |
|
276 |
|
|
277 |
ISymbol defaultSymbol = |
|
278 |
getSymbolManager().createSymbol(shapeType, randomColor); |
|
279 |
legend.setDefaultSymbol(defaultSymbol); |
|
280 |
return legend; |
|
267 |
try { |
|
268 |
Random rand = new Random(); |
|
269 |
|
|
270 |
int numreg = rand.nextInt(255 / 2); |
|
271 |
double div = (1 - rand.nextDouble() * 0.66) * 0.9; |
|
272 |
Color randomColor = new Color(((int) (255 * div + (numreg * rand |
|
273 |
.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
|
274 |
.nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
|
275 |
.nextDouble()))) % 255); |
|
276 |
IVectorLegend legend = (IVectorLegend) createLegend(getDefaultVectorLegend()); |
|
277 |
if( legend == null ) { |
|
278 |
return null; |
|
279 |
} |
|
280 |
ISymbol defaultSymbol = |
|
281 |
getSymbolManager().createSymbol(shapeType, randomColor); |
|
282 |
legend.setDefaultSymbol(defaultSymbol); |
|
283 |
return legend; |
|
284 |
} catch(Exception e) { |
|
285 |
throw new MapContextRuntimeException(e); |
|
286 |
} |
|
281 | 287 |
} |
282 | 288 |
|
283 | 289 |
public void registerLegendReader(String format, Class readerClass) |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/LegendLayerException.java | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
public class LegendLayerException extends LoadLayerException { |
8 | 8 |
|
9 |
public LegendLayerException(String l,Throwable exception) { |
|
10 |
super(l,exception); |
|
11 |
init(); |
|
12 |
} |
|
13 | 9 |
/** |
14 |
* |
|
10 |
*
|
|
15 | 11 |
*/ |
16 |
private void init() { |
|
17 |
messageKey = "error_legend_layer"; |
|
18 |
formatString = "Can?t load legend of the layer: %(layer) "; |
|
12 |
private static final long serialVersionUID = -4033030636689365030L; |
|
13 |
|
|
14 |
protected LegendLayerException(String message, Throwable cause, String key, |
|
15 |
long code) { |
|
16 |
super(message, cause, key, code); |
|
17 |
} |
|
18 |
|
|
19 |
public LegendLayerException(String layer,Throwable cause) { |
|
20 |
super( |
|
21 |
"Can?t load the legend for layer %(layer).", |
|
22 |
cause, |
|
23 |
"Cant_load_the_legend_for_layer_XlayerX", |
|
24 |
serialVersionUID |
|
25 |
); |
|
26 |
setValue("layer", layer); |
|
19 | 27 |
} |
20 |
|
|
28 |
|
|
29 |
public LegendLayerException(String layer) { |
|
30 |
this(layer,null); |
|
31 |
} |
|
32 |
|
|
21 | 33 |
} |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/exceptions/LoadLayerException.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.mapcontext.exceptions; |
2 | 2 |
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import org.gvsig.tools.exception.BaseException; |
|
3 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
7 | 4 |
/** |
8 | 5 |
* @author Vicente Caballero Navarro |
9 | 6 |
*/ |
10 |
public class LoadLayerException extends BaseException { |
|
11 |
private String layer = null; |
|
7 |
public class LoadLayerException extends MapContextException { |
|
8 |
/** |
|
9 |
* |
|
10 |
*/ |
|
11 |
private static final long serialVersionUID = -7500729722899605739L; |
|
12 | 12 |
|
13 |
public LoadLayerException(String layer,Throwable exception) {
|
|
14 |
this.layer = layer;
|
|
15 |
init();
|
|
16 |
initCause(exception);
|
|
17 |
} |
|
13 |
protected LoadLayerException(String message, Throwable cause, String key,
|
|
14 |
long code) {
|
|
15 |
super(message, cause, key, code);
|
|
16 |
}
|
|
17 |
|
|
18 | 18 |
|
19 |
private void init() { |
|
20 |
messageKey = "error_load_layer"; |
|
21 |
formatString = "Can?t load the layer: %(layer) "; |
|
19 |
public LoadLayerException(String layer,Throwable cause) { |
|
20 |
super( |
|
21 |
"Can?t load the layer %(layer).", |
|
22 |
cause, |
|
23 |
"Cant_load_the_layer_XlayerX", |
|
24 |
serialVersionUID |
|
25 |
); |
|
26 |
setValue("layer", layer); |
|
22 | 27 |
} |
23 | 28 |
|
24 |
protected Map values() { |
|
25 |
Map params = new HashMap(); |
|
26 |
if (layer!=null) |
|
27 |
params.put("layer",layer); |
|
28 |
return params; |
|
29 |
|
|
30 |
public LoadLayerException(String layer) { |
|
31 |
super( |
|
32 |
"Can?t load the layer %(layer).", |
|
33 |
"Cant_load_the_layer_XlayerX", |
|
34 |
serialVersionUID |
|
35 |
); |
|
36 |
setValue("layer", layer); |
|
29 | 37 |
} |
30 |
|
|
38 |
|
|
39 |
|
|
31 | 40 |
} |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContextException.java | ||
---|---|---|
40 | 40 |
/** |
41 | 41 |
* @see BaseException#BaseException(String, String, long) |
42 | 42 |
*/ |
43 |
public MapContextException(String message, String key, long code) {
|
|
43 |
protected MapContextException(String message, String key, long code) {
|
|
44 | 44 |
super(message, key, code); |
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
/** |
48 | 48 |
* @see BaseException#BaseException(String, Throwable, String, long) |
49 | 49 |
*/ |
50 |
public MapContextException(String message, Throwable cause, String key,
|
|
50 |
protected MapContextException(String message, Throwable cause, String key,
|
|
51 | 51 |
long code) { |
52 | 52 |
super(message, cause, key, code); |
53 | 53 |
} |
54 | 54 |
|
55 |
public MapContextException(Throwable cause) { |
|
56 |
this( |
|
57 |
"MapContext related error", |
|
58 |
cause, |
|
59 |
"_MapContext_related_error", |
|
60 |
serialVersionUID |
|
61 |
); |
|
62 |
} |
|
55 | 63 |
} |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContextRuntimeException.java | ||
---|---|---|
34 | 34 |
* |
35 | 35 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
36 | 36 |
*/ |
37 |
public abstract class MapContextRuntimeException extends BaseRuntimeException {
|
|
37 |
public class MapContextRuntimeException extends BaseRuntimeException { |
|
38 | 38 |
|
39 | 39 |
private static final long serialVersionUID = 3993964182701795153L; |
40 | 40 |
|
41 | 41 |
/** |
42 | 42 |
* @see BaseException#BaseException(String, String, long) |
43 | 43 |
*/ |
44 |
public MapContextRuntimeException(String message, String key, long code) {
|
|
45 |
super(message, key, code); |
|
44 |
protected MapContextRuntimeException(String message, String key, long code) {
|
|
45 |
super(message, null, key, code);
|
|
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
/** |
49 | 49 |
* @see BaseException#BaseException(String, Throwable, String, long) |
50 | 50 |
*/ |
51 |
public MapContextRuntimeException(String message, Throwable cause, String key,
|
|
51 |
protected MapContextRuntimeException(String message, Throwable cause, String key,
|
|
52 | 52 |
long code) { |
53 | 53 |
super(message, cause, key, code); |
54 | 54 |
} |
55 |
|
|
55 |
|
|
56 |
public MapContextRuntimeException(Throwable cause) { |
|
57 |
this( |
|
58 |
"MapContext related error", |
|
59 |
cause, |
|
60 |
"_MapContext_related_error", |
|
61 |
serialVersionUID |
|
62 |
); |
|
63 |
} |
|
56 | 64 |
} |
Also available in: Unified diff