Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / PictureLine.java @ 34294

History | View | Annotate | Download (5.07 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.gui.styling;
42

    
43
import java.io.File;
44
import java.io.IOException;
45
import java.net.URISyntaxException;
46

    
47
import org.gvsig.andami.PluginServices;
48
import org.gvsig.andami.messages.NotificationManager;
49
import org.gvsig.fmap.mapcontext.MapContextLocator;
50
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
51
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol;
52
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
53
import org.gvsig.i18n.Messages;
54
import org.gvsig.symbology.SymbologyLocator;
55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IPictureLineSymbol;
56

    
57
/**
58
 * PictureLine initializes the properties that define a
59
 * <b>picture marker symbol</b> and are showed in the tab created by
60
 * PictureMarker which is called simple marker.<p>
61
 * <p>
62
 * Moreover, PictureLine has other methods such as getSymbolClass,getName,
63
 * refreshControls and getLayer.
64
 *
65
 *
66
 *@author jaume dominguez faus - jaume.dominguez@iver.es
67
 */
68
public class PictureLine extends PictureMarker {
69
        public PictureLine(SymbolEditor owner) {
70
                super(owner);
71
                initialize();
72
        }
73
        /**
74
         * Initializes the values in the tab
75
         *
76
         */
77
        private void initialize() {
78
//                tabs.remove(mask);
79
                lblSize.setText(Messages.getText("width")+":");
80
                lblX.setText(Messages.getText("scale")+" X:");
81
                lblY.setText(Messages.getText("scale")+" Y:");
82
                txtX.setMinValue(0.1);
83
                txtX.setMaxValue(Double.POSITIVE_INFINITY);
84
                txtX.setStep(0.1);
85
                txtX.setDouble(1);
86

    
87
                txtY.setMinValue(0.1);
88
                txtY.setMaxValue(Double.POSITIVE_INFINITY);
89
                txtY.setStep(0.1);
90
                txtY.setDouble(1);
91
        }
92

    
93
        public String getName() {
94
                return Messages.getText("picture_line_symbol");
95

    
96
        }
97

    
98
        public void refreshControls(ISymbol layer) {
99
                IPictureLineSymbol sym;
100
                try {
101
                        double size, xScale, yScale;
102
                        String fileName = null, selectionFileName = null;
103

    
104
                        if (layer == null) {
105
                                // initialize defaults
106
                                System.err.println(getClass().getName()+":: should be unreachable code");
107

    
108
                                size = 1D;
109
                                xScale = 1D;
110
                                yScale = 1D;
111
                                fileName = "-";
112
                                selectionFileName = "-";
113
                        } else {
114
                                sym = (IPictureLineSymbol) layer;
115

    
116
                                size = sym.getLineWidth();
117
                                xScale = sym.getXScale();
118
                                yScale = sym.getYScale();
119

    
120
                                fileName = sym.getSource().toURI().getPath();
121
                                selectionFileName = sym.getSelectedSource().toURI().getPath();
122

    
123
                        }
124

    
125
                        setValues(size, xScale, yScale, fileName, selectionFileName);
126
                } catch (IndexOutOfBoundsException ioEx) {
127
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
128
                } catch (ClassCastException ccEx) {
129
                        NotificationManager.addWarning("Illegal casting from " +
130
                                        layer.getClass().getName() + " to IPictureLineSymbol.", ccEx);
131
                } catch (URISyntaxException e) {
132
                        NotificationManager.addWarning("URI Syntax error", e);
133
                }
134
        }
135

    
136
        public ISymbol getLayer() {
137

    
138
                try {
139
                        IPictureLineSymbol layer = null;
140

    
141

    
142
                        if(lblFileName.getText().equals("") )
143
                                layer=null;
144

    
145
                        else {
146
                                layer =  SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),null);
147
                                if (!lblSelFileName.getText().equals("")){
148
                                        layer = SymbologyLocator.getSymbologyManager().createPictureLineSymbol(new File(lblFileName.getText()).toURI().toURL(),new File(lblSelFileName.getText()).toURI().toURL());
149
                                }
150
//                                layer.setIsShapeVisible(true); //true is the default value of this property
151
                                layer.setLineWidth(txtSize.getDouble());
152
                                layer.setXScale(txtX.getDouble());
153
                                layer.setYScale(txtY.getDouble());
154
                        }
155

    
156
                        return layer;
157
                } catch (IOException e) {
158
                        IWarningSymbol warning =
159
                                (IWarningSymbol) MapContextLocator.getSymbolManager()
160
                                .getWarningSymbol(
161
                                                SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
162
                                                Messages.getText("failed_acessing_files"),
163
                                                SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
164
                        return warning;
165

    
166
                }
167

    
168
        }
169
        
170
        public boolean canManageSymbol(ISymbol symbol) {
171
                return symbol instanceof IPictureLineSymbol;
172
        }
173

    
174
}