Revision 2270

View differences:

org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/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.heatmap</artifactId>
5
  <version>1.0.14</version>
6
  <packaging>pom</packaging>
7
  <name>${project.artifactId}</name>
8
  <description>Legend for heat maps.</description>
9
  <parent>
10
    <groupId>org.gvsig</groupId>
11
    <artifactId>org.gvsig.desktop</artifactId>
12
    <version>2.0.218</version>
13
  </parent>
14

  
15
  <url>https://devel.gvsig.org/sites/org.gvsig.legend.heatmap/${project.version}</url>
16
  <scm>
17
    <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14</connection>
18
    <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14</developerConnection>
19
    <url>https://devel.gvsig.org/redmine/projects/gvsig-base-legends/repository/show/org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14</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.heatmap/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.heatmap.lib.api</artifactId>
65
        <version>1.0.14</version>
66
      </dependency>
67
      <dependency>
68
        <groupId>org.gvsig</groupId>
69
        <artifactId>org.gvsig.legend.heatmap.lib.impl</artifactId>
70
        <version>1.0.14</version>
71
      </dependency>
72
      <dependency>
73
        <groupId>org.gvsig</groupId>
74
        <artifactId>org.gvsig.legend.heatmap.swing.api</artifactId>
75
        <version>1.0.14</version>
76
      </dependency>
77
      <dependency>
78
        <groupId>org.gvsig</groupId>
79
        <artifactId>org.gvsig.legend.heatmap.swing.impl</artifactId>
80
        <version>1.0.14</version>
81
      </dependency>
82
      <dependency>
83
        <groupId>org.gvsig</groupId>
84
        <artifactId>org.gvsig.legend.heatmap.app.mainplugin</artifactId>
85
        <version>1.0.14</version>
86
      </dependency>
87
    </dependencies>
88
  </dependencyManagement>
89
  <modules>
90
    <module>org.gvsig.legend.heatmap.lib</module>
91
    <module>org.gvsig.legend.heatmap.swing</module>
92
    <module>org.gvsig.legend.heatmap.app</module>
93
  </modules>
94
</project>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/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.heatmap</artifactId>
6
    <version>1.0.14</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.heatmap.app</artifactId>
10
  <packaging>pom</packaging>
11
  <name>org.gvsig.legend.heatmap.app</name>
12

  
13
  <modules>
14
    <module>org.gvsig.legend.heatmap.app.mainplugin</module>
15
  </modules>
16

  
17
</project>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/java/org/gvsig/legend/heatmap/app/HeatmapLegendExtension.java
1

  
2
package org.gvsig.legend.heatmap.app;
3

  
4
import org.gvsig.andami.IconThemeHelper;
5
import org.gvsig.andami.plugins.Extension;
6

  
7

  
8
public class HeatmapLegendExtension extends Extension {
9

  
10
    @Override
11
    public void initialize() {
12
        IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-heatmap", this);
13
    }
14

  
15
    @Override
16
    public void execute(String string) {
17
    }
18

  
19
    @Override
20
    public boolean isEnabled() {
21
        return true;
22
    }
23

  
24
    @Override
25
    public boolean isVisible() {
26
        return true;
27
    }
28
    
29
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/resources-plugin/plugin-persistence.def
1
<?xml version="1.0"?>
2
<!--
3
Definitions of plugin persistence org.gvsig.aggregatelegend.app.mainplugin
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    <class name="org.gvsig.legend.aggregate.app.mainplugin">
9
      <extends>
10
      </extends>
11
      <description>Persistence of the legend of aggregate texts</description>
12
      <fields>
13
      </fields>
14
    </class>
15
  </classes>
16
</definitions>  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
_Heatmap_legend_description=Mapa de calor que representa la densidad de puntos en un mapa.
2
_Heatmap_legend=Mapa de calor
3
_Distance=Distancia
4
pixels=pixels
5
_Use_color_ramp=Usar un gradiente de color
6
_Number_of_colors=Numero de colores
7
_Hot_color=Color caliente
8
Alpha=Alpha
9
_Cold_color=Color frio
10
_Use_color_table=Usar tabla de color
11
_Color_table=Tabla de color
12
_Use_transparency=Usar transparencia
13
_Hot_color_transparency=Transparencia del color caliente
14
_Cold_color_transparency=Transparencia del color frio
15
_Use_a_field_to_weight_the_heat_map=Usar un campo para ponderar el mapa de calor
16

  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
_Heatmap_legend_description=heat map for representing the density of dots in a map.
2
_Heatmap_legend=heat map
3
_Distance=Distance
4
pixels=pixels
5
_Use_color_ramp=Use a color ramp
6
_Number_of_colors=Number of colors
7
_Hot_color=Hot color
8
Alpha=Alpha
9
_Cold_color=Cold color
10
_Use_color_table=Use a color table
11
_Color_table=Color table
12
_Use_transparency=Use transparencia
13
_Hot_color_transparency=Hot color transparency
14
_Cold_color_transparency=Cold color transparency
15
_Use_a_field_to_weight_the_heat_map=Use a field to weight the heat map
16

  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG
3
  Association. This program is free software; you can redistribute it and/or modify
4
  it under the terms of the GNU General Public License as published by the Free Software
5
  Foundation; either version 3 of the License, or (at your option) any later version.
6
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
  PURPOSE. See the GNU General Public License for more details. You should have received
9
  a copy of the GNU General Public License along with this program; if not, write to
10
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
11
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
12
  or visit our website www.gvsig.com. -->
13
<plugin-config>
14
  <depends plugin-name="org.gvsig.app.mainplugin" />
15
  <resourceBundle name="text" />
16
  <libraries library-dir="lib" />
17
  <extensions>
18
    <extension class-name="org.gvsig.legend.heatmap.app.HeatmapLegendExtension"
19
      description="" active="true" priority="1">
20

  
21
    </extension>
22

  
23
  </extensions>
24
</plugin-config>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<!-- gvSIG. Desktop Geographic Information System. Copyright (C) 2007-2013 gvSIG
2
  Association. This program is free software; you can redistribute it and/or modify
3
  it under the terms of the GNU General Public License as published by the Free Software
4
  Foundation; either version 3 of the License, or (at your option) any later version.
5
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
6
  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7
  PURPOSE. See the GNU General Public License for more details. You should have received
8
  a copy of the GNU General Public License along with this program; if not, write to
9
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
10
  USA. For any additional information, do not hesitate to contact us at info AT gvsig.com,
11
  or visit our website www.gvsig.com. -->
12
<assembly>
13
  <id>gvsig-plugin-package</id>
14
  <formats>
15
    <format>zip</format>
16
  </formats>
17
  <baseDirectory>${project.artifactId}</baseDirectory>
18
  <includeBaseDirectory>true</includeBaseDirectory>
19
  <files>
20
    <file>
21
      <source>target/${project.artifactId}-${project.version}.jar</source>
22
      <outputDirectory>lib</outputDirectory>
23
    </file>
24
    <file>
25
      <source>target/package.info</source>
26
    </file>
27
  </files>
28

  
29
  <fileSets>
30
    <fileSet>
31
      <directory>src/main/resources-plugin</directory>
32
      <outputDirectory>.</outputDirectory>
33
    </fileSet>
34
  </fileSets>
35

  
36

  
37
  <dependencySets>
38
    <dependencySet>
39
      <useProjectArtifact>false</useProjectArtifact>
40
      <useTransitiveDependencies>false</useTransitiveDependencies>
41
      <outputDirectory>lib</outputDirectory>
42
      <includes>
43
        <include>org.gvsig:org.gvsig.legend.heatmap.lib.api</include>
44
        <include>org.gvsig:org.gvsig.legend.heatmap.lib.impl</include>
45
        <include>org.gvsig:org.gvsig.legend.heatmap.swing.api</include>
46
        <include>org.gvsig:org.gvsig.legend.heatmap.swing.impl</include>
47
      </includes>
48
    </dependencySet>
49
  </dependencySets>
50

  
51
</assembly>
52

  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/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.heatmap.app</artifactId>
6
    <version>1.0.14</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.heatmap.app.mainplugin</artifactId>
10
  <version>1.0.14</version>
11
  <name>org.gvsig.legend.heatmap.app.mainplugin</name>
12

  
13
    <properties>
14
    <!-- Package info property values -->
15
    <gvsig.package.info.state>testing</gvsig.package.info.state>
16
    <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.4.0-A</gvsig.package.info.dependencies>
17
    <gvsig.package.info.official>true</gvsig.package.info.official>
18
    <gvsig.package.info.name>Vector legend: heat map</gvsig.package.info.name>
19
    <gvsig.package.info.description>Legend for aggregate text symbols that are near.</gvsig.package.info.description>
20
    <gvsig.package.info.categories>View,Vector,Symbology</gvsig.package.info.categories>
21
    <gvsig.package.info.javaVM>j1_7</gvsig.package.info.javaVM>
22
    <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-base-legends/pool</gvsig.package.info.poolURL>
23
  </properties>
24

  
25
  <dependencies>
26
    <dependency>
27
      <groupId>org.gvsig</groupId>
28
      <artifactId>org.gvsig.andami</artifactId>
29
      <scope>compile</scope>
30
    </dependency>
31
    <dependency>
32
      <groupId>org.gvsig</groupId>
33
      <artifactId>org.gvsig.legend.heatmap.swing.api</artifactId>
34
      <scope>compile</scope>
35
    </dependency>
36
    <dependency>
37
      <groupId>org.gvsig</groupId>
38
      <artifactId>org.gvsig.legend.heatmap.lib.api</artifactId>
39
      <scope>compile</scope>
40
    </dependency>
41
    <dependency>
42
      <groupId>org.gvsig</groupId>
43
      <artifactId>org.gvsig.legend.heatmap.lib.impl</artifactId>
44
      <scope>runtime</scope>
45
    </dependency>
46
    <dependency>
47
      <groupId>org.gvsig</groupId>
48
      <artifactId>org.gvsig.legend.heatmap.swing.impl</artifactId>
49
      <scope>runtime</scope>
50
    </dependency>
51
    <dependency>
52
      <groupId>org.gvsig</groupId>
53
      <artifactId>org.gvsig.app.mainplugin</artifactId>
54
      <scope>compile</scope>
55
    </dependency>
56
  </dependencies>
57
</project>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.app/org.gvsig.legend.heatmap.app.mainplugin/buildNumber.properties
1
#Sun Mar 04 14:19:55 CET 2018
2
buildNumber=17
0 3

  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.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.heatmap</artifactId>
6
    <version>1.0.14</version>
7
  </parent>
8
  <groupId>org.gvsig</groupId>
9
  <artifactId>org.gvsig.legend.heatmap.lib</artifactId>
10
  <packaging>pom</packaging>
11
  <modules>
12
    <module>org.gvsig.legend.heatmap.lib.api</module>
13
    <module>org.gvsig.legend.heatmap.lib.impl</module>
14
  </modules>
15
</project>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendManager.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.heatmap.lib.api;
24

  
25

  
26
public interface HeatmapLegendManager {
27

  
28
    /**
29
     * Creates an aggregate legend
30
     *
31
     * @return the aggregate legend
32
     */
33
    public HeatmapLegend create();
34

  
35
    public Class<? extends HeatmapLegend> getLegendClass();
36
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegend.java
1
package org.gvsig.legend.heatmap.lib.api;
2

  
3
import java.awt.Color;
4
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
5

  
6
public interface HeatmapLegend extends IVectorLegend {
7

  
8
    public int getDistance();
9

  
10
    public void setDistance(int distance);
11

  
12
    public void setColorTable(Color[] colorTable);
13

  
14
    public void setColorTable(int numColors, Color coldColor, Color hotColor);
15

  
16
    public Color[] getSourceColorTable();
17

  
18
    public Color[] getTargetColorTable();
19

  
20
    public boolean useRamp();
21

  
22
    public String getFieldName();
23

  
24
    public void setFieldName(String fieldName);
25

  
26
    public int getColorTableHotColorAlpha();
27

  
28
    public void setColorTableHotColorAlpha(int colorTableHotColorAlpha);
29

  
30
    public int getColorTableColdColorAlpha();
31

  
32
    public void setColorTableColdColorAlpha(int colorTableColdColorAlpha);
33

  
34
    public boolean useAlphaInColorTable();
35

  
36
    public boolean setUseAlphaInColorTable(boolean use);
37

  
38
    public int getRampNumColors();
39

  
40
    public Color getRampColdColor();
41

  
42
    public Color getRampHotColor();
43

  
44
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendLocator.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.heatmap.lib.api;
24

  
25
import org.gvsig.tools.locator.AbstractLocator;
26
import org.gvsig.tools.locator.Locator;
27
import org.gvsig.tools.locator.LocatorException;
28

  
29

  
30
public class HeatmapLegendLocator extends AbstractLocator {
31

  
32
    /**
33
     * HeatmapLegend locator name
34
     */
35
    private static final String LOCATOR_NAME = "HeatmapLegendLocator";
36

  
37
    /**
38
     * HeatmapLegend manager name
39
     */
40
    public static final String MANAGER_NAME = "HeatmapLegendManager";
41

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

  
48

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

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

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

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

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

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

  
99
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendLibrary.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.heatmap.lib.api;
24

  
25
import org.gvsig.fmap.mapcontext.MapContextLocator;
26
import org.gvsig.fmap.mapcontext.MapContextManager;
27
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
28
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
29
import org.gvsig.symbology.SymbologyLocator;
30
import org.gvsig.symbology.SymbologyManager;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
34

  
35

  
36
public class HeatmapLegendLibrary extends AbstractLibrary {
37

  
38
    @Override
39
    protected void doInitialize() throws LibraryException {
40
        registerAsAPI(HeatmapLegendLibrary.class);
41
    }
42

  
43
    @Override
44
    protected void doPostInitialize() throws LibraryException {
45
        // Validate there is any implementation registered.
46
        HeatmapLegendManager manager = HeatmapLegendLocator.getHeatmapLegendManager();
47
        if (manager == null) {
48
            throw new ReferenceNotRegisteredException(
49
                HeatmapLegendLocator.MANAGER_NAME, HeatmapLegendLocator.getInstance());
50
        }
51

  
52
        SymbologyManager symbolManager = SymbologyLocator.getSymbologyManager();
53
        ILegendWriter legendWriter = symbolManager.getDefaultLegendWriter();
54

  
55
        MapContextManager mcoman = MapContextLocator.getMapContextManager();
56
        mcoman.registerLegendWriter(
57
            HeatmapLegend.class,
58
            SymbolManager.LEGEND_FILE_EXTENSION.substring(1),
59
            legendWriter.getClass());
60
    }
61

  
62
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.legend.heatmap.lib.api.HeatmapLegendLibrary
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.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.heatmap.lib.api</artifactId>
5
  <name>org.gvsig.legend.heatmap.lib.api</name>
6
  <parent>
7
    <groupId>org.gvsig</groupId>
8
    <artifactId>org.gvsig.legend.heatmap.lib</artifactId>
9
    <version>1.0.14</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
    <dependency>
43
      <groupId>org.gvsig</groupId>
44
      <artifactId>org.gvsig.symbology.lib.api</artifactId>
45
    </dependency>
46
  </dependencies>
47
</project>
0 48

  
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/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
  <artifactId>org.gvsig.legend.heatmap.lib.impl</artifactId>
4
  <name>org.gvsig.legend.heatmap.lib.impl</name>
5
  <parent>
6
    <groupId>org.gvsig</groupId>
7
    <artifactId>org.gvsig.legend.heatmap.lib</artifactId>
8
    <version>1.0.14</version>
9
  </parent>
10
  <groupId>org.gvsig</groupId>
11
  <dependencies>
12
    <dependency>
13
      <groupId>org.gvsig</groupId>
14
      <artifactId>org.gvsig.legend.heatmap.lib.api</artifactId>
15
      <scope>compile</scope>
16
    </dependency>
17
    <dependency>
18
      <groupId>org.gvsig</groupId>
19
      <artifactId>org.gvsig.fmap.dal.api</artifactId>
20
      <scope>compile</scope>
21
    </dependency>
22
    <dependency>
23
      <groupId>org.gvsig</groupId>
24
      <artifactId>org.gvsig.symbology.lib.impl</artifactId>
25
      <scope>compile</scope>
26
    </dependency>
27
    <dependency>
28
      <groupId>org.gvsig</groupId>
29
      <artifactId>org.gvsig.ui</artifactId>
30
      <scope>compile</scope>
31
    </dependency>
32
  </dependencies>
33
</project>
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegendManager.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.heatmap.lib.impl;
24

  
25
import org.gvsig.legend.heatmap.lib.api.HeatmapLegend;
26
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendManager;
27

  
28

  
29
public class DefaultHeatmapLegendManager implements HeatmapLegendManager {
30

  
31
    @Override
32
    public HeatmapLegend create() {
33
        return new DefaultHeatmapLegend();
34
    }
35

  
36
    @Override
37
    public Class<? extends HeatmapLegend> getLegendClass() {
38
        return DefaultHeatmapLegend.class;
39
    }
40

  
41
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.java
1
package org.gvsig.legend.heatmap.lib.impl;
2

  
3
import java.awt.Color;
4
import java.awt.Graphics2D;
5
import java.awt.Image;
6
import java.awt.image.BufferedImage;
7
import java.util.Map;
8

  
9
import org.apache.commons.lang3.StringUtils;
10
import org.cresques.cts.ICoordTrans;
11
import org.gvsig.compat.print.PrintAttributes;
12

  
13
import org.gvsig.fmap.dal.exception.DataException;
14
import org.gvsig.fmap.dal.feature.Feature;
15
import org.gvsig.fmap.dal.feature.FeatureQuery;
16
import org.gvsig.fmap.dal.feature.FeatureSelection;
17
import org.gvsig.fmap.dal.feature.FeatureSet;
18
import org.gvsig.fmap.dal.feature.FeatureStore;
19
import org.gvsig.fmap.dal.feature.FeatureType;
20
import org.gvsig.fmap.geom.Geometry;
21
import org.gvsig.fmap.geom.primitive.Point;
22
import org.gvsig.fmap.mapcontext.MapContextException;
23
import org.gvsig.fmap.mapcontext.ViewPort;
24
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
25
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
26
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
27
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
28
import org.gvsig.gui.ColorTablePainter;
29
import org.gvsig.gui.DefaultColorTablePainter;
30
import org.gvsig.legend.heatmap.lib.api.HeatmapLegend;
31
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
32
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.DefaultFeatureDrawnNotification;
33
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
34
import org.gvsig.tools.exception.BaseException;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37
import org.gvsig.tools.swing.api.ToolsSwingLocator;
38
import org.gvsig.tools.swing.api.ToolsSwingManager;
39
import org.gvsig.tools.task.Cancellable;
40
import org.gvsig.tools.visitor.VisitCanceledException;
41
import org.gvsig.tools.visitor.Visitor;
42

  
43
public class DefaultHeatmapLegend extends AbstractVectorialLegend implements HeatmapLegend, IHasImageLegend {
44

  
45
    private class DensityAlgorithm {
46

  
47
        private double[][] grid;
48
        private double[][] kernel;
49
        private int distance;
50
        private int height;
51
        private int with;
52
        private double maxValue;
53
        private double minValue;
54

  
55
        public DensityAlgorithm(int distance) {
56
            this.setDistance(distance);
57
        }
58

  
59
        public void setDistance(int distance) {
60
            if( this.distance == distance ) {
61
                return;
62
            }
63
            this.distance = distance;
64
            this.kernel = new double[2 * this.distance + 1][2 * this.distance + 1];
65
            for( int y = -this.distance; y < this.distance + 1; y++ ) {
66
                for( int x = -this.distance; x < this.distance + 1; x++ ) {
67
                    final double dDist = Math.sqrt(x * x + y * y);
68
                    if( dDist < this.distance ) {
69
                        this.kernel[x + this.distance][y + this.distance] = Math.pow(1 - (dDist * dDist) / (this.distance * this.distance), 2);
70
                    } else {
71
                        this.kernel[x + this.distance][y + this.distance] = 0;
72
                    }
73
                }
74
            }
75
        }
76

  
77
        public int getDistance() {
78
            return this.distance;
79
        }
80

  
81
        public void init(int with, int height) {
82
            this.with = with;
83
            this.height = height;
84
            this.grid = new double[with][height];
85
            this.maxValue = 0;
86
            this.minValue = 0;
87
        }
88

  
89
        public void add(int px, int py) {
90
            add(px, py, 1);
91
        }
92

  
93
        public void add(int px, int py, double value) {
94
            for( int y = -this.distance; y < this.distance + 1; y++ ) {
95
                for( int x = -this.distance; x < this.distance + 1; x++ ) {
96
                    if( this.kernel[x + this.distance][y + this.distance] != 0 ) {
97
                        addValue(px + x, py + y, value * this.kernel[x + this.distance][y + this.distance]);
98
                    }
99
                }
100
            }
101
        }
102

  
103
        private void addValue(int px, int py, double value) {
104
            if( px < 0 || py < 0 || px >= with || py >= height ) {
105
                return;
106
            }
107
            value += this.grid[px][py];
108
            this.grid[px][py] = value;
109
            if( value > this.maxValue ) {
110
                this.maxValue = value;
111
            }
112
            if( value < this.minValue ) {
113
                this.minValue = value;
114
            }
115
        }
116

  
117
        public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
118
            try {
119
                ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
120
                Color c;
121
                int maxIndexColor = colorTable.length-1;
122
                for( int x = 0; x < with; x++ ) {
123
                    for( int y = 0; y < height; y++ ) {
124
                        if( cancel.isCanceled() ) {
125
                            return;
126
                        }
127
                        double value = this.grid[x][y];
128
                        if( value > 0 ) {
129
                            int icolor = (int) (value * maxIndexColor / maxValue);
130
                            c = toolsSwingManager.alphaBlendingWithOpaqueBackground(
131
                                    new Color(img.getRGB(x, y)),
132
                                    colorTable[icolor]
133
                            );
134
                            img.setRGB(x, y, c.getRGB());
135
                        }
136
                    }
137
                }
138
            } catch (Exception ex) {
139
                LOG.warn("Problems drawing heatmap", ex);
140
            }
141
        }
142

  
143
        public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
144
            try {
145
                Color c;
146
                int maxIndexColor = colorTable.length-1;
147
                for( int x = 0; x < with; x++ ) {
148
                    for( int y = 0; y < height; y++ ) {
149
                        if( cancel.isCanceled() ) {
150
                            return;
151
                        }
152
                        double value = this.grid[x][y];
153
                        if( value > 0 ) {
154
                            int icolor = (int) (value * maxIndexColor / maxValue);
155
                            c = colorTable[icolor];
156
                            img.setRGB(x, y, c.getRGB());
157
                        }
158
                    }
159
                }
160
            } catch (Exception ex) {
161
                LOG.warn("Problems drawing heatmap", ex);
162
            }
163
        }
164
    }
165

  
166
    private ISymbol defaultSymbol;
167
    private DensityAlgorithm algorithm;
168
    private boolean isRamp;
169
    private Color[] sourceColorTable;
170
    private int colorTableHotColorAlpha;
171
    private int colorTableColdColorAlpha;
172
    private boolean useAlphaInColorTable;
173
    private String fieldName;
174
    private Image imageLegend;
175
    private HeatmapColorTable hmColorTable;
176
    private Color rampColdColor;
177
    private Color rampHotColor;
178
    private int rampNumColors;
179

  
180
    public DefaultHeatmapLegend() {
181
        this.defaultSymbol = new SimpleTextSymbol();
182
        this.algorithm = new DensityAlgorithm(30);
183
        this.colorTableHotColorAlpha = 255;
184
        this.colorTableColdColorAlpha = 0;
185
        this.useAlphaInColorTable = false;
186
        this.setColorTable(100, new Color(0, 0, 255, 0), new Color(255, 0, 0, 255));
187
        this.imageLegend = null;
188
        this.hmColorTable = null;
189
        this.fieldName = null;
190
    }
191

  
192
    @Override
193
    protected String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
194
        FeatureType ftype = featureStore.getDefaultFeatureType();
195
        if( StringUtils.isEmpty(this.fieldName) ) {
196
            return new String[]{
197
                ftype.getDefaultGeometryAttributeName()
198
            };
199
        }
200
        return new String[]{
201
            ftype.getDefaultGeometryAttributeName(),
202
            this.fieldName
203
        };
204
    }
205

  
206
    @Override
207
    public ISymbol getDefaultSymbol() {
208
        return this.defaultSymbol;
209
    }
210

  
211
    @Override
212
    public void setDefaultSymbol(ISymbol is) {
213
    }
214

  
215
    @Override
216
    public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException {
217
        return this.defaultSymbol;
218
    }
219

  
220
    @Override
221
    public int getShapeType() {
222
        return Geometry.TYPES.GEOMETRY;
223
    }
224

  
225
    @Override
226
    public void setShapeType(int i) {
227
    }
228

  
229
    @Override
230
    public boolean isUseDefaultSymbol() {
231
        return true;
232
    }
233

  
234
    @Override
235
    public void useDefaultSymbol(boolean bln) {
236
    }
237

  
238
    @Override
239
    public boolean isSuitableForShapeType(int shapeType) {
240
        return true;
241
    }
242

  
243
    @Override
244
    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 {
245
        int saved_distance = this.algorithm.getDistance();
246
        try {
247
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
248
            this.algorithm.setDistance(distance);
249
            this.algorithm.init(image.getWidth(), image.getHeight());
250
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
251
            if( !cancel.isCanceled() ) {
252
                this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
253
            }
254
        } finally {
255
            this.algorithm.setDistance(saved_distance);
256

  
257
        }
258
    }
259
    
260
    @Override
261
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
262
            double scale, Map queryParameters, ICoordTrans coordTrans,
263
            FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
264
            throws LegendException {
265
        int saved_distance = this.algorithm.getDistance();
266
        try {
267
            double dpi = viewPort.getDPI();
268
            // Ver CartographicSupportToolkit.getCartographicLength
269
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
270
            
271
            this.algorithm.setDistance(distance);
272
            this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight());
273
            BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
274
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
275
            if (!cancel.isCanceled()) {
276
                this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
277
                g.drawImage(image, 0, 0, null);
278
            }
279
        } finally {
280
            this.algorithm.setDistance(saved_distance);
281

  
282
        }
283
    }
284

  
285
    @Override
286
    protected void drawFeatures(
287
        BufferedImage image,
288
        Graphics2D g,
289
        final ViewPort viewPort,
290
        final Cancellable cancel,
291
        final ICoordTrans coordTrans,
292
        double dpi,
293
        DefaultFeatureDrawnNotification drawnNotification,
294
        FeatureSet featureSet,
295
        FeatureSelection selection
296
    ) throws BaseException {
297
        int x = -1;
298
        if( !StringUtils.isEmpty(this.fieldName) ) {
299
            x = featureSet.getDefaultFeatureType().getIndex(this.fieldName);
300
        }
301
        final int n = x;
302
        featureSet.accept(new Visitor() {
303
            @Override
304
            public void visit(Object o) throws VisitCanceledException, BaseException {
305
                if( cancel.isCanceled() ) {
306
                    throw new VisitCanceledException();
307
                }
308
                Feature feature = (Feature) o;
309
                Geometry geom = feature.getDefaultGeometry();
310
                if( geom != null ) {
311
                    Point pointGeo = geom.centroid();
312
                    if( coordTrans != null ) {
313
                        pointGeo.reProject(coordTrans);
314
                    }
315
                    Point pointPixels = (Point) pointGeo.cloneGeometry();
316
                    pointPixels.transform(viewPort.getAffineTransform());
317
                    if( n >= 0 ) {
318
                        double value = 0;
319
                        try {
320
                            value = feature.getDouble(n);
321
                        } catch(Exception ex) {
322
                        }
323
                        if( value >0 ) {
324
                            algorithm.add((int) pointPixels.getX(), (int) pointPixels.getY(), value);
325
                        }
326
                    } else {
327
                        algorithm.add((int) pointPixels.getX(), (int) pointPixels.getY());
328
                    }
329
                }
330
            }
331
        });
332
    }
333

  
334
    /**
335
     * @return the distance
336
     */
337
    @Override
338
    public int getDistance() {
339
        return this.algorithm.getDistance();
340
    }
341

  
342
    /**
343
     * @param distance the distance to set
344
     */
345
    @Override
346
    public void setDistance(int distance) {
347
        this.algorithm.setDistance(distance);
348
    }
349

  
350
    @Override
351
    public void setColorTable(Color[] colorTable) {
352
        this.isRamp = false;
353
        this.sourceColorTable = colorTable;
354
        this.imageLegend = null;
355
        this.hmColorTable = null;
356
        this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
357
    }
358

  
359
    @Override
360
    public void setColorTable(int numColors, Color coldColor, Color hotColor) {
361
        this.isRamp = true;
362
        this.rampColdColor = coldColor;
363
        this.rampHotColor = hotColor;
364
        this.rampNumColors = numColors;
365
        this.imageLegend = null;
366
        this.hmColorTable = null;
367
        this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null));
368
    }
369

  
370
    @Override
371
    public Color[] getSourceColorTable() {
372
        return this.sourceColorTable;
373
    }
374

  
375
    @Override
376
    public Color[] getTargetColorTable() {
377
        return this.getHeatMapColorTable().getColorTable();
378
    }
379

  
380
    private HeatmapColorTable getHeatMapColorTable() {
381
        if (this.hmColorTable == null) {
382
            if (this.useRamp()) {
383
                this.hmColorTable = new HeatmapColorTable(this.rampColdColor, this.rampHotColor, this.rampNumColors);
384
            } else {
385
                if(useAlphaInColorTable) {
386
                    this.hmColorTable = new HeatmapColorTable(this.getSourceColorTable(), colorTableColdColorAlpha, colorTableHotColorAlpha);
387
                } else {
388
                this.hmColorTable =
389
                    this.hmColorTable = new HeatmapColorTable(this.getSourceColorTable());
390
                }
391
            }
392
        }
393
        return this.hmColorTable;
394
    }
395

  
396

  
397
    @Override
398
    public boolean useRamp() {
399
        return this.isRamp;
400
    }
401

  
402
    @Override
403
    public String getFieldName() {
404
        return this.fieldName;
405
    }
406

  
407
    @Override
408
    public void setFieldName(String fieldName) {
409
        this.fieldName = fieldName;
410
    }
411

  
412
    @Override
413
    public int getColorTableHotColorAlpha() {
414
        return colorTableHotColorAlpha;
415
    }
416

  
417
    @Override
418
    public void setColorTableHotColorAlpha(int colorTableHotColorAlpha) {
419
        this.colorTableHotColorAlpha = colorTableHotColorAlpha;
420
        this.imageLegend = null;
421
        this.hmColorTable = null;
422
    }
423

  
424
    @Override
425
    public int getColorTableColdColorAlpha() {
426
        return colorTableColdColorAlpha;
427
    }
428

  
429
    @Override
430
    public void setColorTableColdColorAlpha(int colorTableColdColorAlpha) {
431
        this.colorTableColdColorAlpha = colorTableColdColorAlpha;
432
        this.imageLegend = null;
433
        this.hmColorTable = null;
434
    }
435

  
436
    @Override
437
    public boolean useAlphaInColorTable() {
438
        return this.useAlphaInColorTable;
439
    }
440

  
441
    @Override
442
    public boolean setUseAlphaInColorTable(boolean use) {
443
        boolean x = this.useAlphaInColorTable;
444
        this.useAlphaInColorTable = use;
445
        this.hmColorTable = null;
446

  
447
        return x;
448
    }
449

  
450
    @Override
451
    public Image getImageLegend() {
452
        if( this.imageLegend==null ) {
453
            BufferedImage img = new BufferedImage(80, 20, BufferedImage.TYPE_INT_RGB);
454
            ColorTablePainter painter = new DefaultColorTablePainter(this.getTargetColorTable(),"");
455
            Graphics2D g = img.createGraphics();
456
            g.setClip(0, 0, 80, 20);
457
            g.setBackground(Color.WHITE);
458
            g.fillRect(0, 0, 80, 20);
459
            painter.paint(g, false);
460
            this.imageLegend = img;
461
        }
462
        return this.imageLegend;
463
    }
464

  
465
    @Override
466
    public String getPathImage() {
467
        return null;
468
    }
469

  
470
    @Override
471
    public void loadFromState(PersistentState state) throws PersistenceException {
472
        this.defaultSymbol = new SimpleTextSymbol();
473
        this.imageLegend = null;
474
        this.hmColorTable = null;
475

  
476
        super.loadFromState(state);
477
        this.isRamp = state.getBoolean("isRamp");
478
        this.sourceColorTable = (Color[]) state.getArray("sourceColorTable",Color.class);
479
        this.colorTableHotColorAlpha = state.getInt("colorTableHotColorAlpha");
480
        this.colorTableColdColorAlpha = state.getInt("colorTableColdColorAlpha");
481
        this.useAlphaInColorTable = state.getBoolean("useAlphaInColorTable");
482
        this.fieldName = state.getString("fieldName");
483
        this.rampNumColors = state.getInt("rampNumColors");
484
        this.rampColdColor = (Color)state.get("rampColdColor");
485
        this.rampHotColor = (Color)state.get("rampHotColor");
486

  
487
        this.algorithm = new DensityAlgorithm(state.getInt("distance"));
488
    }
489

  
490
    @Override
491
    public int getRampNumColors() {
492
        return this.rampNumColors;
493
    }
494

  
495
    @Override
496
    public Color getRampColdColor() {
497
        return this.rampColdColor;
498
    }
499

  
500
    @Override
501
    public Color getRampHotColor() {
502
        return this.rampHotColor;
503
    }
504

  
505
    @Override
506
    public void saveToState(PersistentState state) throws PersistenceException {
507
        super.saveToState(state);
508
        state.set("isRamp", isRamp);
509
        state.set("sourceColorTable", sourceColorTable);
510
        state.set("colorTableHotColorAlpha", colorTableHotColorAlpha);
511
        state.set("colorTableColdColorAlpha", colorTableColdColorAlpha);
512
        state.set("useAlphaInColorTable", useAlphaInColorTable);
513
        state.set("fieldName", fieldName);
514
        state.set("distance", algorithm.distance);
515

  
516
        state.set("rampNumColors", rampNumColors);
517
        state.set("rampColdColor", rampColdColor);
518
        state.set("rampHotColor", rampHotColor);
519
    }
520

  
521

  
522
    private static class HeatmapColorTable {
523

  
524
        private Color[] sourceColorTable = null;
525
        private int coldAlpha = -1;
526
        private int hotAlpha = -1;
527
        private Color coldColor = null;
528
        private Color hotColor = null;
529
        private Color[] targetColorTable = null;
530
        private int length = -1;
531

  
532
        public HeatmapColorTable(Color[] sourceColorTable){
533
            this.sourceColorTable  = sourceColorTable;
534
        }
535

  
536
        public HeatmapColorTable(Color[] sourceColorTable, int coldAlpha, int hotAlpha){
537
            this.sourceColorTable  = sourceColorTable;
538
            this.coldAlpha = coldAlpha;
539
            this.hotAlpha = hotAlpha;
540
        }
541

  
542
        public HeatmapColorTable(Color coldColor, Color hotColor, int length){
543
            this.coldColor = coldColor;
544
            this.hotColor = hotColor;
545
            this.length = length;
546
        }
547

  
548
        public Color[] getColorTable(){
549
            if(targetColorTable==null){
550
                if(sourceColorTable!=null){ //Tenemos tabla de color
551
                    if (coldAlpha >= 0 || hotAlpha >= 0) { //Se usa alpha para la tabla de color
552
                        double alphaDelta = getDelta(coldAlpha, hotAlpha, sourceColorTable.length);
553
                        targetColorTable = new Color[sourceColorTable.length];
554
                        for (int i = 0; i < sourceColorTable.length; i++) {
555
                            Color sourceColor = sourceColorTable[i];
556
                            if (coldAlpha >= 0 && hotAlpha >= 0) {
557
                                targetColorTable[i] =
558
                                    new Color(sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue(),
559
                                        coldAlpha + (int) (i * alphaDelta));
560
                            } else {
561
                                targetColorTable[i] = sourceColor;
562
                            }
563
                        }
564
                    } else { //No se usa alpha para la tabla de color
565
                        targetColorTable = sourceColorTable;
566
                    }
567
                } else { // Tenemos gradiente
568
                    targetColorTable = new Color[length];
569

  
570
                    double deltaRed = (hotColor.getRed() - coldColor.getRed()) / length;
571
                    double deltaGreen = (hotColor.getGreen() - coldColor.getGreen()) / length;
572
                    double deltaBlue = (hotColor.getBlue() - coldColor.getBlue()) / length;
573
                    double deltaAlpha = (hotColor.getAlpha() - coldColor.getAlpha()) / length;
574
                    for (int i = 0; i < length; i++) {
575
                        targetColorTable[i] =
576
                            new Color(
577
                                (int) (coldColor.getRed() + i * deltaRed),
578
                                (int) (coldColor.getGreen() + i * deltaGreen),
579
                                (int) (coldColor.getBlue() + i * deltaBlue),
580
                                (int) (coldColor.getAlpha() + i * deltaAlpha));
581
                    }
582
                }
583
            }
584
            return targetColorTable;
585
        }
586

  
587
        private double getDelta(int x1, int x2, int lenght){
588
            return (x2-x1)/((double)lenght-1);
589
        }
590
    }
591
}
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.14/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/HeatmapLegendLibraryImpl.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.heatmap.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.heatmap.lib.api.HeatmapLegendLibrary;
31
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendLocator;
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;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff