Revision 10289

View differences:

org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.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.urbanhorizontalsignage.lib.impl</artifactId>
4
    <name>org.gvsig.legend.urbanhorizontalsignage.lib.impl</name>
5
    <parent>
6
        <groupId>org.gvsig</groupId>
7
        <artifactId>org.gvsig.legend.urbanhorizontalsignage.lib</artifactId>
8
        <version>1.0.104</version>
9
    </parent>
10
    <groupId>org.gvsig</groupId>
11
    <dependencies>
12
        <dependency>
13
            <groupId>org.gvsig</groupId>
14
            <artifactId>org.gvsig.legend.urbanhorizontalsignage.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
    
33
        <dependency>
34
            <groupId>org.gvsig</groupId>
35
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
36
            <scope>test</scope>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
<!--
41
            <artifactId>${org.gvsig.h2spatial.provider}</artifactId>
42
-->
43
            <artifactId>org.gvsig.h2spatial.h2gis132.provider</artifactId>
44
            
45
            <scope>test</scope>
46
        </dependency>
47
        <dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
50
            <scope>test</scope>
51
        </dependency>    
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId>
55
            <scope>test</scope>
56
        </dependency>    
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
60
            <scope>test</scope>
61
        </dependency>    
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
65
            <scope>test</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.compat.se</artifactId>
70
            <scope>test</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
75
            <scope>test</scope>
76
        </dependency>      
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
80
            <scope>test</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
85
            <scope>test</scope>
86
        </dependency>
87
        <dependency>
88
            <groupId>org.gvsig</groupId>
89
            <artifactId>org.gvsig.tools.util.impl</artifactId>
90
            <scope>test</scope>
91
        </dependency>
92
        <dependency>
93
            <groupId>org.gvsig</groupId>
94
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
95
            <scope>test</scope>
96
        </dependency>
97
        <dependency>
98
            <groupId>org.gvsig</groupId>
99
            <artifactId>org.gvsig.fmap.dal.db.jdbc</artifactId>
100
            <scope>compile</scope>
101
        </dependency>
102
    </dependencies>
103
</project>
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/test/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/Test01CalculateGeometries.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl;
2

  
3
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.SplittedLine;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import org.gvsig.fmap.geom.GeometryUtils;
7
import org.gvsig.fmap.geom.primitive.Line;
8
import org.gvsig.fmap.geom.primitive.Point;
9
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
10
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
11
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

  
15
public class Test01CalculateGeometries extends TestCase {
16

  
17
    private static final Logger LOGGER = LoggerFactory.getLogger(Test01CalculateGeometries.class);
18

  
19
    public Test01CalculateGeometries(String testName) {
20
        super(testName);
21
    }
22

  
23
    @Override
24
    protected void setUp() throws Exception {
25
        super.setUp();
26
        new DefaultLibrariesInitializer().fullInitialize();
27
    }
28

  
29
    @Override
30
    protected void tearDown() throws Exception {
31
        super.tearDown();
32
    }
33

  
34
    // TODO add test methods here. The name must begin with 'test'. For example:
35
    // public void testHello() {}
36
    public void test01CalculateIntermediatePoint() {
37
        final String testid = "calculateIntermediatePoint";
38
        Point p1 = GeometryUtils.createPoint(0,0);
39
        Point p2 = GeometryUtils.createPoint(10,0);
40
              
41
        DefaultUrbanHorizontalSignageManager uhsManager = (DefaultUrbanHorizontalSignageManager)UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
42
        try {
43
            for (double lambda = 0; lambda <= 1; lambda += 0.1) {
44
                Point intermediatePoint = uhsManager.calculateIntermediatePoint(p1, p2, lambda);
45
                assertEquals(10*lambda, intermediatePoint.getCoordinateAt(0));
46
                assertEquals(0.0, intermediatePoint.getCoordinateAt(1));
47
            }
48
        } catch (Exception ex) {
49
            //TODO:
50
            fail(ex.getMessage());
51
        }
52
        
53
        
54
    }
55
    
56
    public void test02SplitLine() throws Exception {
57
        final String testid = "splitLine";
58
        
59
        Point p1 = GeometryUtils.createPoint(0,0);
60
        Point p2 = GeometryUtils.createPoint(10,0);
61
        Line line = GeometryUtils.createLine(p1, p2, 0);
62
        
63
        DefaultUrbanHorizontalSignageManager uhsManager = (DefaultUrbanHorizontalSignageManager)UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
64
//        UrbanHorizontalSignageData data = uhsManager.createUrbanHorizontalSignageData();
65

  
66
//        data.setWidth(20);
67
//        data.setContinuity(UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE);
68
//        data.setSegmentsLength(100);
69
//        data.setHolesLength(50);
70
//        data.setGapWith(10);
71
//        data.setSegmentsColor(Color.RED);
72
//        data.setHolesColor(Color.BLACK);
73
//        data.setRoundVertex(false);
74
//        data.setPaintHoles(true);
75
        
76
        SplittedLine splittedLine = uhsManager.splitLine(line, 1, 0.5);
77
        
78
        List<Line> segments = splittedLine.getSegments();
79
        List<Line> holes = splittedLine.getHoles();
80
        
81
        assertEquals(7, segments.size());
82
        assertEquals(6, holes.size());
83
        
84
        double x = 0;
85
        for (Line segment : segments) {
86
            assertEquals(x, segment.getVertex(0).getX());
87
            assertEquals(x+1.0, segment.getVertex(1).getX());
88
            x += 1.50;
89
        }
90
        x = 1.0;
91
        for (Line hole : holes) {
92
            assertEquals(x, hole.getVertex(0).getX());
93
            assertEquals(x+0.5, hole.getVertex(1).getX());
94
            x += 1.50;
95
        }
96
    }
97
    
98
    
99
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/UrbanHorizontalSignageLibraryImpl.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.urbanhorizontalsignage.lib.impl;
26

  
27
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageLegend;
28
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.UrbanHorizontalSignageSymbol;
29
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageConfig;
30
import java.io.InputStream;
31
import java.util.Map;
32
import org.gvsig.fmap.mapcontext.MapContextLibrary;
33
import org.gvsig.fmap.mapcontext.MapContextLocator;
34
import org.gvsig.fmap.mapcontext.MapContextManager;
35
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLibrary;
36
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
37
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DynStruct;
40
import org.gvsig.tools.library.AbstractLibrary;
41
import org.gvsig.tools.library.LibraryException;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

  
44
public class UrbanHorizontalSignageLibraryImpl extends AbstractLibrary {
45

  
46
    @Override
47
    public void doRegistration() {
48
        registerAsImplementationOf(UrbanHorizontalSignageLibrary.class);
49
        this.require(MapContextLibrary.class);
50
        this.require(SymbologyDefaultImplLibrary.class);
51
    }
52

  
53
    @Override
54
    protected void doInitialize() throws LibraryException {
55
        UrbanHorizontalSignageLocator.registerUrbanHorizontalSignageManager(DefaultUrbanHorizontalSignageManager.class);
56
        MapContextManager mcmanager = MapContextLocator.getMapContextManager();
57
        mcmanager.registerLegend("UrbanHorizontalSignageLegend", DefaultUrbanHorizontalSignageLegend.class);
58
    }
59

  
60
    @Override
61
    protected void doPostInitialize() throws LibraryException {
62
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
63
        InputStream is = this.getClass().getResourceAsStream("UrbanHorizontalSignagePersistence.xml");
64
        Map<String,DynStruct> definitions;
65
        try {
66
            definitions = ToolsLocator.getDynObjectManager().importDynClassDefinitions(is, this.getClass().getClassLoader());
67
        } catch (Exception ex) {
68
            throw new LibraryException(this.getClass(), ex);
69
        }
70
        
71
        persistenceManager.addDefinition(
72
                DefaultUrbanHorizontalSignageLegend.class,
73
                "DefaultUrbanHorizontalSignageLegend",
74
                definitions,
75
                null,
76
                null);
77
        persistenceManager.addDefinition(
78
                UrbanHorizontalSignageSymbol.class,
79
                "UrbanHorizontalSignageSymbol",
80
                definitions,
81
                null,
82
                null
83
        );
84
        persistenceManager.addDefinition(
85
                DefaultUrbanHorizontalSignageConfig.class,
86
                "DefaultUrbanHorizontalSignageConfig",
87
                definitions,
88
                null,
89
                null
90
        );
91
    }
92

  
93
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageConfig.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
7

  
8
import java.awt.Color;
9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.dal.feature.FeatureType;
11
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
12
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig.DEFAULT_GAP_WIDTH_VALUE;
13
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
14
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE;
15
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_HOLES_COLOR_VALUE;
16
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_HOLES_LENGTH_VALUE;
17
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_PAINT_HOLES_VALUE;
18
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_ROUND_VERTEX_VALUE;
19
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_SEGMENT_COLOR_VALUE;
20
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_SEGMENT_LENGTH_VALUE;
21
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.DEFAULT_WIDTH_VALUE;
22
import org.gvsig.tools.ToolsLocator;
23
import org.gvsig.tools.dataTypes.DataTypesManager;
24
import org.gvsig.tools.persistence.PersistentState;
25
import org.gvsig.tools.persistence.exception.PersistenceException;
26
import org.gvsig.tools.swing.api.DataTypes;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
/**
31
 *
32
 * @author fdiaz
33
 */
34
public class DefaultUrbanHorizontalSignageConfig implements UrbanHorizontalSignageConfig {
35

  
36
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageConfig.class);
37

  
38
    private String widthFieldName;
39
    private String continuityFieldName;
40
    private String holesLengthFieldName;
41
    private String holesColorFieldName;
42
    private String paintHolesFieldName;
43
    private String segmentsLengthFieldName;
44
    private String segmentsColorFieldName;
45
    private String roundVertexFieldName;
46
    private int gapWidth;
47
    private String targetColorFieldName;
48
    private String targetLenghtFieldName;
49
    private String targetAreaFieldName;
50
    
51
    public DefaultUrbanHorizontalSignageConfig() {
52
        this.gapWidth = DEFAULT_GAP_WIDTH_VALUE;
53
    }
54

  
55
    @Override
56
    public void loadFromState(PersistentState state) throws PersistenceException {
57

  
58
        this.widthFieldName = state.getString("widthFieldName");
59
        this.continuityFieldName = state.getString("continuityFieldName");
60
        this.holesLengthFieldName = state.getString("holesLengthFieldName");
61
        this.holesColorFieldName = state.getString("holesColorFieldName");
62
        this.paintHolesFieldName = state.getString("paintHolesFieldName");
63
        this.segmentsLengthFieldName = state.getString("segmentsLengthFieldName");
64
        this.segmentsColorFieldName = state.getString("segmentsColorFieldName");
65
        this.roundVertexFieldName = state.getString("roundVertexFieldName");
66
        this.gapWidth = state.getInt("gapWidth", DEFAULT_GAP_WIDTH_VALUE);
67
    }
68

  
69
    @Override
70
    public void saveToState(PersistentState state) throws PersistenceException {
71
        state.set("widthFieldName", this.widthFieldName);
72
        state.set("continuityFieldName", this.continuityFieldName);
73
        state.set("holesLengthFieldName", this.holesLengthFieldName);
74
        state.set("holesColorFieldName", this.holesColorFieldName);
75
        state.set("paintHolesFieldName", this.paintHolesFieldName);
76
        state.set("segmentsLengthFieldName", this.segmentsLengthFieldName);
77
        state.set("segmentsColorFieldName", this.segmentsColorFieldName);
78
        state.set("roundVertexFieldName", this.roundVertexFieldName);
79
        state.set("gapWidth", this.gapWidth);
80
    }
81

  
82
    @Override
83
    public String getWidthFieldName() {
84
        return this.widthFieldName;
85
    }
86

  
87
    @Override
88
    public void setWidthFieldName(String fieldName) {
89
        this.widthFieldName = fieldName;
90
    }
91

  
92
    @Override
93
    public String getContinuityFieldName() {
94
        return this.continuityFieldName;
95
    }
96

  
97
    @Override
98
    public void setContinuityFieldName(String fieldName) {
99
        this.continuityFieldName = fieldName;
100
    }
101

  
102
    @Override
103
    public String getSegmentsColorFieldName() {
104
        return this.segmentsColorFieldName;
105
    }
106

  
107
    @Override
108
    public void setSegmentsColorFieldName(String fieldName) {
109
        this.segmentsColorFieldName = fieldName;
110
    }
111

  
112
    @Override
113
    public String getSegmentsLengthFieldName() {
114
        return this.segmentsLengthFieldName;
115
    }
116

  
117
    @Override
118
    public void setSegmentsLengthFieldName(String fieldName) {
119
        this.segmentsLengthFieldName = fieldName;
120
    }
121

  
122
    @Override
123
    public String getPaintHolesFieldName() {
124
        return this.paintHolesFieldName;
125
    }
126

  
127
    @Override
128
    public void setPaintHolesFieldName(String fieldName) {
129
        this.paintHolesFieldName = fieldName;
130
    }
131

  
132
    @Override
133
    public String getHolesColorFieldName() {
134
        return this.holesColorFieldName;
135
    }
136

  
137
    @Override
138
    public void setHolesColorFieldName(String fieldName) {
139
        this.holesColorFieldName = fieldName;
140
    }
141

  
142
    @Override
143
    public String getHolesLengthFieldName() {
144
        return this.holesLengthFieldName;
145
    }
146

  
147
    @Override
148
    public void setHolesLengthFieldName(String fieldName) {
149
        this.holesLengthFieldName = fieldName;
150
    }
151
    
152
    @Override
153
    public String getRoundVertexFieldName() {
154
        return this.roundVertexFieldName;
155
    }
156

  
157
    @Override
158
    public void setRoundVertexFieldName(String fieldName) {
159
        this.roundVertexFieldName = fieldName;
160
    }
161
    
162
    @Override
163
    public int getGapWidth() {
164
        return this.gapWidth;
165
    }
166

  
167
    @Override
168
    public void setGapWith(int value) {
169
        this.gapWidth = value;
170
    }
171

  
172
    @Override
173
    public UrbanHorizontalSignageData getValues(Feature feature) {
174
        UrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
175
        DataTypesManager manager = ToolsLocator.getDataTypesManager();
176
        FeatureType ftype = feature.getType();
177
        double valueDouble = feature.getIntOrDefault( this.widthFieldName, (int)DEFAULT_WIDTH_VALUE*100 )/100.0;
178
        data.setWidth(valueDouble);
179
        int valueInt = feature.getIntOrDefault( this.continuityFieldName, DEFAULT_CONTINUITY_VALUE );
180
        data.setContinuity(valueInt);
181
        Color valueColor = (Color)feature.getOrDefault( this.segmentsColorFieldName, DataTypes.COLOR, DEFAULT_SEGMENT_COLOR_VALUE );
182
        data.setSegmentsColor(valueColor);
183
        valueDouble = feature.getIntOrDefault( this.segmentsLengthFieldName, (int)DEFAULT_SEGMENT_LENGTH_VALUE*100 )/100.0;
184
        data.setSegmentsLength(valueDouble);
185
        valueDouble = feature.getIntOrDefault( this.holesLengthFieldName, (int)DEFAULT_HOLES_LENGTH_VALUE*100 )/100.0;
186
        data.setHolesLength(valueDouble);
187
        boolean valueBoolean = feature.getBooleanOrDefault( this.paintHolesFieldName, DEFAULT_PAINT_HOLES_VALUE );
188
        data.setPaintHoles(valueBoolean);
189
        valueColor = (Color) feature.getOrDefault( this.holesColorFieldName, DataTypes.COLOR, DEFAULT_HOLES_COLOR_VALUE );
190
        data.setHolesColor(valueColor);
191
        valueBoolean = feature.getBooleanOrDefault( this.roundVertexFieldName, DEFAULT_ROUND_VERTEX_VALUE );
192
        data.setRoundVertex(valueBoolean);
193

  
194
        data.setGapWidth(this.getGapWidth()/100.0);
195
        
196
        return data;
197
    }
198

  
199
    @Override
200
    public String getTargetColorFieldName() {
201
        return this.targetColorFieldName;
202
    }
203

  
204
    @Override
205
    public void setTargetColorFieldName(String fieldName) {
206
        this.targetColorFieldName = fieldName;
207
    }
208

  
209
    @Override
210
    public String getTargetLenghtFieldName() {
211
        return this.targetLenghtFieldName;
212
    }
213

  
214
    @Override
215
    public void setTargetLenghtFieldName(String fieldName) {
216
        this.targetLenghtFieldName = fieldName;
217
    }
218

  
219
    @Override
220
    public String getTargetAreaFieldName() {
221
        return this.targetAreaFieldName;
222
    }
223

  
224
    @Override
225
    public void setTargetAreaFieldName(String fieldName) {
226
        this.targetAreaFieldName = fieldName;
227
    }
228

  
229
    @Override
230
    public UrbanHorizontalSignageConfig clone() throws CloneNotSupportedException {
231
        return (UrbanHorizontalSignageConfig) super.clone(); 
232
    }
233

  
234
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageData.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
7

  
8
import java.awt.Color;
9
import org.gvsig.fmap.geom.Geometry;
10
import org.gvsig.fmap.geom.aggregate.MultiLine;
11
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
12
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
13

  
14
/**
15
 *
16
 * @author fdiaz
17
 */
18
public class DefaultUrbanHorizontalSignageData implements UrbanHorizontalSignageData {
19
    
20
    private double width;
21
    private int continuity;
22
    private Color segmentsColor;
23
    private double segmentsLength;
24
    private MultiPolygon segmentsGeometry;
25
    private boolean isPaintHoles;
26
    private Color holesColor;
27
    private double holesLength;
28
    private MultiPolygon holesGeometry;
29
    private double gapWidth;
30
    private Geometry originalGeometry;
31
    private boolean roundVertex;
32
    private MultiLine lineSegmentsGeometry;
33
    private MultiLine lineHolesGeometry;
34

  
35
    public DefaultUrbanHorizontalSignageData() {
36
        width = DEFAULT_WIDTH_VALUE;
37
        continuity = DEFAULT_CONTINUITY_VALUE;
38
        segmentsColor = DEFAULT_SEGMENT_COLOR_VALUE;
39
        segmentsLength = DEFAULT_SEGMENT_LENGTH_VALUE;
40
        isPaintHoles = DEFAULT_PAINT_HOLES_VALUE;
41
        holesColor = DEFAULT_HOLES_COLOR_VALUE;
42
        holesLength = DEFAULT_HOLES_LENGTH_VALUE;
43
        gapWidth = DEFAULT_GAP_WIDTH_VALUE;
44
        roundVertex = DEFAULT_ROUND_VERTEX_VALUE;
45
    }
46

  
47
    @Override
48
    public double getWidth() {
49
        return this.width;
50
    }
51

  
52
    @Override
53
    public void setWidth(double value) {
54
        this.width = value;
55
    }
56

  
57
    @Override
58
    public int getContinuity() {
59
        return this.continuity;
60
    }
61

  
62
    @Override
63
    public void setContinuity(int value) {
64
        this.continuity = value;
65
    }
66

  
67
    @Override
68
    public Color getSegmentsColor() {
69
        return this.segmentsColor;
70
    }
71

  
72
    @Override
73
    public void setSegmentsColor(Color value) {
74
        this.segmentsColor = value;
75
    }
76

  
77
    @Override
78
    public double getSegmentsLength() {
79
        return this.segmentsLength;
80
    }
81

  
82
    @Override
83
    public void setSegmentsLength(double value) {
84
        this.segmentsLength = value;
85
    }
86

  
87
    @Override
88
    public MultiPolygon getSegmentsGeometry() {
89
        return this.segmentsGeometry;
90
    }
91

  
92
    @Override
93
    public void setSegmentsGeometry(MultiPolygon value) {
94
        this.segmentsGeometry = value;
95
    }
96

  
97
    @Override
98
    public boolean isPaintHoles() {
99
        return this.isPaintHoles;
100
    }
101

  
102
    @Override
103
    public void setPaintHoles(boolean value) {
104
        this.isPaintHoles = value;
105
    }
106

  
107
    @Override
108
    public Color getHolesColor() {
109
        return this.holesColor;
110
    }
111

  
112
    @Override
113
    public void setHolesColor(Color value) {
114
        this.holesColor = value;
115
    }
116

  
117
    @Override
118
    public double getHolesLength() {
119
        return this.holesLength;
120
    }
121

  
122
    @Override
123
    public void setHolesLength(double value) {
124
        this.holesLength = value;
125
    }
126

  
127
    @Override
128
    public MultiPolygon getHolesGeometry() {
129
        return this.holesGeometry;
130
    }
131

  
132
    @Override
133
    public void setHolesGeometry(MultiPolygon value) {
134
        this.holesGeometry = value;
135
    }
136

  
137
    @Override
138
    public double getGapWidth() {
139
        return this.gapWidth;
140
    }
141

  
142
    @Override
143
    public void setGapWidth(double value) {
144
        this.gapWidth = value;
145
    }
146
    
147
    public boolean isRoundVertex(){
148
        return this.roundVertex;
149
    }
150

  
151
    public void setRoundVertex(boolean value){
152
        this.roundVertex = value;
153
    }
154

  
155
    @Override
156
    public MultiLine getLineSegmentsGeometry() {
157
        return this.lineSegmentsGeometry;
158
    }
159

  
160
    @Override
161
    public void setLineSegmentsGeometry(MultiLine value) {
162
        this.lineSegmentsGeometry = value;
163
    }
164

  
165
    @Override
166
    public MultiLine getLineHolesGeometry() {
167
        return this.lineHolesGeometry;
168
    }
169

  
170
    @Override
171
    public void setLineHolesGeometry(MultiLine value) {
172
        this.lineHolesGeometry = value;
173
    }
174
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/SplittedLine.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.gvsig.fmap.geom.primitive.Line;
6

  
7
/**
8
 *
9
 * @author gvSIG Team
10
 */
11
public class SplittedLine {
12
    
13
    List<Line> segments;
14
    List<Line> holes;
15

  
16
    public SplittedLine() {
17
        segments = new ArrayList<>();
18
        holes = new ArrayList<>();
19
    }
20

  
21
    public List<Line> getSegments() {
22
        return this.segments;
23
    }
24

  
25
    public List<Line> getHoles() {
26
        return this.holes;
27
    }
28

  
29
    public void addSegment(Line segment) {
30
        this.segments.add(segment);
31
    }
32

  
33
    public void addHole(Line hole) {
34
        this.holes.add(hole);
35
    }
36
    
37
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/DefaultUrbanHorizontalSignageLegend.java
1
package org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend;
2

  
3
import java.awt.Image;
4
import java.util.ArrayList;
5
import java.util.List;
6
import org.apache.commons.lang3.StringUtils;
7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10
import org.gvsig.fmap.geom.Geometry;
11
import org.gvsig.fmap.geom.GeometryUtils;
12
import org.gvsig.fmap.mapcontext.MapContextException;
13
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
14
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
15
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
16
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageLegend;
17
import org.gvsig.symbology.SymbologyLocator;
18
import org.gvsig.symbology.SymbologyManager;
19
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
20
import org.gvsig.tools.persistence.PersistentState;
21
import org.gvsig.tools.persistence.exception.PersistenceException;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class DefaultUrbanHorizontalSignageLegend 
26
        extends AbstractVectorialLegend 
27
        implements UrbanHorizontalSignageLegend //, IHasImageLegend 
28
{
29
    
30
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageLegend.class);
31

  
32
    private final UrbanHorizontalSignageSymbol defaultSymbol;
33
    
34
    private UrbanHorizontalSignageConfig config;
35
    
36
    private Image imageLegend;
37
    
38
    public DefaultUrbanHorizontalSignageLegend() {
39
        
40
        SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager();
41
        this.defaultSymbol = new UrbanHorizontalSignageSymbol();
42
        DefaultUrbanHorizontalSignageData data = new DefaultUrbanHorizontalSignageData();
43
        data.setContinuity(UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT);
44
        this.defaultSymbol.setData(new DefaultUrbanHorizontalSignageData());
45
        
46
        this.config = new DefaultUrbanHorizontalSignageConfig();
47
    }
48

  
49
    @Override
50
    public ISymbol getDefaultSymbol() {
51
        return this.defaultSymbol;
52
    }
53

  
54
    @Override
55
    public void setDefaultSymbol(ISymbol is) {
56
        //DO NOTHING
57
    }
58

  
59
    @Override
60
    public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException {
61

  
62
        UrbanHorizontalSignageData values = this.getConfig().getValues(ftr);
63

  
64
        UrbanHorizontalSignageSymbol symbol = new UrbanHorizontalSignageSymbol();
65
        symbol.setData(values);
66
        return symbol;
67
    }
68

  
69
    @Override
70
    public int getShapeType() {
71
        return Geometry.TYPES.CURVE;
72
    }
73

  
74
    @Override
75
    public void setShapeType(int i) {
76
    }
77

  
78
    @Override
79
    public boolean isUseDefaultSymbol() {
80
        return true;
81
    }
82

  
83
    @Override
84
    public void useDefaultSymbol(boolean bln) {
85
    }
86

  
87
    @Override
88
    public boolean isSuitableForShapeType(int shapeType) {
89
        return (GeometryUtils.isSubtype(Geometry.TYPES.CURVE, shapeType) ||  
90
            GeometryUtils.isSubtype(Geometry.TYPES.MULTICURVE, shapeType));
91
    }
92

  
93
    @Override
94
    public void loadFromState(PersistentState state) throws PersistenceException {
95
//        this.defaultSymbol = new SimpleTextSymbol();
96
        this.imageLegend = null;
97

  
98
        super.loadFromState(state);
99
        this.config = (UrbanHorizontalSignageConfig) state.get("config");
100
        if(this.config == null){
101
            this.config = new DefaultUrbanHorizontalSignageConfig();
102
        }
103
    }
104

  
105
    @Override
106
    public void saveToState(PersistentState state) throws PersistenceException {
107
        super.saveToState(state);
108
        state.set("config", this.getConfig());
109
    }
110

  
111
    @Override
112
    protected String[] getRequiredFeatureAttributeNames(FeatureStore fs) throws DataException {
113
        List<String> names = new ArrayList<>(10);
114
        UrbanHorizontalSignageConfig theConfig = this.getConfig();
115
        
116
        String name = theConfig.getWidthFieldName();
117
        if( StringUtils.isNotBlank(name) ) {
118
            names.add(name);
119
        }
120
        name = theConfig.getContinuityFieldName();
121
        if( StringUtils.isNotBlank(name) ) {
122
            names.add(name);
123
        }
124
        name = theConfig.getHolesLengthFieldName();
125
        if( StringUtils.isNotBlank(name) ) {
126
            names.add(name);
127
        }
128
        name = theConfig.getHolesColorFieldName();
129
        if( StringUtils.isNotBlank(name) ) {
130
            names.add(name);
131
        }
132
        name = theConfig.getPaintHolesFieldName();
133
        if( StringUtils.isNotBlank(name) ) {
134
            names.add(name);
135
        }
136
        name = theConfig.getPaintHolesFieldName();
137
        if( StringUtils.isNotBlank(name) ) {
138
            names.add(name);
139
        }
140
        name = theConfig.getSegmentsLengthFieldName();
141
        if( StringUtils.isNotBlank(name) ) {
142
            names.add(name);
143
        }
144
        name = theConfig.getSegmentsColorFieldName();
145
        if( StringUtils.isNotBlank(name) ) {
146
            names.add(name);
147
        }
148
        name = theConfig.getRoundVertexFieldName();
149
        if( StringUtils.isNotBlank(name) ) {
150
            names.add(name);
151
        }
152
        name = fs.getDefaultFeatureType().getDefaultGeometryAttributeName();
153
        if( StringUtils.isNotBlank(name) ) {
154
            names.add(name);
155
        }
156
        return names.toArray(new String[names.size()]);
157
    }
158

  
159
    @Override
160
    public UrbanHorizontalSignageConfig getConfig() {
161
        return config;
162
    }
163
    
164
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/linelegend/UrbanHorizontalSignageSymbol.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.urbanhorizontalsignage.lib.impl.linelegend;
25

  
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29
import java.awt.Shape;
30
import java.awt.geom.AffineTransform;
31
import java.util.concurrent.Callable;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.geom.Geometry;
34
import org.gvsig.fmap.geom.GeometryUtils;
35
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.geom.primitive.Line;
38
import org.gvsig.fmap.geom.primitive.Point;
39
import org.gvsig.fmap.mapcontext.MapContext;
40
import org.gvsig.fmap.mapcontext.MapContextLocator;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
43
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
44
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
45
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageManager;
46
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
47
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT_DISC;
48
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC;
49
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT;
50
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_DISC;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
52
import org.gvsig.tools.persistence.PersistentState;
53
import org.gvsig.tools.persistence.exception.PersistenceException;
54
import org.gvsig.tools.swing.api.TransparencySupport;
55
import org.gvsig.tools.task.Cancellable;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58

  
59
public class UrbanHorizontalSignageSymbol extends AbstractSymbol implements ISymbol_v2, TransparencySupport {
60

  
61
    private static final Logger LOG = LoggerFactory.getLogger(UrbanHorizontalSignageSymbol.class);
62
    private static final String SYMBOL_NAME = "UrbanHorizontalSignageSymbol";
63
    private static final String URBAN_HORIZONTAL_SIGNAGE_SYMBOL_PERSISTENCE_DEFINITION_NAME = "UrbanHorizontalSignageSymbol";
64
    
65
    private static final String FIELD_WIDTH = "width";
66
    private static final String FIELD_CONTINUITY = "continuity";
67
    private static final String FIELD_SEGMENTS_COLOR = "segmentsColor";
68
    private static final String FIELD_SEGMENTS_LENGTH = "segmentsLength";
69
    private static final String FIELD_HOLES_COLOR = "holesColor";
70
    private static final String FIELD_HOLES_LENGTH = "holesLength";
71
    private static final String FIELD_PAINT_HOLES = "paintHoles";
72
    private static final String FIELD_GAP_WIDTH = "gapWidth";
73
    private static final String FIELD_ROUND_VERTEX = "roundVertex";
74
    private static final String FIELD_SEGMENTS_GEOMETRY = "segmentsGeometry";
75
    private static final String FIELD_HOLES_GEOMETRY = "holesGeometry";
76
    private static final String FIELD_TRANSPARENCY = "transparency";
77
    private static final String FIELD_MUST_DRAW_ORIGINAL_GEOMETRY = "mustDrawOriginalGeometry";
78
    private static final String FIELD_COLOR_FOR_ORIGINAL_GEOMETRY = "colorForOriginalGeometry";
79
    
80

  
81

  
82
//    private static final String FIELD_SYMBOL_FOR_SELECTION = "symbolForSelection";
83
    private UrbanHorizontalSignageData data;
84

  
85
    transient private UrbanHorizontalSignageSymbol symbolForSelection;
86
    
87
    private boolean mustDrawOriginalGeometry;
88
    private Color colorForOriginalGeometry;
89
    private double cartographicSize;
90
    private double transparency; //[0.0, 1.0]
91

  
92
    public UrbanHorizontalSignageSymbol() {
93
        super();
94
        this.mustDrawOriginalGeometry = false;
95
        this.transparency = 1.0;
96
    }
97

  
98
    public void setData(UrbanHorizontalSignageData data) {
99
        this.data = data;
100
    }
101

  
102
    public UrbanHorizontalSignageData getData() {
103
        return data;
104
    }
105

  
106
    /**
107
     * Sets the transparency for symbol. The valid values are in [0.0, 1.0]
108
     * 
109
     * @param transparency 
110
     */
111
    @Override
112
    public void setTransparency(double transparency) {
113
        if(transparency < 0 || transparency > 1.0){
114
            throw new IllegalArgumentException("Transparency value must be in [0.0, 1.0] ("+transparency+")");
115
        }
116
        this.transparency = transparency;
117
    }
118

  
119
    @Override
120
    public double getTransparency() {
121
        return transparency;
122
    }
123
    
124
    @Override
125
    public ISymbol getSymbolForSelection() {
126
        if (symbolForSelection == null) {
127
            symbolForSelection = (UrbanHorizontalSignageSymbol) cloneForSelection();
128
            symbolForSelection.mustDrawOriginalGeometry = true;
129
        } else {
130
            symbolForSelection.setColor(MapContext.getSelectionColor());
131
        }
132
        return symbolForSelection;
133
    }
134
    
135
    protected Geometry getSampleGeometry(Rectangle r) {
136
        final int hGap = (int) (r.getWidth() * 0.1); // the left and right margins
137
        final int vPos = 1; 						 // the top and bottom margins
138
        final int splitCount = 3; 					 // number of lines
139
        final int splitHSize = (r.width - hGap - hGap) / splitCount;
140
        int hPos = hGap;
141
        boolean swap = false;
142

  
143
        Line geom = GeometryUtils.createLine(Geometry.SUBTYPES.GEOM2D);
144
        geom.addVertex(r.x + hPos, r.y + r.height - vPos);
145

  
146
        for (int i = 0; i < splitCount; i++) {
147
            swap = !swap;
148
            geom.addVertex(r.x + hPos + splitHSize, (swap ? vPos : r.height - vPos) + r.y);
149
            hPos += splitHSize;
150
        }
151
        return geom;
152
    }
153
    
154

  
155
    @Override
156
    public void draw(Graphics2D g, AffineTransform affineTransform,
157
            Geometry originalGeometry, Feature feature, Cancellable cancel, Rectangle r) {
158
        if(r != null){
159
            originalGeometry = getSampleGeometry(r);
160
        }
161
        if (true) {
162
            // Esto deberia ser para optimizar el pintado de 
163
            // geometrias grandes.
164
            try {
165
                Geometry env = originalGeometry.getEnvelope().getGeometry();
166
                env.transform(affineTransform);
167
                Envelope env2 = env.getEnvelope();
168
                if (env2.getLength(0) < 1.5 && env2.getLength(1) < 1.5) {
169
                    Color color = data.getSegmentsColor();
170
                    Color transparentColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(transparency*color.getAlpha()));
171
                    g.setColor(transparentColor);
172
                    Point upperCorner = env2.getUpperCorner();
173
                    int x = (int) upperCorner.getX();
174
                    int y = (int) upperCorner.getY();
175
                    g.drawLine(x, y, x, y);
176
                    return;
177
                }
178
            } catch (Exception ex) {
179
                LOG.warn("Error optimizing the drawing of the geometry. Continues with normal drawing.", ex);
180
                // Do nothing, continue with the draw of the original geometry
181
            }
182
        }
183

  
184
        UrbanHorizontalSignageManager uhsManager = UrbanHorizontalSignageLocator.getUrbanHorizontalSignageManager();
185
        uhsManager.calculateGeometries(originalGeometry, data);
186
        
187
        MultiPolygon geom = data.getSegmentsGeometry();
188
        if (geom != null && geom.getPrimitivesNumber() > 0) {
189
            Color color = data.getSegmentsColor();
190
            Shape shape = geom.getShape(affineTransform);
191
            Color transparentColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(transparency*color.getAlpha()));
192
            g.setColor(transparentColor);
193
            g.fill(shape);
194
            g.setColor(color.darker());
195
            g.draw(shape);
196
        }
197

  
198
        switch (data.getContinuity()) {
199
            case CONTINUITY_MODE_CONT_DISC:
200
            case CONTINUITY_MODE_DISC_CONT:
201
            case CONTINUITY_MODE_DISC:
202
            case CONTINUITY_MODE_DISC_DISC:
203
                if (data.isPaintHoles()) {
204
                    geom = data.getHolesGeometry();
205
                    if (geom != null && geom.getPrimitivesNumber() > 0) {
206
                        Color color = data.getHolesColor();
207
                        Color transparentColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(transparency*color.getAlpha()));
208
                        g.setColor(transparentColor);
209
                        g.fill(geom.getShape(affineTransform));
210
                    }
211
                }
212
        }
213

  
214
        //For debug purposse only
215
        if(mustDrawOriginalGeometry){
216
            g.setColor(getColor());
217
            g.draw(originalGeometry.getShape(affineTransform));
218
        }
219

  
220
    }
221

  
222
    @Override
223
    public Object clone() throws CloneNotSupportedException {
224
        UrbanHorizontalSignageSymbol copy = (UrbanHorizontalSignageSymbol) super.clone();
225

  
226
        if (symbolForSelection != null) {
227
            copy.symbolForSelection = (UrbanHorizontalSignageSymbol) symbolForSelection
228
                    .clone();
229
        }
230

  
231
        return copy;
232
    }
233

  
234
    @Override
235
    public void loadFromState(PersistentState state) throws PersistenceException {
236
        // Set parent style properties
237
        super.loadFromState(state);
238
        
239
        UrbanHorizontalSignageData theData = new DefaultUrbanHorizontalSignageData();
240
        theData.setWidth(state.getDouble(FIELD_WIDTH, UrbanHorizontalSignageData.DEFAULT_WIDTH_VALUE));
241
        theData.setContinuity(state.getInt(FIELD_CONTINUITY, UrbanHorizontalSignageData.DEFAULT_CONTINUITY_VALUE));
242
        
243
        Color color = (Color) state.get(FIELD_SEGMENTS_COLOR);
244
        theData.setSegmentsColor(color != null ? color : UrbanHorizontalSignageData.DEFAULT_SEGMENT_COLOR_VALUE);
245
        
246
        theData.setSegmentsLength(state.getDouble(FIELD_SEGMENTS_LENGTH, UrbanHorizontalSignageData.DEFAULT_SEGMENT_LENGTH_VALUE));
247
        
248
        color = (Color) state.get(FIELD_HOLES_COLOR);
249
        theData.setHolesColor(color != null ? color : UrbanHorizontalSignageData.DEFAULT_HOLES_COLOR_VALUE);
250
        
251
        theData.setHolesLength(state.getDouble(FIELD_HOLES_LENGTH, UrbanHorizontalSignageData.DEFAULT_HOLES_LENGTH_VALUE));
252
        theData.setGapWidth(state.getDouble(FIELD_GAP_WIDTH, UrbanHorizontalSignageData.DEFAULT_GAP_WIDTH_VALUE));
253
        theData.setRoundVertex(state.getBoolean(FIELD_ROUND_VERTEX, UrbanHorizontalSignageData.DEFAULT_ROUND_VERTEX_VALUE));
254
        
255
        this.transparency = state.getDouble(FIELD_TRANSPARENCY, 1.0);
256
        this.mustDrawOriginalGeometry = state.getBoolean(FIELD_MUST_DRAW_ORIGINAL_GEOMETRY, false);
257
        color = (Color) state.get(FIELD_COLOR_FOR_ORIGINAL_GEOMETRY);
258
        this.colorForOriginalGeometry = color != null ? color : MapContext.getSelectionColor();
259
        this.data = theData;
260

  
261
    }
262

  
263
    @Override
264
    public void saveToState(PersistentState state) throws PersistenceException {
265
        // Save parent fill symbol properties
266
        super.saveToState(state);
267

  
268
        // Save own properties
269
        
270
        if(data != null){
271
            state.set(FIELD_WIDTH, data.getWidth());
272
            state.set(FIELD_CONTINUITY, data.getContinuity());
273
            state.set(FIELD_SEGMENTS_COLOR, data.getSegmentsColor());
274
            state.set(FIELD_SEGMENTS_LENGTH, data.getSegmentsLength());
275
            state.set(FIELD_HOLES_COLOR, data.getHolesColor());
276
            state.set(FIELD_HOLES_LENGTH, data.getHolesLength());
277
            state.set(FIELD_PAINT_HOLES, data.isPaintHoles());
278
            state.set(FIELD_GAP_WIDTH, data.getGapWidth());
279
            state.set(FIELD_ROUND_VERTEX, data.isRoundVertex());
280
        }
281
        state.set(FIELD_MUST_DRAW_ORIGINAL_GEOMETRY, mustDrawOriginalGeometry);
282
        state.set(FIELD_COLOR_FOR_ORIGINAL_GEOMETRY, colorForOriginalGeometry);
283
        state.set(FIELD_TRANSPARENCY, this.getTransparency());
284
    }
285

  
286
    @Override
287
    public int getSymbolType() {
288
        return Geometry.TYPES.CURVE;
289
    }
290

  
291
    @Override
292
    public boolean isSuitableFor(Geometry geom) {
293
        return geom.getGeometryType().isTypeOf(Geometry.TYPES.CURVE);
294
    }
295

  
296
    @Override
297
    public Color getColor() {
298
        return this.colorForOriginalGeometry;
299
    }
300

  
301
    @Override
302
    public void setColor(Color color) {
303
        this.colorForOriginalGeometry = color;
304
    }
305

  
306
//    public static class RegisterPersistence implements Callable {
307
//
308
//        @Override
309
//        public Object call() throws Exception {
310
//            PersistenceManager manager = ToolsLocator.getPersistenceManager();
311
//            if (manager.getDefinition(URBAN_HORIZONTAL_SIGNAGE_SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) {
312
//                DynStruct definition = manager.addDefinition(
313
//                        UrbanHorizontalSignageSymbol.class,
314
//                        URBAN_HORIZONTAL_SIGNAGE_SYMBOL_PERSISTENCE_DEFINITION_NAME,
315
//                        URBAN_HORIZONTAL_SIGNAGE_SYMBOL_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
316
//                        null,
317
//                        null
318
//                );
319
//                // Extend the LineSymbol base definition
320
//                definition.extend(manager.getDefinition(AbstractSymbol.SYMBOL_PERSISTENCE_DEFINITION_NAME));
321
//                
322
//                definition.addDynFieldDouble(FIELD_WIDTH).setMandatory(false);
323
//                definition.addDynFieldInt(FIELD_CONTINUITY).setMandatory(false);
324
//                definition.addDynFieldObject(FIELD_SEGMENTS_COLOR).setClassOfValue(Color.class).setMandatory(false);
325
//                definition.addDynFieldDouble(FIELD_SEGMENTS_LENGTH).setMandatory(false);
326
//                definition.addDynFieldObject(FIELD_HOLES_COLOR).setClassOfValue(Color.class).setMandatory(false);
327
//                definition.addDynFieldDouble(FIELD_HOLES_LENGTH).setMandatory(false);
328
//                definition.addDynFieldBoolean(FIELD_PAINT_HOLES).setMandatory(false);
329
//                definition.addDynFieldDouble(FIELD_GAP_WIDTH).setMandatory(false);
330
//                definition.addDynFieldBoolean(FIELD_ROUND_VERTEX).setMandatory(false);
331
//                definition.addDynFieldDouble(FIELD_TRANSPARENCY).setMandatory(false);
332
//                definition.addDynFieldBoolean(FIELD_MUST_DRAW_ORIGINAL_GEOMETRY).setMandatory(false);
333
//                definition.addDynFieldObject(FIELD_COLOR_FOR_ORIGINAL_GEOMETRY).setClassOfValue(Color.class).setMandatory(false);
334
//            }
335
//            return Boolean.TRUE;
336
//        }
337
//
338
//    }
339

  
340
    public static class RegisterSymbol implements Callable {
341

  
342
        @Override
343
        public Object call() throws Exception {
344
            int[] shapeTypes;
345
            SymbolManager manager = MapContextLocator.getSymbolManager();
346

  
347
            shapeTypes = new int[]{Geometry.TYPES.CURVE, Geometry.TYPES.ARC,
348
                Geometry.TYPES.MULTICURVE, Geometry.TYPES.CIRCUMFERENCE,
349
                Geometry.TYPES.PERIELLIPSE, Geometry.TYPES.SPLINE,
350
                Geometry.TYPES.LINE, Geometry.TYPES.MULTILINE};
351
            manager.registerSymbol(SYMBOL_NAME,
352
                    shapeTypes,
353
                    UrbanHorizontalSignageSymbol.class);
354

  
355
            return Boolean.TRUE;
356
        }
357

  
358
    }
359

  
360
}
org.gvsig.legend.urbanhorizontalsignage/tags/org.gvsig.legend.urbanhorizontalsignage-1.0.104/org.gvsig.legend.urbanhorizontalsignage.lib/org.gvsig.legend.urbanhorizontalsignage.lib.impl/src/main/java/org/gvsig/legend/urbanhorizontalsignage/lib/impl/DefaultUrbanHorizontalSignageManager.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.urbanhorizontalsignage.lib.impl;
24

  
25
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageLegend;
26
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.DefaultUrbanHorizontalSignageData;
27
import org.gvsig.legend.urbanhorizontalsignage.lib.impl.linelegend.SplittedLine;
28
import java.io.File;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.UUID;
32
import org.apache.commons.lang3.StringUtils;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.EditableFeature;
38
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.EditableFeatureType;
40
import org.gvsig.fmap.dal.feature.Feature;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureSet;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
46
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
47
import org.gvsig.fmap.geom.DataTypes;
48
import org.gvsig.fmap.geom.Geometry;
49
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_MITRE;
50
import static org.gvsig.fmap.geom.Geometry.JOIN_STYLE_ROUND;
51
import org.gvsig.fmap.geom.GeometryLocator;
52
import org.gvsig.fmap.geom.GeometryManager;
53
import org.gvsig.fmap.geom.GeometryUtils;
54
import org.gvsig.fmap.geom.aggregate.MultiLine;
55
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
56
import org.gvsig.fmap.geom.exception.CreateGeometryException;
57
import org.gvsig.fmap.geom.operation.GeometryOperationException;
58
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
59
import org.gvsig.fmap.geom.primitive.Line;
60
import org.gvsig.fmap.geom.primitive.Point;
61
import org.gvsig.fmap.geom.primitive.Polygon;
62
import org.gvsig.fmap.geom.type.GeometryType;
63
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageConfig;
64
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData;
65
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT;
66
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT_CONT;
67
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_CONT_DISC;
68
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC;
69
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_CONT;
70
import static org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageData.CONTINUITY_MODE_DISC_DISC;
71
import org.gvsig.legend.urbanhorizontalsignage.lib.api.linelegend.UrbanHorizontalSignageLegend;
72
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageLocator;
73
import org.gvsig.legend.urbanhorizontalsignage.lib.api.UrbanHorizontalSignageManager;
74
import org.gvsig.tools.ToolsLocator;
75
import org.gvsig.tools.folders.FoldersManager;
76
import org.gvsig.tools.task.SimpleTaskStatus;
77
import org.gvsig.tools.util.HasAFile;
78
import org.slf4j.LoggerFactory;
79

  
80
@SuppressWarnings("UseSpecificCatch")
81
public class DefaultUrbanHorizontalSignageManager implements UrbanHorizontalSignageManager {
82

  
83
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DefaultUrbanHorizontalSignageManager.class);
84

  
85
    @Override
86
    public UrbanHorizontalSignageLegend createUrbanHorizontalSignageLegend() {
87
        return new DefaultUrbanHorizontalSignageLegend();
88
    }
89

  
90
    @Override
91
    public Class<? extends UrbanHorizontalSignageLegend> getUrbanHorizontalSignageLegendClass() {
92
        return DefaultUrbanHorizontalSignageLegend.class;
93
    }
94

  
95
    @Override
96
    public UrbanHorizontalSignageData createUrbanHorizontalSignageData() {
97
        return new DefaultUrbanHorizontalSignageData();
98
    }
99

  
100
    @Override
101
    public void calculateGeometries(Geometry originalGeometry, UrbanHorizontalSignageData data) {
102
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
103
        try {
104
            MultiPolygon segments = geomManager.createMultiPolygon(originalGeometry.getGeometryType().getSubType());
105
            MultiPolygon holes = geomManager.createMultiPolygon(originalGeometry.getGeometryType().getSubType());
106
            MultiLine lineSegments = geomManager.createMultiLine(originalGeometry.getGeometryType().getSubType());
107
            MultiLine lineHoles = geomManager.createMultiLine(originalGeometry.getGeometryType().getSubType());
108
            MultiLine lines = originalGeometry.toLines();
109
            final double offsetValueInMeters = Math.abs(data.getGapWidth() / 2.0 + data.getWidth() / 2.0);
110
            final double bufferValueInMeters = Math.abs(data.getWidth() / 2.0);
111
            for (Geometry geom : lines) {
112
                Line line = (Line) geom;
113
                switch (data.getContinuity()) {
114
                    case CONTINUITY_MODE_CONT:
115
                    default:
116
                        Geometry buffer = line.buffer(
117
                                bufferValueInMeters,
118
                                data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
119
                                true
120
                        );
121
                        if (buffer != null) {
122
                            segments.addPrimitives(buffer);
123
                            lineSegments.addPrimitives(line);
124
                        }
125
                        break;
126

  
127
                    case CONTINUITY_MODE_DISC:
128
                        SplittedLine splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
129
                        List<Line> splittedSegments = splittedLine.getSegments();
130
                        List<Line> splittedHoles = splittedLine.getHoles();
131
                        for (Line segment : splittedSegments) {
132
                            buffer = segment.buffer(bufferValueInMeters,
133
                                    data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
134
                                    true
135
                            );
136
                            if (buffer != null) {
137
                                segments.addPrimitives(buffer);
138
                                lineSegments.addPrimitives(segment);
139
                            }
140
                        }
141
                        for (Line hole : splittedHoles) {
142
                            buffer = hole.buffer(
143
                                    bufferValueInMeters,
144
                                    data.isRoundVertex() ? JOIN_STYLE_ROUND : JOIN_STYLE_MITRE,
145
                                    true
146
                            );
147
                            if (buffer != null) {
148
                                holes.addPrimitives(buffer);
149
                                lineHoles.addPrimitives(hole);
150
                            }
151
                        }
152
                        break;
153

  
154
                    case CONTINUITY_MODE_CONT_CONT:
155
                        //Left
156
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
157
                        //Right
158
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, -offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
159
                        break;
160

  
161
                    case CONTINUITY_MODE_CONT_DISC:
162
                        //Left
163
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
164
                        //Right
165
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
166
                        splittedSegments = splittedLine.getSegments();
167
                        splittedHoles = splittedLine.getHoles();
168
                        for (Line segment : splittedSegments) {
169
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, -offsetValueInMeters, bufferValueInMeters, true);
170
                        }
171
                        for (Line hole : splittedHoles) {
172
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, -offsetValueInMeters, bufferValueInMeters, true);
173
                        }
174
                        break;
175

  
176
                    case CONTINUITY_MODE_DISC_CONT:
177
                        //Left
178
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
179
                        splittedSegments = splittedLine.getSegments();
180
                        splittedHoles = splittedLine.getHoles();
181
                        for (Line segment : splittedSegments) {
182
                            addOffsetedAndBufferedSegment(segments, lineSegments, segment, offsetValueInMeters, bufferValueInMeters, true);
183
                        }
184
                        for (Line hole : splittedHoles) {
185
                            addOffsetedAndBufferedSegment(holes, lineHoles, hole, offsetValueInMeters, bufferValueInMeters, true);
186
                        }
187
                        //Right
188
                        addOffsetedAndBufferedSegment(segments, lineSegments, line, -offsetValueInMeters, bufferValueInMeters, data.isRoundVertex());
189
                        break;
190

  
191
                    case CONTINUITY_MODE_DISC_DISC:
192
                        splittedLine = splitLine(line, data.getSegmentsLength(), data.getHolesLength());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff