Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/styling/AttrInTableLabelingStrategy.java
AttrInTableLabelingStrategy.java | ||
---|---|---|
30 | 30 |
import java.awt.image.BufferedImage; |
31 | 31 |
import java.util.ArrayList; |
32 | 32 |
import java.util.List; |
33 |
|
|
34 | 33 |
import org.apache.batik.ext.awt.geom.DefaultPathLength; |
35 | 34 |
import org.cresques.cts.ICoordTrans; |
36 | 35 |
import org.cresques.cts.IProjection; |
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 | 36 |
import org.gvsig.compat.print.PrintAttributes; |
40 | 37 |
import org.gvsig.fmap.dal.exception.DataException; |
41 | 38 |
import org.gvsig.fmap.dal.exception.ReadException; |
... | ... | |
47 | 44 |
import org.gvsig.fmap.geom.Geometry; |
48 | 45 |
import org.gvsig.fmap.geom.GeometryLocator; |
49 | 46 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
50 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
51 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
52 | 47 |
import org.gvsig.fmap.geom.primitive.Envelope; |
53 | 48 |
import org.gvsig.fmap.geom.primitive.Point; |
54 | 49 |
import org.gvsig.fmap.geom.type.GeometryType; |
... | ... | |
60 | 55 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
61 | 56 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IZoomConstraints; |
62 | 57 |
import org.gvsig.symbology.PathLength; |
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractCartographicSupport; |
|
63 | 59 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
64 | 60 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol; |
65 | 61 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
73 | 69 |
import org.gvsig.tools.task.Cancellable; |
74 | 70 |
import org.gvsig.tools.util.Callable; |
75 | 71 |
import org.slf4j.Logger; |
72 |
import org.slf4j.LoggerFactory; |
|
76 | 73 |
|
77 | 74 |
/** |
78 | 75 |
* LabelingStrategy used when the user wants to use label sizes, rotations, etc. |
79 | 76 |
* from the values included in fields of the datasource's table |
80 | 77 |
* |
81 | 78 |
*/ |
82 |
public class AttrInTableLabelingStrategy implements IAttrInTableLabelingStrategy { |
|
79 |
public class AttrInTableLabelingStrategy extends AbstractCartographicSupport implements IAttrInTableLabelingStrategy {
|
|
83 | 80 |
|
84 | 81 |
private static final String FIELD_LABELING_METHOD = "labelingMethod"; |
85 | 82 |
private static final String FIELD_ZOOM_CONSTRAINTS = "zoomConstraints"; |
... | ... | |
105 | 102 |
// private double unitFactor = 1D; |
106 | 103 |
private double fixedSize = 10; |
107 | 104 |
private Color fixedColor; |
108 |
private int unit = -1; //(pixel) |
|
105 |
// private int unit = -1; //(pixel)
|
|
109 | 106 |
private boolean useFixedSize; |
110 | 107 |
private boolean useFixedColor; |
111 |
private int referenceSystem; |
|
108 |
// private int referenceSystem;
|
|
112 | 109 |
// private boolean isPrinting; |
113 | 110 |
private String[] usedFields = null; |
114 | 111 |
private Font font; |
... | ... | |
118 | 115 |
private String heightFieldName; |
119 | 116 |
private String colorFieldName; |
120 | 117 |
|
118 |
@Override |
|
121 | 119 |
public ILabelingMethod getLabelingMethod() { |
122 | 120 |
return this.method; |
123 | 121 |
} |
124 | 122 |
|
123 |
@Override |
|
125 | 124 |
public void setLabelingMethod(ILabelingMethod method) { |
126 | 125 |
this.method = method; |
127 | 126 |
} |
128 | 127 |
|
128 |
@Override |
|
129 | 129 |
public IPlacementConstraints getPlacementConstraints() { |
130 | 130 |
return null; // (automatically handled by the driver) |
131 | 131 |
} |
132 | 132 |
|
133 |
@Override |
|
133 | 134 |
public void setPlacementConstraints(IPlacementConstraints constraints) { |
134 | 135 |
// nothing |
135 | 136 |
} |
136 | 137 |
|
138 |
@Override |
|
137 | 139 |
public IZoomConstraints getZoomConstraints() { |
138 | 140 |
return zoom; |
139 | 141 |
} |
140 | 142 |
|
143 |
@Override |
|
141 | 144 |
public void setZoomConstraints(IZoomConstraints constraints) { |
142 | 145 |
this.zoom = constraints; |
143 | 146 |
} |
144 | 147 |
|
145 |
// private double getScale(ViewPort vp, PrintAttributes patts) |
|
146 |
// throws ReadException { |
|
147 |
// |
|
148 |
// double dpi = 0; |
|
149 |
// if (patts != null) { |
|
150 |
// int len = PrintAttributes.PRINT_QUALITY_DPI.length; |
|
151 |
// int priq = patts.getPrintQuality(); |
|
152 |
// if (priq < 0 || priq >= len) { |
|
153 |
// dpi = vp.getDPI(); |
|
154 |
// } else { |
|
155 |
// dpi = PrintAttributes.PRINT_QUALITY_DPI[priq]; |
|
156 |
// } |
|
157 |
// } else { |
|
158 |
// dpi = vp.getDPI(); |
|
159 |
// } |
|
160 |
// |
|
161 |
// // ============== We have dpi now ==================== |
|
162 |
// IProjection proj = vp.getProjection(); |
|
163 |
// |
|
164 |
// if (vp.getImageSize() == null || vp.getAdjustedEnvelope() == null) { |
|
165 |
// throw new ReadException("", |
|
166 |
// new Exception("Viewport does not have image size or envelope")); |
|
167 |
// } |
|
168 |
// |
|
169 |
// double[] trans2Meter = MapContext.getDistanceTrans2Meter(); |
|
170 |
// if (proj == null) { |
|
171 |
// double wmeters = ((vp.getImageSize().width / dpi) * 0.0254); |
|
172 |
// return (long) ((trans2Meter[vp.getMapUnits()] * vp.getAdjustedEnvelope().getLength(0)) |
|
173 |
// / wmeters); |
|
174 |
// } else { |
|
175 |
// return Math.round(proj.getScale( |
|
176 |
// vp.getAdjustedEnvelope().getMinimum(0) |
|
177 |
// * trans2Meter[vp.getMapUnits()], |
|
178 |
// vp.getAdjustedEnvelope().getMaximum(0) |
|
179 |
// * trans2Meter[vp.getMapUnits()], |
|
180 |
// vp.getImageSize().width, |
|
181 |
// dpi)); |
|
182 |
// } |
|
183 |
// |
|
184 |
// } |
|
185 |
|
|
186 | 148 |
private void draw(BufferedImage image, Graphics2D g, double scale, ViewPort viewPort, |
187 | 149 |
Cancellable cancel, PrintAttributes props) throws ReadException { |
188 | 150 |
|
189 |
// double scale = getScale(viewPort, props); |
|
190 | 151 |
|
191 | 152 |
SimpleTextSymbol sym = new SimpleTextSymbol(); |
192 | 153 |
sym.setFont(getFont()); |
193 |
sym.setUnit(unit); |
|
194 |
sym.setReferenceSystem(referenceSystem); |
|
154 |
sym.setCartographicContext(this.getCartographicContext()); |
|
195 | 155 |
if (zoom == null |
196 | 156 |
|| (zoom.isUserDefined() && (scale >= zoom.getMaxScale()) |
197 | 157 |
&& (scale <= zoom.getMinScale()))) { |
... | ... | |
477 | 437 |
} |
478 | 438 |
} |
479 | 439 |
|
440 |
@Override |
|
480 | 441 |
public void draw(BufferedImage image, Graphics2D g, double scale, ViewPort viewPort, |
481 | 442 |
Cancellable cancel, double dpi) throws ReadException { |
482 | 443 |
draw(image, g, scale, viewPort, cancel, null); |
... | ... | |
487 | 448 |
|
488 | 449 |
try { |
489 | 450 |
return geom.centroid(); |
490 |
} catch (GeometryOperationNotSupportedException e) {
|
|
451 |
} catch (Exception e) { |
|
491 | 452 |
return null; |
492 |
} catch (GeometryOperationException e) { |
|
493 |
return null; |
|
494 | 453 |
} |
495 | 454 |
} |
496 | 455 |
|
497 |
// public String getClassName() { |
|
498 |
// return getClass().getName(); |
|
499 |
// } |
|
456 |
@Override |
|
500 | 457 |
public String getRotationField() { |
501 | 458 |
return this.rotationFieldName; |
502 | 459 |
} |
503 | 460 |
|
461 |
@Override |
|
504 | 462 |
public String getTextField() { |
505 | 463 |
return this.textFieldName; |
506 | 464 |
} |
507 | 465 |
|
466 |
@Override |
|
508 | 467 |
public String getHeightField() { |
509 | 468 |
return this.heightFieldName; |
510 | 469 |
} |
511 | 470 |
|
471 |
@Override |
|
512 | 472 |
public String getColorField() { |
513 | 473 |
return this.colorFieldName; |
514 | 474 |
} |
515 | 475 |
|
476 |
@Override |
|
516 | 477 |
public void setTextField(String textFieldName) { |
517 | 478 |
this.textFieldName = textFieldName; |
518 | 479 |
this.usedFields = null; |
519 | 480 |
} |
520 | 481 |
|
482 |
@Override |
|
521 | 483 |
public void setRotationField(String rotationFieldName) { |
522 | 484 |
this.rotationFieldName = rotationFieldName; |
523 | 485 |
this.usedFields = null; |
... | ... | |
530 | 492 |
* |
531 | 493 |
* @param heightFieldName |
532 | 494 |
*/ |
495 |
@Override |
|
533 | 496 |
public void setHeightField(String heightFieldName) { |
534 | 497 |
this.heightFieldName = heightFieldName; |
535 | 498 |
this.usedFields = null; |
536 | 499 |
} |
537 | 500 |
|
501 |
@Override |
|
538 | 502 |
public void setColorField(String colorFieldName) { |
539 | 503 |
this.colorFieldName = colorFieldName; |
540 | 504 |
} |
541 | 505 |
|
506 |
@Override |
|
542 | 507 |
public void print(Graphics2D g, double scale, ViewPort viewPort, Cancellable cancel, |
543 | 508 |
PrintAttributes props) throws ReadException { |
544 | 509 |
draw(null, g, scale, viewPort, cancel, props); |
545 | 510 |
} |
546 | 511 |
|
512 |
@Override |
|
547 | 513 |
public void setUsesFixedSize(boolean b) { |
548 | 514 |
useFixedSize = b; |
549 | 515 |
this.usedFields = null; |
550 | 516 |
} |
551 | 517 |
|
518 |
@Override |
|
552 | 519 |
public boolean usesFixedSize() { |
553 | 520 |
return useFixedSize; |
554 | 521 |
} |
555 | 522 |
|
523 |
@Override |
|
556 | 524 |
public double getFixedSize() { |
557 | 525 |
return fixedSize; |
558 | 526 |
} |
559 | 527 |
|
528 |
@Override |
|
560 | 529 |
public void setFixedSize(double fixedSize) { |
561 | 530 |
this.fixedSize = fixedSize; |
562 | 531 |
this.usedFields = null; |
563 | 532 |
} |
564 | 533 |
|
534 |
@Override |
|
565 | 535 |
public void setUsesFixedColor(boolean b) { |
566 | 536 |
useFixedColor = b; |
567 | 537 |
this.usedFields = null; |
568 | 538 |
} |
569 | 539 |
|
540 |
@Override |
|
570 | 541 |
public boolean usesFixedColor() { |
571 | 542 |
return useFixedColor; |
572 | 543 |
} |
573 | 544 |
|
545 |
@Override |
|
574 | 546 |
public Color getFixedColor() { |
575 | 547 |
return fixedColor; |
576 | 548 |
} |
577 | 549 |
|
550 |
@Override |
|
578 | 551 |
public void setFixedColor(Color fixedColor) { |
579 | 552 |
this.fixedColor = fixedColor; |
580 | 553 |
} |
581 | 554 |
|
582 |
public void setUnit(int unitIndex) { |
|
583 |
unit = unitIndex; |
|
584 |
|
|
585 |
} |
|
586 |
|
|
587 |
public int getUnit() { |
|
588 |
return unit; |
|
589 |
} |
|
590 |
|
|
555 |
@Override |
|
591 | 556 |
public String[] getUsedFields() { |
592 | 557 |
if (this.usedFields == null) { |
593 |
List<String> v = new ArrayList<String>(4);
|
|
558 |
List<String> v = new ArrayList<>(4); |
|
594 | 559 |
if (!this.usesFixedSize()) { |
595 | 560 |
if (getHeightField() != null) { |
596 | 561 |
v.add(getHeightField()); |
... | ... | |
611 | 576 |
return this.usedFields; |
612 | 577 |
} |
613 | 578 |
|
614 |
public int getReferenceSystem() { |
|
615 |
return referenceSystem; |
|
616 |
} |
|
617 |
|
|
618 |
public void setReferenceSystem(int referenceSystem) { |
|
619 |
this.referenceSystem = referenceSystem; |
|
620 |
} |
|
621 |
|
|
622 |
public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
623 |
// not required here |
|
624 |
throw new Error("Undefined in this context"); |
|
625 |
} |
|
626 |
|
|
627 |
public void setCartographicSize(double cartographicSize, Geometry geom) { |
|
628 |
// not required here |
|
629 |
throw new Error("Undefined in this context"); |
|
630 |
} |
|
631 |
|
|
632 |
public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) { |
|
633 |
// not required here |
|
634 |
throw new Error("Undefined in this context"); |
|
635 |
|
|
636 |
} |
|
637 |
|
|
579 |
@Override |
|
638 | 580 |
public void setLayer(FLayer layer) { |
639 | 581 |
this.layer = (FLyrVect) layer; |
640 | 582 |
if (layer == null) { |
... | ... | |
669 | 611 |
} |
670 | 612 |
} |
671 | 613 |
|
614 |
@Override |
|
672 | 615 |
public boolean shouldDrawLabels(double scale) { |
673 | 616 |
return layer.isWithinScale(scale); |
674 | 617 |
} |
675 | 618 |
|
619 |
@Override |
|
676 | 620 |
public Color getColorFont() { |
677 | 621 |
return colorFont; |
678 | 622 |
} |
679 | 623 |
|
624 |
@Override |
|
680 | 625 |
public void setColorFont(Color colorFont) { |
681 | 626 |
this.colorFont = colorFont; |
682 | 627 |
} |
683 | 628 |
|
629 |
@Override |
|
684 | 630 |
public Font getFont() { |
685 | 631 |
return font; |
686 | 632 |
} |
687 | 633 |
|
634 |
@Override |
|
688 | 635 |
public void setFont(Font selFont) { |
689 | 636 |
this.font = selFont; |
690 | 637 |
} |
... | ... | |
692 | 639 |
/* (non-Javadoc) |
693 | 640 |
* @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState) |
694 | 641 |
*/ |
642 |
@Override |
|
695 | 643 |
public void loadFromState(PersistentState state) |
696 | 644 |
throws PersistenceException { |
697 | 645 |
|
... | ... | |
714 | 662 |
/* (non-Javadoc) |
715 | 663 |
* @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState) |
716 | 664 |
*/ |
665 |
@Override |
|
717 | 666 |
public void saveToState(final PersistentState state) throws PersistenceException { |
718 | 667 |
state.set(FIELD_TEXT, getTextField()); |
719 | 668 |
state.set(FIELD_HEIGHT, getHeightField()); |
... | ... | |
733 | 682 |
|
734 | 683 |
public static class RegisterPersistence implements Callable { |
735 | 684 |
|
685 |
@Override |
|
736 | 686 |
public Object call() throws Exception { |
737 | 687 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
738 | 688 |
if (manager.getDefinition(ATTR_IN_TABLE_LABELING_STRATEGY_PERSISTENCE_DEFINITION_NAME) == null) { |
Also available in: Unified diff