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