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 / SimpleMarker.java @ 34294
History | View | Annotate | Download (9.29 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: SimpleMarker.java 30289 2009-07-31 11:10:41Z jpiera $
|
45 |
* $Log$
|
46 |
* Revision 1.15 2007-08-14 11:10:20 jvidal
|
47 |
* javadoc updated
|
48 |
*
|
49 |
* Revision 1.14 2007/08/08 11:49:15 jaume
|
50 |
* refactored to avoid provide more than one EditorTool
|
51 |
*
|
52 |
* Revision 1.13 2007/08/07 11:20:11 jvidal
|
53 |
* javadoc
|
54 |
*
|
55 |
* Revision 1.12 2007/08/03 11:29:13 jaume
|
56 |
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
|
57 |
*
|
58 |
* Revision 1.11 2007/07/18 06:56:03 jaume
|
59 |
* continuing with cartographic support
|
60 |
*
|
61 |
* Revision 1.10 2007/07/12 10:43:55 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.9 2007/05/31 09:36:22 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.8 2007/05/29 15:47:06 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.7 2007/05/21 10:38:27 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.6 2007/05/09 16:08:14 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.5 2007/04/27 12:10:17 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.4 2007/04/05 16:08:34 jaume
|
80 |
* Styled labeling stuff
|
81 |
*
|
82 |
* Revision 1.3 2007/04/04 16:01:14 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
86 |
* Advanced symbology (start committing)
|
87 |
*
|
88 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.1.2.3 2007/02/08 15:43:04 jaume
|
92 |
* some bug fixes in the editor and removed unnecessary imports
|
93 |
*
|
94 |
* Revision 1.1.2.2 2007/01/30 18:10:10 jaume
|
95 |
* start commiting labeling stuff
|
96 |
*
|
97 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
*
|
101 |
*/
|
102 |
package org.gvsig.app.gui.styling; |
103 |
|
104 |
import java.awt.Color; |
105 |
import java.awt.Dimension; |
106 |
import java.awt.FlowLayout; |
107 |
import java.awt.event.ActionEvent; |
108 |
import java.awt.event.ActionListener; |
109 |
import java.awt.event.FocusEvent; |
110 |
import java.awt.event.FocusListener; |
111 |
import java.awt.geom.Point2D; |
112 |
import java.util.ArrayList; |
113 |
|
114 |
import javax.swing.JCheckBox; |
115 |
import javax.swing.JPanel; |
116 |
|
117 |
import org.gvsig.andami.messages.NotificationManager; |
118 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
119 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
120 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
121 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
122 |
import org.gvsig.i18n.Messages; |
123 |
import org.gvsig.symbology.SymbologyLocator; |
124 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
125 |
|
126 |
|
127 |
/**
|
128 |
* SimpleMarker allows the user to store and modify the main properties that
|
129 |
* define a <b>simple marker</b>.<p>
|
130 |
* <p>
|
131 |
* This functionality is carried out thanks to a tab (simple marker and mask)
|
132 |
* which are included in the panel to edit the properities of a symbol (SymbolEditor)
|
133 |
* how is explained in AbstractTypeSymbolEditor.<p>
|
134 |
* <p>
|
135 |
* This tab (Simple Marker)allows the user to change the different attributes
|
136 |
* which are color (<b>jccColor</b>),text size (<b>txtSize</b>),text offset
|
137 |
* (<b>txtXOffset</b> and <b>txtXOffset</b>), style of the marker (<b></b>)
|
138 |
* the width (<b>txtWidth</b>) and the style of the line (<b>cmbStyle</b>)
|
139 |
* and the color of the outline(<b>jccOutlineColor</b>).<p>
|
140 |
*
|
141 |
*@see Mask
|
142 |
*@see AbstractTypeSymbolEditor
|
143 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
144 |
*/
|
145 |
public class SimpleMarker extends AbstractTypeSymbolEditor implements ActionListener, FocusListener{ |
146 |
|
147 |
private ArrayList tabs = new ArrayList(); |
148 |
private ColorChooserPanel jccColor;
|
149 |
private JIncrementalNumberField txtSize;
|
150 |
private JIncrementalNumberField txtXOffset;
|
151 |
private JIncrementalNumberField txtYOffset;
|
152 |
//TODO: Comentarizado hasta que mask est? acabado
|
153 |
// private Mask mask;
|
154 |
private JComboBoxSimpleMarkeStyles cmbStyle;
|
155 |
private JCheckBox chkUseOutline; |
156 |
private ColorChooserPanel jccOutlineColor;
|
157 |
|
158 |
public SimpleMarker(SymbolEditor owner) {
|
159 |
super(owner);
|
160 |
initialize(); |
161 |
} |
162 |
/**
|
163 |
* Initializes the parameters that define a simplemarker.To do it,
|
164 |
* a tab is created inside the SymbolEditor panel with default values
|
165 |
* for the different attributes of the simple marker.Also, a mask will be
|
166 |
* added as a new tab.
|
167 |
*/
|
168 |
|
169 |
private void initialize() { |
170 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
171 |
myTab.setName(Messages.getText("simple_marker"));
|
172 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
173 |
|
174 |
// color chooser
|
175 |
jccColor = new ColorChooserPanel(true); |
176 |
jccColor.setAlpha(255);
|
177 |
|
178 |
aux.addComponent(Messages.getText("color")+":", |
179 |
jccColor ); |
180 |
|
181 |
// marker width
|
182 |
txtSize = new JIncrementalNumberField("5", 25); |
183 |
aux.addComponent(Messages.getText("size")+":", |
184 |
txtSize ); |
185 |
txtSize.setDouble(5);
|
186 |
|
187 |
// marker xOffset
|
188 |
txtXOffset = new JIncrementalNumberField("0", 25); |
189 |
aux.addComponent(Messages.getText("x_offset")+":", |
190 |
txtXOffset ); |
191 |
|
192 |
|
193 |
// marker width
|
194 |
txtYOffset = new JIncrementalNumberField("0", 25); |
195 |
aux.addComponent(Messages.getText("y_offset")+":", |
196 |
txtYOffset ); |
197 |
|
198 |
// marker style
|
199 |
cmbStyle = new JComboBoxSimpleMarkeStyles();
|
200 |
aux.addComponent(Messages.getText("marker_style")+":", |
201 |
cmbStyle); |
202 |
|
203 |
// use outline
|
204 |
chkUseOutline = new JCheckBox(Messages.getText("use_outline")); |
205 |
aux.addComponent(chkUseOutline); |
206 |
|
207 |
// outline color
|
208 |
jccOutlineColor = new ColorChooserPanel(true); |
209 |
jccOutlineColor.setAlpha(255);
|
210 |
aux.addComponent(Messages.getText("outline_color"), jccOutlineColor);
|
211 |
|
212 |
aux.setPreferredSize(new Dimension(300, 300)); |
213 |
myTab.add(aux); |
214 |
|
215 |
// initialize defaults
|
216 |
jccColor.setColor(Color.BLACK);
|
217 |
cmbStyle.setSymbolColor(jccColor.getColor()); |
218 |
|
219 |
|
220 |
jccColor.addActionListener(this);
|
221 |
txtSize.addActionListener(this);
|
222 |
txtSize.addFocusListener(this);
|
223 |
txtXOffset.addActionListener(this);
|
224 |
txtXOffset.addFocusListener(this);
|
225 |
txtYOffset.addActionListener(this);
|
226 |
txtYOffset.addFocusListener(this);
|
227 |
cmbStyle.addActionListener(this);
|
228 |
chkUseOutline.addActionListener(this);
|
229 |
jccOutlineColor.addActionListener(this);
|
230 |
|
231 |
tabs.add(myTab); |
232 |
|
233 |
// mask = new Mask(this);
|
234 |
// tabs.add(mask);
|
235 |
} |
236 |
|
237 |
public ISymbol getLayer() {
|
238 |
ISimpleMarkerSymbol layer = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol(); |
239 |
layer.setColor(jccColor.getColor()); |
240 |
// layer.setIsShapeVisible(true); //true is the default value for this property
|
241 |
layer.setSize(txtSize.getDouble()); |
242 |
// layer.setUnit(owner.getUnit());
|
243 |
// layer.setReferenceSystem(owner.getUnitsReferenceSystem());
|
244 |
layer.setOffset(new Point2D.Double( |
245 |
txtXOffset.getDouble(), |
246 |
txtYOffset.getDouble())); |
247 |
// layer.setMask(mask.getMask());
|
248 |
layer.setStyle(((Integer) cmbStyle.getSelectedItem()).intValue());
|
249 |
layer.setOutlined(chkUseOutline.isSelected()); |
250 |
layer.setOutlineColor(jccOutlineColor.getColor()); |
251 |
return layer;
|
252 |
} |
253 |
|
254 |
public String getName() { |
255 |
return Messages.getText("simple_marker_symbol"); |
256 |
} |
257 |
|
258 |
public JPanel[] getTabs() { |
259 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
260 |
} |
261 |
|
262 |
public void refreshControls(ISymbol layer) { |
263 |
ISimpleMarkerSymbol sym; |
264 |
try {
|
265 |
if (layer == null) { |
266 |
// initialize defaults
|
267 |
System.err.println("SimpleLine.java:: should be unreachable code"); |
268 |
jccColor.setColor(Color.BLACK);
|
269 |
|
270 |
txtSize.setDouble(1.0);
|
271 |
txtXOffset.setDouble(0.0);
|
272 |
txtYOffset.setDouble(0.0);
|
273 |
} else {
|
274 |
sym = (ISimpleMarkerSymbol) layer; |
275 |
jccColor.setColor(sym.getColor()); |
276 |
|
277 |
txtSize.setDouble(sym.getSize()); |
278 |
txtXOffset.setDouble(sym.getOffset().getX()); |
279 |
txtYOffset.setDouble(sym.getOffset().getY()); |
280 |
cmbStyle.setSymbolColor(sym.getColor()); |
281 |
chkUseOutline.setSelected(sym.hasOutline()); |
282 |
cmbStyle.setOutlineColor(sym.getOutlineColor()); |
283 |
cmbStyle.setSelectedItem(new Integer(sym.getStyle())); |
284 |
} |
285 |
} catch (IndexOutOfBoundsException ioEx) { |
286 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
287 |
} catch (ClassCastException ccEx) { |
288 |
NotificationManager.addWarning("Illegal casting from " +
|
289 |
layer.getClass().getName() + " to ISimpleMarkerSymbol.", ccEx);
|
290 |
|
291 |
} |
292 |
} |
293 |
|
294 |
public void actionPerformed(ActionEvent e) { |
295 |
fireSymbolChangedEvent(); |
296 |
} |
297 |
|
298 |
public EditorTool[] getEditorTools() { |
299 |
return null; |
300 |
} |
301 |
public void focusGained(FocusEvent arg0) { |
302 |
// TODO Auto-generated method stub
|
303 |
|
304 |
} |
305 |
public void focusLost(FocusEvent arg0) { |
306 |
fireSymbolChangedEvent(); |
307 |
|
308 |
} |
309 |
@Override
|
310 |
public boolean canManageSymbol(ISymbol symbol) { |
311 |
return symbol instanceof ISimpleMarkerSymbol; |
312 |
|
313 |
} |
314 |
} |