Revision 1317

View differences:

org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/DefaultDerivedGeometriesManager.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;
24

  
25
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager;
26
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters;
27
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess;
28
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess.TYPE;
29
import org.gvsig.derivedgeometries.swing.api.panels.DerivedGeometriesPanel;
30
import org.gvsig.derivedgeometries.swing.api.panels.FeaturesControlPanel;
31
import org.gvsig.derivedgeometries.swing.api.panels.LayerAndProcessSelectionPanel;
32
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultDerivedGeometriesPanel;
33
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultFeaturesControlPanel;
34
import org.gvsig.derivedgeometries.swing.impl.panels.DefaultLayerAndProcessSelectionPanel;
35
import org.gvsig.derivedgeometries.swing.impl.processes.LineToClosedPolylineDerivedGeometriesProcess;
36
import org.gvsig.derivedgeometries.swing.impl.processes.PointToLineDerivedGeometriesProcess;
37
import org.gvsig.derivedgeometries.swing.impl.processes.PointToPolygonDerivedGeometriesProcess;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.fmap.mapcontrol.MapControl;
40

  
41
public class DefaultDerivedGeometriesManager implements
42
    DerivedGeometriesManager {
43

  
44
    public DerivedGeometriesParameters createDerivedGeometriesParameters(
45
        MapControl mapControl, FLyrVect sourceLayer, String outputLayerName,
46
        String outputLayerPath, int outputLayerType, TYPE processType) {
47

  
48
        return new DefaultDerivedGeometriesParameters(mapControl, sourceLayer,
49
            outputLayerName, outputLayerPath, outputLayerType, processType);
50
    }
51

  
52
    public DerivedGeometriesParameters createDerivedGeometriesParameters() {
53
        return new DefaultDerivedGeometriesParameters();
54
    }
55

  
56
    public LayerAndProcessSelectionPanel getLayerAndProcessSelectionPanel(
57
        MapControl mapControl) {
58
        return new DefaultLayerAndProcessSelectionPanel(mapControl);
59
    }
60

  
61
    public FeaturesControlPanel getFeaturesControlPanel() {
62
        return new DefaultFeaturesControlPanel();
63
    }
64

  
65
    public DerivedGeometriesPanel getDerivedGeometriesPanel(
66
        MapControl mapControl) {
67
        return new DefaultDerivedGeometriesPanel(mapControl);
68
    }
69

  
70
    public void startDerivedGeometriesProcess(
71
        DerivedGeometriesParameters parameters) {
72
        TYPE processType = parameters.getProcessType();
73
        DerivedGeometriesProcess newProcess = null;
74

  
75
        switch (processType) {
76
        case POINTS_TO_LINE:
77
            newProcess = new PointToLineDerivedGeometriesProcess(parameters);
78
            break;
79
        case POINTS_TO_POLYGON:
80
            newProcess = new PointToPolygonDerivedGeometriesProcess(parameters);
81
            break;
82
        case LINES_TO_CLOSED_POLYLINE:
83
            newProcess =
84
                new LineToClosedPolylineDerivedGeometriesProcess(parameters);
85
            break;
86
        default:
87
            break;
88
        }
89

  
90
        newProcess.start();
91

  
92
    }
93
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/processes/PointToLineDerivedGeometriesProcess.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.processes;
24

  
25
import java.util.List;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.cresques.cts.IProjection;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters;
34
import org.gvsig.derivedgeometries.swing.impl.AbstractDerivedGeometriesProcess;
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.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.primitive.Line;
42
import org.gvsig.fmap.geom.primitive.Point;
43
import org.gvsig.fmap.geom.type.GeometryType;
44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
47
import org.gvsig.tools.task.SimpleTaskStatus;
48

  
49
public class PointToLineDerivedGeometriesProcess extends
50
    AbstractDerivedGeometriesProcess {
51

  
52
    private static final Logger logger = LoggerFactory
53
        .getLogger(PointToLineDerivedGeometriesProcess.class);
54

  
55
    public PointToLineDerivedGeometriesProcess(
56
        DerivedGeometriesParameters parameters) {
57
        super("Point to line process", parameters);
58
    }
59

  
60
    public void run() {
61
        SimpleTaskStatus status = null;
62

  
63
        try {
64
            status = (SimpleTaskStatus) this.getTaskStatus();
65

  
66
            if (status.isCancellationRequested()) {
67

  
68
                status.cancel();
69
                return;
70
            }
71

  
72
            // Get data process
73
            DerivedGeometriesParameters parameters = super.getParameters();
74
            String outputLayerName = parameters.getOutPutLayerName();
75
            String outputLayerPath = parameters.getOutPutLayerPath();
76
            int outputLayerType = parameters.getOutPutLayerType();
77
            boolean addLayer = parameters.getAddLayer();
78
            boolean createNewFeatureStore =
79
                parameters.getCreateNewFeatureStore();
80
            FLyrVect sourceLayer = parameters.getSourceLayer();
81
            IProjection projection = sourceLayer.getProjection();
82
            FeatureType sourceFeatureType =
83
                sourceLayer.getFeatureStore().getDefaultFeatureType();
84
            List<FeatureReference> selectedFeatures =
85
                parameters.getSelectedFeatures();
86

  
87
            GeometryManager geomManager = GeometryLocator.getGeometryManager();
88
            GeometryType sourceGeomType =
89
                sourceLayer.getFeatureStore().getDefaultFeatureType()
90
                    .getDefaultGeometryAttribute().getGeomType();
91
            Line line = geomManager.createLine(sourceGeomType.getSubType());
92

  
93
            status.setRangeOfValues(1, selectedFeatures.size());
94

  
95
            // Iterate over features getting geometries to create polygon
96
            for (int i = 0; i < selectedFeatures.size(); i++) {
97

  
98
                // Si ha sido solicitada la cancelacion de la tarea
99
                // la marcamos como cancelada y salimos del proceso.
100
                if (status.isCancellationRequested()) {
101
                    status.cancel();
102
                    return;
103
                }
104

  
105
                // Informamos del progreso de la tarea
106
                status.setCurValue(i);
107

  
108
                FeatureReference featureReference = selectedFeatures.get(i);
109
                Geometry geom =
110
                    featureReference.getFeature().getDefaultGeometry();
111
                line.addVertex((Point) geom);
112

  
113
            }
114

  
115
            if (status.isCancellationRequested()) {
116
                status.cancel();
117

  
118
                return;
119
            }
120

  
121
            if (createNewFeatureStore) {
122
                // Creating new feature store
123
                createNewFeatureStore(sourceFeatureType, outputLayerType,
124
                    outputLayerPath, projection);
125

  
126
                // Set createNewFeatureStore false to avoid create new feature
127
                // if process is started again
128
                parameters.setCreateNewFeatureStore(false);
129
            }
130

  
131
            // Open the new feature store
132
            FeatureStore featureStore = parameters.getFeatureStore();
133
            if (featureStore == null) {
134
                featureStore = getFeatureStore(outputLayerPath, projection);
135
            }
136

  
137
            // Set feature store in edit mode
138
            setEditingMode(featureStore);
139

  
140
            // Add line
141
            insertGeometryIntoFeauteStore(featureStore, line);
142

  
143
            // Save changes and finish editing
144
            endEditingMode(featureStore);
145

  
146
            if (status.isCancellationRequested()) {
147
                status.cancel();
148

  
149
                return;
150
            }
151

  
152
            if (addLayer) {
153
                // Dispose feature store to liberate resources
154
                featureStore.dispose();
155

  
156
                // Add layer to MapControl
157
                featureStore =
158
                    addLayerToMapContex(outputLayerName, outputLayerPath,
159
                        projection);
160
                parameters.setAddLayer(false);
161
                parameters.setFeatureStore(featureStore);
162
            }
163

  
164
            this.postProcess();
165

  
166
        } catch (Exception e) {
167
            ThreadSafeDialogsManager dlgManager =
168
                ToolsSwingLocator.getThreadSafeDialogsManager();
169

  
170
            dlgManager.messageDialog("_process_error", "_error",
171
                JOptionPane.ERROR_MESSAGE);
172

  
173
            logger.info("Error in point to line process", e);
174
            if (status != null) {
175
                status.abort();
176
            }
177

  
178
        } finally {
179
            if (status != null) {
180
                // Mark process as terminate if it is running.
181
                if (status.isRunning()) {
182
                    status.terminate();
183
                }
184
            }
185
        }
186
    }
187

  
188
    private void postProcess() {
189

  
190
        ThreadSafeDialogsManager dlgManager =
191
            ToolsSwingLocator.getThreadSafeDialogsManager();
192

  
193
        String message = "_process_finished_successfully";
194
        String title = "_information";
195
        dlgManager.messageDialog(message, title,
196
            JOptionPane.INFORMATION_MESSAGE);
197

  
198
        // Repaint mapContext to view new derived geometries added.
199
        getParameters().getMapControl().getMapContext().invalidate();
200
    }
201

  
202
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/processes/PointToPolygonDerivedGeometriesProcess.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.processes;
24

  
25
import java.util.List;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.cresques.cts.IProjection;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters;
34
import org.gvsig.derivedgeometries.swing.impl.AbstractDerivedGeometriesProcess;
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.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.primitive.Point;
42
import org.gvsig.fmap.geom.primitive.Polygon;
43
import org.gvsig.fmap.geom.type.GeometryType;
44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
47
import org.gvsig.tools.task.SimpleTaskStatus;
48

  
49
public class PointToPolygonDerivedGeometriesProcess extends
50
    AbstractDerivedGeometriesProcess {
51

  
52
    private static final Logger logger = LoggerFactory
53
        .getLogger(PointToPolygonDerivedGeometriesProcess.class);
54

  
55
    public PointToPolygonDerivedGeometriesProcess(
56
        DerivedGeometriesParameters parameters) {
57
        super("Point to polygon process", parameters);
58
    }
59

  
60
    public void run() {
61
        SimpleTaskStatus status = null;
62

  
63
        try {
64
            status = (SimpleTaskStatus) this.getTaskStatus();
65

  
66
            if (status.isCancellationRequested()) {
67

  
68
                status.cancel();
69
                return;
70
            }
71

  
72
            // Get data process
73
            DerivedGeometriesParameters parameters = super.getParameters();
74
            String outputLayerName = parameters.getOutPutLayerName();
75
            String outputLayerPath = parameters.getOutPutLayerPath();
76
            int outputLayerType = parameters.getOutPutLayerType();
77
            boolean addLayer = parameters.getAddLayer();
78
            boolean createNewFeatureStore =
79
                parameters.getCreateNewFeatureStore();
80
            FLyrVect sourceLayer = parameters.getSourceLayer();
81
            IProjection projection = sourceLayer.getProjection();
82
            FeatureType sourceFeatureType =
83
                sourceLayer.getFeatureStore().getDefaultFeatureType();
84
            List<FeatureReference> selectedFeatures =
85
                parameters.getSelectedFeatures();
86

  
87
            GeometryManager geomManager = GeometryLocator.getGeometryManager();
88
            GeometryType sourceGeomType =
89
                sourceLayer.getFeatureStore().getDefaultFeatureType()
90
                    .getDefaultGeometryAttribute().getGeomType();
91
            Polygon polygon =
92
                geomManager.createPolygon(sourceGeomType.getSubType());
93
            Point vertexAnt = null;
94

  
95
            status.setRangeOfValues(1, selectedFeatures.size());
96

  
97
            // Iterate over features getting geometries to create polygon
98
            for (int i = 0; i < selectedFeatures.size(); i++) {
99

  
100
                // Si ha sido solicitada la cancelacion de la tarea
101
                // la marcamos como cancelada y salimos del proceso.
102
                if (status.isCancellationRequested()) {
103

  
104
                    status.cancel();
105
                    return;
106
                }
107

  
108
                // Informamos del progreso de la tarea
109
                status.setCurValue(i);
110

  
111
                FeatureReference featureReference = selectedFeatures.get(i);
112
                Geometry point =
113
                    featureReference.getFeature().getDefaultGeometry();
114

  
115
                if (vertexAnt == null || !vertexAnt.equals(point)) {
116
                    polygon.addVertex((Point) point);
117
                    vertexAnt = (Point) point;
118

  
119
                }
120

  
121
            }
122

  
123
            // Close polygon if it is necessary
124
            closeSurfaceIfNecessary(polygon);
125

  
126
            if (status.isCancellationRequested()) {
127
                status.cancel();
128

  
129
                return;
130
            }
131

  
132
            if (createNewFeatureStore) {
133
                // Creating new feature store
134
                createNewFeatureStore(sourceFeatureType, outputLayerType,
135
                    outputLayerPath, projection);
136

  
137
                // Set createNewFeatureStore false to avoid create new feature
138
                // if process is started again
139
                parameters.setCreateNewFeatureStore(false);
140
            }
141

  
142
            // Open the new feature store
143
            FeatureStore featureStore = parameters.getFeatureStore();
144
            if (featureStore == null) {
145
                featureStore = getFeatureStore(outputLayerPath, projection);
146
            }
147

  
148
            // Set feature store in edit mode
149
            setEditingMode(featureStore);
150

  
151
            // Add line
152
            insertGeometryIntoFeauteStore(featureStore, polygon);
153

  
154
            // Save changes and finish editing
155
            endEditingMode(featureStore);
156

  
157
            if (status.isCancellationRequested()) {
158
                status.cancel();
159

  
160
                return;
161
            }
162

  
163
            if (addLayer) {
164
                // Dispose feature store to liberate resources
165
                featureStore.dispose();
166

  
167
                // Add layer to MapControl
168
                featureStore =
169
                    addLayerToMapContex(outputLayerName, outputLayerPath,
170
                        projection);
171
                parameters.setAddLayer(false);
172
                parameters.setFeatureStore(featureStore);
173
            }
174

  
175
            this.postProcess();
176

  
177
        } catch (Exception e) {
178
            ThreadSafeDialogsManager dlgManager =
179
                ToolsSwingLocator.getThreadSafeDialogsManager();
180

  
181
            dlgManager.messageDialog("_process_error", "_error",
182
                JOptionPane.ERROR_MESSAGE);
183

  
184
            logger.info("Error in point to polygon process", e);
185
            if (status != null) {
186
                status.abort();
187
            }
188

  
189
        } finally {
190
            if (status != null) {
191
                // Mark process as terminate if it is running.
192
                if (status.isRunning()) {
193
                    status.terminate();
194
                }
195
            }
196
        }
197
    }
198

  
199
    private void postProcess() {
200

  
201
        ThreadSafeDialogsManager dlgManager =
202
            ToolsSwingLocator.getThreadSafeDialogsManager();
203

  
204
        String message = "_process_finished_successfully";
205
        String title = "_information";
206
        dlgManager.messageDialog(message, title,
207
            JOptionPane.INFORMATION_MESSAGE);
208

  
209
        // Repaint mapContext to view new derived geometries added.
210
        getParameters().getMapControl().getMapContext().invalidate();
211
    }
212
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/processes/LineToClosedPolylineDerivedGeometriesProcess.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.processes;
24

  
25
import java.util.List;
26

  
27
import javax.swing.JOptionPane;
28

  
29
import org.cresques.cts.IProjection;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters;
34
import org.gvsig.derivedgeometries.swing.impl.AbstractDerivedGeometriesProcess;
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.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.primitive.Curve;
42
import org.gvsig.fmap.geom.primitive.Point;
43
import org.gvsig.fmap.geom.primitive.Polygon;
44
import org.gvsig.fmap.geom.type.GeometryType;
45
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
47
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
48
import org.gvsig.tools.task.SimpleTaskStatus;
49

  
50
public class LineToClosedPolylineDerivedGeometriesProcess extends
51
    AbstractDerivedGeometriesProcess {
52

  
53
    private static final Logger logger = LoggerFactory
54
        .getLogger(LineToClosedPolylineDerivedGeometriesProcess.class);
55

  
56
    public LineToClosedPolylineDerivedGeometriesProcess(
57
        DerivedGeometriesParameters parameters) {
58
        super("Line to polyline process", parameters);
59
    }
60

  
61
    public void run() {
62
        SimpleTaskStatus status = null;
63

  
64
        try {
65
            status = (SimpleTaskStatus) this.getTaskStatus();
66

  
67
            if (status.isCancellationRequested()) {
68

  
69
                status.cancel();
70
                return;
71
            }
72

  
73
            // Get data process
74
            DerivedGeometriesParameters parameters = super.getParameters();
75
            String outputLayerName = parameters.getOutPutLayerName();
76
            String outputLayerPath = parameters.getOutPutLayerPath();
77
            int outputLayerType = parameters.getOutPutLayerType();
78
            boolean addLayer = parameters.getAddLayer();
79
            boolean createNewFeatureStore =
80
                parameters.getCreateNewFeatureStore();
81
            FLyrVect sourceLayer = parameters.getSourceLayer();
82
            IProjection projection = sourceLayer.getProjection();
83
            FeatureType sourceFeatureType =
84
                sourceLayer.getFeatureStore().getDefaultFeatureType();
85
            List<FeatureReference> selectedFeatures =
86
                parameters.getSelectedFeatures();
87

  
88
            GeometryManager geomManager = GeometryLocator.getGeometryManager();
89
            GeometryType sourceGeomType =
90
                sourceLayer.getFeatureStore().getDefaultFeatureType()
91
                    .getDefaultGeometryAttribute().getGeomType();
92
            Polygon polygon =
93
                geomManager.createPolygon(sourceGeomType.getSubType());
94
            Point vertexAnt = null;
95

  
96
            status.setRangeOfValues(1, selectedFeatures.size());
97

  
98
            // Iterate over features getting geometries to create polygon
99
            for (int i = 0; i < selectedFeatures.size(); i++) {
100

  
101
                // Si ha sido solicitada la cancelacion de la tarea
102
                // la marcamos como cancelada y salimos del proceso.
103
                if (status.isCancellationRequested()) {
104

  
105
                    status.cancel();
106
                    return;
107
                }
108

  
109
                // Informamos del progreso de la tarea
110
                status.setCurValue(i);
111

  
112
                FeatureReference featureReference = selectedFeatures.get(i);
113
                Geometry geom =
114
                    featureReference.getFeature().getDefaultGeometry();
115
                for (int j = 0; j < ((Curve) geom).getNumVertices(); j++) {
116
                    Point point = ((Curve) geom).getVertex(j);
117

  
118
                    if (vertexAnt == null || !vertexAnt.equals(point)) {
119
                        polygon.addVertex(point);
120
                        vertexAnt = point;
121
                    }
122

  
123
                }
124

  
125
            }
126

  
127
            // Close polygon if it is necessary
128
            closeSurfaceIfNecessary(polygon);
129

  
130
            if (status.isCancellationRequested()) {
131
                status.cancel();
132

  
133
                return;
134
            }
135

  
136
            if (createNewFeatureStore) {
137
                // Creating new feature store
138
                createNewFeatureStore(sourceFeatureType, outputLayerType,
139
                    outputLayerPath, projection);
140

  
141
                // Set createNewFeatureStore false to avoid create new feature
142
                // if process is started again
143
                parameters.setCreateNewFeatureStore(false);
144
            }
145

  
146
            // Open the new feature store
147
            FeatureStore featureStore = parameters.getFeatureStore();
148
            if (featureStore == null) {
149
                featureStore = getFeatureStore(outputLayerPath, projection);
150
            }
151

  
152
            // Set feature store in edit mode
153
            setEditingMode(featureStore);
154

  
155
            // Add line
156
            insertGeometryIntoFeauteStore(featureStore, polygon);
157

  
158
            // Save changes and finish editing
159
            endEditingMode(featureStore);
160

  
161
            if (status.isCancellationRequested()) {
162
                status.cancel();
163

  
164
                return;
165
            }
166

  
167
            if (addLayer) {
168
                // Dispose feature store to liberate resources
169
                featureStore.dispose();
170

  
171
                // Add layer to MapControl
172
                featureStore =
173
                    addLayerToMapContex(outputLayerName, outputLayerPath,
174
                        projection);
175
                parameters.setAddLayer(false);
176
                parameters.setFeatureStore(featureStore);
177
            }
178

  
179
            this.postProcess();
180

  
181
        } catch (Exception e) {
182
            ThreadSafeDialogsManager dlgManager =
183
                ToolsSwingLocator.getThreadSafeDialogsManager();
184

  
185
            dlgManager.messageDialog("_process_error", "_error",
186
                JOptionPane.ERROR_MESSAGE);
187

  
188
            logger.info("Error in line to closed process", e);
189
            if (status != null) {
190
                status.abort();
191
            }
192

  
193
        } finally {
194
            if (status != null) {
195
                // Mark process as terminate if it is running.
196
                if (status.isRunning()) {
197
                    status.terminate();
198
                }
199
            }
200
        }
201
    }
202

  
203
    private void postProcess() {
204

  
205
        ThreadSafeDialogsManager dlgManager =
206
            ToolsSwingLocator.getThreadSafeDialogsManager();
207

  
208
        String message = "_process_finished_successfully";
209
        String title = "_information";
210
        dlgManager.messageDialog(message, title,
211
            JOptionPane.INFORMATION_MESSAGE);
212

  
213
        // Repaint mapContext to view new derived geometries added.
214
        getParameters().getMapControl().getMapContext().invalidate();
215
    }
216

  
217
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/AbstractDerivedGeometriesProcess.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;
24

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

  
28
import org.cresques.cts.IProjection;
29

  
30
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesParameters;
31
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesProcess;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34
import org.gvsig.fmap.dal.DataServerExplorer;
35
import org.gvsig.fmap.dal.DataServerExplorerParameters;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.EditingNotification;
38
import org.gvsig.fmap.dal.EditingNotificationManager;
39
import org.gvsig.fmap.dal.feature.EditableFeature;
40
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
41
import org.gvsig.fmap.dal.feature.EditableFeatureType;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
43
import org.gvsig.fmap.dal.feature.FeatureReference;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureType;
46
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
47
import org.gvsig.fmap.dal.swing.DALSwingLocator;
48
import org.gvsig.fmap.geom.DataTypes;
49
import org.gvsig.fmap.geom.Geometry;
50
import org.gvsig.fmap.geom.GeometryLocator;
51
import org.gvsig.fmap.geom.GeometryManager;
52
import org.gvsig.fmap.geom.primitive.Point;
53
import org.gvsig.fmap.geom.primitive.Surface;
54
import org.gvsig.fmap.geom.type.GeometryType;
55
import org.gvsig.fmap.mapcontext.MapContextLocator;
56
import org.gvsig.fmap.mapcontext.MapContextManager;
57
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
58
import org.gvsig.fmap.mapcontrol.MapControlLocator;
59
import org.gvsig.tools.task.AbstractMonitorableTask;
60

  
61
public abstract class AbstractDerivedGeometriesProcess extends
62
    AbstractMonitorableTask implements DerivedGeometriesProcess {
63

  
64
    private DerivedGeometriesParameters parameters;
65

  
66
    public AbstractDerivedGeometriesProcess(String name,
67
        DerivedGeometriesParameters parameters) {
68
        super(name);
69
        this.parameters = parameters;
70
    }
71

  
72
    protected FeatureStore addLayerToMapContex(String name, String path,
73
        IProjection projection) throws Exception {
74
        DataManager dataManager = DALLocator.getDataManager();
75
        MapContextManager mapContextManager =
76
            MapContextLocator.getMapContextManager();
77
        DataStoreParameters dataStoreParams =
78
            dataManager.createStoreParameters("Shape");
79
        dataStoreParams.setDynValue("shpfile", path);
80
        dataStoreParams.setDynValue("CRS", projection);
81
        dataStoreParams.setDynValue("useNullGeometry", false);
82
        dataStoreParams.validate();
83

  
84
        FLyrVect newLayer =
85
            (FLyrVect) mapContextManager.createLayer(name, dataStoreParams);
86
        getParameters().getMapControl().getMapContext().getLayers()
87
            .addLayer(newLayer);
88

  
89
        return newLayer.getFeatureStore();
90
    }
91

  
92
    protected Surface closeSurfaceIfNecessary(Surface surface) {
93
        if (!isClosed(surface) && surface != null) {
94
            Point firstp = surface.getVertex(0);
95
            firstp = (Point) firstp.cloneGeometry();
96
            surface.addVertex(firstp);
97
        }
98
        return surface;
99
    }
100

  
101
    protected void createNewFeatureStore(FeatureType sourceFeatureType,
102
        int outputLayerType, String outputLayerPath, IProjection projection)
103
        throws Exception {
104

  
105
        DataManager dataManager = DALLocator.getDataManager();
106
        DataServerExplorerParameters eparams =
107
            dataManager.createServerExplorerParameters("FilesystemExplorer");
108
        eparams.setDynValue("initialpath", "/data");
109
        DataServerExplorer serverExplorer =
110
            dataManager.openServerExplorer(eparams.getExplorerName(), eparams);
111

  
112
        NewFeatureStoreParameters sparams =
113
            (NewFeatureStoreParameters) serverExplorer
114
                .getAddParameters("Shape");
115

  
116
        EditableFeatureType newEditableFeatureType =
117
            (EditableFeatureType) sparams.getDefaultFeatureType();
118

  
119
        // Iterate over feature type. Don't add geometry fields.
120
        for (int i = 0; i < sourceFeatureType.size(); i++) {
121
            String fieldName =
122
                sourceFeatureType.getAttributeDescriptor(i).getName();
123
            int fieldType =
124
                sourceFeatureType.getAttributeDescriptor(i).getType();
125
            if (fieldType != DataTypes.GEOMETRY) {
126
                newEditableFeatureType.add(fieldName, fieldType);
127
            }
128
        }
129

  
130
        // Add new geometry field with new geometry type
131
        FeatureAttributeDescriptor geometryAttribute =
132
            (FeatureAttributeDescriptor) sourceFeatureType
133
                .get(sourceFeatureType.getDefaultGeometryAttributeName());
134
        EditableFeatureAttributeDescriptor newGeometryAttribute =
135
            newEditableFeatureType.add(geometryAttribute.getName(),
136
                geometryAttribute.getType(), geometryAttribute.getSize());
137

  
138
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
139
        GeometryType sourceLayerGeomType =
140
            sourceFeatureType.getDefaultGeometryAttribute().getGeomType();
141
        GeometryType outputLayerGeomType =
142
            geoManager.getGeometryType(outputLayerType,
143
                sourceLayerGeomType.getSubType());
144

  
145
        newGeometryAttribute.setGeometryType(outputLayerGeomType);
146
        newGeometryAttribute.setPrecision(geometryAttribute.getPrecision());
147
        newGeometryAttribute.setDefaultValue(geometryAttribute
148
            .getDefaultValue());
149

  
150
        newEditableFeatureType
151
            .setDefaultGeometryAttributeName(geometryAttribute.getName());
152

  
153
        sparams.setDynValue("geometryType", null);
154
        sparams.setDynValue("shpfile", outputLayerPath);
155
        sparams.setDynValue("CRS", projection);
156
        sparams.setDynValue("useNullGeometry", false);
157
        sparams.setDefaultFeatureType(newEditableFeatureType);
158
        sparams.validate();
159

  
160
        serverExplorer.add("Shape", sparams, true);
161
    }
162

  
163
    protected void endEditingMode(FeatureStore featureStore) throws Exception {
164

  
165
        EditingNotificationManager editingNotificationManager =
166
            DALSwingLocator.getEditingNotificationManager();
167

  
168
        EditingNotification notification =
169
            editingNotificationManager.notifyObservers(this,
170
                EditingNotification.BEFORE_EXIT_EDITING_STORE, null,
171
                featureStore);
172

  
173
        if (notification.isCanceled()) {
174
            String message =
175
                String.format(
176
                    "FinishEditing of %1 has been canceled by some observer",
177
                    featureStore.getName());
178
            throw new InterruptedException(message);
179
        }
180

  
181
        getParameters().getMapControl().getCanceldraw().setCanceled(true);
182

  
183
        featureStore.finishEditing();
184
        featureStore.deleteObserver(parameters.getMapControl());
185

  
186
        editingNotificationManager.notifyObservers(this,
187
            EditingNotification.AFTER_EXIT_EDITING_STORE, null, featureStore);
188
    }
189

  
190
    protected FeatureStore getFeatureStore(String outputLayerPath,
191
        IProjection projection) throws Exception {
192

  
193
        DataManager dataManager = DALLocator.getDataManager();
194
        DataStoreParameters dataStoreParams =
195
            dataManager.createStoreParameters("Shape");
196
        dataStoreParams.setDynValue("shpfile", outputLayerPath);
197
        dataStoreParams.setDynValue("CRS", projection);
198
        dataStoreParams.setDynValue("useNullGeometry", false);
199
        dataStoreParams.validate();
200

  
201
        return (FeatureStore) dataManager.openStore("Shape", dataStoreParams);
202
    }
203

  
204
    protected List<Geometry> getGeometries(
205
        List<FeatureReference> selectedFeatures) throws Exception {
206
        List<Geometry> geometries = new ArrayList<Geometry>();
207
        for (FeatureReference featureReference : selectedFeatures) {
208
            Geometry geom = featureReference.getFeature().getDefaultGeometry();
209
            geometries.add(geom);
210
        }
211
        return geometries;
212
    }
213

  
214
    public DerivedGeometriesParameters getParameters() {
215
        return this.parameters;
216
    }
217

  
218
    protected void insertGeometryIntoFeauteStore(FeatureStore newFeatureStore,
219
        Geometry geometry) throws Exception {
220
        EditableFeature eFeature = newFeatureStore.createNewFeature(true);
221
        eFeature.setGeometry(newFeatureStore.getDefaultFeatureType()
222
            .getDefaultGeometryAttributeName(), geometry);
223
        newFeatureStore.insert(eFeature);
224

  
225
    }
226

  
227
    private boolean isClosed(Surface surface) {
228

  
229
        if (surface != null) {
230
            Point firstPoint = surface.getVertex(0);
231
            Point lastPoint = surface.getVertex(surface.getNumVertices() - 1);
232
            if (firstPoint.equals(lastPoint)) {
233
                return true;
234
            }
235
        }
236
        return false;
237
    }
238

  
239
    protected void setEditingMode(FeatureStore featureStore) throws Exception {
240
        EditingNotificationManager editingNotificationManager =
241
            DALSwingLocator.getEditingNotificationManager();
242

  
243
        EditingNotification notification =
244
            editingNotificationManager.notifyObservers(this,
245
                EditingNotification.BEFORE_ENTER_EDITING_STORE, null,
246
                featureStore);
247

  
248
        if (notification.isCanceled()) {
249
            String message =
250
                String.format("Edit of %1 has been canceled by some observer",
251
                    featureStore.getName());
252
            throw new InterruptedException(message);
253
        }
254

  
255
        featureStore.edit();
256

  
257
        featureStore.addObserver(parameters.getMapControl());
258

  
259
        editingNotificationManager.notifyObservers(this,
260
            EditingNotification.AFTER_ENTER_EDITING_STORE, null, featureStore);
261
    }
262

  
263
    public void setParameters(DerivedGeometriesParameters theParameters) {
264
        this.parameters = theParameters;
265
    }
266
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.253/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
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff