Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / DotDensity.java @ 24821

History | View | Annotate | Download (22.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.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
import org.gvsig.symbology.fmap.rendering.DotDensityLegend;
134
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol;
135

    
136
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
137
import com.hardcode.gdbms.engine.values.NumericValue;
138
import com.hardcode.gdbms.engine.values.ValueFactory;
139
import com.iver.andami.PluginServices;
140
import com.iver.andami.messages.NotificationManager;
141
import com.iver.cit.gvsig.fmap.core.FShape;
142
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
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.layers.XMLException;
149
import com.iver.cit.gvsig.fmap.rendering.ILegend;
150
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
151
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILegendPanel;
152
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton;
153
import com.iver.cit.gvsig.project.documents.view.legend.gui.Quantities;
154

    
155
/**
156
 *
157
 * @author jaume dominguez faus - jaume.dominguez@iver.es
158
 *
159
 */
160
public class DotDensity extends JPanel implements ILegendPanel {
161
        private static final int MAX_VALUE_COUNT = 300;
162
        private FLyrVect layer;
163
        private JPanel northPanel = null;
164
        private GridBagLayoutPanel densityButtonsPanel = null;
165
        private JPanel pnlDensities = null;
166
        private JComboBox cmbLegendField = null;
167
        private JRadioButton rdBtnHigh = null;
168
        private JRadioButton rdBtnMedium = null;
169
        private JRadioButton rdBtnLow = null;
170
        private JIncrementalNumberField numDotSize = null;
171

    
172
        private JIncrementalNumberField nmbrDotValue = null;
173
        private JLabel lblLabellingField = null;
174
        private DotDensityLegend legend;
175
        private String fieldName;
176
        private boolean initializing;
177
        private double max;
178
        private double maxDotSize = 0;
179
        private double b, a; // regression function params where: y = bx + a
180
        private int valueCount;
181

    
182
        private NumberFormat nf = NumberFormat.getInstance();
183
        {
184
                nf.setMaximumFractionDigits(3);
185
        }
186
        private MyListener cmbAction = new MyListener();
187

    
188
        private class MyListener implements ItemListener, ActionListener {
189
                public void itemStateChanged(ItemEvent e) {
190
                        if (!initializing)
191
                                doIt();
192
                }
193

    
194
                public void actionPerformed(ActionEvent e) {
195
                        if (!initializing)
196
                                doIt();
197
                }
198

    
199
                private void doIt() {
200
                        int index = cmbLegendField.getSelectedIndex();
201
            try {
202
                SelectableDataSource sds = layer.getRecordset();
203

    
204
                if (index != -1) {
205
                    fieldName = (String) cmbLegendField.getSelectedItem();
206
                } else {
207
                    fieldName = (String) cmbLegendField.getItemAt(0);
208
                }
209

    
210
                int fieldIndex = sds.getFieldIndexByName(fieldName);
211

    
212
                // will extract a "Minimum Square Adjustment" regression function.
213
                long rowCount = sds.getRowCount();
214
                valueCount = (rowCount > MAX_VALUE_COUNT) ? MAX_VALUE_COUNT : (int) rowCount;
215

    
216
                double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxy = 0;
217
                            double Sxx, Sxy;
218

    
219
                for (int i = 0; i < valueCount; i++) {
220
                        double value = ((NumericValue) sds.getFieldValue(i,fieldIndex)).doubleValue();
221
                        sumx += i;
222
                                    sumy += value;
223
                                    sumxx += i*i;
224
                                    sumyy += value*value;
225
                                    sumxy += i*value;
226

    
227
                                    if(value > maxDotSize)
228
                                            maxDotSize = value;
229
                }
230

    
231

    
232

    
233
                // start regression
234
                            double n = (double) valueCount;
235
                            Sxx = sumxx-sumx*sumx/n;
236
                            Sxy = sumxy-sumx*sumy/n;
237
                            b = Sxy/Sxx;
238
                            a = (sumy-b*sumx)/n;
239

    
240
                buttonsListener.actionPerformed(null);
241

    
242
            } catch (Exception ex) {
243
                ex.printStackTrace();
244
            }
245
                }
246
        };
247
        private ActionListener buttonsListener = new ActionListener() {
248
            public void actionPerformed(ActionEvent e) {
249
                    if (getRdBtnHigh().isSelected()) {
250
                            getSldDensity().setValue(66);
251
                    } else if (getRdBtnLow().isSelected()) {
252
                            getSldDensity().setValue(33);
253
                    } else if (getRdBtnMedium().isSelected()) {
254
                            getSldDensity().setValue(50);
255
                    }
256
            }
257
    };
258
        private JPanel centerPanel = null;
259
        private JSlider sldDensity = null;
260

    
261
        private ChangeListener sldListener = new ChangeListener() {
262

    
263
                public void stateChanged(ChangeEvent e) {
264

    
265
                        int quantileIndex = (MAX_VALUE_COUNT*getSldDensity().getValue())/100;
266
                        nmbrDotValue.setDouble((b*quantileIndex+a)/50);
267

    
268
                }
269

    
270
        };
271
        private ColorChooserPanel jcc;
272
        private ILegend oldLegend;
273
        private JSymbolPreviewButton btnOutline;
274
        private ColorChooserPanel jccBackground;
275

    
276
        public DotDensity() {
277
        super();
278
        initialize();
279
    }
280

    
281
    /**
282
     * This method initializes this
283
     *
284
     */
285
    private void initialize() {
286
        this.setLayout(new BorderLayout());
287
        this.setSize(new java.awt.Dimension(492,278));
288
        this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
289
        this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
290
    }
291

    
292
    public void setData(FLayer lyr, ILegend legend) {
293
        this.layer = (FLyrVect) lyr;
294
        try {
295
                        this.oldLegend = legend.cloneLegend();
296
                } catch (XMLException e1) {
297
                        // TODO Auto-generated catch block
298
                        e1.printStackTrace();
299
                }
300
        try {
301
                SelectableDataSource sds = layer.getRecordset();
302
                initializing = true; // silents events to the combo box
303
                cmbLegendField.removeAllItems();
304
                String[] fNames = sds.getFieldNames();
305
                for (int i = 0; i < fNames.length; i++) {
306
                        if (isNumericField(sds.getFieldType(i))) {
307
                                cmbLegendField.addItem(fNames[i]);
308
                        }
309
                }
310
                if (!(legend instanceof DotDensityLegend)) {
311
                        legend = new DotDensityLegend();
312
                        ((DotDensityLegend) legend).setClassifyingFieldNames(
313
                                        new String[] {(String) cmbLegendField.getItemAt(0)});
314
                        ((DotDensityLegend) legend).setShapeType(layer.getShapeType());
315
                }
316

    
317
                DotDensityLegend theLegend = (DotDensityLegend) legend;
318

    
319
                initializing = false; // enables events to the combo box
320

    
321
                cmbLegendField.setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
322
                try {
323
                        getDotColorChooserPanel().setColor(theLegend.getDotColor());
324
                } catch (NullPointerException npEx) {
325
                        getDotColorChooserPanel().setColor(Color.RED);
326
                }
327
                try {
328
                        getBackgroundColorChooserPanel().setColor(theLegend.getBGColor());
329
                } catch (NullPointerException npEx) {
330
                        getDotColorChooserPanel().setColor(Color.WHITE);
331
                }
332

    
333
                getBtnOutline().setSymbol(theLegend.getOutline());
334
                try {
335
                        double dotValue = theLegend.getDotValue();
336
                        if (dotValue <= 0)
337
                                dotValue = 100;
338
                        getNmbrDotValue().setDouble(dotValue);
339

    
340
                } catch (NullPointerException npEx) {
341
                        getNmbrDotValue().setDouble(max);
342
                }
343
                try {
344
                        double dotSize = theLegend.getDotSize();
345
                        if (dotSize <= 0)
346
                                dotSize = 2;
347
                        getNumDotSize().setDouble(dotSize);
348
                } catch (NullPointerException npEx) {
349
                        getNumDotSize().setDouble(3);
350
                }
351

    
352
        } catch (Exception e) {
353
                e.printStackTrace();
354
        }
355
    }
356

    
357
    private boolean isNumericField(int fieldType) {
358
        switch (fieldType) {
359
        case Types.BIGINT:
360
        case Types.DECIMAL:
361
        case Types.DOUBLE:
362
        case Types.FLOAT:
363
        case Types.INTEGER:
364
        case Types.NUMERIC:
365
        case Types.REAL:
366
        case Types.SMALLINT:
367
        case Types.TINYINT:
368
            return true;
369
        default:
370
            return false;
371
        }
372

    
373
    }
374

    
375
    public ILegend getLegend() {
376
            try {
377
                        int shapeType = layer.getShapeType();
378

    
379
                    // shapeType should be always polygon
380
                    if (shapeType != FShape.POLYGON) {
381
                            NotificationManager.addError(PluginServices.getText(this, "cannot_apply_to_a_non_polygon_layer"), new Exception());
382
                    }
383

    
384
                    // check if the field exists (this is probably dead code)
385
                    SelectableDataSource sds;
386
                    sds = layer.getRecordset();
387
                    if (-1 == sds.getFieldIndexByName(fieldName))
388
                            return null;
389

    
390
                    // gather values
391
                    double dotValue;
392
                    double dotSize;
393
                    try {
394
//                            dotValue = Double.parseDouble(nmbrDotValue.getText());
395
                            dotValue = nmbrDotValue.getDouble();
396
                    } catch (Exception e) {
397
//                            dotValue = nf.parse(nmbrDotValue.getText()).doubleValue();
398
                            dotValue = nmbrDotValue.getDouble();
399
                    }
400
                    if (dotValue == 0)
401
                            dotValue = 1;
402
                    try {
403
//                            dotSize = Double.parseDouble(numDotSize.getText());
404
                            dotSize = numDotSize.getDouble();
405
                    } catch (Exception e) {
406
//                            dotSize = nf.parse(numDotSize.getText()).doubleValue();
407
                            dotSize = numDotSize.getDouble();
408
                    }
409

    
410
                    if (max/dotValue > 50000) {
411
                            int option = JOptionPane.showConfirmDialog(this,
412
                                            PluginServices.getText(this, "looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"),
413
                                            PluginServices.getText(this, "warning"),
414
                                            JOptionPane.OK_CANCEL_OPTION);
415
                            if (option        == JOptionPane.CANCEL_OPTION)
416
                                    return oldLegend;
417
                    }
418

    
419
                    // create the density symbol with the values set above
420
                    DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol();
421
                    densitySymbol.setDotSize(dotSize);
422
                    densitySymbol.setDotColor(getDotColorChooserPanel().getColor());
423

    
424
                    // create a simple-fill symbol over which the dot density will be drawn
425
                    SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
426
                    fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor());
427
                    fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol());
428

    
429
                    // combine both the DotDensitySymbol and the SimpleFillSymbol in
430
                    // MultiLayerSymbol so they will be paint as a unique ISymbol
431
                    MultiLayerFillSymbol symbol = new MultiLayerFillSymbol();
432
                    symbol.setDescription(
433
                                    "DotDensitySymbol" + PluginServices.getText(this, "in_layer") +
434
                                    ": '"+layer.getName()+"'");
435
                    symbol.addLayer(fillSymbol);
436
                    symbol.addLayer(densitySymbol);
437

    
438
                    legend = new DotDensityLegend();
439
                    legend.addSymbol(ValueFactory.createValue("theSymbol"), symbol);
440
                    legend.setDefaultSymbol(symbol);
441
                    legend.setDotValue(dotValue);
442
                    legend.setClassifyingFieldNames(new String[] {fieldName});
443
                    legend.setBGColor(getBackgroundColorChooserPanel().getColor());
444
                    legend.setDotColor(getDotColorChooserPanel().getColor());
445

    
446
            } catch (Exception e) {
447
                    NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend")+".", e);
448
            }
449
            return legend;
450

    
451
    }
452

    
453
    /**
454
     * This method initializes centerPanel
455
     *
456
     * @return javax.swing.JPanel
457
     */
458
    private JPanel getNorthPanel() {
459
        if (northPanel == null) {
460
            lblLabellingField = new JLabel();
461
            lblLabellingField.setText(PluginServices.getText(this, "labeling_field")+".");
462
            northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,15,0));
463
            northPanel.add(lblLabellingField, null);
464
            northPanel.add(getCmbLegendField(), null);
465

    
466
        }
467
        return northPanel;
468
    }
469

    
470
    private ColorChooserPanel getDotColorChooserPanel() {
471
            if (jcc == null) {
472
                    jcc = new ColorChooserPanel() ;
473
                    jcc.setAlpha(255);
474
            }
475
            return jcc;
476
        }
477

    
478
        /**
479
     * This method initializes southPanel
480
     *
481
     * @return javax.swing.JPanel
482
     */
483
    private JPanel getDensityButtonsPanel() {
484
        if (densityButtonsPanel == null) {
485
                densityButtonsPanel = new GridBagLayoutPanel();
486
                LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0,0);
487
                JPanel aux = new JPanel(layout);
488
                aux.add(getNumDotSize());
489
                densityButtonsPanel.addComponent(
490
                                PluginServices.getText(this, "dot_size"), aux);
491
                aux = new JPanel(layout);
492
                aux.add(getNmbrDotValue());
493
            densityButtonsPanel.addComponent(
494
                            PluginServices.getText(this,"dot_value"), aux);
495
            aux = new JPanel(layout);
496
            aux.add(getDotColorChooserPanel());
497
            densityButtonsPanel.addComponent(
498
                            PluginServices.getText(this, "color"), aux);
499
            aux = new JPanel(layout);
500
            aux.add(getBackgroundColorChooserPanel());
501
            densityButtonsPanel.addComponent(
502
                            PluginServices.getText(this, "background_color"), aux);
503
            aux = new JPanel(layout);
504
            aux.add(getBtnOutline());
505
            densityButtonsPanel.addComponent(
506
                            PluginServices.getText(this, "outline"), aux);
507
        }
508
        return densityButtonsPanel;
509
    }
510

    
511
        private ColorChooserPanel getBackgroundColorChooserPanel() {
512
                if (jccBackground == null) {
513
                        jccBackground = new ColorChooserPanel() ;
514
                        jccBackground.setColor(Color.WHITE);
515
                        jccBackground.setAlpha(255);
516
            }
517
            return jccBackground;
518
        }
519

    
520
        private JSymbolPreviewButton getBtnOutline() {
521
                if (btnOutline == null) {
522
                        btnOutline = new JSymbolPreviewButton(FShape.LINE);
523
                        btnOutline.setPreferredSize(new Dimension(100, 35));
524
                }
525
                return btnOutline;
526
        }
527

    
528
        /**
529
     * This method initializes pnlDensities
530
     *
531
     * @return javax.swing.JPanel
532
     */
533
    private JPanel getPnlDensities() {
534
        if (pnlDensities == null) {
535
            pnlDensities = new JPanel(new BorderLayout(5,0));
536
            pnlDensities.setBorder(BorderFactory.createTitledBorder(null,
537
                                        PluginServices.getText(this, "densities")));
538
            JPanel aux2 = new JPanel();
539
            JPanel aux;
540
                        aux = new JPanel(new GridLayout(1,3));
541
            aux.add(new JLabel(PluginServices.getText(this, "high")));
542
            aux.add(new JLabel(PluginServices.getText(this, "medium")));
543
            aux.add(new JLabel(PluginServices.getText(this, "low")));
544

    
545
            aux2.add(aux);
546

    
547
                        aux = new JPanel(new GridLayout(1,3));
548
            aux.add(getRdBtnHigh());
549
            aux.add(getRdBtnMedium());
550
            aux.add(getRdBtnLow());
551

    
552
            aux2.add(aux);
553
            aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
554

    
555
            pnlDensities.add(aux2, BorderLayout.NORTH);
556
            pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
557
            pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
558

    
559
            ButtonGroup group = new ButtonGroup();
560
            group.add(getRdBtnHigh());
561
            group.add(getRdBtnLow());
562
            group.add(getRdBtnMedium());
563
            getRdBtnMedium().setSelected(true);
564
        }
565
        return pnlDensities;
566
    }
567

    
568

    
569
        /**
570
     * This method initializes cmbLegendField
571
     *
572
     * @return javax.swing.JComboBox
573
     */
574
    private JComboBox getCmbLegendField() {
575
        if (cmbLegendField == null) {
576
            cmbLegendField = new JComboBox();
577
            cmbLegendField.addActionListener(cmbAction);
578
        }
579
        return cmbLegendField;
580
    }
581

    
582
    /**
583
     * This method initializes rdBtnHigh
584
     *
585
     * @return javax.swing.JRadioButton
586
     */
587
    private JRadioButton getRdBtnHigh() {
588
        if (rdBtnHigh == null) {
589
            rdBtnHigh = new JRadioButton(PluginServices.getIconTheme().get("high-density"));
590
            rdBtnHigh.addActionListener(buttonsListener);
591
        }
592
        return rdBtnHigh;
593
    }
594

    
595
    /**
596
     * This method initializes rdBtnMedium
597
     *
598
     * @return javax.swing.JRadioButton
599
     */
600
    private JRadioButton getRdBtnMedium() {
601
        if (rdBtnMedium == null) {
602
                        rdBtnMedium = new JRadioButton(PluginServices.getIconTheme()
603
                            .get("medium-density"));
604
            rdBtnMedium.addActionListener(buttonsListener);
605
        }
606
        return rdBtnMedium;
607
    }
608

    
609
    /**
610
     * This method initializes rdBtnMax
611
     *
612
     * @return javax.swing.JRadioButton
613
     */
614
    private JRadioButton getRdBtnLow() {
615
        if (rdBtnLow == null) {
616
                        rdBtnLow = new JRadioButton(PluginServices.getIconTheme().get("low-density"));
617
            rdBtnLow.addActionListener(buttonsListener);
618
        }
619
        return rdBtnLow;
620
    }
621

    
622
    /**
623
     * This method initializes numDotSize
624
     *
625
     * @return de.ios.framework.swing.JNumberField
626
     */
627
    private JIncrementalNumberField getNumDotSize() {
628
        if (numDotSize == null) {
629
            numDotSize = new JIncrementalNumberField(null, 4);
630
            numDotSize.setDouble(1);
631
        }
632
        return numDotSize;
633
    }
634

    
635
        /**
636
         * This method initializes nmbrDotValue
637
         *
638
         * @return de.ios.framework.swing.JNumberField
639
         */
640
        private JIncrementalNumberField getNmbrDotValue() {
641
                if (nmbrDotValue == null) {
642
                        nmbrDotValue = new JIncrementalNumberField(null, 15);
643

    
644
                }
645
                return nmbrDotValue;
646
        }
647

    
648
        /**
649
         * This method initializes centerPanel
650
         *
651
         * @return javax.swing.JPanel
652
         */
653
        private JPanel getCenterPanel() {
654
                if (centerPanel == null) {
655
                        centerPanel = new JPanel();
656
                        centerPanel.setLayout(new BorderLayout(5, 5));
657
                        centerPanel.add(getPnlDensities(), java.awt.BorderLayout.WEST);
658
                }
659
                return centerPanel;
660
        }
661

    
662
        /**
663
         * This method initializes sldDensity
664
         *
665
         * @return javax.swing.JSlider
666
         */
667
        private JSlider getSldDensity() {
668
                if (sldDensity == null) {
669
                        sldDensity = new JSlider();
670
                        sldDensity.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
671
                        sldDensity.addChangeListener(sldListener);
672
                }
673
                return sldDensity;
674
        }
675

    
676
        public String getDescription() {
677
                return PluginServices.getText(this,"Defines_a_dot_density_symbol_based_on_a_field_value") + ".";
678
        }
679

    
680
        public ImageIcon getIcon() {
681
                return new ImageIcon(this.getClass().getClassLoader().
682
                                getResource("images/DotDensity.PNG"));
683
        }
684

    
685
        public Class getParentClass() {
686
                return Quantities.class;
687
        }
688

    
689
        public String getTitle() {
690
                return PluginServices.getText(this, "dot_density");
691
        }
692

    
693
        public JPanel getPanel() {
694
                return this;
695
        }
696

    
697
        public Class getLegendClass() {
698
                return DotDensityLegend.class;
699
        }
700

    
701
        public boolean isSuitableFor(FLayer layer) {
702
                if (layer instanceof FLyrVect) {
703
                        try {
704
                                FLyrVect lyr = (FLyrVect) layer;
705

    
706
                                if (lyr.getShapeType() != FShape.POLYGON)
707
                                        return false;
708

    
709
                                SelectableDataSource sds;
710
                                sds = lyr.getRecordset();
711
                                String[] fNames = sds.getFieldNames();
712
                                for (int i = 0; i < fNames.length; i++) {
713
                                        if (isNumericField(sds.getFieldType(i))) {
714
                                                return true;
715
                                        }
716
                                }
717
                        } catch (ReadDriverException e) {
718
                                return false;
719
                        }
720
                }
721
                return false;
722
        }
723

    
724
}  //  @jve:decl-index=0:visual-constraint="10,10"