Revision 23303 branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/dgn/DGNResource.java

View differences:

DGNResource.java
32 32

  
33 33
import java.awt.geom.AffineTransform;
34 34
import java.awt.geom.Arc2D;
35
import java.util.HashMap;
36
import java.util.Map;
35 37

  
36 38
import org.gvsig.fmap.data.DataException;
37 39
import org.gvsig.fmap.data.OpenException;
38 40
import org.gvsig.fmap.data.ReadException;
39 41
import org.gvsig.fmap.data.feature.Feature;
40
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
41 42
import org.gvsig.fmap.data.feature.FeatureType;
42 43
import org.gvsig.fmap.data.feature.IsNotFeatureSettingException;
43 44
import org.gvsig.fmap.data.feature.file.FileMemoryResource;
......
49 50
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNElemText;
50 51
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNFileHeader;
51 52
import org.gvsig.fmap.data.feature.file.dgn.utils.DGNReader;
53
import org.gvsig.fmap.data.feature.operation.LegendLabelingManager;
54
import org.gvsig.fmap.data.feature.operation.LegendLabelingManagerFactory;
52 55
import org.gvsig.fmap.geom.Geometry;
53 56
import org.gvsig.fmap.geom.GeometryFactory;
54 57
import org.gvsig.fmap.geom.GeometryManager;
55 58
import org.gvsig.fmap.geom.primitive.Envelope;
56 59
import org.gvsig.fmap.geom.primitive.GeneralPathX;
57
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
58
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
59
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
60
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
61
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
62 60

  
63 61
/**
64 62
 * @author jmvivo
65 63
 *
66 64
 */
67 65
public class DGNResource extends FileMemoryResource {
66
	private static LegendLabelingManagerFactory legendLabelingManagerFactory = null;
68 67

  
68
	public static final int ID_FIELD_ID = 0;
69
	public static final int ID_FIELD_ENTITY = 1;
70
	public static final int ID_FIELD_LAYER = 2;
71
	public static final int ID_FIELD_COLOR = 3;
72
	public static final int ID_FIELD_HEIGHTTEXT = 4;
73
	public static final int ID_FIELD_ROTATIONTEXT = 5;
74
	public static final int ID_FIELD_TEXT = 6;
75
	public static final int ID_FIELD_GEOMETRY = 7;
69 76

  
70
	private final int ID_FIELD_ID = 0;
71
	private final int ID_FIELD_ENTITY = 1;
72
	private final int ID_FIELD_LAYER = 2;
73
	private final int ID_FIELD_COLOR = 3;
74
	private final int ID_FIELD_HEIGHTTEXT = 4;
75
	private final int ID_FIELD_ROTATIONTEXT = 5;
76
	private final int ID_FIELD_TEXT = 6;
77
	private final int ID_FIELD_GEOMETRY = 7;
78 77

  
79

  
80 78
	private FeatureType featureType;
81 79

  
82
	private AttrInTableLabelingStrategy labeling;
83
	private VectorialUniqueValueLegend defaultLegend;
80
	private LegendLabelingManager legendlabelingManager;
84 81

  
85 82
	/**
86 83
	 * @param params
......
114 111
		} catch (ReadException e) {
115 112
			throw new OpenException(this.description(),e);
116 113
		}
114
		if (legendLabelingManagerFactory != null) {
115
			legendlabelingManager = legendLabelingManagerFactory.newManager();
116
			Map params = new HashMap();
117
			params.put("reader", m_DgnReader);
118
			legendlabelingManager.startLoading(params);
119
		} else {
120
			legendlabelingManager = null;
121
		}
117 122

  
118 123
		try{
119 124
//			Value[] auxRow = new Value[7];
......
137 142

  
138 143
//			getTableModel().setColumnIdentifiers(arrayFields.toArray());
139 144

  
140
			// jaume
141
			labeling = new AttrInTableLabelingStrategy();
142
			(labeling).setTextFieldId(featureType.getFieldIndex("Text"));
143
			(labeling).setRotationFieldId(featureType.getFieldIndex("RotationText"));
144
			(labeling).setHeightFieldId(featureType.getFieldIndex("HeightText"));
145
			(labeling).setUnit(1); //MapContext.NAMES[1] (meters)
146 145

  
147

  
148 146
			// Ahora las rellenamos.
149 147
//			FShape aux;
150 148
			boolean bElementoCompuesto = false;
......
166 164
				DGNElemCore elemento = m_DgnReader.DGNReadElement();
167 165
				nClass = 0;
168 166
//				auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
167
				auxFeature.set(ID_FIELD_HEIGHTTEXT, 0);
169 168
//				auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
169
				auxFeature.set(ID_FIELD_ROTATIONTEXT, 0);
170 170
//				auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
171
				auxFeature.set(ID_FIELD_TEXT, null);
171 172

  
172 173
				if (elemento.properties != 0) {
173 174
					nClass = elemento.properties & DGNFileHeader.DGNPF_CLASS;
......
595 596
					addDGNFeature(auxFeature);
596 597
//					addShape(new FPolygon2D(elementoCompuesto), auxRow);
597 598
				}
599

  
598 600
			}
599 601
			cellFeature.stopLoading();
600 602
			auxFeature.stopLoading();
601 603
			complexFeature.stopLoading();
602
			defaultLegend = LegendFactory.createVectorialUniqueValueLegend(Geometry.TYPES.GEOMETRY);
603
			defaultLegend.setClassifyingFieldNames(new String[] {"Color"} );
604
			defaultLegend.setClassifyingFieldTypes(new String[]{FeatureAttributeDescriptor.TYPE_INT,FeatureAttributeDescriptor.TYPE_STRING,FeatureAttributeDescriptor.TYPE_INT,FeatureAttributeDescriptor.TYPE_INT,FeatureAttributeDescriptor.TYPE_FLOAT,FeatureAttributeDescriptor.TYPE_DOUBLE,FeatureAttributeDescriptor.TYPE_STRING});
605 604

  
606

  
607
			ISymbol myDefaultSymbol = SymbologyFactory.
608
			createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY);
609

  
610
			defaultLegend.setDefaultSymbol(myDefaultSymbol);
611 605
		}catch (IsNotFeatureSettingException e) {
612 606
			throw new OpenException(this.description(),e);
613 607
		} catch (ReadException e) {
614 608
			throw new OpenException(this.description(),e);
615 609
		}
616 610

  
611
		if (legendlabelingManager != null) {
612
			legendlabelingManager.endLoading();
613
		}
617 614
//		ISymbol theSymbol = null;
618 615

  
619 616
//		try {
......
660 657
	}
661 658

  
662 659
	private void addDGNFeature(Feature feature) throws DataException{
663
		this.addFeature(new DGNFeature(feature));
660
		DGNFeature newFeature = new DGNFeature(feature);
661
		this.addFeature(newFeature);
662
		if (this.legendlabelingManager != null) {
663
			this.legendlabelingManager.add(newFeature, null);
664
		}
664 665
	}
665 666

  
666 667

  
......
682 683
	 */
683 684
	protected Object getDefaultLegend() throws ReadException {
684 685
		this.checkOpen();
685
		return this.defaultLegend;
686
		if (this.legendlabelingManager == null) {
687
			return null;
688
		}
689
		return this.legendlabelingManager.getDefaultLegend();
686 690
	}
687 691

  
688 692
	/* (non-Javadoc)
......
706 710
		return super.getFeature(index);
707 711
	}
708 712

  
709
	protected AttrInTableLabelingStrategy getDefaultLabelingStrategy()  throws ReadException {
713
	protected Object getDefaultLabelingStrategy() throws ReadException {
710 714
		this.checkOpen();
711
		return labeling;
715

  
716
		if (this.legendlabelingManager == null) {
717
			return null;
718
		}
719
		return this.legendlabelingManager.getLabeling();
712 720
	}
713 721

  
722
	public static void setLegendLabelingManagerFactory(
723
			LegendLabelingManagerFactory factory) {
724
		legendLabelingManagerFactory = factory;
725
	}
726

  
727
	public static LegendLabelingManagerFactory getLegendLabelingManagerFactory() {
728
		return legendLabelingManagerFactory;
729
	}
730

  
714 731
}
715 732

  

Also available in: Unified diff