Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / styling / SimpleLine.java @ 29596

History | View | Annotate | Download (9.82 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

    
42
/* CVS MESSAGES:
43
 *
44
 * $Id: SimpleLine.java 29596 2009-06-29 16:02:00Z jpiera $
45
 * $Log$
46
 * Revision 1.20  2007-08-14 11:10:20  jvidal
47
 * javadoc updated
48
 *
49
 * Revision 1.19  2007/08/08 11:49:15  jaume
50
 * refactored to avoid provide more than one EditorTool
51
 *
52
 * Revision 1.18  2007/08/07 11:19:06  jvidal
53
 * javadoc
54
 *
55
 * Revision 1.17  2007/08/03 11:37:15  jvidal
56
 * javadoc
57
 *
58
 * Revision 1.16  2007/08/03 11:29:13  jaume
59
 * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
60
 *
61
 * Revision 1.15  2007/08/03 09:03:29  jvidal
62
 * *** empty log message ***
63
 *
64
 * Revision 1.14  2007/07/30 06:59:51  jaume
65
 * finished (maybe) LineFillSymbol
66
 *
67
 * Revision 1.13  2007/07/26 12:28:29  jaume
68
 * maybe finished ArrowMarkerSymbol and ArrowDecoratorStyle
69
 *
70
 * Revision 1.12  2007/07/23 07:08:10  jaume
71
 * Added support for arrow line decorator (start commiting)
72
 *
73
 * Revision 1.11  2007/07/12 10:43:55  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.10  2007/06/29 13:07:33  jaume
77
 * +PictureLineSymbol
78
 *
79
 * Revision 1.9  2007/05/31 09:36:22  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.8  2007/05/21 10:38:27  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.7  2007/04/27 12:10:17  jaume
86
 * *** empty log message ***
87
 *
88
 * Revision 1.6  2007/04/05 16:08:34  jaume
89
 * Styled labeling stuff
90
 *
91
 * Revision 1.5  2007/04/04 16:01:13  jaume
92
 * *** empty log message ***
93
 *
94
 * Revision 1.4  2007/03/26 15:05:26  jaume
95
 * *** empty log message ***
96
 *
97
 * Revision 1.3  2007/03/21 08:03:03  jaume
98
 * refactored to use ISymbol instead of FSymbol
99
 *
100
 * Revision 1.2  2007/03/09 11:25:00  jaume
101
 * Advanced symbology (start committing)
102
 *
103
 * Revision 1.1.2.6  2007/02/21 07:35:14  jaume
104
 * *** empty log message ***
105
 *
106
 * Revision 1.1.2.5  2007/02/12 15:14:41  jaume
107
 * refactored interval legend and added graduated symbol legend
108
 *
109
 * Revision 1.1.2.4  2007/02/09 11:05:16  jaume
110
 * *** empty log message ***
111
 *
112
 * Revision 1.1.2.3  2007/02/09 11:00:02  jaume
113
 * *** empty log message ***
114
 *
115
 * Revision 1.1.2.2  2007/02/08 15:43:05  jaume
116
 * some bug fixes in the editor and removed unnecessary imports
117
 *
118
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
119
 * *** empty log message ***
120
 *
121
 *
122
 */
123
package org.gvsig.app.gui.styling;
124

    
125
import java.awt.BasicStroke;
126
import java.awt.Color;
127
import java.awt.Dimension;
128
import java.awt.FlowLayout;
129
import java.awt.event.ActionEvent;
130
import java.awt.event.ActionListener;
131
import java.util.ArrayList;
132

    
133
import javax.swing.JPanel;
134

    
135
import org.gvsig.andami.PluginServices;
136
import org.gvsig.andami.messages.NotificationManager;
137
import org.gvsig.app.gui.panels.ColorChooserPanel;
138
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
139
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleLineSymbol;
140
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
141
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ArrowDecoratorStyle;
142
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILineStyle;
143
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.SimpleLineStyle;
144
import org.gvsig.gui.beans.listeners.BeanListener;
145
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
146
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
147
import org.gvsig.utils.XMLException;
148

    
149

    
150
/**
151
 * SimpleLine allows the user to store and modify the main properties that
152
 * define a <b>simple line</b>.<p>
153
 * <p>
154
 * This functionality is carried out thanks to two tabs (simple line and arrow
155
 * decorator)which are included in the panel to edit the properities of a symbol
156
 * (SymbolEditor)how is explained in AbstractTypeSymbolEditor.<p>
157
 * <p>
158
 * The first tab (Simple Line)allows the user to change the color (<b>jccColor</b>),
159
 * the width (<b>txtWidth</b>) and the style of the line (<b>cmbLinStyles</b>).<p>
160
 * <p>
161
 * The second tab (<b>arrowDecorator</b>)allows the user to insert a symbol in the
162
 * line (for example an arrow to specify its orientation)and to modify it.
163
 *
164
 *@see ArrowDecorator
165
 *@see AbstractTypeSymbolEditor
166
 *@author jaume dominguez faus - jaume.dominguez@iver.es
167
 */
168
public class SimpleLine extends AbstractTypeSymbolEditor implements ActionListener {
169

    
170
        private ColorChooserPanel jccColor;
171
        private JIncrementalNumberField txtWidth;
172
        private ArrayList<JPanel> tabs = new ArrayList<JPanel>();
173
        private ArrowDecorator arrowDecorator;
174
        private LineProperties lineProperties;
175
        private JIncrementalNumberField txtOffset;
176

    
177

    
178
        public SimpleLine(SymbolEditor owner) {
179
                super(owner);
180
                initialize();
181
        }
182

    
183

    
184
        /**
185
         * Initializes the parameters that define a simpleline.To do it, two tabs
186
         * are created inside the SymbolEditor panel with default values for the
187
         * different attributes of the simple line.This two tabs will be simple
188
         * line tab (options of color, width and style of the line)and arrow
189
         * decorator tab (options to "decorate" the line with a symbol).
190
         */
191
        private void initialize() {
192
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
193
                myTab.setName(PluginServices.getText(this, "simple_line"));
194
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
195

    
196
                // color chooser
197
                jccColor = new ColorChooserPanel(true);
198
                jccColor.setAlpha(255);
199
                aux.addComponent(PluginServices.getText(this, "color"),
200
                                jccColor        );
201

    
202
                // line width
203
                txtWidth = new JIncrementalNumberField("3", 25, 0, Double.POSITIVE_INFINITY, 1);
204
                aux.addComponent(PluginServices.getText(this, "width")+":",
205
                                txtWidth );
206

    
207
                // line offset
208
                txtOffset = new JIncrementalNumberField("0", 25, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1);
209
                aux.addComponent(PluginServices.getText(this, "offset")+":",
210
                                txtOffset );
211

    
212

    
213

    
214
                aux.setPreferredSize(new Dimension(300, 300));
215
                myTab.add(aux);
216

    
217
                // initialize defaults
218
                jccColor.setColor(Color.BLACK);
219
                txtWidth.setDouble(1.0);
220
                jccColor.addActionListener(this);
221
                txtWidth.addActionListener(this);
222
                txtOffset.addActionListener(this);
223
                tabs.add(myTab);
224

    
225
                // Arrow Decorator
226
                arrowDecorator = new ArrowDecorator();
227
                arrowDecorator.addListener(new BeanListener() {
228

    
229
                        public void beanValueChanged(Object value) {
230
                                fireSymbolChangedEvent();
231
                        }
232

    
233
                });
234
                tabs.add(arrowDecorator);
235

    
236
                lineProperties = new LineProperties((float) txtWidth.getDouble());
237
                lineProperties.addListener(new BeanListener(){
238

    
239
                        public void beanValueChanged(Object value) {
240
                                fireSymbolChangedEvent();
241
                        }
242
                });
243
                tabs.add(lineProperties);
244
        }
245

    
246

    
247
        public ISymbol getLayer() {
248
                SimpleLineSymbol layer = new SimpleLineSymbol();
249
                layer.setLineColor(jccColor.getColor());
250
                layer.setIsShapeVisible(true);
251
                // clone the selected style in the combo box
252

    
253
                SimpleLineStyle simplLine= new SimpleLineStyle();
254

    
255
                simplLine.setStroke(lineProperties.getLinePropertiesStyle());
256
                simplLine.setOffset(-txtOffset.getDouble());
257

    
258
                ArrowDecoratorStyle ads= arrowDecorator.getArrowDecoratorStyle();
259
                if (ads != null) {
260
                        ads.getMarker().setColor(jccColor.getColor());
261
                }
262
                simplLine.setArrowDecorator(arrowDecorator.getArrowDecoratorStyle());
263
                layer.setLineStyle(simplLine);
264
                layer.setLineWidth((float) txtWidth.getDouble());
265

    
266
                return layer;
267
        }
268

    
269
        public String getName() {
270
                return PluginServices.getText(this, "simple_line");
271
        }
272

    
273
        public JPanel[] getTabs() {
274
                return (JPanel[]) tabs.toArray(new JPanel[0]);
275
        }
276

    
277
        public void refreshControls(ISymbol layer) {
278
                SimpleLineSymbol sym;
279
                try {
280
                        if (layer == null) {
281
                                // initialize defaults
282
                                System.err.println(getClass().getName()+":: should be unreachable code");
283
                                jccColor.setColor(Color.BLACK);
284
                                txtWidth.setDouble(1.0);
285
                                txtOffset.setDouble(0);
286
                        } else {
287
                                sym = (SimpleLineSymbol) layer;
288
                                jccColor.setColor(sym.getColor());
289
                                txtWidth.setDouble(sym.getLineStyle().getLineWidth());
290
                                txtOffset.setDouble(sym.getLineStyle().getOffset() == 0 ? 0 : -sym.getLineStyle().getOffset() );
291
                                arrowDecorator.setArrowDecoratorStyle( sym.getLineStyle().getArrowDecorator());
292
                                /*
293
                                 * this line discards any temp changes in the linestyle
294
                                 * widths made by any previous rendering and sets all the
295
                                 * values to those to be persisted.
296
                                 */
297
                                ILineStyle tempLineStyle = (ILineStyle) SymbologyFactory.createStyleFromXML(sym.getLineStyle().getXMLEntity(), sym.getDescription());
298
                                lineProperties.setLinePropertiesStyle((BasicStroke) tempLineStyle.getStroke());
299
                        }
300
                } catch (IndexOutOfBoundsException ioEx) {
301
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
302
                } catch (ClassCastException ccEx) {
303
                        NotificationManager.addWarning("Illegal casting from " +
304
                                        layer.getClassName() + " to " + getSymbolClass().
305
                                        getName() + ".", ccEx);
306
                } catch (XMLException e) {
307
                        NotificationManager.addWarning("Symbol layer", e);
308
                }
309
        }
310

    
311
        public Class getSymbolClass() {
312
                return SimpleLineSymbol.class;
313
        }
314

    
315
        public void actionPerformed(ActionEvent e) {
316
                fireSymbolChangedEvent();
317
        }
318

    
319
        public EditorTool[] getEditorTools() {
320
                return null;
321
        }
322
}