Revision 45527

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/legend/gui/SingleSymbol.java
36 36
import javax.swing.JPanel;
37 37
import javax.swing.JTextField;
38 38
import javax.swing.border.TitledBorder;
39
import org.apache.commons.lang3.mutable.MutableObject;
39 40

  
40 41
import org.gvsig.andami.IconThemeHelper;
41 42
import org.gvsig.andami.PluginServices;
42 43
import org.gvsig.andami.messages.NotificationManager;
44
import org.gvsig.app.gui.styling.AbstractTypeSymbolEditor;
43 45
import org.gvsig.app.gui.styling.SymbolLevelsWindow;
44 46
import org.gvsig.app.gui.styling.SymbolPreviewer;
45 47
import org.gvsig.app.gui.styling.SymbolSelector;
46 48
import org.gvsig.fmap.dal.exception.ReadException;
49
import org.gvsig.fmap.dal.feature.Feature;
47 50
import org.gvsig.fmap.dal.feature.FeatureStore;
48 51
import org.gvsig.fmap.mapcontext.MapContextLocator;
49 52
import org.gvsig.fmap.mapcontext.layers.FLayer;
......
71 74
	private JButton btnOpenSymbolLevelsEditor;
72 75
	private SingleSymbolLegend legend;
73 76
	private ZSort zSort;
74
    private FeatureStore featureStore;
77
        private FeatureStore featureStore;
78
        private transient MutableObject<Feature> sampleFeature;
75 79

  
76 80

  
77 81
	public SingleSymbol() {
......
97 101
			NotificationManager.addError("Could not find out the shape type" ,e);
98 102
		}
99 103
                if( lyr instanceof FLyrVect ) {
100
                    this.featureStore = ((FLyrVect) lyr).getFeatureStore();
104
                    this.setFeatureStore(((FLyrVect) lyr).getFeatureStore());
101 105
                }
102 106
		if (legend instanceof SingleSymbolLegend) {
103 107
			setSymbol(legend.getDefaultSymbol());
......
204 208

  
205 209
	private SymbolPreviewer getSymbolPreviewPanel() {
206 210
		if (symbolPreviewComponent == null) {
207
			symbolPreviewComponent = new SymbolPreviewer();
211
			symbolPreviewComponent = new SymbolPreviewer(this.getSampleFeature());
208 212
			symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1));
209 213
			symbolPreviewComponent.setPreferredSize(new Dimension(150, 75));
210 214
		}
......
283 287
		}
284 288
	}
285 289

  
290
        public void setFeatureStore(FeatureStore store) {
291
            this.featureStore = store;
292
            if( this.featureStore!=null ) {
293
                this.sampleFeature.setValue(this.featureStore.getSampleFeature());
294
            }
295
        }
296
        
297
        public MutableObject<Feature> getSampleFeature() {
298
            if( this.sampleFeature == null ) {
299
                this.sampleFeature = new MutableObject();
300
                if( this.featureStore!=null ) {
301
                    this.sampleFeature.setValue(this.featureStore.getSampleFeature());
302
                }
303
            }
304
            return this.sampleFeature;
305
        }
286 306
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestEvaluateDynamicText.java
1 1
package org.gvsig.expresionevaluator.impl;
2 2

  
3 3
import java.io.File;
4
import java.net.MalformedURLException;
5
import java.net.URL;
4 6
import junit.framework.TestCase;
5 7
import org.gvsig.expressionevaluator.SymbolTable;
6 8
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
......
90 92
        assertEquals(source.getAbsolutePath(), s);
91 93
    }
92 94

  
95
    public void testURL() throws Exception {
96
        SymbolTable symbolTable = createSymbolTable();
93 97

  
98
        URL source = new URL("file://tmp/gvsig/<%='nombre-'||precio||'.txt'%>");
99
        URL target = ExpressionUtils.evaluateURL(symbolTable,source);
100
        
101
        assertEquals("file://tmp/gvsig/nombre-200.txt", target.toString());
102
    }
103

  
94 104
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionUtils.java
2 2

  
3 3
import java.awt.Color;
4 4
import java.io.File;
5
import java.net.MalformedURLException;
6
import java.net.URL;
5 7
import java.util.List;
6 8
import java.util.regex.Matcher;
7 9
import java.util.regex.Pattern;
......
208 210
        return evaluateFilename(null, source);
209 211
    }
210 212

  
213
    public static URL evaluateURL(URL source) {
214
        return evaluateURL(null, source);
215
    }
216

  
211 217
    public static boolean isDynamicFilename(File source) {
212 218
        if( source == null ) {
213 219
            return false;
......
215 221
        return isDynamicText(source.getPath());
216 222
    }
217 223

  
224
    public static boolean isDynamicURL(URL source) {
225
        if( source == null ) {
226
            return false;
227
        }
228
        return isDynamicText(source.toString());
229
    }
230

  
218 231
    public static File createDynamicFile(Value builder) {
219 232
        File f = new File(surroundByDynamicTextTag(builder.toString()));
220 233
        return f;
......
227 240
    
228 241
    @SuppressWarnings("StringEquality")
229 242
    public static File evaluateFilename(SymbolTable symbolTable, File source) {
243
        String src =  source.getPath();
244
        if( !isDynamicText(src) ) {
245
            return source;
246
        }
230 247
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
231
        String src =  source.getPath();
232 248
        String r = manager.evaluateDynamicText(symbolTable, src);
233 249
        if( r == src ) { // !!! I compare that it is the same pointer, it is what I want.
234 250
            return source;
......
237 253
        return f;
238 254
    }
239 255

  
256
    @SuppressWarnings("StringEquality")
257
    public static URL evaluateURL(SymbolTable symbolTable, URL source) {
258
        String src =  source.toString();
259
        if( !isDynamicText(src) ) {
260
            return source;
261
        }
262
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
263
        String r = manager.evaluateDynamicText(symbolTable, src);
264
        if( r == src ) { // !!! I compare that it is the same pointer, it is what I want.
265
            return source;
266
        }
267
        try {
268
            URL url = new URL(r);
269
            return url;
270
        } catch (MalformedURLException ex) {
271
            return source;
272
        }
273
    }
274

  
240 275
    public static int parseInt(String s) throws NumberFormatException {
241 276
        if( StringUtils.isBlank(s) ) {
242 277
            throw new NumberFormatException("Can't get integer from a blank string.");
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/DefaultExpressionEvaluatorSwingManager.java
18 18
import javax.swing.text.JTextComponent;
19 19
import org.apache.commons.io.FilenameUtils;
20 20
import org.apache.commons.lang3.StringUtils;
21
import org.apache.commons.lang3.tuple.ImmutablePair;
22
import org.apache.commons.lang3.tuple.Pair;
21 23
import org.gvsig.expressionevaluator.ExpressionUtils;
22 24
import org.gvsig.expressionevaluator.Function;
23 25
import org.gvsig.expressionevaluator.SymbolTable;
......
40 42
import org.gvsig.expressionevaluator.swing.impl.elements.DefaultFunctionElement;
41 43
import org.gvsig.expressionevaluator.swing.impl.elements.DefaultGroupElement;
42 44
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dataTypes.DataType;
44 45
import org.gvsig.tools.i18n.I18nManager;
45 46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46 47
import org.gvsig.tools.swing.api.windowmanager.Dialog;
......
186 187
        Action action = new CreateJExpressionBuilderAction(jtext);
187 188
        return action;
188 189
    }
190

  
191
    @Override
192
    public Action createUniqueTemporalFileAction(JTextComponent jtext, String filename, String fileExtension) {
193
        return this.createUniqueTemporalFileAction(jtext, new ImmutablePair(filename, fileExtension));
194
    }
195

  
196
    @Override
197
    public Action createUniqueTemporalFileAction(JTextComponent jtext, Pair<String, String> nameAndExtension) {
198
        I18nManager i18nManager = ToolsLocator.getI18nManager();
199
        Action uniqueTemporalFileAction = new AbstractAction(
200
                i18nManager.getTranslation("_Temporal_file_path")) {
201
                @Override
202
                public void actionPerformed(ActionEvent e) {
203
                    String fileExtension = nameAndExtension.getRight();
204
                    if( !StringUtils.startsWith(fileExtension, ".") ) {
205
                        fileExtension = "."+fileExtension;
206
                    }
207
                    if (jtext.isEditable() && jtext.isEnabled()) {
208
                        jtext.setText("<%=UNIQUETEMPORARYFILE('" + nameAndExtension.getLeft() + fileExtension + "')%>");
209
                    }
210
                }
211
            };
212
        return uniqueTemporalFileAction;
213
    }
189 214
    
190 215
    public JExpressionBuilder createJExpressionBuilder(ExpressionBuilderConfig config) {
191 216
        DefaultJExpressionBuilder x = new DefaultJExpressionBuilder(
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/ExpressionEvaluatorSwingManager.java
7 7
import javax.swing.Action;
8 8
import javax.swing.JButton;
9 9
import javax.swing.text.JTextComponent;
10
import org.apache.commons.lang3.tuple.Pair;
10 11
import org.gvsig.expressionevaluator.Function;
11 12
import org.gvsig.expressionevaluator.SymbolTable;
12 13
import org.gvsig.expressionevaluator.swing.Element.ConstantElement;
......
15 16

  
16 17
public interface ExpressionEvaluatorSwingManager {
17 18

  
19
    public interface FileNameAndExtension {
20
        
21
    }
18 22
    
19 23
    public List<Element> createElements(Collection<SymbolTable> symbolTables, Predicate<Function> isAllowed);
20 24
    
......
26 30
    
27 31
    public Action createJExpressionBuilderAction(JTextComponent jtext);
28 32
    
33
    public Action createUniqueTemporalFileAction(JTextComponent jtext, String filename, String fileExtension);
34
    
35
    public Action createUniqueTemporalFileAction(JTextComponent jtext, Pair<String,String> nameAndExtension);
36
    
29 37
    public JExpressionPicker createJExpressionPicker();
30 38

  
31 39
    public void registerElement(ElementFactory factory);
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.api/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/marker/IPictureMarkerSymbol.java
23 23
 */
24 24
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker;
25 25

  
26
import java.awt.Color;
27 26
import java.io.IOException;
28 27
import java.net.URL;
29
import org.gvsig.fmap.dal.feature.Feature;
30 28

  
31
public interface IPictureMarkerSymbol extends IMarkerSymbol {
29
public interface IPictureMarkerSymbol extends IMarkerSymbol_v2 {
32 30

  
33 31
    /**
34 32
     * Sets the file for the image to be used as a marker symbol
35 33
     *
36
     * @param imageFile , File
34
     * @param imageUrl
37 35
     * @throws IOException
38 36
     */
39 37
    public abstract void setImage(URL imageUrl) throws IOException;
......
42 40
     * Sets the file for the image to be used as a marker symbol (when it is
43 41
     * selected in the map)
44 42
     *
45
     * @param imageFile , File
43
     * @param imageFileUrl
46 44
     * @throws IOException
47 45
     */
48 46
    public abstract void setSelImage(URL imageFileUrl) throws IOException;
49 47

  
50
    // public void print(Graphics2D g, AffineTransform at, FShape shape)
51
    // throws ReadDriverException {
52
    // // TODO Implement it
53
    // throw new Error("Not yet implemented!");
54
    //
55
    // }
56 48
    /**
57 49
     * Returns the URL of the image that is used as a marker symbol
58 50
     *
......
68 60
     */
69 61
    public abstract URL getSelectedSource();
70 62

  
71
    public String getOffsetXExpression();
72

  
73
    public void setOffsetXExpression(String offsetXExpression);
74

  
75
    public String getOffsetYExpression();
76

  
77
    public void setOffsetYExpression(String offsetYExpression);
78

  
79
    public String getRotationExpression();
80

  
81
    public void setRotationExpression(String rotationExpression);
82

  
83
    public Color getLineToOffsetColor();
84

  
85
    public Color getLineToOffsetColor(Feature f);
86

  
87
    public String getLineToOffsetColorExpression();
88

  
89
    public void setLineToOffsetColorExpression(String lineToOffsetColorExpression);
90

  
91
    public void setLineToOffsetColor(Color lineToOffsetColor);
92

  
93
    public boolean isDrawLineToOffset();
94

  
95
    public boolean isDrawLineToOffset(Feature f);
96

  
97
    public void setDrawLineToOffset(boolean drawLineToOffset);
98

  
99 63
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.api/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/marker/IMarkerSymbol_v2.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker;
23

  
24
import java.awt.Color;
25
import java.awt.geom.Point2D;
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
28

  
29
/**
30
 *
31
 * @author gvSIG Team
32
 */
33
public interface IMarkerSymbol_v2 extends IMarkerSymbol, ISymbol_v2 {
34

  
35
    Color getEfectiveLineToOffsetColor(Feature f);
36

  
37
    Point2D getEfectiveOffset(Feature f);
38

  
39
    double getEfectiveRotationInDegres(Feature f);
40

  
41
    double getEfectiveRotationInRadians(Feature f);
42

  
43
    double getEfectiveSize(Feature f);
44

  
45
    Color getLineToOffsetColor();
46

  
47
    String getLineToOffsetColorExpression();
48

  
49
    String getOffsetXExpression();
50

  
51
    String getOffsetYExpression();
52

  
53
    String getRotationExpression();
54

  
55
    String getSizeExpression();
56

  
57
    public boolean isDrawLineToOffset();
58

  
59
    void setDrawLineToOffset(boolean drawLineToOffset);
60

  
61
    
62
    void setLineToOffsetColor(Color color);
63

  
64
    void setLineToOffsetColorExpression(String lineToOffsetColorExpression);
65

  
66
    void setOffsetXExpression(String offsetXExpression);
67

  
68
    void setOffsetYExpression(String offsetYExpression);
69

  
70
    void setRotationExpression(String rotationExpression);
71

  
72
    void setSizeExpression(String sizeExpression);
73
    
74
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/BackgroundFileStyle.java
30 30
import java.io.IOException;
31 31
import java.net.MalformedURLException;
32 32
import java.net.URL;
33
import org.gvsig.expressionevaluator.SymbolTable;
33 34

  
34 35
import org.gvsig.fmap.mapcontext.MapContextLocator;
35 36
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
......
68 69
        return bgImage;
69 70
    }
70 71
    protected URL source;
72
    protected SymbolTable symbolTable;
71 73
    /**
72 74
     * Sets the file that is used as a source to create the Background
73 75
     * @param f, File
......
131 133
    	return source.toString().substring(getSymbolLibraryURL().toString().length());
132 134
    }
133 135

  
136
    @Override
137
    public void setSymbolTable(SymbolTable symbolTable) {
138
        this.symbolTable = symbolTable;
139
    }
140

  
141
    
134 142
    public static class RegisterPersistence implements Callable {
135 143

  
136 144
        public Object call() throws Exception {
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/ImageStyle.java
30 30
import java.awt.image.BufferedImage;
31 31
import java.io.IOException;
32 32
import java.net.URL;
33
import java.util.Objects;
33 34

  
34 35
import javax.imageio.ImageIO;
36
import org.apache.commons.collections4.map.LRUMap;
37
import org.gvsig.expressionevaluator.ExpressionUtils;
38
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable;
39
import static org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable.SYMBOL_CURRENT_ROW;
35 40

  
36 41
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
37 42
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
......
55 60
    public static final String IMAGE_STYLE_PERSISTENCE_DEFINITION_NAME = "ImageStyle";
56 61
    private static final String SOURCE = "source";
57 62

  
63
    private static  BufferedImage imageNotFound = null;
64
    private static LRUMap<URL, BufferedImage> cachedImages = null;
65
    
58 66
    private BufferedImage img;
59 67

  
68
    private URL getEfectiveURL() {
69
        if( !ExpressionUtils.isDynamicURL(source) ) {
70
            return source;
71
        }
72
        try {
73
            return ExpressionUtils.evaluateURL(this.symbolTable, this.source);
74
        } catch(Exception ex) {
75
            return null;
76
        }
77
    }
78

  
79
    private BufferedImage getEfectiveImage() {
80
        if (!ExpressionUtils.isDynamicURL(this.source)) {
81
            if (this.img == null) {
82
                try {
83
                    this.img = ImageIO.read(this.source);
84
                } catch (IOException ex) {
85
                    LOGGER.warn("Can't load image from url (" + Objects.toString(this.source) + ")", ex);
86
                }
87
            }
88
            return this.img;
89
        }
90
        URL url = this.getEfectiveURL();
91
        if( url == null ) {
92
            return null;
93
        }
94
        if (cachedImages == null) {
95
            cachedImages = new LRUMap<>(20);
96
        }
97
        BufferedImage theImage = cachedImages.get(url);
98
        if (theImage == null) {
99
            try {
100
                theImage = ImageIO.read(url);
101
                cachedImages.put(url, theImage);
102
            } catch (IOException ex) {
103
                theImage = this.getImageNotFound();
104
            }
105
        }
106
        return theImage;
107
    }
108
    
109
    private BufferedImage getImageNotFound() {
110
        if( imageNotFound==null ) {
111
            URL url = this.getClass().getResource("imageStyle-filenotfound.png");
112
            if( url == null ) {
113
                return null;
114
            }
115
            try {
116
                imageNotFound = ImageIO.read(url);
117
            } catch (IOException ex) {
118
                imageNotFound = null;
119
            }
120
        } 
121
        return imageNotFound;
122
    }
123

  
60 124
    /**
125
     * Defines the source (file) from where the buffered image will be taken.
126
     *
127
     * @param url
128
     */
129
    @Override
130
    public void setSource(URL url) throws IOException {
131
        this.source = url;
132
        this.img = null;
133
    }
134

  
135
    /**
61 136
     * Creates a rectangle with the dimensions of the buffered image
62 137
     *
63 138
     * @return Rectangle
64 139
     */
65 140
    @Override
66 141
    public Rectangle getBounds() {
67
        if (img == null) {
142
        if (getEfectiveImage() == null) {
68 143
            return new Rectangle();
69 144
        }
70 145
        return new Rectangle(new Dimension(img.getWidth(), img.getHeight()));
71 146
    }
72 147

  
73
    /**
74
     * Defines the source (file) from where the buffered image will be taken.
75
     *
76
     * @param url
77
     */
78 148
    @Override
79
    public void setSource(URL url) throws IOException {
80
        source = url;
81
        img = ImageIO.read(url);
82
    }
83

  
84
    @Override
85 149
    public void drawInsideRectangle(Graphics2D g, Rectangle r, boolean keepAspectRatio) {
86
        if (img != null) {
150
        BufferedImage theImage = getEfectiveImage();
151
        if (theImage != null) {
87 152

  
88 153
            double xOffset = 0;
89 154
            double yOffset = 0;
......
93 158
            double yScale = 1;
94 159
            if (keepAspectRatio) {
95 160
                double scale;
96
                if (img.getWidth() > img.getHeight()) {
97
                    scale = r.getWidth() / img.getWidth();
98
                    yOffset = 0.5 * (r.getHeight() - img.getHeight() * scale);
161
                if (theImage.getWidth() > theImage.getHeight()) {
162
                    scale = r.getWidth() / theImage.getWidth();
163
                    yOffset = 0.5 * (r.getHeight() - theImage.getHeight() * scale);
99 164
                } else {
100
                    scale = r.getHeight() / img.getHeight();
101
                    xOffset = 0.5 * (r.getWidth() - img.getWidth() * scale);
165
                    scale = r.getHeight() / theImage.getHeight();
166
                    xOffset = 0.5 * (r.getWidth() - theImage.getWidth() * scale);
102 167
                }
103 168
                xScale = yScale = scale;
104 169

  
105 170
            } else {
106
                xScale = r.getWidth() / img.getWidth();
107
                yScale = r.getHeight() / img.getHeight();
108
                yOffset = img.getHeight() * 0.5 * yScale;
171
                xScale = r.getWidth() / theImage.getWidth();
172
                yScale = r.getHeight() / theImage.getHeight();
173
                yOffset = theImage.getHeight() * 0.5 * yScale;
109 174

  
110 175
            }
111 176

  
112 177
            AffineTransform at = AffineTransform.getTranslateInstance(xOffset, yOffset);
113 178
            at.concatenate(AffineTransform.getScaleInstance(xScale, yScale));
114
            g.drawRenderedImage(img, at);
179
            g.drawRenderedImage(theImage, at);
115 180
        }
116 181
    }
117 182

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/style/AbstractStyle.java
30 30
import org.gvsig.tools.persistence.PersistentState;
31 31
import org.gvsig.tools.persistence.exception.PersistenceException;
32 32
import org.gvsig.tools.util.Callable;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
33 35

  
34 36
/**
35 37
 * Implements the IStyle interface in order to complete the methods ot the
......
40 42
 */
41 43
public abstract class AbstractStyle implements IStyle {
42 44

  
45
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractStyle.class);
46
    
43 47
    public static final String STYLE_PERSISTENCE_DEFINITION_NAME = "Style";
44 48

  
45 49
    private static final String FIELD_DESCRIPTION = "description";
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/impl/AbstractSymbol.java
25 25

  
26 26
import java.awt.Rectangle;
27 27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.Feature;
28 29
import org.gvsig.fmap.dal.feature.FeatureStore;
29 30

  
30 31
import org.gvsig.fmap.geom.Geometry;
......
49 50
 * considered as the father of all XXXSymbols and will implement all the methods
50 51
 * that these classes had not developed (and correspond with one of the methods
51 52
 * of AbstractSymbol class)
52
 * 
53
 *
53 54
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
54 55
 * @author 2009-     <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
55 56
 */
56 57
public abstract class AbstractSymbol implements ISymbol_v2, CartographicSupport {
57 58

  
58
	private static final Logger LOG = LoggerFactory.getLogger(AbstractSymbol.class);
59
    private static final Logger LOG = LoggerFactory.getLogger(AbstractSymbol.class);
59 60

  
60
	public static final String SYMBOL_PERSISTENCE_DEFINITION_NAME = "Symbol";
61
	
62
	private static final String FIELD_UNIT = "unit";
61
    public static final String SYMBOL_PERSISTENCE_DEFINITION_NAME = "Symbol";
63 62

  
64
	private static final String FIELD_REFERENCE_SYSTEM = "referenceSystem";
63
    private static final String FIELD_UNIT = "unit";
65 64

  
66
	private static final String FIELD_IS_SHAPE_VISIBLE = "isShapeVisible";
65
    private static final String FIELD_REFERENCE_SYSTEM = "referenceSystem";
67 66

  
68
	private static final String FIELD_DESCRIPTION = "description";
67
    private static final String FIELD_IS_SHAPE_VISIBLE = "isShapeVisible";
69 68

  
69
    private static final String FIELD_DESCRIPTION = "description";
70 70

  
71
	private String desc;
72
        private String id; 
73
	private int unit;
74
	private int referenceSystem;
71
    private String desc;
72
    private String id;
73
    private int unit;
74
    private int referenceSystem;
75 75

  
76
	private boolean isShapeVisible = true;
76
    private boolean isShapeVisible = true;
77
    
78
    private transient Feature feature;
77 79

  
78
	public AbstractSymbol() {
79
		super();
80
		SymbolPreferences preferences =
81
				MapContextLocator.getSymbolManager().getSymbolPreferences();
82
		unit =
83
				preferences.getDefaultCartographicSupportMeasureUnit();
84
		referenceSystem =
85
				preferences.getDefaultCartographicSupportReferenceSystem();
86
	}
80
    public AbstractSymbol() {
81
        super();
82
        SymbolPreferences preferences
83
                = MapContextLocator.getSymbolManager().getSymbolPreferences();
84
        unit
85
                = preferences.getDefaultCartographicSupportMeasureUnit();
86
        referenceSystem
87
                = preferences.getDefaultCartographicSupportReferenceSystem();
88
    }
87 89

  
88
	public final void setDescription(String desc) {
89
		this.desc = desc;
90
	}
90
    @Override
91
    public Feature getFeature() {
92
        return this.feature;
93
    }
91 94

  
92
	public final String getDescription() {
93
		return desc;
94
	}
95
    @Override
96
    public void setFeature(Feature feature) {
97
        this.feature = feature;
98
    }
99
    
100
    @Override
101
    public final void setDescription(String desc) {
102
        this.desc = desc;
103
    }
95 104

  
96
        /**
97
         * Set the id ob the symbol (the basename of file)
98
         * 
99
         * @param id 
100
         */
101
	public final void setID(String id) {
102
		this.id = id;
103
	}
105
    @Override
106
    public final String getDescription() {
107
        return desc;
108
    }
104 109

  
105
        /**
106
         * Get the id ob the symbol (the basename of file)
107
         * 
108
         * @param id 
109
         */
110
	public final String getID() {
111
		return id;
112
	}
110
    @Override
111
    public final void setID(String id) {
112
        this.id = id;
113
    }
113 114

  
114
        
115
	/**
116
	 * @return
117
	 * @uml.property name="isShapeVisible"
118
	 */
119
	public final boolean isShapeVisible() {
120
		return isShapeVisible;
121
	}
115
    @Override
116
    public final String getID() {
117
        return id;
118
    }
122 119

  
123
	/**
124
	 * Sets this symbol to visible
125
	 * 
126
	 * @param isShapeVisible
127
	 */
128
	public final void setIsShapeVisible(boolean isShapeVisible) {
129
		this.isShapeVisible = isShapeVisible;
130
	}
120
    @Override
121
    public final boolean isShapeVisible() {
122
        return isShapeVisible;
123
    }
131 124

  
132
	public void setUnit(int unitIndex) {
133
		this.unit = unitIndex;
134
	}
125
    /**
126
     * Sets this symbol to visible
127
     *
128
     * @param isShapeVisible
129
     */
130
    public final void setIsShapeVisible(boolean isShapeVisible) {
131
        this.isShapeVisible = isShapeVisible;
132
    }
135 133

  
136
	public int getUnit() {
137
		return this.unit;
138
	}
134
    @Override
135
    public void setUnit(int unitIndex) {
136
        this.unit = unitIndex;
137
    }
139 138

  
140
	public int getReferenceSystem() {
141
		return this.referenceSystem;
142
	}
139
    @Override
140
    public int getUnit() {
141
        return this.unit;
142
    }
143 143

  
144
	public void setReferenceSystem(int system) {
145
		this.referenceSystem = system;
144
    @Override
145
    public int getReferenceSystem() {
146
        return this.referenceSystem;
147
    }
146 148

  
147
	}
148
	
149
	private boolean areEquals(Object a,Object b) {
150
		if( a==null ) {
151
			if( b==null) {
152
				return true;
153
			}
154
			return false;
155
		} else {
156
			if( b == null ) {
157
				return false;
158
			}
159
		}
160
		return a.equals(b);
161
	}
149
    @Override
150
    public void setReferenceSystem(int system) {
151
        this.referenceSystem = system;
162 152

  
163
	public boolean equals(Object obj) {
164
		ISymbol other = null;
165
		
166
		if( obj==null ) {
167
			return false;
168
		}
169
		if( ! areEquals(obj.getClass(),this.getClass()) ) {
170
			// El try/catch y la salida al log es una medida
171
			// temporal hasta que averiguemos quien causa que
172
			// pase por aqui, ya que no parece razonable que 
173
			// desde gvSIG se invoque con algo que no sea un ISymbol.
174
			try {
175
				other = (ISymbol) obj;
176
			} catch(Exception ex) {
177
				LOG.warn("Suspicious comparison between ISymbol and '"+obj.getClass().getName()+"'.",ex);
178
			}
179
			return false;
180
		}
181
		
182
		other = (ISymbol) obj;
183
		
184
		if( ! areEquals(other.getColor(),this.getColor()) ) {
185
			return false;
186
		}
187
		if( other.getOnePointRgb() != this.getOnePointRgb()) {
188
			return false;
189
		}
190
		if( ! areEquals(other.getDescription(),this.getDescription()) ) {
191
			return false;
192
		}
193
		return true;
194
	}
153
    }
195 154

  
196
	public boolean isOneDotOrPixel(Geometry geom,
197
			double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
155
    private boolean areEquals(Object a, Object b) {
156
        if (a == null) {
157
            if (b == null) {
158
                return true;
159
            }
160
            return false;
161
        } else {
162
            if (b == null) {
163
                return false;
164
            }
165
        }
166
        return a.equals(b);
167
    }
198 168

  
199
		int type = geom.getType();
200
		switch (type) {
201
		case Geometry.TYPES.NULL:
202
		case Geometry.TYPES.POINT:
203
		case Geometry.TYPES.MULTIPOINT:
204
			return false;
205
		default:
206
			org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom
207
			.getEnvelope();
169
    @Override
170
    @SuppressWarnings("UnusedAssignment")
171
    public boolean equals(Object obj) {
172
        ISymbol other = null;
208 173

  
209
			double dist1Pixel = viewPort.getDist1pixel();
174
        if (obj == null) {
175
            return false;
176
        }
177
        if (!areEquals(obj.getClass(), this.getClass())) {
178
            // El try/catch y la salida al log es una medida
179
            // temporal hasta que averiguemos quien causa que
180
            // pase por aqui, ya que no parece razonable que 
181
            // desde gvSIG se invoque con algo que no sea un ISymbol.
182
            try {
183
                other = (ISymbol) obj;
184
            } catch (Exception ex) {
185
                LOG.warn("Suspicious comparison between ISymbol and '" + obj.getClass().getName() + "'.", ex);
186
            }
187
            return false;
188
        }
210 189

  
211
			float[] distances = new float[2];
212
			this.getPixExtentPlus(geom, distances, viewPort, dpi);
190
        other = (ISymbol) obj;
213 191

  
214
			boolean onePoint =
215
					(geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds
216
					.getLength(1)
217
					+ distances[1] <= dist1Pixel);
192
        if (!areEquals(other.getColor(), this.getColor())) {
193
            return false;
194
        }
195
        if (other.getOnePointRgb() != this.getOnePointRgb()) {
196
            return false;
197
        }
198
        if (!areEquals(other.getDescription(), this.getDescription())) {
199
            return false;
200
        }
201
        return true;
202
    }
218 203

  
219
			if (onePoint) {
220
				Rectangle bounds = geom.getShape().getBounds();
221
				positionOfDotOrPixel[0] = bounds.x;
222
				positionOfDotOrPixel[1] = bounds.y;
223
			}
224
			return onePoint;
225
		}
226
	}
204
    @Override
205
    public boolean isOneDotOrPixel(Geometry geom,
206
            double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
227 207

  
228
	public Object clone() throws CloneNotSupportedException {
229
		return super.clone();	
230
	}
208
        int type = geom.getType();
209
        switch (type) {
210
            case Geometry.TYPES.NULL:
211
            case Geometry.TYPES.POINT:
212
            case Geometry.TYPES.MULTIPOINT:
213
                return false;
214
            default:
215
                org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom
216
                        .getEnvelope();
231 217

  
232
	protected ISymbol cloneForSelection() {
233
		try {
234
			ISymbol selectionSymbol = (ISymbol) clone();
235
			selectionSymbol.setColor(MapContext.getSelectionColor());
236
			if (getDescription() != null){
237
				selectionSymbol.setDescription(getDescription().concat(
238
				" version for selection"));
239
			}else{
240
				selectionSymbol.setDescription("version for selection");
241
			}
242
			return selectionSymbol;
243
		} catch (CloneNotSupportedException e) {
244
			LOG.error(
245
					"Error creating the selection symbol for the symbol "
246
					+ this, e);
247
		}
248
		return null;
249
	}
218
                double dist1Pixel = viewPort.getDist1pixel();
250 219

  
251
	public void loadFromState(PersistentState state)
252
			throws PersistenceException {
253
		setDescription(state.getString(FIELD_DESCRIPTION));
254
		setIsShapeVisible(state.getBoolean(FIELD_IS_SHAPE_VISIBLE));
255
		setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM));
256
		setUnit(state.getInt(FIELD_UNIT));
257
	}
220
                float[] distances = new float[2];
221
                this.getPixExtentPlus(geom, distances, viewPort, dpi);
258 222

  
259
	public void saveToState(PersistentState state) throws PersistenceException {
260
		state.set(FIELD_DESCRIPTION, getDescription());
261
		state.set(FIELD_IS_SHAPE_VISIBLE, isShapeVisible());
262
		state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem());
263
		state.set(FIELD_UNIT, getUnit());
264
	}
223
                boolean onePoint
224
                        = (geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds
225
                        .getLength(1)
226
                        + distances[1] <= dist1Pixel);
265 227

  
266
	public static class RegisterPersistence implements Callable {
228
                if (onePoint) {
229
                    Rectangle bounds = geom.getShape().getBounds();
230
                    positionOfDotOrPixel[0] = bounds.x;
231
                    positionOfDotOrPixel[1] = bounds.y;
232
                }
233
                return onePoint;
234
        }
235
    }
267 236

  
268
		public Object call() throws Exception {
269
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
270
			if( manager.getDefinition(SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
271
				DynStruct definition = manager.addDefinition(
272
						AbstractSymbol.class, 
273
						SYMBOL_PERSISTENCE_DEFINITION_NAME, 
274
						SYMBOL_PERSISTENCE_DEFINITION_NAME+" persistence definition", 
275
						null, 
276
						null
277
				);
278
				// Description
279
				definition.addDynFieldString(FIELD_DESCRIPTION);
280
				// Is Shape Visible
281
				definition.addDynFieldBoolean(FIELD_IS_SHAPE_VISIBLE).setMandatory(true);
282
				// Reference system
283
				definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
284
				// Unit
285
				definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
286
			}
287
			return Boolean.TRUE;
288
		}
289
		
290
	}
237
    @Override
238
    public Object clone() throws CloneNotSupportedException {
239
        return super.clone();
240
    }
291 241

  
292
        public String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
293
            // By default only need the default Geometry
294
            return new String[] { featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName() };            
242
    protected ISymbol cloneForSelection() {
243
        try {
244
            ISymbol selectionSymbol = (ISymbol) clone();
245
            selectionSymbol.setColor(MapContext.getSelectionColor());
246
            if (getDescription() != null) {
247
                selectionSymbol.setDescription(getDescription().concat(
248
                        " version for selection"));
249
            } else {
250
                selectionSymbol.setDescription("version for selection");
251
            }
252
            return selectionSymbol;
253
        } catch (CloneNotSupportedException e) {
254
            LOG.error(
255
                    "Error creating the selection symbol for the symbol "
256
                    + this, e);
295 257
        }
258
        return null;
259
    }
296 260

  
297
}
261
    @Override
262
    public void loadFromState(PersistentState state)
263
            throws PersistenceException {
264
        setDescription(state.getString(FIELD_DESCRIPTION));
265
        setIsShapeVisible(state.getBoolean(FIELD_IS_SHAPE_VISIBLE));
266
        setReferenceSystem(state.getInt(FIELD_REFERENCE_SYSTEM));
267
        setUnit(state.getInt(FIELD_UNIT));
268
    }
269

  
270
    @Override
271
    public void saveToState(PersistentState state) throws PersistenceException {
272
        state.set(FIELD_DESCRIPTION, getDescription());
273
        state.set(FIELD_IS_SHAPE_VISIBLE, isShapeVisible());
274
        state.set(FIELD_REFERENCE_SYSTEM, getReferenceSystem());
275
        state.set(FIELD_UNIT, getUnit());
276
    }
277

  
278
    public static class RegisterPersistence implements Callable {
279

  
280
        @Override
281
        public Object call() throws Exception {
282
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
283
            if (manager.getDefinition(SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) {
284
                DynStruct definition = manager.addDefinition(
285
                        AbstractSymbol.class,
286
                        SYMBOL_PERSISTENCE_DEFINITION_NAME,
287
                        SYMBOL_PERSISTENCE_DEFINITION_NAME + " persistence definition",
288
                        null,
289
                        null
290
                );
291
                // Description
292
                definition.addDynFieldString(FIELD_DESCRIPTION);
293
                // Is Shape Visible
294
                definition.addDynFieldBoolean(FIELD_IS_SHAPE_VISIBLE).setMandatory(true);
295
                // Reference system
296
                definition.addDynFieldInt(FIELD_REFERENCE_SYSTEM).setMandatory(true);
297
                // Unit
298
                definition.addDynFieldInt(FIELD_UNIT).setMandatory(true);
299
            }
300
            return Boolean.TRUE;
301
        }
302

  
303
    }
304

  
305
    public String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException {
306
        // By default only need the default Geometry
307
        return new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()};
308
    }
309

  
310
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/marker/impl/AbstractMarkerSymbol.java
23 23
 */
24 24
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl;
25 25

  
26
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol_v2;
26 27
import java.awt.Color;
27 28
import java.awt.Graphics2D;
28 29
import java.awt.Point;
......
31 32
import java.awt.geom.Point2D;
32 33
import org.apache.commons.lang3.StringUtils;
33 34
import org.gvsig.compat.print.PrintAttributes;
34
import org.gvsig.expressionevaluator.ExpressionBuilder;
35 35
import org.gvsig.expressionevaluator.ExpressionUtils;
36 36
import org.gvsig.expressionevaluator.SymbolTable;
37 37
import org.gvsig.fmap.dal.DALLocator;
......
48 48
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
49 49
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
50 50
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
52 51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask;
53 52
import org.gvsig.tools.ToolsLocator;
54 53
import org.gvsig.tools.dynobject.DynStruct;
......
63 62
 * @author gvSIG team
64 63
 */
65 64
@SuppressWarnings("UseSpecificCatch")
66
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol {
65
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol_v2 {
67 66

  
68 67
    public static final String MARKER_SYMBOL_PERSISTENCE_DEFINITION_NAME = "MarkerSymbol";
69 68

  
......
72 71
    private static final String FIELD_OFFSET = "offset";
73 72
    private static final String FIELD_SIZE = "size";
74 73
    private static final String FIELD_MASK = "mask";
74
    private static final String FIELD_LINETOOFFSETCOLOR = "lineToOffsetColor";
75
    private static final String FIELD_DRAWLINETOOFFSET = "drawLineToOffset";
76
    private static final String FIELD_SIZE_EXPRESSION = "sizeExpression";
75 77
    private static final String FIELD_OFFSETX_EXPRESSION = "offsetXExpression";
76 78
    private static final String FIELD_OFFSETY_EXPRESSION = "offsetYExpression";
77 79
    private static final String FIELD_ROTATION_EXPRESSION = "rotationExpression";
78
    private static final String FIELD_DRAWLINETOOFFSET = "drawLineToOffsetExpression";
79 80
    private static final String FIELD_LINETOOFFSETCOLOR_EXPRESSION = "lineToOffsetColorExpression";
80 81

  
81 82
    private static final GeometryManager GEOMETRY_MANAGER = GeometryLocator.getGeometryManager();
83
    
82 84
    private Color color;
83 85
    private double rotation;
84 86
    private Point2D offset = new Point2D.Double();
85 87
    private double size = 4d;
86 88
    private IMask mask;
87 89

  
90
    private Color lineToOffsetColor;
88 91
    private boolean drawLineToOffset;
89 92

  
93
    private String sizeExpression;
90 94
    private String offsetXExpression;
91 95
    private String offsetYExpression;
92 96
    private String rotationExpression;
93 97
    private String lineToOffsetColorExpression;
98
    
99
    private transient org.gvsig.fmap.geom.primitive.Point point;
94 100

  
95 101
    public AbstractMarkerSymbol() {
96 102
        super();
97 103
        color = MapContextLocator.getSymbolManager()
98 104
                .getSymbolPreferences()
99 105
                .getDefaultSymbolFillColor();
106
        this.lineToOffsetColor = Color.BLACK;
107
        try {
108
            this.point = GEOMETRY_MANAGER.createPoint(0, 0, SUBTYPES.GEOM2D);
109
        } catch (CreateGeometryException ex) {
110
            
111
        }
100 112
    }
101 113

  
114
    protected org.gvsig.fmap.geom.primitive.Point getPoint(double x, double y) {
115
        this.point.setX(x);
116
        this.point.setY(y);
117
        return this.point;
118
    }
119
    
102 120
    @Override
103 121
    public final int getSymbolType() {
104 122
        return Geometry.TYPES.POINT;
105 123
    }
106

  
124
    
107 125
    @Override
108 126
    public double getRotation() {
109 127
        return rotation;
......
129 147

  
130 148
    private FeatureSymbolTable symbolTable = null;
131 149
    
132
    private SymbolTable getSymbolTable(Feature f) {
150
    protected SymbolTable getSymbolTable(Feature f) {
133 151
        if( symbolTable==null ) {
134 152
            this.symbolTable = DALLocator.getManager().createFeatureSymbolTable();
135 153
        }
......
137 155
        return symbolTable;
138 156
    }
139 157
        
158
    @Override
159
    public Color getLineToOffsetColor() {
160
        return this.lineToOffsetColor;
161
    }
162

  
163
    @Override
164
    public void setLineToOffsetColor(Color color) {
165
        this.lineToOffsetColor = color;
166
    }
167

  
168
    @Override
169
    public boolean isDrawLineToOffset() {
170
        return this.drawLineToOffset;
171
    }
172

  
173
    @Override
174
    public void setDrawLineToOffset(boolean drawLineToOffset) {
175
        this.drawLineToOffset = drawLineToOffset;
176
    }
177

  
178
    @Override
140 179
    public String getOffsetXExpression() {
141 180
        return offsetXExpression;
142 181
    }
143 182

  
183
    @Override
144 184
    public void setOffsetXExpression(String offsetXExpression) {
145 185
        this.offsetXExpression = StringUtils.trimToNull(offsetXExpression);
146 186
    }
147 187

  
188
    @Override
148 189
    public String getOffsetYExpression() {
149 190
        return offsetYExpression;
150 191
    }
151 192

  
193
    @Override
152 194
    public void setOffsetYExpression(String offsetYExpression) {
153 195
        this.offsetYExpression = StringUtils.trimToNull(offsetYExpression);
154 196
    }
155 197

  
198
    @Override
156 199
    public String getRotationExpression() {
157 200
        return rotationExpression;
158 201
    }
159 202

  
203
    @Override
160 204
    public void setRotationExpression(String rotationExpression) {
161 205
        this.rotationExpression = StringUtils.trimToNull(rotationExpression);
162 206
    }
163 207

  
164
    public Color getLineToOffsetColor() {
165
        return this.getLineToOffsetColor(null);
208
    @Override
209
    public String getSizeExpression() {
210
        return sizeExpression;
166 211
    }
167 212

  
168
    public Color getLineToOffsetColor(Feature f) {
169
        return ExpressionUtils.parseColor(this.getSymbolTable(f), this.lineToOffsetColorExpression, Color.BLACK);
213
    @Override
214
    public void setSizeExpression(String sizeExpression) {
215
        this.sizeExpression = StringUtils.trimToNull(sizeExpression);
170 216
    }
171 217

  
218
    @Override
172 219
    public String getLineToOffsetColorExpression() {
173 220
        return this.lineToOffsetColorExpression;
174 221
    }
175 222

  
223
    @Override
176 224
    public void setLineToOffsetColorExpression(String lineToOffsetColorExpression) {
177 225
        this.lineToOffsetColorExpression = StringUtils.trimToNull(lineToOffsetColorExpression);
178 226
    }
179 227

  
180
    public void setLineToOffsetColor(Color lineToOffsetColor) {
181
        ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
182
        this.lineToOffsetColorExpression = StringUtils.trimToNull(builder.color(color).toString());
183
    }
184

  
185
    public boolean isDrawLineToOffset() {
186
        return this.isDrawLineToOffset(null);
187
    }
188

  
189
    public boolean isDrawLineToOffset(Feature f) {
190
        return this.drawLineToOffset;
191
    }
192

  
193
    public void setDrawLineToOffset(boolean drawLineToOffset) {
194
        this.drawLineToOffset = drawLineToOffset;
195
    }
196

  
228
    @Override
197 229
    public Point2D getEfectiveOffset(Feature f) {
230
        if( f == null ) {
231
            f = this.getFeature();
232
        }
198 233
        if( f==null || StringUtils.isBlank(this.offsetXExpression) || StringUtils.isBlank(this.offsetYExpression) ) {
199 234
            return this.getOffset();
200 235
        }
201
        int offsetX = ExpressionUtils.parseInt(this.getSymbolTable(f), offsetXExpression, (int) this.getOffset().getX());
202
        int offsetY = ExpressionUtils.parseInt(this.getSymbolTable(f), offsetYExpression, (int) this.getOffset().getY());
236
        int offsetX = ExpressionUtils.parseInt(
237
                this.getSymbolTable(f), 
238
                offsetXExpression, 
239
                (int) this.getOffset().getX()
240
        );
241
        int offsetY = ExpressionUtils.parseInt(
242
                this.getSymbolTable(f), 
243
                offsetYExpression, 
244
                (int) this.getOffset().getY()
245
        );
203 246
        Point p = new Point(offsetX, offsetY);
204 247
        return p;
205 248
    }
206 249

  
207
    public double getEfectiveRotation(Feature f) {
250
    @Override
251
    public double getEfectiveRotationInDegres(Feature f) {
252
        // Por defecto vedra en grados.
253
        if( f == null ) {
254
            f = this.getFeature();
255
        }
208 256
        if( f==null || StringUtils.isBlank(this.rotationExpression) ) {
209 257
            return this.getRotation();
210 258
        }
211
        double r = ExpressionUtils.parseDouble(this.getSymbolTable(f), rotationExpression, this.getRotation());
259
        double r = ExpressionUtils.parseDouble(
260
                this.getSymbolTable(f), 
261
                rotationExpression, 
262
                this.getRotation()
263
        );
212 264
        return r;
213 265
    }
214 266

  
215 267
    @Override
268
    public double getEfectiveRotationInRadians(Feature f) {
269
        // Pillamos el valor por defecto que es en grados y lo transformamos a radianes.
270
        double r = this.getEfectiveRotationInDegres(f);
271
        if( r == 0 ) {
272
            return 0;
273
        }
274
        r = Math.toRadians(r);
275
        return r;
276
    }
277

  
278
    @Override
279
    public Color getEfectiveLineToOffsetColor(Feature f) {
280
        if( f == null ) {
281
            f = this.getFeature();
282
        }
283
        if( f==null || StringUtils.isBlank(this.lineToOffsetColorExpression) ) {
284
            return this.getLineToOffsetColor();
285
        }
286
        Color theColor = ExpressionUtils.parseColor(
287
                this.getSymbolTable(f), 
288
                this.lineToOffsetColorExpression, 
289
                this.getLineToOffsetColor()
290
        );
291
        return theColor;
292
    }
293

  
294
    @Override
295
    public double getEfectiveSize(Feature f) {
296
        if( f == null ) {
297
            f = this.getFeature();
298
        }
299
        if( f==null || StringUtils.isBlank(this.sizeExpression) ) {
300
            return this.getSize();
301
        }
302
        double sz = ExpressionUtils.parseDouble(
303
                this.getSymbolTable(f), 
304
                this.sizeExpression, 
305
                this.getSize()
306
        );
307
        return sz;
308
    }
309

  
310
    @Override
216 311
    public boolean isSuitableFor(Geometry geom) {
217 312
        return geom.getType() == Geometry.TYPES.POINT;
218 313
    }
......
258 353

  
259 354
    @Override
260 355
    public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintAttributes properties) {
261
        double originalSize = getSize();
356
        double originalSize = getEfectiveSize(getFeature());
262 357
        double theSize = originalSize;
263 358
        // scale it to size
264 359
        int pq = properties.getPrintQuality();
......
276 371
                break;
277 372
        }
278 373
//		setSize(theSize);
279
        draw(g, at, geom, null, null);
374
        draw(g, at, geom, getFeature(), null);
280 375
//		setSize(originalSize);
281 376
    }
282 377

  
......
289 384
    public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException {
290 385
        try {
291 386
            if (properties == null) {
292
                draw(g, scaleInstance, GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null, null);
387
                draw(
388
                        g, 
389
                        scaleInstance, 
390
                        this.getPoint(r.getCenterX(), r.getCenterY()),
391
//                        GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), 
392
                        this.getFeature(), 
393
                        null
394
                );
293 395
            } else {
294
                double originalSize = getSize();
396
                double originalSize = getEfectiveSize(getFeature());
295 397
                double theSize = originalSize;
296 398
                int pq = properties.getPrintQuality();
297 399
                switch (pq) {
......
308 410
                        break;
309 411
                }
310 412
                setSize(theSize);
311
                print(g, scaleInstance, GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties);
413
                print(
414
                        g, 
415
                        scaleInstance, 
416
                        this.getPoint(r.getCenterX(), r.getCenterY()),
417
//                        GEOMETRY_MANAGER.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), 
418
                        properties
419
                );
312 420
                setSize(originalSize);
313 421
            }
314 422

  
315
        } catch (CreateGeometryException e) {
423
        } catch (Exception e) {
316 424
            throw new SymbolDrawingException(TYPES.POINT);
317 425
        }
318 426
    }
......
329 437

  
330 438
    @Override
331 439
    public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
332
        double oldSize = getSize();
440
        double oldSize = getEfectiveSize(getFeature());
333 441
        setCartographicSize(getCartographicSize(
334 442
                viewPort,
335 443
                dpi,
......
374 482
        setOffset((Point2D) state.get(FIELD_OFFSET));
375 483
        setRotation(state.getDouble(FIELD_ROTATION));
376 484
        setSize(state.getDouble(FIELD_SIZE));
377

  
378 485
        setDrawLineToOffset(state.getBoolean(FIELD_DRAWLINETOOFFSET, false));
486
        setLineToOffsetColor((Color) state.get(FIELD_LINETOOFFSETCOLOR));
487
        
488
        setSizeExpression(state.getString(FIELD_SIZE_EXPRESSION));
379 489
        setOffsetXExpression(state.getString(FIELD_OFFSETX_EXPRESSION));
380 490
        setOffsetYExpression(state.getString(FIELD_OFFSETY_EXPRESSION));
381 491
        setRotationExpression(state.getString(FIELD_ROTATION_EXPRESSION));
......
392 502
        state.set(FIELD_OFFSET, getOffset());
393 503
        state.set(FIELD_ROTATION, getRotation());
394 504
        state.set(FIELD_SIZE, getSize());
505
        state.set(FIELD_LINETOOFFSETCOLOR, getLineToOffsetColor());
506
        state.set(FIELD_DRAWLINETOOFFSET, isDrawLineToOffset());
395 507

  
396 508
        state.set(FIELD_OFFSETX_EXPRESSION, getOffsetXExpression());
397 509
        state.set(FIELD_OFFSETY_EXPRESSION, getOffsetYExpression());
510
        state.set(FIELD_SIZE_EXPRESSION, getSizeExpression());
398 511
        state.set(FIELD_ROTATION_EXPRESSION, getRotationExpression());
399
        state.set(FIELD_DRAWLINETOOFFSET, isDrawLineToOffset());
400 512
        state.set(FIELD_LINETOOFFSETCOLOR_EXPRESSION, getLineToOffsetColorExpression());
401 513
    }
402 514

  
......
429 541
                definition.addDynFieldDouble(FIELD_ROTATION).setMandatory(false);
430 542

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff