Revision 340

View differences:

org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.derivedgeometries.swing.impl.DefaultDerivedGeometriesLibrary
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/FeaturesControlPanelView.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30

  
31
import javax.swing.BorderFactory;
32
import javax.swing.ImageIcon;
33
import javax.swing.JButton;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JScrollPane;
37
import javax.swing.JSplitPane;
38
import javax.swing.JTable;
39
import javax.swing.JTextField;
40
import javax.swing.ListSelectionModel;
41
import javax.swing.table.TableModel;
42

  
43
import org.gvsig.derivedgeometries.swing.api.exceptions.FetaureTableModelException;
44
import org.gvsig.fmap.dal.exception.DataException;
45
import org.gvsig.fmap.dal.feature.FeatureQuery;
46
import org.gvsig.fmap.dal.feature.FeatureStore;
47
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTable;
48
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel;
49
import org.gvsig.tools.ToolsLocator;
50
import org.gvsig.tools.exception.BaseException;
51
import org.gvsig.tools.i18n.I18nManager;
52
import org.gvsig.tools.swing.api.ToolsSwingLocator;
53

  
54
public class FeaturesControlPanelView extends JPanel {
55

  
56
    private static final long serialVersionUID = -3899738999699332396L;
57

  
58
    private I18nManager i18nManager = ToolsLocator.getI18nManager();
59

  
60
    private JPanel summaryPanel;
61

  
62
    private JLabel sourceLayerNameLabel;
63

  
64
    private JTextField sourceLayerNameTextField;
65

  
66
    private JLabel destLayerNameLabel;
67

  
68
    private JTextField destLayerNameTextField;
69

  
70
    private JPanel centerPanel;
71

  
72
    private JSplitPane horizontalSplitPane;
73

  
74
    private JPanel featuresPanel;
75

  
76
    private JScrollPane allFeaturesScrollPane;
77

  
78
    private FeatureTable allFeaturesTable;
79

  
80
    private ConfigurableFeatureTableModel allFeaturesTableModel;
81

  
82
    private JPanel newFeatureSelectionPanel;
83

  
84
    private JPanel motionButtonsPanel;
85

  
86
    private JScrollPane selectedFeaturesScrollPane;
87

  
88
    private JTable selectedFeaturesTable;
89

  
90
    private JButton addAllIconButton;
91

  
92
    private JButton removeAllIconButton;
93

  
94
    private JButton addIconButton;
95

  
96
    private JButton removeIconButton;
97

  
98
    private JButton moveUpButton;
99

  
100
    private JButton moveDownButton;
101

  
102
    public FeaturesControlPanelView() {
103
        initialize();
104
    }
105

  
106
    private void initialize() {
107
        setLayout(new BorderLayout());
108
        add(getSummaryPanel(), BorderLayout.PAGE_START);
109
        add(getCenterPanel(), BorderLayout.CENTER);
110
    }
111

  
112
    @Override
113
    public Dimension getPreferredSize() {
114
        return new Dimension(500, 550);
115
    }
116

  
117
    protected JScrollPane getAllFeaturesScrollPane() {
118
        if (allFeaturesScrollPane == null) {
119
            allFeaturesScrollPane = new JScrollPane();
120
            allFeaturesScrollPane
121
                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
122
        }
123

  
124
        return allFeaturesScrollPane;
125
    }
126

  
127
    @SuppressWarnings("serial")
128
    protected FeatureTable getAllFeaturesTable(FeatureStore featureStore)
129
        throws FetaureTableModelException {
130
        if (allFeaturesTable == null) {
131
            try {
132
                allFeaturesTable =
133
                    new FeatureTable(getAllFeaturesTableModel(featureStore)) {
134

  
135
                        public boolean isCellEditable(int row, int column) {
136
                            return false;
137
                        }
138
                    };
139
                allFeaturesTable
140
                    .setSelectionModel(new DefaultDerivedGeometriesSelectionModel(allFeaturesTableModel));
141
            } catch (DataException e) {
142
                throw new FetaureTableModelException(e.getMessage(), e);
143
            }
144

  
145
            allFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
146
        }
147
        return allFeaturesTable;
148
    }
149

  
150
    protected ConfigurableFeatureTableModel getAllFeaturesTableModel(
151
        FeatureStore featureStore) throws FetaureTableModelException {
152
        if (allFeaturesTableModel == null) {
153
            try {
154
                FeatureQuery query = featureStore.createFeatureQuery();
155
                allFeaturesTableModel =
156
                    new ConfigurableFeatureTableModel(featureStore, query);
157
            } catch (BaseException e) {
158
                throw new FetaureTableModelException(e.getMessage(), e);
159
            }
160
        }
161

  
162
        return allFeaturesTableModel;
163
    }
164

  
165
    private JPanel getCenterPanel() {
166
        if (centerPanel == null) {
167
            centerPanel = new JPanel();
168
            centerPanel.setLayout(new BorderLayout());
169
            centerPanel.add(getHorizontalSplitPane(), BorderLayout.CENTER);
170
        }
171

  
172
        return centerPanel;
173
    }
174

  
175
    private JPanel getFeaturesPanel() {
176
        if (featuresPanel == null) {
177
            featuresPanel = new JPanel();
178
            featuresPanel.setBorder(BorderFactory
179
                .createTitledBorder(i18nManager.getTranslation("features")));
180
            featuresPanel.setLayout(new BorderLayout());
181
            featuresPanel.add(getAllFeaturesScrollPane(), BorderLayout.CENTER);
182
        }
183

  
184
        return featuresPanel;
185
    }
186

  
187
    private JSplitPane getHorizontalSplitPane() {
188
        if (horizontalSplitPane == null) {
189
            horizontalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
190
            horizontalSplitPane.setPreferredSize(this.getPreferredSize());
191
            horizontalSplitPane.setOneTouchExpandable(true);
192

  
193
            horizontalSplitPane.setTopComponent(getFeaturesPanel());
194
            horizontalSplitPane.setBottomComponent(getNewFeaturePanel());
195

  
196
            // Sets the split pane's divider to the 40 %
197
            horizontalSplitPane.setDividerLocation((int) (horizontalSplitPane
198
                .getPreferredSize().getHeight() * 0.40));
199
        }
200

  
201
        return horizontalSplitPane;
202
    }
203

  
204
    private JPanel getNewFeaturePanel() {
205
        if (newFeatureSelectionPanel == null) {
206
            newFeatureSelectionPanel = new JPanel();
207
            newFeatureSelectionPanel
208
                .setBorder(BorderFactory.createTitledBorder(i18nManager
209
                    .getTranslation("_new_features")));
210
            newFeatureSelectionPanel.setLayout(new BorderLayout());
211

  
212
            // Add all button
213
            addAllIconButton = getAddAllButton();
214
            // Remove all button
215
            removeAllIconButton = getRemoveAllButton();
216
            // Add button
217
            addIconButton = getAddButton();
218
            // Remove button
219
            removeIconButton = getRemoveButton();
220

  
221
            // Right panel
222
            JPanel rightPanel = new JPanel();
223
            rightPanel.add(addIconButton);
224
            rightPanel.add(removeIconButton);
225

  
226
            // Left panel
227
            JPanel leftPanel = new JPanel();
228
            leftPanel.add(addAllIconButton);
229
            leftPanel.add(removeAllIconButton);
230

  
231
            // North panel
232
            JPanel northPanel = new JPanel();
233
            northPanel.setLayout(new BorderLayout());
234
            northPanel.add(leftPanel, BorderLayout.LINE_START);
235
            northPanel.add(rightPanel, BorderLayout.LINE_END);
236
            newFeatureSelectionPanel.add(northPanel, BorderLayout.PAGE_START);
237

  
238
            // South panel
239
            JPanel southPanel = new JPanel();
240
            southPanel.setLayout(new GridBagLayout());
241

  
242
            GridBagConstraints constraints = new GridBagConstraints();
243
            constraints.gridx = GridBagConstraints.RELATIVE;
244
            constraints.gridy = 0;
245
            constraints.weightx = 1;
246
            constraints.weighty = 1;
247
            constraints.fill = GridBagConstraints.BOTH;
248
            constraints.anchor = GridBagConstraints.WEST;
249

  
250
            southPanel.add(getSelectedFeaturesScrollPane(), constraints);
251

  
252
            constraints = new GridBagConstraints();
253
            constraints.gridx = GridBagConstraints.RELATIVE;
254
            constraints.gridy = 0;
255
            constraints.weightx = 0;
256
            constraints.weighty = 0;
257
            constraints.fill = GridBagConstraints.BOTH;
258
            constraints.anchor = GridBagConstraints.EAST;
259

  
260
            southPanel.add(getMotionButtonsPanel(), constraints);
261

  
262
            newFeatureSelectionPanel.add(southPanel, BorderLayout.CENTER);
263
        }
264
        return newFeatureSelectionPanel;
265
    }
266

  
267
    protected JButton getAddAllButton() {
268
        if (addAllIconButton == null) {
269
            ImageIcon addAllIcon =
270
                ToolsSwingLocator.getIconThemeManager().getCurrent()
271
                    .get("add-all-icon");
272
            addAllIconButton = new JButton(addAllIcon);
273
            addAllIconButton.setToolTipText(i18nManager
274
                .getTranslation("_add_all_button_tooltip"));
275
        }
276
        return addAllIconButton;
277
    }
278

  
279
    protected JButton getAddButton() {
280
        if (addIconButton == null) {
281
            ImageIcon addIcon =
282
                ToolsSwingLocator.getIconThemeManager().getCurrent()
283
                    .get("add-selected-icon");
284
            addIconButton = new JButton(addIcon);
285
            addIconButton.setToolTipText(i18nManager
286
                .getTranslation("_add_selected_button_tooltip"));
287
        }
288
        return addIconButton;
289
    }
290

  
291
    protected JButton getRemoveAllButton() {
292
        if (removeAllIconButton == null) {
293
            ImageIcon removeAllIcon =
294
                ToolsSwingLocator.getIconThemeManager().getCurrent()
295
                    .get("remove-all-icon");
296
            removeAllIconButton = new JButton(removeAllIcon);
297
            removeAllIconButton.setToolTipText(i18nManager
298
                .getTranslation("_remove_all_button_tooltip"));
299
        }
300
        return removeAllIconButton;
301
    }
302

  
303
    protected JButton getRemoveButton() {
304
        if (removeIconButton == null) {
305
            ImageIcon removeIcon =
306
                ToolsSwingLocator.getIconThemeManager().getCurrent()
307
                    .get("remove-selected-icon");
308
            removeIconButton = new JButton(removeIcon);
309
            removeIconButton.setToolTipText(i18nManager
310
                .getTranslation("_remove_selected_button_tooltip"));
311
        }
312
        return removeIconButton;
313
    }
314

  
315
    protected JScrollPane getSelectedFeaturesScrollPane() {
316
        if (selectedFeaturesScrollPane == null) {
317
            selectedFeaturesScrollPane = new JScrollPane();
318
            selectedFeaturesScrollPane
319
                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
320
        }
321

  
322
        return selectedFeaturesScrollPane;
323
    }
324

  
325
    @SuppressWarnings("serial")
326
    protected JTable getSelectedFeaturesTable() {
327
        if (selectedFeaturesTable == null) {
328
            selectedFeaturesTable = new JTable() {
329

  
330
                public boolean isCellEditable(int row, int column) {
331
                    return false;
332
                }
333
            };
334

  
335
            selectedFeaturesTable
336
                .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
337
            selectedFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
338
        }
339
        return selectedFeaturesTable;
340
    }
341

  
342
    protected SelectedFeaturesTableModel getSelectedFeaturesTableModel() {
343
        TableModel model = getSelectedFeaturesTable().getModel();
344
        if (model instanceof SelectedFeaturesTableModel) {
345
            return (SelectedFeaturesTableModel) model;
346
        }
347
        return null;
348
    }
349

  
350
    private JPanel getMotionButtonsPanel() {
351
        if (motionButtonsPanel == null) {
352
            motionButtonsPanel = new JPanel();
353
            motionButtonsPanel.setLayout(new GridBagLayout());
354

  
355
            // Move up button
356
            moveUpButton = getMoveUpButton();
357

  
358
            JPanel upPanel = new JPanel();
359
            upPanel.add(moveUpButton);
360

  
361
            GridBagConstraints constraints = new GridBagConstraints();
362
            constraints.gridx = 0;
363
            constraints.gridy = GridBagConstraints.RELATIVE;
364
            constraints.gridheight = 0;
365
            constraints.gridwidth = 0;
366
            constraints.weightx = 0;
367
            constraints.weighty = 0;
368
            constraints.anchor = GridBagConstraints.CENTER;
369
            constraints.fill = GridBagConstraints.NONE;
370
            constraints.insets = new Insets(4, 4, 4, 0);
371

  
372
            motionButtonsPanel.add(upPanel, constraints);
373

  
374
            // Move down button
375
            moveDownButton = getMoveDownButton();
376

  
377
            JPanel downPanel = new JPanel();
378
            downPanel.add(moveDownButton);
379
            motionButtonsPanel.add(downPanel, constraints);
380
        }
381

  
382
        return motionButtonsPanel;
383
    }
384

  
385
    protected JButton getMoveUpButton() {
386
        if (moveUpButton == null) {
387
            ImageIcon moveUpIcon =
388
                ToolsSwingLocator.getIconThemeManager().getCurrent()
389
                    .get("up-arrow-icon");
390
            moveUpButton = new JButton(moveUpIcon);
391
            moveUpButton.setToolTipText(i18nManager
392
                .getTranslation("_move_up_button_tooltip"));
393

  
394
        }
395

  
396
        return moveUpButton;
397
    }
398

  
399
    protected JButton getMoveDownButton() {
400
        if (moveDownButton == null) {
401
            ImageIcon moveDownIcon =
402
                ToolsSwingLocator.getIconThemeManager().getCurrent()
403
                    .get("down-arrow-icon");
404
            moveDownButton = new JButton(moveDownIcon);
405
            moveDownButton.setToolTipText(i18nManager
406
                .getTranslation("_move_down_button_tooltip"));
407
        }
408
        return moveDownButton;
409
    }
410

  
411
    private JLabel getOutputLayerNameLabel() {
412
        if (destLayerNameLabel == null) {
413
            destLayerNameLabel =
414
                new JLabel(i18nManager.getTranslation("_output_layer"));
415
            destLayerNameLabel.setToolTipText(i18nManager
416
                .getTranslation("_output_layer"));
417
        }
418

  
419
        return destLayerNameLabel;
420
    }
421

  
422
    protected JTextField getOutputLayerNameTextField() {
423
        if (destLayerNameTextField == null) {
424
            destLayerNameTextField = new JTextField();
425
            destLayerNameTextField.setEnabled(false);
426
        }
427

  
428
        return destLayerNameTextField;
429
    }
430

  
431
    private JLabel getSourceLayerNameLabel() {
432
        if (sourceLayerNameLabel == null) {
433
            sourceLayerNameLabel =
434
                new JLabel(i18nManager.getTranslation("_source_layer"));
435
            sourceLayerNameLabel.setToolTipText(i18nManager
436
                .getTranslation("_source_layer"));
437
        }
438

  
439
        return sourceLayerNameLabel;
440
    }
441

  
442
    protected JTextField getSourceLayerNameTextField() {
443
        if (sourceLayerNameTextField == null) {
444
            sourceLayerNameTextField = new JTextField();
445
            sourceLayerNameTextField.setEnabled(false);
446
        }
447

  
448
        return sourceLayerNameTextField;
449
    }
450

  
451
    private JPanel getSummaryPanel() {
452
        if (summaryPanel == null) {
453
            summaryPanel = new JPanel();
454
            summaryPanel.setLayout(new BorderLayout());
455
            summaryPanel.setBorder(BorderFactory.createTitledBorder(i18nManager
456
                .getTranslation("_layers")));
457

  
458
            JPanel pageStartPanel = new JPanel();
459
            pageStartPanel.setLayout(new GridBagLayout());
460

  
461
            GridBagConstraints constraints = getConstraintsForLabel();
462
            pageStartPanel.add(getSourceLayerNameLabel(), constraints);
463

  
464
            constraints = getContraintsForTextField();
465
            pageStartPanel.add(getSourceLayerNameTextField(), constraints);
466

  
467
            summaryPanel.add(pageStartPanel, BorderLayout.PAGE_START);
468

  
469
            JPanel pageEndPanel = new JPanel();
470
            pageEndPanel.setLayout(new GridBagLayout());
471
            constraints = getConstraintsForLabel();
472
            pageEndPanel.add(getOutputLayerNameLabel(), constraints);
473

  
474
            constraints = getContraintsForTextField();
475
            pageEndPanel.add(getOutputLayerNameTextField(), constraints);
476

  
477
            summaryPanel.add(pageEndPanel, BorderLayout.PAGE_END);
478
        }
479

  
480
        return summaryPanel;
481
    }
482

  
483
    private GridBagConstraints getConstraintsForLabel() {
484
        GridBagConstraints constraints = new GridBagConstraints();
485
        constraints.gridx = GridBagConstraints.RELATIVE;
486
        constraints.gridy = 0;
487
        constraints.gridwidth = 1;
488
        constraints.gridheight = 1;
489
        constraints.anchor = GridBagConstraints.WEST;
490
        constraints.fill = GridBagConstraints.NONE;
491
        constraints.insets = new Insets(4, 4, 4, 4);
492
        return constraints;
493
    }
494

  
495
    private GridBagConstraints getContraintsForTextField() {
496
        GridBagConstraints constraints = new GridBagConstraints();
497
        constraints.gridx = GridBagConstraints.RELATIVE;
498
        constraints.gridy = 0;
499
        constraints.gridwidth = 2;
500
        constraints.gridheight = 1;
501
        constraints.weightx = 1;
502
        constraints.anchor = GridBagConstraints.CENTER;
503
        constraints.fill = GridBagConstraints.HORIZONTAL;
504
        constraints.insets = new Insets(4, 4, 4, 4);
505
        return constraints;
506
    }
507
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/SourceLayerComboBoxRenderer.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.awt.Color;
26
import java.awt.Component;
27

  
28
import javax.swing.DefaultListCellRenderer;
29
import javax.swing.ImageIcon;
30
import javax.swing.JList;
31

  
32
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
33
import org.gvsig.tools.swing.api.ToolsSwingLocator;
34

  
35
public class SourceLayerComboBoxRenderer extends DefaultListCellRenderer {
36

  
37
    private static final long serialVersionUID = 5975166847058585247L;
38

  
39
    public Component getListCellRendererComponent(JList list, Object value,
40
        int index, boolean isSelected, boolean cellHasFocus) {
41

  
42
        super.getListCellRendererComponent(list, value, index, isSelected,
43
            cellHasFocus);
44

  
45
        FLyrVect selectedLayer = (FLyrVect) value;
46

  
47
        if (selectedLayer != null) {
48
            if (isSelected) {
49
                setBackground(Color.LIGHT_GRAY);
50
                setForeground(Color.BLACK);
51
            } else {
52
                setBackground(Color.WHITE);
53
                setForeground(Color.BLACK);
54
            }
55

  
56
            // Set icon
57
            String iconName = selectedLayer.getTocImageIcon();
58
            ImageIcon moveUpIcon =
59
                ToolsSwingLocator.getIconThemeManager().getCurrent()
60
                    .get(iconName);
61
            setIcon(moveUpIcon);
62

  
63
            // Set name and icon
64
            String layerName = selectedLayer.getName();
65

  
66
            setText(layerName);
67
            setFont(list.getFont());
68
        } else {
69
            setText("");
70
            setIcon(null);
71
        }
72
        return this;
73
    }
74

  
75
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/LayerAndProcessSelectionPanelView.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.awt.Color;
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30

  
31
import javax.swing.BorderFactory;
32
import javax.swing.JButton;
33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35
import javax.swing.JTextField;
36

  
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.i18n.I18nManager;
39
import org.gvsig.utils.swing.JComboBox;
40

  
41
public class LayerAndProcessSelectionPanelView extends JPanel {
42

  
43
    private static final long serialVersionUID = 5814562877542407537L;
44

  
45
    private I18nManager i18nManager = ToolsLocator.getI18nManager();
46

  
47
    private JPanel sourceLayerPanel;
48

  
49
    private JPanel layersPanel;
50

  
51
    private JPanel optionsPanel;
52

  
53
    private JPanel outputProcessPanel;
54

  
55
    private JPanel outputLayerNamePanel;
56

  
57
    private JPanel outputPathPanel;
58

  
59
    private JPanel outputLayerTypePanel;
60

  
61
    private JComboBox layersComboBox;
62

  
63
    private JComboBox outputProcessCombo;
64

  
65
    private JComboBox outputShapeTypeCombo;
66

  
67
    private JLabel layersLabel;
68

  
69
    private JLabel outputProcessLabel;
70

  
71
    private JLabel labelName;
72

  
73
    private JLabel labelPath;
74

  
75
    private JLabel outputShapeTypeLabel;
76

  
77
    private JTextField outputLayerPath;
78

  
79
    private JTextField outputLayerName;
80

  
81
    private JButton selectPathButton;
82

  
83
    public LayerAndProcessSelectionPanelView() {
84
        initilize();
85
        doLayout();
86
        setVisible(true);
87

  
88
        setPreferredSize(new Dimension(500, 360));
89
    }
90

  
91
    private GridBagConstraints getConstraintsForCombo() {
92
        GridBagConstraints constraints;
93
        constraints = new GridBagConstraints();
94
        constraints.gridx = GridBagConstraints.RELATIVE;
95
        constraints.gridy = 0;
96
        constraints.gridwidth = GridBagConstraints.REMAINDER;
97
        constraints.gridheight = 1;
98
        constraints.weightx = 1;
99
        constraints.anchor = GridBagConstraints.CENTER;
100
        constraints.fill = GridBagConstraints.HORIZONTAL;
101
        constraints.insets = new Insets(4, 4, 4, 4);
102
        return constraints;
103
    }
104

  
105
    private GridBagConstraints getConstraintsForLabel() {
106
        GridBagConstraints constraints = new GridBagConstraints();
107
        constraints.gridx = GridBagConstraints.RELATIVE;
108
        constraints.gridy = 0;
109
        constraints.gridwidth = 1;
110
        constraints.gridheight = 1;
111
        constraints.anchor = GridBagConstraints.WEST;
112
        constraints.fill = GridBagConstraints.NONE;
113
        constraints.insets = new Insets(4, 4, 4, 4);
114
        return constraints;
115
    }
116

  
117
    private GridBagConstraints getContraintsForTextField() {
118
        GridBagConstraints constraints = new GridBagConstraints();
119
        constraints.gridx = GridBagConstraints.RELATIVE;
120
        constraints.gridy = 0;
121
        constraints.gridwidth = 2;
122
        constraints.gridheight = 1;
123
        constraints.weightx = 1;
124
        constraints.anchor = GridBagConstraints.CENTER;
125
        constraints.fill = GridBagConstraints.HORIZONTAL;
126
        constraints.insets = new Insets(4, 4, 4, 4);
127
        return constraints;
128
    }
129

  
130
    protected JButton getJButtonSelectPath() {
131
        if (selectPathButton == null) {
132
            selectPathButton = new JButton();
133
            selectPathButton.setToolTipText(i18nManager
134
                .getTranslation("_select_path"));
135
            selectPathButton.setText("...");
136
        }
137
        return selectPathButton;
138
    }
139

  
140
    private JLabel getLabelName() {
141
        if (labelName == null) {
142
            labelName = new JLabel(i18nManager.getTranslation("_name"));
143
            labelName.setToolTipText(i18nManager.getTranslation("name"));
144
        }
145

  
146
        return labelName;
147
    }
148

  
149
    private JLabel getLabelPath() {
150
        if (labelPath == null) {
151
            labelPath = new JLabel(i18nManager.getTranslation("_path"));
152
            labelPath.setToolTipText(i18nManager.getTranslation("_path"));
153
        }
154

  
155
        return labelPath;
156
    }
157

  
158
    @SuppressWarnings("unchecked")
159
    protected JComboBox getLayersComboBox() {
160
        if (layersComboBox == null) {
161
            layersComboBox = new JComboBox();
162
            layersComboBox.setRenderer(new SourceLayerComboBoxRenderer());
163
        }
164
        return layersComboBox;
165
    }
166

  
167
    private JLabel getLayersLabel() {
168
        if (layersLabel == null) {
169
            layersLabel = new JLabel(i18nManager.getTranslation("_layer"));
170
        }
171

  
172
        return layersLabel;
173
    }
174

  
175
    private JPanel getLayersPanel() {
176
        if (layersPanel == null) {
177

  
178
            layersPanel = new JPanel(new GridBagLayout());
179

  
180
            GridBagConstraints constraints = getConstraintsForLabel();
181
            layersPanel.add(getLayersLabel(), constraints);
182

  
183
            constraints = getConstraintsForCombo();
184

  
185
            layersPanel.add(getLayersComboBox(), constraints);
186
        }
187

  
188
        return layersPanel;
189
    }
190

  
191
    private JPanel getOptionsPanel() {
192
        if (optionsPanel == null) {
193
            optionsPanel = new JPanel();
194
            optionsPanel.setBorder(BorderFactory.createTitledBorder(i18nManager
195
                .getTranslation("_options")));
196
            optionsPanel.setLayout(new GridBagLayout());
197

  
198
            GridBagConstraints constraints = getConstraintsForLabel();
199
            optionsPanel.add(getProcessLabel(), constraints);
200

  
201
            constraints = getConstraintsForCombo();
202
            optionsPanel.add(getProcessCombo(), constraints);
203
        }
204

  
205
        return optionsPanel;
206
    }
207

  
208
    protected JTextField getOutputLayerName() {
209
        if (outputLayerName == null) {
210
            outputLayerName = new JTextField();
211
            outputLayerName.setEnabled(false);
212
            outputLayerName.setBackground(Color.white);
213
            outputLayerName.setToolTipText(i18nManager
214
                .getTranslation("_output_layer_name"));
215
        }
216

  
217
        return outputLayerName;
218
    }
219

  
220
    private JPanel getOutputLayerNamePanel() {
221
        if (outputLayerNamePanel == null) {
222
            outputLayerNamePanel = new JPanel();
223
            outputLayerNamePanel.setLayout(new GridBagLayout());
224

  
225
            GridBagConstraints constraints = getConstraintsForLabel();
226
            outputLayerNamePanel.add(getLabelName(), constraints);
227

  
228
            constraints = getContraintsForTextField();
229
            outputLayerNamePanel.add(getOutputLayerName(), constraints);
230
        }
231

  
232
        return outputLayerNamePanel;
233
    }
234

  
235
    protected JTextField getOutputLayerPath() {
236
        if (outputLayerPath == null) {
237
            outputLayerPath = new JTextField();
238
            outputLayerPath.setEditable(false);
239
            outputLayerPath.setBackground(Color.white);
240
            outputLayerPath.setToolTipText(i18nManager
241
                .getTranslation("_path_where_create_the_new_layer_files"));
242
        }
243

  
244
        return outputLayerPath;
245
    }
246

  
247
    private JPanel getOutputLayerTypePanel() {
248
        if (outputLayerTypePanel == null) {
249
            outputLayerTypePanel = new JPanel(new GridBagLayout());
250

  
251
            GridBagConstraints constraints = getConstraintsForLabel();
252
            outputLayerTypePanel.add(getOutputShapeTypeLabel(), constraints);
253

  
254
            constraints = getConstraintsForCombo();
255
            outputLayerTypePanel.add(getOutputShapeTypeCombo(), constraints);
256
        }
257

  
258
        return outputLayerTypePanel;
259
    }
260

  
261
    private JPanel getOutputPathPanel() {
262
        if (outputPathPanel == null) {
263
            outputPathPanel = new JPanel();
264
            outputPathPanel.setLayout(new GridBagLayout());
265

  
266
            GridBagConstraints constraints = getConstraintsForLabel();
267
            outputPathPanel.add(getLabelPath(), constraints);
268

  
269
            constraints = getContraintsForTextField();
270
            outputPathPanel.add(getOutputLayerPath(), constraints);
271

  
272
            constraints.gridwidth = 1;
273
            constraints.weightx = 0;
274
            constraints.fill = GridBagConstraints.NONE;
275
            outputPathPanel.add(getJButtonSelectPath(), constraints);
276
        }
277

  
278
        return outputPathPanel;
279
    }
280

  
281
    private JPanel getOutputProcessPanel() {
282
        if (outputProcessPanel == null) {
283
            outputProcessPanel = new JPanel();
284
            outputProcessPanel.setLayout(new GridBagLayout());
285
            outputProcessPanel
286
                .setBorder(BorderFactory.createTitledBorder(i18nManager
287
                    .getTranslation("_output_layer")));
288

  
289
            GridBagConstraints constraints = new GridBagConstraints();
290
            constraints.gridx = 0;
291
            constraints.gridy = GridBagConstraints.RELATIVE;
292
            constraints.gridwidth = 1;
293
            constraints.gridheight = 1;
294
            constraints.weightx = 1;
295
            constraints.weighty = 1;
296
            constraints.anchor = GridBagConstraints.CENTER;
297
            constraints.fill = GridBagConstraints.BOTH;
298
            constraints.insets = new Insets(4, 4, 4, 4);
299

  
300
            outputProcessPanel.add(getOutputLayerNamePanel(), constraints);
301
            outputProcessPanel.add(getOutputPathPanel(), constraints);
302
            outputProcessPanel.add(getOutputLayerTypePanel(), constraints);
303
        }
304

  
305
        return outputProcessPanel;
306
    }
307

  
308
    protected JComboBox getOutputShapeTypeCombo() {
309
        if (outputShapeTypeCombo == null) {
310
            outputShapeTypeCombo = new JComboBox();
311
            outputShapeTypeCombo.setToolTipText(i18nManager
312
                .getTranslation("_destination_layer_type"));
313
        }
314

  
315
        return outputShapeTypeCombo;
316
    }
317

  
318
    private JLabel getOutputShapeTypeLabel() {
319
        if (outputShapeTypeLabel == null) {
320
            outputShapeTypeLabel =
321
                new JLabel(i18nManager.getTranslation("_type"));
322
            outputShapeTypeLabel.setToolTipText(i18nManager
323
                .getTranslation("_type"));
324
        }
325

  
326
        return outputShapeTypeLabel;
327
    }
328

  
329
    protected JComboBox getProcessCombo() {
330
        if (outputProcessCombo == null) {
331
            outputProcessCombo = new JComboBox();
332
            outputProcessCombo.setToolTipText(i18nManager
333
                .getTranslation("_process_type"));
334
        }
335
        return outputProcessCombo;
336
    }
337

  
338
    private JLabel getProcessLabel() {
339
        if (outputProcessLabel == null) {
340
            outputProcessLabel =
341
                new JLabel(i18nManager.getTranslation("_process_type"));
342
            outputProcessLabel.setToolTipText(i18nManager
343
                .getTranslation("_process_type"));
344
        }
345

  
346
        return outputProcessLabel;
347
    }
348

  
349
    private JPanel getSourceLayerPanel() {
350
        if (sourceLayerPanel == null) {
351
            sourceLayerPanel = new JPanel();
352
            sourceLayerPanel
353
                .setBorder(BorderFactory.createTitledBorder(i18nManager
354
                    .getTranslation("_source_layer")));
355
            sourceLayerPanel.setLayout(new GridBagLayout());
356

  
357
            GridBagConstraints constraints = new GridBagConstraints();
358
            constraints.gridx = 0;
359
            constraints.gridy = 0;
360
            constraints.gridwidth = GridBagConstraints.REMAINDER;
361
            constraints.gridheight = GridBagConstraints.REMAINDER;
362
            constraints.weightx = 1;
363
            constraints.weighty = 1;
364
            constraints.anchor = GridBagConstraints.CENTER;
365
            constraints.fill = GridBagConstraints.HORIZONTAL;
366

  
367
            sourceLayerPanel.add(getLayersPanel(), constraints);
368
        }
369

  
370
        return sourceLayerPanel;
371
    }
372

  
373
    private void initilize() {
374

  
375
        setLayout(new GridBagLayout());
376

  
377
        GridBagConstraints constraints = new GridBagConstraints();
378
        constraints.gridx = 0;
379
        constraints.gridy = GridBagConstraints.RELATIVE;
380
        constraints.gridwidth = 1;
381
        constraints.gridheight = 1;
382
        constraints.weightx = 1;
383
        constraints.weighty = 1;
384
        constraints.anchor = GridBagConstraints.CENTER;
385
        constraints.fill = GridBagConstraints.BOTH;
386
        constraints.insets = new Insets(4, 4, 4, 4);
387

  
388
        add(getSourceLayerPanel(), constraints);
389
        add(getOutputProcessPanel(), constraints);
390
        add(getOptionsPanel(), constraints);
391

  
392
        setPreferredSize(new Dimension(500, 360));
393

  
394
        setVisible(true);
395
    }
396
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/SelectedFeaturesTableModel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.util.ArrayList;
26
import java.util.Collections;
27
import java.util.List;
28

  
29
import javax.swing.table.AbstractTableModel;
30

  
31
import org.gvsig.derivedgeometries.swing.api.exceptions.FormatRowException;
32
import org.gvsig.derivedgeometries.swing.api.exceptions.LoadSelectedFeatureDataException;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureReference;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.fmap.dal.feature.FeatureType;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.i18n.I18nManager;
40

  
41
public class SelectedFeaturesTableModel extends AbstractTableModel {
42

  
43
    private static final long serialVersionUID = -3905635376996886077L;
44

  
45
    private List<String[]> data = null;
46

  
47
    private String[] columnNames = null;
48

  
49
    private int rowCount = 0;
50

  
51
    private FeatureStore featureStore;
52

  
53
    // Autoincrement variable
54
    private int orderCount = 0;
55

  
56
    public SelectedFeaturesTableModel() {
57
        this.featureStore = null;
58
    }
59

  
60
    public SelectedFeaturesTableModel(FeatureStore theFeatureStore) {
61
        this.featureStore = theFeatureStore;
62
    }
63

  
64
    public void loadData(List<FeatureReference> features)
65
        throws LoadSelectedFeatureDataException {
66
        clear();
67
        List<String[]> tmpData = new ArrayList<String[]>();
68
        Feature feature = null;
69
        for (FeatureReference featureReference : features) {
70

  
71
            try {
72
                feature = featureReference.getFeature();
73
                tmpData.add(formatRow(feature));
74
            } catch (DataException e) {
75
                String message =
76
                    String.format("Error getting feature through %1 ",
77
                        featureReference);
78
                throw new LoadSelectedFeatureDataException(message, e);
79
            } catch (FormatRowException e) {
80
                String message =
81
                    String.format("Error formatting data of %1", feature);
82
                throw new LoadSelectedFeatureDataException(message, e);
83
            }
84

  
85
        }
86

  
87
        data = Collections.unmodifiableList(tmpData);
88
        rowCount = data.size();
89

  
90
        try {
91
            columnNames =
92
                getColumnNamesFromType(featureStore.getDefaultFeatureType());
93
        } catch (DataException e) {
94
            String message = String.format("Error getting feature type of %1", featureStore);
95
            throw new LoadSelectedFeatureDataException(message, e);
96
        }
97

  
98
        fireTableStructureChanged();
99
    }
100

  
101
    private String[] getColumnNamesFromType(FeatureType featureType) {
102
        int count = featureType.size();
103
        List<String> names = new ArrayList<String>();
104
        I18nManager i18nManager = ToolsLocator.getI18nManager();
105
        names.add(i18nManager.getTranslation("_Order"));
106
        for (int i = 0; i < count; i++) {
107
            names.add(featureType.getAttributeDescriptor(i).getName());
108
        }
109
        return names.toArray(new String[] {});
110
    }
111

  
112
    private String[] formatRow(Feature feature) throws FormatRowException {
113
        FeatureType featureType;
114
        try {
115
            featureType = featureStore.getDefaultFeatureType();
116
        } catch (DataException e) {
117
            String message =
118
                String.format("Error getting feature type of %1",
119
                    featureStore.getName());
120
            throw new FormatRowException(message, e);
121
        }
122
        int featureSize = featureType.size();
123
        List<String> featureData = null;
124
        if (featureSize > 0) {
125
            featureData = new ArrayList<String>();
126

  
127
            // Add Order data and autoincrement
128
            featureData.add(String.valueOf(orderCount));
129
            orderCount++;
130

  
131
            for (int i = 0; i < featureSize; i++) {
132
                featureData.add(String.valueOf(feature.get(i)));
133
            }
134
        }
135
        return featureData.toArray(new String[] {});
136
    }
137

  
138
    public int getRowCount() {
139
        return rowCount;
140
    }
141

  
142
    public int getColumnCount() {
143
        if (columnNames == null) {
144
            return 0;
145
        }
146
        return columnNames.length;
147
    }
148

  
149
    public Object getValueAt(int rowIndex, int columnIndex) {
150
        if (data == null) {
151
            return "";
152
        }
153
        return data.get(rowIndex)[columnIndex];
154
    }
155

  
156
    @Override
157
    public String getColumnName(int column) {
158
        if (columnNames == null) {
159
            return null;
160
        }
161
        return columnNames[column];
162
    }
163

  
164
    public void clear() {
165
        data = null;
166
        columnNames = null;
167
        rowCount = 0;
168
        orderCount = 0;
169
        fireTableDataChanged();
170
    }
171
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/DerivedGeometriesPanelView.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.FlowLayout;
28

  
29
import javax.swing.JButton;
30
import javax.swing.JComponent;
31
import javax.swing.JPanel;
32

  
33
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator;
34
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager;
35
import org.gvsig.derivedgeometries.swing.api.panels.FeaturesControlPanel;
36
import org.gvsig.derivedgeometries.swing.api.panels.LayerAndProcessSelectionPanel;
37
import org.gvsig.fmap.mapcontrol.MapControl;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.i18n.I18nManager;
40

  
41
public class DerivedGeometriesPanelView extends JPanel {
42

  
43
    private static final long serialVersionUID = -5574613054191988321L;
44

  
45
    private LayerAndProcessSelectionPanel layerAndProcessSelectionPanel;
46

  
47
    private FeaturesControlPanel featuresControlPanel;
48

  
49
    private JPanel buttonsPanel;
50

  
51
    private JButton nextButton;
52

  
53
    private JButton cancelButton;
54

  
55
    public DerivedGeometriesPanelView(MapControl theMapControl) {
56

  
57
        DerivedGeometriesManager manager =
58
            DerivedGeometriesLocator.getManager();
59

  
60
        this.layerAndProcessSelectionPanel =
61
            manager.getLayerAndProcessSelectionPanel(theMapControl);
62
        this.featuresControlPanel = manager.getFeaturesControlPanel();
63
        
64
        initialize();
65
    }
66

  
67
    private void initialize() {
68
        setLayout(new BorderLayout());
69
        
70
        add(layerAndProcessSelectionPanel.asJComponent(), BorderLayout.PAGE_START);
71
        
72
        add(featuresControlPanel.asJComponent(), BorderLayout.CENTER);
73
        featuresControlPanel.asJComponent().setVisible(false);
74
        
75
        add(getButtonsPanel(), BorderLayout.PAGE_END);
76
    }
77

  
78
    @Override
79
    public Dimension getPreferredSize() {
80
        JComponent c1 = layerAndProcessSelectionPanel.asJComponent();
81
        JComponent c2 = featuresControlPanel.asJComponent();
82
        
83
        int with =  (int) Math.max(c1.getPreferredSize().getWidth(), c2.getPreferredSize().getWidth()); 
84
        int height =  (int) Math.max(c1.getPreferredSize().getHeight(), c2.getPreferredSize().getHeight()); 
85
        return new Dimension(with,height);
86
    }
87
    
88
    private JPanel getButtonsPanel() {
89
        if (buttonsPanel == null) {
90
            buttonsPanel = new JPanel();
91
            buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
92
            buttonsPanel.add(getNextButton());
93
            buttonsPanel.add(getCancelButton());
94
        }
95
        return buttonsPanel;
96
    }
97

  
98
    protected JButton getCancelButton() {
99
        if (cancelButton == null) {
100
            I18nManager i18nManager = ToolsLocator.getI18nManager();
101
            cancelButton = new JButton(i18nManager.getTranslation("_cancel"));
102
        }
103
        return cancelButton;
104
    }
105

  
106
    protected JButton getNextButton() {
107
        if (nextButton == null) {
108
            I18nManager i18nManager = ToolsLocator.getI18nManager();
109
            nextButton = new JButton(i18nManager.getTranslation("_next") + " >");
110
        }
111
        return nextButton;
112
    }
113

  
114
    protected LayerAndProcessSelectionPanel getLayerAndProcessSelectionPanel() {
115
        return layerAndProcessSelectionPanel;
116
    }
117

  
118
    protected FeaturesControlPanel getFeaturesControlPanel() {
119
        return featuresControlPanel;
120
    }
121
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.58/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/DefaultDerivedGeometriesSelectionModel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.derivedgeometries.swing.impl.views;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27

  
28
import javax.swing.event.EventListenerList;
29
import javax.swing.event.ListSelectionEvent;
30
import javax.swing.event.ListSelectionListener;
31

  
32
import org.gvsig.derivedgeometries.swing.api.tablemodels.DerivedGeometriesSelectionModel;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureReference;
36
import org.gvsig.fmap.dal.feature.FeatureSelection;
37
import org.gvsig.fmap.dal.feature.FeatureSet;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.mapcontrol.dal.feature.swing.SelectionChangeException;
40
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel;
41
import org.gvsig.tools.dispose.DisposableIterator;
42

  
43
public class DefaultDerivedGeometriesSelectionModel implements
44
    DerivedGeometriesSelectionModel {
45

  
46
    protected EventListenerList listenerList = new EventListenerList();
47

  
48
    List<FeatureReference> selectedFeatures;
49

  
50
    FeatureTableModel featureTableModel;
51

  
52
    private int selectionMode = SINGLE_INTERVAL_SELECTION;
53

  
54
    private boolean isAdjusting = false;
55

  
56
    private int anchor = -1;
57

  
58
    private int lead = -1;
59

  
60
    private int currentFirst = -1;
61
    private int currentLast = -1;
62

  
63
    public DefaultDerivedGeometriesSelectionModel(
64
        FeatureTableModel theFeatureTableModel) {
65

  
66
        this.selectedFeatures = new ArrayList<FeatureReference>();
67
        this.featureTableModel = theFeatureTableModel;
68

  
69
    }
70

  
71
    public void addListSelectionListener(ListSelectionListener listener) {
72
        listenerList.add(ListSelectionListener.class, listener);
73
    }
74

  
75
    public void addSelectionInterval(int index0, int index1) {
76
        doWithSelection(new FeatureSelectionOperation() {
77

  
78
            public void doWithSelection(FeatureSelection selection, int first,
79
                int last) throws DataException {
80
                for (int i = first; i <= last; i++) {
81
                    Feature feature = getFeature(i);
82
                    if (!selection.isSelected(feature)) {
83
                        selection.select(feature);
84

  
85
                        // After add new feature reference, we have to get index
86
                        // of new feature selected within
87
                        // selectedFeatures to keep feature order
88
                        for (int j = 0; j < selectedFeatures.size(); j++) {
89
                            int index =
90
                                getIndexOfFeatureReference(selectedFeatures.get(j));
91
                            if (i < index) {
92
                                selectedFeatures.add(j, feature.getReference());
93
                                return;
94
                            }
95
                        }
96

  
97
                        // if new feature has not been added, add it at last
98
                        // position
99
                        selectedFeatures.add(feature.getReference());
100
                    }
101
                }
102
            }
103

  
104
        }, index0, index1, true);
105
    }
106

  
107
    public void clearSelection() {
108
        try {
109
            getFeatureSelection().deselectAll();
110
        } catch (DataException e) {
111
            throw new SelectionChangeException(e);
112
        }
113
        selectedFeatures.clear();
114
    }
115

  
116
    public int getAnchorSelectionIndex() {
117
        return anchor;
118
    }
119

  
120
    private interface FeatureSelectionOperation {
121

  
122
        void doWithSelection(FeatureSelection selection, int first, int last)
123
            throws DataException;
124
    }
125

  
126
    private void doWithSelection(FeatureSelectionOperation operation,
127
        int index0, int index1, boolean select) {
128
        // Set the anchor and lead
129
        anchor = index0;
130
        lead = index1;
131

  
132
        // As index0 <= index1 is no guaranteed, calculate the first and second
133
        // values
134
        int first = (index0 <= index1) ? index0 : index1;
135
        int last = (index0 <= index1) ? index1 : index0;
136

  
137
        // If the new selection is not updated don't continue
138
        if ((currentFirst == first) && (currentLast == last)) {
139
            return;
140
        }
141
        currentFirst = first;
142
        currentLast = last;
143

  
144
        FeatureSelection selection = getFeatureSelection();
145

  
146
        // Perform the selection operation into a complex notification
147
        selection.beginComplexNotification();
148
        try {
149
            // Is a full select or deselect
150
            if (first == 00 && last == featureTableModel.getRowCount() - 1) {
151
                if (!select) {
152
                    selection.deselectAll();
153
                    selectedFeatures.clear();
154
                } else {
155
                    operation.doWithSelection(selection, first, last);
156
                }
157
            } else {
158
                operation.doWithSelection(selection, first, last);
159
            }
160
        } catch (DataException e) {
161
            throw new SelectionChangeException(e);
162
        } finally {
163
            selection.endComplexNotification();
164
        }
165

  
166
        fireValueChanged(first, last, isAdjusting);
167
    }
168

  
169
    protected void fireValueChanged(int firstIndex, int lastIndex,
170
        boolean isAdjusting) {
171
        Object[] listeners = listenerList.getListenerList();
172
        ListSelectionEvent e = null;
173

  
174
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
175
            if (listeners[i] == ListSelectionListener.class) {
176
                if (e == null) {
177
                    e =
178
                        new ListSelectionEvent(this, firstIndex, lastIndex,
179
                            isAdjusting);
180
                }
181
                ((ListSelectionListener) listeners[i + 1]).valueChanged(e);
182
            }
183
        }
184
    }
185

  
186
    /**
187
     * Returns a Feature by table row position.
188
     */
189
    private Feature getFeature(int index) {
190
        return featureTableModel.getFeatureAt(index);
191
    }
192

  
193
    private FeatureSelection getFeatureSelection() {
194
        try {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff