Revision 38581

View differences:

branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContextManager.java
364 364
	ILabelingStrategy getLabelingStrategy(DataStore dataStore);
365 365

  
366 366

  
367
	void registerIconLayer(String store, String iconName);
368
	
369
	String getIconLayer(DataStore store);
370
	
367 371
    // TODO:
368 372
    // DynObjectModel getFeatureTypeUIModel(DataStore store,
369 373
    // FeatureType featureType);
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java
143 143
    public FLyrVect() {
144 144
        super();
145 145
    }
146
    
147
	public String getTocImageIcon() {
148
		return MapContextLocator.getMapContextManager().getIconLayer(this.getDataStore());
149
	}
146 150

  
147 151
    /**
148 152
     * Devuelve el VectorialAdapater de la capa.
......
156 160
        return featureStore;
157 161
    }
158 162
    
159
//    public void setCoordTrans(ICoordTrans ct) {
160
//    	super.setCoordTrans(ct);
161
//    	if (ct != null){
162
//    		if (this.reprojectTransform == null){
163
//    			this.reprojectTransform = new ReprojectDefaultGeometry(ct);
164
//    		} else {
165
//    			this.reprojectTransform.setCoordTrans(ct);
166
//    		}
167
//    		try {
168
//    			this.getFeatureStore().getTransforms().add(this.reprojectTransform);
169
//    		} catch (DataException e) {
170
//    			throw new RuntimeException(e);
171
//    		}
172
//    	}
173
//    }
174

  
175 163
    /**
176
     * If we use a persistent spatial index associated with this layer, and the
177
     * index is not intrisic to the layer (for example spatial databases) this
178
     * method looks for existent spatial index, and loads it.
164
     * Inserta el DataStore a la capa.
179 165
     * 
180
     */
181
    // private void loadSpatialIndex() {
182
    // //FIXME: Al abrir el indice en fichero...
183
    // //?C?mo lo liberamos? un metodo Layer.shutdown()
184
    //
185
    //
186
    // ReadableVectorial source = getSource();
187
    // //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
188
    // //PUES SON VECTORIALFILEADAPTER
189
    // if (!(source instanceof VectorialFileAdapter)) {
190
    // // we are not interested in db adapters
191
    // return;
192
    // }
193
    // VectorialDriver driver = source.getDriver();
194
    // if (!(driver instanceof BoundedShapes)) {
195
    // // we dont spatially index layers that are not bounded
196
    // return;
197
    // }
198
    // File file = ((VectorialFileAdapter) source).getFile();
199
    // String fileName = file.getAbsolutePath();
200
    // File sptFile = new File(fileName + ".qix");
201
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
202
    // // before to exit, look for it in temp path
203
    // String tempPath = System.getProperty("java.io.tmpdir");
204
    // fileName = tempPath + File.separator + sptFile.getName();
205
    // sptFile = new File(fileName);
206
    // // it doesnt exists, must to create
207
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
208
    // return;
209
    // }// if
210
    // }// if
211
    //
212
    // try {
213
    // source.start();
214
    // spatialIndex = new
215
    // QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
216
    // "NM", source.getFullExtent(), source.getShapeCount(), false);
217
    // source.setSpatialIndex(spatialIndex);
218
    // } catch (SpatialIndexException e) {
219
    // spatialIndex = null;
220
    // e.printStackTrace();
221
    // return;
222
    // } catch (ReadDriverException e) {
223
    // spatialIndex = null;
224
    // e.printStackTrace();
225
    // return;
226
    // }
227
    //
228
    // }
229

  
230
    /**
231
     * Checks if it has associated an external spatial index
232
     * (an spatial index file).
233
     * 
234
     * It looks for it in main file path, or in temp system path.
235
     * If main file is rivers.shp, it looks for a file called
236
     * rivers.shp.qix.
237
     * 
238
     * @return
239
     */
240
    // public boolean isExternallySpatiallyIndexed() {
241
    // /*
242
    // * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
243
    // * con el que se trabaje (ahora mismo considera la extension .qix,
244
    // * pero esto depender? del tipo de ?ndice)
245
    // * */
246
    // ReadableVectorial source = getSource();
247
    // if (!(source instanceof VectorialFileAdapter)) {
248
    // // we are not interested in db adapters.
249
    // // think in non spatial dbs, like HSQLDB
250
    // return false;
251
    // }
252
    // File file = ((VectorialFileAdapter) source).getFile();
253
    // String fileName = file.getAbsolutePath();
254
    // File sptFile = new File(fileName + ".qix");
255
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
256
    // // before to exit, look for it in temp path
257
    // // it doesnt exists, must to create
258
    // String tempPath = System.getProperty("java.io.tmpdir");
259
    // fileName = tempPath + File.separator + sptFile.getName();
260
    // sptFile = new File(fileName);
261
    // if (!sptFile.exists() || (!(sptFile.length() > 0))) {
262
    // return false;
263
    // }// if
264
    // }// if
265
    // return true;
266
    // }
267
    /**
268
     * Inserta el VectorialAdapter a la capa.
269
     * 
270 166
     * @param va
271 167
     *            VectorialAdapter.
272 168
     * 
......
336 232
        	rAux = rAux.convert(ct);
337 233
        }
338 234
        return rAux;
235

  
339 236
    }
340 237

  
341 238
    /**
......
439 336
        }
440 337
    }
441 338

  
442
    /**
443
     * <p>
444
     * Creates an spatial index associated to this layer. The spatial index will
445
     * used the native projection of the layer, so if the layer is reprojected,
446
     * it will be ignored.
447
     * </p>
448
     * 
449
     * @param cancelMonitor
450
     *            instance of CancellableMonitorable that allows
451
     *            to monitor progress of spatial index creation, and cancel the
452
     *            process
453
     */
454
    // public void createSpatialIndex(CancellableMonitorable cancelMonitor){
455
    // // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
456
    // // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
457
    // // para que acepten recorrer sin geometria, solo con rectangulos.
458
    //
459
    // //If this vectorial layer is based in a spatial database, the spatial
460
    // //index is already implicit. We only will index file drivers
461
    // ReadableVectorial va = getSource();
462
    // //We must think in non spatial databases, like HSQLDB
463
    // if(!(va instanceof VectorialFileAdapter)){
464
    // return;
465
    // }
466
    // if (!(va.getDriver() instanceof BoundedShapes)) {
467
    // return;
468
    // }
469
    // File file = ((VectorialFileAdapter) va).getFile();
470
    // String fileName = file.getAbsolutePath();
471
    // ISpatialIndex localCopy = null;
472
    // try {
473
    // va.start();
474
    // localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
475
    // va.getShapeCount(), true);
476
    //
477
    // } catch (SpatialIndexException e1) {
478
    // // Probably we dont have writing permissions
479
    // String directoryName = System.getProperty("java.io.tmpdir");
480
    // File newFile = new File(directoryName +
481
    // File.separator +
482
    // file.getName());
483
    // String newFileName = newFile.getName();
484
    // try {
485
    // localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
486
    // va.getShapeCount(), true);
487
    // } catch (SpatialIndexException e) {
488
    // // if we cant build a file based spatial index, we'll build
489
    // // a pure memory spatial index
490
    // localCopy = new QuadtreeJts();
491
    // } catch (ReadException e) {
492
    // localCopy = new QuadtreeJts();
493
    // }
494
    //
495
    // } catch(Exception e){
496
    // e.printStackTrace();
497
    // }//try
498
    // BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
499
    // try {
500
    // for (int i=0; i < va.getShapeCount(); i++)
501
    // {
502
    // if(cancelMonitor != null){
503
    // if(cancelMonitor.isCanceled())
504
    // return;
505
    // cancelMonitor.reportStep();
506
    // }
507
    // Rectangle2D r = shapeBounds.getShapeBounds(i);
508
    // if(r != null)
509
    // localCopy.insert(r, i);
510
    // } // for
511
    // va.stop();
512
    // if(localCopy instanceof IPersistentSpatialIndex)
513
    // ((IPersistentSpatialIndex) localCopy).flush();
514
    // spatialIndex = localCopy;
515
    // //vectorial adapter needs a reference to the spatial index, to solve
516
    // //request for feature iteration based in spatial queries
517
    // source.setSpatialIndex(spatialIndex);
518
    // } catch (ReadException e) {
519
    // // TODO Auto-generated catch block
520
    // e.printStackTrace();
521
    // }
522
    // }
523

  
524
    // public void createSpatialIndex() {
525
    // createSpatialIndex(null);
526
    // }
527

  
528 339
    public void setLegend(IVectorLegend legend) throws LegendLayerException {
529 340
        if (this.legend == legend) {
530 341
            return;
......
633 444
        state.set("typeShape", typeShape);
634 445
    }
635 446

  
636
    // public XMLEntity getXMLEntity() throws XMLException {
637
    //
638
    // if (!this.isAvailable() && this.orgXMLEntity != null) {
639
    // return this.orgXMLEntity;
640
    // }
641
    // XMLEntity xml = super.getXMLEntity();
642
    // if (getLegend()!=null){
643
    // XMLEntity xmlLegend=getLegend().getXMLEntity();
644
    // xmlLegend.putProperty("tagName","legend");
645
    // xml.addChild(xmlLegend);
646
    // }
647
    // try {
648
    // PersistenceManager manager = ToolsLocator.getPersistenceManager();
649
    // PersistentState stateFeatureStore=manager.getState(getFeatureStore());
650
    // stateFeatureStore.set("tagName","featureStore");
651
    // xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
652
    // } catch (ReadException e) {
653
    // throw new XMLLayerException(getName(),e);
654
    // } catch (PersistenceException e) {
655
    // throw new XMLLayerException(getName(),e);
656
    // }
657
    // // properties from ILabelable
658
    // xml.putProperty("isLabeled", isLabeled);
659
    // if (strategy != null) {
660
    // XMLEntity strategyXML = strategy.getXMLEntity();
661
    // strategyXML.putProperty("tagName", "labelingStrategy");
662
    // xml.addChild(strategy.getXMLEntity());
663
    // }
664
    // xml.addChild(getLinkProperties().getXMLEntity());
665
    // return xml;
666
    // }
667 447

  
668 448
    public void loadFromState(PersistentState state) throws PersistenceException {
669 449

  
......
716 496
            this.setLabelingStrategy(null);
717 497
        }
718 498

  
719
        // try {
720
        // linkProperties = (FLyrVectLinkProperties)
721
        // state.get("linkProperties");
722
        // } catch (PersistenceException pex) {
723
        // // not mandatory
724
        // linkProperties = null;
725
        // }
726

  
727
        // bHasJoin = state.getBoolean("bHasJoin");
728 499
        typeShape = state.getInt("typeShape");
729 500

  
730
        // try { _labelFieldName = state.getString("labelFieldName"); } catch
731
        // (PersistenceException ex) {
732
        // _labelFieldName = null;
733
        // }
734
        // try { _labelfield = state.getString("labelfield"); } catch
735
        // (PersistenceException ex) {
736
        // _labelfield = null;
737
        // }
738

  
739
        // ILabelingStrategy not implemented
740
        // if (_labelFieldName != null) {
741
        //
742
        // AttrInTableLabelingStrategy labeling = new
743
        // AttrInTableLabelingStrategy();
744
        // try {
745
        // labeling.setLayer(this);
746
        // } catch (ReadException e) {
747
        // logger.error("While setting layer to AttrInTableLabelingStrategy: " +
748
        // e.getMessage());
749
        // }
750
        // labeling.setUsesFixedSize(true);
751
        // labeling.setFixedSize(10);
752
        // labeling.setTextField(_labelFieldName);
753
        // labeling.setHeightField(state.getString("labelHeightFieldName"));
754
        // labeling.setRotationField(state.getString("labelRotationFieldName"));
755
        // setLabelingStrategy(labeling);
756
        // setIsLabeled(true);
757
        //
758
        // } else {
759
        // if (_labelfield != null) {
760
        //
761
        // AttrInTableLabelingStrategy labeling = new
762
        // AttrInTableLabelingStrategy();
763
        // try {
764
        // labeling.setLayer(this);
765
        // } catch (ReadException e) {
766
        // logger.error("While setting layer to AttrInTableLabelingStrategy: " +
767
        // e.getMessage());
768
        // }
769
        // labeling.setUsesFixedSize(true);
770
        // labeling.setFixedSize(10);
771
        // labeling.setTextField(_labelfield);
772
        // labeling.setHeightField(state.getString("labelFieldHeight"));
773
        // labeling.setRotationField(state.getString("labelFieldRotation"));
774
        // setLabelingStrategy(labeling);
775
        // setIsLabeled(true);
776
        // }
777
        // }
778

  
779 501
    }
780 502

  
781
    // public void setXMLEntity(XMLEntity xml) throws XMLException {
782
    // try {
783
    // super.setXMLEntity(xml);
784
    // XMLEntity legendXML = xml.firstChild("tagName","legend");
785
    // IVectorLegend leg = LegendFactory.createFromXML(legendXML);
786
    //
787
    // // PersistentState persistentState=new XMLEntityState(new
788
    // XMLEntityManager());
789
    // XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
790
    // XMLEntityManager xmlManger = new XMLEntityManager();
791
    // PersistentState state = xmlManger.createState(xmlStore);
792
    // DataStore store = (DataStore)
793
    // ToolsLocator.getPersistenceManager().create(state);
794
    // // persistentState.createState(xmlStore);
795
    //
796
    // // DataManager dm=DALLocator.getDataManager();
797
    //
798
    // this.setDataStore(store);
799
    // /* end patch */
800
    // try {
801
    // setLegend(leg);
802
    // } catch (LegendLayerException e) {
803
    // throw new XMLLegendException(e);
804
    // }
805
    // // set properties for ILabelable
806
    //
807
    // if (xml.contains("isLabeled")
808
    // && xml.getBooleanProperty(("isLabeled"))) {
809
    // XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
810
    // if (labelingXML != null){
811
    //
812
    // isLabeled = true;
813
    // try {
814
    // this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
815
    // } catch (NotExistInXMLEntity neXMLEX) {
816
    // // no strategy was set, just continue;
817
    // logger.warn("Reached what should be unreachable code");
818
    // }
819
    // } else {
820
    // isLabeled = false;
821
    // }
822
    // } else if (legendXML.contains("labelFieldName")||
823
    // legendXML.contains("labelfield")) {
824
    // /* (jaume) begin patch;
825
    // * for backward compatibility purposes. Since gvSIG v1.1 labeling is
826
    // * no longer managed by the Legend but by the ILabelingStrategy. The
827
    // * following allows restoring older projects' labelings.
828
    // */
829
    // String labelTextField = null;
830
    // if (legendXML.contains("labelFieldName")){
831
    // labelTextField = legendXML.getStringProperty("labelFieldName");
832
    // if (labelTextField != null) {
833
    // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
834
    // labeling.setLayer(this);
835
    // labeling.setUsesFixedSize(true);
836
    // labeling.setFixedSize(10);
837
    // labeling.setTextField(labelTextField);
838
    // labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
839
    // labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
840
    // this.setLabelingStrategy(labeling);
841
    // this.setIsLabeled(true);
842
    // }
843
    // }else{
844
    // labelTextField = legendXML.getStringProperty("labelfield");
845
    // if (labelTextField != null) {
846
    // AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
847
    // labeling.setLayer(this);
848
    // labeling.setUsesFixedSize(true);
849
    // labeling.setFixedSize(10);
850
    // labeling.setTextField(labelTextField);
851
    // labeling.setHeightField(legendXML.getStringProperty("labelFieldHeight"));
852
    // labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
853
    // this.setLabelingStrategy(labeling);
854
    // this.setIsLabeled(true);
855
    // }
856
    // }
857
    // }else{
858
    // isLabeled = false;
859
    // }
860
    // XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
861
    // if (xmlLinkProperties != null){
862
    // getLinkProperties().setXMLEntity(xmlLinkProperties);
863
    // }
864
    // } catch (Exception e) {
865
    // e.printStackTrace();
866
    // this.setAvailable(false);
867
    // this.orgXMLEntity = xml;
868
    //
869
    // }
870
    // //
871
    //
872
    // }
873

  
874 503
    /**
875 504
     * Sobreimplementaci?n del m?todo toString para que las bases de datos
876 505
     * identifiquen la capa.
......
887 516
        return "layer" + ret.substring(ret.indexOf('@') + 1);
888 517
    }
889 518

  
890
    // public boolean isJoined() {
891
    // return bHasJoin;
892
    // }
893

  
894
    /**
895
     * Returns if a layer is spatially indexed
896
     * 
897
     * @return if this layer has the ability to proces spatial queries without
898
     *         secuential scans.
899
     * @throws StopEditionLayerException 
900
     */
901
    // public boolean isSpatiallyIndexed() {
902
    // ReadableVectorial source = getSource();
903
    // if (source instanceof ISpatialDB)
904
    // return true;
905
    //
906
    // //FIXME azabala
907
    // /*
908
    // * Esto es muy dudoso, y puede cambiar.
909
    // * Estoy diciendo que las que no son fichero o no son
910
    // * BoundedShapes estan indexadas. Esto es mentira, pero
911
    // * as? quien pregunte no querr? generar el indice.
912
    // * Esta por ver si interesa generar el indice para capas
913
    // * HSQLDB, WFS, etc.
914
    // */
915
    // if(!(source instanceof VectorialFileAdapter)){
916
    // return true;
917
    // }
918
    // if (!(source.getDriver() instanceof BoundedShapes)) {
919
    // return true;
920
    // }
921
    //
922
    // if (getISpatialIndex() != null)
923
    // return true;
924
    // return false;
925
    // }
926
    //
927
    // public void setIsJoined(boolean hasJoin) {
928
    // bHasJoin = hasJoin;
929
    // }
930

  
931
    // /**
932
    // * @return Returns the spatialIndex.
933
    // */
934
    // public ISpatialIndex getISpatialIndex() {
935
    // return spatialIndex;
936
    // }
937
    // /**
938
    // * Sets the spatial index. This could be useful if, for some
939
    // * reasons, you want to work with a distinct spatial index
940
    // * (for example, a spatial index which could makes nearest
941
    // * neighbour querys)
942
    // * @param spatialIndex
943
    // */
944
    // public void setISpatialIndex(ISpatialIndex spatialIndex){
945
    // this.spatialIndex = spatialIndex;
946
    // }
947

  
948 519
    public void setEditing(boolean b) throws StartEditionLayerException {
949 520
        super.setEditing(b);
950 521
        FeatureStore fs = getFeatureStore();
......
1135 706
        return onePoint;
1136 707
    }
1137 708

  
1138
    /*
1139
     * jaume. Stuff from ILabeled.
1140
     */
1141

  
1142 709
    public boolean isLabeled() {
1143 710
        return isLabeled;
1144 711
    }
......
1181 748
        }
1182 749
    }
1183 750

  
1184
    // M?todos para el uso de HyperLinks en capas FLyerVect
1185

  
1186 751
    /**
1187 752
     * Return true, because a Vectorial Layer supports HyperLink
753
     * 
754
     * @deprecated the hiperlink functionaliti is out the layer now
1188 755
     */
1189 756
    public boolean allowLinks() {
1190
        return true;
757
        return false;
1191 758
    }
1192 759

  
1193
    /**
1194
     * Returns an instance of AbstractLinkProperties that contains the
1195
     * information
1196
     * of the HyperLink
1197
     * 
1198
     * @return Abstra
1199
     */
1200
    // public AbstractLinkProperties getLinkProperties()
1201
    // {
1202
    // return linkProperties;
1203
    // }
1204

  
1205
    /**
1206
     * Provides an array with URIs. Returns one URI by geometry that includes
1207
     * the point
1208
     * in its own geometry limits with a allowed tolerance.
1209
     * 
1210
     * @param layer
1211
     *            , the layer
1212
     * @param point
1213
     *            , the point to check that is contained or not in the
1214
     *            geometries in the layer
1215
     * @param tolerance
1216
     *            , the tolerance allowed. Allowed margin of error to detect if
1217
     *            the point
1218
     *            is contained in some geometries of the layer
1219
     * @return
1220
     * @throws ReadException
1221
     * @throws BehaviorException
1222
     */
1223
    // public URI[] getLink(Point2D point, double tolerance) throws
1224
    // ReadException
1225
    // {
1226
    // //return linkProperties.getLink(this)
1227
    // return linkProperties.getLink(this,point,tolerance);
1228
    // }
1229

  
1230 760
    public void load() throws LoadLayerException {
1231 761
        super.load();
1232 762
    }
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/FLyrDefault.java
54 54
import org.gvsig.fmap.dal.DataTypes;
55 55
import org.gvsig.fmap.dal.exception.ReadException;
56 56
import org.gvsig.fmap.mapcontext.MapContext;
57
import org.gvsig.fmap.mapcontext.MapContextLocator;
57 58
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
58 59
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
59 60
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
......
665 666
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
666 667
	 */
667 668
	public String getTocImageIcon() {
668
		return "toc-layer-group";
669
		return "layer-icon";
669 670
	}
671
	
670 672
	/*
671 673
	 * (non-Javadoc)
672 674
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/coerce/CoerceColorToString.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.mapcontext.tools.coerce;
23

  
24
import java.awt.Color;
25

  
26
import org.gvsig.fmap.geom.DataTypes;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dataTypes.CoercionException;
29
import org.gvsig.tools.dataTypes.DataTypesManager;
30
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
31

  
32
/**
33
 * Convert a Color to String.
34
 * 
35
 *  
36
 * @author gvSIG Team
37
 * @version $Id$
38
 * 
39
 */
40
public class CoerceColorToString implements Coercion {
41

  
42
	public CoerceColorToString() {
43
		// Do nothing
44
	}
45
	
46
	public Object coerce(Object value) throws CoercionException {
47
		try {
48
			if( value == null || value instanceof String ) {
49
				return value;
50
			}
51
			if( value instanceof Color ) {
52
				Color color = (Color) value;
53
				SimpleAttributesSerializer properties = new SimpleAttributesSerializer("Color");
54
				properties.put("red", new Integer(color.getRed()));
55
				properties.put("green", new Integer(color.getGreen()));
56
				properties.put("blue", new Integer(color.getBlue()));
57
				properties.put("alpha", new Integer(color.getAlpha()));
58
				return properties.toString();
59
			}
60
		} catch (Exception e) {
61
			throw new CoercionException(e);
62
		}
63
		throw new CoercionException();
64
	}
65

  
66
	public static void selfRegister() {
67
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
68
		if( dataTypesManager.getType("Color")== DataTypes.INVALID ) {
69
	        dataTypesManager.addtype(DataTypes.INVALID, null, "Color",Color.class, null);
70
		}
71
		int type = dataTypesManager.getType("Color");
72
        dataTypesManager.addCoercion(type, new CoerceStringToColor());
73
	}
74
}
75

  
0 76

  
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/coerce/CoerceStringToColor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.mapcontext.tools.coerce;
23

  
24
import java.awt.Color;
25

  
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dataTypes.CoercionException;
28
import org.gvsig.tools.dataTypes.DataTypesManager;
29
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
30

  
31
/**
32
 * Convert a Color to String.
33
 * 
34
 *  
35
 * @author gvSIG Team
36
 * @version $Id$
37
 * 
38
 */
39
public class CoerceStringToColor implements Coercion {
40

  
41
	public CoerceStringToColor() {
42
		// Do nothing
43
	}
44
	
45
	public Object coerce(Object value) throws CoercionException {
46
		try {
47
			if( value == null ) {
48
				return value;
49
			}
50
			if( value instanceof String ) {
51
				SimpleAttributesSerializer properties = new SimpleAttributesSerializer("Color");
52
				properties.load((String) value);
53
				int r = Integer.parseInt((String)(properties.get("red")));
54
				int g = Integer.parseInt((String)(properties.get("green")));
55
				int b = Integer.parseInt((String)(properties.get("blue")));
56
				int a = Integer.parseInt((String)(properties.get("alpha")));
57
				return new Color(r,g,b,a);
58
			}
59
		} catch (Exception e) {
60
			throw new CoercionException(e);
61
		}
62
		throw new CoercionException();
63
	}
64
	public static void selfRegister() {
65
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
66
		int id = dataTypesManager.getType("String");
67
        dataTypesManager.addCoercion(id, new CoerceStringToColor());
68
	}
69
}
70

  
0 71

  
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/coerce/SimpleAttributesSerializer.java
1
package org.gvsig.fmap.mapcontext.tools.coerce;
2

  
3
import java.util.HashMap;
4
import java.util.Iterator;
5
import java.util.Map;
6
import java.util.Map.Entry;
7

  
8
public class SimpleAttributesSerializer {
9
	Map values = null;
10
	String name = null;
11
	
12
	public SimpleAttributesSerializer(String name) {
13
		this.name = name;
14
		this.values = new HashMap();
15
	}
16
	
17
	public void put(String name, Object value) {
18
		this.values.put(name, value);
19
	}
20
	
21
	public Object get(String name) {
22
		return this.get(name);
23
	}
24
	
25
	public String toString() {
26
		StringBuffer buffer = null;
27
		Iterator it = this.values.entrySet().iterator();
28
		while( it.hasNext() ) {
29
			Entry entry = (Entry)(it.next());
30
			if( buffer==null ) {
31
				buffer = new StringBuffer();
32
				buffer.append(this.name).append(":");
33
			} else {
34
				buffer.append(";");
35
			}
36
			buffer.append(entry.getKey())
37
				.append("=")
38
				.append(entry.getValue())
39
				.append(";");
40
		}
41
		return buffer.toString();
42
	}
43
	
44
	public void load(String buffer) {
45
		if( ! buffer.startsWith(this.name+":") ) {
46
			return;
47
		}
48
		
49
		String[] pairs = buffer.substring(this.name.length()) .split(";");
50
		for( int i=0; i<pairs.length; i++ ) {
51
			String[] pair = pairs[i].split("=");
52
			if( pair.length==2 ) {
53
				this.values.put(pair[0].trim(), pair[1].trim());
54
			}
55
		}
56
	}
57
}
0 58

  
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/coerce/CoerceFontToString.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.mapcontext.tools.coerce;
23

  
24
import java.awt.Font;
25

  
26
import org.gvsig.fmap.geom.DataTypes;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dataTypes.CoercionException;
29
import org.gvsig.tools.dataTypes.DataTypesManager;
30
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
31

  
32
/**
33
 * Convert a Font to String.
34
 * 
35
 *  
36
 * @author gvSIG Team
37
 * @version $Id$
38
 * 
39
 */
40
public class CoerceFontToString implements Coercion {
41
	
42
	public CoerceFontToString() {
43
		// Do nothing
44
	}
45
	
46
	public Object coerce(Object value) throws CoercionException {
47
		try {
48
			if( value == null || value instanceof String ) {
49
				return value;
50
			}
51
			if( value instanceof Font ) {
52
				Font font = (Font) value;
53
				SimpleAttributesSerializer properties = new SimpleAttributesSerializer("Font");
54
				properties.put("name", font.getName());
55
				properties.put("style", new Integer(font.getStyle()));
56
				properties.put("size", new Integer(font.getSize()));
57
				return properties.toString();
58
			}
59
		} catch (Exception e) {
60
			throw new CoercionException(e);
61
		}
62
		throw new CoercionException();
63
	}
64

  
65
	public static void selfRegister() {
66
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
67
		if( dataTypesManager.getType("Font")== DataTypes.INVALID ) {
68
	        dataTypesManager.addtype(DataTypes.INVALID, null, "Font",Font.class, null);
69
		}
70
		int type = dataTypesManager.getType("Font");
71
        dataTypesManager.addCoercion(type, new CoerceStringToColor());
72
	}
73
}
74

  
0 75

  
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/coerce/CoerceStringToFont.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.mapcontext.tools.coerce;
23

  
24
import java.awt.Font;
25

  
26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.dataTypes.CoercionException;
28
import org.gvsig.tools.dataTypes.DataTypesManager;
29
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
30

  
31
/**
32
 * Convert a String to Font.
33
 * 
34
 *  
35
 * @author gvSIG Team
36
 * @version $Id$
37
 * 
38
 */
39
public class CoerceStringToFont implements Coercion {
40

  
41
	public CoerceStringToFont() {
42
		// Do nothing
43
	}
44
	
45
	public Object coerce(Object value) throws CoercionException {
46
		try {
47
			if( value == null ) {
48
				return value;
49
			}
50
			if( value instanceof String ) {
51
				SimpleAttributesSerializer properties = new SimpleAttributesSerializer("Font");
52
				properties.load((String) value);
53
				String name = (String) properties.get("name");
54
				int style = Integer.parseInt((String) properties.get("size"));
55
				int size = Integer.parseInt((String) properties.get("style"));
56
				return new Font(name, style, size);
57
			}
58
		} catch (Exception e) {
59
			throw new CoercionException(e);
60
		}
61
		throw new CoercionException();
62
	}
63
	public static void selfRegister() {
64
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
65
		int id = dataTypesManager.getType("String");
66
        dataTypesManager.addCoercion(id, new CoerceStringToFont());
67
	}
68
}
69

  
0 70

  
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
82 82
 */
83 83
public class DefaultMapContextManager implements MapContextManager {
84 84

  
85
    private static final Logger LOG = LoggerFactory
85
    private static final Logger logger = LoggerFactory
86 86
        .getLogger(DefaultMapContextManager.class);
87 87

  
88 88
	private Class drawerClazz = DefaultMapContextDrawer.class;
......
235 235
			layer.initialize(projection);	
236 236
			layer.setLegend((IVectorLegend)createLegend(IVectorialUniqueValueLegend.LEGEND_NAME));
237 237
		} catch (Exception e) {
238
			LOG.error("Error initializing the graphics layer", e);
238
			logger.error("Error initializing the graphics layer", e);
239 239
		}
240 240
		return layer;
241 241
	}
......
472 472
			is.close();
473 473
		}
474 474
		} catch (FileNotFoundException e){
475
		    LOG.error("Legend not found", e);
475
		    logger.error("Legend not found", e);
476 476
		} catch (IOException e) {
477
		    LOG.error("Error reading the legend", e);
477
		    logger.error("Error reading the legend", e);
478 478
        }
479 479
		
480 480
		//If the legend is null, next option is to check if the store has the getLegend method
......
483 483
				legend = (IVectorLegend) dataStore.invokeDynMethod(
484 484
						"getLegend", null);
485 485
			} catch (DynMethodNotSupportedException e) {
486
                LOG.debug("This store {} does not provide a legend.",
486
                logger.debug("This store {} does not provide a legend.",
487 487
                    dataStore.getName());
488 488
			} catch (DynMethodException e) {
489
                LOG.error(
489
                logger.error(
490 490
                    "Can't load the specific legend provided for the store {}.",
491 491
                    dataStore.getName(), e);
492 492
			}
......
501 501
				int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType();
502 502
				legend = createDefaultVectorLegend(typeShape);
503 503
			} catch (DataException e) {
504
				LOG.error("Error getting the default feature type", e);
504
				logger.error("Error getting the default feature type", e);
505 505
			}			
506 506
		}
507 507

  
......
520 520
                is.close();
521 521
            }
522 522
        } catch (FileNotFoundException e){
523
            LOG.error("Label strategy not found", e);
523
            logger.error("Label strategy not found", e);
524 524
        } catch (IOException e) {
525
            LOG.error("Error reading the labeling strategy", e);
525
            logger.error("Error reading the labeling strategy", e);
526 526
        }
527 527
        
528 528
        //If the legend is null, next option is to check if the store has the getLegend method
......
534 534
            } catch (DynMethodNotSupportedException e1) {
535 535
                labelingStrategy = null;
536 536
            } catch (DynMethodException e1) {
537
                LOG.error("Can't load the specific lebeling strategy provided for the datastore {}.",
537
                logger.error("Can't load the specific lebeling strategy provided for the datastore {}.",
538 538
                    dataStore.getName(),
539 539
                    e1);
540 540
            }
......
559 559
                return (File)method.invoke(dataServerExplorer, params);
560 560
            }
561 561
        } catch (Exception e) {
562
            LOG.debug(
562
            logger.debug(
563 563
                "Can't load the specific legend provided by the explorer "
564 564
                + dataServerExplorer, e);
565 565
        } 
566 566
        return null;
567 567
    }
568
}
568

  
569
    private Map iconLayers = new HashMap(); //  (Map<String storeProviderName, String iconName>)
570
    
571
    public void registerIconLayer(String storeProviderName, String iconName) {
572
    	if( storeProviderName == null || iconName == null ) {
573
    		logger.info("registerIconLayer, storeProviderName or iconName are null");
574
    		return;
575
    	}
576
    	if( storeProviderName.trim().length()==0 || iconName.trim().length()==0 ) {
577
    		logger.info("registerIconLayer, invalid storeProviderName or iconName");
578
    		return;
579
    	}
580
    	iconLayers.put(storeProviderName.trim().toLowerCase(), iconName);
581
    }
582
    
583
    public String getIconLayer(DataStore store) {
584
    	String name = (String) iconLayers.get(store.getProviderName().trim().toLowerCase());
585
    	if( name == null ) {
586
    		return "layer-icon";
587
    	}
588
    	return name;
589
    }
590
}

Also available in: Unified diff