Revision 1848

View differences:

org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegendManager.java
95 95
    public Operation getDefaultOperation() {
96 96
        return this.defaultOperation;
97 97
    }
98
    
98

  
99
    @Override
100
    public Operation createOperation(String name) {
101
        Operation op = this.operations.get(name);
102
        if( op == null ) {
103
            throw new IllegalArgumentException("Can't locate operation '"+name+"'.");
104
        }
105
        return op.clone();
106
    }
107

  
108

  
99 109
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegend.java
13 13
import java.util.ArrayList;
14 14
import java.util.List;
15 15
import java.util.Map;
16
import java.util.logging.Level;
17 16
import javax.swing.UIManager;
18 17

  
19 18
import org.cresques.cts.ICoordTrans;
......
43 42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
44 43
import org.gvsig.tools.exception.BaseException;
45 44
import org.gvsig.tools.logger.FilteredLogger;
45
import org.gvsig.tools.persistence.PersistentState;
46
import org.gvsig.tools.persistence.exception.PersistenceException;
46 47
import org.gvsig.tools.task.Cancellable;
47 48
import org.gvsig.tools.visitor.VisitCanceledException;
48 49
import org.gvsig.tools.visitor.Visitor;
......
411 412
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
412 413
        }
413 414
    }
415

  
416
    @Override
417
    public void loadFromState(PersistentState state) throws PersistenceException {
418
        super.loadFromState(state);
419
        this.symbolSize = state.getInt("symbolSize");
420
        this.fillColor = (Color) state.get("fillColor");
421
        this.outlineColor = (Color) state.get("outlineColor");
422
        this.textColor = (Color) state.get("textColor");
423
        this.showBounds = state.getBoolean("showBounds");
424
        this.font = (Font) state.get("font");
425
        this.useStyle = state.getBoolean("useStyle");
426
        this.labelStyle = (ILabelStyle) state.get("labelStyle");
427
        this.operation = (Operation) state.get("operation");
428
    }
429

  
430
    @Override
431
    public void saveToState(PersistentState state) throws PersistenceException {
432
        super.saveToState(state);
433
        state.set("symbolSize", symbolSize);
434
        state.set("fillColor", fillColor);
435
        state.set("outlineColor", outlineColor);
436
        state.set("textColor", textColor);
437
        state.set("showBounds", showBounds);
438
        state.set("font", font);
439
        state.set("useStyle", useStyle);
440
        state.set("labelStyle", labelStyle);
441
        state.set("operation", operation);
442
    }
414 443
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/AggregateLegendLibraryImpl.java
29 29
import org.gvsig.fmap.mapcontext.MapContextManager;
30 30
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLibrary;
31 31
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator;
32
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary;
33
import org.gvsig.tools.ToolsLocator;
32 34
import org.gvsig.tools.library.AbstractLibrary;
33 35
import org.gvsig.tools.library.LibraryException;
36
import org.gvsig.tools.persistence.PersistenceManager;
34 37

  
35 38
public class AggregateLegendLibraryImpl extends AbstractLibrary {
36 39

  
......
38 41
    public void doRegistration() {
39 42
        registerAsImplementationOf(AggregateLegendLibrary.class);
40 43
        this.require(MapContextLibrary.class);
44
        this.require(SymbologyDefaultImplLibrary.class);
41 45
    }
42 46

  
43 47
    @Override
44 48
    protected void doInitialize() throws LibraryException {
45 49
        AggregateLegendLocator.registerAggregateLegendManager(DefaultAggregateLegendManager.class);
50

  
46 51
        MapContextManager mcmanager = MapContextLocator.getMapContextManager();
47 52
        mcmanager.registerLegend("AggregateLegend", DefaultAggregateLegend.class);
48 53
    }
49 54

  
50 55
    @Override
51 56
    protected void doPostInitialize() throws LibraryException {
57
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
58
        persistenceManager.registerFactory(new OperationPersistenceFactory());
59
        persistenceManager.addDefinition(
60
            DefaultAggregateLegend.class, 
61
            "DefaultAggregateLegend", 
62
            "/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegend.persistence.xml"
63
        );
52 64
    }
53 65

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

  
26
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator;
27
import org.gvsig.legend.aggregate.lib.api.AggregateLegendManager;
28
import org.gvsig.legend.aggregate.lib.api.Operation;
29

  
30
import org.gvsig.tools.dynobject.DynStruct;
31
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34

  
35
public class OperationPersistenceFactory extends AbstractSinglePersistenceFactory {
36

  
37
    static final String FIELD_NAME = "name";
38
    static final String FIELD_ATTRIBUTE = "attribute";
39
    static final String FIELD_VALUE = "value";
40

  
41
    private static final String DYNCLASS_NAME = "AggregateLegendOperation";
42
    private static final String DYNCLASS_DESCRIPTION = "Operation for aggregate legend";
43

  
44
    public OperationPersistenceFactory() {
45
        super(Operation.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null);
46

  
47
        DynStruct definition = this.getDefinition();
48

  
49
        definition.addDynFieldString(FIELD_NAME).setMandatory(true);
50
        definition.addDynFieldString(FIELD_ATTRIBUTE).setMandatory(false);
51
        definition.addDynFieldString(FIELD_VALUE).setMandatory(false);
52
    }
53

  
54
    @Override
55
    public Object createFromState(PersistentState state)
56
        throws PersistenceException {
57
        AggregateLegendManager manager = AggregateLegendLocator.getAggregateLegendManager();
58

  
59
        String name = (String) state.get(FIELD_NAME);
60
        Operation operation = manager.createOperation(name);
61
        operation.setAttributeName(state.getString(FIELD_ATTRIBUTE));
62
        operation.setAditionalValue(state.getString(FIELD_VALUE));
63

  
64
        return operation;
65
    }
66

  
67
    @Override
68
    public void saveToState(PersistentState state, Object obj)
69
        throws PersistenceException {
70

  
71
        Operation op = (Operation) obj;
72
        state.set(FIELD_NAME, op.getName());
73
        state.set(FIELD_ATTRIBUTE, op.getAttributeName());
74
        state.set(FIELD_VALUE, op.getAditionalValue());
75
    }
76
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/MinOperation.java
1 1
package org.gvsig.legend.aggregate.lib.impl.operation;
2 2

  
3 3
import org.gvsig.fmap.dal.feature.Feature;
4
import org.gvsig.legend.aggregate.lib.api.AbstractOperation;
4
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
5 5

  
6 6
public class MinOperation extends AbstractOperation {
7 7

  
8 8
    private int min = 0;
9 9

  
10 10
    public MinOperation() {
11
        super("_Minimun", "_Calculate_the_minimum_of_the_selected_attribute_for_the_grouped_features");
11
        super("Minimun", "_Calculate_the_minimum_of_the_selected_attribute_for_the_grouped_features");
12 12
    }
13 13

  
14 14
    @Override
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/SumOperation.java
3 3
import java.text.MessageFormat;
4 4
import org.apache.commons.lang3.StringUtils;
5 5
import org.gvsig.fmap.dal.feature.Feature;
6
import org.gvsig.legend.aggregate.lib.api.AbstractOperation;
6
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
7 7

  
8 8

  
9 9
public class SumOperation extends AbstractOperation {
10 10
    int sum = 0;
11 11
    
12 12
    public SumOperation() {
13
        super("_Sum", "_Calculate_the_sum_of_the_selected_attribute_for_the_grouped_features");
13
        super("Sum", "_Calculate_the_sum_of_the_selected_attribute_for_the_grouped_features");
14 14

  
15 15
    }
16 16

  
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/MaxOperation.java
1 1
package org.gvsig.legend.aggregate.lib.impl.operation;
2 2

  
3 3
import org.gvsig.fmap.dal.feature.Feature;
4
import org.gvsig.legend.aggregate.lib.api.AbstractOperation;
4
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
5 5

  
6 6
public class MaxOperation extends AbstractOperation {
7 7

  
8 8
    private int max = 0;
9 9

  
10 10
    public MaxOperation() {
11
        super("_Maximum", "_Calculate_the_maximum_of_the_selected_attribute_for_the_grouped_features");
11
        super("Maximum", "_Calculate_the_maximum_of_the_selected_attribute_for_the_grouped_features");
12 12
    }
13 13

  
14 14
    @Override
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/CountOperation.java
1 1
package org.gvsig.legend.aggregate.lib.impl.operation;
2 2

  
3 3
import org.gvsig.fmap.dal.feature.Feature;
4
import org.gvsig.legend.aggregate.lib.api.AbstractOperation;
4
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
5 5

  
6 6

  
7 7
public class CountOperation extends AbstractOperation {
8 8
    int count = 0;
9 9
    
10 10
    public CountOperation() {
11
        super("_Count", "_Count_of_grouped_features");
11
        super("Count", "_Count_of_grouped_features");
12 12
    }
13 13

  
14 14
    @Override
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/AvgOperation.java
3 3
import java.text.MessageFormat;
4 4
import org.apache.commons.lang3.StringUtils;
5 5
import org.gvsig.fmap.dal.feature.Feature;
6
import org.gvsig.legend.aggregate.lib.api.AbstractOperation;
6
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
7 7

  
8 8
public class AvgOperation extends AbstractOperation {
9 9

  
......
12 12

  
13 13
    public AvgOperation() {
14 14
        super(
15
            "_Average", 
15
            "Average", 
16 16
            "_Calculate_the_average_of_the_selected_attribute_for_the_grouped_features"
17 17
        );
18 18
    }
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/resources/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegend.persistence.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5
    <class name="DefaultAggregateLegend">
6
      <extends>
7
        <class>VectorialLegend</class>
8
      </extends>
9
      <fields>
10
        <field name="symbolSize" type="integer" defaultValue="30">
11
          <description></description>
12
        </field>
13
        <field name="fillColor" type="object" classOfValue="java.awt.Color">
14
          <description></description>
15
        </field>
16
        <field name="outlineColor" type="object" classOfValue="java.awt.Color">
17
          <description></description>
18
        </field>
19
        <field name="textColor" type="object" classOfValue="java.awt.Color">
20
          <description></description>
21
        </field>
22
        <field name="showBounds" type="boolean" defaultValue="false">
23
          <description></description>
24
        </field>
25
        <field name="font" type="object" classOfValue="java.awt.Font">
26
          <description></description>
27
        </field>
28
        <field name="labelStyle" type="object" classOfValue="org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle">
29
          <description></description>
30
        </field>
31
        <field name="useStyle" type="boolean" defaultValue="false">
32
          <description></description>
33
        </field>
34
        <field name="operation" type="object" classOfValue="org.gvsig.legend.aggregate.lib.api.Operation">
35
          <description></description>
36
        </field>
37
      </fields>
38
    </class>
39

  
40
  </classes>
41
</definitions>  
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AbstractOperation.java
1
package org.gvsig.legend.aggregate.lib.api;
2

  
3
import org.gvsig.tools.ToolsLocator;
4
import org.gvsig.tools.i18n.I18nManager;
5

  
6

  
7
public abstract class AbstractOperation implements Operation {
8
    private final String name;
9
    private final String description;
10
    private String attrName;
11
    private String aditionalValue;
12
    
13
    protected AbstractOperation(String name, String description) {
14
        this.name = name;
15
        this.description = description;
16
        reset();
17
    }
18
    
19
    @Override
20
    public String getName() {
21
        return this.name;
22
    }
23

  
24
    @Override
25
    public String getDescription() {
26
        I18nManager i18n = ToolsLocator.getI18nManager();
27
        return i18n.getTranslation(this.description);
28
    }
29

  
30
    @Override
31
    public boolean isAttributeRequiered() {
32
        return false;
33
    }
34

  
35
    @Override
36
    public boolean isAditionalValueRequiered() {
37
        return false;
38
    }
39

  
40
    @Override
41
    public String getAttributeName() {
42
        return attrName;
43
    }
44

  
45
    @Override
46
    public void setAttributeName(String attributeName) {
47
        this.attrName = attributeName;
48
    }
49

  
50
    @Override
51
    public String getAditionalValue() {
52
        return aditionalValue;
53
    }
54

  
55
    @Override
56
    public void setAditionalValue(String aditionalValue) {
57
        this.aditionalValue = aditionalValue;
58
    }
59

  
60
    @Override
61
    public String format() {
62
        return String.valueOf(getValue());
63
    }
64

  
65
    @Override
66
    public String toString() {
67
        I18nManager i18n = ToolsLocator.getI18nManager();
68
        return i18n.getTranslation(this.getName());
69
    }
70

  
71
    @Override
72
    public Operation clone() {
73
        try {
74
            return (Operation) super.clone();
75
        } catch (CloneNotSupportedException ex) {
76
            return null;
77
        }
78
    }
79
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AggregateLegendManager.java
46 46
    void addOperation(Operation operation);
47 47
    
48 48
    public Collection<Operation> getOperations();
49

  
50
    public Operation createOperation(String name);
49 51
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/spi/AbstractOperation.java
1
package org.gvsig.legend.aggregate.lib.spi;
2

  
3
import org.gvsig.legend.aggregate.lib.api.Operation;
4
import org.gvsig.tools.ToolsLocator;
5
import org.gvsig.tools.i18n.I18nManager;
6

  
7

  
8
public abstract class AbstractOperation implements Operation {
9
    private final String name;
10
    private final String description;
11
    private String attrName;
12
    private String aditionalValue;
13
    
14
    protected AbstractOperation(String name, String description) {
15
        this.name = name;
16
        this.description = description;
17
        reset();
18
    }
19
    
20
    @Override
21
    public String getName() {
22
        return this.name;
23
    }
24

  
25
    @Override
26
    public String getDescription() {
27
        I18nManager i18n = ToolsLocator.getI18nManager();
28
        return i18n.getTranslation(this.description);
29
    }
30

  
31
    @Override
32
    public boolean isAttributeRequiered() {
33
        return false;
34
    }
35

  
36
    @Override
37
    public boolean isAditionalValueRequiered() {
38
        return false;
39
    }
40

  
41
    @Override
42
    public String getAttributeName() {
43
        return attrName;
44
    }
45

  
46
    @Override
47
    public void setAttributeName(String attributeName) {
48
        this.attrName = attributeName;
49
    }
50

  
51
    @Override
52
    public String getAditionalValue() {
53
        return aditionalValue;
54
    }
55

  
56
    @Override
57
    public void setAditionalValue(String aditionalValue) {
58
        this.aditionalValue = aditionalValue;
59
    }
60

  
61
    @Override
62
    public String format() {
63
        return String.valueOf(getValue());
64
    }
65

  
66
    @Override
67
    public String toString() {
68
        I18nManager i18n = ToolsLocator.getI18nManager();
69
        return i18n.getTranslation(this.getName());
70
    }
71

  
72
    @Override
73
    public Operation clone() {
74
        try {
75
            return (Operation) super.clone();
76
        } catch (CloneNotSupportedException ex) {
77
            return null;
78
        }
79
    }
80
}
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.app/org.gvsig.legend.aggregate.app.mainplugin/src/main/resources-plugin/i18n/text.properties
13 13
_Attribute=Atributo
14 14
_Aditional_value=Valor adicional
15 15
Alpha=Alpha
16
_Average=Media
16
Average=Media
17 17
_Calculate_the_average_of_the_selected_attribute_for_the_grouped_features=Calcula la media del atributo seleccionado para las features agrupadas
18
_Count=Cuenta
18
Count=Cuenta
19 19
_Count_of_grouped_features=Cuenta de las features agrupadas
20
_Maximum=M\u00e1ximo
20
Maximum=M\u00e1ximo
21 21
_Calculate_the_maximum_of_the_selected_attribute_for_the_grouped_features=Calcula el maximo del atributo seleccionado para las features agrupadas
22
_Minimun=Minimo
22
Minimun=Minimo
23 23
_Calculate_the_minimun_of_the_selected_attribute_for_the_grouped_features=Calcula el minimo del atributo seleccionado para las features agrupadas
24 24
_Select_style=Seleccion de estilo
25
_Sum=Suma
25
Sum=Suma
26 26
_Calculate_the_sum_of_the_selected_attribute_for_the_grouped_features=Calcula la suma del atributo seleccionado para las features agrupadas
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/org.gvsig.legend.aggregate.app/org.gvsig.legend.aggregate.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
13 13
_Attribute=Attribute
14 14
_Aditional_value=Aditional value
15 15
Alpha=Alpha
16
_Average=Average
16
Average=Average
17 17
_Calculate_the_average_of_the_selected_attribute_for_the_grouped_features=Calculate the average of the selected attribute for the grouped features
18
_Count=Count
18
Count=Count
19 19
_Count_of_grouped_features=Count of grouped features
20
_Maximum=Maximum
20
Maximum=Maximum
21 21
_Calculate_the_maximum_of_the_selected_attribute_for_the_grouped_features=Calculate the maximum of the selected attribute for the grouped features
22
_Minimun=Minimun
22
Minimun=Minimun
23 23
_Calculate_the_minimun_of_the_selected_attribute_for_the_grouped_features=Calculate the minimun of the selected attribute for the grouped features
24 24
_Select_style=Select style
25 25
_Calculate_the_sum_of_the_selected_attribute_for_the_grouped_features=Calculate the sum of the selected attribute for the grouped features
26
_Sum=Sum
26
Sum=Sum
org.gvsig.legend.aggregate/trunk/org.gvsig.legend.aggregate/pom.xml
9 9
  <parent>
10 10
    <groupId>org.gvsig</groupId>
11 11
    <artifactId>org.gvsig.desktop</artifactId>
12
    <version>2.0.203</version>
12
    <version>2.0.204-SNAPSHOT</version>
13 13
  </parent>
14 14

  
15 15
  <url>https://devel.gvsig.org/sites/org.gvsig.legend.aggregate/${project.version}</url>

Also available in: Unified diff