root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleMarker.java @ 22869
History | View | Annotate | Download (8.95 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 22869 2008-08-25 06:56:34Z vcaballero $
|
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 com.iver.cit.gvsig.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.geom.Point2D; |
110 |
import java.util.ArrayList; |
111 |
|
112 |
import javax.swing.JCheckBox; |
113 |
import javax.swing.JPanel; |
114 |
|
115 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
116 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
117 |
|
118 |
import com.iver.andami.PluginServices; |
119 |
import com.iver.andami.messages.NotificationManager; |
120 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
121 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
122 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
123 |
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor; |
124 |
import com.iver.cit.gvsig.gui.styling.EditorTool; |
125 |
import com.iver.cit.gvsig.gui.styling.JComboBoxSimpleMarkeStyles; |
126 |
import com.iver.cit.gvsig.gui.styling.SymbolEditor; |
127 |
|
128 |
/**
|
129 |
* SimpleMarker allows the user to store and modify the main properties that
|
130 |
* define a <b>simple marker</b>.<p>
|
131 |
* <p>
|
132 |
* This functionality is carried out thanks to a tab (simple marker and mask)
|
133 |
* which are included in the panel to edit the properities of a symbol (SymbolEditor)
|
134 |
* how is explained in AbstractTypeSymbolEditor.<p>
|
135 |
* <p>
|
136 |
* This tab (Simple Marker)allows the user to change the different attributes
|
137 |
* which are color (<b>jccColor</b>),text size (<b>txtSize</b>),text offset
|
138 |
* (<b>txtXOffset</b> and <b>txtXOffset</b>), style of the marker (<b></b>)
|
139 |
* the width (<b>txtWidth</b>) and the style of the line (<b>cmbStyle</b>)
|
140 |
* and the color of the outline(<b>jccOutlineColor</b>).<p>
|
141 |
*
|
142 |
*@see Mask
|
143 |
*@see AbstractTypeSymbolEditor
|
144 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
145 |
*/
|
146 |
public class SimpleMarker extends AbstractTypeSymbolEditor implements ActionListener{ |
147 |
|
148 |
private ArrayList tabs = new ArrayList(); |
149 |
private ColorChooserPanel jccColor;
|
150 |
private JIncrementalNumberField txtSize;
|
151 |
private JIncrementalNumberField txtXOffset;
|
152 |
private JIncrementalNumberField txtYOffset;
|
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(PluginServices.getText(this, "simple_marker")); |
172 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
173 |
|
174 |
// color chooser
|
175 |
jccColor = new ColorChooserPanel(true); |
176 |
jccColor.setAlpha(255);
|
177 |
|
178 |
aux.addComponent(PluginServices.getText(this, "color")+":", |
179 |
jccColor ); |
180 |
|
181 |
// marker width
|
182 |
txtSize = new JIncrementalNumberField("5", 25); |
183 |
aux.addComponent(PluginServices.getText(this, "size")+":", |
184 |
txtSize ); |
185 |
txtSize.setDouble(5);
|
186 |
|
187 |
// marker xOffset
|
188 |
txtXOffset = new JIncrementalNumberField("0", 25); |
189 |
aux.addComponent(PluginServices.getText(this, "x_offset")+":", |
190 |
txtXOffset ); |
191 |
|
192 |
|
193 |
// marker width
|
194 |
txtYOffset = new JIncrementalNumberField("0", 25); |
195 |
aux.addComponent(PluginServices.getText(this, "y_offset")+":", |
196 |
txtYOffset ); |
197 |
|
198 |
// marker style
|
199 |
cmbStyle = new JComboBoxSimpleMarkeStyles();
|
200 |
aux.addComponent(PluginServices.getText(this, "marker_style")+":", |
201 |
cmbStyle); |
202 |
|
203 |
// use outline
|
204 |
chkUseOutline = new JCheckBox(PluginServices.getText(this, "use_outline")); |
205 |
aux.addComponent(chkUseOutline); |
206 |
|
207 |
// outline color
|
208 |
jccOutlineColor = new ColorChooserPanel(true); |
209 |
jccOutlineColor.setAlpha(255);
|
210 |
aux.addComponent(PluginServices.getText(this, "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 |
txtXOffset.addActionListener(this);
|
223 |
txtYOffset.addActionListener(this);
|
224 |
cmbStyle.addActionListener(this);
|
225 |
chkUseOutline.addActionListener(this);
|
226 |
jccOutlineColor.addActionListener(this);
|
227 |
|
228 |
tabs.add(myTab); |
229 |
|
230 |
mask = new Mask(this); |
231 |
tabs.add(mask); |
232 |
} |
233 |
|
234 |
public ISymbol getLayer() {
|
235 |
SimpleMarkerSymbol layer = new SimpleMarkerSymbol();
|
236 |
layer.setColor(jccColor.getColor()); |
237 |
layer.setIsShapeVisible(true);
|
238 |
layer.setSize(txtSize.getDouble()); |
239 |
// layer.setUnit(owner.getUnit());
|
240 |
// layer.setReferenceSystem(owner.getUnitsReferenceSystem());
|
241 |
layer.setOffset(new Point2D.Double( |
242 |
txtXOffset.getDouble(), |
243 |
txtYOffset.getDouble())); |
244 |
layer.setMask(mask.getMask()); |
245 |
layer.setStyle(((Integer) cmbStyle.getSelectedItem()).intValue());
|
246 |
layer.setOutlined(chkUseOutline.isSelected()); |
247 |
layer.setOutlineColor(jccOutlineColor.getColor()); |
248 |
return layer;
|
249 |
} |
250 |
|
251 |
public String getName() { |
252 |
return PluginServices.getText(this, "simple_marker_symbol"); |
253 |
} |
254 |
|
255 |
public JPanel[] getTabs() { |
256 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
257 |
} |
258 |
|
259 |
public void refreshControls(ISymbol layer) { |
260 |
SimpleMarkerSymbol sym; |
261 |
try {
|
262 |
if (layer == null) { |
263 |
// initialize defaults
|
264 |
System.err.println("SimpleLine.java:: should be unreachable code"); |
265 |
jccColor.setColor(Color.BLACK);
|
266 |
|
267 |
txtSize.setDouble(1.0);
|
268 |
txtXOffset.setDouble(0.0);
|
269 |
txtYOffset.setDouble(0.0);
|
270 |
} else {
|
271 |
sym = (SimpleMarkerSymbol) layer; |
272 |
jccColor.setColor(sym.getColor()); |
273 |
|
274 |
txtSize.setDouble(sym.getSize()); |
275 |
txtXOffset.setDouble(sym.getOffset().getX()); |
276 |
txtYOffset.setDouble(sym.getOffset().getY()); |
277 |
cmbStyle.setSymbolColor(sym.getColor()); |
278 |
cmbStyle.setOutlineColor(sym.getOutlineColor()); |
279 |
cmbStyle.setSelectedItem(new Integer(sym.getStyle())); |
280 |
} |
281 |
} catch (IndexOutOfBoundsException ioEx) { |
282 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
283 |
} catch (ClassCastException ccEx) { |
284 |
NotificationManager.addWarning("Illegal casting from " +
|
285 |
layer.getClassName() + " to " + getSymbolClass().
|
286 |
getName() + ".", ccEx);
|
287 |
|
288 |
} |
289 |
} |
290 |
|
291 |
public Class getSymbolClass() { |
292 |
return SimpleMarkerSymbol.class;
|
293 |
} |
294 |
|
295 |
public void actionPerformed(ActionEvent e) { |
296 |
fireSymbolChangedEvent(); |
297 |
} |
298 |
|
299 |
public EditorTool[] getEditorTools() { |
300 |
return null; |
301 |
} |
302 |
} |