Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / DotDensity.java @ 13522

History | View | Annotate | Download (21.2 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 13522 2007-09-04 14:13:01Z jaume $
45
* $Log$
46
* Revision 1.10  2007-09-04 14:13:01  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.9  2007/05/21 10:38:27  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.8  2007/05/17 09:32:37  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.7  2007/05/10 09:46:45  jaume
56
* Refactored legend interface names
57
*
58
* Revision 1.6  2007/05/08 15:45:31  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.5  2007/04/20 07:54:39  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.4  2007/04/20 07:24:56  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.3  2007/04/17 06:53:46  bsanchez
68
* - Corregido fallo de Double.MIN_VALUE por Double.NEGATIVE_INFINITY comentado por Victor Olaya.
69
*
70
* Revision 1.2  2007/03/09 11:25:00  jaume
71
* Advanced symbology (start committing)
72
*
73
* Revision 1.1.2.4  2007/02/21 07:35:14  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1.2.3  2007/02/12 15:14:41  jaume
77
* refactored interval legend and added graduated symbol legend
78
*
79
* Revision 1.1.2.2  2007/02/09 11:00:03  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.4  2006/11/17 13:53:45  cesar
86
* *** empty log message ***
87
*
88
* Revision 1.3  2006/11/17 12:50:36  jaume
89
* tama?o de punto defecto 2
90
*
91
* Revision 1.2  2006/11/15 12:57:31  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1  2006/11/14 11:10:27  jaume
95
* *** empty log message ***
96
*
97
*
98
*/
99
package com.iver.cit.gvsig.project.documents.view.legend.gui;
100

    
101
import java.awt.BorderLayout;
102
import java.awt.Color;
103
import java.awt.ComponentOrientation;
104
import java.awt.Dimension;
105
import java.awt.FlowLayout;
106
import java.awt.GridLayout;
107
import java.awt.LayoutManager;
108
import java.awt.event.ActionEvent;
109
import java.awt.event.ActionListener;
110
import java.awt.event.ItemEvent;
111
import java.awt.event.ItemListener;
112
import java.sql.Types;
113
import java.text.NumberFormat;
114

    
115
import javax.swing.BorderFactory;
116
import javax.swing.BoxLayout;
117
import javax.swing.ButtonGroup;
118
import javax.swing.ImageIcon;
119
import javax.swing.JComboBox;
120
import javax.swing.JLabel;
121
import javax.swing.JOptionPane;
122
import javax.swing.JPanel;
123
import javax.swing.JRadioButton;
124
import javax.swing.JSlider;
125
import javax.swing.event.ChangeEvent;
126
import javax.swing.event.ChangeListener;
127

    
128
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
129
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
130

    
131
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
132
import com.hardcode.gdbms.engine.values.NumericValue;
133
import com.hardcode.gdbms.engine.values.ValueFactory;
134
import com.iver.andami.PluginServices;
135
import com.iver.andami.messages.NotificationManager;
136
import com.iver.cit.gvsig.fmap.core.FShape;
137
import com.iver.cit.gvsig.fmap.core.symbols.DotDensityFillSymbol;
138
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
139
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
140
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol;
141
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
142
import com.iver.cit.gvsig.fmap.layers.FLayer;
143
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
144
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
145
import com.iver.cit.gvsig.fmap.rendering.DotDensityLegend;
146
import com.iver.cit.gvsig.fmap.rendering.ILegend;
147
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
148

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

    
166
        private JIncrementalNumberField nmbrDotValue = null;
167
        private JLabel lblLabellingField = null;
168
        private DotDensityLegend legend;
169
        private String fieldName;
170
        private boolean initializing;
171
        private double max;
172
        private double b, a; // regression function params where: y = bx + a
173
        private int valueCount;
174

    
175
        private NumberFormat nf = NumberFormat.getInstance();
176
        {
177
                nf.setMaximumFractionDigits(3);
178
        }
179
        private MyListener cmbAction = new MyListener();
180

    
181
        private class MyListener implements ItemListener, ActionListener {
182
                public void itemStateChanged(ItemEvent e) {
183
                        if (!initializing)
184
                                doIt();
185
                }
186

    
187
                public void actionPerformed(ActionEvent e) {
188
                        if (!initializing)
189
                                doIt();
190
                }
191

    
192
                private void doIt() {
193
                        int index = cmbLegendField.getSelectedIndex();
194
            try {
195
                SelectableDataSource sds = layer.getRecordset();
196

    
197
                if (index != -1) {
198
                    fieldName = (String) cmbLegendField.getSelectedItem();
199
                } else {
200
                    fieldName = (String) cmbLegendField.getItemAt(0);
201
                }
202

    
203
                int fieldIndex = sds.getFieldIndexByName(fieldName);
204

    
205
                // will extract a "Minimum Square Adjustment" regression function.
206
                long rowCount = sds.getRowCount();
207
                valueCount = (rowCount > MAX_VALUE_COUNT) ? MAX_VALUE_COUNT : (int) rowCount;
208

    
209
                double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxy = 0;
210
                            double Sxx, Sxy;
211

    
212
                for (int i = 0; i < valueCount; i++) {
213
                        double value = ((NumericValue) sds.getFieldValue(i,fieldIndex)).doubleValue();
214
                        sumx += i;
215
                                    sumy += value;
216
                                    sumxx += i*i;
217
                                    sumyy += value*value;
218
                                    sumxy += i*value;
219
                }
220

    
221
                // start regression
222
                            double n = (double) valueCount;
223
                            Sxx = sumxx-sumx*sumx/n;
224
                            Sxy = sumxy-sumx*sumy/n;
225
                            b = Sxy/Sxx;
226
                            a = (sumy-b*sumx)/n;
227

    
228
                buttonsListener.actionPerformed(null);
229

    
230
            } catch (Exception ex) {
231
                ex.printStackTrace();
232
            }
233
                }
234
        };
235
        private ActionListener buttonsListener = new ActionListener() {
236
            public void actionPerformed(ActionEvent e) {
237
                    if (getRdBtnHigh().isSelected()) {
238
                            getSldDensity().setValue(66);
239
                    } else if (getRdBtnLow().isSelected()) {
240
                            getSldDensity().setValue(33);
241
                    } else if (getRdBtnMedium().isSelected()) {
242
                            getSldDensity().setValue(50);
243
                    }
244
            }
245
    };
246
        private JPanel centerPanel = null;
247
        private JSlider sldDensity = null;
248

    
249
        private ChangeListener sldListener = new ChangeListener() {
250

    
251
                public void stateChanged(ChangeEvent e) {
252

    
253
                        int quantileIndex = (MAX_VALUE_COUNT*getSldDensity().getValue())/100;
254
                        nmbrDotValue.setDouble((b*quantileIndex+a)/50);
255

    
256
                }
257

    
258
        };
259
        private ColorChooserPanel jcc;
260
        private ColorChooserPanel outlineColorChooserPanel;
261
        private ILegend oldLegend;
262
        private JSymbolPreviewButton btnOutline;
263
        private ColorChooserPanel jccBackground;
264

    
265
        public DotDensity() {
266
        super();
267
        initialize();
268
    }
269

    
270
    /**
271
     * This method initializes this
272
     *
273
     */
274
    private void initialize() {
275
        this.setLayout(new BorderLayout());
276
        this.setSize(new java.awt.Dimension(492,278));
277
        this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
278

    
279
        this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
280
    }
281

    
282
    public void setData(FLayer lyr, ILegend legend) {
283
        this.layer = (FLyrVect) lyr;
284
        this.oldLegend = legend;
285
        try {
286
                SelectableDataSource sds = layer.getRecordset();
287
                initializing = true; // silents events to the combo box
288
                cmbLegendField.removeAllItems();
289
                String[] fNames = sds.getFieldNames();
290
                for (int i = 0; i < fNames.length; i++) {
291
                        if (isNumericField(sds.getFieldType(i))) {
292
                                cmbLegendField.addItem(fNames[i]);
293
                        }
294
                }
295
                if (!(legend instanceof DotDensityLegend)) {
296
                        legend = new DotDensityLegend();
297
                        ((DotDensityLegend) legend).setFieldNames(
298
                                        new String[] {(String) cmbLegendField.getItemAt(0)});
299
                }
300

    
301
                DotDensityLegend theLegend = (DotDensityLegend) legend;
302

    
303
                initializing = false; // enables events to the combo box
304

    
305
                cmbLegendField.setSelectedItem(theLegend.getFieldNames()[0]);
306
                try {
307
                        getDotColorChooserPanel().setColor(theLegend.getDotColor());
308
                } catch (NullPointerException npEx) {
309
                        getDotColorChooserPanel().setColor(Color.RED);
310
                }
311
                try {
312
                        getBackgroundColorChooserPanel().setColor(theLegend.getBGColor());
313
                } catch (NullPointerException npEx) {
314
                        getDotColorChooserPanel().setColor(Color.WHITE);
315
                }
316

    
317
                getBtnOutline().setSymbol(theLegend.getOutline());
318
                try {
319
                        double dotValue = theLegend.getDotValue();
320
                        if (dotValue <= 0)
321
                                dotValue = 100;
322
                        getNmbrDotValue().setDouble(dotValue);
323

    
324
                } catch (NullPointerException npEx) {
325
                        getNmbrDotValue().setDouble(max);
326
                }
327
                try {
328
                        double dotSize = theLegend.getDotSize();
329
                        if (dotSize <= 0)
330
                                dotSize = 2;
331
                        getNumDotSize().setDouble(dotSize);
332
                } catch (NullPointerException npEx) {
333
                        getNumDotSize().setDouble(3);
334
                }
335

    
336
        } catch (Exception e) {
337
                e.printStackTrace();
338
        }
339
    }
340

    
341
    private boolean isNumericField(int fieldType) {
342
        switch (fieldType) {
343
        case Types.BIGINT:
344
        case Types.DECIMAL:
345
        case Types.DOUBLE:
346
        case Types.FLOAT:
347
        case Types.INTEGER:
348
        case Types.NUMERIC:
349
        case Types.REAL:
350
        case Types.SMALLINT:
351
        case Types.TINYINT:
352
            return true;
353
        default:
354
            return false;
355
        }
356

    
357
    }
358

    
359
    public ILegend getLegend() {
360
            try {
361
                        int shapeType = layer.getShapeType();
362

    
363
                    // shapeType should be always polygon
364
                    if (shapeType != FShape.POLYGON) {
365
                            NotificationManager.addError(PluginServices.getText(this, "cannot_apply_to_a_non_polygon_layer"), new Exception());
366
                    }
367

    
368
                    // check if the field exists (this is probably dead code)
369
                    SelectableDataSource sds;
370
                    sds = layer.getRecordset();
371
                    if (-1 == sds.getFieldIndexByName(fieldName))
372
                            return null;
373

    
374
                    // gather values
375
                    double dotValue;
376
                    double dotSize;
377
                    try {
378
//                            dotValue = Double.parseDouble(nmbrDotValue.getText());
379
                            dotValue = nmbrDotValue.getDouble();
380
                    } catch (Exception e) {
381
//                            dotValue = nf.parse(nmbrDotValue.getText()).doubleValue();
382
                            dotValue = nmbrDotValue.getDouble();
383
                    }
384
                    if (dotValue == 0)
385
                            dotValue = 1;
386
                    try {
387
//                            dotSize = Double.parseDouble(numDotSize.getText());
388
                            dotSize = numDotSize.getDouble();
389
                    } catch (Exception e) {
390
//                            dotSize = nf.parse(numDotSize.getText()).doubleValue();
391
                            dotSize = numDotSize.getDouble();
392
                    }
393

    
394
                    if (max/dotValue > 50000) {
395
                            int option = JOptionPane.showConfirmDialog(this,
396
                                            PluginServices.getText(this, "looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"),
397
                                            PluginServices.getText(this, "warning"),
398
                                            JOptionPane.OK_CANCEL_OPTION);
399
                            if (option        == JOptionPane.CANCEL_OPTION)
400
                                    return oldLegend;
401
                    }
402

    
403
                    // create the density symbol with the values set above
404
                    DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol();
405
                    densitySymbol.setDotSize(dotSize);
406
                    densitySymbol.setDotColor(getDotColorChooserPanel().getColor());
407

    
408
                    // create a simple-fill symbol over which the dot density will be drawn
409
                    SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
410
                    fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor());
411
                    fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol());
412

    
413
                    // combine both the DotDensitySymbol and the SimpleFillSymbol in
414
                    // MultiLayerSymbol so they will be paint as a unique ISymbol
415
                    MultiLayerFillSymbol symbol = new MultiLayerFillSymbol();
416
                    symbol.setDescription(
417
                                    "DotDensitySymbol" + PluginServices.getText(this, "in_layer") +
418
                                    ": '"+layer.getName()+"'");
419
                    symbol.addLayer(fillSymbol);
420
                    symbol.addLayer(densitySymbol);
421

    
422
                    legend = new DotDensityLegend();
423
                    legend.addSymbol(ValueFactory.createValue("theSymbol"), symbol);
424
                    legend.setDefaultSymbol(symbol);
425
                    legend.setDotValue(dotValue);
426
                    legend.setFieldNames(new String[] {fieldName});
427

    
428

    
429
            } catch (Exception e) {
430
                    NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend")+".", e);
431
            }
432
            return legend;
433

    
434
    }
435

    
436
    /**
437
     * This method initializes centerPanel
438
     *
439
     * @return javax.swing.JPanel
440
     */
441
    private JPanel getNorthPanel() {
442
        if (northPanel == null) {
443
            lblLabellingField = new JLabel();
444
            lblLabellingField.setText(PluginServices.getText(this, "labeling_field")+".");
445
            northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,15,0));
446
            northPanel.add(lblLabellingField, null);
447
            northPanel.add(getCmbLegendField(), null);
448

    
449
        }
450
        return northPanel;
451
    }
452

    
453
    private ColorChooserPanel getDotColorChooserPanel() {
454
            if (jcc == null) {
455
                    jcc = new ColorChooserPanel() ;
456
                    jcc.setAlpha(255);
457
            }
458
            return jcc;
459
        }
460

    
461
        /**
462
     * This method initializes southPanel
463
     *
464
     * @return javax.swing.JPanel
465
     */
466
    private JPanel getDensityButtonsPanel() {
467
        if (densityButtonsPanel == null) {
468
                densityButtonsPanel = new GridBagLayoutPanel();
469
                LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0,0);
470
                JPanel aux = new JPanel(layout);
471
                aux.add(getNumDotSize());
472
                densityButtonsPanel.addComponent(
473
                                PluginServices.getText(this, "dot_size"), aux);
474
                aux = new JPanel(layout);
475
                aux.add(getNmbrDotValue());
476
            densityButtonsPanel.addComponent(
477
                            PluginServices.getText(this,"dot_value"), aux);
478
            aux = new JPanel(layout);
479
            aux.add(getDotColorChooserPanel());
480
            densityButtonsPanel.addComponent(
481
                            PluginServices.getText(this, "color"), aux);
482
            aux = new JPanel(layout);
483
            aux.add(getBackgroundColorChooserPanel());
484
            densityButtonsPanel.addComponent(
485
                            PluginServices.getText(this, "background_color"), aux);
486
            aux = new JPanel(layout);
487
            aux.add(getBtnOutline());
488
            densityButtonsPanel.addComponent(
489
                            PluginServices.getText(this, "outline"), aux);
490
        }
491
        return densityButtonsPanel;
492
    }
493

    
494
        private ColorChooserPanel getBackgroundColorChooserPanel() {
495
                if (jccBackground == null) {
496
                        jccBackground = new ColorChooserPanel() ;
497
                        jccBackground.setColor(Color.WHITE);
498
                        jccBackground.setAlpha(255);
499
            }
500
            return jccBackground;
501
        }
502

    
503
        private JSymbolPreviewButton getBtnOutline() {
504
                if (btnOutline == null) {
505
                        btnOutline = new JSymbolPreviewButton(FShape.LINE);
506
                        btnOutline.setPreferredSize(new Dimension(100, 35));
507
                }
508
                return btnOutline;
509
        }
510

    
511
        /**
512
     * This method initializes pnlDensities
513
     *
514
     * @return javax.swing.JPanel
515
     */
516
    private JPanel getPnlDensities() {
517
        if (pnlDensities == null) {
518
            pnlDensities = new JPanel(new BorderLayout(5,0));
519
            pnlDensities.setBorder(BorderFactory.createTitledBorder(null,
520
                                        PluginServices.getText(this, "densities")));
521
            JPanel aux2 = new JPanel();
522
            JPanel aux;
523
                        aux = new JPanel(new GridLayout(1,3));
524
            aux.add(new JLabel(PluginServices.getText(this, "high")));
525
            aux.add(new JLabel(PluginServices.getText(this, "medium")));
526
            aux.add(new JLabel(PluginServices.getText(this, "low")));
527

    
528
            aux2.add(aux);
529

    
530
                        aux = new JPanel(new GridLayout(1,3));
531
            aux.add(getRdBtnHigh());
532
            aux.add(getRdBtnMedium());
533
            aux.add(getRdBtnLow());
534

    
535
            aux2.add(aux);
536
            aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
537

    
538
            pnlDensities.add(aux2, BorderLayout.NORTH);
539
            pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
540
            pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
541

    
542
            ButtonGroup group = new ButtonGroup();
543
            group.add(getRdBtnHigh());
544
            group.add(getRdBtnLow());
545
            group.add(getRdBtnMedium());
546
            getRdBtnMedium().setSelected(true);
547
        }
548
        return pnlDensities;
549
    }
550

    
551

    
552
        /**
553
     * This method initializes cmbLegendField
554
     *
555
     * @return javax.swing.JComboBox
556
     */
557
    private JComboBox getCmbLegendField() {
558
        if (cmbLegendField == null) {
559
            cmbLegendField = new JComboBox();
560
            cmbLegendField.addActionListener(cmbAction);
561
        }
562
        return cmbLegendField;
563
    }
564

    
565
    /**
566
     * This method initializes rdBtnHigh
567
     *
568
     * @return javax.swing.JRadioButton
569
     */
570
    private JRadioButton getRdBtnHigh() {
571
        if (rdBtnHigh == null) {
572
            rdBtnHigh = new JRadioButton(new ImageIcon(
573
                            getClass().getClassLoader().
574
                                    getResource("images/high-density-sample.png")));
575
            rdBtnHigh.addActionListener(buttonsListener);
576
        }
577
        return rdBtnHigh;
578
    }
579

    
580
    /**
581
     * This method initializes rdBtnMedium
582
     *
583
     * @return javax.swing.JRadioButton
584
     */
585
    private JRadioButton getRdBtnMedium() {
586
        if (rdBtnMedium == null) {
587
            rdBtnMedium = new JRadioButton(new ImageIcon(
588
                            getClass().getClassLoader().
589
                                getResource("images/medium-density-sample.png")));
590
            rdBtnMedium.addActionListener(buttonsListener);
591
        }
592
        return rdBtnMedium;
593
    }
594

    
595
    /**
596
     * This method initializes rdBtnMax
597
     *
598
     * @return javax.swing.JRadioButton
599
     */
600
    private JRadioButton getRdBtnLow() {
601
        if (rdBtnLow == null) {
602
            rdBtnLow = new JRadioButton(new ImageIcon(
603
                            getClass().getClassLoader().
604
                                getResource("images/low-density-sample.png")));
605
            rdBtnLow.addActionListener(buttonsListener);
606
        }
607
        return rdBtnLow;
608
    }
609

    
610
    /**
611
     * This method initializes numDotSize
612
     *
613
     * @return de.ios.framework.swing.JNumberField
614
     */
615
    private JIncrementalNumberField getNumDotSize() {
616
        if (numDotSize == null) {
617
            numDotSize = new JIncrementalNumberField(null, 4);
618
        }
619
        return numDotSize;
620
    }
621

    
622
        /**
623
         * This method initializes nmbrDotValue
624
         *
625
         * @return de.ios.framework.swing.JNumberField
626
         */
627
        private JIncrementalNumberField getNmbrDotValue() {
628
                if (nmbrDotValue == null) {
629
                        nmbrDotValue = new JIncrementalNumberField(null, 15);
630

    
631
                }
632
                return nmbrDotValue;
633
        }
634

    
635
        /**
636
         * This method initializes centerPanel
637
         *
638
         * @return javax.swing.JPanel
639
         */
640
        private JPanel getCenterPanel() {
641
                if (centerPanel == null) {
642
                        centerPanel = new JPanel();
643
                        centerPanel.setLayout(new BorderLayout(5, 5));
644
                        centerPanel.add(getPnlDensities(), java.awt.BorderLayout.WEST);
645
                }
646
                return centerPanel;
647
        }
648

    
649
        /**
650
         * This method initializes sldDensity
651
         *
652
         * @return javax.swing.JSlider
653
         */
654
        private JSlider getSldDensity() {
655
                if (sldDensity == null) {
656
                        sldDensity = new JSlider();
657
                        sldDensity.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
658
                        sldDensity.addChangeListener(sldListener);
659
                }
660
                return sldDensity;
661
        }
662

    
663
        public String getDescription() {
664
                return PluginServices.getText(this,"Defines_a_dot_density_symbol_based_on_a_field_value") + ".";
665
        }
666

    
667
        public ISymbol getPreviewSymbol() {
668
                // TODO Implement it
669
                return null;
670
        }
671

    
672
        public Class getParentClass() {
673
                return Quantities.class;
674
        }
675

    
676
        public String getTitle() {
677
                return PluginServices.getText(this, "dot_density");
678
        }
679

    
680
        public JPanel getPanel() {
681
                return this;
682
        }
683

    
684
        public Class getLegendClass() {
685
                return DotDensityLegend.class;
686
        }
687

    
688
        public boolean isSuitableFor(FLayer layer) {
689
                if (layer instanceof FLyrVect) {
690
                        try {
691
                                FLyrVect lyr = (FLyrVect) layer;
692

    
693
                                if (lyr.getShapeType() != FShape.POLYGON)
694
                                        return false;
695

    
696
                                SelectableDataSource sds;
697
                                sds = lyr.getRecordset();
698
                                String[] fNames = sds.getFieldNames();
699
                                for (int i = 0; i < fNames.length; i++) {
700
                                        if (isNumericField(sds.getFieldType(i))) {
701
                                                return true;
702
                                        }
703
                                }
704
                        } catch (ReadDriverException e) {
705
                                return false;
706
                        }
707
                }
708
                return false;
709
        }
710

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