Statistics
| Revision:

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

History | View | Annotate | Download (9.78 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 30011 2009-07-17 11:07:14Z cordinyana $
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.gui.beans.listeners.BeanListener;
140
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
141
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
142
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
143
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle;
144
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ILineStyle;
145
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleLineStyle;
146
import org.gvsig.utils.XMLException;
147

    
148

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

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

    
176

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

    
182

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

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

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

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

    
211

    
212

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

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

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

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

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

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

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

    
245

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

    
252
                SimpleLineStyle simplLine= new SimpleLineStyle();
253

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

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

    
265
                return layer;
266
        }
267

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

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

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