Revision 571 org.gvsig.chart/trunk/org.gvsig.chart/org.gvsig.chart.app/org.gvsig.chart.app.legendplugin/src/main/java/org/gvsig/project/documents/view/legend/BasePieChartLegend.java
BasePieChartLegend.java | ||
---|---|---|
31 | 31 |
import org.gvsig.symbology.SymbologyLocator; |
32 | 32 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
33 | 33 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol; |
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.dynobject.DynStruct; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 | 34 |
import org.gvsig.tools.persistence.PersistentState; |
38 | 35 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
39 | 36 |
import org.gvsig.tools.task.Cancellable; |
40 |
import org.gvsig.tools.util.Callable; |
|
41 | 37 |
|
42 | 38 |
/** |
43 | 39 |
* @author Fjp |
... | ... | |
46 | 42 |
* ESTA SE USA PARA TODO TIPO DE CHARTS. (BarsChartLegend no se usa, borrarla) |
47 | 43 |
*/ |
48 | 44 |
public class BasePieChartLegend extends VectorialUniqueValueLegend { |
45 |
|
|
49 | 46 |
final static private Logger LOG = LoggerFactory.getLogger(BasePieChartLegend.class); |
50 | 47 |
|
51 |
public static final String PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "PieChartLegend";
|
|
48 |
public static final String BASE_PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "BasePieChartLegend";
|
|
52 | 49 |
|
53 |
private static final String FIELD_NAMES = "FieldLegendNames";
|
|
54 |
private static final String FIELD_LABEL_NAMES = "FieldLabelNames";
|
|
55 |
private static final String FIELD_LABEL_COLOR = "FieldLabelColor";
|
|
50 |
private static final String FIELD_NAMES = "FieldLegendNames";
|
|
51 |
private static final String FIELD_LABEL_NAMES = "FieldLabelNames";
|
|
52 |
private static final String FIELD_LABEL_COLOR = "FieldLabelColor";
|
|
56 | 53 |
|
57 |
protected ISymbol backgroundSymbol;
|
|
58 |
protected String[] fields;
|
|
59 |
protected String[] labels;
|
|
60 |
protected int size=150;
|
|
61 |
protected boolean is3D;
|
|
54 |
protected ISymbol backgroundSymbol;
|
|
55 |
protected String[] fields;
|
|
56 |
protected String[] labels;
|
|
57 |
protected int size = 150;
|
|
58 |
protected boolean is3D;
|
|
62 | 59 |
|
63 |
protected boolean isOutlineShow;
|
|
64 |
protected Color outlineColor;
|
|
65 |
protected int outlineWidth;
|
|
66 |
protected boolean onlySelection=false;
|
|
67 |
protected int referenceSystem=0;
|
|
68 |
protected String fieldSize;
|
|
69 |
protected String fieldNormalize="---";
|
|
70 |
protected int sizeFrom=10;
|
|
71 |
protected int sizeTo=1000;
|
|
72 |
protected int unit=-1;
|
|
73 |
protected int sizeOption = IChartSymbol.SIZEFIXED;
|
|
74 |
protected ZSort zSort = null;
|
|
75 |
protected boolean isActiveLimits;
|
|
76 |
protected double minFeature;
|
|
77 |
protected double maxFeature;
|
|
78 |
protected Color[] colors= null;
|
|
79 |
protected IChartSymbol symbol;
|
|
80 |
private double maxField;
|
|
81 |
protected FeatureSelection featSelection;
|
|
60 |
protected boolean isOutlineShow;
|
|
61 |
protected Color outlineColor;
|
|
62 |
protected int outlineWidth;
|
|
63 |
protected boolean onlySelection = false;
|
|
64 |
protected int referenceSystem = 0;
|
|
65 |
protected String fieldSize;
|
|
66 |
protected String fieldNormalize = "---";
|
|
67 |
protected int sizeFrom = 10;
|
|
68 |
protected int sizeTo = 1000;
|
|
69 |
protected int unit = -1;
|
|
70 |
protected int sizeOption = IChartSymbol.SIZEFIXED;
|
|
71 |
protected ZSort zSort = null;
|
|
72 |
protected boolean isActiveLimits;
|
|
73 |
protected double minFeature;
|
|
74 |
protected double maxFeature;
|
|
75 |
protected Color[] colors = null;
|
|
76 |
protected IChartSymbol symbol;
|
|
77 |
private double maxField;
|
|
78 |
protected FeatureSelection featSelection;
|
|
82 | 79 |
|
83 |
public BasePieChartLegend() {
|
|
84 |
}
|
|
80 |
public BasePieChartLegend() {
|
|
81 |
}
|
|
85 | 82 |
|
86 |
public BasePieChartLegend(int shapeType) {
|
|
87 |
super(shapeType);
|
|
88 |
}
|
|
83 |
public BasePieChartLegend(int shapeType) {
|
|
84 |
super(shapeType);
|
|
85 |
}
|
|
89 | 86 |
|
87 |
@Override |
|
88 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
89 |
Cancellable cancel, double scale, Map queryParameters, |
|
90 |
ICoordTrans coordTrans, FeatureStore featureStore, |
|
91 |
FeatureQuery featureQuery) throws LegendException { |
|
92 |
try { |
|
93 |
this.featSelection = featureStore.getFeatureSelection(); |
|
94 |
System.out.println("CHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados."); |
|
95 |
} catch (DataException e) { |
|
96 |
e.printStackTrace(); |
|
97 |
} |
|
90 | 98 |
|
91 |
@Override |
|
92 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
93 |
Cancellable cancel, double scale, Map queryParameters, |
|
94 |
ICoordTrans coordTrans, FeatureStore featureStore, |
|
95 |
FeatureQuery featureQuery) throws LegendException { |
|
96 |
try { |
|
97 |
this.featSelection = featureStore.getFeatureSelection(); |
|
98 |
System.out.println("CHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados."); |
|
99 |
} catch (DataException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
} |
|
99 |
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
100 |
featureStore, featureQuery); |
|
101 |
} |
|
102 | 102 |
|
103 |
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, |
|
104 |
featureStore, featureQuery); |
|
105 |
} |
|
106 |
|
|
107 |
/* (non-Javadoc) |
|
103 |
/* (non-Javadoc) |
|
108 | 104 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#is3D() |
109 |
*/
|
|
110 |
public boolean is3D() {
|
|
111 |
return is3D;
|
|
112 |
}
|
|
105 |
*/
|
|
106 |
public boolean is3D() {
|
|
107 |
return is3D;
|
|
108 |
}
|
|
113 | 109 |
|
114 |
/* (non-Javadoc)
|
|
110 |
/* (non-Javadoc)
|
|
115 | 111 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setIs3D(boolean) |
116 |
*/
|
|
117 |
public void setIs3D(boolean b){
|
|
118 |
is3D=b;
|
|
119 |
}
|
|
112 |
*/
|
|
113 |
public void setIs3D(boolean b) {
|
|
114 |
is3D = b;
|
|
115 |
}
|
|
120 | 116 |
|
121 |
/* (non-Javadoc)
|
|
117 |
/* (non-Javadoc)
|
|
122 | 118 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getSize() |
123 |
*/
|
|
124 |
public int getSize() {
|
|
125 |
return size;
|
|
126 |
}
|
|
119 |
*/
|
|
120 |
public int getSize() {
|
|
121 |
return size;
|
|
122 |
}
|
|
127 | 123 |
|
128 |
/* (non-Javadoc)
|
|
124 |
/* (non-Javadoc)
|
|
129 | 125 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setSize(int) |
130 |
*/
|
|
131 |
public void setSize(int size) {
|
|
132 |
this.size = size;
|
|
133 |
}
|
|
126 |
*/
|
|
127 |
public void setSize(int size) {
|
|
128 |
this.size = size;
|
|
129 |
}
|
|
134 | 130 |
|
135 |
/* (non-Javadoc)
|
|
131 |
/* (non-Javadoc)
|
|
136 | 132 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#isOutlineShow() |
137 |
*/
|
|
138 |
public boolean isOutlineShow() {
|
|
139 |
return isOutlineShow;
|
|
140 |
}
|
|
133 |
*/
|
|
134 |
public boolean isOutlineShow() {
|
|
135 |
return isOutlineShow;
|
|
136 |
}
|
|
141 | 137 |
|
142 |
/* (non-Javadoc)
|
|
138 |
/* (non-Javadoc)
|
|
143 | 139 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineShow(boolean) |
144 |
*/
|
|
145 |
public void setOutlineShow(boolean isOutlineShow) {
|
|
146 |
this.isOutlineShow = isOutlineShow;
|
|
147 |
}
|
|
140 |
*/
|
|
141 |
public void setOutlineShow(boolean isOutlineShow) {
|
|
142 |
this.isOutlineShow = isOutlineShow;
|
|
143 |
}
|
|
148 | 144 |
|
149 |
/* (non-Javadoc)
|
|
145 |
/* (non-Javadoc)
|
|
150 | 146 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getOutlineColor() |
151 |
*/
|
|
152 |
public Color getOutlineColor() {
|
|
153 |
return outlineColor;
|
|
154 |
}
|
|
147 |
*/
|
|
148 |
public Color getOutlineColor() {
|
|
149 |
return outlineColor;
|
|
150 |
}
|
|
155 | 151 |
|
156 |
/* (non-Javadoc)
|
|
152 |
/* (non-Javadoc)
|
|
157 | 153 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineColor(java.awt.Color) |
158 |
*/
|
|
159 |
public void setOutlineColor(Color outlineColor) {
|
|
160 |
this.outlineColor = outlineColor;
|
|
161 |
}
|
|
154 |
*/
|
|
155 |
public void setOutlineColor(Color outlineColor) {
|
|
156 |
this.outlineColor = outlineColor;
|
|
157 |
}
|
|
162 | 158 |
|
163 |
/* (non-Javadoc)
|
|
159 |
/* (non-Javadoc)
|
|
164 | 160 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getOutlineWidth() |
165 |
*/
|
|
166 |
public int getOutlineWidth() {
|
|
167 |
return outlineWidth;
|
|
168 |
}
|
|
161 |
*/
|
|
162 |
public int getOutlineWidth() {
|
|
163 |
return outlineWidth;
|
|
164 |
}
|
|
169 | 165 |
|
170 |
/* (non-Javadoc)
|
|
166 |
/* (non-Javadoc)
|
|
171 | 167 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineWidth(int) |
172 |
*/ |
|
173 |
public void setOutlineWidth(int outlineWidth) { |
|
174 |
this.outlineWidth = outlineWidth; |
|
175 |
} |
|
176 |
/* (non-Javadoc) |
|
168 |
*/ |
|
169 |
public void setOutlineWidth(int outlineWidth) { |
|
170 |
this.outlineWidth = outlineWidth; |
|
171 |
} |
|
172 |
|
|
173 |
/* (non-Javadoc) |
|
177 | 174 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOnlySelection(boolean) |
178 |
*/
|
|
179 |
public void setOnlySelection(boolean onlySelection) {
|
|
180 |
this.onlySelection=onlySelection;
|
|
181 |
}
|
|
175 |
*/
|
|
176 |
public void setOnlySelection(boolean onlySelection) {
|
|
177 |
this.onlySelection = onlySelection;
|
|
178 |
}
|
|
182 | 179 |
|
183 |
/* (non-Javadoc)
|
|
180 |
/* (non-Javadoc)
|
|
184 | 181 |
* @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#isOnlySelection() |
185 |
*/
|
|
186 |
public boolean isOnlySelection() {
|
|
187 |
return onlySelection;
|
|
188 |
}
|
|
182 |
*/
|
|
183 |
public boolean isOnlySelection() {
|
|
184 |
return onlySelection;
|
|
185 |
}
|
|
189 | 186 |
|
190 |
public ISymbol getBackgroundSymbol() {
|
|
191 |
return backgroundSymbol;
|
|
192 |
}
|
|
187 |
public ISymbol getBackgroundSymbol() {
|
|
188 |
return backgroundSymbol;
|
|
189 |
}
|
|
193 | 190 |
|
194 |
public void setBackgroundSymbol(ISymbol backgroundSymbol) {
|
|
195 |
this.backgroundSymbol = backgroundSymbol;
|
|
196 |
}
|
|
191 |
public void setBackgroundSymbol(ISymbol backgroundSymbol) {
|
|
192 |
this.backgroundSymbol = backgroundSymbol;
|
|
193 |
}
|
|
197 | 194 |
|
198 |
public int getSizeOption() {
|
|
199 |
return this.sizeOption;
|
|
200 |
}
|
|
195 |
public int getSizeOption() {
|
|
196 |
return this.sizeOption;
|
|
197 |
}
|
|
201 | 198 |
|
202 |
public String getFieldSize() {
|
|
203 |
return this.fieldSize;
|
|
204 |
}
|
|
199 |
public String getFieldSize() {
|
|
200 |
return this.fieldSize;
|
|
201 |
}
|
|
205 | 202 |
|
206 |
public String getFieldNormalize() {
|
|
207 |
return this.fieldNormalize;
|
|
208 |
}
|
|
203 |
public String getFieldNormalize() {
|
|
204 |
return this.fieldNormalize;
|
|
205 |
}
|
|
209 | 206 |
|
210 |
public int getSizeFrom() {
|
|
211 |
return this.sizeFrom;
|
|
212 |
}
|
|
207 |
public int getSizeFrom() {
|
|
208 |
return this.sizeFrom;
|
|
209 |
}
|
|
213 | 210 |
|
214 |
public int getSizeTo() {
|
|
215 |
return this.sizeTo;
|
|
216 |
}
|
|
211 |
public int getSizeTo() {
|
|
212 |
return this.sizeTo;
|
|
213 |
}
|
|
217 | 214 |
|
218 |
public int getUnit() {
|
|
219 |
return unit;
|
|
220 |
}
|
|
215 |
public int getUnit() {
|
|
216 |
return unit;
|
|
217 |
}
|
|
221 | 218 |
|
222 |
public void setSizeFrom(int s) {
|
|
223 |
this.sizeFrom = s;
|
|
224 |
}
|
|
219 |
public void setSizeFrom(int s) {
|
|
220 |
this.sizeFrom = s;
|
|
221 |
}
|
|
225 | 222 |
|
226 |
public void setSizeTo(int s) {
|
|
227 |
this.sizeTo = s;
|
|
228 |
}
|
|
223 |
public void setSizeTo(int s) {
|
|
224 |
this.sizeTo = s;
|
|
225 |
}
|
|
229 | 226 |
|
230 |
public void setUnit(int unit) {
|
|
231 |
this.unit = unit;
|
|
232 |
}
|
|
227 |
public void setUnit(int unit) {
|
|
228 |
this.unit = unit;
|
|
229 |
}
|
|
233 | 230 |
|
234 |
public void setFieldSize(String f) {
|
|
235 |
this.fieldSize = f;
|
|
236 |
}
|
|
231 |
public void setFieldSize(String f) {
|
|
232 |
this.fieldSize = f;
|
|
233 |
}
|
|
237 | 234 |
|
238 |
public void setFieldNormalize(String f) {
|
|
239 |
this.fieldNormalize = f;
|
|
240 |
}
|
|
235 |
public void setFieldNormalize(String f) {
|
|
236 |
this.fieldNormalize = f;
|
|
237 |
}
|
|
241 | 238 |
|
242 |
public void setSizeOption(int option) {
|
|
243 |
this.sizeOption = option;
|
|
244 |
}
|
|
239 |
public void setSizeOption(int option) {
|
|
240 |
this.sizeOption = option;
|
|
241 |
}
|
|
245 | 242 |
|
246 |
public boolean isActiveLimits() {
|
|
247 |
return isActiveLimits;
|
|
248 |
}
|
|
243 |
public boolean isActiveLimits() {
|
|
244 |
return isActiveLimits;
|
|
245 |
}
|
|
249 | 246 |
|
250 |
public void setActiveLimits(boolean b) {
|
|
251 |
this.isActiveLimits = b;
|
|
252 |
}
|
|
247 |
public void setActiveLimits(boolean b) {
|
|
248 |
this.isActiveLimits = b;
|
|
249 |
}
|
|
253 | 250 |
|
254 |
public Color[] getColors() {
|
|
255 |
return colors;
|
|
256 |
}
|
|
251 |
public Color[] getColors() {
|
|
252 |
return colors;
|
|
253 |
}
|
|
257 | 254 |
|
258 |
public void setColors(Color[] colors) {
|
|
259 |
this.colors = colors;
|
|
260 |
updateSymbols();
|
|
261 |
}
|
|
255 |
public void setColors(Color[] colors) {
|
|
256 |
this.colors = colors;
|
|
257 |
updateSymbols();
|
|
258 |
}
|
|
262 | 259 |
|
263 |
public int getReferenceSystem() {
|
|
264 |
return referenceSystem;
|
|
265 |
}
|
|
260 |
public int getReferenceSystem() {
|
|
261 |
return referenceSystem;
|
|
262 |
}
|
|
266 | 263 |
|
267 |
public void setReferenceSystem(int rs) {
|
|
268 |
this.referenceSystem = rs;
|
|
269 |
}
|
|
264 |
public void setReferenceSystem(int rs) {
|
|
265 |
this.referenceSystem = rs;
|
|
266 |
}
|
|
270 | 267 |
|
271 |
public void setMinFeature(double min) {
|
|
272 |
this.minFeature = min;
|
|
273 |
}
|
|
268 |
public void setMinFeature(double min) {
|
|
269 |
this.minFeature = min;
|
|
270 |
}
|
|
274 | 271 |
|
275 |
public void setMaxFeature(double max) {
|
|
276 |
this.maxFeature = max;
|
|
277 |
}
|
|
272 |
public void setMaxFeature(double max) {
|
|
273 |
this.maxFeature = max;
|
|
274 |
}
|
|
278 | 275 |
|
279 |
@Override
|
|
280 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
|
|
276 |
@Override
|
|
277 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
|
|
281 | 278 |
|
282 |
if (this.onlySelection) |
|
283 |
if (!featSelection.isSelected(feat)) |
|
284 |
return null; |
|
279 |
if (this.onlySelection) { |
|
280 |
if (!featSelection.isSelected(feat)) { |
|
281 |
return null; |
|
282 |
} |
|
283 |
} |
|
285 | 284 |
|
286 |
// TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
|
|
287 |
symbol = (IChartSymbol) getDefaultSymbol();
|
|
288 |
if (symbol==null){
|
|
289 |
symbol = (IChartSymbol) MapContextLocator
|
|
290 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
|
|
285 |
// TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
|
|
286 |
symbol = (IChartSymbol) getDefaultSymbol();
|
|
287 |
if (symbol == null) {
|
|
288 |
symbol = (IChartSymbol) MapContextLocator
|
|
289 |
.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
|
|
291 | 290 |
|
292 |
}
|
|
293 |
symbol.setOnlySelection(onlySelection);
|
|
294 |
double size=0;
|
|
291 |
}
|
|
292 |
symbol.setOnlySelection(onlySelection);
|
|
293 |
double size = 0;
|
|
295 | 294 |
|
296 |
ChartDataSet dataSet = ChartLocator.getServiceManager()
|
|
297 |
.getChartManager().createChartDataSet();
|
|
295 |
ChartDataSet dataSet = ChartLocator.getServiceManager()
|
|
296 |
.getChartManager().createChartDataSet();
|
|
298 | 297 |
|
299 |
String[] names=getFieldNames();
|
|
300 |
String[] labels=getFieldLabels();
|
|
301 |
if (names!=null && labels != null && labels.length == names.length){
|
|
298 |
String[] names = getFieldNames();
|
|
299 |
String[] labels = getFieldLabels();
|
|
300 |
if (names != null && labels != null && labels.length == names.length) {
|
|
302 | 301 |
|
303 |
ArrayList serie = new ArrayList();
|
|
304 |
ArrayList category = new ArrayList();
|
|
305 |
for (int i = 0; i < names.length; i++) {
|
|
306 |
double val = feat.getDouble(names[i]);
|
|
307 |
if (sizeOption==IChartSymbol.SIZESUM){
|
|
308 |
size+=val;
|
|
309 |
}
|
|
310 |
if(!this.onlySelection || featSelection.isSelected(feat)){
|
|
311 |
serie.add(labels[i]);
|
|
312 |
category.add(val);
|
|
313 |
}
|
|
314 |
}
|
|
315 |
dataSet.addData("series", serie);
|
|
316 |
dataSet.addData("categories", category);
|
|
302 |
ArrayList serie = new ArrayList();
|
|
303 |
ArrayList category = new ArrayList();
|
|
304 |
for (int i = 0; i < names.length; i++) {
|
|
305 |
double val = feat.getDouble(names[i]);
|
|
306 |
if (sizeOption == IChartSymbol.SIZESUM) {
|
|
307 |
size += val;
|
|
308 |
}
|
|
309 |
if (!this.onlySelection || featSelection.isSelected(feat)) {
|
|
310 |
serie.add(labels[i]);
|
|
311 |
category.add(val);
|
|
312 |
}
|
|
313 |
}
|
|
314 |
dataSet.addData("series", serie);
|
|
315 |
dataSet.addData("categories", category);
|
|
317 | 316 |
|
318 |
if(!this.onlySelection || featSelection.isSelected(feat)){ |
|
319 |
symbol.getChart().setChartDataSet(dataSet); |
|
320 |
} |
|
321 |
ChartService cs = symbol.getChart(); |
|
322 |
// cs.createChartLegendItems(); |
|
323 |
List<ChartSerieEntity> lst = cs.getChartLegendItems(); |
|
317 |
if (!this.onlySelection || featSelection.isSelected(feat)) { |
|
318 |
symbol.getChart().setChartDataSet(dataSet); |
|
319 |
} |
|
320 |
ChartService cs = symbol.getChart(); |
|
324 | 321 |
|
325 |
for (int j=0; j < names.length; j++) { |
|
326 |
LegendItem item = new LegendItem(names[j], getSymbolByValue(names[j]).getColor()); |
|
327 |
item.setSeriesKey(names[j]); |
|
328 |
ChartSerieEntity e = cs.createNewChartSerieEntity(item); |
|
329 |
if(e!=null) |
|
330 |
lst.add(e); |
|
331 |
} |
|
332 |
} |
|
333 |
double separation = sizeTo-sizeFrom; |
|
322 |
List<ChartSerieEntity> lst = cs.getChartLegendItems(); |
|
334 | 323 |
|
335 |
if (sizeOption==IChartSymbol.SIZESUM){ |
|
336 |
if (isActiveLimits()){ |
|
337 |
double difFeat = maxFeature - minFeature; |
|
338 |
double step = difFeat/separation; |
|
339 |
size = sizeFrom + ((size - minFeature)/step); |
|
340 |
} |
|
341 |
symbol.setSize(size); |
|
342 |
}else if (sizeOption==IChartSymbol.SIZEFIELD){ |
|
343 |
if(separation == 0) |
|
344 |
separation = 1; |
|
345 |
double value=feat.getDouble(getFieldSize()); |
|
324 |
for (int j = 0; j < names.length; j++) { |
|
325 |
LegendItem item = new LegendItem(names[j], getSymbolByValue(names[j]).getColor()); |
|
326 |
item.setSeriesKey(names[j]); |
|
327 |
ChartSerieEntity e = cs.createNewChartSerieEntity(item); |
|
328 |
if (e != null) { |
|
329 |
lst.add(e); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
double separation = sizeTo - sizeFrom; |
|
346 | 334 |
|
347 |
if (!getFieldNormalize().equals("---")){ |
|
348 |
double normalize=feat.getDouble(getFieldNormalize()); |
|
349 |
if (normalize!=0){ |
|
350 |
value= value/normalize; |
|
351 |
} |
|
352 |
if (isActiveLimits()) |
|
353 |
size = sizeFrom + (value * separation) ; |
|
354 |
else |
|
355 |
size=value; |
|
356 |
}else{ |
|
357 |
if (isActiveLimits()){ |
|
358 |
double difFeat = maxFeature - minFeature; |
|
359 |
double step = difFeat/separation; |
|
360 |
size = sizeFrom + ((value - minFeature)/step); |
|
361 |
}else{ |
|
362 |
size=value; |
|
363 |
} |
|
364 |
} |
|
335 |
switch (sizeOption) { |
|
336 |
case IChartSymbol.SIZESUM: |
|
337 |
if (isActiveLimits()) { |
|
338 |
double difFeat = maxFeature - minFeature; |
|
339 |
double step = difFeat / separation; |
|
340 |
size = sizeFrom + ((size - minFeature) / step); |
|
341 |
} |
|
342 |
symbol.setSize(size); |
|
343 |
break; |
|
344 |
case IChartSymbol.SIZEFIELD: |
|
345 |
if (separation == 0) { |
|
346 |
separation = 1; |
|
347 |
} |
|
348 |
double value = feat.getDouble(getFieldSize()); |
|
349 |
if (!getFieldNormalize().equals("---")) { |
|
350 |
double normalize = feat.getDouble(getFieldNormalize()); |
|
351 |
if (normalize != 0) { |
|
352 |
value = value / normalize; |
|
353 |
} |
|
354 |
if (isActiveLimits()) { |
|
355 |
size = sizeFrom + (value * separation); |
|
356 |
} else { |
|
357 |
size = value; |
|
358 |
} |
|
359 |
} else { |
|
360 |
if (isActiveLimits()) { |
|
361 |
double difFeat = maxFeature - minFeature; |
|
362 |
double step = difFeat / separation; |
|
363 |
size = sizeFrom + ((value - minFeature) / step); |
|
364 |
} else { |
|
365 |
size = value; |
|
366 |
} |
|
367 |
} |
|
368 |
symbol.setSize(size); |
|
369 |
break; |
|
370 |
default: |
|
371 |
symbol.setSize(getSize()); |
|
372 |
break; |
|
373 |
} |
|
374 |
return symbol; |
|
365 | 375 |
|
366 |
}else{ |
|
367 |
symbol.setSize(getSize()); |
|
368 |
} |
|
369 |
return symbol; |
|
376 |
} |
|
370 | 377 |
|
371 |
} |
|
378 |
public String[] getFieldNames() { |
|
379 |
return fields; |
|
380 |
} |
|
372 | 381 |
|
373 |
public String[] getFieldNames() { |
|
374 |
return fields; |
|
375 |
} |
|
382 |
public String[] getFieldLabels() { |
|
383 |
if (labels == null) { |
|
384 |
return new String[0]; |
|
385 |
} |
|
386 |
return labels; |
|
387 |
} |
|
376 | 388 |
|
377 |
public String[] getFieldLabels() { |
|
378 |
if(labels==null) |
|
379 |
return new String[0]; |
|
380 |
return labels; |
|
381 |
} |
|
389 |
public void setFields(String[] fields) { |
|
390 |
this.fields = fields; |
|
391 |
updateSymbols(); |
|
392 |
} |
|
382 | 393 |
|
383 |
public void setFields(String[] fields) {
|
|
384 |
this.fields = fields;
|
|
385 |
updateSymbols();
|
|
386 |
}
|
|
394 |
public void setLabels(String[] fields) {
|
|
395 |
this.labels = fields;
|
|
396 |
updateSymbols();
|
|
397 |
}
|
|
387 | 398 |
|
388 |
public void setLabels(String[] fields) { |
|
389 |
this.labels = fields; |
|
390 |
updateSymbols(); |
|
391 |
} |
|
399 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
400 |
public void loadFromState(PersistentState state) |
|
401 |
throws PersistenceException { |
|
402 |
// Set parent properties |
|
403 |
super.loadFromState(state); |
|
392 | 404 |
|
393 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
394 |
public void loadFromState(PersistentState state) |
|
395 |
throws PersistenceException { |
|
396 |
// Set parent properties |
|
397 |
super.loadFromState(state); |
|
405 |
this.fields = state.getStringArray(FIELD_NAMES); |
|
406 |
this.labels = state.getStringArray(FIELD_LABEL_NAMES); |
|
407 |
this.colors = (Color[]) state.getArray(FIELD_LABEL_COLOR, Color.class); |
|
408 |
// Set own properties |
|
409 |
this.backgroundSymbol = (ISymbol) state.get("backgroundSymbol"); |
|
410 |
this.size = state.getInt("size"); |
|
411 |
this.is3D = state.getBoolean("is3D"); |
|
398 | 412 |
|
399 |
this.fields = state.getStringArray(FIELD_NAMES); |
|
400 |
this.labels = state.getStringArray(FIELD_LABEL_NAMES); |
|
401 |
this.colors = (Color[]) state.getArray(FIELD_LABEL_COLOR,Color.class); |
|
402 |
// Set own properties |
|
403 |
this.backgroundSymbol = (ISymbol) state.get("backgroundSymbol"); |
|
404 |
this.size = state.getInt("size"); |
|
405 |
this.is3D = state.getBoolean("is3D"); |
|
413 |
this.isOutlineShow = state.getBoolean("isOutlineShow"); |
|
414 |
this.onlySelection = state.getBoolean("onlySelection"); |
|
415 |
this.isActiveLimits = state.getBoolean("isActiveLimits"); |
|
406 | 416 |
|
407 |
this.isOutlineShow = state.getBoolean("isOutlineShow"); |
|
408 |
this.onlySelection = state.getBoolean("onlySelection"); |
|
409 |
this.isActiveLimits = state.getBoolean("isActiveLimits"); |
|
417 |
this.outlineWidth = state.getInt("outlineWidth"); |
|
418 |
this.referenceSystem = state.getInt("referenceSystem"); |
|
419 |
this.sizeFrom = state.getInt("sizeFrom"); |
|
420 |
this.sizeTo = state.getInt("sizeTo"); |
|
421 |
this.unit = state.getInt("unit"); |
|
422 |
this.sizeOption = state.getInt("sizeOption"); |
|
410 | 423 |
|
411 |
this.outlineWidth = state.getInt("outlineWidth"); |
|
412 |
this.referenceSystem = state.getInt("referenceSystem"); |
|
413 |
this.sizeFrom = state.getInt("sizeFrom"); |
|
414 |
this.sizeTo = state.getInt("sizeTo"); |
|
415 |
this.unit = state.getInt("unit"); |
|
416 |
this.sizeOption = state.getInt("sizeOption"); |
|
424 |
this.outlineColor = (Color) state.get("outlineColor"); |
|
425 |
this.symbol = (IChartSymbol) state.get("symbol"); |
|
426 |
this.featSelection = (FeatureSelection) state.get("featSelection"); |
|
417 | 427 |
|
418 |
this.outlineColor = (Color) state.get("outlineColor"); |
|
419 |
this.symbol = (IChartSymbol) state.get("symbol"); |
|
420 |
this.featSelection = (FeatureSelection) state.get("featSelection"); |
|
428 |
this.fieldSize = state.getString("fieldSize"); |
|
429 |
this.fieldNormalize = state.getString("fieldNormalize"); |
|
421 | 430 |
|
422 |
this.fieldSize = state.getString("fieldSize"); |
|
423 |
this.fieldNormalize = state.getString("fieldNormalize"); |
|
431 |
this.minFeature = state.getDouble("minFeature"); |
|
432 |
this.maxFeature = state.getDouble("maxFeature"); |
|
433 |
this.maxField = state.getDouble("maxField"); |
|
434 |
} |
|
424 | 435 |
|
425 |
this.minFeature = state.getDouble("minFeature"); |
|
426 |
this.maxFeature = state.getDouble("maxFeature"); |
|
427 |
this.maxField = state.getDouble("maxField"); |
|
428 |
} |
|
436 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
437 |
// Save parent properties |
|
438 |
super.saveToState(state); |
|
439 |
// Save own properties |
|
440 |
state.set(FIELD_NAMES, this.fields); |
|
441 |
state.set(FIELD_LABEL_NAMES, this.labels); |
|
442 |
state.set(FIELD_LABEL_COLOR, this.colors); |
|
429 | 443 |
|
430 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
431 |
// Save parent properties |
|
432 |
super.saveToState(state); |
|
433 |
// Save own properties |
|
434 |
state.set(FIELD_NAMES, this.fields); |
|
435 |
state.set(FIELD_LABEL_NAMES, this.labels); |
|
436 |
state.set(FIELD_LABEL_COLOR, this.colors); |
|
444 |
state.set("backgroundSymbol", this.backgroundSymbol); |
|
445 |
state.set("size", this.size); |
|
446 |
state.set("is3D", this.is3D); |
|
437 | 447 |
|
438 |
state.set("backgroundSymbol", this.backgroundSymbol);
|
|
439 |
state.set("size", this.size);
|
|
440 |
state.set("is3D", this.is3D);
|
|
448 |
state.set("isOutlineShow", this.isOutlineShow);
|
|
449 |
state.set("onlySelection", this.onlySelection);
|
|
450 |
state.set("isActiveLimits", this.isActiveLimits);
|
|
441 | 451 |
|
442 |
state.set("isOutlineShow", this.isOutlineShow); |
|
443 |
state.set("onlySelection", this.onlySelection); |
|
444 |
state.set("isActiveLimits", this.isActiveLimits); |
|
452 |
state.set("outlineWidth", this.outlineWidth); |
|
453 |
state.set("referenceSystem", this.referenceSystem); |
|
454 |
state.set("sizeFrom", this.sizeFrom); |
|
455 |
state.set("sizeTo", this.sizeTo); |
|
456 |
state.set("unit", this.unit); |
|
457 |
state.set("sizeOption", this.sizeOption); |
|
445 | 458 |
|
446 |
state.set("outlineWidth", this.outlineWidth); |
|
447 |
state.set("referenceSystem", this.referenceSystem); |
|
448 |
state.set("sizeFrom", this.sizeFrom); |
|
449 |
state.set("sizeTo", this.sizeTo); |
|
450 |
state.set("unit", this.unit); |
|
451 |
state.set("sizeOption", this.sizeOption); |
|
459 |
state.set("outlineColor", this.outlineColor); |
|
460 |
state.set("symbol", this.symbol); |
|
461 |
state.set("featSelection", this.featSelection); |
|
452 | 462 |
|
453 |
state.set("outlineColor", this.outlineColor); |
|
454 |
state.set("symbol", this.symbol); |
|
455 |
state.set("featSelection", this.featSelection); |
|
463 |
state.set("fieldSize", this.fieldSize); |
|
464 |
state.set("fieldNormalize", this.fieldNormalize); |
|
456 | 465 |
|
457 |
state.set("fieldSize", this.fieldSize); |
|
458 |
state.set("fieldNormalize", this.fieldNormalize); |
|
466 |
state.set("minFeature", this.minFeature); |
|
467 |
state.set("maxFeature", this.maxFeature); |
|
468 |
state.set("maxField", this.maxField); |
|
459 | 469 |
|
460 |
state.set("minFeature", this.minFeature); |
|
461 |
state.set("maxFeature", this.maxFeature); |
|
462 |
state.set("maxField", this.maxField); |
|
470 |
} |
|
463 | 471 |
|
464 |
} |
|
465 |
|
|
466 |
public static class RegisterPersistence implements Callable { |
|
467 |
|
|
468 |
public Object call() throws Exception { |
|
469 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
470 |
if( manager.getDefinition(PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
|
471 |
DynStruct definition = manager.addDefinition( |
|
472 |
BasePieChartLegend.class, |
|
473 |
PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
474 |
PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition", |
|
475 |
null, |
|
476 |
null |
|
477 |
); |
|
478 |
// Extend the Classified Vector Legend base definition |
|
479 |
definition.extend(manager.getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
|
480 |
|
|
481 |
// Field names |
|
482 |
definition.addDynFieldArray(FIELD_NAMES) |
|
483 |
.setClassOfItems(String.class); |
|
484 |
definition.addDynFieldArray(FIELD_LABEL_NAMES) |
|
485 |
.setClassOfItems(String.class); |
|
486 |
definition.addDynFieldArray(FIELD_LABEL_COLOR) |
|
487 |
.setClassOfItems(Color.class); |
|
488 |
|
|
489 |
definition.addDynField("backgroundSymbol").setClassOfValue(ISymbol.class); |
|
490 |
definition.addDynFieldInt("size"); |
|
491 |
definition.addDynFieldBoolean("is3D"); |
|
492 |
|
|
493 |
definition.addDynFieldBoolean("isOutlineShow"); |
|
494 |
definition.addDynFieldBoolean("onlySelection"); |
|
495 |
definition.addDynFieldBoolean("isActiveLimits"); |
|
496 |
|
|
497 |
definition.addDynFieldInt("outlineWidth"); |
|
498 |
definition.addDynFieldInt("referenceSystem"); |
|
499 |
definition.addDynFieldInt("sizeFrom"); |
|
500 |
definition.addDynFieldInt("sizeTo"); |
|
501 |
definition.addDynFieldInt("unit"); |
|
502 |
definition.addDynFieldInt("sizeOption"); |
|
503 |
|
|
504 |
definition.addDynFieldObject("outlineColor").setClassOfValue(Color.class); |
|
505 |
definition.addDynFieldObject("symbol").setClassOfValue(IChartSymbol.class); |
|
506 |
definition.addDynFieldObject("featSelection").setClassOfValue(FeatureSelection.class); |
|
507 |
|
|
508 |
definition.addDynFieldString("fieldSize"); |
|
509 |
definition.addDynFieldString("fieldNormalize"); |
|
510 |
|
|
511 |
definition.addDynFieldDouble("minFeature"); |
|
512 |
definition.addDynFieldDouble("maxFeature"); |
|
513 |
definition.addDynFieldDouble("maxField"); |
|
514 |
} |
|
515 |
return Boolean.TRUE; |
|
516 |
} |
|
517 |
|
|
518 |
} |
|
519 |
|
|
472 |
// public static class RegisterPersistence implements Callable { |
|
473 |
// |
|
474 |
// public Object call() throws Exception { |
|
475 |
// PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
476 |
// if( manager.getDefinition(BASE_PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
|
477 |
// DynStruct definition = manager.addDefinition( |
|
478 |
// BasePieChartLegend.class, |
|
479 |
// BASE_PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
480 |
// BASE_PIE_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition", |
|
481 |
// null, |
|
482 |
// null |
|
483 |
// ); |
|
484 |
// // Extend the Classified Vector Legend base definition |
|
485 |
// definition.extend(manager.getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
|
486 |
// |
|
487 |
// // Field names |
|
488 |
// definition.addDynFieldArray(FIELD_NAMES) |
|
489 |
// .setClassOfItems(String.class); |
|
490 |
// definition.addDynFieldArray(FIELD_LABEL_NAMES) |
|
491 |
// .setClassOfItems(String.class); |
|
492 |
// definition.addDynFieldArray(FIELD_LABEL_COLOR) |
|
493 |
// .setClassOfItems(Color.class); |
|
494 |
// |
|
495 |
// definition.addDynField("backgroundSymbol").setClassOfValue(ISymbol.class); |
|
496 |
// definition.addDynFieldInt("size"); |
|
497 |
// definition.addDynFieldBoolean("is3D"); |
|
498 |
// |
|
499 |
// definition.addDynFieldBoolean("isOutlineShow"); |
|
500 |
// definition.addDynFieldBoolean("onlySelection"); |
|
501 |
// definition.addDynFieldBoolean("isActiveLimits"); |
|
502 |
// |
|
503 |
// definition.addDynFieldInt("outlineWidth"); |
|
504 |
// definition.addDynFieldInt("referenceSystem"); |
|
505 |
// definition.addDynFieldInt("sizeFrom"); |
|
506 |
// definition.addDynFieldInt("sizeTo"); |
|
507 |
// definition.addDynFieldInt("unit"); |
|
508 |
// definition.addDynFieldInt("sizeOption"); |
|
509 |
// |
|
510 |
// definition.addDynFieldObject("outlineColor").setClassOfValue(Color.class); |
|
511 |
// definition.addDynFieldObject("symbol").setClassOfValue(IChartSymbol.class); |
|
512 |
// definition.addDynFieldObject("featSelection").setClassOfValue(FeatureSelection.class); |
|
513 |
// |
|
514 |
// definition.addDynFieldString("fieldSize"); |
|
515 |
// definition.addDynFieldString("fieldNormalize"); |
|
516 |
// |
|
517 |
// definition.addDynFieldDouble("minFeature"); |
|
518 |
// definition.addDynFieldDouble("maxFeature"); |
|
519 |
// definition.addDynFieldDouble("maxField"); |
|
520 |
// } |
|
521 |
// return Boolean.TRUE; |
|
522 |
// } |
|
523 |
// |
|
524 |
// } |
|
520 | 525 |
protected void updateSymbols() { |
521 | 526 |
ISymbol[] symbols = getSymbols(); |
522 |
for (int i = 0; i < symbols.length; i++) {
|
|
523 |
delSymbol(getSymbolKey(symbols[i]));
|
|
527 |
for (ISymbol symbol1 : symbols) {
|
|
528 |
delSymbol(getSymbolKey(symbol1));
|
|
524 | 529 |
} |
525 | 530 |
if (fields != null && colors != null && labels != null) { |
526 | 531 |
|
527 | 532 |
if (fields.length != colors.length) { |
528 | 533 |
LOG.warn("The length of fields and colors isn't the same: fields.length = " + fields.length |
529 |
+ " fields.length = " + colors.length); |
|
534 |
+ " fields.length = " + colors.length);
|
|
530 | 535 |
} |
531 | 536 |
|
532 | 537 |
if (fields.length != labels.length) { |
533 | 538 |
LOG.warn("The length of fields and labels isn't the same: fields.length = " + fields.length |
534 |
+ " labels.length = " + labels.length); |
|
539 |
+ " labels.length = " + labels.length);
|
|
535 | 540 |
} |
536 | 541 |
|
537 | 542 |
for (int i = 0; i < Math.min(fields.length, Math.min(labels.length, colors.length)); i++) { |
538 |
ISimpleFillSymbol symbol = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol(); |
|
539 |
symbol.setColor(colors[i]); |
|
540 |
symbol.setDescription(labels[i]); |
|
541 |
addSymbol(fields[i], symbol); |
|
543 |
ISimpleFillSymbol symbol1 = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
|
|
544 |
symbol1.setColor(colors[i]);
|
|
545 |
symbol1.setDescription(labels[i]);
|
|
546 |
addSymbol(fields[i], symbol1);
|
|
542 | 547 |
} |
543 | 548 |
} |
544 | 549 |
} |
Also available in: Unified diff