svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleLine.java @ 16204
History | View | Annotate | Download (9.51 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 16204 2007-11-08 16:33:03Z jdominguez $
|
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 com.iver.cit.gvsig.gui.styling; |
124 |
|
125 |
import java.awt.BasicStroke; |
126 |
import java.awt.BorderLayout; |
127 |
import java.awt.Color; |
128 |
import java.awt.Dimension; |
129 |
import java.awt.FlowLayout; |
130 |
import java.awt.event.ActionEvent; |
131 |
import java.awt.event.ActionListener; |
132 |
import java.util.ArrayList; |
133 |
|
134 |
import javax.swing.JPanel; |
135 |
|
136 |
import org.gvsig.gui.beans.listeners.BeanListener; |
137 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
138 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
139 |
|
140 |
import com.iver.andami.PluginServices; |
141 |
import com.iver.andami.messages.NotificationManager; |
142 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
143 |
import com.iver.cit.gvsig.fmap.core.styles.ArrowDecoratorStyle; |
144 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
145 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
146 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
147 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
148 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
149 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
150 |
|
151 |
/**
|
152 |
* SimpleLine allows the user to store and modify the main properties that
|
153 |
* define a <b>simple line</b>.<p>
|
154 |
* <p>
|
155 |
* This functionality is carried out thanks to two tabs (simple line and arrow
|
156 |
* decorator)which are included in the panel to edit the properities of a symbol
|
157 |
* (SymbolEditor)how is explained in AbstractTypeSymbolEditor.<p>
|
158 |
* <p>
|
159 |
* The first tab (Simple Line)allows the user to change the color (<b>jccColor</b>),
|
160 |
* the width (<b>txtWidth</b>) and the style of the line (<b>cmbLinStyles</b>).<p>
|
161 |
* <p>
|
162 |
* The second tab (<b>arrowDecorator</b>)allows the user to insert a symbol in the
|
163 |
* line (for example an arrow to specify its orientation)and to modify it.
|
164 |
*
|
165 |
*@see ArrowDecorator
|
166 |
*@see AbstractTypeSymbolEditor
|
167 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
168 |
*/
|
169 |
public class SimpleLine extends AbstractTypeSymbolEditor implements ActionListener { |
170 |
|
171 |
private ColorChooserPanel jccColor;
|
172 |
private JIncrementalNumberField txtWidth;
|
173 |
private ArrayList<JPanel> tabs = new ArrayList<JPanel>(); |
174 |
private ArrowDecorator arrowDecorator;
|
175 |
private LineProperties lineProperties;
|
176 |
private JIncrementalNumberField txtOffset;
|
177 |
|
178 |
|
179 |
public SimpleLine(SymbolEditor owner) {
|
180 |
super(owner);
|
181 |
initialize(); |
182 |
} |
183 |
|
184 |
|
185 |
/**
|
186 |
* Initializes the parameters that define a simpleline.To do it, two tabs
|
187 |
* are created inside the SymbolEditor panel with default values for the
|
188 |
* different attributes of the simple line.This two tabs will be simple
|
189 |
* line tab (options of color, width and style of the line)and arrow
|
190 |
* decorator tab (options to "decorate" the line with a symbol).
|
191 |
*/
|
192 |
private void initialize() { |
193 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
194 |
myTab.setName(PluginServices.getText(this, "simple_line")); |
195 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
196 |
|
197 |
// color chooser
|
198 |
jccColor = new ColorChooserPanel(true); |
199 |
jccColor.setAlpha(255);
|
200 |
aux.addComponent(PluginServices.getText(this, "color"), |
201 |
jccColor ); |
202 |
|
203 |
// line width
|
204 |
txtWidth = new JIncrementalNumberField("3", 25, 0, Double.POSITIVE_INFINITY, 1); |
205 |
aux.addComponent(PluginServices.getText(this, "width")+":", |
206 |
txtWidth ); |
207 |
|
208 |
// line offset
|
209 |
txtOffset = new JIncrementalNumberField("0", 25, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1); |
210 |
aux.addComponent(PluginServices.getText(this, "offset")+":", |
211 |
txtOffset ); |
212 |
|
213 |
|
214 |
|
215 |
aux.setPreferredSize(new Dimension(300, 300)); |
216 |
myTab.add(aux); |
217 |
|
218 |
// initialize defaults
|
219 |
jccColor.setColor(Color.BLACK);
|
220 |
txtWidth.setDouble(1.0);
|
221 |
jccColor.addActionListener(this);
|
222 |
txtWidth.addActionListener(this);
|
223 |
txtOffset.addActionListener(this);
|
224 |
tabs.add(myTab); |
225 |
|
226 |
// Arrow Decorator
|
227 |
arrowDecorator = new ArrowDecorator();
|
228 |
arrowDecorator.addListener(new BeanListener() {
|
229 |
|
230 |
public void beanValueChanged(Object value) { |
231 |
fireSymbolChangedEvent(); |
232 |
} |
233 |
|
234 |
}); |
235 |
tabs.add(arrowDecorator); |
236 |
|
237 |
lineProperties = new LineProperties((float) txtWidth.getDouble()); |
238 |
lineProperties.addListener(new BeanListener(){
|
239 |
|
240 |
public void beanValueChanged(Object value) { |
241 |
fireSymbolChangedEvent(); |
242 |
} |
243 |
}); |
244 |
tabs.add(lineProperties); |
245 |
} |
246 |
|
247 |
|
248 |
public ISymbol getLayer() {
|
249 |
SimpleLineSymbol layer = new SimpleLineSymbol();
|
250 |
layer.setLineColor(jccColor.getColor()); |
251 |
layer.setIsShapeVisible(true);
|
252 |
// clone the selected style in the combo box
|
253 |
|
254 |
SimpleLineStyle simplLine= new SimpleLineStyle();
|
255 |
simplLine.setStroke(lineProperties.getLinePropertiesStyle()); |
256 |
|
257 |
ILineStyle sty = (ILineStyle)SymbologyFactory.createStyleFromXML(simplLine.getXMLEntity(), null);
|
258 |
|
259 |
sty.setLineWidth((float) txtWidth.getDouble());
|
260 |
sty.setOffset(-txtOffset.getDouble()); |
261 |
|
262 |
ArrowDecoratorStyle ads= arrowDecorator.getArrowDecoratorStyle(); |
263 |
if (ads != null) { |
264 |
ads.getMarker().setColor(jccColor.getColor()); |
265 |
} |
266 |
sty.setArrowDecorator(arrowDecorator.getArrowDecoratorStyle()); |
267 |
layer.setLineStyle(sty); |
268 |
|
269 |
return layer;
|
270 |
} |
271 |
|
272 |
public String getName() { |
273 |
return PluginServices.getText(this, "simple_line"); |
274 |
} |
275 |
|
276 |
public JPanel[] getTabs() { |
277 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
278 |
} |
279 |
|
280 |
public void refreshControls(ISymbol layer) { |
281 |
SimpleLineSymbol sym; |
282 |
try {
|
283 |
if (layer == null) { |
284 |
// initialize defaults
|
285 |
System.err.println(getClass().getName()+":: should be unreachable code"); |
286 |
jccColor.setColor(Color.BLACK);
|
287 |
txtWidth.setDouble(1.0);
|
288 |
txtOffset.setDouble(0);
|
289 |
} else {
|
290 |
sym = (SimpleLineSymbol) layer; |
291 |
jccColor.setColor(sym.getColor()); |
292 |
txtWidth.setDouble(sym.getLineStyle().getLineWidth()); |
293 |
txtOffset.setDouble(sym.getLineStyle().getOffset() == 0 ? 0 : -sym.getLineStyle().getOffset() ); |
294 |
arrowDecorator.setArrowDecoratorStyle( sym.getLineStyle().getArrowDecorator()); |
295 |
lineProperties.setLinePropertiesStyle((BasicStroke) sym.getLineStyle().getStroke());
|
296 |
} |
297 |
} catch (IndexOutOfBoundsException ioEx) { |
298 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
299 |
} catch (ClassCastException ccEx) { |
300 |
NotificationManager.addWarning("Illegal casting from " +
|
301 |
layer.getClassName() + " to " + getSymbolClass().
|
302 |
getName() + ".", ccEx);
|
303 |
} |
304 |
} |
305 |
|
306 |
public Class getSymbolClass() { |
307 |
return SimpleLineSymbol.class;
|
308 |
} |
309 |
|
310 |
public void actionPerformed(ActionEvent e) { |
311 |
fireSymbolChangedEvent(); |
312 |
} |
313 |
|
314 |
public EditorTool[] getEditorTools() { |
315 |
return null; |
316 |
} |
317 |
} |