Revision 11547 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/operation/strategies/Annotation_Strategy.java

View differences:

Annotation_Strategy.java
81 81
//	 */
82 82
//	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
83 83
//		Cancellable cancel) throws DriverException {
84
//		Rectangle2D elExtent = viewPort.getAdjustedExtent();
85
//		graphics=g;
86
//		Annotation_Layer lyrAnnotation=(Annotation_Layer)capa;
87
//		List lstIndexes=null;
84
//			Annotation_Legend l = (Annotation_Legend) capa.getLegend();
85
//	FSymbol sym = (FSymbol) l.getDefaultSymbol();
88 86
//
89
//		Annotation_Legend l=(Annotation_Legend)lyrAnnotation.getLegend();
90
//		FBitSet bitSet=lyrAnnotation.getRecordset().getSelection();
87
//	Rectangle2D elExtent = viewPort.getAdjustedExtent();
88
//	List lstIndexes=null;
91 89
//
92
//		boolean inPixels=lyrAnnotation.isInPixels();
93
//		FSymbol theSymbol = (FSymbol) l.getDefaultSymbol();
94
//		theSymbol.setFontSizeInPixels(inPixels);
95
//		System.out.println("Dibujando Anotaciones...");
96
//		this.viewPort=viewPort;//capa.getFMap().getViewPort();
97
//		AffineTransform at=viewPort.getAffineTransform();
98
//		try {
99
//			int sc;
100
//			sc=lyrAnnotation.getSource().getShapeCount();
101
//            // If area of needed extent is less than fullExtent / 4,
102
//            // it will be worthy to use SpatialIndex.
103
//            // Otherwhise, we will not use it.
104
//			boolean bUseSpatialIndex = false;
105
//            if(lyrAnnotation.getISpatialIndex() != null)
106
//            {
107
//            	if(isSpatialIndexNecessary(elExtent)){
108
//            		lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent);
109
//                    sc = lstIndexes.size();
110
//                    System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc);
111
//                    bUseSpatialIndex = true;
112
//            	}//if
113
//            }//if
90
//	try {
91
//		int sc;
92
//		ReadableVectorial source = capa.getSource();
93
//		sc=source.getShapeCount();
114 94
//
115
//			FontMetrics metrics = g.getFontMetrics();
116
//			SpatialCache cache = lyrAnnotation.getSpatialCache();
117
//			cache.clearAll();
118
//			int numOriginal;
119
//			ReadableVectorial adapter = capa.getSource();
120
//			adapter.start();
121
//			for (int numReg = 0; numReg < sc; numReg++) {
122
//				if (cancel.isCanceled()){
123
//					break;
95
//		SelectableDataSource recordSet = source.getRecordset();
96
//		FBitSet bitSet=recordSet.getSelection();
97
//		// If area of needed extent is less than fullExtent / 4,
98
//        // it will be worthy to use SpatialIndex.
99
//        // Otherwhise, we will not use it.
100
//		boolean bUseSpatialIndex = false;
101
//        if(capa.getISpatialIndex() != null)
102
//        {
103
//        	if(isSpatialIndexNecessary(elExtent)){
104
//        		lstIndexes = capa.getISpatialIndex().query(elExtent);
105
//                sc = lstIndexes.size();
106
//                System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc);
107
//                bUseSpatialIndex = true;
108
//        	}//if
109
//        }//if
110
//        FontMetrics metrics = g.getFontMetrics();
111
//		Annotation_Mapping mapping = ((Annotation_Layer) capa)
112
//			.getMapping();
113
//		int idHeightField = mapping.getColumnHeight();
114
//		int idFontName = mapping.getColumnTypeFont();
115
//		int idFontStyle = mapping.getColumnStyleFont();
116
//		int idRotationField = mapping.getColumnRotate();
117
//		int idFontColor = mapping.getColumnColor();
118
//		int idTextField = mapping.getColumnText();
119
//
120
//		double rotation = 0D;
121
//		double size = sym.getFont().getSize();
122
//		sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels());
123
//		String fontName = "Dialog";
124
//		int fontStyle = sym.getFont().getStyle();
125
//		int fontColor = sym.getFontColor().getRGB();
126
//		SpatialCache cache = capa.getSpatialCache();
127
//		cache.clearAll();
128
//		int numOriginal;
129
//		for (int numReg = 0; numReg < sc; numReg++) {
130
//        	if (cancel.isCanceled()){
131
//				break;
132
//			}
133
//            if (bUseSpatialIndex){
134
//                Integer idRec = (Integer) lstIndexes.get(numReg);
135
//                numOriginal = idRec.intValue();
136
//            }else{
137
//                numOriginal = numReg;
138
//            }
139
//            Value[] vv = recordSet.getRow(numOriginal);
140
//			if (idHeightField != -1) {
141
//				// text size is defined in the table
142
//				try {
143
//					size = ((NumericValue) vv[idHeightField]).doubleValue()
144
//							* FConstant.FONT_HEIGHT_SCALE_FACTOR;
145
//				} catch (ClassCastException ccEx) {
146
//					if (!NullValue.class.equals(vv[idHeightField]
147
//							.getClass())) {
148
//						// throw new ReadDriverException("Unknown", ccEx);
149
//					}
150
//					// a null value
151
//					// Logger.getAnonymousLogger().
152
//					// warning("Null text height value for text
153
//					// '"+vv[idTextField].toString()+"'");
154
//					continue;
124 155
//				}
125
//                if (bUseSpatialIndex){
126
//                    Integer idRec = (Integer) lstIndexes.get(numReg);
127
//                    numOriginal = idRec.intValue();
128
//                }else{
129
//                    numOriginal = numReg;
130
//                }
131
//				/* if (lyrAnnotation.getSource() instanceof EditableAdapter)
132
//					numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/
133
//                theSymbol = (FSymbol) l.getSymbol(numReg);
134
//				IGeometry geom = l.getTextWrappingGeometry(theSymbol,numOriginal);
135
////				if ((theLabel == null) || (theLabel.getOrig() == null))
136
////					continue;
156
//			} else {
157
//				// otherwise will use the size in the symbol
137 158
//
159
//			}
138 160
//
139
//				Rectangle2D r=null;
140
//				if (inPixels || lyrAnnotation.getMapping().getColumnHeight()==-1) {
141
//					r=geom.getBounds2D();//getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString());
142
//				}else {
143
//					r=geom.getBounds2D();//getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(), theLabel.getJustification(),theLabel.getString());
144
//				}
145
////				theLabel.setBoundBox(r);
161
//			// size = CartographicSupportToolkit.
162
//			// toScreenUnitYAxis(size,
163
//			// unit,
164
//			// viewPort
165
//			// );
146 166
//
147
//				if (XRectangle2D.intersectInclusive(r,elExtent))
148
//				{
149
//					FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new Point2D.Double(r.getX(),r.getY())));
150
//					symbolPoint.draw(g, at, p);
151
//					// FGraphicUtilities.DrawShape(g,at,p,symbolPoint);
152
//					FLabel label=new FLabel();
153
//					label.setHeight(theSymbol.getFontSize());
154
//					label.setRotation(theSymbol.getRotation());
155
//					label.setString(theSymbol.getDescription());
156
//					label.setOrig(new Point2D.Double(r.getMinX(),r.getMaxY()));
157
//					if (bitSet.get(numOriginal)) {
158
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, label,metrics,true);
159
//					}else{
167
////			if (size <= 3) {
168
////				// label is too small to be readable, will be skipped
169
////				// this speeds up the rendering in wider zooms
170
////				continue;
171
////			}
160 172
//
161 173
//
162
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, label,metrics,false);
163
//					}
174
//			if (idFontName != -1) {
175
//				fontName = ((StringValue) vv[idFontName]).toString();
176
//			}
164 177
//
165 178
//
166
//					if (lyrAnnotation.isSpatialCacheEnabled())
167
//					{
168
//						if (cache.getMaxFeatures() >= cache.size())
169
//						{
170
//							// 	Ya reproyectado todo
171
//							IGeometry geo=ShapeFactory.createPoint2D(r.getX(),r.getY());
172
//							Rectangle2D re= new Rectangle2D.Double(r.getX(),r.getY(),1,1);
173
//							cache.insert(re, geo);
174
//						}
175
//					}
176
//				} // XIntersects
179
//			if (idFontStyle != -1) {
180
//				fontStyle = ((NumericValue) vv[idFontStyle]).intValue();
181
//			}
177 182
//
178 183
//
184
//
185
//			if (idRotationField != -1) {
186
//				// text rotation is defined in the table
187
//				rotation = ((NumericValue) vv[idRotationField])
188
//						.doubleValue();
179 189
//			}
180
//			adapter.stop();
181 190
//
191
//
192
//			if (idFontColor != -1) {
193
//				// text rotation is defined in the table
194
//				fontColor = ((NumericValue) vv[idFontColor]).intValue();
195
//				sym.setFontColor(new Color(fontColor));
196
//			}
197
//
198
//			if (bitSet.get(numOriginal)){
199
//				sym = (FSymbol)sym.getSymbolForSelection();
200
//			}
201
//			IGeometry geom = source.getShape(numOriginal);
202
//
203
//			sym.setFont(new Font(fontName, fontStyle, (int) size));
204
//
205
//
206
////			sym.setDescription(vv[idTextField].toString());
207
////			sym.setRotation((int) rotation);
208
//			FLabel[] aux = geom.createLabels(0, true);
209
//			aux[0].setHeight(size);
210
//			aux[0].setRotation((int) rotation);
211
//			aux[0].setString(vv[idTextField].toString());
212
//			symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig())));
213
//			FGraphicUtilities.DrawAnnotation(g, viewPort
214
//					.getAffineTransform(), sym, aux[0], metrics, false);
215
//		}
216
//
182 217
//		//	 System.out.println("..................Fin del dibujado ..............");
183 218
//		} catch (DriverIOException e) {
184 219
//			e.printStackTrace();
......
195 230
		// Copia draw AttrInTableLabeling
196 231
		Annotation_Legend l = (Annotation_Legend) capa.getLegend();
197 232
		FSymbol sym = (FSymbol) l.getDefaultSymbol();
198

  
199
		Rectangle2D elExtent = viewPort.getAdjustedExtent();
200
		List lstIndexes=null;
201

  
202 233
		try {
203
			int sc;
204 234
			ReadableVectorial source = capa.getSource();
205
			sc=source.getShapeCount();
235
			// limit the labeling to the visible extent
236
			FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent());
206 237

  
238

  
207 239
			SelectableDataSource recordSet = source.getRecordset();
208 240
			FBitSet bitSet=recordSet.getSelection();
209
			// If area of needed extent is less than fullExtent / 4,
210
            // it will be worthy to use SpatialIndex.
211
            // Otherwhise, we will not use it.
212
			boolean bUseSpatialIndex = false;
213
            if(capa.getISpatialIndex() != null)
214
            {
215
            	if(isSpatialIndexNecessary(elExtent)){
216
            		lstIndexes = capa.getISpatialIndex().query(elExtent);
217
                    sc = lstIndexes.size();
218
                    System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc);
219
                    bUseSpatialIndex = true;
220
            	}//if
221
            }//if
222
            FontMetrics metrics = g.getFontMetrics();
241
			FontMetrics metrics = g.getFontMetrics();
223 242
			Annotation_Mapping mapping = ((Annotation_Layer) capa)
224 243
				.getMapping();
225 244
			int idHeightField = mapping.getColumnHeight();
......
235 254
			String fontName = "Dialog";
236 255
			int fontStyle = sym.getFont().getStyle();
237 256
			int fontColor = sym.getFontColor().getRGB();
238
			SpatialCache cache = capa.getSpatialCache();
239
			cache.clearAll();
240
			int numOriginal;
241
			for (int numReg = 0; numReg < sc; numReg++) {
242
            	if (cancel.isCanceled()){
257
			for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
258
				if (cancel.isCanceled()){
243 259
					break;
244 260
				}
245
                if (bUseSpatialIndex){
246
                    Integer idRec = (Integer) lstIndexes.get(numReg);
247
                    numOriginal = idRec.intValue();
248
                }else{
249
                    numOriginal = numReg;
250
                }
251
                Value[] vv = recordSet.getRow(numOriginal);
261
				Value[] vv = recordSet.getRow(i);
252 262
				if (idHeightField != -1) {
253 263
					// text size is defined in the table
254 264
					try {
......
307 317
					sym.setFontColor(new Color(fontColor));
308 318
				}
309 319

  
310
				if (bitSet.get(numOriginal)){
320
				if (bitSet.get(i)){
311 321
					sym = (FSymbol)sym.getSymbolForSelection();
312 322
				}
313
				IGeometry geom = source.getShape(numOriginal);
323
				IGeometry geom = source.getShape(i);
314 324

  
315 325
				sym.setFont(new Font(fontName, fontStyle, (int) size));
316 326

  
......
325 335
				FGraphicUtilities.DrawAnnotation(g, viewPort
326 336
						.getAffineTransform(), sym, aux[0], metrics, false);
327 337
			}
328

  
329

  
330

  
331

  
332

  
333

  
334

  
335
//			// limit the labeling to the visible extent
336
//			FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent());
337
//
338
//
339
//			SelectableDataSource recordSet = source.getRecordset();
340
//			FBitSet bitSet=recordSet.getSelection();
341
//			FontMetrics metrics = g.getFontMetrics();
342
//			Annotation_Mapping mapping = ((Annotation_Layer) capa)
343
//				.getMapping();
344
//			int idHeightField = mapping.getColumnHeight();
345
//			int idFontName = mapping.getColumnTypeFont();
346
//			int idFontStyle = mapping.getColumnStyleFont();
347
//			int idRotationField = mapping.getColumnRotate();
348
//			int idFontColor = mapping.getColumnColor();
349
//			int idTextField = mapping.getColumnText();
350
//
351
//			double rotation = 0D;
352
//			double size = sym.getFont().getSize();
353
//			sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels());
354
//			String fontName = "Dialog";
355
//			int fontStyle = sym.getFont().getStyle();
356
//			int fontColor = sym.getFontColor().getRGB();
357
//			for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
358
//				if (cancel.isCanceled()){
359
//					break;
360
//				}
361
//				Value[] vv = recordSet.getRow(i);
362
//				if (idHeightField != -1) {
363
//					// text size is defined in the table
364
//					try {
365
//						size = ((NumericValue) vv[idHeightField]).doubleValue()
366
//								* FConstant.FONT_HEIGHT_SCALE_FACTOR;
367
//					} catch (ClassCastException ccEx) {
368
//						if (!NullValue.class.equals(vv[idHeightField]
369
//								.getClass())) {
370
//							// throw new ReadDriverException("Unknown", ccEx);
371
//						}
372
//						// a null value
373
//						// Logger.getAnonymousLogger().
374
//						// warning("Null text height value for text
375
//						// '"+vv[idTextField].toString()+"'");
376
//						continue;
377
//					}
378
//				} else {
379
//					// otherwise will use the size in the symbol
380
//
381
//				}
382
//
383
//				// size = CartographicSupportToolkit.
384
//				// toScreenUnitYAxis(size,
385
//				// unit,
386
//				// viewPort
387
//				// );
388
//
389
////				if (size <= 3) {
390
////					// label is too small to be readable, will be skipped
391
////					// this speeds up the rendering in wider zooms
392
////					continue;
393
////				}
394
//
395
//
396
////				if (idFontName != -1) {
397
////					fontName = ((StringValue) vv[idFontName]).toString();
398
////				}
399
//
400
//
401
////				if (idFontStyle != -1) {
402
////					fontStyle = ((NumericValue) vv[idFontStyle]).intValue();
403
////				}
404
//
405
//
406
//
407
//				if (idRotationField != -1) {
408
//					// text rotation is defined in the table
409
//					rotation = ((NumericValue) vv[idRotationField])
410
//							.doubleValue();
411
//				}
412
//
413
//
414
//				if (idFontColor != -1) {
415
//					// text rotation is defined in the table
416
//					fontColor = ((NumericValue) vv[idFontColor]).intValue();
417
//					sym.setFontColor(new Color(fontColor));
418
//				}
419
//
420
//				if (bitSet.get(i)){
421
//					sym = (FSymbol)sym.getSymbolForSelection();
422
//				}
423
//				IGeometry geom = source.getShape(i);
424
//
425
//				sym.setFont(new Font(fontName, fontStyle, (int) size));
426
//
427
//
428
////				sym.setDescription(vv[idTextField].toString());
429
////				sym.setRotation((int) rotation);
430
//				FLabel[] aux = geom.createLabels(0, true);
431
//				aux[0].setHeight(size);
432
//				aux[0].setRotation((int) rotation);
433
//				aux[0].setString(vv[idTextField].toString());
434
//				symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig())));
435
//				FGraphicUtilities.DrawAnnotation(g, viewPort
436
//						.getAffineTransform(), sym, aux[0], metrics, false);
437
//			}
438 338
		} catch (Exception e) {
439 339
			// Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the
440 340
			// layer extent.\n" +
......
790 690
				NumericValue vRotation = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnRotate());
791 691
				NumericValue vHeight = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnHeight());
792 692
				Value vText = va.getRecordset().getFieldValue(index,mapping.getColumnText());
793
				IGeometry geom=((Annotation_Legend)capa.getLegend()).getTextWrappingGeometry(vHeight.floatValue(),
693
				IGeometry geom=((Annotation_Layer)capa).getTextWrappingGeometry(vHeight.floatValue(),
794 694
						vText.toString(),vRotation.doubleValue(),index);
795 695
//                  IGeometry geom=va.getShape(index);
796 696
//                IGeometry geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox());

Also available in: Unified diff