47 |
47 |
import java.awt.FontMetrics;
|
48 |
48 |
import java.awt.Graphics2D;
|
49 |
49 |
import java.awt.geom.AffineTransform;
|
|
50 |
import java.awt.geom.NoninvertibleTransformException;
|
50 |
51 |
import java.awt.geom.Point2D;
|
51 |
52 |
import java.awt.geom.Rectangle2D;
|
52 |
53 |
import java.awt.image.BufferedImage;
|
53 |
54 |
import java.util.List;
|
54 |
55 |
|
55 |
56 |
import javax.print.attribute.PrintRequestAttributeSet;
|
|
57 |
import javax.print.attribute.standard.PrintQuality;
|
56 |
58 |
|
57 |
59 |
import org.cresques.cts.ICoordTrans;
|
58 |
60 |
|
... | ... | |
62 |
64 |
import com.hardcode.gdbms.engine.values.StringValue;
|
63 |
65 |
import com.hardcode.gdbms.engine.values.Value;
|
64 |
66 |
import com.iver.andami.messages.NotificationManager;
|
|
67 |
import com.iver.cit.gvsig.PrintProperties;
|
65 |
68 |
import com.iver.cit.gvsig.fmap.DriverException;
|
66 |
69 |
import com.iver.cit.gvsig.fmap.ViewPort;
|
67 |
70 |
import com.iver.cit.gvsig.fmap.core.FPoint2D;
|
... | ... | |
97 |
100 |
public class Annotation_Strategy extends DefaultStrategy {
|
98 |
101 |
private FSymbol symbolPoint = new FSymbol(FShape.POINT, Color.black);
|
99 |
102 |
private Annotation_Layer capa;
|
100 |
|
private Geometry geometry;
|
101 |
103 |
private static AffineTransform ati=new AffineTransform();
|
102 |
104 |
/**
|
103 |
105 |
* Crea un nuevo AnotationStrategy.
|
... | ... | |
121 |
123 |
|
122 |
124 |
try {
|
123 |
125 |
ReadableVectorial source = capa.getSource();
|
124 |
|
// limit the labeling to the visible extent
|
|
126 |
// limit the labeling to the visible extent
|
125 |
127 |
FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent());
|
126 |
128 |
|
127 |
129 |
SelectableDataSource recordSet = source.getRecordset();
|
|
130 |
recordSet.start();
|
128 |
131 |
FBitSet bitSet = recordSet.getSelection();
|
129 |
|
FontMetrics metrics = g.getFontMetrics();
|
130 |
132 |
Annotation_Mapping mapping = ((Annotation_Layer) capa).getAnnotatonMapping();
|
131 |
133 |
int idHeightField = mapping.getColumnHeight();
|
132 |
134 |
int idFontName = mapping.getColumnTypeFont();
|
... | ... | |
157 |
159 |
} catch (ClassCastException ccEx) {
|
158 |
160 |
if (!NullValue.class.equals(
|
159 |
161 |
vv[idHeightField].getClass())) {
|
160 |
|
// throw new ReadDriverException("Unknown", ccEx);
|
161 |
162 |
}
|
162 |
163 |
continue;
|
163 |
164 |
}
|
... | ... | |
174 |
175 |
if (idRotationField != -1) {
|
175 |
176 |
// text rotation is defined in the table
|
176 |
177 |
rotation = ((NumericValue) vv[idRotationField]).doubleValue();
|
|
178 |
sym.setRotation((int)rotation);
|
177 |
179 |
}
|
178 |
180 |
|
179 |
181 |
if (idFontColor != -1) {
|
... | ... | |
191 |
193 |
//Si el tama?o de la fuente est? en unidades de mapa.
|
192 |
194 |
if (!sym.isFontSizeInPixels()){
|
193 |
195 |
boolean draw=false;
|
194 |
|
Rectangle2D r=capa.getTextWrappingGeometry(size,vv[idTextField].toString(),rotation,fontName, fontStyle,i,viewPort).getBounds2D();
|
195 |
|
Rectangle2D rPixels=viewPort.fromMapRectangle(r);
|
196 |
|
//Point2D fp=new Point2D.Double(r.getX(),r.getY());
|
|
196 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,fontName, fontStyle,i,viewPort).getBounds2D();
|
|
197 |
Rectangle2D rPixels=new Rectangle2D.Double(r.getX(),r.getY()+r.getHeight(),r.getWidth(),r.getHeight());
|
197 |
198 |
Point2D p=new Point2D.Double(rPixels.getX(),rPixels.getY());
|
198 |
199 |
FPoint2D fpPixels=new FPoint2D(rPixels.getX(),rPixels.getY());
|
199 |
|
rPixels.setRect(rPixels.getX(),rPixels.getY()-rPixels.getHeight(),rPixels.getWidth(),rPixels.getHeight());
|
200 |
200 |
|
201 |
201 |
if (!capa.isEditing() && l.isAvoidOverLapping()){
|
202 |
202 |
p=getPoint(bi,rPixels,l.isDelOverLapping());
|
203 |
|
draw=true;
|
|
203 |
if (p!=null)
|
|
204 |
draw=true;
|
204 |
205 |
}else{
|
205 |
206 |
if (!capa.isEditing() && l.isDelOverLapping()){
|
206 |
207 |
if (isOverlapping(bi,rPixels)){
|
... | ... | |
211 |
212 |
}
|
212 |
213 |
}
|
213 |
214 |
if (draw){
|
214 |
|
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true);
|
215 |
|
aux[0].setOrig(viewPort.toMapPoint(p));
|
216 |
|
aux[0].setHeight(size);
|
217 |
|
aux[0].setRotation((int) rotation);
|
218 |
|
aux[0].setString(vv[idTextField].toString());
|
219 |
|
AffineTransform at = viewPort.getAffineTransform();
|
220 |
215 |
if (sym.isShapeVisible()) {
|
221 |
|
symbolPoint.draw(g,
|
222 |
|
at,
|
|
216 |
symbolPoint.draw(gBi,
|
|
217 |
ati,
|
223 |
218 |
fpPixels);
|
224 |
219 |
}
|
225 |
220 |
// g.drawRect((int)rPixels.getX(),(int)rPixels.getY(),(int)rPixels.getWidth(),(int)rPixels.getHeight());
|
226 |
|
FGraphicUtilities.DrawAnnotation(gBi,
|
227 |
|
at, sym, aux[0], metrics, false);
|
|
221 |
// FGraphicUtilities.DrawAnnotation(gBi,
|
|
222 |
// ati, sym, aux[0], metrics, false);
|
|
223 |
DrawAnnotation(gBi,sym, p, vv[idTextField].toString(),viewPort,null);
|
228 |
224 |
}
|
229 |
225 |
}else{
|
230 |
226 |
|
... | ... | |
232 |
228 |
boolean draw=false;
|
233 |
229 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,fontName,fontStyle,i,viewPort).getBounds2D();
|
234 |
230 |
|
235 |
|
Rectangle2D rPixels=r;//capa.getMapContext().getViewPort().fromMapRectangle(r);
|
|
231 |
Rectangle2D rPixels= new Rectangle2D.Double(r.getX(),r.getY()+r.getHeight(),r.getWidth(),r.getHeight());
|
236 |
232 |
FPoint2D fp=new FPoint2D(rPixels.getX(),rPixels.getY());
|
237 |
233 |
Point2D p=new Point2D.Double(rPixels.getX(),rPixels.getY());
|
238 |
234 |
|
239 |
235 |
if (!capa.isEditing() && l.isAvoidOverLapping()){
|
240 |
236 |
p=getPoint(bi,rPixels,l.isDelOverLapping());
|
241 |
|
if (p==null){
|
242 |
|
draw=false;
|
243 |
|
}else{
|
244 |
|
//fp=new FPoint2D(p);
|
|
237 |
if (p!=null){
|
245 |
238 |
draw=true;
|
246 |
239 |
}
|
247 |
240 |
}else{
|
... | ... | |
254 |
247 |
}
|
255 |
248 |
}
|
256 |
249 |
if (draw){
|
257 |
|
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true);
|
258 |
|
aux[0].setOrig(p);
|
259 |
|
aux[0].setHeight(size);
|
260 |
|
aux[0].setRotation((int) rotation);
|
261 |
|
aux[0].setString(vv[idTextField].toString());
|
262 |
|
|
263 |
250 |
if (sym.isShapeVisible()) {
|
264 |
|
symbolPoint.draw(g,
|
|
251 |
symbolPoint.draw(gBi,
|
265 |
252 |
ati,
|
266 |
253 |
fp);
|
267 |
254 |
}
|
268 |
255 |
// g.drawRect((int)p.getX(),(int)(p.getY()-rPixels.getHeight()),(int)rPixels.getWidth(),(int)rPixels.getHeight());
|
269 |
|
FGraphicUtilities.DrawAnnotation(gBi,
|
270 |
|
ati, sym, aux[0], metrics, false);
|
271 |
|
|
|
256 |
// FGraphicUtilities.DrawAnnotation(gBi,
|
|
257 |
// ati, sym, aux[0], metrics, false);
|
|
258 |
DrawAnnotation(gBi,sym, p, vv[idTextField].toString(),viewPort,null);
|
272 |
259 |
}
|
273 |
260 |
}
|
274 |
261 |
//Al dibujar esta imagen sobre el graphics la trasparencia no puede existir.
|
... | ... | |
279 |
266 |
gBi.translate(offset.getX(),offset.getY());
|
280 |
267 |
g.drawImage(bi,(int)offset.getX(),(int)offset.getY(),null);
|
281 |
268 |
System.err.println(System.currentTimeMillis()-t1+"millis");
|
282 |
|
|
|
269 |
recordSet.stop();
|
283 |
270 |
} catch (Exception e) {
|
284 |
|
// Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the
|
285 |
|
// layer extent.\n" +
|
286 |
|
// e.getMessage());
|
287 |
271 |
NotificationManager.addError(e);
|
288 |
272 |
}
|
289 |
|
|
290 |
|
// }
|
291 |
273 |
}
|
292 |
274 |
|
293 |
|
// /**
|
294 |
|
// * @see
|
295 |
|
// com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
296 |
|
// * java.awt.Graphics2D, ISymbol)
|
297 |
|
// */
|
298 |
|
// public void print(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
299 |
|
// Cancellable cancel) throws DriverException {
|
300 |
|
//
|
301 |
|
// // Rectangle2D elExtent = viewPort.getAdjustedExtent();
|
302 |
|
// // graphics=g;
|
303 |
|
// // Annotation_Layer lyrAnnotation=(Annotation_Layer)capa;
|
304 |
|
// // List lstIndexes=null;
|
305 |
|
// //
|
306 |
|
// // VectorialLegend l=(VectorialLegend)lyrAnnotation.getLegend();
|
307 |
|
// // FBitSet bitSet=lyrAnnotation.getRecordset().getSelection();
|
308 |
|
// //
|
309 |
|
// // boolean inPixels=lyrAnnotation.isInPixels();
|
310 |
|
// // FSymbol theSymbol = (FSymbol) l.getDefaultSymbol();
|
311 |
|
// // theSymbol.setFontSizeInPixels(inPixels);
|
312 |
|
// // this.viewPort=viewPort;//capa.getFMap().getViewPort();
|
313 |
|
// // AffineTransform at=viewPort.getAffineTransform();
|
314 |
|
// // try {
|
315 |
|
// // int sc;
|
316 |
|
// // sc=lyrAnnotation.getSource().getShapeCount();
|
317 |
|
// // // If area of needed extent is less than fullExtent / 4,
|
318 |
|
// // // it will be worthy to use SpatialIndex.
|
319 |
|
// // // Otherwhise, we will not use it.
|
320 |
|
// // boolean bUseSpatialIndex = false;
|
321 |
|
// // if(lyrAnnotation.getISpatialIndex() != null)
|
322 |
|
// // {
|
323 |
|
// // if(isSpatialIndexNecessary(elExtent)){
|
324 |
|
// // lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent);
|
325 |
|
// // sc = lstIndexes.size();
|
326 |
|
// // bUseSpatialIndex = true;
|
327 |
|
// // }//if
|
328 |
|
// // }//if
|
329 |
|
// //
|
330 |
|
// // FontMetrics metrics = g.getFontMetrics();
|
331 |
|
// // //SpatialCache cache = lyrAnnotation.createSpatialCache();
|
332 |
|
// // int numOriginal;
|
333 |
|
// // for (int numReg = 0; numReg < sc; numReg++) {
|
334 |
|
// // if (cancel.isCanceled()){
|
335 |
|
// // break;
|
336 |
|
// // }
|
337 |
|
// // if (bUseSpatialIndex){
|
338 |
|
// // Integer idRec = (Integer) lstIndexes.get(numReg);
|
339 |
|
// // numOriginal = idRec.intValue();
|
340 |
|
// // }else{
|
341 |
|
// // numOriginal = numReg;
|
342 |
|
// // }
|
343 |
|
// // /* if (lyrAnnotation.getSource() instanceof EditableAdapter)
|
344 |
|
// //
|
345 |
|
// numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/
|
346 |
|
// //
|
347 |
|
// // FLabel theLabel = lyrAnnotation.getLabel(numOriginal);
|
348 |
|
// // if ((theLabel == null) || (theLabel.getOrig() == null))
|
349 |
|
// // continue;
|
350 |
|
// //
|
351 |
|
// //
|
352 |
|
// // Rectangle2D r=null;
|
353 |
|
// // if (inPixels && lyrAnnotation.getMapping().getColumnHeight()==-1) {
|
354 |
|
// //
|
355 |
|
// r=getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString());
|
356 |
|
// // }else {
|
357 |
|
// // r=getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(),
|
358 |
|
// theLabel.getJustification(),theLabel.getString());
|
359 |
|
// // }
|
360 |
|
// // theLabel.setBoundBox(r);
|
361 |
|
// //
|
362 |
|
// // if (elExtent.intersects(r))
|
363 |
|
// // {
|
364 |
|
// // FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new
|
365 |
|
// Point2D.Double(r.getX(),r.getY())));
|
366 |
|
// // FGraphicUtilities.DrawShape(g,at,p,symbolPoint);
|
367 |
|
// // if (bitSet.get(numOriginal)) {
|
368 |
|
// // FGraphicUtilities.DrawAnnotation(g, at, theSymbol,
|
369 |
|
// theLabel,metrics,true);
|
370 |
|
// // }else{
|
371 |
|
// // FGraphicUtilities.DrawAnnotation(g, at, theSymbol,
|
372 |
|
// theLabel,metrics,false);
|
373 |
|
// // }
|
374 |
|
// //
|
375 |
|
// //
|
376 |
|
// // } // XIntersects
|
377 |
|
// //
|
378 |
|
// //
|
379 |
|
// // }
|
380 |
|
// //
|
381 |
|
// // } catch (DriverIOException e) {
|
382 |
|
// // e.printStackTrace();
|
383 |
|
// // }
|
384 |
|
// // heightDefault=-1;
|
385 |
|
// }
|
386 |
|
// public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics,
|
387 |
|
// Point2D p, String s) {
|
388 |
|
// int w = metrics.stringWidth(s);
|
389 |
|
// double width = viewPort.toMapDistance(w);
|
390 |
|
// if (heightDefault == -1) {
|
391 |
|
// int h = metrics.getMaxAscent();
|
392 |
|
// heightDefault = viewPort.toMapDistance(h);
|
393 |
|
// }
|
394 |
|
// return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault);
|
395 |
|
//
|
396 |
|
// }
|
397 |
|
|
398 |
275 |
private Point2D getPoint(BufferedImage bi, Rectangle2D rec, boolean b) {
|
399 |
276 |
Rectangle2D r=new Rectangle2D.Double(rec.getX(),rec.getY()-rec.getHeight(),rec.getWidth(),rec.getHeight());
|
400 |
277 |
if (isOverlapping(bi,r))
|
... | ... | |
420 |
297 |
if (isOverlapping(bi,r))
|
421 |
298 |
return new Point2D.Double(r.getX(),r.getY()+rec.getHeight());
|
422 |
299 |
|
423 |
|
// r.setFrame(rec.getX()-rec.getWidth(),rec.getY()+rec.getHeight()/2,rec.getWidth(),rec.getHeight());
|
424 |
|
// if (isOverlapping(bi,r))
|
425 |
|
// return new Point2D.Double(r.getX(),r.getY());
|
426 |
|
|
427 |
300 |
r.setFrame(rec.getX(),rec.getY()+rec.getHeight()/2,rec.getWidth(),rec.getHeight());
|
428 |
301 |
if (isOverlapping(bi,r))
|
429 |
302 |
return new Point2D.Double(r.getX(),r.getY()+rec.getHeight());
|
... | ... | |
447 |
320 |
return true;
|
448 |
321 |
}
|
449 |
322 |
|
450 |
|
/**
|
451 |
|
* Construcci?n del rect?ngulo
|
452 |
|
*
|
453 |
|
* @param g DOCUMENT ME!
|
454 |
|
* @param relationship
|
455 |
|
*
|
456 |
|
* @return
|
457 |
|
*
|
458 |
|
* @throws DriverException DOCUMENT ME!
|
459 |
|
* @throws VisitException DOCUMENT ME!
|
460 |
|
*/
|
461 |
|
|
462 |
|
// public Rectangle2D getBoundBox(Point2D p, float hp,
|
463 |
|
// int justification,String s) {
|
464 |
|
// //Rectangle2D bounding=null;
|
465 |
|
// if (((Annotation_Layer)capa).isInPixels()){
|
466 |
|
// graphics.setFont(graphics.getFont().deriveFont(hp));
|
467 |
|
// }else{
|
468 |
|
// float alturaPixels = (float) ((hp *
|
469 |
|
// viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR);
|
470 |
|
// graphics.setFont(graphics.getFont().deriveFont(alturaPixels));
|
471 |
|
// }
|
472 |
|
// FontMetrics metrics = graphics.getFontMetrics();
|
473 |
|
// int w = metrics.stringWidth(s);
|
474 |
|
// double width = viewPort.toMapDistance(w);
|
475 |
|
// int h = metrics.getMaxAscent();
|
476 |
|
// double height = viewPort.toMapDistance(h);
|
477 |
|
// //double dist = viewPort.toMapDistance(3);
|
478 |
|
// return new Rectangle2D.Double(p.getX(), p.getY(), width, height);
|
479 |
|
// /* switch (justification) {
|
480 |
|
// case FLabel.LEFT_BOTTOM:
|
481 |
|
// bounding=justification(p, width,height, 0, 0);
|
482 |
|
//
|
483 |
|
// break;
|
484 |
|
//
|
485 |
|
// case FLabel.LEFT_CENTER:
|
486 |
|
// bounding=justification(p, width,height, 0, -(height / 2));
|
487 |
|
//
|
488 |
|
// break;
|
489 |
|
//
|
490 |
|
// case FLabel.LEFT_TOP:
|
491 |
|
// bounding=justification(p,width,height, 0, -height);
|
492 |
|
//
|
493 |
|
// break;
|
494 |
|
//
|
495 |
|
// case FLabel.CENTER_BOTTOM:
|
496 |
|
// bounding=justification(p, width,height, -(width / 2), -dist);
|
497 |
|
//
|
498 |
|
// break;
|
499 |
|
//
|
500 |
|
// case FLabel.CENTER_CENTER:
|
501 |
|
// bounding=justification(p, width,height, -(width / 2), -(height / 2));
|
502 |
|
//
|
503 |
|
// break;
|
504 |
|
//
|
505 |
|
// case FLabel.CENTER_TOP:
|
506 |
|
// bounding=justification(p, width,height, -(width / 2), -height);
|
507 |
|
//
|
508 |
|
// break;
|
509 |
|
//
|
510 |
|
// case FLabel.RIGHT_BOTTOM:
|
511 |
|
// bounding=justification(p, width,height, -width, -dist);
|
512 |
|
//
|
513 |
|
// break;
|
514 |
|
//
|
515 |
|
// case FLabel.RIGHT_CENTER:
|
516 |
|
// bounding=justification(p, width,height, -width, -(height / 2));
|
517 |
|
//
|
518 |
|
// break;
|
519 |
|
//
|
520 |
|
// case FLabel.RIGHT_TOP:
|
521 |
|
// bounding=justification(p, width,height, -width, -height);
|
522 |
|
//
|
523 |
|
// break;
|
524 |
|
// }
|
525 |
|
//
|
526 |
|
// return bounding;
|
527 |
|
// */
|
528 |
|
// }
|
529 |
|
|
530 |
323 |
/*
|
531 |
|
* private Rectangle2D justification(Point2D p, double w,double h, double x,
|
532 |
|
* double y) { Rectangle2D r=new Rectangle2D.Double(p.getX() + x, p.getY() -
|
533 |
|
* y, w, h); return r; }
|
534 |
|
*/
|
535 |
|
/*
|
536 |
324 |
* (non-Javadoc)
|
537 |
325 |
*
|
538 |
326 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry,
|
... | ... | |
734 |
522 |
StringValue vType = (StringValue) sds.getFieldValue(index,mapping.getColumnTypeFont());
|
735 |
523 |
Value vText = sds.getFieldValue(index,
|
736 |
524 |
mapping.getColumnText());
|
737 |
|
IGeometry geom = ((Annotation_Layer) capa).getTextWrappingGeometry(vHeight.floatValue(),
|
|
525 |
IGeometry geom = ((Annotation_Layer) capa).getTextWrappingGeometryInPixels(vHeight.floatValue(),
|
738 |
526 |
vText.toString(), vRotation.doubleValue(),vType.getValue(),vStyle.intValue(), index, vp);
|
739 |
|
|
|
527 |
geom.transform(vp.getAffineTransform().createInverse());
|
740 |
528 |
if (ct != null) {
|
741 |
529 |
if (bMustClone) {
|
742 |
530 |
geom = geom.cloneGeometry();
|
... | ... | |
757 |
545 |
throw new DriverException(e);
|
758 |
546 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
759 |
547 |
throw new DriverException(e);
|
760 |
|
}
|
|
548 |
} catch (NoninvertibleTransformException e) {
|
|
549 |
throw new DriverException(e);
|
|
550 |
}
|
761 |
551 |
|
762 |
552 |
return bitset;
|
763 |
553 |
}
|
... | ... | |
801 |
591 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
802 |
592 |
PrintRequestAttributeSet properties) throws DriverException {
|
803 |
593 |
capa.beforePrinting(properties);
|
804 |
|
drawAllAnnotations(g, viewPort, cancel);
|
|
594 |
drawAllAnnotations(g, viewPort, cancel, properties);
|
805 |
595 |
capa.afterPrinting();
|
806 |
596 |
}
|
807 |
597 |
private void drawAllAnnotations(Graphics2D g, ViewPort viewPort,
|
808 |
|
Cancellable cancel){
|
|
598 |
Cancellable cancel,PrintRequestAttributeSet properties){
|
809 |
599 |
Annotation_Legend l = (Annotation_Legend) capa.getLegend();
|
810 |
600 |
FSymbol sym = (FSymbol) l.getDefaultSymbol();
|
811 |
601 |
|
... | ... | |
814 |
604 |
FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent());
|
815 |
605 |
|
816 |
606 |
SelectableDataSource recordSet = source.getRecordset();
|
|
607 |
recordSet.start();
|
817 |
608 |
FBitSet bitSet = recordSet.getSelection();
|
818 |
|
FontMetrics metrics = g.getFontMetrics();
|
819 |
609 |
Annotation_Mapping mapping = ((Annotation_Layer) capa).getAnnotatonMapping();
|
820 |
610 |
int idHeightField = mapping.getColumnHeight();
|
821 |
611 |
int idFontName = mapping.getColumnTypeFont();
|
... | ... | |
825 |
615 |
int idTextField = mapping.getColumnText();
|
826 |
616 |
|
827 |
617 |
double rotation = 0D;
|
828 |
|
float size = sym.getFont().getSize();
|
|
618 |
float size = sym.getFont().getSize()* (float)FConstant.FONT_HEIGHT_SCALE_FACTOR;
|
829 |
619 |
String fontName = "Dialog";
|
830 |
620 |
int fontStyle = sym.getFont().getStyle();
|
831 |
621 |
int fontColor = sym.getFontColor().getRGB();
|
832 |
|
ViewPort vp=getCapa().getMapContext().getViewPort();
|
833 |
622 |
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
|
834 |
623 |
if (cancel.isCanceled()) {
|
835 |
624 |
break;
|
... | ... | |
861 |
650 |
if (idRotationField != -1) {
|
862 |
651 |
// text rotation is defined in the table
|
863 |
652 |
rotation = ((NumericValue) vv[idRotationField]).doubleValue();
|
|
653 |
sym.setRotation((int)rotation);
|
864 |
654 |
}
|
865 |
655 |
if (idFontColor != -1) {
|
866 |
656 |
// text rotation is defined in the table
|
... | ... | |
874 |
664 |
|
875 |
665 |
//Si el tama?o de la fuente est? en unidades de mapa.
|
876 |
666 |
if (!sym.isFontSizeInPixels()){
|
877 |
|
Rectangle2D r=capa.getTextWrappingGeometry(size,vv[idTextField].toString(),rotation,fontName,fontStyle,i,vp).getBounds2D();
|
878 |
|
Rectangle2D rPixels=viewPort.fromMapRectangle(r);
|
879 |
|
Point2D p = vp.fromMapPoint((int)r.getX(),(int)r.getY());
|
|
667 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,fontName, fontStyle,i,viewPort).getBounds2D();
|
|
668 |
Rectangle2D rPixels=new Rectangle2D.Double(r.getX(),r.getY()+r.getHeight(),r.getWidth(),r.getHeight());
|
|
669 |
Point2D p=new Point2D.Double(rPixels.getX(),rPixels.getY());
|
880 |
670 |
FPoint2D fpPixels=new FPoint2D(rPixels.getX(),rPixels.getY());
|
881 |
|
rPixels.setRect(rPixels.getX(),rPixels.getY()-rPixels.getHeight(),rPixels.getWidth(),rPixels.getHeight());
|
882 |
|
|
883 |
|
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true);
|
884 |
|
aux[0].setOrig(viewPort.toMapPoint(p));
|
885 |
|
aux[0].setHeight(size);
|
886 |
|
aux[0].setRotation((int) rotation);
|
887 |
|
aux[0].setString(vv[idTextField].toString());
|
|
671 |
sym.setRotation((int)rotation);
|
888 |
672 |
if (sym.isShapeVisible()) {
|
889 |
673 |
symbolPoint.draw(g,
|
890 |
674 |
viewPort.getAffineTransform(),
|
891 |
675 |
fpPixels);
|
892 |
676 |
}
|
893 |
|
FGraphicUtilities.DrawAnnotation(g,
|
894 |
|
viewPort.getAffineTransform(), sym, aux[0], metrics, false);
|
|
677 |
DrawAnnotation(g,sym, p, vv[idTextField].toString(),viewPort,properties);
|
|
678 |
// FGraphicUtilities.DrawAnnotation(g,
|
|
679 |
// ati, sym, aux[0], metrics, false);
|
895 |
680 |
}else{
|
896 |
681 |
// Si el tama?o de la fuente est? en pixels.
|
897 |
|
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,fontName,fontStyle,i,viewPort).getBounds2D();
|
898 |
|
Rectangle2D rPixels=r;//capa.getMapContext().getViewPort().fromMapRectangle(r);
|
|
682 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,fontName,fontStyle,i,viewPort).getBounds2D();
|
|
683 |
Rectangle2D rPixels= new Rectangle2D.Double(r.getX(),r.getY()+r.getHeight(),r.getWidth(),r.getHeight());
|
899 |
684 |
FPoint2D fp=new FPoint2D(rPixels.getX(),rPixels.getY());
|
900 |
685 |
Point2D p=new Point2D.Double(rPixels.getX(),rPixels.getY());
|
901 |
|
rPixels.setRect(rPixels.getX(),rPixels.getY()-rPixels.getHeight(),rPixels.getWidth(),rPixels.getHeight());
|
902 |
|
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true);
|
903 |
|
aux[0].setOrig(p);
|
904 |
|
aux[0].setHeight(size);
|
905 |
|
aux[0].setRotation((int) rotation);
|
906 |
|
aux[0].setString(vv[idTextField].toString());
|
907 |
686 |
if (sym.isShapeVisible()) {
|
908 |
687 |
symbolPoint.draw(g,
|
909 |
688 |
ati,
|
910 |
689 |
fp);
|
911 |
690 |
}
|
912 |
|
FGraphicUtilities.DrawAnnotation(g,
|
913 |
|
ati, sym, aux[0], metrics, false);
|
|
691 |
DrawAnnotation(g,sym, p, vv[idTextField].toString(),viewPort,properties);
|
|
692 |
// FGraphicUtilities.DrawAnnotation(g,
|
|
693 |
// ati, sym, aux[0], metrics, false);
|
914 |
694 |
|
915 |
695 |
}
|
|
696 |
recordSet.stop();
|
916 |
697 |
}
|
917 |
698 |
} catch (Exception e) {
|
918 |
699 |
NotificationManager.addError(e);
|
919 |
700 |
}
|
920 |
701 |
}
|
|
702 |
private static void DrawAnnotation(Graphics2D g2,
|
|
703 |
FSymbol theSymbol,Point2D pAux, String text,ViewPort viewPort,PrintRequestAttributeSet properties) {
|
|
704 |
float x;
|
|
705 |
float y;
|
|
706 |
// Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
|
|
707 |
// ?til para cuando queramos eliminar duplicados.
|
|
708 |
if (text == null) {
|
|
709 |
return;
|
|
710 |
}
|
|
711 |
int size=theSymbol.getFont().getSize();
|
|
712 |
double resolutionPrinting=0;
|
|
713 |
if (!theSymbol.isFontSizeInPixels()){
|
|
714 |
size=viewPort.fromMapDistance(size);
|
|
715 |
}
|
|
716 |
if (properties!=null){
|
|
717 |
PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
|
|
718 |
if (resolution.equals(PrintQuality.NORMAL)){
|
|
719 |
resolutionPrinting=300/72;
|
|
720 |
}else if (resolution.equals(PrintQuality.HIGH)){
|
|
721 |
resolutionPrinting=600/72;
|
|
722 |
}else if (resolution.equals(PrintQuality.DRAFT)){
|
|
723 |
resolutionPrinting=72/72;
|
|
724 |
}
|
|
725 |
size=(int)(size*resolutionPrinting);
|
|
726 |
}
|
|
727 |
Font font=new Font(theSymbol.getFont().getName(),theSymbol.getFont().getStyle(),size);
|
|
728 |
g2.setFont(font);
|
|
729 |
g2.setColor(theSymbol.getFontColor());
|
|
730 |
AffineTransform ant = g2.getTransform();
|
|
731 |
|
|
732 |
x = (float) pAux.getX();
|
|
733 |
y = (float) pAux.getY();
|
|
734 |
|
|
735 |
AffineTransform Tx = (AffineTransform) ant.clone();
|
|
736 |
Tx.translate(x, y); // S3: final translation
|
|
737 |
Tx.rotate(Math.toRadians(-theSymbol.getRotation())); // S2: rotate around anchor
|
|
738 |
g2.setTransform(Tx);
|
|
739 |
g2.drawString(text, 0, 0);
|
|
740 |
g2.setTransform(ant);
|
|
741 |
}
|
|
742 |
|
921 |
743 |
}
|