Revision 24375

View differences:

trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/rendering/DotDensityLegend.java
100 100
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol;
101 101
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
102 102
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
103
import com.iver.utiles.StringUtilities;
103 104
import com.iver.utiles.XMLEntity;
104 105

  
105 106

  
106 107
/**
107 108
 *
108
 * Implements a legend where the magnitudes of a specific area of the map are 
109
 * Implements a legend where the magnitudes of a specific area of the map are
109 110
 * represented by the density of the points that are distributed in the surface.
110 111
 *
111 112
 *
......
114 115
public class DotDensityLegend extends VectorialUniqueValueLegend {
115 116

  
116 117
	private double dotValue;
118
	private Color dotColor;
119
	private Color backgroundColor;
117 120
	private static final int SIMPLE_FILL_LAYER_INDEX = 0;
118 121
	private static final int DOT_DENSITY_LAYER_INDEX = 1;
119 122

  
......
127 130

  
128 131
	@Override
129 132
	public ISymbol getSymbolByFeature(IFeature feat) {
130
		return getSymbolByValue(feat.getAttribute(
131
				FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD
132
				? 0 :fieldId));
133
//		return getSymbolByValue(feat.getAttribute(
134
//				FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD
135
//				? 0 :fieldId));
136

  
137
		return getSymbolByValue(feat.getAttribute(0));
133 138
	}
134
	
139

  
135 140
	/**
136 141
	 * Establishes the value for the dot used in the dot density legend
137
	 * 
142
	 *
138 143
	 * @param dotValue
139 144
	 */
140 145
	public void setDotValue(double dotValue) {
141 146
		this.dotValue = dotValue;
142 147
	}
143
	
148

  
144 149
	/**
145 150
	 * <p>Returns an XML entity with all needed information about the class to de-serialize
146 151
	 *  and create instances of it.</p>
147
	 * 
152
	 *
148 153
	 * @return the XML entity of the class that persists
149 154
	 */
150 155
	@Override
......
153 158
		xml.putProperty("className", getClass().getName());
154 159
		xml.putProperty("dotValue", dotValue);
155 160
		xml.putProperty("fieldName", getClassifyingFieldNames());
161
		xml.putProperty("dotColor",StringUtilities.color2String(getDotColor()));
162
		xml.putProperty("bgColor",StringUtilities.color2String(getBGColor()));
156 163
		xml.addChild(getDefaultSymbol().getXMLEntity());
157 164
		return xml;
158 165
	}
......
160 167
	/**
161 168
	 * <p>Sets an XML entity with all needed information about the class to de-serialize
162 169
	 *  and create instances of it.</p>
163
	 * 
170
	 *
164 171
	 * @param xml the XML entity of the class that persists
165 172
	 */
166 173
	@Override
......
168 175
		dotValue = xml.getDoubleProperty("dotValue");
169 176
		setClassifyingFieldNames(xml.getStringArrayProperty("fieldName"));
170 177
		setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
178
		if(xml.contains("dotColor"))
179
			setDotColor(StringUtilities.string2Color(xml.getStringProperty("dotColor")));
180
		if(xml.contains("bgColor"))
181
			setBGColor(StringUtilities.string2Color(xml.getStringProperty("bgColor")));
171 182
	}
172 183

  
173 184
	/**
174 185
	 * Returns the outline
175
	 * 
186
	 *
176 187
	 * @return
177 188
	 */
178 189
	public ILineSymbol getOutline() {
......
191 202
	 * @return
192 203
	 */
193 204
	public Color getDotColor() {
194
		try {
195
			// defined by the DotDensitySymbol layer
196
			DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
197
			getLayer(DOT_DENSITY_LAYER_INDEX);
198
			return sym.getDotColor();
199
		} catch (NullPointerException npE) {
200
			return null;
201
		}
205
//		try {
206
//			// defined by the DotDensitySymbol layer
207
//			DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
208
//			getLayer(DOT_DENSITY_LAYER_INDEX);
209
//			return sym.getDotColor();
210
//		} catch (NullPointerException npE) {
211
//			return null;
212
//		}
213
		return dotColor;
202 214
	}
215

  
216

  
203 217
	/**
218
	 * Sets the color for the dot used in the dot density legend.
219
	 * @return
220
	 */
221
	public void setDotColor(Color color){
222

  
223
//		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
224
//		getLayer(DOT_DENSITY_LAYER_INDEX);
225
//		sym.setDotColor(color);
226

  
227
		this.dotColor = color;
228

  
229
	}
230

  
231
	/**
204 232
	 * Obtains the background color for the dot density legend
205 233
	 * @return
206 234
	 */
207 235
	public Color getBGColor() {
208
		try {
209
			// defined by the SimpleFillSymbol layer
210
			IFillSymbol symbol = (IFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
211
			getLayer(SIMPLE_FILL_LAYER_INDEX);
212
			return symbol.getFillColor();
213
		} catch (NullPointerException npE) {
214
			return null;
215
		}
236
//		try {
237
//			// defined by the SimpleFillSymbol layer
238
//			IFillSymbol symbol = (IFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
239
//			getLayer(SIMPLE_FILL_LAYER_INDEX);
240
//			return symbol.getFillColor();
241
//		} catch (NullPointerException npE) {
242
//			return null;
243
//		}
244
		return backgroundColor;
216 245
	}
246

  
217 247
	/**
248
	 * Sets the background color for the dot density legend
249
	 * @return
250
	 */
251
	public void setBGColor(Color color) {
252
		this.backgroundColor = color;
253
	}
254
	/**
218 255
	 * Returns the value for the dot that is used in the dot density legend
219 256
	 * @return
220 257
	 */
......
240 277
			return -1; // TODO define default
241 278
		}
242 279
	}
280

  
281
	/**
282
	 * Sets the size of the dot that is used in the dot density legend
283
	 */
284
	public void setDotSize(double value) {
285

  
286
		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
287
		getLayer(DOT_DENSITY_LAYER_INDEX);
288
		sym.setDotSize(value);
289

  
290
	}
291

  
243 292
}

Also available in: Unified diff