Revision 453

View differences:

org.gvsig.legend.quantitybycategory.app.mainplugin/tags/org.gvsig.legend.quantitybycategory.app.mainplugin-1.0.13/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
<!-- No dependencies
51
  <dependencySets>
52
    <dependencySet>
53
      <useProjectArtifact>false</useProjectArtifact>
54
      <useTransitiveDependencies>false</useTransitiveDependencies>
55
      <outputDirectory>lib</outputDirectory>
56
      <includes>
57
		<include>...</include>
58
      </includes>
59
    </dependencySet>
60
  </dependencySets>
61
-->
62

  
63
</assembly>
64

  
org.gvsig.legend.quantitybycategory.app.mainplugin/tags/org.gvsig.legend.quantitybycategory.app.mainplugin-1.0.13/src/main/java/org/gvsig/symbology/fmap/rendering/QuantityByCategoryLegend.java
1
package org.gvsig.symbology.fmap.rendering;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

  
9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.geom.Geometry;
11
import org.gvsig.fmap.mapcontext.MapContextException;
12
import org.gvsig.fmap.mapcontext.MapContextLocator;
13
import org.gvsig.fmap.mapcontext.MapContextManager;
14
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
15
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
16
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
17
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
18
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
19
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
20
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialIntervalLegend;
21
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
22
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
23
import org.gvsig.tools.ToolsLocator;
24
import org.gvsig.tools.dynobject.DynStruct;
25
import org.gvsig.tools.persistence.PersistenceManager;
26
import org.gvsig.tools.persistence.PersistentState;
27
import org.gvsig.tools.persistence.exception.PersistenceException;
28
import org.gvsig.tools.util.Callable;
29

  
30
/**
31
 * Implements a legend where the user can compare two different characteristics
32
 * of a region in the map. These two "fields" will be compared, on one side,
33
 * using a color for the region and , on the other side, using a graduated symbol.
34
 * Both methods will change (the color or the size of the symbol) depending on
35
 * the value of the fields.
36
 *
37
 * @author jaume dominguez faus - jaume.dominguez@iver.es
38
 */
39
public class QuantityByCategoryLegend extends AbstractClassifiedVectorLegend {
40

  
41
    private static final Logger logger =
42
        LoggerFactory.getLogger(QuantityByCategoryLegend.class);
43

  
44
    public static final String
45
    QUANTITY_BY_CATEGORY_LEGEND_PERSISTENCE_DEFINITION_NAME =
46
    "QUANTITY_BY_CATEGORY_LEGEND_PERSISTENCE_DEFINITION_NAME";
47

  
48
    public static final String
49
    QUANTITY_BY_CATEGORY_LEGEND_NAME = "QUANTITY_BY_CATEGORY_LEGEND_NAME";
50

  
51
	private GraduatedSymbolsLegend graduatedSymbol;
52
	private VectorialIntervalLegend colorRamp;
53

  
54
	private ISymbol defaultSymbol = null;
55
	private int shapeType = Geometry.TYPES.SURFACE;
56

  
57
	private boolean isUseDefaultSymbol;
58
	// private DataSource ds;
59

  
60
	public QuantityByCategoryLegend() {
61
		graduatedSymbol = new GraduatedSymbolsLegend();
62
		colorRamp = new VectorialIntervalLegend(getShapeType());
63
		this.setShapeType(Geometry.TYPES.SURFACE);
64

  
65
		ISymbol def = MapContextLocator.getSymbolManager().
66
            createSymbol(getShapeType());
67
		this.setDefaultSymbol(def);
68
	}
69

  
70

  
71
	public void clear() {
72
		colorRamp.clear();
73
		graduatedSymbol.clear();
74
	}
75

  
76
	public String[] getClassifyingFieldNames() {
77
		ArrayList<String> l = new ArrayList<String>();
78
		for (int i = 0; i < graduatedSymbol.getClassifyingFieldNames().length; i++) {
79
			l.add(graduatedSymbol.getClassifyingFieldNames()[i]);
80
		}
81

  
82
		for (int i = 0; i < colorRamp.getClassifyingFieldNames().length; i++) {
83
			l.add(colorRamp.getClassifyingFieldNames()[i]);
84
		}
85
		return l.toArray(new String[l.size()]);
86
	}
87

  
88

  
89
	@Override
90
	public int[] getClassifyingFieldTypes() {
91
        ArrayList<Integer> l = new ArrayList<Integer>();
92
        for (int i = 0; i < graduatedSymbol.getClassifyingFieldTypes().length; i++) {
93
            l.add(graduatedSymbol.getClassifyingFieldTypes()[i]);
94
        }
95

  
96
        for (int i = 0; i < colorRamp.getClassifyingFieldTypes().length; i++) {
97
            l.add(colorRamp.getClassifyingFieldTypes()[i]);
98
        }
99

  
100
        int len = l.size();
101
        int[] resp = new int[len];
102
        for (int i=0; i<len; i++) {
103
            resp[i] = l.get(i).intValue();
104
        }
105
        return resp;
106
	}
107

  
108
	public void setClassifyingFieldTypes(int[] fieldTypes) {
109
		if (fieldTypes.length == 2) {
110
	        colorRamp.setClassifyingFieldTypes(new int[] {fieldTypes[1]});
111
	        graduatedSymbol.setClassifyingFieldTypes(new int[] {fieldTypes[0]});
112
		} else {
113
		    logger.info("Error: Unexpected array size (should be 2)");
114
		}
115
		super.setClassifyingFieldTypes(fieldTypes);
116
	}
117

  
118

  
119
	/**
120
	 * Sets the field names required to build this legend. In this case
121
	 * fieldNames is an array of length 2 where the first element is
122
	 * the field name for the embedded GraduatedSymbolLegend, and the
123
	 * second is the field name for the embedded colorRamp (VectorialIntervalLegend)
124
	 * legend.
125
	 */
126
	public void setClassifyingFieldNames(String[] fieldNames) {
127

  
128
		if (fieldNames.length == 2) {
129
	        colorRamp.setClassifyingFieldNames(new String[] {fieldNames[1]});
130
	        graduatedSymbol.setClassifyingFieldNames(new String[] {fieldNames[0]});
131
		} else {
132
            logger.info("Error: Unexpected array size (should be 2)");
133
		}
134
		super.setClassifyingFieldNames(fieldNames);
135
	}
136

  
137
	public void addSymbol(Object key, ISymbol symbol) {
138
//		System.out.println("adding "+key+"["+symbol+"]");
139

  
140
		if(symbol instanceof IFillSymbol)
141
			colorRamp.addSymbol(key, symbol);
142
		else if(symbol instanceof IMarkerSymbol)
143
			graduatedSymbol.addSymbol(key, symbol);
144

  
145
		fireClassifiedSymbolChangeEvent(
146
		    new SymbolLegendEvent(null, symbol));
147
	}
148

  
149
	public void delSymbol(Object key) {
150
		colorRamp.delSymbol(key);
151
		graduatedSymbol.delSymbol(key);
152
		fireClassifiedSymbolChangeEvent(
153
				new SymbolLegendEvent(
154
						null,
155
						null));
156
	}
157

  
158
	public String[] getDescriptions() {
159
		String[] desc1 = colorRamp.getDescriptions();
160
		String[] desc2 = graduatedSymbol.getDescriptions();
161
        Object[] objects1 = colorRamp.getValues();
162
        Object[] objects2 = graduatedSymbol.getValues();
163

  
164
        List descriptionsList = new ArrayList<String>();
165
        for (int i = 0; i < objects1.length; i++) {
166
            //Pretend?a saltar el valor por defecto pero no es necesario si en getValues se pone como clave null
167
//            if(objects1[i] instanceof IInterval){
168
                descriptionsList.add(desc1[i]);
169
//            }
170
        }
171
        for (int i = 0; i < objects2.length; i++) {
172
            //Pretend?a saltar el valor por defecto pero no es necesario si en getValues se pone como clave null
173
//            if(objects2[i] instanceof IInterval){
174
                descriptionsList.add(desc2[i]);
175
//            }
176
        }
177

  
178
        String[] descriptions = new String[descriptionsList.size()];
179
        descriptions = (String[]) descriptionsList.toArray(descriptions);
180
        return descriptions;
181

  
182
	}
183

  
184
	public ISymbol[] getSymbols() {
185
		ISymbol[] symbols1 = colorRamp.getSymbols();
186
		ISymbol[] symbols2 = graduatedSymbol.getSymbols();
187
	    Object[] objects1 = colorRamp.getValues();
188
	    Object[] objects2 = graduatedSymbol.getValues();
189

  
190

  
191
        List symbolsList = new ArrayList<ISymbol>();
192
        for (int i = 0; i < objects1.length; i++) {
193
            //Pretend?a saltar el valor por defecto pero no es necesario si en getValues se pone como clave null
194
//            if(objects1[i] instanceof IInterval){
195
                symbolsList.add(symbols1[i]);
196
//            }
197
        }
198
        for (int i = 0; i < objects2.length; i++) {
199
            //Pretend?a saltar el valor por defecto pero no es necesario si en getValues se pone como clave null
200
//            if(objects2[i] instanceof IInterval){
201
                symbolsList.add(symbols2[i]);
202
//            }
203
        }
204

  
205
        ISymbol[] symbols = new ISymbol[symbolsList.size()];
206
        symbols = (ISymbol[]) symbolsList.toArray(symbols);
207
        return symbols;
208
	}
209

  
210
	public Object[] getValues() {
211
		Object[] objects1 = colorRamp.getValues();
212
		Object[] objects2 = graduatedSymbol.getValues();
213

  
214
		List objectsList = new ArrayList<IInterval>();
215
		for (int i = 0; i < objects1.length; i++) {
216
            if(objects1[i] instanceof IInterval){
217
                objectsList.add(objects1[i]);
218
            } else {
219
                objectsList.add(null); //Si no es un IInterval es el valor por defecto
220
            }
221
        }
222
        for (int i = 0; i < objects2.length; i++) {
223
            if(objects2[i] instanceof IInterval){
224
                objectsList.add(objects2[i]);
225
            } else {
226
                objectsList.add(null); //Si no es un IInterval es el valor por defecto
227
            }
228
        }
229
        Object[] objects = new IInterval[objectsList.size()];
230
        objects = objectsList.toArray(objects);
231
		return objects;
232

  
233
	}
234

  
235

  
236
	public Object clone() throws CloneNotSupportedException {
237

  
238
	    QuantityByCategoryLegend resp =
239
	        (QuantityByCategoryLegend) super.clone();
240

  
241
        resp.setShapeType(this.getShapeType());
242

  
243
	    resp.useDefaultSymbol(this.isUseDefaultSymbol());
244
	    ISymbol defsym = this.getDefaultSymbol();
245
	    defsym = (ISymbol) defsym.clone();
246
	    resp.setDefaultSymbol(defsym);
247

  
248
	    GraduatedSymbolsLegend gleg = this.getGraduatedSymbolsLegend();
249
	    gleg = (GraduatedSymbolsLegend) gleg.cloneLegend();
250
	    resp.setGraduateSymbolLegend(gleg);
251

  
252
	    VectorialIntervalLegend interleg = this.getColorRampLegend();
253
	    interleg = (VectorialIntervalLegend) interleg.cloneLegend();
254
	    resp.setColorRampLegend(interleg);
255
		return resp;
256
	}
257
	/**
258
	 * Obtains the GraduatedSymbolLegend
259
	 *
260
	 * @return GraduatedSymbolLegend
261
	 */
262
	public GraduatedSymbolsLegend getGraduatedSymbolsLegend() {
263
		return graduatedSymbol;
264
	}
265
	/**
266
	 * Obtains the VectorialIntervalLegend
267
	 *
268
	 * @return VectorialIntervalLegend
269
	 */
270
	public VectorialIntervalLegend getColorRampLegend() {
271
		return colorRamp;
272
	}
273

  
274
	/*
275
	public void setDataSource(DataSource ds) throws FieldNotFoundException, ReadDriverException {
276
		// TODO remove it when FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD is removed
277
//		if (FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) {
278
			this.ds = ds;
279
//		}
280
		graduatedSymbol.setDataSource(ds);
281
		colorRamp.setDataSource(ds);
282
	}
283
	*/
284

  
285
	/*
286
	public ISymbol getSymbol(int i) {
287

  
288
		IMarkerSymbol sym1 = (IMarkerSymbol) graduatedSymbol.getSymbol(i);
289
		ISymbol sym2 =  colorRamp.getSymbol(i);
290

  
291
		IMultiLayerSymbol multiSym = null;
292
		int shpt = this.getShapeType();
293

  
294
		if (isPolygonal(shpt)) {
295
            // symbol from the GraduatedSymbolLegend is a marker, but
296
            // what we need is a fill symbol. Will use a MarkerFillSymbol
297
            // to enable support for Polygons
298
            MarkerFillSymbol aux = new MarkerFillSymbol();
299
            // tell the fill style to draw the IMarkerSymbol
300
            // as a IFillSymbol centering it in the shape polygon
301
            // centroid and applying offset (if any).
302
            aux.setMarker(sym1);
303
            SimpleMarkerFillPropertiesStyle p =
304
                new SimpleMarkerFillPropertiesStyle();
305
            p.setFillStyle(SimpleMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
306
            aux.setMarkerFillProperties(p);
307

  
308
            multiSym = MapContextLocator.getSymbolManager().
309
                createMultiLayerSymbol(Geometry.TYPES.SURFACE);
310

  
311
            multiSym.addLayer(sym2);
312
            multiSym.addLayer(aux);
313
            break;
314

  
315
		} else {
316
		    logger.info("Error: unexpected shape type (should be surface): " + shpt);
317
		}
318

  
319
		return multiSym;
320
	}
321
	*/
322

  
323
	public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
324

  
325
		ISymbol sym1 = null, sym2 = null;
326
		sym1 = graduatedSymbol.getSymbolByFeature(feat);
327
		// Ensure fill symbol
328
		sym1 = GraduatedSymbolsLegend.toFillSymbol(sym1);
329

  
330
		sym2 = colorRamp.getSymbolByFeature(feat);
331

  
332
		IMultiLayerSymbol multiSym = null;
333
		int shpt = this.getShapeType();
334

  
335
		if (isPolygonal(shpt)) {
336

  
337
            multiSym = MapContextLocator.getSymbolManager().
338
                createMultiLayerSymbol(Geometry.TYPES.SURFACE);
339

  
340
            if (sym2 != null) multiSym.addLayer(sym2);
341
            if (sym1 != null) multiSym.addLayer(sym1);
342
		} else {
343
		    logger.info("Error: unexpected shape type (should be surface): " + shpt);
344
		}
345

  
346
		return multiSym;
347
	}
348

  
349
	public void setShapeType(int shpt) {
350

  
351
	    this.shapeType = shpt;
352
	    ISymbol sym = null;
353

  
354
		graduatedSymbol.setShapeType(Geometry.TYPES.POINT);
355
		sym = MapContextLocator.getSymbolManager().createSymbol(
356
		    Geometry.TYPES.POINT);
357
		graduatedSymbol.setDefaultSymbol(sym);
358

  
359
		colorRamp.setShapeType(shpt);
360
		sym = MapContextLocator.getSymbolManager().createSymbol(shpt);
361
		colorRamp.setDefaultSymbol(sym);
362
	}
363

  
364

  
365

  
366
	public boolean isUseDefaultSymbol() {
367
		return isUseDefaultSymbol;
368
	}
369

  
370
	public void useDefaultSymbol(boolean b) {
371
		this.isUseDefaultSymbol = b;
372
	}
373

  
374
	public void setGraduateSymbolLegend(GraduatedSymbolsLegend legend) {
375
		this.graduatedSymbol = legend;
376
	}
377

  
378
	public void setColorRampLegend(VectorialIntervalLegend legend) {
379
		this.colorRamp = legend;
380
	}
381

  
382
	public String getClassName() {
383
		return getClass().getName();
384
	}
385

  
386
	public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
387
		ISymbol[] symbols;
388
		// look first in the graduated symbol legend
389
		symbols = graduatedSymbol.getSymbols();
390

  
391
		for (int i = 0; i < symbols.length; i++) {
392
			if (symbols[i].equals(oldSymbol)) {
393
				graduatedSymbol.replace(oldSymbol, newSymbol);
394
				return;
395
			}
396
		}
397

  
398
		// if the symbol wasn't found yet, proceed with color ramp
399
		symbols = colorRamp.getSymbols();
400

  
401
		for (int i = 0; i < symbols.length; i++) {
402
			if (symbols[i].equals(oldSymbol)) {
403
				colorRamp.replace(oldSymbol, newSymbol);
404
				return;
405
			}
406
		}
407

  
408
	}
409

  
410
    public static boolean isPolygonal(int ty) {
411
        if (ty == Geometry.TYPES.MULTISURFACE
412
            || ty == Geometry.TYPES.SURFACE
413
            ) {
414
            return true;
415
        } else {
416
            return false;
417
        }
418
    }
419

  
420

  
421
    public ISymbol getDefaultSymbol() {
422
        return this.defaultSymbol;
423
    }
424

  
425

  
426
    public int getShapeType() {
427
        return this.shapeType;
428
    }
429

  
430

  
431
    public void setDefaultSymbol(ISymbol s) {
432
        this.defaultSymbol = s;
433
    }
434

  
435

  
436
    // =============================
437

  
438
    public static class RegisterPersistence implements Callable {
439

  
440
        public Object call() throws Exception {
441

  
442
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
443
            if (manager.getDefinition(
444
                QUANTITY_BY_CATEGORY_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
445
                DynStruct definition = manager
446
                    .addDefinition(QuantityByCategoryLegend.class,
447
                        QUANTITY_BY_CATEGORY_LEGEND_PERSISTENCE_DEFINITION_NAME,
448
                        QUANTITY_BY_CATEGORY_LEGEND_PERSISTENCE_DEFINITION_NAME
449
                        + " Persistence definition", null, null);
450

  
451
                definition.extend(manager.getDefinition(
452
                    AbstractClassifiedVectorLegend
453
                    .CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME));
454

  
455
                definition.addDynFieldBoolean("useDefaultSymbol")
456
                .setMandatory(true);
457

  
458
                definition.addDynFieldObject("graduatedLegend")
459
                .setClassOfValue(ILegend.class).setMandatory(true);
460
                definition.addDynFieldObject("rampLegend")
461
                .setClassOfValue(ILegend.class).setMandatory(true);
462
            }
463
            return Boolean.TRUE;
464
        }
465

  
466
    }
467

  
468
    public static class RegisterLegend implements Callable {
469

  
470
        public Object call() throws Exception {
471
            MapContextManager manager =
472
                MapContextLocator.getMapContextManager();
473

  
474
            manager.registerLegend(
475
                QUANTITY_BY_CATEGORY_LEGEND_NAME,
476
                QuantityByCategoryLegend.class);
477

  
478
            return Boolean.TRUE;
479
        }
480

  
481
    }
482

  
483
    public void saveToState(PersistentState state) throws PersistenceException {
484

  
485
        super.saveToState(state);
486
        state.set("useDefaultSymbol", this.isUseDefaultSymbol());
487
        state.set("graduatedLegend", this.getGraduatedSymbolsLegend());
488
        state.set("rampLegend", this.getColorRampLegend());
489
    }
490

  
491
    public void loadFromState(PersistentState state)
492
        throws PersistenceException {
493

  
494
        super.loadFromState(state);
495

  
496
        Boolean b = state.getBoolean("useDefaultSymbol");
497
        this.useDefaultSymbol(b);
498

  
499
        ILegend leg = (ILegend) state.get("graduatedLegend");
500
        if (leg instanceof GraduatedSymbolsLegend) {
501
            this.setGraduateSymbolLegend((GraduatedSymbolsLegend) leg);
502
        } else {
503
            throw new PersistenceException(new ClassCastException(
504
                "Unexpected legend type (" + leg + "). Should be GraduatedSymbolsLegend"));
505
        }
506

  
507
        leg = (ILegend) state.get("rampLegend");
508
        if (leg instanceof VectorialIntervalLegend) {
509
            this.setColorRampLegend((VectorialIntervalLegend) leg);
510
        } else {
511
            throw new PersistenceException(new ClassCastException(
512
                "Unexpected legend type (" + leg + "). Should be VectorialIntervalLegend"));
513
        }
514
    }
515

  
516

  
517

  
518
}
org.gvsig.legend.quantitybycategory.app.mainplugin/tags/org.gvsig.legend.quantitybycategory.app.mainplugin-1.0.13/src/main/java/org/gvsig/symbology/gui/layerproperties/QuantityByCategoryPanel.java
1
package org.gvsig.symbology.gui.layerproperties;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.GridLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7
import java.util.ArrayList;
8
import java.util.List;
9

  
10
import javax.swing.BorderFactory;
11
import javax.swing.DefaultComboBoxModel;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JComboBox;
15
import javax.swing.JComponent;
16
import javax.swing.JOptionPane;
17
import javax.swing.JPanel;
18

  
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

  
22
import org.gvsig.andami.IconThemeHelper;
23
import org.gvsig.andami.ui.mdiManager.IWindow;
24
import org.gvsig.andami.ui.mdiManager.WindowInfo;
25
import org.gvsig.app.ApplicationLocator;
26
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
27
import org.gvsig.app.project.documents.view.legend.gui.MultipleAttributes;
28
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
29
import org.gvsig.app.project.documents.view.legend.gui.VectorialInterval;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
32
import org.gvsig.fmap.dal.feature.FeatureStore;
33
import org.gvsig.fmap.dal.feature.FeatureType;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.mapcontext.MapContextLocator;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
39
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
40
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
41
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.gui.beans.AcceptCancelPanel;
44
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
45
import org.gvsig.i18n.Messages;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialIntervalLegend;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
48
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
49
import org.gvsig.symbology.fmap.rendering.GraduatedSymbolsLegend;
50
import org.gvsig.symbology.fmap.rendering.QuantityByCategoryLegend;
51

  
52

  
53
/**
54
 * Implements the panel of a legend where the user can compare two different characteristics
55
 * of a region in the map. These two "fields" will be compared, on one side,
56
 * using a color for the region and , on the other side, using a graduated symbol.
57
 * Both methods will change (the color or the size of the symbol) depending on
58
 * the value of the fields.
59
 *
60
 * @author jaume dominguez faus - jaume.dominguez@iver.es
61
 */
62
public class QuantityByCategoryPanel extends JPanel
63
implements ILegendPanel, ActionListener {
64

  
65
	private static final long serialVersionUID = 5098346573350040756L;
66
	private static final Logger logger =
67
	    LoggerFactory.getLogger(QuantityByCategoryPanel.class);
68

  
69
	private JPanel pnlNorth;
70
	private JPanel pnlSouth;
71
	private JPanel pnlButtons;
72
	private GridBagLayoutPanel pnlFields;
73
	private JPanel pnlColorAndSymbol;
74
	private JComboBox cmbColorField;
75
	private JComboBox cmbGraduatedSymbolField;
76
	private JButton btnColor;
77
	private JButton btnSymbol;
78
//	private JButton btnDelete;
79
//	private JButton btnDeleteAll;
80
	private QuantityByCategoryLegend legend;
81
	private QuantityByCategoryLegend oldLegend;
82
	private FLayer layer;
83
	private SymbolTable symbolTable;
84
	/**
85
	 * Constructor method
86
	 */
87
	public QuantityByCategoryPanel() {
88
		super();
89
		initialize();
90
	}
91
	/**
92
	 * This method initializes this
93
	 */
94
	private void initialize() {
95
		this.setLayout(new BorderLayout());
96
		this.setSize(490, 300);
97
		this.add(getPnlNorth(), BorderLayout.NORTH);
98
		this.add(getPnlSouth(),BorderLayout.CENTER);
99
//		this.add(getPnlButtons(),BorderLayout.SOUTH);
100
	}
101
	/**
102
	 * Obtains the south panel
103
	 *
104
	 * @return JPanel
105
	 */
106
	private JPanel getPnlSouth() {
107
		if (pnlSouth == null) {
108
			pnlSouth = new JPanel();
109
			pnlSouth.setLayout(new BorderLayout());
110
		}
111
		return pnlSouth;
112
	}
113
	/**
114
	 * Obtains the panel where the buttons will be placed
115
	 *
116
	 * @return JPanel
117
	 */
118
//	private JPanel getPnlButtons() {
119
//		if(pnlButtons == null) {
120
//			pnlButtons = new JPanel();
121
//			pnlButtons.add(getButDel());
122
//			pnlButtons.add(getButDelAll());
123
//		}
124
//		return pnlButtons;
125
//	}
126
	/**
127
	 * Obtains the button that is used to delete all the rows of the symbolTable
128
	 *
129
	 * @return JButton
130
	 */
131
//	private JButton getButDelAll() {
132
//		if (btnDeleteAll == null) {
133
//			btnDeleteAll = new JButton();
134
//			btnDeleteAll.addActionListener(this);
135
//			btnDeleteAll.setText(PluginServices.getText(this, "Quitar_todos"));
136
//		}
137
//		return btnDeleteAll;
138
//	}
139
	/**
140
	 * Obtains the button that is used to delete a row of the symbolTable
141
	 *
142
	 * @return JButton
143
	 */
144
//	private JButton getButDel() {
145
//		if (btnDelete == null) {
146
//			btnDelete = new JButton();
147
//			btnDelete.addActionListener(this);
148
//			btnDelete.setText(PluginServices.getText(this, "Quitar"));
149
//		}
150
//
151
//		return btnDelete;
152
//	}
153
	/**
154
	 * Obtains the north panel
155
	 *
156
	 * @return JPanel
157
	 */
158
	private JPanel getPnlNorth() {
159
		if (pnlNorth == null) {
160
			pnlNorth = new JPanel(new GridLayout(1, 2));
161
			pnlNorth.add(getPnlFields());
162
			pnlNorth.add(getPnlColorAndSymbol());
163
		}
164

  
165
		return pnlNorth;
166
	}
167
	/**
168
	 * Obtains the panel where the user has the options to select the variation to be applied
169
	 *
170
	 * @return JPanel
171
	 */
172
	private JPanel getPnlColorAndSymbol() {
173
		if (pnlColorAndSymbol == null) {
174
			pnlColorAndSymbol = new JPanel();
175
			pnlColorAndSymbol.setBorder(
176
					BorderFactory.createTitledBorder(
177
							null, Messages.getText("variation_by")));
178
			pnlColorAndSymbol.add(getBtnColor());
179
			pnlColorAndSymbol.add(getBtnSymbol());
180
		}
181

  
182
		return pnlColorAndSymbol;
183
	}
184
	/**
185
	 * Creates the button which is used to selecte the variation by symbol
186
	 *
187
	 * @return JButton
188
	 */
189
	private JButton getBtnSymbol() {
190
		if (btnSymbol == null) {
191
			btnSymbol = new JButton(Messages.getText("symbol"));
192
			btnSymbol.addActionListener(this);
193
		}
194
		return btnSymbol;
195
	}
196
	/**
197
	 * Creates the button which is used to selecte the variation by color ramp
198
	 *
199
	 * @return JButton
200
	 */
201
	private JButton getBtnColor() {
202
		if (btnColor == null) {
203
			btnColor = new JButton(Messages.getText("color_ramp"));
204
			btnColor.addActionListener(this);
205
		}
206

  
207
		return btnColor;
208
	}
209
	/**
210
	 * Creates the panel where the JComboBoxes to select the fields for the variation will be placed
211
	 *
212
	 * @return GridBagLayoutPanel
213
	 */
214
	private GridBagLayoutPanel getPnlFields() {
215
		if (pnlFields == null) {
216
			pnlFields = new GridBagLayoutPanel();
217
			pnlFields.setBorder(
218
					BorderFactory.createTitledBorder(
219
							null, Messages.getText("value_fields")));
220
			pnlFields.addComponent(
221
			    Messages.getText("color_field"), getCmbColorField());
222
			pnlFields.addComponent(
223
			    Messages.getText("symbol_field") ,getCmbGraduatedField());
224
		}
225

  
226
		return pnlFields;
227
	}
228
	/**
229
	 * Creates a JComboBox where the user will select the field for the symbol variation
230
	 *
231
	 * @return JComboBox
232
	 */
233
	private JComboBox getCmbGraduatedField() {
234
		if (cmbGraduatedSymbolField == null) {
235
			cmbGraduatedSymbolField = new JComboBox();
236
			cmbGraduatedSymbolField.addActionListener(this);
237
		}
238
		return cmbGraduatedSymbolField;
239
	}
240
	/**
241
	 * Creates a JComboBox where the user will select the field for the color ramp variation
242
	 *
243
	 * @return JComboBox
244
	 */
245
	private JComboBox getCmbColorField() {
246
		if (cmbColorField == null) {
247
			cmbColorField = new JComboBox();
248
			cmbColorField.addActionListener(this);
249
		}
250
		return cmbColorField;
251
	}
252

  
253
	public void setData(FLayer lyr, ILegend legend) {
254
		this.layer = lyr;
255
		this.oldLegend = null;
256

  
257
		if (symbolTable != null)
258
			pnlSouth.remove(symbolTable);
259

  
260

  
261
		symbolTable = new SymbolTable(
262
		    this, SymbolTable.INTERVALS_TYPE, Geometry.TYPES.GEOMETRY);
263

  
264
		pnlSouth.add(symbolTable,BorderLayout.CENTER);
265
		fillFieldNames();
266

  
267

  
268
		if (legend instanceof QuantityByCategoryLegend) {
269
            this.oldLegend = (QuantityByCategoryLegend) legend.cloneLegend();
270
			cmbColorField.setSelectedItem(this.oldLegend.getColorRampLegend().getClassifyingFieldNames()[0]);
271
			cmbGraduatedSymbolField.setSelectedItem(
272
			    this.oldLegend.getGraduatedSymbolsLegend()
273
			    .getClassifyingFieldNames()[0]);
274
			symbolTable.removeAllItems();
275

  
276
			this.fillTableSkipDefault(this.oldLegend);
277

  
278
		} else {
279
			this.oldLegend = new QuantityByCategoryLegend();
280
			String[] fnn = {
281
                (String) getCmbColorField().getSelectedItem(),
282
                (String) getCmbGraduatedField().getSelectedItem() };
283

  
284
			this.oldLegend.setClassifyingFieldNames(fnn);
285

  
286
            try {
287
                FLyrVect lv = (FLyrVect) lyr;
288
                this.setFieldTypesFromFieldNames(lv, this.oldLegend, fnn);
289
                this.oldLegend.setShapeType(lv.getShapeType());
290
            } catch (Exception exc) {
291
                logger.info("Error while setting data in legend panel", exc);
292
                ApplicationLocator.getManager().messageDialog(
293
                    Messages.getText("error_trying_to_access_to_the_layer"),
294
                    Messages.getText("error"),
295
                    JOptionPane.ERROR_MESSAGE);
296
            }
297
		}
298
	}
299

  
300
	private void setFieldTypesFromFieldNames(
301
	    FLyrVect vect,
302
	    QuantityByCategoryLegend leg,
303
	    String[] nn) throws DataException {
304

  
305
        FeatureStore fsto = (FeatureStore) vect.getDataStore();
306
        FeatureType fty = fsto.getDefaultFeatureType();
307
        int[] fieldTypes  = new int[nn.length];
308
        FeatureAttributeDescriptor attdesc = null;
309

  
310
        for (int i = 0; i < nn.length; i++) {
311
            attdesc = fty.getAttributeDescriptor(nn[i]);
312
            fieldTypes[i]= attdesc.getDataType().getType();
313
        }
314
        leg.setClassifyingFieldTypes(fieldTypes);
315
	}
316

  
317

  
318

  
319
	private void fillSymbolListFromTable() {
320

  
321
		ISymbol theSymbol;
322
		IInterval theInterval = null;
323
		// Borramos las anteriores listas:
324
		this.oldLegend.clear();
325

  
326
		FLyrVect vect = (FLyrVect) layer;
327
		try {
328

  
329
		    String[] fNames = this.oldLegend.getClassifyingFieldNames();
330
			if (fNames != null) {
331
			    setFieldTypesFromFieldNames(vect, this.oldLegend, fNames);
332
			}
333
		} catch (DataException e) {
334

  
335
            logger.info("Error while fillSymbolListFromTablel", e);
336
            ApplicationLocator.getManager().messageDialog(
337
                Messages.getText("could_not_setup_legend"),
338
                Messages.getText("error"),
339
                JOptionPane.ERROR_MESSAGE);
340
            return;
341
		}
342

  
343
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
344

  
345
			theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
346
			theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
347
			theSymbol.setDescription((String) symbolTable.getFieldValue(
348
					row, 2));
349

  
350
			if (theSymbol instanceof IFillSymbol) {
351
				this.oldLegend.getColorRampLegend().addSymbol(theInterval, theSymbol);
352
			} else if (theSymbol instanceof IMarkerSymbol){
353
				this.oldLegend.getGraduatedSymbolsLegend().addSymbol(theInterval, theSymbol);
354
			}
355

  
356
		}
357

  
358
		if(oldLegend.getColorRampLegend().isUseDefaultSymbol())
359
			this.oldLegend.getColorRampLegend().addSymbol(
360
			    null, oldLegend.getColorRampLegend().getDefaultSymbol());
361
		if(oldLegend.getGraduatedSymbolsLegend().isUseDefaultSymbol())
362
			this.oldLegend.getGraduatedSymbolsLegend().addSymbol(
363
			    null, oldLegend.getGraduatedSymbolsLegend().getDefaultSymbol());
364
	}
365

  
366
	public ILegend getLegend() {
367
		fillSymbolListFromTable();
368
        this.legend = (QuantityByCategoryLegend) this.oldLegend.cloneLegend();
369
		return this.legend;
370
	}
371

  
372
	public String getDescription() {
373
		return Messages.getText("draw_quantities_for_each_category");
374
	}
375

  
376
	public ImageIcon getIcon() {
377
	    ImageIcon ii = IconThemeHelper.getImageIcon(
378
	        "legend-overview-quantity-by-category");
379
	    return ii;
380
	}
381

  
382
	public Class getParentClass() {
383
		return MultipleAttributes.class;
384
	}
385

  
386
	public String getTitle() {
387
		return Messages.getText("quantity_by_category");
388
	}
389

  
390
	public JPanel getPanel() {
391
		return this;
392
	}
393

  
394
	public Class getLegendClass() {
395
		return QuantityByCategoryLegend.class;
396
	}
397

  
398
	public void actionPerformed(ActionEvent e) {
399
		JComponent c = (JComponent) e.getSource();
400

  
401
		if (c.equals(getBtnColor())) {
402
			VectorialIntervalLegend colorRamp = this.oldLegend.getColorRampLegend();
403
			String fieldName = (String) getCmbColorField().getSelectedItem();
404
			if (!fieldName.equals(colorRamp.getClassifyingFieldNames()[0])) {
405
				// if classification field has changed, clear the legend
406
				colorRamp.setClassifyingFieldNames(new String[] {fieldName});
407
				colorRamp.clear();
408
			}
409
			// create a new modal window to edit the color ramp legend
410
			VectorialInterval legPanel = new VectorialInterval();
411
			legPanel.setData(layer, colorRamp);
412
			InnerWindow window = new InnerWindow(legPanel);
413

  
414
			ApplicationLocator.getManager().getUIManager().addWindow(window);
415

  
416
			cmbColorField.setSelectedItem(colorRamp.getClassifyingFieldNames()[0].toString());
417
			ILegend newLegend = window.getLegend();
418
			if (newLegend != null) {
419

  
420
				if (newLegend instanceof VectorialIntervalLegend) {
421
	                this.oldLegend.getColorRampLegend().clear();
422
	                this.oldLegend.setColorRampLegend(
423
	                    (VectorialIntervalLegend) newLegend);
424
				} else {
425
		            ApplicationLocator.getManager().messageDialog(
426
		                Messages.getText("could_not_setup_legend"),
427
		                Messages.getText("error"),
428
		                JOptionPane.ERROR_MESSAGE);
429
				}
430
			}
431
			symbolTable.removeAllItems();
432
			this.fillTableSkipDefault(this.oldLegend);
433

  
434
		} else if (c.equals(getBtnSymbol())) {
435

  
436
			GraduatedSymbolsLegend graduatedSymbol =
437
			    this.oldLegend.getGraduatedSymbolsLegend();
438
			String fieldName = (String) getCmbGraduatedField().getSelectedItem();
439
			if (!fieldName.equals(graduatedSymbol.getClassifyingFieldNames()[0])) {
440
				// if classification field has changed, clear the legend
441
				graduatedSymbol.setClassifyingFieldNames(new String[] {fieldName});
442

  
443
		        ISymbol def = MapContextLocator.getSymbolManager().
444
		            createSymbol(Geometry.TYPES.POINT);
445
				graduatedSymbol.setDefaultSymbol(def);
446

  
447
				graduatedSymbol.setMinSymbolSize(1);
448
				graduatedSymbol.setMaxSymbolSize(14);
449
				graduatedSymbol.clear();
450
			}
451
			// create a new modal window to edit the graduated symbol legend
452
			GraduatedSymbolsPanel legPanel = new GraduatedSymbolsPanel(false);
453
			legPanel.setData(layer, graduatedSymbol);
454
			InnerWindow window = new InnerWindow(legPanel);
455

  
456
			ApplicationLocator.getManager().getUIManager().addWindow(window);
457

  
458
			cmbGraduatedSymbolField.setSelectedItem(graduatedSymbol.getClassifyingFieldNames()[0].toString());
459
			ILegend newLegend = window.getLegend();
460
			if(newLegend != null) {
461

  
462
			    if (newLegend instanceof GraduatedSymbolsLegend) {
463
	                this.oldLegend.getGraduatedSymbolsLegend().clear();
464
	                this.oldLegend.setGraduateSymbolLegend(
465
	                    (GraduatedSymbolsLegend) newLegend);
466
			    } else {
467
                    ApplicationLocator.getManager().messageDialog(
468
                        Messages.getText("could_not_setup_legend"),
469
                        Messages.getText("error"),
470
                        JOptionPane.ERROR_MESSAGE);
471
			    }
472
			}
473
			symbolTable.removeAllItems();
474
			this.fillTableSkipDefault(this.oldLegend);
475
		}
476

  
477
		else if (c.equals(getCmbColorField())) {
478
			symbolTable.removeAllItems();
479

  
480
			this.fillTableSkipDefault(
481
			    this.oldLegend.getGraduatedSymbolsLegend().getSymbols(),
482
			    this.oldLegend.getGraduatedSymbolsLegend().getValues(),
483
			    this.oldLegend.getDescriptions());
484
		}
485

  
486
		else if (c.equals(getCmbGraduatedField())) {
487
			symbolTable.removeAllItems();
488

  
489
			this.fillTableSkipDefault(
490
			    this.oldLegend.getColorRampLegend().getSymbols(),
491
			    this.oldLegend.getColorRampLegend().getValues(),
492
			    this.oldLegend.getDescriptions());
493
		}
494

  
495
//		if (c.equals(getButDel())) {
496
//			symbolTable.removeSelectedRows();
497
//		}
498
//
499
//		else if(c.equals(getButDelAll())) {
500
//			symbolTable.removeAllItems();
501
//		}
502
	}
503
	private class InnerWindow extends JPanel implements IWindow {
504

  
505
		private ActionListener okAction = new ActionListener() {
506
			public void actionPerformed(ActionEvent e) {
507
				legend = panel.getLegend();
508
				ApplicationLocator.getManager().getUIManager()
509
				.closeWindow(InnerWindow.this);
510
			}
511

  
512
		}, cancelAction = new ActionListener() {
513
			public void actionPerformed(ActionEvent e) {
514
                ApplicationLocator.getManager().getUIManager()
515
                .closeWindow(InnerWindow.this);
516
			}
517
		};
518
		private ILegend legend;
519
		private ILegendPanel panel;
520
		private WindowInfo wi;
521
		public InnerWindow(ILegendPanel panel) {
522
			this.panel = panel;
523
			this.setLayout(new BorderLayout());
524
			add((JComponent) panel, BorderLayout.NORTH);
525
			add(new AcceptCancelPanel(okAction, cancelAction), BorderLayout.SOUTH);
526
		}
527

  
528
		public ILegend getLegend() {
529
			return legend;
530
		}
531

  
532
		public WindowInfo getWindowInfo() {
533
			if (wi == null) {
534
				wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
535
				JComponent c = (JComponent) panel;
536
				wi.setWidth(c.getWidth());
537
				wi.setHeight(c.getHeight());
538
				wi.setTitle(panel.getTitle());
539
			}
540
			return wi;
541
		}
542

  
543
		public Object getWindowProfile() {
544
			return WindowInfo.DIALOG_PROFILE;
545
		}
546

  
547

  
548
	}
549
	/**
550
	 * Fills the comboboxes that are placed in the panel with the
551
	 * classifying field names of the layer
552
	 *
553
	 */
554
	protected void fillFieldNames() {
555

  
556
		ArrayList<String> nomFields = null;
557
		FLyrVect vect = null;
558

  
559
		try {
560

  
561
            FeatureStore fsto = null;
562
            FeatureType fty = null;
563
            FeatureAttributeDescriptor[] atts = null;
564
			if (layer instanceof FLyrVect) {
565
			    vect = (FLyrVect) layer;
566
	            fsto = (FeatureStore) vect.getDataStore();
567
	            fty = fsto.getDefaultFeatureType();
568
	            atts = fty.getAttributeDescriptors();
569
			} else {
570
	            ApplicationLocator.getManager().messageDialog(
571
	                Messages.getText("error_trying_to_access_to_the_layer"),
572
	                Messages.getText("error"),
573
	                JOptionPane.ERROR_MESSAGE);
574
	            logger.info("Error while fillFieldNames, Unexpected layer class: "
575
	                + layer);
576
	            return;
577
			}
578
			nomFields = new ArrayList<String>();
579
			for (int i = 0; i < atts.length; i++) {
580
			    if (atts[i].getDataType().isNumeric()) {
581
                    nomFields.add(atts[i].getName());
582
			    }
583
			}
584
		} catch (DataException e) {
585
            ApplicationLocator.getManager().messageDialog(
586
                Messages.getText("error_trying_to_access_to_the_layer"),
587
                Messages.getText("error"),
588
                JOptionPane.ERROR_MESSAGE);
589
            logger.info("Error while fillFieldNames", e);
590
            nomFields = new ArrayList<String>();
591
		}
592

  
593
		DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray());
594
		cmbColorField.setModel(cM);
595
		cM = new DefaultComboBoxModel(nomFields.toArray());
596
		cmbGraduatedSymbolField.setModel(cM);
597

  
598
		symbolTable.removeAllItems();
599
	}
600

  
601

  
602
	public boolean isSuitableFor(FLayer layer) {
603
		if (layer instanceof FLyrVect) {
604
			try {
605
				FLyrVect vect = (FLyrVect) layer;
606
				int shpt = vect.getGeometryType().getType();
607

  
608
				if (!QuantityByCategoryLegend.isPolygonal(shpt)) {
609
				    return false;
610
				}
611

  
612
                FeatureStore fsto = (FeatureStore) vect.getDataStore();
613
                FeatureType fty = fsto.getDefaultFeatureType();
614
                FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
615

  
616
				for (int i = 0; i < atts.length; i++) {
617
				    if (atts[i].getDataType().isNumeric()) {
618
				        return true;
619
				    }
620
				}
621
			} catch (Exception e) {
622
			    logger.info("Error while isSuitableFor.", e);
623
	            ApplicationLocator.getManager().message(
624
	                Messages.getText("error"),
625
	                JOptionPane.ERROR_MESSAGE);
626
				return false;
627
			}
628
		}
629
		return false;
630
	}
631

  
632

  
633
	// reemplazar esto por arriba
634
    private void fillTableSkipDefault(
635
        IClassifiedLegend leg) {
636

  
637
        Object[] src_expr = leg.getValues();
638
        ISymbol[] src_syms = leg.getSymbols();
639
        String[] src_descs = leg.getDescriptions();
640

  
641
        List syms = new ArrayList();
642
        List vals = new ArrayList();
643
        List descs = new ArrayList();
644
        for (int i=0; i<src_expr.length; i++) {
645
            if (src_expr[i] instanceof IInterval) {
646
                syms.add(src_syms[i]);
647
                vals.add(src_expr[i]);
648
                descs.add(src_descs[i]);
649
            }
650
        }
651
        symbolTable.fillTableFromSymbolList(
652
            (ISymbol[]) syms.toArray(new ISymbol[0]),
653
            (Object[]) vals.toArray(new Object[0]),
654
            (String[]) descs.toArray(new String[0]));
655
    }
656

  
657
    private void fillTableSkipDefault(
658
        ISymbol[] src_syms,
659
        Object[] src_expr,
660
        String[] src_descs) {
661

  
662
        List syms = new ArrayList();
663
        List vals = new ArrayList();
664
        List descs = new ArrayList();
665
        for (int i=0; i<src_expr.length; i++) {
666
            if (src_expr[i] instanceof IInterval) {
667
                syms.add(src_syms[i]);
668
                vals.add(src_expr[i]);
669
                descs.add(src_descs[i]);
670
            }
671
        }
672
        symbolTable.fillTableFromSymbolList(
673
            (ISymbol[]) syms.toArray(new ISymbol[0]),
674
            (Object[]) vals.toArray(new Object[0]),
675
            (String[]) descs.toArray(new String[0]));
676
    }
677

  
678

  
679
}
org.gvsig.legend.quantitybycategory.app.mainplugin/tags/org.gvsig.legend.quantitybycategory.app.mainplugin-1.0.13/src/main/java/org/gvsig/symbology/library/QuantityByCategoryLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2013 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.symbology.library;
24

  
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.app.project.documents.view.legend.gui.LegendManager;
27
import org.gvsig.symbology.SymbologyLibrary;
28
import org.gvsig.symbology.fmap.rendering.QuantityByCategoryLegend;
29
import org.gvsig.symbology.gui.layerproperties.QuantityByCategoryPanel;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32
import org.gvsig.tools.persistence.xml.XMLPersistenceLibrary;
33
import org.gvsig.tools.util.Caller;
34
import org.gvsig.tools.util.impl.DefaultCaller;
35

  
36

  
37
/**
38
 * Simple library to register Quantity by category legend
39
 * 
40
 * @author jldominguez
41
 *
42
 */
43
public class QuantityByCategoryLibrary extends AbstractLibrary {
44

  
45

  
46
    public void doRegistration() {
47
        registerAsImplementationOf(QuantityByCategoryLibrary.class);
48
        /*
49
         * This checks map context library registration
50
         */
51
        require(SymbologyLibrary.class);
52
        /*
53
         * This is because we need to use persistence manager
54
         */
55
        require(XMLPersistenceLibrary.class);
56
    }
57

  
58
    protected void doInitialize() throws LibraryException {
59
        
60
    }
61

  
62

  
63
    protected void doPostInitialize() throws LibraryException {
64
        
65
        IconThemeHelper.registerIcon("legend",
66
            "legend-overview-quantity-by-category", this);
67

  
68
        Caller caller = new DefaultCaller();
69
        
70
        caller.add(new QuantityByCategoryLegend.RegisterLegend());
71
        caller.add(new QuantityByCategoryLegend.RegisterPersistence());
72
        
73
        /*
74
         * Do register of all
75
         */
76
        if( !caller.call() ) {
77
            throw new LibraryException(
78
                QuantityByCategoryLibrary.class,
79
                caller.getExceptions());
80
        }
81
        LegendManager.addLegendPage(QuantityByCategoryPanel.class);
82
    }
83
    
84

  
85

  
86
}
org.gvsig.legend.quantitybycategory.app.mainplugin/tags/org.gvsig.legend.quantitybycategory.app.mainplugin-1.0.13/src/main/resources-plugin/i18n/text_el.properties
1
#Translations for language [el]
2
#Mon Sep 21 10:02:12 CEST 2009
3
a_default_symbol_will_be_used=
4
above=
5
accept=\u0391\u03c0\u03bf\u03b4\u03bf\u03c7\u03ae
6
accessing_file_structure=
7
add=\u03a0\u03c1\u03bf\u03c3\u03b8\u03ae\u03ba\u03b7
8
add_class=
9
add_expression=
10
add_field=\u03a0\u03c1\u03bf\u03c3\u03b8\u03ae\u03ba\u03b7 \u03c0\u03b5\u03b4\u03af\u03bf\u03c5
11
add_operator=
12
add_text_area=
13
all_features=
14
all_supported_background_image_formats=
15
allow_label_overlapping=
16
always_circular=
17
always_horizontal=
18
always_straight=
19
angle=\u0393\u03c9\u03bd\u03af\u03b1
20
anticlockwise=
21
apply_visual_correction_to_glyph_for_precise_size_and_position=
22
arguments_added_to_a_costant=
23
at_begin=
24
at_best=
25
at_end=
26
at_fields=
27
background=
28
background_color=\u03a7\u03c1\u03ce\u03bc\u03b1 \u03c6\u03cc\u03bd\u03c4\u03bf\u03c5
29
background_style=
30
barchar3d_legend=
31
barchar3d_legend_desc=
32
barchart_3D=
33
below=
34
bitmap_and_svg_image_files=
35
boolean_value=\u03a4\u03b9\u03bc\u03ae Boolean
36
browse=\u03a0\u03bb\u03bf\u03ae\u03b3\u03b7\u03c3\u03b7
37
buffered=
38
cancel=\u0391\u03ba\u03cd\u03c1\u03c9\u03c3\u03b7
39
cannot_apply_to_a_non_polygon_layer=\u0391\u03b4\u03cd\u03bd\u03b1\u03c4\u03b7 \u03b7 \u03b5\u03c6\u03b1\u03c1\u03bc\u03bf\u03b3\u03ae \u03c3\u03b5 \u03bc\u03b7 \u03c0\u03bf\u03bb\u03c5\u03b3\u03c9\u03bd\u03b9\u03ba\u03cc \u03b5\u03c0\u03af\u03c0\u03b5\u03b4\u03bf
40
cannot_be_null=
41
cannot_exist_two_label_classes_with_the_same_name=
42
cannot_install_labeling_method=
43
cant_draw_preview=
44
change_location=
45
character_marker=\u0395\u03c0\u03b9\u03c3\u03ae\u03bc\u03b1\u03bd\u03c3\u03b7 \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03ae\u03c1\u03c9\u03bd
46
character_marker_symbol=\u03a3\u03cd\u03bc\u03b2\u03bf\u03bb\u03bf \u03b5\u03c0\u03b9\u03c3\u03ae\u03bc\u03b1\u03bd\u03c3\u03b7\u03c2 \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03ae\u03c1\u03c9\u03bd
47
choose_marker=\u0395\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae \u03b5\u03c0\u03b9\u03c3\u03ae\u03bc\u03b1\u03bd\u03c3\u03b7\u03c2
48
circular=
49
class=
50
classes=
51
classifying_field_name_not_found=
52
clear=\u0395\u03ba\u03ba\u03b1\u03b8\u03ac\u03c1\u03b9\u03c3\u03b7
53
color=\u03a7\u03c1\u03ce\u03bc\u03b1\:
54
color_field=
55
color_ramp=
56
confirmation_dialog=\u0394\u03b9\u03ac\u03bb\u03bf\u03b3\u03bf\u03c2 \u03b5\u03c0\u03b9\u03b2\u03b5\u03b2\u03b1\u03af\u03c9\u03c3\u03b7\u03c2
57
constant=
58
correct_expression=
59
could_not_get_shape_type=
60
could_not_retreive_layer_field_names=
61
could_not_setup_legend=\u0391\u03b4\u03cd\u03bd\u03b1\u03c4\u03b7 \u03b7 \u03b5\u03b3\u03ba\u03b1\u03c4\u03ac\u03c3\u03c4\u03b1\u03c3\u03b7 \u03c4\u03bf\u03c5 \u03c5\u03c0\u03bf\u03bc\u03bd\u03ae\u03bc\u03b1\u03c4\u03bf\u03c2. \u03a0\u03b1\u03c1\u03b1\u03ba\u03b1\u03bb\u03ce \u03bd\u03b1 \u03b5\u03bb\u03ad\u03b3\u03be\u03b5\u03c4\u03b5 \u03c4\u03b9\u03c2 \u03c4\u03b9\u03bc\u03ad\u03c2.
62
date_value=\u03a4\u03b9\u03bc\u03ae \u03b7\u03bc\u03b5\u03c1\u03bf\u03bc\u03b7\u03bd\u03af\u03b1\u03c2
63
default=\u03a0\u03c1\u03bf\u03b5\u03c0\u03b9\u03bb\u03bf\u03b3\u03ae
64
define_classes_of_features_and_label_each_differently=
65
Defines_a_dot_density_symbol_based_on_a_field_value=\u039a\u03b1\u03b8\u03bf\u03c1\u03af\u03b6\u03b5\u03b9 \u03ad\u03bd\u03b1 \u03c3\u03cd\u03bc\u03b2\u03bf\u03bb\u03bf \u03c3\u03b7\u03bc\u03b5\u03b9\u03b1\u03ba\u03ae\u03c2 \u03c0\u03c5\u03ba\u03bd\u03cc\u03c4\u03b7\u03c4\u03b1\u03c2 \u03b2\u03ac\u03c3\u03b7 \u03bc\u03b9\u03b1\u03c2 \u03c4\u03b9\u03bc\u03ae\u03c2 \u03c0\u03b1\u03c1\u03b5\u03c7\u03cc\u03bc\u03b5\u03bd\u03bf\u03c5 \u03c0\u03b5\u03b4\u03af\u03bf\u03c5 
66
delete=
67
delete_class=
68
delete_filter_expression=
69
densities=\u03a0\u03c5\u03ba\u03bd\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2
70
depth_factor=
71
description=\u03a0\u03b5\u03c1\u03b9\u03b3\u03c1\u03b1\u03c6\u1f20
72
divided_by_0=
73
dont_show_labels_when_zoomed=
74
dot_density=\u03a0\u03c5\u03ba\u03bd\u03cc\u03c4\u03b7\u03c4\u03b1 \u03ba\u03bf\u03c5\u03ba\u03ba\u03af\u03b4\u03c9\u03bd
75
dot_size=\u039c\u03ad\u03b3\u03b5\u03b8\u03bf\u03c2 \u03ba\u03bf\u03c5\u03ba\u03ba\u03af\u03b4\u03b1\u03c2
76
dot_value=\u03a4\u03b9\u03bc\u03ae \u03ba\u03bf\u03c5\u03ba\u03ba\u03af\u03b4\u03b1\u03c2
77
draw_quantities_for_each_category=
78
draw_quantities_using_symbol_size_to_show_exact_values=
79
draw_quantities_using_symbol_size_to_show_relative_values=
80
duplicate_labels=
81
edit_expression=
82
Enable_layer_preview=
83
enter_new_name=
84
error=\u03a3\u03c6\u03ac\u03bb\u03bc\u03b1
85
error\ accessing\ to\ the\ layer=
86
error_coding_filter_query=\u0397 \u03bc\u03bf\u03c1\u03c6\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7 \u03c4\u03bf\u03c5 \u03c6\u03af\u03bb\u03c4\u03c1\u03bf\u03c5 \u03b5\u03af\u03bd\u03b1\u03b9 \u03bb\u03b1\u03bd\u03b8\u03b1\u03c3\u03bc\u03ad\u03bd\u03b7\: \u03c3\u03c6\u1f00\u03bb\u03bc\u03b1 \u03c3\u03c4\u03b7\u03bd \u03ba\u03c9\u03b4\u03b9\u03ba\u03bf\u03c0\u03bf\u03af\u03b7\u03c3\u03b7
87
error_trying_to_access_to_the_layer=
88
error_validating_filter_query=
89
expression=
90
expression_creator=
91
expressions=
92
failed_acessing_files=
93
failed_applying_following_line_will_use_default_confg=
94
failed_computing_intervals=
95
features=
96
field_number=
97
fields=\u03a0\u03b5\u03b4\u03af\u03b1
98
fields_exp=
99
fill_color=\u03a7\u03c1\u03ce\u03bc\u03b1 \u03b3\u03b5\u03bc\u03af\u03c3\u03bc\u03b1\u03c4\u03bf\u03c2
100
fill_properties=\u0399\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03b5\u03c2 \u03b3\u03b5\u03bc\u03af\u03c3\u03bc\u03b1\u03c4\u03bf\u03c2
101
filter=\u03a6\u03af\u03bb\u03c4\u03c1\u03bf
102
filtered_features=
103
fit_inside_polygon=
104
fit_on_text_area=
105
fixed_text_size=
106
following_line=
107
font=
108
foreground_alpha=
109
format=\u03a6\u03bf\u03c1\u03bc\u03ac\u03c4
110
from=\u0391\u03c0\u03cc
111
fuente=\u0393\u03c1\u03b1\u03bc\u03bc\u03b1\u03c4\u03bf\u03c3\u03b5\u03b9\u03c1\u03ac
112
GeneralLabeling.sample_text=
113
generating_intervals=
114
getting_layer_shape_type=
115
gradient_color=
116
gradient_fill=
117
gradient_fill_symbol=
118
graduated_symbols=
119
grid=\u039a\u03ac\u03bd\u03bd\u03b1\u03b2\u03bf\u03c2
120
high=\u03a5\u03c8\u03b7\u03bb\u03ae
121
horizontal=\u039f\u03c1\u03b9\u03b6\u03cc\u03bd\u03c4\u03b9\u03bf\u03c2
122
ignore_zero_values=
123
in_beyond=
124
in_layer=
125
in_the_middle=
126
incompatible_types_to_calculate_the_normalization=
127
incorrect_expression=
128
intervals=
129
invalid_filter_expression=
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff