Revision 10215

View differences:

org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <groupId>org.gvsig</groupId>
4
  <artifactId>org.gvsig.legend.aggregate</artifactId>
5
  <version>1.0.187</version>
6
  <packaging>pom</packaging>
7
  <name>${project.artifactId}</name>
8
  <description>Legend for aggregate text symbols that are near.</description>
9
  <parent>
10
    <groupId>org.gvsig</groupId>
11
    <artifactId>org.gvsig.desktop</artifactId>
12
    <version>2.0.445</version>
13
  </parent>
14

  
15
  <url>https://devel.gvsig.org/sites/org.gvsig.legend.aggregate/${project.version}</url>
16
  <scm>
17
    <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187</connection>
18
    <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187</developerConnection>
19
    <url>https://devel.gvsig.org/redmine/projects/gvsig-base-legends/repository/show/org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187</url>
20
  </scm>
21
  <repositories>
22
    <repository>
23
      <id>gvsig-public-http-repository</id>
24
      <name>gvSIG maven public HTTP repository</name>
25
      <url>http://devel.gvsig.org/m2repo/j2se</url>
26
      <releases>
27
        <enabled>true</enabled>
28
        <updatePolicy>daily</updatePolicy>
29
        <checksumPolicy>warn</checksumPolicy>
30
      </releases>
31
      <snapshots>
32
        <enabled>true</enabled>
33
        <updatePolicy>daily</updatePolicy>
34
        <checksumPolicy>warn</checksumPolicy>
35
      </snapshots>
36
    </repository>
37
  </repositories>
38

  
39
  <distributionManagement>
40
    <site>
41
      <id>gvsig-repository</id>
42
      <url>dav:https://devel.gvsig.org/download/projects/gvsig-base-legends/pool/${project.artifactId}/${project.version}</url>
43
    </site>
44
  </distributionManagement>
45

  
46
  <build>
47
    <plugins>
48
      <plugin>
49
        <groupId>org.apache.maven.plugins</groupId>
50
        <artifactId>maven-release-plugin</artifactId>
51
        <configuration>
52
          <tagBase>https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.aggregate/tags</tagBase>
53
        </configuration>
54
      </plugin>
55
    </plugins>
56
  </build>
57

  
58

  
59

  
60
  <dependencyManagement>
61
    <dependencies>
62
      <dependency>
63
        <groupId>org.gvsig</groupId>
64
        <artifactId>org.gvsig.legend.aggregate.lib.api</artifactId>
65
        <version>1.0.187</version>
66
      </dependency>
67
      <dependency>
68
        <groupId>org.gvsig</groupId>
69
        <artifactId>org.gvsig.legend.aggregate.lib.impl</artifactId>
70
        <version>1.0.187</version>
71
      </dependency>
72
      <dependency>
73
        <groupId>org.gvsig</groupId>
74
        <artifactId>org.gvsig.legend.aggregate.swing.api</artifactId>
75
        <version>1.0.187</version>
76
      </dependency>
77
      <dependency>
78
        <groupId>org.gvsig</groupId>
79
        <artifactId>org.gvsig.legend.aggregate.swing.impl</artifactId>
80
        <version>1.0.187</version>
81
      </dependency>
82
      <dependency>
83
        <groupId>org.gvsig</groupId>
84
        <artifactId>org.gvsig.legend.aggregate.app.mainplugin</artifactId>
85
        <version>1.0.187</version>
86
      </dependency>
87
      <dependency>
88
        <groupId>org.jfree</groupId>
89
        <artifactId>jcommon</artifactId>
90
        <version>1.0.24</version>
91
      </dependency>
92
      
93
    </dependencies>
94
  </dependencyManagement>
95
  <modules>
96
    <module>org.gvsig.legend.aggregate.lib</module>
97
    <module>org.gvsig.legend.aggregate.swing</module>
98
    <module>org.gvsig.legend.aggregate.app</module>
99
  </modules>
100
</project>
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AggregateLegendLocator.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.aggregate.lib.api;
24

  
25
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
26
import org.gvsig.tools.locator.AbstractLocator;
27
import org.gvsig.tools.locator.Locator;
28
import org.gvsig.tools.locator.LocatorException;
29

  
30

  
31
public class AggregateLegendLocator extends AbstractLocator {
32

  
33
    /**
34
     * AggregateLegend locator name
35
     */
36
    private static final String LOCATOR_NAME = "AggregateLegendLocator";
37

  
38
    /**
39
     * AggregateLegend manager name
40
     */
41
    public static final String MANAGER_NAME = "AggregateLegendManager";
42

  
43
    /**
44
     * AggregateLegend manager description
45
     */
46
    private static final String MANAGER_DESCRIPTION =
47
        "AggregateLegend Manager of gvSIG";
48

  
49

  
50
    /**
51
     * Unique instance
52
     */
53
    private static final AggregateLegendLocator instance = new AggregateLegendLocator();
54

  
55
    @Override
56
    public String getLocatorName() {
57
        return LOCATOR_NAME;
58
    }
59

  
60
    /**
61
     * Registers the Class implementing the AggregateLegendManager interface.
62
     *
63
     * @param clazz
64
     *            implementing the AggregateLegendManager interface
65
     */
66
    public static void registerAggregateLegendManager(Class clazz){
67
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
68
    }
69

  
70
    /**
71
     * Registers the default Class implementing the AggregateLegendManager interface
72
     *
73
     * @param clazz
74
     *            implementing the AggregateLegendManager interface
75
     */
76
    public static void registerDefaultAggregateLegendManager(Class clazz){
77
        getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
78
    }
79

  
80
    /**
81
     * Return a reference to AggregateLegendManager.
82
     *
83
     * @return a reference to AggregateLegendManager
84
     * @throws LocatorException
85
     *             if there is no access to the class or the class
86
     *             cannot be instantiated
87
     * @see Locator#get(String)
88
     */
89
    public static AggregateLegendManager getAggregateLegendManager() throws LocatorException {
90
        return (AggregateLegendManager) getInstance().get(MANAGER_NAME);
91
    }
92

  
93
    /**
94
     * @return
95
     */
96
    public static Locator getInstance() {
97
        return instance;
98
    }
99

  
100
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AggregateLegendLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.aggregate.lib.api;
24

  
25
import org.gvsig.tools.library.AbstractLibrary;
26
import org.gvsig.tools.library.LibraryException;
27
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
28

  
29

  
30
/**
31
 * @author fdiaz
32
 *
33
 */
34
public class AggregateLegendLibrary extends AbstractLibrary {
35

  
36
    /* (non-Javadoc)
37
     * @see org.gvsig.tools.library.AbstractLibrary#doInitialize()
38
     */
39
    @Override
40
    protected void doInitialize() throws LibraryException {
41
        registerAsAPI(AggregateLegendLibrary.class);
42
    }
43

  
44
    /* (non-Javadoc)
45
     * @see org.gvsig.tools.library.AbstractLibrary#doPostInitialize()
46
     */
47
    @Override
48
    protected void doPostInitialize() throws LibraryException {
49
        // Validate there is any implementation registered.
50
        AggregateLegendManager manager = AggregateLegendLocator.getAggregateLegendManager();
51
        if (manager == null) {
52
            throw new ReferenceNotRegisteredException(
53
                AggregateLegendLocator.MANAGER_NAME, AggregateLegendLocator.getInstance());
54
        }
55
    }
56

  
57
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AggregateLegendManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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 3
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.legend.aggregate.lib.api;
24

  
25
import java.util.Collection;
26
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
27

  
28

  
29
public interface AggregateLegendManager {
30

  
31
    /**
32
     * Creates an aggregate legend
33
     *
34
     * @return the aggregate legend
35
     */
36
    public AggregateLegend createAggregateLegend();
37

  
38
    public Class<? extends AggregateLegend> getLegendClass();
39
    
40
    public ILabelStyle getDefaultLabelStyle();
41
    
42
    public void setDefaultLabelStyle(ILabelStyle defaultLabelStyle);
43

  
44
    public Operation getDefaultOperation();
45

  
46
    void addOperation(Operation operation);
47
    
48
    public Collection<Operation> getOperations();
49

  
50
    public Operation createOperation(String name);
51
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/Operation.java
1

  
2
package org.gvsig.legend.aggregate.lib.api;
3

  
4
import org.gvsig.fmap.dal.feature.Feature;
5

  
6

  
7
public interface Operation extends org.gvsig.tools.lang.Cloneable {
8
    
9
    public String getName();
10
    
11
    public String getDescription();
12
    
13
    public boolean isAttributeRequiered();
14
    
15
    public boolean isAditionalValueRequiered();
16
    
17
    public void reset();
18
    
19
    public void perform(Feature feature);
20
        
21
    public Object getValue();
22

  
23
    public String format();
24
    
25
    public String getAttributeName();
26
    
27
    public void setAttributeName(String attributeName);
28
    
29
    public String getAditionalValue();
30
    
31
    public void setAditionalValue(String constant);
32

  
33
    @Override
34
    public Operation clone();
35
    
36
    
37
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/java/org/gvsig/legend/aggregate/lib/api/AggregateLegend.java
1
package org.gvsig.legend.aggregate.lib.api;
2

  
3
import java.awt.Color;
4
import java.awt.Font;
5
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
6
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
7
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
8

  
9
public interface AggregateLegend extends IVectorLegend, ISingleSymbolLegend {
10

  
11
    public int getSymbolSize();
12
    public void setSymbolSize(int simbolSize);
13
    
14
    public ILabelStyle getLabelStyle();
15
    public void setLabelStyle(ILabelStyle labelStyle);    
16

  
17
    Color getFillColor();
18

  
19
    void setFillColor(Color fillColor);
20

  
21
    Color getTextColor();
22

  
23
    void setTextColor(Color textColor);
24

  
25
    Font getFont();
26

  
27
    void setFont(Font font);
28

  
29
    Operation getOperation();
30

  
31
    void setOperation(Operation operation);
32

  
33
    Color getOutlineColor();
34

  
35
    void setOutlineColor(Color outlineColor);
36

  
37
    boolean isShowBounds();
38

  
39
    void setShowBounds(boolean showBounds);
40

  
41
    boolean isUseStyle();
42

  
43
    void setUseStyle(boolean useStyle);
44

  
45
}
46

  
47

  
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/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/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.legend.aggregate.lib.api.AggregateLegendLibrary
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <groupId>org.gvsig</groupId>
4
  <artifactId>org.gvsig.legend.aggregate.lib.api</artifactId>
5
  <name>org.gvsig.legend.aggregate.lib.api</name>
6
  <parent>
7
    <groupId>org.gvsig</groupId>
8
    <artifactId>org.gvsig.legend.aggregate.lib</artifactId>
9
    <version>1.0.187</version>
10
  </parent>
11

  
12
  <build>
13
    <plugins>
14
      <plugin>
15
        <groupId>org.apache.maven.plugins</groupId>
16
        <artifactId>maven-jar-plugin</artifactId>
17
        <configuration>
18
        </configuration>
19
        <executions>
20
          <!-- Generates a jar file only with the test classes -->
21
          <execution>
22
            <goals>
23
              <goal>test-jar</goal>
24
            </goals>
25
          </execution>
26
        </executions>
27
      </plugin>
28
    </plugins>
29
  </build>
30

  
31
  <dependencies>
32
    <dependency>
33
      <groupId>org.gvsig</groupId>
34
      <artifactId>org.gvsig.tools.lib</artifactId>
35
      <scope>compile</scope>
36
    </dependency>
37
    <dependency>
38
      <groupId>org.gvsig</groupId>
39
      <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
40
      <scope>compile</scope>
41
    </dependency>
42
  </dependencies>
43
</project>
0 44

  
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.legend.aggregate</artifactId>
6
    <version>1.0.187</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.aggregate.lib</artifactId>
10
  <packaging>pom</packaging>
11
  <modules>
12
    <module>org.gvsig.legend.aggregate.lib.api</module>
13
    <module>org.gvsig.legend.aggregate.lib.impl</module>
14
  </modules>
15
</project>
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegend.java
1
package org.gvsig.legend.aggregate.lib.impl;
2

  
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.Font;
6
import java.awt.FontMetrics;
7
import java.awt.Graphics2D;
8
import java.awt.Rectangle;
9
import java.awt.geom.AffineTransform;
10
import java.awt.geom.Ellipse2D;
11
import java.awt.geom.Rectangle2D;
12
import java.awt.image.BufferedImage;
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.Map;
16
import javax.swing.UIManager;
17

  
18
import org.cresques.cts.ICoordTrans;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

  
22
import org.gvsig.fmap.dal.exception.DataException;
23
import org.gvsig.fmap.dal.feature.Feature;
24
import org.gvsig.fmap.dal.feature.FeatureQuery;
25
import org.gvsig.fmap.dal.feature.FeatureSelection;
26
import org.gvsig.fmap.dal.feature.FeatureSet;
27
import org.gvsig.fmap.dal.feature.FeatureStore;
28
import org.gvsig.fmap.geom.Geometry;
29
import org.gvsig.fmap.geom.primitive.Envelope;
30
import org.gvsig.fmap.geom.primitive.Point;
31
import org.gvsig.fmap.mapcontext.MapContextException;
32
import org.gvsig.fmap.mapcontext.ViewPort;
33
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
34
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
35
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
36
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
37
import org.gvsig.legend.aggregate.lib.api.AggregateLegend;
38
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator;
39
import org.gvsig.legend.aggregate.lib.api.Operation;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.DefaultFeatureDrawnNotification;
42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
44
import org.gvsig.tools.exception.BaseException;
45
import org.gvsig.tools.logger.FilteredLogger;
46
import org.gvsig.tools.persistence.PersistentState;
47
import org.gvsig.tools.persistence.exception.PersistenceException;
48
import org.gvsig.tools.task.Cancellable;
49
import org.gvsig.tools.visitor.VisitCanceledException;
50
import org.gvsig.tools.visitor.Visitor;
51

  
52
public class DefaultAggregateLegend extends AbstractVectorialLegend implements AggregateLegend {
53

  
54
    private static class Group {
55

  
56
//        private final Point pointGeo;
57
//        private final Rectangle2D rectangle;
58
        private Operation op;
59
        private final Point pointPixels;
60
        private final Ellipse2D circle;
61

  
62
        public Group(Point pointGeo, Point pointPixels, double size, Operation op) {
63
            this.op = op;
64
            this.op.reset();
65
//            this.pointGeo = pointGeo;
66
            this.pointPixels = pointPixels;
67
            double d2 = size * 2;
68
//            this.rectangle = new Rectangle2D.Double(pointPixels.getX() - distance, pointPixels.getY() - distance, d2, d2);
69
            this.circle = new Ellipse2D.Double(pointPixels.getX() - size, pointPixels.getY() - size, d2, d2);
70
        }
71

  
72
        public boolean contains(Point pointPixels) {
73
//            return this.rectangle.contains(pointPixels.getX(), pointPixels.getY());
74
          return this.circle.contains(pointPixels.getX(), pointPixels.getY());
75
        }
76

  
77
        public void add(Feature feature) {
78
            op.perform(feature);
79
        }
80
        
81
        public Operation getOperation() {
82
            return this.op;
83
        }
84
    }
85

  
86
    private static final Logger LOG = LoggerFactory.getLogger(DefaultAggregateLegend.class);
87

  
88
    private List<Group> groups;
89

  
90
    private int symbolSize; // Pixels
91
    private Color fillColor;
92
    private Color outlineColor;
93
    private Color textColor;
94
    private boolean showBounds;
95
    private Font font;
96

  
97
    private boolean useStyle;
98
    private ILabelStyle labelStyle;
99
    
100
    private Operation operation;
101
    
102
    private SimpleFillSymbol defaultSymbol;
103

  
104
    public DefaultAggregateLegend() {
105
        this.groups = null;
106
        
107
        this.useStyle = false;
108
        this.symbolSize = 30;
109
        this.fillColor = new Color(0xd0ffcccc, true); // Un rojo
110
        this.outlineColor = new Color(0xff5f60de, true); // un azul
111
        this.textColor = new Color(0xff000000, true); // negro
112
        this.showBounds = false;
113
        this.labelStyle = null;        
114
        this.font = UIManager.getFont("Label.font");
115
        this.operation = AggregateLegendLocator.getAggregateLegendManager().getDefaultOperation().clone();
116
        this.defaultSymbol = new SimpleFillSymbol();
117
        this.defaultSymbol.setOutline(new SimpleLineSymbol());
118
        this.defaultSymbol.getOutline().setLineColor(this.outlineColor);
119
        this.defaultSymbol.setFillColor(this.fillColor);
120
        
121
    }
122

  
123
    @Override
124
    protected String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
125
        if( this.operation.isAttributeRequiered() && this.operation.getAttributeName()!=null ) {
126
            return new String[]{
127
                this.operation.getAttributeName(),
128
                featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()
129
            };
130
        }
131
        return new String[]{
132
            featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()
133
        };
134
    }
135

  
136
    @Override
137
    public ISymbol getDefaultSymbol() {
138
        return this.defaultSymbol;
139
    }
140

  
141
    @Override
142
    public void setDefaultSymbol(ISymbol is) {
143
    }
144

  
145
    @Override
146
    public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException {
147
        return this.getDefaultSymbol();
148
    }
149

  
150
    @Override
151
    public int getShapeType() {
152
        return Geometry.TYPES.GEOMETRY;
153
    }
154

  
155
    @Override
156
    public void setShapeType(int i) {
157
    }
158

  
159
    @Override
160
    public boolean isUseDefaultSymbol() {
161
        return true;
162
    }
163

  
164
    @Override
165
    public void useDefaultSymbol(boolean bln) {
166
    }
167

  
168
    @Override
169
    public boolean isSuitableForShapeType(int shapeType) {
170
        return true;
171
    }
172

  
173
    @Override
174
    protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, Map queryParameters, ICoordTrans coordTrans, FeatureStore featureStore, FeatureQuery featureQuery, double dpi) throws LegendException {
175
        super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
176
        this.drawGroups(image, g, cancel, viewPort.getAffineTransform());
177
    }
178

  
179
    @Override
180
    protected void drawFeatures(
181
        BufferedImage image,
182
        Graphics2D g,
183
        final ViewPort viewPort,
184
        final Cancellable cancel,
185
        final ICoordTrans coordTrans,
186
        double dpi,
187
        DefaultFeatureDrawnNotification drawnNotification,
188
        FeatureSet featureSet,
189
        FeatureSelection selection
190
    ) throws BaseException {
191
        this.groups = new ArrayList<>();
192
        featureSet.accept(new Visitor() {
193
            @Override
194
            public void visit(Object o) throws VisitCanceledException, BaseException {
195
                if( cancel.isCanceled() ) {
196
                    throw new VisitCanceledException();
197
                }
198
                Feature feature = (Feature) o;
199
                Geometry geom = feature.getDefaultGeometry();
200
                if( geom != null ) {
201
                    Point pointGeo = geom.centroid();
202
                    if( coordTrans != null ) {
203
                        pointGeo.reProject(coordTrans);
204
                    }
205
                    Point pointPixels = (Point) pointGeo.cloneGeometry();
206
                    pointPixels.transform(viewPort.getAffineTransform());
207
                    boolean inGroup = false;
208
                    for( Group group : groups ) {
209
                        if( group.contains(pointPixels) ) {
210
                            group.add(feature);
211
                            inGroup = true;
212
                            break;
213
                        }
214
                    }
215
                    if( !inGroup ) {
216
                        Group group = new Group(pointGeo, pointPixels, getSymbolSize(), getOperation().clone());
217
                        group.add(feature);
218
                        groups.add(group);
219
                    }
220
                }
221
            }
222
        });
223
    }
224

  
225
    private void drawGroups(BufferedImage image, Graphics2D g, Cancellable cancel, AffineTransform affineTransform) {
226
        FilteredLogger logger = new FilteredLogger(LOG, "", 10);
227
        AffineTransform identity = new AffineTransform();
228
        
229
        g.setFont(this.font);
230
        FontMetrics fm = g.getFontMetrics();
231
        int fontAscent = fm.getAscent();
232
        int fontAscentAddDescentDiv2 = ((fm.getAscent() + fm.getDescent())) / 2;        
233

  
234
        for( Group group : groups ) {
235
            if( cancel.isCanceled() ) {
236
                return;
237
            }
238
            try {
239
                int x = (int) group.pointPixels.getX();
240
                int y = (int) group.pointPixels.getY();
241
                String txt = group.getOperation().format();
242
                if( this.useStyle && this.labelStyle != null ) {
243
                    Dimension size = this.labelStyle.getSize();
244
                    this.labelStyle.setTextFields(new String[]{txt});
245
                    g.setTransform(identity);
246
                    g.translate(x-size.getWidth()/2, y-size.getHeight()/2);
247
                    Rectangle rect = new Rectangle(
248
                        0,
249
                        0,
250
                        (int)size.getWidth(),
251
                        (int)size.getHeight());
252
                    this.labelStyle.drawInsideRectangle(g, rect);
253
                    Rectangle2D[] bounds = this.labelStyle.getTextBounds();
254
                    if(bounds.length>0){
255
                        Rectangle2D bound = bounds[0];
256
                        Rectangle2D expandedBound = new Rectangle2D.Double(
257
                            bound.getMinX()*size.getWidth(),
258
                            bound.getMinY()*size.getHeight(),
259
                            bound.getWidth()*size.getWidth(),
260
                            bound.getHeight()*size.getHeight());
261
                        drawCenteredString(txt, expandedBound, g);
262
                    }
263
                    g.translate(-(x-size.getWidth()/2), -(y-size.getHeight()/2));
264
                } else {
265
                    int r = symbolSize/2;
266
                    g.setColor(this.fillColor);
267
                    g.fillOval( x-r, y-r, 2*r, 2*r);
268
                    g.setColor(this.outlineColor);
269
                    g.drawOval( x-r, y-r, 2*r, 2*r);
270
                    if( this.showBounds ) {
271
                        g.drawRect( x-r, y-r, 2*r, 2*r);
272
                    }
273
                    g.setColor(this.textColor);
274
                    int txtX = x - (fm.stringWidth(txt) / 2);
275
                    int txtY = fontAscent + y - fontAscentAddDescentDiv2; //((fm.getAscent() + fm.getDescent())) / 2;
276
                    g.drawString(txt, txtX, txtY);
277
                }
278
            } catch (Exception ex) {
279
                logger.warn("Can't draw group",ex);
280
            }
281
        }
282
        this.groups.clear();
283
    }
284

  
285
    private void drawCenteredString(String s, Rectangle2D rect, Graphics2D g) {
286

  
287
        double x = rect.getMinX();
288
        double y = rect.getMinY();
289
        double w = rect.getWidth();
290
        double h = rect.getHeight();
291

  
292
        FontMetrics fm = g.getFontMetrics();
293
        int auxX = (int)(x+((w - fm.stringWidth(s)) / 2));
294
        int auxY = (int)(y+((fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2)));
295
        g.setColor(Color.BLACK);
296
        g.drawString(s, auxX, auxY);
297
      }
298

  
299
    @Override
300
    public ILabelStyle getLabelStyle() {
301
        return this.labelStyle;
302
    }
303

  
304
    @Override
305
    public void setLabelStyle(ILabelStyle labelStyle) {
306
        this.labelStyle = labelStyle;
307
    }
308

  
309
    @Override
310
    public int getSymbolSize() {
311
        return this.symbolSize;
312
    }
313

  
314
    @Override
315
    public void setSymbolSize(int simbolSize) {
316
        boolean changed = (this.symbolSize == simbolSize);
317
        this.symbolSize = simbolSize;
318
        if( changed ) {
319
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
320
        }
321
    }
322

  
323
    @Override
324
    public Operation getOperation() {
325
        return this.operation;
326
    }
327
    
328
    @Override
329
    public void setOperation(Operation operation) {
330
        boolean changed = (this.operation.getName().equalsIgnoreCase(operation.getName()));
331
        this.operation = operation;
332
        if( changed ) {
333
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
334
        }
335
    }
336

  
337
    @Override
338
    public Color getFillColor() {
339
        return fillColor;
340
    }
341

  
342
    @Override
343
    public void setFillColor(Color fillColor) {
344
        boolean changed = (this.fillColor.equals(fillColor));
345
        this.fillColor = fillColor;
346
        this.defaultSymbol.setFillColor(this.fillColor);
347
        if( changed ) {
348
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
349
        }
350
    }
351

  
352
    @Override
353
    public Color getOutlineColor() {
354
        return outlineColor;
355
    }
356

  
357
    @Override
358
    public void setOutlineColor(Color outlineColor) {
359
        boolean changed = (this.outlineColor.equals(outlineColor));
360
        this.outlineColor = outlineColor;
361
        this.defaultSymbol.getOutline().setLineColor(this.outlineColor);
362
        if( changed ) {
363
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
364
        }
365
    }
366

  
367
    @Override
368
    public boolean isShowBounds() {
369
        return showBounds;
370
    }
371

  
372
    @Override
373
    public void setShowBounds(boolean showBounds) {
374
        boolean changed = (this.showBounds == showBounds);
375
        this.showBounds = showBounds;
376
        if( changed ) {
377
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
378
        }
379
    }
380

  
381
    @Override
382
    public Font getFont() {
383
        return font;
384
    }
385

  
386
    @Override
387
    public void setFont(Font font) {
388
        this.font = font;
389
        this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
390
    }
391

  
392
    @Override
393
    public boolean isUseStyle() {
394
        return useStyle;
395
    }
396

  
397
    @Override
398
    public void setUseStyle(boolean useStyle) {
399
        boolean changed = (this.useStyle == useStyle);
400
        this.useStyle = useStyle;
401
        if( changed ) {
402
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
403
        }
404
    }
405

  
406
    @Override
407
    public Color getTextColor() {
408
        return this.textColor;
409
    }
410

  
411
    @Override
412
    public void setTextColor(Color textColor) {
413
        boolean changed = (this.textColor.equals(textColor));
414
        this.textColor = textColor;
415
        if( changed ) {
416
            this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
417
        }
418
    }
419

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

  
434
    @Override
435
    public void saveToState(PersistentState state) throws PersistenceException {
436
        super.saveToState(state);
437
        state.set("symbolSize", symbolSize);
438
        state.set("fillColor", fillColor);
439
        state.set("outlineColor", outlineColor);
440
        state.set("textColor", textColor);
441
        state.set("showBounds", showBounds);
442
        state.set("font", font);
443
        state.set("useStyle", useStyle);
444
        state.set("labelStyle", labelStyle);
445
        state.set("operation", operation);
446
    }
447
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/AggregateLegendLibraryImpl.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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 2
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

  
25
package org.gvsig.legend.aggregate.lib.impl;
26

  
27
import org.gvsig.fmap.mapcontext.MapContextLibrary;
28
import org.gvsig.fmap.mapcontext.MapContextLocator;
29
import org.gvsig.fmap.mapcontext.MapContextManager;
30
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLibrary;
31
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator;
32
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.library.AbstractLibrary;
35
import org.gvsig.tools.library.LibraryException;
36
import org.gvsig.tools.persistence.PersistenceManager;
37

  
38
public class AggregateLegendLibraryImpl extends AbstractLibrary {
39

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

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

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

  
55
    @Override
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
        );
64
    }
65

  
66
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/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/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/CountOperation.java
1
package org.gvsig.legend.aggregate.lib.impl.operation;
2

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

  
6

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

  
14
    @Override
15
    public void reset() {
16
        count = 0;
17
    }
18
    
19
    @Override
20
    public void perform(Feature feature) {
21
        count++;
22
    }
23

  
24
    @Override
25
    public Object getValue() {
26
        return count;
27
    }
28
    
29
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/AvgOperation.java
1
package org.gvsig.legend.aggregate.lib.impl.operation;
2

  
3
import java.text.MessageFormat;
4
import org.apache.commons.lang3.StringUtils;
5
import org.gvsig.fmap.dal.feature.Feature;
6
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
7

  
8
public class AvgOperation extends AbstractOperation {
9

  
10
    private double avg = 0;
11
    private int count = 0;
12

  
13
    public AvgOperation() {
14
        super(
15
            "Average", 
16
            "_Calculate_the_average_of_the_selected_attribute_for_the_grouped_features"
17
        );
18
    }
19

  
20
    @Override
21
    public boolean isAttributeRequiered() {
22
        return true;
23
    }
24

  
25
    @Override
26
    public boolean isAditionalValueRequiered() {
27
        return true;
28
    }
29

  
30
    @Override
31
    public void reset() {
32
        avg = 0;
33
        count = 0;
34
    }
35

  
36
    @Override
37
    public void perform(Feature feature) {
38
            try {
39
                double value = feature.getDouble(this.getAttributeName());
40
                avg = ( avg * count + value ) / (count+1);
41
                count++;
42
            } catch(Exception ex) {
43
            }
44
    }
45

  
46
    @Override
47
    public Object getValue() {
48
        return this.avg;
49
    }
50

  
51
    @Override
52
    public String format() {
53
        if( StringUtils.isEmpty(this.getAditionalValue()) ) {
54
            return super.format(); 
55
        }
56
        try {
57
            return MessageFormat.format("{0,number,"+this.getAditionalValue()+"}", this.getValue());
58
        } catch(Exception ex) {
59
            return super.format(); 
60
        }
61
    }
62
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/MinOperation.java
1
package org.gvsig.legend.aggregate.lib.impl.operation;
2

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

  
6
public class MinOperation extends AbstractOperation {
7

  
8
    private int min = 0;
9

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

  
14
    @Override
15
    public boolean isAttributeRequiered() {
16
        return true;
17
    }
18

  
19
    @Override
20
    public void reset() {
21
        min = 0;
22
    }
23

  
24
    @Override
25
    public void perform(Feature feature) {
26
        try {
27
            int x = feature.getInt(this.getAttributeName());
28
            if( x > min ) {
29
                min = x;
30
            }
31
        } catch (Exception ex) {
32
        }
33
    }
34

  
35
    @Override
36
    public Object getValue() {
37
        return this.min;
38
    }
39

  
40
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/SumOperation.java
1
package org.gvsig.legend.aggregate.lib.impl.operation;
2

  
3
import java.text.MessageFormat;
4
import org.apache.commons.lang3.StringUtils;
5
import org.gvsig.fmap.dal.feature.Feature;
6
import org.gvsig.legend.aggregate.lib.spi.AbstractOperation;
7

  
8

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

  
15
    }
16

  
17
    @Override
18
    public boolean isAttributeRequiered() {
19
        return true;
20
    }
21

  
22
    @Override
23
    public boolean isAditionalValueRequiered() {
24
        return true;
25
    }
26
    
27
    @Override
28
    public void reset() {
29
        sum = 0;
30
    }
31
    
32
    @Override
33
    public void perform(Feature feature) {
34
        try {
35
            double x = feature.getDouble(this.getAttributeName());
36
            sum += x;
37
        } catch (Exception ex) {
38
        }
39
    }
40

  
41
    @Override
42
    public Object getValue() {
43
        return sum;
44
    }
45

  
46
    @Override
47
    public String format() {
48
        if( StringUtils.isEmpty(this.getAditionalValue()) ) {
49
            return super.format(); 
50
        }
51
        try {
52
            return MessageFormat.format("{0,number,"+this.getAditionalValue().trim()+"}", this.getValue());
53
        } catch(Exception ex) {
54
            return super.format(); 
55
        }
56
    }    
57
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/operation/MaxOperation.java
1
package org.gvsig.legend.aggregate.lib.impl.operation;
2

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

  
6
public class MaxOperation extends AbstractOperation {
7

  
8
    private int max = 0;
9

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

  
14
    @Override
15
    public boolean isAttributeRequiered() {
16
        return true;
17
    }
18

  
19
    @Override
20
    public void reset() {
21
        max = 0;
22
    }
23

  
24
    @Override
25
    public void perform(Feature feature) {
26
        try {
27
            int x = feature.getInt(this.getAttributeName());
28
            if( x > max ) {
29
                max = x;
30
            }
31
        } catch (Exception ex) {
32
        }
33
    }
34

  
35
    @Override
36
    public Object getValue() {
37
        return this.max;
38
    }
39
}
org.gvsig.legend.aggregate/tags/org.gvsig.legend.aggregate-1.0.187/org.gvsig.legend.aggregate.lib/org.gvsig.legend.aggregate.lib.impl/src/main/java/org/gvsig/legend/aggregate/lib/impl/DefaultAggregateLegendManager.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 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.legend.aggregate.lib.impl;
24

  
25
import java.util.Collection;
26
import java.util.HashMap;
27
import java.util.Map;
28
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle;
29
import org.gvsig.legend.aggregate.lib.api.AggregateLegend;
30
import org.gvsig.legend.aggregate.lib.api.AggregateLegendManager;
31
import org.gvsig.legend.aggregate.lib.api.Operation;
32
import org.gvsig.legend.aggregate.lib.impl.operation.AvgOperation;
33
import org.gvsig.legend.aggregate.lib.impl.operation.CountOperation;
34
import org.gvsig.legend.aggregate.lib.impl.operation.MaxOperation;
35
import org.gvsig.legend.aggregate.lib.impl.operation.MinOperation;
36
import org.gvsig.legend.aggregate.lib.impl.operation.SumOperation;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLabelStyle;
38

  
39

  
40
public class DefaultAggregateLegendManager implements AggregateLegendManager {
41

  
42
    private ILabelStyle defaultLabelStyle = null;
43
    private Map<String,Operation> operations;
44
    private Operation defaultOperation = null;
45
    
46
    public DefaultAggregateLegendManager() {
47
        this.defaultLabelStyle = new SimpleLabelStyle();
48
        this.addOperation(new CountOperation());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff