root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / DotDensity.java @ 14821
History | View | Annotate | Download (21.3 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 14821 2007-10-22 12:15:26Z 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 com.iver.cit.gvsig.project.documents.view.legend.gui; |
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.sql.Types; |
116 |
import java.text.NumberFormat; |
117 |
|
118 |
import javax.swing.BorderFactory; |
119 |
import javax.swing.BoxLayout; |
120 |
import javax.swing.ButtonGroup; |
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.gvsig.gui.beans.swing.GridBagLayoutPanel; |
132 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
133 |
|
134 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
135 |
import com.hardcode.gdbms.engine.values.NumericValue; |
136 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
137 |
import com.iver.andami.PluginServices; |
138 |
import com.iver.andami.messages.NotificationManager; |
139 |
import com.iver.cit.gvsig.fmap.core.FShape; |
140 |
import com.iver.cit.gvsig.fmap.core.symbols.DotDensityFillSymbol; |
141 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
142 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
143 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol; |
144 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
145 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
146 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
147 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
148 |
import com.iver.cit.gvsig.fmap.rendering.DotDensityLegend; |
149 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
150 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
151 |
|
152 |
/**
|
153 |
*
|
154 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
155 |
*
|
156 |
*/
|
157 |
public class DotDensity extends JPanel implements ILegendPanel { |
158 |
private static final int MAX_VALUE_COUNT = 300; |
159 |
private FLyrVect layer;
|
160 |
private JPanel northPanel = null; |
161 |
private GridBagLayoutPanel densityButtonsPanel = null; |
162 |
private JPanel pnlDensities = null; |
163 |
private JComboBox cmbLegendField = null; |
164 |
private JRadioButton rdBtnHigh = null; |
165 |
private JRadioButton rdBtnMedium = null; |
166 |
private JRadioButton rdBtnLow = null; |
167 |
private JIncrementalNumberField numDotSize = null; |
168 |
|
169 |
private JIncrementalNumberField nmbrDotValue = null; |
170 |
private JLabel lblLabellingField = null; |
171 |
private DotDensityLegend legend;
|
172 |
private String fieldName; |
173 |
private boolean initializing; |
174 |
private double max; |
175 |
private double b, a; // regression function params where: y = bx + a |
176 |
private int valueCount; |
177 |
|
178 |
private NumberFormat nf = NumberFormat.getInstance(); |
179 |
{ |
180 |
nf.setMaximumFractionDigits(3);
|
181 |
} |
182 |
private MyListener cmbAction = new MyListener(); |
183 |
|
184 |
private class MyListener implements ItemListener, ActionListener { |
185 |
public void itemStateChanged(ItemEvent e) { |
186 |
if (!initializing)
|
187 |
doIt(); |
188 |
} |
189 |
|
190 |
public void actionPerformed(ActionEvent e) { |
191 |
if (!initializing)
|
192 |
doIt(); |
193 |
} |
194 |
|
195 |
private void doIt() { |
196 |
int index = cmbLegendField.getSelectedIndex();
|
197 |
try {
|
198 |
SelectableDataSource sds = layer.getRecordset(); |
199 |
|
200 |
if (index != -1) { |
201 |
fieldName = (String) cmbLegendField.getSelectedItem();
|
202 |
} else {
|
203 |
fieldName = (String) cmbLegendField.getItemAt(0); |
204 |
} |
205 |
|
206 |
int fieldIndex = sds.getFieldIndexByName(fieldName);
|
207 |
|
208 |
// will extract a "Minimum Square Adjustment" regression function.
|
209 |
long rowCount = sds.getRowCount();
|
210 |
valueCount = (rowCount > MAX_VALUE_COUNT) ? MAX_VALUE_COUNT : (int) rowCount;
|
211 |
|
212 |
double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxy = 0; |
213 |
double Sxx, Sxy;
|
214 |
|
215 |
for (int i = 0; i < valueCount; i++) { |
216 |
double value = ((NumericValue) sds.getFieldValue(i,fieldIndex)).doubleValue();
|
217 |
sumx += i; |
218 |
sumy += value; |
219 |
sumxx += i*i; |
220 |
sumyy += value*value; |
221 |
sumxy += i*value; |
222 |
} |
223 |
|
224 |
// start regression
|
225 |
double n = (double) valueCount; |
226 |
Sxx = sumxx-sumx*sumx/n; |
227 |
Sxy = sumxy-sumx*sumy/n; |
228 |
b = Sxy/Sxx; |
229 |
a = (sumy-b*sumx)/n; |
230 |
|
231 |
buttonsListener.actionPerformed(null);
|
232 |
|
233 |
} catch (Exception ex) { |
234 |
ex.printStackTrace(); |
235 |
} |
236 |
} |
237 |
}; |
238 |
private ActionListener buttonsListener = new ActionListener() { |
239 |
public void actionPerformed(ActionEvent e) { |
240 |
if (getRdBtnHigh().isSelected()) {
|
241 |
getSldDensity().setValue(66);
|
242 |
} else if (getRdBtnLow().isSelected()) { |
243 |
getSldDensity().setValue(33);
|
244 |
} else if (getRdBtnMedium().isSelected()) { |
245 |
getSldDensity().setValue(50);
|
246 |
} |
247 |
} |
248 |
}; |
249 |
private JPanel centerPanel = null; |
250 |
private JSlider sldDensity = null; |
251 |
|
252 |
private ChangeListener sldListener = new ChangeListener() { |
253 |
|
254 |
public void stateChanged(ChangeEvent e) { |
255 |
|
256 |
int quantileIndex = (MAX_VALUE_COUNT*getSldDensity().getValue())/100; |
257 |
nmbrDotValue.setDouble((b*quantileIndex+a)/50);
|
258 |
|
259 |
} |
260 |
|
261 |
}; |
262 |
private ColorChooserPanel jcc;
|
263 |
private ColorChooserPanel outlineColorChooserPanel;
|
264 |
private ILegend oldLegend;
|
265 |
private JSymbolPreviewButton btnOutline;
|
266 |
private ColorChooserPanel jccBackground;
|
267 |
|
268 |
public DotDensity() {
|
269 |
super();
|
270 |
initialize(); |
271 |
} |
272 |
|
273 |
/**
|
274 |
* This method initializes this
|
275 |
*
|
276 |
*/
|
277 |
private void initialize() { |
278 |
this.setLayout(new BorderLayout()); |
279 |
this.setSize(new java.awt.Dimension(492,278)); |
280 |
this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
|
281 |
|
282 |
this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
|
283 |
} |
284 |
|
285 |
public void setData(FLayer lyr, ILegend legend) { |
286 |
this.layer = (FLyrVect) lyr;
|
287 |
this.oldLegend = legend;
|
288 |
try {
|
289 |
SelectableDataSource sds = layer.getRecordset(); |
290 |
initializing = true; // silents events to the combo box |
291 |
cmbLegendField.removeAllItems(); |
292 |
String[] fNames = sds.getFieldNames(); |
293 |
for (int i = 0; i < fNames.length; i++) { |
294 |
if (isNumericField(sds.getFieldType(i))) {
|
295 |
cmbLegendField.addItem(fNames[i]); |
296 |
} |
297 |
} |
298 |
if (!(legend instanceof DotDensityLegend)) { |
299 |
legend = new DotDensityLegend();
|
300 |
((DotDensityLegend) legend).setClassifyingFieldNames( |
301 |
new String[] {(String) cmbLegendField.getItemAt(0)}); |
302 |
((DotDensityLegend) legend).setShapeType(layer.getShapeType()); |
303 |
} |
304 |
|
305 |
DotDensityLegend theLegend = (DotDensityLegend) legend; |
306 |
|
307 |
initializing = false; // enables events to the combo box |
308 |
|
309 |
cmbLegendField.setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
|
310 |
try {
|
311 |
getDotColorChooserPanel().setColor(theLegend.getDotColor()); |
312 |
} catch (NullPointerException npEx) { |
313 |
getDotColorChooserPanel().setColor(Color.RED);
|
314 |
} |
315 |
try {
|
316 |
getBackgroundColorChooserPanel().setColor(theLegend.getBGColor()); |
317 |
} catch (NullPointerException npEx) { |
318 |
getDotColorChooserPanel().setColor(Color.WHITE);
|
319 |
} |
320 |
|
321 |
getBtnOutline().setSymbol(theLegend.getOutline()); |
322 |
try {
|
323 |
double dotValue = theLegend.getDotValue();
|
324 |
if (dotValue <= 0) |
325 |
dotValue = 100;
|
326 |
getNmbrDotValue().setDouble(dotValue); |
327 |
|
328 |
} catch (NullPointerException npEx) { |
329 |
getNmbrDotValue().setDouble(max); |
330 |
} |
331 |
try {
|
332 |
double dotSize = theLegend.getDotSize();
|
333 |
if (dotSize <= 0) |
334 |
dotSize = 2;
|
335 |
getNumDotSize().setDouble(dotSize); |
336 |
} catch (NullPointerException npEx) { |
337 |
getNumDotSize().setDouble(3);
|
338 |
} |
339 |
|
340 |
} catch (Exception e) { |
341 |
e.printStackTrace(); |
342 |
} |
343 |
} |
344 |
|
345 |
private boolean isNumericField(int fieldType) { |
346 |
switch (fieldType) {
|
347 |
case Types.BIGINT: |
348 |
case Types.DECIMAL: |
349 |
case Types.DOUBLE: |
350 |
case Types.FLOAT: |
351 |
case Types.INTEGER: |
352 |
case Types.NUMERIC: |
353 |
case Types.REAL: |
354 |
case Types.SMALLINT: |
355 |
case Types.TINYINT: |
356 |
return true; |
357 |
default:
|
358 |
return false; |
359 |
} |
360 |
|
361 |
} |
362 |
|
363 |
public ILegend getLegend() {
|
364 |
try {
|
365 |
int shapeType = layer.getShapeType();
|
366 |
|
367 |
// shapeType should be always polygon
|
368 |
if (shapeType != FShape.POLYGON) {
|
369 |
NotificationManager.addError(PluginServices.getText(this, "cannot_apply_to_a_non_polygon_layer"), new Exception()); |
370 |
} |
371 |
|
372 |
// check if the field exists (this is probably dead code)
|
373 |
SelectableDataSource sds; |
374 |
sds = layer.getRecordset(); |
375 |
if (-1 == sds.getFieldIndexByName(fieldName)) |
376 |
return null; |
377 |
|
378 |
// gather values
|
379 |
double dotValue;
|
380 |
double dotSize;
|
381 |
try {
|
382 |
// dotValue = Double.parseDouble(nmbrDotValue.getText());
|
383 |
dotValue = nmbrDotValue.getDouble(); |
384 |
} catch (Exception e) { |
385 |
// dotValue = nf.parse(nmbrDotValue.getText()).doubleValue();
|
386 |
dotValue = nmbrDotValue.getDouble(); |
387 |
} |
388 |
if (dotValue == 0) |
389 |
dotValue = 1;
|
390 |
try {
|
391 |
// dotSize = Double.parseDouble(numDotSize.getText());
|
392 |
dotSize = numDotSize.getDouble(); |
393 |
} catch (Exception e) { |
394 |
// dotSize = nf.parse(numDotSize.getText()).doubleValue();
|
395 |
dotSize = numDotSize.getDouble(); |
396 |
} |
397 |
|
398 |
if (max/dotValue > 50000) { |
399 |
int option = JOptionPane.showConfirmDialog(this, |
400 |
PluginServices.getText(this, "looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"), |
401 |
PluginServices.getText(this, "warning"), |
402 |
JOptionPane.OK_CANCEL_OPTION);
|
403 |
if (option == JOptionPane.CANCEL_OPTION) |
404 |
return oldLegend;
|
405 |
} |
406 |
|
407 |
// create the density symbol with the values set above
|
408 |
DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol();
|
409 |
densitySymbol.setDotSize(dotSize); |
410 |
densitySymbol.setDotColor(getDotColorChooserPanel().getColor()); |
411 |
|
412 |
// create a simple-fill symbol over which the dot density will be drawn
|
413 |
SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
|
414 |
fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor()); |
415 |
fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol()); |
416 |
|
417 |
// combine both the DotDensitySymbol and the SimpleFillSymbol in
|
418 |
// MultiLayerSymbol so they will be paint as a unique ISymbol
|
419 |
MultiLayerFillSymbol symbol = new MultiLayerFillSymbol();
|
420 |
symbol.setDescription( |
421 |
"DotDensitySymbol" + PluginServices.getText(this, "in_layer") + |
422 |
": '"+layer.getName()+"'"); |
423 |
symbol.addLayer(fillSymbol); |
424 |
symbol.addLayer(densitySymbol); |
425 |
|
426 |
legend = new DotDensityLegend();
|
427 |
legend.addSymbol(ValueFactory.createValue("theSymbol"), symbol);
|
428 |
legend.setDefaultSymbol(symbol); |
429 |
legend.setDotValue(dotValue); |
430 |
legend.setClassifyingFieldNames(new String[] {fieldName}); |
431 |
|
432 |
|
433 |
} catch (Exception e) { |
434 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend")+".", e); |
435 |
} |
436 |
return legend;
|
437 |
|
438 |
} |
439 |
|
440 |
/**
|
441 |
* This method initializes centerPanel
|
442 |
*
|
443 |
* @return javax.swing.JPanel
|
444 |
*/
|
445 |
private JPanel getNorthPanel() { |
446 |
if (northPanel == null) { |
447 |
lblLabellingField = new JLabel(); |
448 |
lblLabellingField.setText(PluginServices.getText(this, "labeling_field")+"."); |
449 |
northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,15,0)); |
450 |
northPanel.add(lblLabellingField, null);
|
451 |
northPanel.add(getCmbLegendField(), null);
|
452 |
|
453 |
} |
454 |
return northPanel;
|
455 |
} |
456 |
|
457 |
private ColorChooserPanel getDotColorChooserPanel() {
|
458 |
if (jcc == null) { |
459 |
jcc = new ColorChooserPanel() ;
|
460 |
jcc.setAlpha(255);
|
461 |
} |
462 |
return jcc;
|
463 |
} |
464 |
|
465 |
/**
|
466 |
* This method initializes southPanel
|
467 |
*
|
468 |
* @return javax.swing.JPanel
|
469 |
*/
|
470 |
private JPanel getDensityButtonsPanel() { |
471 |
if (densityButtonsPanel == null) { |
472 |
densityButtonsPanel = new GridBagLayoutPanel();
|
473 |
LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0,0); |
474 |
JPanel aux = new JPanel(layout); |
475 |
aux.add(getNumDotSize()); |
476 |
densityButtonsPanel.addComponent( |
477 |
PluginServices.getText(this, "dot_size"), aux); |
478 |
aux = new JPanel(layout); |
479 |
aux.add(getNmbrDotValue()); |
480 |
densityButtonsPanel.addComponent( |
481 |
PluginServices.getText(this,"dot_value"), aux); |
482 |
aux = new JPanel(layout); |
483 |
aux.add(getDotColorChooserPanel()); |
484 |
densityButtonsPanel.addComponent( |
485 |
PluginServices.getText(this, "color"), aux); |
486 |
aux = new JPanel(layout); |
487 |
aux.add(getBackgroundColorChooserPanel()); |
488 |
densityButtonsPanel.addComponent( |
489 |
PluginServices.getText(this, "background_color"), aux); |
490 |
aux = new JPanel(layout); |
491 |
aux.add(getBtnOutline()); |
492 |
densityButtonsPanel.addComponent( |
493 |
PluginServices.getText(this, "outline"), aux); |
494 |
} |
495 |
return densityButtonsPanel;
|
496 |
} |
497 |
|
498 |
private ColorChooserPanel getBackgroundColorChooserPanel() {
|
499 |
if (jccBackground == null) { |
500 |
jccBackground = new ColorChooserPanel() ;
|
501 |
jccBackground.setColor(Color.WHITE);
|
502 |
jccBackground.setAlpha(255);
|
503 |
} |
504 |
return jccBackground;
|
505 |
} |
506 |
|
507 |
private JSymbolPreviewButton getBtnOutline() {
|
508 |
if (btnOutline == null) { |
509 |
btnOutline = new JSymbolPreviewButton(FShape.LINE);
|
510 |
btnOutline.setPreferredSize(new Dimension(100, 35)); |
511 |
} |
512 |
return btnOutline;
|
513 |
} |
514 |
|
515 |
/**
|
516 |
* This method initializes pnlDensities
|
517 |
*
|
518 |
* @return javax.swing.JPanel
|
519 |
*/
|
520 |
private JPanel getPnlDensities() { |
521 |
if (pnlDensities == null) { |
522 |
pnlDensities = new JPanel(new BorderLayout(5,0)); |
523 |
pnlDensities.setBorder(BorderFactory.createTitledBorder(null, |
524 |
PluginServices.getText(this, "densities"))); |
525 |
JPanel aux2 = new JPanel(); |
526 |
JPanel aux;
|
527 |
aux = new JPanel(new GridLayout(1,3)); |
528 |
aux.add(new JLabel(PluginServices.getText(this, "high"))); |
529 |
aux.add(new JLabel(PluginServices.getText(this, "medium"))); |
530 |
aux.add(new JLabel(PluginServices.getText(this, "low"))); |
531 |
|
532 |
aux2.add(aux); |
533 |
|
534 |
aux = new JPanel(new GridLayout(1,3)); |
535 |
aux.add(getRdBtnHigh()); |
536 |
aux.add(getRdBtnMedium()); |
537 |
aux.add(getRdBtnLow()); |
538 |
|
539 |
aux2.add(aux); |
540 |
aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS)); |
541 |
|
542 |
pnlDensities.add(aux2, BorderLayout.NORTH);
|
543 |
pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
|
544 |
pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
|
545 |
|
546 |
ButtonGroup group = new ButtonGroup(); |
547 |
group.add(getRdBtnHigh()); |
548 |
group.add(getRdBtnLow()); |
549 |
group.add(getRdBtnMedium()); |
550 |
getRdBtnMedium().setSelected(true);
|
551 |
} |
552 |
return pnlDensities;
|
553 |
} |
554 |
|
555 |
|
556 |
/**
|
557 |
* This method initializes cmbLegendField
|
558 |
*
|
559 |
* @return javax.swing.JComboBox
|
560 |
*/
|
561 |
private JComboBox getCmbLegendField() { |
562 |
if (cmbLegendField == null) { |
563 |
cmbLegendField = new JComboBox(); |
564 |
cmbLegendField.addActionListener(cmbAction); |
565 |
} |
566 |
return cmbLegendField;
|
567 |
} |
568 |
|
569 |
/**
|
570 |
* This method initializes rdBtnHigh
|
571 |
*
|
572 |
* @return javax.swing.JRadioButton
|
573 |
*/
|
574 |
private JRadioButton getRdBtnHigh() { |
575 |
if (rdBtnHigh == null) { |
576 |
rdBtnHigh = new JRadioButton(new ImageIcon( |
577 |
getClass().getClassLoader(). |
578 |
getResource("images/high-density-sample.png")));
|
579 |
rdBtnHigh.addActionListener(buttonsListener); |
580 |
} |
581 |
return rdBtnHigh;
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* This method initializes rdBtnMedium
|
586 |
*
|
587 |
* @return javax.swing.JRadioButton
|
588 |
*/
|
589 |
private JRadioButton getRdBtnMedium() { |
590 |
if (rdBtnMedium == null) { |
591 |
rdBtnMedium = new JRadioButton(PluginServices.getIconTheme() |
592 |
.get("medium-density"));
|
593 |
rdBtnMedium.addActionListener(buttonsListener); |
594 |
} |
595 |
return rdBtnMedium;
|
596 |
} |
597 |
|
598 |
/**
|
599 |
* This method initializes rdBtnMax
|
600 |
*
|
601 |
* @return javax.swing.JRadioButton
|
602 |
*/
|
603 |
private JRadioButton getRdBtnLow() { |
604 |
if (rdBtnLow == null) { |
605 |
rdBtnLow = new JRadioButton(PluginServices.getIconTheme().get("low-density")); |
606 |
rdBtnLow.addActionListener(buttonsListener); |
607 |
} |
608 |
return rdBtnLow;
|
609 |
} |
610 |
|
611 |
/**
|
612 |
* This method initializes numDotSize
|
613 |
*
|
614 |
* @return de.ios.framework.swing.JNumberField
|
615 |
*/
|
616 |
private JIncrementalNumberField getNumDotSize() {
|
617 |
if (numDotSize == null) { |
618 |
numDotSize = new JIncrementalNumberField(null, 4); |
619 |
} |
620 |
return numDotSize;
|
621 |
} |
622 |
|
623 |
/**
|
624 |
* This method initializes nmbrDotValue
|
625 |
*
|
626 |
* @return de.ios.framework.swing.JNumberField
|
627 |
*/
|
628 |
private JIncrementalNumberField getNmbrDotValue() {
|
629 |
if (nmbrDotValue == null) { |
630 |
nmbrDotValue = new JIncrementalNumberField(null, 15); |
631 |
|
632 |
} |
633 |
return nmbrDotValue;
|
634 |
} |
635 |
|
636 |
/**
|
637 |
* This method initializes centerPanel
|
638 |
*
|
639 |
* @return javax.swing.JPanel
|
640 |
*/
|
641 |
private JPanel getCenterPanel() { |
642 |
if (centerPanel == null) { |
643 |
centerPanel = new JPanel(); |
644 |
centerPanel.setLayout(new BorderLayout(5, 5)); |
645 |
centerPanel.add(getPnlDensities(), java.awt.BorderLayout.WEST); |
646 |
} |
647 |
return centerPanel;
|
648 |
} |
649 |
|
650 |
/**
|
651 |
* This method initializes sldDensity
|
652 |
*
|
653 |
* @return javax.swing.JSlider
|
654 |
*/
|
655 |
private JSlider getSldDensity() { |
656 |
if (sldDensity == null) { |
657 |
sldDensity = new JSlider(); |
658 |
sldDensity.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
659 |
sldDensity.addChangeListener(sldListener); |
660 |
} |
661 |
return sldDensity;
|
662 |
} |
663 |
|
664 |
public String getDescription() { |
665 |
return PluginServices.getText(this,"Defines_a_dot_density_symbol_based_on_a_field_value") + "."; |
666 |
} |
667 |
|
668 |
public ISymbol getIconSymbol() {
|
669 |
// TODO Implement it
|
670 |
return null; |
671 |
} |
672 |
|
673 |
public Class getParentClass() { |
674 |
return Quantities.class;
|
675 |
} |
676 |
|
677 |
public String getTitle() { |
678 |
return PluginServices.getText(this, "dot_density"); |
679 |
} |
680 |
|
681 |
public JPanel getPanel() { |
682 |
return this; |
683 |
} |
684 |
|
685 |
public Class getLegendClass() { |
686 |
return DotDensityLegend.class;
|
687 |
} |
688 |
|
689 |
public boolean isSuitableFor(FLayer layer) { |
690 |
if (layer instanceof FLyrVect) { |
691 |
try {
|
692 |
FLyrVect lyr = (FLyrVect) layer; |
693 |
|
694 |
if (lyr.getShapeType() != FShape.POLYGON)
|
695 |
return false; |
696 |
|
697 |
SelectableDataSource sds; |
698 |
sds = lyr.getRecordset(); |
699 |
String[] fNames = sds.getFieldNames(); |
700 |
for (int i = 0; i < fNames.length; i++) { |
701 |
if (isNumericField(sds.getFieldType(i))) {
|
702 |
return true; |
703 |
} |
704 |
} |
705 |
} catch (ReadDriverException e) {
|
706 |
return false; |
707 |
} |
708 |
} |
709 |
return false; |
710 |
} |
711 |
|
712 |
} // @jve:decl-index=0:visual-constraint="10,10"
|