Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / PictureLine.java @ 47476

History | View | Annotate | Download (7.5 KB)

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.app.gui.styling;
25

    
26
import java.awt.Color;
27
import java.awt.geom.Point2D;
28
import java.io.IOException;
29
import java.net.URL;
30
import static org.gvsig.expressionevaluator.ExpressionUtils.getPhrase;
31
import org.gvsig.fmap.mapcontext.MapContextLocator;
32
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
33
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol;
34
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
35
import org.gvsig.i18n.Messages;
36
import org.gvsig.symbology.SymbologyLocator;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
39

    
40
/**
41
 * PictureLine initializes the properties that define a
42
 * <b>picture marker symbol</b> and are showed in the tab created by
43
 * PictureMarker which is called simple marker.<p>
44
 * <p>
45
 * Moreover, PictureLine has other methods such as getSymbolClass,getName,
46
 * refreshControls and getLayer.
47
 *
48
 *
49
 * @author gvSIG Team
50
 */
51
public class PictureLine extends PictureMarker {
52

    
53
    public PictureLine(SymbolEditor owner) {
54
        super(owner);
55
    }
56

    
57
    @Override
58
    protected void initComponents() {
59
        super.initComponents();
60
        
61
        
62
        this.colorLinePicker.setEditable(false);
63
        this.xoffsetExpPicker.setEditable(false);
64
        this.yoffsetExpPicker.setEditable(false);
65
        this.rotationExpPicker.setEditable(false);
66
        this.colorExpPicker.setEditable(false);
67

    
68
        this.view.txtColorLine.setEnabled(false);
69
        this.view.btnColorLine.setEnabled(false);
70
        this.view.txtColorLineExp.setEnabled(false);
71
        this.view.btnColorLineExpression.setEnabled(false);
72
        this.view.btnColorLineExpressionBookmarks.setEnabled(false);
73
        this.view.btnColorLineExpressionHistory.setEnabled(false);
74

    
75
        this.view.txtX.setEnabled(false);
76
        this.view.txtXOffset.setEnabled(false);
77
        this.view.btnXOffsetExpression.setEnabled(false);
78
        this.view.btnXOffsetExpressionBookmarks.setEnabled(false);
79
        this.view.btnXOffsetExpressionHistory.setEnabled(false);
80

    
81
        this.view.txtY.setEnabled(false);
82
        this.view.txtYOffset.setEnabled(false);
83
        this.view.btnYOffsetExpression.setEnabled(false);
84
        this.view.btnYOffsetExpressionBookmarks.setEnabled(false);
85
        this.view.btnYOffsetExpressionHistory.setEnabled(false);
86
        
87
        this.view.txtRotation.setEnabled(false);
88
        this.view.txtRotationExp.setEnabled(false);
89
        this.view.btnRotationExpression.setEnabled(false);
90
        this.view.btnRotationExpressionBookmarks.setEnabled(false);
91
        this.view.btnRotationExpressionHistory.setEnabled(false);
92
        
93
        this.view.chkDrawLineToOffset.setEnabled(false);
94

    
95
    }
96
    
97
    
98

    
99
    @Override
100
    public String getName() {
101
        return Messages.getText("picture_line_symbol");
102
    }
103

    
104
    @Override
105
    public void refreshControls(ISymbol layer) {
106
        try {
107
            if (layer == null) {
108
                setValues(1d, 0d, 0d, null, null, null, null, null, null, null, null, false);
109
            } else {
110
                IPictureLineSymbol sym = (IPictureLineSymbol) layer;
111
                setValues(sym.getLineWidth(), 
112
                        sym.getRotation(), 
113
                        sym.getOffset().getX(), 
114
                        sym.getOffset().getY(), 
115
                        sym.getSource(), 
116
                        sym.getSelectedSource(), 
117
                        sym.getSizeExpression(),
118
                        sym.getOffsetXExpression(), 
119
                        sym.getOffsetYExpression(), 
120
                        sym.getLineToOffsetColor(), 
121
                        sym.getLineToOffsetColorExpression(), 
122
                        sym.getRotationExpression(),
123
                        sym.isDrawLineToOffset()
124
                );
125
            }
126
        } catch (Exception ex) {
127
            LOGGER.warn("Can't refresh picture line symbol panel.", ex);
128
        }
129
            
130
    }
131

    
132
    @Override
133
    protected void setValues(
134
            double size,
135
            double rotation,
136
            double xOffset, 
137
            double yOffset, 
138
            URL picture, 
139
            URL selectedPicture, 
140
            String sizeExpression,
141
            String offsetXExpression, 
142
            String offsetYExpression, 
143
            Color lineToOffsetColor, 
144
            String lineToOffsetColorExpression, 
145
            String rotationExpression,
146
            boolean isDrawLineToOffset) {
147
        
148
        super.setValues(size, rotation, xOffset, yOffset, picture, selectedPicture, sizeExpression, offsetXExpression, offsetYExpression, lineToOffsetColor, lineToOffsetColorExpression, rotationExpression, isDrawLineToOffset);
149
        
150
    }
151

    
152
    @Override
153
    public ISymbol getLayer() {
154
        try {
155
            IPictureLineSymbol layer = null;
156
            if (this.getPictureFile() != null) {
157
                layer = SymbologyLocator.getSymbologyManager().createPictureLineSymbol(
158
                        this.getPictureURL(),
159
                        this.getSelectedPictureURL()
160
                );
161
                layer.setFeature(this.getSampleFeature());
162
                layer.setLineWidth(this.getSize());
163
                layer.setSizeExpression(getPhrase(getSizeExpression()));
164
                layer.setOffset(new Point2D.Double(this.getX(), this.getY()));
165
                layer.setRotation(Math.toRadians(getRotation()));
166
                layer.setRotationExpression(getPhrase(this.getRotationExpression()));
167
                layer.setOffsetXExpression(getPhrase(this.getXOffsetExpression()));
168
                layer.setOffsetYExpression(getPhrase(this.getYOffsetExpression()));
169
                layer.setSizeExpression(getPhrase(getSizeExpression()));
170
                layer.setDrawLineToOffset(isSelectedDrawLineToOffset());
171
                layer.setLineToOffsetColor(this.getLineToOffsetColor());
172
                layer.setLineToOffsetColorExpression(getPhrase(getLineToOffsetColorExpression()));
173
            }
174
            return layer;
175
        } catch (IOException e) {
176
            IWarningSymbol warning
177
                    = (IWarningSymbol) MapContextLocator.getSymbolManager()
178
                            .getWarningSymbol(
179
                                    SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
180
                                    Messages.getText("failed_acessing_files"),
181
                                    SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
182
            return warning;
183

    
184
        }
185

    
186
    }
187

    
188
    @Override
189
    public boolean canManageSymbol(ISymbol symbol) {
190
        return symbol instanceof IPictureMarkerSymbol;
191
    }
192

    
193
}