Revision 12131 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/operation/strategies/Annotation_Strategy.java
Annotation_Strategy.java | ||
---|---|---|
61 | 61 |
import com.hardcode.gdbms.engine.values.NumericValue; |
62 | 62 |
import com.hardcode.gdbms.engine.values.StringValue; |
63 | 63 |
import com.hardcode.gdbms.engine.values.Value; |
64 |
import com.iver.andami.messages.NotificationManager; |
|
64 | 65 |
import com.iver.cit.gvsig.fmap.DriverException; |
65 | 66 |
import com.iver.cit.gvsig.fmap.ViewPort; |
66 | 67 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
... | ... | |
312 | 313 |
vv[idHeightField].getClass())) { |
313 | 314 |
// throw new ReadDriverException("Unknown", ccEx); |
314 | 315 |
} |
315 |
|
|
316 |
// a null value |
|
317 |
// Logger.getAnonymousLogger(). |
|
318 |
// warning("Null text height value for text |
|
319 |
// '"+vv[idTextField].toString()+"'"); |
|
320 | 316 |
continue; |
321 | 317 |
} |
322 | 318 |
} else { |
323 | 319 |
// otherwise will use the size in the symbol |
324 | 320 |
} |
325 | 321 |
|
326 |
// size = CartographicSupportToolkit. |
|
327 |
// toScreenUnitYAxis(size, |
|
328 |
// unit, |
|
329 |
// viewPort |
|
330 |
// ); |
|
331 |
// if (size <= 3) { |
|
332 |
// // label is too small to be readable, will be skipped |
|
333 |
// // this speeds up the rendering in wider zooms |
|
334 |
// continue; |
|
335 |
// } |
|
336 | 322 |
if (idFontName != -1) { |
337 | 323 |
fontName = ((StringValue) vv[idFontName]).toString(); |
338 | 324 |
} |
... | ... | |
358 | 344 |
|
359 | 345 |
sym.setFont(new Font(fontName, fontStyle, (int) size)); |
360 | 346 |
|
347 |
//Si el tama?o de la fuente est? en unidades de mapa. |
|
361 | 348 |
if (!sym.isFontSizeInPixels()){ |
349 |
boolean draw=false; |
|
362 | 350 |
Rectangle2D r=capa.getTextWrappingGeometry(size,vv[idTextField].toString(),rotation,i).getBounds2D(); |
363 | 351 |
Rectangle2D rPixels=viewPort.fromMapRectangle(r); |
364 |
FPoint2D fp=new FPoint2D(r.getX(),r.getY()); |
|
352 |
//Point2D fp=new Point2D.Double(r.getX(),r.getY()); |
|
353 |
Point2D p=new Point2D.Double(r.getX(),r.getY()); |
|
365 | 354 |
FPoint2D fpPixels=new FPoint2D(rPixels.getX(),rPixels.getY()); |
366 | 355 |
rPixels.setRect(rPixels.getX(),rPixels.getY()-rPixels.getHeight(),rPixels.getWidth(),rPixels.getHeight()); |
367 |
if (l.isOverWrite() || isTrasparent(bi,rPixels)){ |
|
368 |
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true); |
|
369 |
aux[0].setOrig(new Point2D.Double(fp.getX(),fp.getY())); |
|
356 |
|
|
357 |
if (!capa.isEditing() && l.isAvoidOverLapping()){ |
|
358 |
p=getPoint(bi,rPixels,l.isDelOverLapping()); |
|
359 |
draw=true; |
|
360 |
}else{ |
|
361 |
if (!capa.isEditing() && l.isDelOverLapping()){ |
|
362 |
if (isOverlapping(bi,rPixels)){ |
|
363 |
draw=true; |
|
364 |
} |
|
365 |
}else{ |
|
366 |
draw=true; |
|
367 |
} |
|
368 |
} |
|
369 |
if (draw){ |
|
370 |
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true); |
|
371 |
aux[0].setOrig(viewPort.toMapPoint(p)); |
|
370 | 372 |
aux[0].setHeight(size); |
371 | 373 |
aux[0].setRotation((int) rotation); |
372 | 374 |
aux[0].setString(vv[idTextField].toString()); |
... | ... | |
381 | 383 |
viewPort.getAffineTransform(), sym, aux[0], metrics, false); |
382 | 384 |
} |
383 | 385 |
}else{ |
384 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,i).getBounds2D(); |
|
386 |
|
|
387 |
// Si el tama?o de la fuente est? en pixels. |
|
388 |
boolean draw=false; |
|
389 |
Rectangle2D r=capa.getTextWrappingGeometryInPixels(size,vv[idTextField].toString(),rotation,i).getBounds2D(); |
|
385 | 390 |
Rectangle2D rPixels=r;//capa.getMapContext().getViewPort().fromMapRectangle(r); |
386 | 391 |
FPoint2D fp=new FPoint2D(rPixels.getX(),rPixels.getY()); |
392 |
Point2D p=new Point2D.Double(rPixels.getX(),rPixels.getY()); |
|
387 | 393 |
rPixels.setRect(rPixels.getX(),rPixels.getY()-rPixels.getHeight(),rPixels.getWidth(),rPixels.getHeight()); |
388 |
if (l.isOverWrite() || isTrasparent(bi,rPixels)){ |
|
394 |
if (!capa.isEditing() && l.isAvoidOverLapping()){ |
|
395 |
p=getPoint(bi,rPixels,l.isDelOverLapping()); |
|
396 |
if (p==null){ |
|
397 |
draw=false; |
|
398 |
}else{ |
|
399 |
//fp=new FPoint2D(p); |
|
400 |
draw=true; |
|
401 |
} |
|
402 |
}else{ |
|
403 |
if (!capa.isEditing() && l.isDelOverLapping()){ |
|
404 |
if (isOverlapping(bi,rPixels)){ |
|
405 |
draw=true; |
|
406 |
} |
|
407 |
}else{ |
|
408 |
draw=true; |
|
409 |
} |
|
410 |
} |
|
411 |
if (draw){ |
|
389 | 412 |
FLabel[] aux = new FLabel[]{new FLabel()};//geom.createLabels(0, true); |
390 |
aux[0].setOrig(new Point2D.Double(fp.getX(),fp.getY()));
|
|
413 |
aux[0].setOrig(p);
|
|
391 | 414 |
aux[0].setHeight(size); |
392 | 415 |
aux[0].setRotation((int) rotation); |
393 | 416 |
aux[0].setString(vv[idTextField].toString()); |
... | ... | |
397 | 420 |
ati, |
398 | 421 |
fp); |
399 | 422 |
} |
400 |
// g.drawRect((int)rPixels.getX(),(int)rPixels.getY(),(int)rPixels.getWidth(),(int)rPixels.getHeight());
|
|
423 |
// g.drawRect((int)p.getX(),(int)(p.getY()-rPixels.getHeight()),(int)rPixels.getWidth(),(int)rPixels.getHeight());
|
|
401 | 424 |
FGraphicUtilities.DrawAnnotation(gBi, |
402 | 425 |
ati, sym, aux[0], metrics, false); |
403 | 426 |
|
... | ... | |
415 | 438 |
// Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the |
416 | 439 |
// layer extent.\n" + |
417 | 440 |
// e.getMessage()); |
418 |
e.printStackTrace();
|
|
441 |
NotificationManager.addError(e);
|
|
419 | 442 |
} |
420 | 443 |
|
421 | 444 |
// } |
... | ... | |
526 | 549 |
// |
527 | 550 |
// } |
528 | 551 |
|
529 |
private boolean isTrasparent(BufferedImage bi, Rectangle2D rPixels) { |
|
552 |
private Point2D getPoint(BufferedImage bi, Rectangle2D rec, boolean b) { |
|
553 |
Rectangle2D r=new Rectangle2D.Double(rec.getX(),rec.getY(),rec.getWidth(),rec.getHeight()); |
|
554 |
if (isOverlapping(bi,r)) |
|
555 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
556 |
r.setFrame(rec.getX(),rec.getY()+rec.getHeight(),rec.getWidth(),rec.getHeight()); |
|
557 |
if (isOverlapping(bi,r)) |
|
558 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
559 |
r.setFrame(rec.getX()-rec.getWidth(),rec.getY()+rec.getHeight(),rec.getWidth(),rec.getHeight()); |
|
560 |
if (isOverlapping(bi,r)) |
|
561 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
562 |
r.setFrame(rec.getX()-rec.getWidth(),rec.getY(),rec.getWidth(),rec.getHeight()); |
|
563 |
if (isOverlapping(bi,r)) |
|
564 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
565 |
r.setFrame(rec.getX()-rec.getWidth()/2,rec.getY(),rec.getWidth(),rec.getHeight()); |
|
566 |
if (isOverlapping(bi,r)) |
|
567 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
568 |
r.setFrame(rec.getX()-rec.getWidth()/2,rec.getY()+rec.getHeight(),rec.getWidth(),rec.getHeight()); |
|
569 |
if (isOverlapping(bi,r)) |
|
570 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
571 |
r.setFrame(rec.getX()-rec.getWidth(),rec.getY()+rec.getHeight()/2,rec.getWidth(),rec.getHeight()); |
|
572 |
if (isOverlapping(bi,r)) |
|
573 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
574 |
r.setFrame(rec.getX(),rec.getY()+rec.getHeight()/2,rec.getWidth(),rec.getHeight()); |
|
575 |
if (isOverlapping(bi,r)) |
|
576 |
return new Point2D.Double(r.getX(),r.getY()+r.getHeight()); |
|
577 |
// r.setFrame(rec.getX()-rec.getWidth(),rec.getY()+rec.getHeight()/2,rec.getWidth(),rec.getHeight()); |
|
578 |
// if (isTrasparent(bi,r)) |
|
579 |
// return new Point2D.Double(r.getX(),r.getY()); |
|
580 |
|
|
581 |
if (!b) |
|
582 |
return new Point2D.Double(rec.getX(),rec.getY()+rec.getHeight()); |
|
583 |
else |
|
584 |
return null; |
|
585 |
} |
|
586 |
|
|
587 |
private boolean isOverlapping(BufferedImage bi, Rectangle2D rPixels) { |
|
530 | 588 |
for (int i=(int)rPixels.getX();i<rPixels.getMaxX();i++){ |
531 | 589 |
for (int j=(int)rPixels.getY();j<rPixels.getMaxY();j++){ |
532 | 590 |
if (i<0 || j<0 || bi.getWidth()<i+1 || bi.getHeight()<j+1) |
533 | 591 |
continue; |
534 |
// try{ |
|
535 | 592 |
if (bi.getRGB(i,j)!=0){ |
536 | 593 |
return false; |
537 | 594 |
} |
538 |
// }catch (Exception e) { |
|
539 |
// System.err.println("X= "+i+", Y= "+j); |
|
540 |
// } |
|
541 | 595 |
} |
542 | 596 |
} |
543 |
// System.err.println("imageX= "+bi.getWidth()+", imageY= "+bi.getHeight()); |
|
544 |
// if (bi.getRGB((int)rPixels.getX(),(int)rPixels.getY())!=0){ |
|
545 |
// return false; |
|
546 |
// } |
|
547 |
// if (bi.getRGB((int)rPixels.getCenterX(),(int)rPixels.getCenterY())!=0){ |
|
548 |
// return false; |
|
549 |
// } |
|
550 |
// if (bi.getRGB((int)rPixels.getMaxX(),(int)rPixels.getMaxY())!=0){ |
|
551 |
// return false; |
|
552 |
// } |
|
553 |
// if (bi.getRGB((int)rPixels.getMaxX(),(int)rPixels.getMinY())!=0){ |
|
554 |
// return false; |
|
555 |
// } |
|
556 |
// if (bi.getRGB((int)rPixels.getMinX(),(int)rPixels.getMaxY())!=0){ |
|
557 |
// return false; |
|
558 |
// } |
|
559 |
|
|
560 | 597 |
return true; |
561 | 598 |
} |
562 | 599 |
|
Also available in: Unified diff