Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / DotDensity.java @ 11734

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

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

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

    
125
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
126
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
127

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

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

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

    
172
        private NumberFormat nf = NumberFormat.getInstance();
173
        {
174
                nf.setMaximumFractionDigits(3);
175
        }
176
        private MyListener cmbAction = new MyListener();
177

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

    
184
                public void actionPerformed(ActionEvent e) {
185
                        if (!initializing)
186
                                doIt();
187
                }
188

    
189
                private void doIt() {
190
                        int index = cmbLegendField.getSelectedIndex();
191
            try {
192
                SelectableDataSource sds = layer.getRecordset();
193

    
194
                if (index != -1) {
195
                    fieldName = (String) cmbLegendField.getSelectedItem();
196
                } else {
197
                    fieldName = (String) cmbLegendField.getItemAt(0);
198
                }
199

    
200
                int fieldIndex = sds.getFieldIndexByName(fieldName);
201

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

    
206
                double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxy = 0;
207
                            double Sxx, Sxy;
208

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

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

    
225
                buttonsListener.actionPerformed(null);
226

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

    
246
        private ChangeListener sldListener = new ChangeListener() {
247

    
248
                public void stateChanged(ChangeEvent e) {
249

    
250
                        int quantileIndex = (MAX_VALUE_COUNT*getSldDensity().getValue())/100;
251
                        nmbrDotValue.setDouble((b*quantileIndex+a)/50);
252

    
253
                }
254

    
255
        };
256
        private ColorChooserPanel jcc;
257
        private ColorChooserPanel outlineColorChooserPanel;
258
        private ILegend oldLegend;
259
        private JSymbolPreviewButton btnOutline;
260
        private ColorChooserPanel jccBackground;
261

    
262
        public DotDensity() {
263
        super();
264
        initialize();
265
    }
266

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

    
276
        this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
277
    }
278

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

    
298
                DotDensityLegend theLegend = (DotDensityLegend) legend;
299

    
300
                initializing = false; // enables events to the combo box
301

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

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

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

    
333
        } catch (Exception e) {
334
                e.printStackTrace();
335
        }
336
    }
337

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

    
354
    }
355

    
356
    public ILegend getLegend() {
357
            try {
358
                        int shapeType = layer.getShapeType();
359

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

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

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

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

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

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

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

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

    
425

    
426
            } catch (Exception e) {
427
                    NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend")+".", e);
428
            }
429
            return legend;
430

    
431
    }
432

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

    
446
        }
447
        return northPanel;
448
    }
449

    
450
    private ColorChooserPanel getDotColorChooserPanel() {
451
            if (jcc == null) {
452
                    jcc = new ColorChooserPanel() ;
453
                    jcc.setAlpha(255);
454
            }
455
            return jcc;
456
        }
457

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

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

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

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

    
525
            aux2.add(aux);
526

    
527
                        aux = new JPanel(new GridLayout(1,3));
528
            aux.add(getRdBtnHigh());
529
            aux.add(getRdBtnMedium());
530
            aux.add(getRdBtnLow());
531

    
532
            aux2.add(aux);
533
            aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
534

    
535
            pnlDensities.add(aux2, BorderLayout.NORTH);
536
            pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
537
            pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
538

    
539
            ButtonGroup group = new ButtonGroup();
540
            group.add(getRdBtnHigh());
541
            group.add(getRdBtnLow());
542
            group.add(getRdBtnMedium());
543
            getRdBtnMedium().setSelected(true);
544
        }
545
        return pnlDensities;
546
    }
547

    
548

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

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

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

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

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

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

    
628
                }
629
                return nmbrDotValue;
630
        }
631

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

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

    
660
        public String getDescription() {
661
                return PluginServices.getText(this,"Defines_a_dot_density_symbol_based_on_a_field_value") + ".";
662
        }
663

    
664
        public ISymbol getPreviewSymbol() {
665
                // TODO Implement it
666
                return null;
667
        }
668

    
669
        public Class getParentClass() {
670
                return Quantities.class;
671
        }
672

    
673
        public String getTitle() {
674
                return PluginServices.getText(this, "dot_density");
675
        }
676

    
677
        public JPanel getPanel() {
678
                return this;
679
        }
680

    
681
        public Class getLegendClass() {
682
                return DotDensityLegend.class;
683
        }
684

    
685
        public boolean isSuitableFor(FLayer layer) {
686
                if (layer instanceof FLyrVect) {
687
                        try {
688
                                FLyrVect lyr = (FLyrVect) layer;
689

    
690
                                if (lyr.getShapeType() != FShape.POLYGON)
691
                                        return false;
692

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

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