Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / buffer / gui / GeoProcessingBufferPanel.java @ 6877

History | View | Annotate | Download (20.6 KB)

1
/*
2
 * Created on 04-jul-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.geoprocess.impl.buffer.gui;
45

    
46
import java.awt.Color;
47
import java.awt.Component;
48
import java.awt.event.ItemEvent;
49
import java.io.File;
50

    
51
import javax.swing.ButtonGroup;
52
import javax.swing.DefaultComboBoxModel;
53
import javax.swing.JButton;
54
import javax.swing.JCheckBox;
55
import javax.swing.JComboBox;
56
import javax.swing.JFileChooser;
57
import javax.swing.JFormattedTextField;
58
import javax.swing.JLabel;
59
import javax.swing.JRadioButton;
60
import javax.swing.JSpinner;
61
import javax.swing.JTextField;
62
import javax.swing.SpinnerListModel;
63

    
64
import com.hardcode.gdbms.engine.data.DataSource;
65
import com.iver.andami.PluginServices;
66
import com.iver.andami.ui.mdiManager.IWindow;
67
import com.iver.andami.ui.mdiManager.ViewInfo;
68
import com.iver.cit.gvsig.fmap.DriverException;
69
import com.iver.cit.gvsig.fmap.layers.FBitSet;
70
import com.iver.cit.gvsig.fmap.layers.FLayers;
71
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
72
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
73
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
74
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
75
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
76
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessPanel;
77
import com.iver.utiles.GenericFileFilter;
78
import javax.swing.JPanel;
79

    
80
/**
81
 * Component that represents a Step of the GeoProcessingPanel Wizard. It allows
82
 * user to make selections to do buffers geoprocesses.
83
 * 
84
 * @author jmorell, azabala
85
 * 
86
 * TODO copiar del ClipPanel el que se muestre el numero de elementos
87
 * seleccionados en la capa
88
 */
89
public class GeoProcessingBufferPanel extends AbstractGeoprocessPanel implements
90
                BufferPanelIF, IWindow {
91
        /*
92
         * Constants to indicate how to create buffers on polygonal geometries
93
         */
94
        public final String BUFFER_INSIDE = PluginServices.getText(this, "Dentro");
95

    
96
        public final String BUFFER_INSIDE_OUTSIDE = PluginServices.getText(this,
97
                        "Dentro_y_fuera");
98

    
99
        public final String BUFFER_OUTSIDE = PluginServices.getText(this, "Fuera");
100

    
101
        private static final long serialVersionUID = 1L;
102

    
103
        private JLabel jLabel = null;
104

    
105
        private JCheckBox selectedOnlyCheckbox = null;
106

    
107
        private JButton openFileButton = null;
108

    
109
        private JRadioButton distanceBufferRadioButton = null;
110

    
111
        private JTextField bufferDistanceTextField = null;
112

    
113
        private JRadioButton attributeBufferRadioButton = null;
114

    
115
        private JComboBox layerFieldsComboBox = null;
116

    
117
        private ButtonGroup buttonGroup = null;
118

    
119
        private JLabel jLabel3 = null;
120

    
121
        private JCheckBox dissolveEntitiesJCheckBox = null;
122

    
123
        private ViewInfo viewInfo;
124

    
125
        private JPanel methodSelectionPanel = null;
126

    
127
        private JPanel resultSelectionPanel = null;
128

    
129
        private JLabel jLabel1 = null;
130

    
131
        private JCheckBox endCapCheckBox = null;
132

    
133
        private JPanel extendedOptionsPanel = null;
134

    
135
        private JPanel typePolygonBufferPanel = null;
136

    
137
        private JLabel typeBufferLabel = null;
138

    
139
        private JComboBox typeBufferComboBox = null;
140

    
141
        private JPanel numBuffersPanel = null;
142

    
143
        private JLabel radialBufferLabel = null;
144

    
145
        private JSpinner radialBufferSpinner = null;
146

    
147
        /**
148
         * This constructor initializes the set of layers
149
         */
150
        public GeoProcessingBufferPanel(FLayers layers) {
151
                super();
152
                this.layers = layers;
153
                initialize();
154
        }
155

    
156
        /**
157
         * This method initializes this
158
         * 
159
         * @return void
160
         */
161
        private void initialize() {
162
                jLabel3 = new JLabel();
163
                jLabel = new JLabel();
164
                this.setLayout(null);
165
                this.setBounds(new java.awt.Rectangle(0, 0, 486, 377));
166
                jLabel.setText(PluginServices.getText(this,
167
                                "Areas_de_influencia._Introduccion_de_datos")
168
                                + ":");
169
                jLabel.setBounds(5, 20, 343, 21);
170
                jLabel3.setText(PluginServices.getText(this, "Cobertura_de_entrada")
171
                                + ":");
172
                jLabel3.setBounds(6, 63, 190, 21);
173
                this.add(jLabel, null);
174
                this.add(jLabel3, null);
175
                this.add(getLayersComboBox(), null);
176
                this.add(getSelectedOnlyCheckBox(), null);
177
                this.add(getMethodSelectionPanel(), null);
178
                this.add(getResultSelectionPanel(), null);
179
                this.add(getExtendedOptionsPanel(), null);
180
                confButtonGroup();
181
                layersComboBox.setSelectedIndex(0);
182
                initSelectedItemsJCheckBox();
183
                distanceBufferRadioButton.setSelected(true);
184
                layerFieldsComboBox.setEnabled(false);
185
                verifyTypeBufferComboEnabled();
186
        }
187

    
188
        private String[] getFieldNames() {
189
                AlphanumericData lyr = (AlphanumericData) (layers
190
                                .getLayer((String) layersComboBox.getSelectedItem()));
191
                DataSource ds;
192
                String[] fieldNames = null;
193
                try {
194
                        ds = lyr.getRecordset();
195
                        fieldNames = new String[ds.getFieldCount()];
196
                        for (int i = 0; i < ds.getFieldCount(); i++) {
197
                                fieldNames[i] = ds.getFieldName(i);
198
                        }
199
                } catch (DriverException e) {
200
                        // TODO Auto-generated catch block
201
                        e.printStackTrace();
202
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
203
                        // TODO Auto-generated catch block
204
                        e.printStackTrace();
205
                }
206
                return fieldNames;
207
        }
208

    
209
        private void initSelectedItemsJCheckBox() {
210
                String selectedLayer = (String) layersComboBox.getSelectedItem();
211
                FLyrVect inputLayer = (FLyrVect) layers.getLayer(selectedLayer);
212
                FBitSet fBitSet = null;
213
                try {
214
                        fBitSet = inputLayer.getRecordset().getSelection();
215
                } catch (DriverException e) {
216
                        // TODO Auto-generated catch block
217
                        e.printStackTrace();
218
                }
219
                if (fBitSet.cardinality() == 0) {
220
                        selectedOnlyCheckbox.setEnabled(false);
221
                } else {
222
                        selectedOnlyCheckbox.setEnabled(true);
223
                }
224
                selectedOnlyCheckbox.setSelected(false);
225
        }
226

    
227
        private JCheckBox getSelectedOnlyCheckBox() {
228
                if (selectedOnlyCheckbox == null) {
229
                        selectedOnlyCheckbox = new JCheckBox();
230
                        selectedOnlyCheckbox.setText(PluginServices.getText(this,
231
                                        "Usar_solamente_los_elementos_seleccionados"));
232
                        selectedOnlyCheckbox.setBounds(8, 102, 339, 21);
233
                }
234
                return selectedOnlyCheckbox;
235
        }
236

    
237
        /**
238
         * This method initializes layersComboBox
239
         * 
240
         * @return javax.swing.JComboBox
241
         */
242
        private JComboBox getLayersComboBox() {
243
                if (layersComboBox == null) {
244
                        layersComboBox = new JComboBox();
245
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
246
                                        getLayerNames());
247
                        layersComboBox.setModel(defaultModel);
248
                        layersComboBox.setBounds(142, 63, 260, 21);
249
                        layersComboBox.addItemListener(new java.awt.event.ItemListener() {
250
                                public void itemStateChanged(ItemEvent e) {
251
                                        if (e.getStateChange() == ItemEvent.SELECTED) {
252
                                                // Cambiar el estado del CheckBox
253
                                                initSelectedItemsJCheckBox();
254

    
255
                                                // Cambiar el estado del layerFieldsComboBox
256
                                                DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
257
                                                                getFieldNames());
258
                                                layerFieldsComboBox.setModel(defaultModel);
259
                                                verifyTypeBufferComboEnabled();
260
                                        }
261
                                }
262
                        });
263
                }
264
                return layersComboBox;
265
        }
266
        
267
        
268
        private void verifyTypeBufferComboEnabled(){
269
                String layerName = (String) layersComboBox.getSelectedItem();
270
                FLyrVect layer = (FLyrVect) layers.getLayer(layerName);
271
                boolean enable = false;
272
                try {
273
                        enable = layer.getShapeType() == XTypes.POLYGON;
274
                } catch (DriverException e1) {
275
                        e1.printStackTrace();
276
                }
277
                enableTypePolygonBufferPanel(enable);
278
        }
279
        
280

    
281
        /**
282
         * This method initializes fileNameResultTextField
283
         * 
284
         * @return javax.swing.JTextField
285
         */
286
        public JTextField getFileNameResultTextField() {
287
                if (fileNameResultTextField == null) {
288
                        super.getFileNameResultTextField().
289
                                setBounds(new java.awt.Rectangle(132, 11,
290
                                                                                                199, 21));
291
                }
292
                return fileNameResultTextField;
293
        }
294

    
295
        /**
296
         * This method initializes openFileButton
297
         * 
298
         * @return javax.swing.JButton
299
         */
300
        private JButton getOpenFileButton() {
301
                if (openFileButton == null) {
302
                        openFileButton = new JButton();
303
                        openFileButton.setText(PluginServices.getText(this, "Abrir"));
304
                        openFileButton.setBounds(new java.awt.Rectangle(335, 11, 129, 21));
305
                        openFileButton
306
                                        .addActionListener(new java.awt.event.ActionListener() {
307
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
308
                                                        openResultFile();
309
                                                }
310
                                        });
311
                }
312
                return openFileButton;
313
        }
314

    
315
        private void confButtonGroup() {
316
                if (buttonGroup == null) {
317
                        buttonGroup = new ButtonGroup();
318
                        buttonGroup.add(getDistanceBufferRadioButton());
319
                        buttonGroup.add(getAttributeBufferRadioButton());
320
                }
321
        }
322

    
323
        /**
324
         * This method initializes distanceBufferRadioButton
325
         * 
326
         * @return javax.swing.JRadioButton
327
         */
328
        private JRadioButton getDistanceBufferRadioButton() {
329
                if (distanceBufferRadioButton == null) {
330
                        distanceBufferRadioButton = new JRadioButton();
331
                        distanceBufferRadioButton.setText(PluginServices.getText(this,
332
                                        "Area_de_influencia_definida_por_una_distancia")
333
                                        + ":");
334
                        distanceBufferRadioButton.setBounds(new java.awt.Rectangle(2, 10,
335
                                        303, 24));
336
                        distanceBufferRadioButton
337
                                        .addActionListener(new java.awt.event.ActionListener() {
338
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
339
                                                        constantDistanceSelected();
340
                                                }
341
                                        });
342
                }
343
                return distanceBufferRadioButton;
344
        }
345

    
346
        /**
347
         * This method initializes bufferDistanceTextField
348
         * 
349
         * @return javax.swing.JTextField
350
         */
351
        private JTextField getBufferDistanceTextField() {
352
                if (bufferDistanceTextField == null) {
353
                        bufferDistanceTextField = new JTextField();
354
                        bufferDistanceTextField.setBounds(new java.awt.Rectangle(308, 11,
355
                                        134, 21));
356
                }
357
                return bufferDistanceTextField;
358
        }
359

    
360
        /**
361
         * This method initializes attributeBufferRadioButton
362
         * 
363
         * @return javax.swing.JRadioButton
364
         */
365
        private JRadioButton getAttributeBufferRadioButton() {
366
                if (attributeBufferRadioButton == null) {
367
                        attributeBufferRadioButton = new JRadioButton();
368
                        attributeBufferRadioButton.setText(PluginServices.getText(this,
369
                                        "Area_de_influencia_definida_por_un_campo")
370
                                        + ":");
371
                        attributeBufferRadioButton.setBounds(new java.awt.Rectangle(2, 41,
372
                                        287, 21));
373
                        attributeBufferRadioButton
374
                                        .addActionListener(new java.awt.event.ActionListener() {
375
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
376
                                                        attributeDistanceSelected();
377
                                                }
378
                                        });
379
                }
380
                return attributeBufferRadioButton;
381
        }
382

    
383
        /**
384
         * This method initializes layerFieldsComboBox
385
         * 
386
         * @return javax.swing.JComboBox
387
         */
388
        private JComboBox getLayerFieldsComboBox() {
389
                if (layerFieldsComboBox == null) {
390
                        layerFieldsComboBox = new JComboBox();
391
                        layerFieldsComboBox.setBounds(new java.awt.Rectangle(308, 41, 138,
392
                                        21));
393
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
394
                                        getFieldNames());
395
                        layerFieldsComboBox.setModel(defaultModel);
396
                }
397
                return layerFieldsComboBox;
398
        }
399

    
400
        private JCheckBox getDissolveEntitiesJCheckBox() {
401
                if (dissolveEntitiesJCheckBox == null) {
402
                        dissolveEntitiesJCheckBox = new JCheckBox();
403
                        dissolveEntitiesJCheckBox.setText(PluginServices.getText(this,
404
                                        "Disolver_entidades"));
405
                        dissolveEntitiesJCheckBox.setBounds(new java.awt.Rectangle(9, 70,
406
                                        190, 21));
407
                }
408
                return dissolveEntitiesJCheckBox;
409
        }
410

    
411
        public void openResultFile() {
412
                JFileChooser jfc = new JFileChooser();
413
                jfc
414
                                .addChoosableFileFilter(new GenericFileFilter("shp",
415
                                                "Ficheros SHP"));
416
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
417
                        File file = jfc.getSelectedFile();
418
                        if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(
419
                                        ".SHP"))) {
420
                                file = new File(file.getPath() + ".shp");
421
                        }
422
                }// if
423
                if (jfc.getSelectedFile() != null) {
424
                        getFileNameResultTextField().setText(
425
                                        jfc.getSelectedFile().getAbsolutePath());
426
                }
427

    
428
        }
429

    
430
        public void constantDistanceSelected() {
431
                getBufferDistanceTextField().setEnabled(true);
432
                getLayerFieldsComboBox().setEnabled(false);
433

    
434
        }
435

    
436
        public void attributeDistanceSelected() {
437
                getBufferDistanceTextField().setEnabled(false);
438
                getLayerFieldsComboBox().setEnabled(true);
439

    
440
        }
441

    
442
        public boolean isConstantDistanceSelected() {
443
                return distanceBufferRadioButton.isSelected();
444
        }
445

    
446
        public boolean isAttributeDistanceSelected() {
447
                return attributeBufferRadioButton.isSelected();
448
        }
449

    
450
        public double getConstantDistance() throws GeoprocessException {
451
                try {
452
                        String strDist = bufferDistanceTextField.getText();
453
                        return Double.parseDouble(strDist);
454
                } catch (NumberFormatException ex) {
455
                        throw new GeoprocessException(
456
                                        "Distancia de buffer introducida no numerica");
457
                }
458
        }
459

    
460
        public String getAttributeDistanceField() throws GeoprocessException {
461
                String attributeField = (String) layerFieldsComboBox.getSelectedItem();
462
                FLyrVect selectedLayer = getInputLayer();
463
                try {
464
                        SelectableDataSource selectable = selectedLayer.getRecordset();
465

    
466
                        int fieldIndex = selectable.getFieldIndexByName(attributeField);
467
                        int fieldType = selectable.getFieldType(fieldIndex);
468

    
469
                        if (!XTypes.isNumeric(fieldType))
470
                                throw new GeoprocessException(
471
                                                "Atributo no numerico para distancia de buffer");
472

    
473
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
474
                        throw new GeoprocessException(
475
                                        "Problemas accediendo al campo que define la distancia de buffer");
476
                } catch (DriverException e) {
477
                        throw new GeoprocessException(
478
                                        "Problemas accediendo al campo que define la distancia de buffer");
479
                }
480
                return attributeField;
481
        }
482

    
483
        public boolean isBufferOnlySelected() {
484
                return selectedOnlyCheckbox.isSelected();
485
        }
486

    
487
        public boolean isDissolveBuffersSelected() {
488
                return dissolveEntitiesJCheckBox.isSelected();
489
        }
490

    
491
        public ViewInfo getViewInfo() {
492
                if (viewInfo == null) {
493
                        viewInfo = new ViewInfo(ViewInfo.MODALDIALOG);
494
                        viewInfo.setTitle(PluginServices
495
                                        .getText(this, "Area_de_influencia"));
496
                }
497
                return viewInfo;
498
        }
499

    
500
        /**
501
         * This method initializes methodSelectionPanel
502
         * 
503
         * @return javax.swing.JPanel
504
         */
505
        private JPanel getMethodSelectionPanel() {
506
                if (methodSelectionPanel == null) {
507
                        methodSelectionPanel = new JPanel();
508
                        methodSelectionPanel.setLayout(null);
509
                        methodSelectionPanel.setBounds(new java.awt.Rectangle(2, 127, 467,
510
                                        94));
511
                        methodSelectionPanel
512
                                        .setBorder(javax.swing.BorderFactory
513
                                                        .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
514
                        methodSelectionPanel.add(getDistanceBufferRadioButton(), null);
515
                        methodSelectionPanel.add(getBufferDistanceTextField(), null);
516
                        methodSelectionPanel.add(getAttributeBufferRadioButton(), null);
517
                        methodSelectionPanel.add(getLayerFieldsComboBox(), null);
518
                        methodSelectionPanel.add(getDissolveEntitiesJCheckBox(), null);
519
                        methodSelectionPanel.add(getEndCapCheckBox(), null);
520
                }
521
                return methodSelectionPanel;
522
        }
523

    
524
        /**
525
         * This method initializes resultSelectionPanel
526
         * 
527
         * @return javax.swing.JPanel
528
         */
529
        private JPanel getResultSelectionPanel() {
530
                if (resultSelectionPanel == null) {
531
                        jLabel1 = new JLabel();
532
                        jLabel1.setBounds(new java.awt.Rectangle(5, 9, 132, 24));
533
                        jLabel1.setText(PluginServices.getText(this, "Cobertura_de_salida")
534
                                        + ":");
535
                        resultSelectionPanel = new JPanel();
536
                        resultSelectionPanel.setLayout(null);
537
                        resultSelectionPanel.setBounds(new java.awt.Rectangle(0, 291, 468,
538
                                        41));
539
                        resultSelectionPanel
540
                                        .setBorder(javax.swing.BorderFactory
541
                                                        .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
542
                        resultSelectionPanel.add(getFileNameResultTextField(), null);
543
                        resultSelectionPanel.add(getOpenFileButton(), null);
544
                        resultSelectionPanel.add(jLabel1, null);
545
                }
546
                return resultSelectionPanel;
547
        }
548

    
549
        public boolean isSquareCap() {
550
                return getEndCapCheckBox().isSelected();
551
        }
552

    
553
        /**
554
         * This method initializes endCapCheckBox
555
         * 
556
         * @return javax.swing.JCheckBox
557
         */
558
        private JCheckBox getEndCapCheckBox() {
559
                if (endCapCheckBox == null) {
560
                        endCapCheckBox = new JCheckBox();
561
                        endCapCheckBox.setBounds(new java.awt.Rectangle(209, 69, 235, 21));
562
                        endCapCheckBox.setText(PluginServices.getText(this,
563
                                        "No_usar_buffer_redondeado"));
564
                }
565
                return endCapCheckBox;
566
        }
567

    
568
        /**
569
         * This method initializes extendedOptionsPanel
570
         * 
571
         * @return javax.swing.JPanel
572
         */
573
        private JPanel getExtendedOptionsPanel() {
574
                if (extendedOptionsPanel == null) {
575
                        extendedOptionsPanel = new JPanel();
576
                        extendedOptionsPanel.setLayout(null);
577
                        extendedOptionsPanel.setBounds(new java.awt.Rectangle(2, 226, 465,
578
                                        62));
579
                        extendedOptionsPanel
580
                                        .setBorder(javax.swing.BorderFactory
581
                                                        .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
582
                        extendedOptionsPanel.add(getTypePolygonBufferPanel(), null);
583
                        extendedOptionsPanel.add(getNumBuffersPanel(), null);
584
                }
585
                return extendedOptionsPanel;
586
        }
587

    
588
        /**
589
         * This method initializes typePolygonBufferPanel
590
         * 
591
         * @return javax.swing.JPanel
592
         */
593
        private JPanel getTypePolygonBufferPanel() {
594
                if (typePolygonBufferPanel == null) {
595
                        typeBufferLabel = new JLabel();
596
                        typeBufferLabel.setBounds(new java.awt.Rectangle(10, 3, 143, 18));
597
                        typeBufferLabel.setText(PluginServices
598
                                        .getText(this, "Crear_Buffer"));
599
                        typePolygonBufferPanel = new JPanel();
600
                        typePolygonBufferPanel.setLayout(null);
601
                        typePolygonBufferPanel.setBounds(new java.awt.Rectangle(8, 6, 449,
602
                                        24));
603
                        typePolygonBufferPanel.add(typeBufferLabel, null);
604
                        typePolygonBufferPanel.add(getTypeBufferComboBox(), null);
605
                }
606
                return typePolygonBufferPanel;
607
        }
608

    
609
        /**
610
         * This method initializes typeBufferComboBox
611
         * 
612
         * @return javax.swing.JComboBox
613
         */
614
        private JComboBox getTypeBufferComboBox() {
615
                if (typeBufferComboBox == null) {
616
                        typeBufferComboBox = new JComboBox();
617
                        typeBufferComboBox
618
                                        .setBounds(new java.awt.Rectangle(167, 4, 270, 18));
619
                        typeBufferComboBox.addItem(BUFFER_INSIDE);
620
                        typeBufferComboBox.addItem(BUFFER_OUTSIDE);
621
                        typeBufferComboBox.addItem(BUFFER_INSIDE_OUTSIDE);
622
                        typeBufferComboBox.setSelectedItem(BUFFER_OUTSIDE);
623
                }
624
                return typeBufferComboBox;
625
        }
626

    
627
        /**
628
         * Returns the type of polygon byffer (inside, outside, inside and outside)
629
         * selected by user
630
         * 
631
         * @return
632
         */
633
        public String getTypePolygonBuffer() {
634
                return (String) getTypeBufferComboBox().getSelectedItem();
635
        }
636

    
637
        /**
638
         * Allow to enable/disable typePolygonBufferPanel (and all its components).
639
         * The reason is that this customizations are only possible with polygon
640
         * layers.
641
         * 
642
         * @param enable
643
         */
644
        public void enableTypePolygonBufferPanel(boolean enable) {
645
                getTypePolygonBufferPanel().setEnabled(enable);
646
                getTypeBufferComboBox().setEnabled(enable);
647
        }
648

    
649
        /**
650
         * This method initializes numBuffersPanel
651
         * 
652
         * @return javax.swing.JPanel
653
         */
654
        private JPanel getNumBuffersPanel() {
655
                if (numBuffersPanel == null) {
656
                        radialBufferLabel = new JLabel();
657
                        radialBufferLabel.setBounds(new java.awt.Rectangle(5, 3, 269, 19));
658
                        radialBufferLabel.setText(PluginServices.getText(this,
659
                                        "Numero_anillos_concentricos"));
660
                        numBuffersPanel = new JPanel();
661
                        numBuffersPanel.setLayout(null);
662
                        numBuffersPanel.setBounds(new java.awt.Rectangle(10, 35, 448, 24));
663
                        numBuffersPanel.add(radialBufferLabel, null);
664
                        numBuffersPanel.add(getRadialBufferSpinner(), null);
665
                }
666
                return numBuffersPanel;
667
        }
668

    
669
        /**
670
         * This method initializes radialBufferTextField
671
         * 
672
         * @return javax.swing.JTextField
673
         */
674
        private JSpinner getRadialBufferSpinner() {
675
                if (radialBufferSpinner == null) {
676
                        Integer one = new Integer(1);
677
                        Integer two = new Integer(2);
678
                        Integer three = new Integer(3);
679
                        SpinnerListModel listModel = new SpinnerListModel(new Integer[] {
680
                                        one, two, three });
681
                        radialBufferSpinner = new JSpinner(listModel);
682
                        radialBufferSpinner.setBounds(new java.awt.Rectangle(298, 3, 137,
683
                                        19));
684

    
685
                        // Disable keyboard edits in the spinner
686
                        JFormattedTextField tf = ((JSpinner.DefaultEditor) radialBufferSpinner
687
                                        .getEditor()).getTextField();
688
                        tf.setEditable(false);
689
                        tf.setBackground(Color.white);
690
                }
691
                return radialBufferSpinner;
692
        }
693

    
694
        /**
695
         * Returns the number of radial buffers selected by user (by now, only a
696
         * maximum of three radial buffers allowed)
697
         * 
698
         * @return
699
         */
700
        public int getNumberOfRadialBuffers() {
701
                return ((Integer) radialBufferSpinner.getValue()).intValue();
702
        }
703
} // @jve:decl-index=0:visual-constraint="25,13"