root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / MarkerFill.java @ 10959
History | View | Annotate | Download (10.8 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: MarkerFill.java 10959 2007-03-28 16:48:22Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.5 2007-03-28 16:44:08 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.4 2007/03/13 16:57:35 jaume
|
50 |
* Added MultiVariable legend
|
51 |
*
|
52 |
* Revision 1.3 2007/03/09 11:25:00 jaume
|
53 |
* Advanced symbology (start committing)
|
54 |
*
|
55 |
* Revision 1.1.2.3 2007/02/21 07:35:14 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
59 |
* some bug fixes in the editor and removed unnecessary imports
|
60 |
*
|
61 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1 2007/01/16 11:52:11 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.8 2007/01/10 17:05:05 jaume
|
68 |
* moved to FMap and gvSIG
|
69 |
*
|
70 |
* Revision 1.7 2006/11/13 09:15:23 jaume
|
71 |
* javadoc and some clean-up
|
72 |
*
|
73 |
* Revision 1.6 2006/11/06 16:06:52 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.5 2006/11/02 17:19:28 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.4 2006/10/31 16:16:34 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.3 2006/10/30 19:30:35 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.2 2006/10/29 23:53:49 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.1 2006/10/27 12:41:09 jaume
|
89 |
* GUI
|
90 |
*
|
91 |
*
|
92 |
*/
|
93 |
package com.iver.cit.gvsig.gui.styling; |
94 |
|
95 |
import java.awt.Color; |
96 |
import java.awt.FlowLayout; |
97 |
import java.awt.GridLayout; |
98 |
import java.awt.event.ActionEvent; |
99 |
import java.awt.event.ActionListener; |
100 |
import java.util.ArrayList; |
101 |
|
102 |
import javax.swing.BorderFactory; |
103 |
import javax.swing.ButtonGroup; |
104 |
import javax.swing.JComponent; |
105 |
import javax.swing.JLabel; |
106 |
import javax.swing.JPanel; |
107 |
import javax.swing.JRadioButton; |
108 |
|
109 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
110 |
import org.gvsig.gui.beans.swing.JButton; |
111 |
|
112 |
import com.iver.andami.PluginServices; |
113 |
import com.iver.cit.gvsig.fmap.core.FShape; |
114 |
import com.iver.cit.gvsig.fmap.core.styles.MarkerFillStyle; |
115 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractMarkerSymbol; |
116 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
117 |
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol; |
118 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
119 |
import com.iver.utiles.XMLEntity; |
120 |
|
121 |
import de.ios.framework.swing.JDecimalField; |
122 |
|
123 |
public class MarkerFill extends AbstractTypeSymbolEditorPanel implements ActionListener { |
124 |
private static final double DEFAULT_SEPARATION = 20; |
125 |
private static final double DEFAULT_OFFSET = 10; |
126 |
private ArrayList tabs = new ArrayList(); |
127 |
private JDecimalField txtOffsetX;
|
128 |
private JDecimalField txtOffsetY;
|
129 |
private JDecimalField txtSeparationX;
|
130 |
private JDecimalField txtSeparationY;
|
131 |
private ColorChooserPanel markerCC;
|
132 |
private JButton btnChooseMarker; |
133 |
private JButton btnOutline; |
134 |
private JRadioButton rdGrid; |
135 |
private JRadioButton rdRandom; |
136 |
private MarkerFillSymbol mfs = new MarkerFillSymbol(); |
137 |
public MarkerFill(SymbolEditor owner) {
|
138 |
super(owner);
|
139 |
initialize(); |
140 |
} |
141 |
|
142 |
private void initialize() { |
143 |
GridLayout layout;
|
144 |
JPanel myTab;
|
145 |
// Marker fill tab
|
146 |
|
147 |
{ |
148 |
myTab = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10)); |
149 |
myTab.setName(PluginServices.getText(this, "marker_fill")); |
150 |
|
151 |
GridBagLayoutPanel p = new GridBagLayoutPanel();
|
152 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
153 |
markerCC = new ColorChooserPanel();
|
154 |
markerCC.setAlpha(255);
|
155 |
markerCC.addActionListener(this);
|
156 |
aux.add(markerCC); |
157 |
|
158 |
p.addComponent(PluginServices.getText(this, "color"), aux); |
159 |
btnChooseMarker = new JButton(PluginServices.getText(this, "choose_marker")); |
160 |
btnChooseMarker.addActionListener(this);
|
161 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
162 |
aux.add(btnChooseMarker); |
163 |
p.addComponent("", aux);
|
164 |
|
165 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
166 |
btnOutline = new JButton(PluginServices.getText(this, "outline")); |
167 |
aux.add(btnOutline); |
168 |
btnOutline.setEnabled(false);
|
169 |
p.addComponent("", aux);
|
170 |
|
171 |
ButtonGroup group = new ButtonGroup(); |
172 |
rdGrid = new JRadioButton(PluginServices.getText(this, "grid")); |
173 |
rdGrid.addActionListener(this);
|
174 |
rdRandom = new JRadioButton(PluginServices.getText(this, "random")); |
175 |
rdRandom.addActionListener(this);
|
176 |
group.add(rdGrid); |
177 |
group.add(rdRandom); |
178 |
|
179 |
|
180 |
|
181 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
182 |
aux.add(rdGrid); |
183 |
aux.add(rdRandom); |
184 |
rdGrid.setSelected(true);
|
185 |
p.addComponent("", aux);
|
186 |
|
187 |
myTab.add(p); |
188 |
|
189 |
} |
190 |
tabs.add(myTab); |
191 |
|
192 |
// Fill properties tab
|
193 |
{ |
194 |
layout = new GridLayout(); |
195 |
layout.setColumns(1);
|
196 |
layout.setVgap(5);
|
197 |
myTab = new JPanel(); |
198 |
myTab.setName(PluginServices.getText(this, "fill_properties")); |
199 |
JPanel offsetPnl = new JPanel(); |
200 |
offsetPnl.setBorder(BorderFactory.
|
201 |
createTitledBorder(null,
|
202 |
PluginServices.getText(this, "offset"))); |
203 |
|
204 |
// add components to the offset panel here
|
205 |
{ |
206 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
207 |
aux.add(new JLabel("X:")); |
208 |
aux.add(txtOffsetX = new JDecimalField(10)); |
209 |
offsetPnl.add(aux); |
210 |
|
211 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
212 |
aux.add(new JLabel("Y:")); |
213 |
aux.add(txtOffsetY = new JDecimalField(10)); |
214 |
offsetPnl.add(aux); |
215 |
|
216 |
|
217 |
|
218 |
} |
219 |
layout.setRows(offsetPnl.getComponentCount()); |
220 |
offsetPnl.setLayout(layout); |
221 |
|
222 |
myTab.add(offsetPnl); |
223 |
|
224 |
JPanel separationPnl = new JPanel(); |
225 |
layout = new GridLayout(); |
226 |
layout.setColumns(1);
|
227 |
layout.setVgap(5);
|
228 |
separationPnl.setBorder(BorderFactory.
|
229 |
createTitledBorder(null,
|
230 |
PluginServices.getText(this, "separation"))); |
231 |
|
232 |
// add components to the separation panel here
|
233 |
{ |
234 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
235 |
aux.add(new JLabel("X:")); |
236 |
aux.add(txtSeparationX = new JDecimalField(10)); |
237 |
separationPnl.add(aux); |
238 |
|
239 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
240 |
aux.add(new JLabel("Y:")); |
241 |
aux.add(txtSeparationY = new JDecimalField(10)); |
242 |
separationPnl.add(aux); |
243 |
} |
244 |
layout.setRows(separationPnl.getComponentCount()); |
245 |
separationPnl.setLayout(layout); |
246 |
myTab.add(separationPnl); |
247 |
layout = new GridLayout(); |
248 |
layout.setColumns(1);
|
249 |
layout.setVgap(5);
|
250 |
layout.setRows(myTab.getComponentCount()); |
251 |
myTab.setLayout(layout); |
252 |
} |
253 |
tabs.add(myTab); |
254 |
} |
255 |
|
256 |
public void refreshControls(ISymbol layer) { |
257 |
if (layer == null) { |
258 |
// set defaults
|
259 |
markerCC.setColor(Color.BLACK);
|
260 |
rdGrid.setSelected(true);
|
261 |
rdRandom.setSelected(false);
|
262 |
txtOffsetX.setText(String.valueOf(DEFAULT_OFFSET));
|
263 |
txtOffsetY.setText(String.valueOf(DEFAULT_OFFSET));
|
264 |
txtSeparationX.setText(String.valueOf(DEFAULT_SEPARATION));
|
265 |
txtSeparationY.setText(String.valueOf(DEFAULT_SEPARATION));
|
266 |
} else {
|
267 |
|
268 |
MarkerFillSymbol mfs = (MarkerFillSymbol) layer; |
269 |
int fillStyle = mfs.getFillStyle();
|
270 |
rdGrid.setSelected(fillStyle == MarkerFillStyle.GRID_FILL); |
271 |
rdRandom.setSelected(fillStyle == MarkerFillStyle.RANDOM_FILL); |
272 |
|
273 |
txtOffsetX.setText(String.valueOf(mfs.getXOffset()));
|
274 |
txtOffsetY.setText(String.valueOf(mfs.getYOffset()));
|
275 |
|
276 |
txtSeparationX.setText(String.valueOf(mfs.getXSeparation()));
|
277 |
txtSeparationY.setText(String.valueOf(mfs.getYSeparation()));
|
278 |
} |
279 |
} |
280 |
|
281 |
public String getName() { |
282 |
return PluginServices.getText(this, "marker_fill"); |
283 |
} |
284 |
|
285 |
public JPanel[] getTabs() { |
286 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
287 |
} |
288 |
|
289 |
public void actionPerformed(ActionEvent e) { |
290 |
JComponent comp = (JComponent) e.getSource(); |
291 |
if (comp.equals(btnChooseMarker)) {
|
292 |
SymbolSelector symSelect = new SymbolSelector( getLayer(), FShape.POINT);
|
293 |
PluginServices.getMDIManager().addWindow(symSelect); |
294 |
AbstractMarkerSymbol marker = (AbstractMarkerSymbol) symSelect.getSelectedObject(); |
295 |
|
296 |
if (marker == null) return; |
297 |
|
298 |
mfs.setMarker(marker); |
299 |
} |
300 |
try {
|
301 |
mfs.setXOffset(Double.parseDouble(txtOffsetX.getText()));
|
302 |
} catch (Exception ex) { /* zero will be used */ } |
303 |
try {
|
304 |
mfs.setYOffset(Double.parseDouble(txtOffsetY.getText()));
|
305 |
} catch (Exception ex) { /* zero will be used */ } |
306 |
try {
|
307 |
mfs.setXSeparation(Double.parseDouble(txtSeparationX.getText()));
|
308 |
} catch (Exception ex) { /* zero will be used */ } |
309 |
try {
|
310 |
mfs.setYSeparation(Double.parseDouble(txtSeparationY.getText()));
|
311 |
} catch (Exception ex) { /* zero will be used */ } |
312 |
int markerFillStyle;
|
313 |
if (rdGrid.isSelected()) {
|
314 |
markerFillStyle = MarkerFillStyle.GRID_FILL; |
315 |
} else /*if (rdRandom.isSelected() )*/ { |
316 |
markerFillStyle = MarkerFillStyle.RANDOM_FILL; |
317 |
} |
318 |
mfs.setFillStyle(markerFillStyle); |
319 |
|
320 |
fireSymbolChangedEvent(); |
321 |
} |
322 |
|
323 |
public Class getSymbolClass() { |
324 |
return MarkerFillSymbol.class;
|
325 |
} |
326 |
|
327 |
public ISymbol getLayer() {
|
328 |
return mfs;
|
329 |
} |
330 |
|
331 |
} |