root / org.gvsig.legend.dotdensity.app.mainplugin / trunk / org.gvsig.legend.dotdensity.app.mainplugin / src / main / java / org / gvsig / symbology / gui / layerproperties / DotDensityPanel.java @ 104
History | View | Annotate | Download (23.5 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: DotDensity.java 15647 2007-10-30 12:03:52Z jmvivo $
|
45 |
* $Log$
|
46 |
* Revision 1.11 2007-09-19 15:47:10 jaume
|
47 |
* refactor name IVectorialLegend -> IVectorLegend and a method name as well
|
48 |
*
|
49 |
* Revision 1.10 2007/09/04 14:13:01 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.9 2007/05/21 10:38:27 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.8 2007/05/17 09:32:37 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.7 2007/05/10 09:46:45 jaume
|
59 |
* Refactored legend interface names
|
60 |
*
|
61 |
* Revision 1.6 2007/05/08 15:45:31 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.5 2007/04/20 07:54:39 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.4 2007/04/20 07:24:56 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.3 2007/04/17 06:53:46 bsanchez
|
71 |
* - Corregido fallo de Double.MIN_VALUE por Double.NEGATIVE_INFINITY comentado por Victor Olaya.
|
72 |
*
|
73 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
74 |
* Advanced symbology (start committing)
|
75 |
*
|
76 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.1.2.3 2007/02/12 15:14:41 jaume
|
80 |
* refactored interval legend and added graduated symbol legend
|
81 |
*
|
82 |
* Revision 1.1.2.2 2007/02/09 11:00:03 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.4 2006/11/17 13:53:45 cesar
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.3 2006/11/17 12:50:36 jaume
|
92 |
* tama?o de punto defecto 2
|
93 |
*
|
94 |
* Revision 1.2 2006/11/15 12:57:31 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.1 2006/11/14 11:10:27 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
*
|
101 |
*/
|
102 |
package org.gvsig.symbology.gui.layerproperties; |
103 |
|
104 |
import java.awt.BorderLayout; |
105 |
import java.awt.Color; |
106 |
import java.awt.ComponentOrientation; |
107 |
import java.awt.Dimension; |
108 |
import java.awt.FlowLayout; |
109 |
import java.awt.GridLayout; |
110 |
import java.awt.LayoutManager; |
111 |
import java.awt.event.ActionEvent; |
112 |
import java.awt.event.ActionListener; |
113 |
import java.awt.event.ItemEvent; |
114 |
import java.awt.event.ItemListener; |
115 |
import java.text.NumberFormat; |
116 |
|
117 |
import javax.swing.BorderFactory; |
118 |
import javax.swing.BoxLayout; |
119 |
import javax.swing.ButtonGroup; |
120 |
import javax.swing.Icon; |
121 |
import javax.swing.ImageIcon; |
122 |
import javax.swing.JComboBox; |
123 |
import javax.swing.JLabel; |
124 |
import javax.swing.JOptionPane; |
125 |
import javax.swing.JPanel; |
126 |
import javax.swing.JRadioButton; |
127 |
import javax.swing.JSlider; |
128 |
import javax.swing.event.ChangeEvent; |
129 |
import javax.swing.event.ChangeListener; |
130 |
|
131 |
import org.slf4j.Logger; |
132 |
import org.slf4j.LoggerFactory; |
133 |
|
134 |
import org.gvsig.andami.IconThemeHelper; |
135 |
import org.gvsig.app.ApplicationLocator; |
136 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
137 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
138 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
139 |
import org.gvsig.app.project.documents.view.legend.gui.Quantities; |
140 |
import org.gvsig.fmap.dal.feature.Feature; |
141 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
142 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
143 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
144 |
import org.gvsig.fmap.dal.feature.FeatureType; |
145 |
import org.gvsig.fmap.geom.Geometry; |
146 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
147 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
148 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
149 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
150 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
151 |
import org.gvsig.i18n.Messages; |
152 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
153 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
154 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
155 |
import org.gvsig.symbology.fmap.rendering.DotDensityLegend; |
156 |
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol; |
157 |
import org.gvsig.tools.dispose.DisposableIterator; |
158 |
|
159 |
/**
|
160 |
* This panel lets the user choose the dot density legend settings
|
161 |
* (numeric field, density of points, etc)
|
162 |
*
|
163 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
164 |
* @param <JNumberSpinner>
|
165 |
*
|
166 |
*/
|
167 |
public class DotDensityPanel extends JPanel implements ILegendPanel { |
168 |
|
169 |
private static Logger logger = LoggerFactory.getLogger(DotDensityPanel.class); |
170 |
|
171 |
private static final int MAX_VALUE_COUNT = 300; |
172 |
private FLyrVect layer;
|
173 |
private JPanel northPanel = null; |
174 |
private GridBagLayoutPanel densityButtonsPanel = null; |
175 |
private JPanel pnlDensities = null; |
176 |
private JComboBox cmbLegendField = null; |
177 |
private JRadioButton rdBtnHigh = null; |
178 |
private JRadioButton rdBtnMedium = null; |
179 |
private JRadioButton rdBtnLow = null; |
180 |
private JNumberSpinner numDotSize = null; |
181 |
|
182 |
private JNumberSpinner nmbrDotValue = null; |
183 |
private JLabel lblLabellingField = null; |
184 |
private DotDensityLegend legend;
|
185 |
|
186 |
private String theFieldName; |
187 |
private int theFieldType; |
188 |
|
189 |
private boolean initializing; |
190 |
private double max; |
191 |
private double maxDotSize = 0; |
192 |
private double b, a; // line function params where: y = bx + a |
193 |
private int theValueCount; |
194 |
|
195 |
|
196 |
private NumberFormat nf = NumberFormat.getInstance(); |
197 |
{ |
198 |
nf.setMaximumFractionDigits(3);
|
199 |
} |
200 |
private MyListener cmbAction = new MyListener(); |
201 |
|
202 |
private class MyListener implements ItemListener, ActionListener { |
203 |
public void itemStateChanged(ItemEvent e) { |
204 |
if (!initializing)
|
205 |
doIt(); |
206 |
} |
207 |
|
208 |
public void actionPerformed(ActionEvent e) { |
209 |
if (!initializing)
|
210 |
doIt(); |
211 |
} |
212 |
|
213 |
private void doIt() { |
214 |
int index = cmbLegendField.getSelectedIndex();
|
215 |
try {
|
216 |
FeatureStore fsto = (FeatureStore) layer.getDataStore(); |
217 |
FeatureSet fset = fsto.getFeatureSet(); |
218 |
FeatureType fty = fsto.getDefaultFeatureType(); |
219 |
|
220 |
if (index != -1) { |
221 |
theFieldName = (String) cmbLegendField.getSelectedItem();
|
222 |
} else {
|
223 |
theFieldName = (String) cmbLegendField.getItemAt(0); |
224 |
} |
225 |
|
226 |
FeatureAttributeDescriptor att = |
227 |
fty.getAttributeDescriptor(theFieldName); |
228 |
theFieldType = att.getDataType().getType(); |
229 |
|
230 |
long vc = 0; |
231 |
// (rowCount > MAX_VALUE_COUNT) ? MAX_VALUE_COUNT : (int) rowCount;
|
232 |
|
233 |
double maxValue = -Double.MAX_VALUE; |
234 |
double minValue = Double.MAX_VALUE; |
235 |
|
236 |
DisposableIterator disp = fset.fastIterator(); |
237 |
Feature fitem = null;
|
238 |
double value = 0; |
239 |
|
240 |
int i = 0; |
241 |
while (i < MAX_VALUE_COUNT && disp.hasNext()) {
|
242 |
|
243 |
fitem = (Feature) disp.next(); |
244 |
value = fitem.getDouble(theFieldName); |
245 |
if (value < minValue){
|
246 |
minValue = value; |
247 |
} |
248 |
if (value > maxValue){
|
249 |
maxValue = value; |
250 |
} |
251 |
// ==========
|
252 |
i++; |
253 |
} |
254 |
disp.dispose(); |
255 |
theValueCount = i; |
256 |
if (theValueCount == 0) { |
257 |
b = 0;
|
258 |
a = minValue; |
259 |
} else {
|
260 |
b = (maxValue - minValue)/(theValueCount); |
261 |
a = minValue; |
262 |
} |
263 |
buttonsListener.actionPerformed(null);
|
264 |
|
265 |
} catch (Exception ex) { |
266 |
logger.info("Error while computing a,b.", ex);
|
267 |
|
268 |
ApplicationLocator.getManager().message( |
269 |
Messages.getText("error") +
|
270 |
" (" + Messages.getText("dot_density") + ")\n\n" |
271 |
+ ex.getMessage(), |
272 |
JOptionPane.ERROR_MESSAGE);
|
273 |
} |
274 |
} |
275 |
} |
276 |
|
277 |
|
278 |
private ActionListener buttonsListener = new ActionListener() { |
279 |
public void actionPerformed(ActionEvent e) { |
280 |
int oldValue = getSldDensity().getValue();
|
281 |
int newValue = 0; |
282 |
if (getRdBtnHigh().isSelected()) {
|
283 |
newValue = 33;
|
284 |
} else if (getRdBtnLow().isSelected()) { |
285 |
newValue = 66;
|
286 |
} else if (getRdBtnMedium().isSelected()) { |
287 |
newValue = 50;
|
288 |
} |
289 |
if (oldValue == newValue){
|
290 |
sldListener.stateChanged(null);
|
291 |
} else{
|
292 |
getSldDensity().setValue(newValue); |
293 |
} |
294 |
} |
295 |
}; |
296 |
private JPanel centerPanel = null; |
297 |
private JSlider sldDensity = null; |
298 |
|
299 |
private boolean dotValueChanging= false; |
300 |
|
301 |
private ChangeListener sldListener = new ChangeListener() { |
302 |
public void stateChanged(ChangeEvent e) { |
303 |
if (dotValueChanging){
|
304 |
return;
|
305 |
} |
306 |
|
307 |
dotValueChanging = true;
|
308 |
double d = sldValueToDotValue(getSldDensity().getValue());
|
309 |
nmbrDotValue.setDouble(d); |
310 |
dotValueChanging = false;
|
311 |
} |
312 |
|
313 |
}; |
314 |
|
315 |
|
316 |
private ActionListener nmbrDotValueListener = new ActionListener(){ |
317 |
public void actionPerformed(ActionEvent e) { |
318 |
if (dotValueChanging){
|
319 |
return;
|
320 |
} |
321 |
|
322 |
dotValueChanging = true;
|
323 |
double dotValue = getNmbrDotValue().getDouble();
|
324 |
if (dotValue < 0) dotValue = 0; |
325 |
int result = dotValueToSldValue(dotValue);
|
326 |
getSldDensity().setValue(result); |
327 |
dotValueChanging = false;
|
328 |
} |
329 |
}; |
330 |
|
331 |
private ColorChooserPanel jcc;
|
332 |
private ILegend oldLegend;
|
333 |
private JSymbolPreviewButton btnOutline;
|
334 |
private ColorChooserPanel jccBackground;
|
335 |
|
336 |
public DotDensityPanel() {
|
337 |
super();
|
338 |
initialize(); |
339 |
} |
340 |
|
341 |
/**
|
342 |
* This method initializes this
|
343 |
*
|
344 |
*/
|
345 |
private void initialize() { |
346 |
this.setLayout(new BorderLayout()); |
347 |
this.setSize(new java.awt.Dimension(492,278)); |
348 |
this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
|
349 |
this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
|
350 |
} |
351 |
|
352 |
private double sldValueToDotValue(int value){ |
353 |
int quantileIndex = (theValueCount*value)/100; |
354 |
double d = (b*quantileIndex+a); // /50; // ?por qu? el 50? |
355 |
return d;
|
356 |
} |
357 |
|
358 |
private int dotValueToSldValue(double value){ |
359 |
int quantileIndex = (int)Math.round((value-a)/b); |
360 |
int result = 100*quantileIndex/theValueCount; |
361 |
return result;
|
362 |
} |
363 |
|
364 |
public void setData(FLayer lyr, ILegend legend) { |
365 |
this.layer = (FLyrVect) lyr;
|
366 |
this.oldLegend = legend.cloneLegend();
|
367 |
|
368 |
try {
|
369 |
// Para evitar los campos no pertenecientes a la fuente original de la capa.
|
370 |
// SelectableDataSource sds = layer.getSource().getRecordset();
|
371 |
// FJP: Otra vez con soporte del join
|
372 |
// SelectableDataSource sds = layer.getRecordset();
|
373 |
FeatureStore fsto = (FeatureStore) layer.getDataStore(); |
374 |
FeatureType fty = fsto.getDefaultFeatureType(); |
375 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
376 |
|
377 |
initializing = true; // silents events to the combo box |
378 |
cmbLegendField.removeAllItems(); |
379 |
for (int i = 0; i < atts.length; i++) { |
380 |
if (atts[i].getDataType().isNumeric()) {
|
381 |
cmbLegendField.addItem(atts[i].getName()); |
382 |
} |
383 |
} |
384 |
|
385 |
if (!(legend instanceof DotDensityLegend)) { |
386 |
legend = new DotDensityLegend();
|
387 |
((DotDensityLegend) legend).setClassifyingFieldNames( |
388 |
new String[] {(String) cmbLegendField.getItemAt(0)}); |
389 |
((DotDensityLegend) legend).setShapeType(layer.getShapeType()); |
390 |
} |
391 |
|
392 |
DotDensityLegend theLegend = (DotDensityLegend) legend; |
393 |
|
394 |
initializing = false; // enables events to the combo box |
395 |
|
396 |
cmbLegendField.setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
|
397 |
try {
|
398 |
getDotColorChooserPanel().setColor(theLegend.getDotColor()); |
399 |
} catch (NullPointerException npEx) { |
400 |
getDotColorChooserPanel().setColor(Color.RED);
|
401 |
} |
402 |
try {
|
403 |
getBackgroundColorChooserPanel().setColor(theLegend.getBGColor()); |
404 |
} catch (NullPointerException npEx) { |
405 |
getDotColorChooserPanel().setColor(Color.WHITE);
|
406 |
} |
407 |
|
408 |
getBtnOutline().setSymbol(theLegend.getOutline()); |
409 |
try {
|
410 |
double dotValue = theLegend.getDotValue();
|
411 |
if (dotValue <= 0) |
412 |
dotValue = sldValueToDotValue(50);//100; |
413 |
getNmbrDotValue().setDouble(dotValue); |
414 |
dotValueChanging = true;
|
415 |
getSldDensity().setValue(dotValueToSldValue(dotValue)); |
416 |
dotValueChanging = false;
|
417 |
|
418 |
} catch (NullPointerException npEx) { |
419 |
getSldDensity().setValue(50);
|
420 |
} |
421 |
try {
|
422 |
double dotSize = theLegend.getDotSize();
|
423 |
if (dotSize <= 0) |
424 |
dotSize = 2;
|
425 |
getNumDotSize().setDouble(dotSize); |
426 |
} catch (NullPointerException npEx) { |
427 |
getNumDotSize().setDouble(3);
|
428 |
} |
429 |
|
430 |
} catch (Exception e) { |
431 |
e.printStackTrace(); |
432 |
} |
433 |
} |
434 |
|
435 |
public ILegend getLegend() {
|
436 |
try {
|
437 |
int shapeType = layer.getShapeType();
|
438 |
|
439 |
// shapeType should be always polygon
|
440 |
if (!DotDensityLegend.isPolygonal(shapeType)) {
|
441 |
|
442 |
ApplicationLocator.getManager().message( |
443 |
Messages.getText("cannot_apply_to_a_non_polygon_layer"),
|
444 |
JOptionPane.ERROR_MESSAGE);
|
445 |
return null; |
446 |
} |
447 |
|
448 |
// gather values
|
449 |
double dotValue;
|
450 |
double dotSize;
|
451 |
try {
|
452 |
// dotValue = Double.parseDouble(nmbrDotValue.getText());
|
453 |
dotValue = nmbrDotValue.getDouble(); |
454 |
} catch (Exception e) { |
455 |
// dotValue = nf.parse(nmbrDotValue.getText()).doubleValue();
|
456 |
dotValue = nmbrDotValue.getDouble(); |
457 |
} |
458 |
if (dotValue == 0) |
459 |
dotValue = 1;
|
460 |
try {
|
461 |
// dotSize = Double.parseDouble(numDotSize.getText());
|
462 |
dotSize = numDotSize.getDouble(); |
463 |
} catch (Exception e) { |
464 |
// dotSize = nf.parse(numDotSize.getText()).doubleValue();
|
465 |
dotSize = numDotSize.getDouble(); |
466 |
} |
467 |
|
468 |
if (max/dotValue > 50000) { |
469 |
int option = JOptionPane.showConfirmDialog(this, |
470 |
Messages.getText("looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"),
|
471 |
Messages.getText("warning"),
|
472 |
JOptionPane.OK_CANCEL_OPTION);
|
473 |
if (option == JOptionPane.CANCEL_OPTION) |
474 |
return oldLegend;
|
475 |
} |
476 |
|
477 |
// create the density symbol with the values set above
|
478 |
DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol();
|
479 |
densitySymbol.setDotSize(dotSize); |
480 |
densitySymbol.setDotColor(getDotColorChooserPanel().getColor()); |
481 |
|
482 |
// create a simple-fill symbol over which the dot density will be drawn
|
483 |
SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
|
484 |
fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor()); |
485 |
fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol()); |
486 |
|
487 |
// combine both the DotDensitySymbol and the SimpleFillSymbol in
|
488 |
// MultiLayerSymbol so they will be paint as a unique ISymbol
|
489 |
MultiLayerFillSymbol symbol = new MultiLayerFillSymbol();
|
490 |
symbol.setDescription( |
491 |
"DotDensitySymbol" + Messages.getText("in_layer") + |
492 |
": '"+layer.getName()+"'"); |
493 |
symbol.addLayer(fillSymbol); |
494 |
symbol.addLayer(densitySymbol); |
495 |
|
496 |
legend = new DotDensityLegend();
|
497 |
legend.addSymbol(Messages.getText("theSymbol"), symbol);
|
498 |
legend.setDefaultSymbol(symbol); |
499 |
legend.setDotValue(dotValue); |
500 |
|
501 |
legend.setClassifyingFieldNames(new String[] { theFieldName }); |
502 |
legend.setClassifyingFieldTypes(new int[] { theFieldType }); |
503 |
|
504 |
legend.setBGColor(getBackgroundColorChooserPanel().getColor()); |
505 |
legend.setDotColor(getDotColorChooserPanel().getColor()); |
506 |
|
507 |
} catch (Exception e) { |
508 |
|
509 |
ApplicationLocator.getManager().message( |
510 |
Messages.getText("could_not_setup_legend"),
|
511 |
JOptionPane.ERROR_MESSAGE);
|
512 |
} |
513 |
return legend;
|
514 |
|
515 |
} |
516 |
|
517 |
/**
|
518 |
* This method initializes centerPanel
|
519 |
*
|
520 |
* @return javax.swing.JPanel
|
521 |
*/
|
522 |
private JPanel getNorthPanel() { |
523 |
if (northPanel == null) { |
524 |
lblLabellingField = new JLabel(); |
525 |
lblLabellingField.setText(Messages.getText("labeling_field")+"."); |
526 |
northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,15,0)); |
527 |
northPanel.add(lblLabellingField, null);
|
528 |
northPanel.add(getCmbLegendField(), null);
|
529 |
|
530 |
} |
531 |
return northPanel;
|
532 |
} |
533 |
|
534 |
private ColorChooserPanel getDotColorChooserPanel() {
|
535 |
if (jcc == null) { |
536 |
jcc = new ColorChooserPanel() ;
|
537 |
jcc.setAlpha(255);
|
538 |
} |
539 |
return jcc;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* This method initializes southPanel
|
544 |
*
|
545 |
* @return javax.swing.JPanel
|
546 |
*/
|
547 |
private JPanel getDensityButtonsPanel() { |
548 |
if (densityButtonsPanel == null) { |
549 |
densityButtonsPanel = new GridBagLayoutPanel();
|
550 |
LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0,0); |
551 |
JPanel aux = new JPanel(layout); |
552 |
aux.add(getNumDotSize()); |
553 |
densityButtonsPanel.addComponent( |
554 |
Messages.getText("dot_size"), aux);
|
555 |
aux = new JPanel(layout); |
556 |
aux.add(getNmbrDotValue()); |
557 |
densityButtonsPanel.addComponent( |
558 |
Messages.getText("dot_value"), aux);
|
559 |
aux = new JPanel(layout); |
560 |
aux.add(getDotColorChooserPanel()); |
561 |
densityButtonsPanel.addComponent( |
562 |
Messages.getText("color"), aux);
|
563 |
aux = new JPanel(layout); |
564 |
aux.add(getBackgroundColorChooserPanel()); |
565 |
densityButtonsPanel.addComponent( |
566 |
Messages.getText("background_color"), aux);
|
567 |
aux = new JPanel(layout); |
568 |
aux.add(getBtnOutline()); |
569 |
densityButtonsPanel.addComponent( |
570 |
Messages.getText("outline"), aux);
|
571 |
} |
572 |
return densityButtonsPanel;
|
573 |
} |
574 |
|
575 |
private ColorChooserPanel getBackgroundColorChooserPanel() {
|
576 |
if (jccBackground == null) { |
577 |
jccBackground = new ColorChooserPanel() ;
|
578 |
jccBackground.setColor(Color.WHITE);
|
579 |
jccBackground.setAlpha(255);
|
580 |
} |
581 |
return jccBackground;
|
582 |
} |
583 |
|
584 |
private JSymbolPreviewButton getBtnOutline() {
|
585 |
if (btnOutline == null) { |
586 |
btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
|
587 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
588 |
} |
589 |
return btnOutline;
|
590 |
} |
591 |
|
592 |
/**
|
593 |
* This method initializes pnlDensities
|
594 |
*
|
595 |
* @return javax.swing.JPanel
|
596 |
*/
|
597 |
private JPanel getPnlDensities() { |
598 |
if (pnlDensities == null) { |
599 |
pnlDensities = new JPanel(new BorderLayout(5,0)); |
600 |
pnlDensities.setBorder(BorderFactory.createTitledBorder(null, |
601 |
Messages.getText("densities")));
|
602 |
JPanel aux2 = new JPanel(); |
603 |
JPanel aux;
|
604 |
aux = new JPanel(new GridLayout(1,3)); |
605 |
aux.add(new JLabel(Messages.getText("low"))); |
606 |
aux.add(new JLabel(Messages.getText("medium"))); |
607 |
aux.add(new JLabel(Messages.getText("high"))); |
608 |
|
609 |
aux2.add(aux); |
610 |
|
611 |
aux = new JPanel(new GridLayout(1,3)); |
612 |
aux.add(getRdBtnLow()); |
613 |
aux.add(getRdBtnMedium()); |
614 |
aux.add(getRdBtnHigh()); |
615 |
|
616 |
aux2.add(aux); |
617 |
aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS)); |
618 |
|
619 |
pnlDensities.add(aux2, BorderLayout.NORTH);
|
620 |
pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
|
621 |
pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
|
622 |
|
623 |
ButtonGroup group = new ButtonGroup(); |
624 |
group.add(getRdBtnHigh()); |
625 |
group.add(getRdBtnLow()); |
626 |
group.add(getRdBtnMedium()); |
627 |
getRdBtnMedium().setSelected(true);
|
628 |
} |
629 |
return pnlDensities;
|
630 |
} |
631 |
|
632 |
|
633 |
/**
|
634 |
* This method initializes cmbLegendField
|
635 |
*
|
636 |
* @return javax.swing.JComboBox
|
637 |
*/
|
638 |
private JComboBox getCmbLegendField() { |
639 |
if (cmbLegendField == null) { |
640 |
cmbLegendField = new JComboBox(); |
641 |
cmbLegendField.addActionListener(cmbAction); |
642 |
} |
643 |
return cmbLegendField;
|
644 |
} |
645 |
|
646 |
/**
|
647 |
* This method initializes rdBtnHigh
|
648 |
*
|
649 |
* @return javax.swing.JRadioButton
|
650 |
*/
|
651 |
private JRadioButton getRdBtnHigh() { |
652 |
if (rdBtnHigh == null) { |
653 |
Icon ic = IconThemeHelper.getImageIcon(
|
654 |
"legend-dot-density-high-density-sample");
|
655 |
rdBtnHigh = new JRadioButton(ic); |
656 |
rdBtnHigh.addActionListener(buttonsListener); |
657 |
} |
658 |
return rdBtnHigh;
|
659 |
} |
660 |
|
661 |
/**
|
662 |
* This method initializes rdBtnMedium
|
663 |
*
|
664 |
* @return javax.swing.JRadioButton
|
665 |
*/
|
666 |
private JRadioButton getRdBtnMedium() { |
667 |
if (rdBtnMedium == null) { |
668 |
Icon ic = IconThemeHelper.getImageIcon(
|
669 |
"legend-dot-density-medium-density-sample");
|
670 |
rdBtnMedium = new JRadioButton(ic); |
671 |
rdBtnMedium.addActionListener(buttonsListener); |
672 |
} |
673 |
return rdBtnMedium;
|
674 |
} |
675 |
|
676 |
/**
|
677 |
* This method initializes rdBtnMax
|
678 |
*
|
679 |
* @return javax.swing.JRadioButton
|
680 |
*/
|
681 |
private JRadioButton getRdBtnLow() { |
682 |
if (rdBtnLow == null) { |
683 |
Icon ic = IconThemeHelper.getImageIcon(
|
684 |
"legend-dot-density-low-density-sample");
|
685 |
rdBtnLow = new JRadioButton(ic); |
686 |
rdBtnLow.addActionListener(buttonsListener); |
687 |
} |
688 |
return rdBtnLow;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* This method initializes numDotSize
|
693 |
*
|
694 |
* @return de.ios.framework.swing.JNumberField
|
695 |
*/
|
696 |
private JNumberSpinner getNumDotSize() {
|
697 |
if (numDotSize == null) { |
698 |
numDotSize = new JNumberSpinner(1.0, 4, 0.0, Double.MAX_VALUE, 1.0, 2); |
699 |
} |
700 |
return numDotSize;
|
701 |
} |
702 |
|
703 |
/**
|
704 |
* This method initializes nmbrDotValue
|
705 |
*
|
706 |
* @return de.ios.framework.swing.JNumberField
|
707 |
*/
|
708 |
private JNumberSpinner getNmbrDotValue() {
|
709 |
if (nmbrDotValue == null) { |
710 |
nmbrDotValue = new JNumberSpinner(1.0, 15, 0.01, Double.MAX_VALUE, 1.0, 2); |
711 |
nmbrDotValue.addActionListener(nmbrDotValueListener); |
712 |
|
713 |
} |
714 |
return nmbrDotValue;
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* This method initializes centerPanel
|
719 |
*
|
720 |
* @return javax.swing.JPanel
|
721 |
*/
|
722 |
private JPanel getCenterPanel() { |
723 |
if (centerPanel == null) { |
724 |
centerPanel = new JPanel(); |
725 |
centerPanel.setLayout(new BorderLayout(5, 5)); |
726 |
centerPanel.add(getPnlDensities(), java.awt.BorderLayout.WEST); |
727 |
} |
728 |
return centerPanel;
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* This method initializes sldDensity
|
733 |
*
|
734 |
* @return javax.swing.JSlider
|
735 |
*/
|
736 |
private JSlider getSldDensity() { |
737 |
if (sldDensity == null) { |
738 |
sldDensity = new JSlider(); |
739 |
sldDensity.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
740 |
sldDensity.addChangeListener(sldListener); |
741 |
} |
742 |
return sldDensity;
|
743 |
} |
744 |
|
745 |
public String getDescription() { |
746 |
return Messages.getText("Defines_a_dot_density_symbol_based_on_a_field_value") + "."; |
747 |
} |
748 |
|
749 |
public ImageIcon getIcon() { |
750 |
ImageIcon ic = IconThemeHelper.getImageIcon(
|
751 |
"legend-overview-dot-density");
|
752 |
return ic;
|
753 |
} |
754 |
|
755 |
public Class getParentClass() { |
756 |
return Quantities.class;
|
757 |
} |
758 |
|
759 |
public String getTitle() { |
760 |
return Messages.getText("dot_density"); |
761 |
} |
762 |
|
763 |
public JPanel getPanel() { |
764 |
return this; |
765 |
} |
766 |
|
767 |
public Class getLegendClass() { |
768 |
return DotDensityLegend.class;
|
769 |
} |
770 |
|
771 |
public boolean isSuitableFor(FLayer layer) { |
772 |
if (layer instanceof FLyrVect) { |
773 |
try {
|
774 |
FLyrVect lyr = (FLyrVect) layer; |
775 |
if (!DotDensityLegend.isPolygonal(lyr.getShapeType())) {
|
776 |
return false; |
777 |
} |
778 |
|
779 |
FeatureStore fsto = (FeatureStore) lyr.getDataStore(); |
780 |
FeatureType fty = fsto.getDefaultFeatureType(); |
781 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
782 |
|
783 |
for (int i=0; i<atts.length; i++) { |
784 |
if (atts[i].getDataType().isNumeric()) {
|
785 |
return true; |
786 |
} |
787 |
} |
788 |
} catch (Exception e) { |
789 |
|
790 |
ApplicationLocator.getManager().messageDialog( |
791 |
Messages.getText("error_trying_to_access_to_the_layer"),
|
792 |
Messages.getText("error"),
|
793 |
JOptionPane.ERROR_MESSAGE);
|
794 |
return false; |
795 |
} |
796 |
} |
797 |
return false; |
798 |
} |
799 |
|
800 |
} |