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 @ 42026

History | View | Annotate | Download (4.78 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.io.File;
27
import java.io.IOException;
28
import java.net.URISyntaxException;
29

    
30
import org.gvsig.andami.messages.NotificationManager;
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

    
39
/**
40
 * PictureLine initializes the properties that define a
41
 * <b>picture marker symbol</b> and are showed in the tab created by
42
 * PictureMarker which is called simple marker.<p>
43
 * <p>
44
 * Moreover, PictureLine has other methods such as getSymbolClass,getName,
45
 * refreshControls and getLayer.
46
 *
47
 *
48
 *@author jaume dominguez faus - jaume.dominguez@iver.es
49
 */
50
public class PictureLine extends PictureMarker {
51
        public PictureLine(SymbolEditor owner) {
52
                super(owner);
53
                initialize();
54
        }
55
        /**
56
         * Initializes the values in the tab
57
         *
58
         */
59
        private void initialize() {
60
//                tabs.remove(mask);
61
                lblSize.setText(Messages.getText("width")+":");
62
                lblX.setText(Messages.getText("scale")+" X:");
63
                lblY.setText(Messages.getText("scale")+" Y:");
64
                txtX.setMinValue(0.1);
65
                txtX.setMaxValue(Double.POSITIVE_INFINITY);
66
                txtX.setStep(0.1);
67
                txtX.setDouble(1);
68

    
69
                txtY.setMinValue(0.1);
70
                txtY.setMaxValue(Double.POSITIVE_INFINITY);
71
                txtY.setStep(0.1);
72
                txtY.setDouble(1);
73
        }
74

    
75
        public String getName() {
76
                return Messages.getText("picture_line_symbol");
77

    
78
        }
79

    
80
        public void refreshControls(ISymbol layer) {
81
                IPictureLineSymbol sym;
82
                try {
83
                        double size, xScale, yScale;
84
                        String fileName = null, selectionFileName = null;
85

    
86
                        if (layer == null) {
87
                                // initialize defaults
88
                                System.err.println(getClass().getName()+":: should be unreachable code");
89

    
90
                                size = 1D;
91
                                xScale = 1D;
92
                                yScale = 1D;
93
                                fileName = "-";
94
                                selectionFileName = "-";
95
                        } else {
96
                                sym = (IPictureLineSymbol) layer;
97

    
98
                                size = sym.getLineWidth();
99
                                xScale = sym.getXScale();
100
                                yScale = sym.getYScale();
101

    
102
                                fileName = sym.getSource().toURI().getPath();
103
                                selectionFileName = sym.getSelectedSource().toURI().getPath();
104

    
105
                        }
106

    
107
                        setValues(size, xScale, yScale, fileName, selectionFileName);
108
                } catch (IndexOutOfBoundsException ioEx) {
109
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
110
                } catch (ClassCastException ccEx) {
111
                        NotificationManager.addWarning("Illegal casting from " +
112
                                        layer.getClass().getName() + " to IPictureLineSymbol.", ccEx);
113
                } catch (URISyntaxException e) {
114
                        NotificationManager.addWarning("URI Syntax error", e);
115
                }
116
        }
117

    
118
        public ISymbol getLayer() {
119

    
120
                try {
121
                        IPictureLineSymbol layer = null;
122

    
123

    
124
                        if(lblFileName.getText().equals("") )
125
                                layer=null;
126

    
127
                        else {
128
                                layer =  SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),null);
129
                                if (!lblSelFileName.getText().equals("")){
130
                                        layer = SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),new File(lblSelFileName.getText()).toURI().toURL());
131
                                }
132
//                                layer.setIsShapeVisible(true); //true is the default value of this property
133
                                layer.setLineWidth(txtSize.getDouble());
134
                                layer.setXScale(txtX.getDouble());
135
                                layer.setYScale(txtY.getDouble());
136
                        }
137

    
138
                        return layer;
139
                } catch (IOException e) {
140
                        IWarningSymbol warning =
141
                                (IWarningSymbol) MapContextLocator.getSymbolManager()
142
                                .getWarningSymbol(
143
                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
144
                                                Messages.getText("failed_acessing_files"),
145
                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
146
                        return warning;
147

    
148
                }
149

    
150
        }
151
        
152
        public boolean canManageSymbol(ISymbol symbol) {
153
                return symbol instanceof IPictureLineSymbol;
154
        }
155

    
156
}