Revision 71

View differences:

org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.5/org.gvsig.derivedgeometries.main/src/main/java/org/gvsig/derivedgeometries/main/Main.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.main;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.event.ActionEvent;
28
import java.io.File;
29

  
30
import javax.swing.AbstractAction;
31
import javax.swing.JButton;
32
import javax.swing.JComponent;
33
import javax.swing.JFrame;
34
import javax.swing.JMenu;
35
import javax.swing.JMenuBar;
36
import javax.swing.JMenuItem;
37
import javax.swing.JOptionPane;
38
import javax.swing.JToolBar;
39
import javax.swing.WindowConstants;
40

  
41
import org.cresques.cts.IProjection;
42

  
43
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator;
44
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager;
45
import org.gvsig.fmap.crs.CRSFactory;
46
import org.gvsig.fmap.dal.DALLocator;
47
import org.gvsig.fmap.dal.DataManager;
48
import org.gvsig.fmap.dal.DataStoreParameters;
49
import org.gvsig.fmap.dal.exception.InitializeException;
50
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
51
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
52
import org.gvsig.fmap.dal.feature.FeatureStore;
53
import org.gvsig.fmap.mapcontext.MapContextLocator;
54
import org.gvsig.fmap.mapcontext.MapContextManager;
55
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
56
import org.gvsig.fmap.mapcontext.layers.FLayer;
57
import org.gvsig.fmap.mapcontrol.MapControl;
58
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
59
import org.gvsig.fmap.mapcontrol.MapControlLocator;
60
import org.gvsig.fmap.mapcontrol.MapControlManager;
61
import org.gvsig.fmap.mapcontrol.tools.PanListenerImpl;
62
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior;
63
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
64
import org.gvsig.tools.swing.api.ToolsSwingLocator;
65
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
66
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
67
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
68

  
69
public class Main {
70

  
71
    final String DEFAULT_CRS_CODE = "EPSG:23030";
72

  
73
    private DerivedGeometriesManager derivedGeometriesManager;
74
    private MapControlManager mapControlManager;
75
    private DataManager dataManager;
76
    private MapContextManager mapContextManager;
77
    private WindowManager windowManager;
78

  
79
    private MapControl mapControl;
80

  
81
    private JFrame mainFrame;
82

  
83
    // Actions
84
    private AbstractAction derivedGeometries;
85

  
86
    private AbstractAction openAddLayerDialog;
87

  
88
    private AbstractAction exit;
89

  
90
    public static void main(String[] args) {
91
        new DefaultLibrariesInitializer().fullInitialize();
92
        Main main = new Main();
93
        main.doMain();
94

  
95
    }
96

  
97
    public Main() {
98
        mapControlManager = MapControlLocator.getMapControlManager();
99
        derivedGeometriesManager = DerivedGeometriesLocator.getManager();
100
        dataManager = DALLocator.getDataManager();
101
        mapContextManager = MapContextLocator.getMapContextManager();
102
        windowManager = ToolsSwingLocator.getWindowManager();
103
        mapContextManager.getSymbolManager().getSymbolPreferences()
104
            .setDefaultSymbolFillColorAleatory(true);
105

  
106
        // Register our DummyLayerOrderManger needed to add sample layer
107
        MapContextLocator
108
            .registerDefaultOrderManager(DummyLayerOrderManager.class);
109
    }
110

  
111
    private void doMain() {
112
        try {
113
            mapControl = mapControlManager.createJMapControlPanel(mapContextManager.createMapContext());
114
        } catch (MapControlCreationException e) {
115
            // TODO Auto-generated catch block
116
        }
117

  
118
        mapControl.addBehavior("pan", new MoveBehavior(new PanListenerImpl(
119
            mapControl)));
120

  
121
        mapControl.setTool("pan");
122

  
123
        IProjection defaultProjection = CRSFactory.getCRS(DEFAULT_CRS_CODE);
124
        mapControl.getViewPort().setProjection(defaultProjection);
125

  
126
        // Create JFrame to show data
127
        mainFrame = new JFrame("Editing test app");
128
        mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
129
        mainFrame.setPreferredSize(new Dimension(800, 680));
130
        mainFrame.add(mapControl, BorderLayout.CENTER);
131

  
132
        // Create actions
133
        createActions();
134

  
135
        // Create menu bar
136
        createMenu();
137

  
138
        // Create tools bar
139
        createToolBar();
140

  
141
        // Display the window.
142
        mainFrame.pack();
143
        mainFrame.setLocation(500, 0);
144
        mainFrame.setVisible(true);
145
    }
146

  
147
    private void createToolBar() {
148
        JToolBar toolBar = new JToolBar();
149

  
150
        toolBar.add(new JButton(openAddLayerDialog));
151
        toolBar.add(new JButton(derivedGeometries));
152

  
153
        mainFrame.add(toolBar, BorderLayout.PAGE_START);
154

  
155
    }
156

  
157
    private void createMenu() {
158
        // Create the menu bar.
159
        JMenuBar menuBar = new JMenuBar();
160

  
161
        // Build the menu.
162
        JMenu menuFile = new JMenu("File");
163
        menuFile.add(openAddLayerDialog);
164
        menuFile.add(new JMenuItem(exit));
165

  
166
        mainFrame.setJMenuBar(menuBar);
167

  
168
    }
169

  
170
    @SuppressWarnings("serial")
171
    private void createActions() {
172

  
173
        derivedGeometries = new AbstractAction("DerivedGeometries") {
174

  
175
            public void actionPerformed(ActionEvent e) {
176
                JComponent panel =
177
                    derivedGeometriesManager.getDerivedGeometriesPanel(
178
                        mapControl).asJComponent();
179

  
180
                windowManager.showWindow(panel, "derived_geometries",
181
                    MODE.WINDOW);
182
            }
183
        };
184

  
185
        openAddLayerDialog = new AbstractAction("Add sample layers") {
186

  
187
            public void actionPerformed(ActionEvent e) {
188
                try {
189
                    addLayer("src/main/resources/sample-cartography/puertos_andalucia.shp");
190
                    addLayer("src/main/resources/sample-cartography/hidro_andalucia.shp");
191
                    addLayer("src/main/resources/sample-cartography/Provincias andalucia.shp");
192

  
193
                    ThreadSafeDialogsManager dlgManager =
194
                        ToolsSwingLocator.getThreadSafeDialogsManager();
195

  
196
                    StringBuilder stb = new StringBuilder();
197
                    stb.append("Layer: Provincias_andalucia Type: multisurface\n");
198
                    stb.append("Layer: hidro_andalucia Type: multicurve\n");
199
                    stb.append("Layer: puertos_andalucia Type: point\n");
200

  
201
                    dlgManager.messageDialog(stb.toString(),
202
                        "Sample layers added succesfully",
203
                        JOptionPane.INFORMATION_MESSAGE);
204
                } catch (Exception e1) {
205
                    // TODO Auto-generated catch block
206
                    e1.printStackTrace();
207
                }
208
            }
209
        };
210

  
211
        exit = new AbstractAction("Exit") {
212

  
213
            public void actionPerformed(ActionEvent e) {
214
                System.exit(0);
215
            }
216
        };
217

  
218
    }
219

  
220
    public void addLayer(String shpPath) throws InitializeException,
221
        ProviderNotRegisteredException, ValidateDataParametersException,
222
        LoadLayerException {
223
        DataStoreParameters params;
224
        params = dataManager.createStoreParameters("Shape");
225

  
226
        File shpFile = new File(shpPath);
227

  
228
        params.setDynValue("shpFile", shpFile.getPath());
229
        params.setDynValue("CRS", CRSFactory.getCRS(DEFAULT_CRS_CODE));
230
        params.validate();
231

  
232
        FeatureStore store =
233
            (FeatureStore) dataManager.openStore("Shape", params);
234

  
235
        FLayer layer = mapContextManager.createLayer(store.getName(), store);
236

  
237
        mapControl.getMapContext().getLayers().addLayer(layer);
238
        mapControl.getMapContext().getLayers().setActive(true);
239
        layer.dispose();
240

  
241
    }
242

  
243
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.5/org.gvsig.derivedgeometries.main/src/main/java/org/gvsig/derivedgeometries/main/DummyLayerOrderManager.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.main;
24

  
25
import org.gvsig.fmap.mapcontext.layers.FLayer;
26
import org.gvsig.fmap.mapcontext.layers.FLayers;
27
import org.gvsig.fmap.mapcontext.layers.order.LayerOrderManager;
28
import org.gvsig.tools.persistence.PersistentState;
29
import org.gvsig.tools.persistence.exception.PersistenceException;
30

  
31

  
32
public class DummyLayerOrderManager implements LayerOrderManager{
33

  
34
    public void saveToState(PersistentState state) throws PersistenceException {
35
        // TODO Auto-generated method stub
36
        
37
    }
38

  
39
    public void loadFromState(PersistentState state)
40
        throws PersistenceException {
41
        // TODO Auto-generated method stub
42
        
43
    }
44

  
45
    public int getPosition(FLayers target, FLayer newLayer) {
46
        // TODO Auto-generated method stub
47
        return 0;
48
    }
49

  
50
    public String getName() {
51
        // TODO Auto-generated method stub
52
        return null;
53
    }
54

  
55
    public String getDescription() {
56
        // TODO Auto-generated method stub
57
        return null;
58
    }
59

  
60
    public String getCode() {
61
        // TODO Auto-generated method stub
62
        return null;
63
    }
64
    
65
    public Object clone() throws CloneNotSupportedException{
66
        return new DummyLayerOrderManager();
67
    }
68

  
69
}
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.5/org.gvsig.derivedgeometries.main/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
	<modelVersion>4.0.0</modelVersion>
3
	<parent>
4
		<groupId>org.gvsig</groupId>
5
		<artifactId>org.gvsig.derivedgeometries</artifactId>
6
		<version>1.0.5</version>
7
	</parent>
8
	<artifactId>org.gvsig.derivedgeometries.main</artifactId>
9
	<name>org.gvsig.derivedgeometries.main</name>
10

  
11
	<dependencies>
12
		<dependency>
13
			<groupId>org.gvsig</groupId>
14
			<artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
15
			<scope>compile</scope>
16
		</dependency>
17
		<dependency>
18
			<groupId>org.gvsig</groupId>
19
			<artifactId>org.gvsig.fmap.control</artifactId>
20
			<scope>compile</scope>
21
		</dependency>
22
		<dependency>
23
			<groupId>org.gvsig</groupId>
24
			<artifactId>org.gvsig.fmap.dal.api</artifactId>
25
			<scope>compile</scope>
26
		</dependency>
27
		<dependency>
28
			<groupId>org.gvsig</groupId>
29
			<artifactId>org.gvsig.fmap.geometry.api</artifactId>
30
			<scope>compile</scope>
31
		</dependency>
32
		<dependency>
33
			<groupId>org.gvsig</groupId>
34
			<artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
35
			<scope>compile</scope>
36
		</dependency>
37
		<dependency>
38
	        <groupId>org.gvsig</groupId>
39
	        <artifactId>org.gvsig.tools.swing.api</artifactId>
40
	        <scope>compile</scope>
41
        </dependency>
42

  
43
		<!-- runtime dependencies -->
44
		<dependency>
45
			<groupId>org.gvsig</groupId>
46
			<artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
47
			<scope>runtime</scope>
48
		</dependency>
49
		<dependency>
50
			<groupId>org.gvsig</groupId>
51
			<artifactId>org.gvsig.fmap.geometry.generalpath</artifactId>
52
			<scope>runtime</scope>
53
		</dependency>
54
		<dependency>
55
			<groupId>org.gvsig</groupId>
56
			<artifactId>org.gvsig.fmap.geometry.operation</artifactId>
57
			<scope>runtime</scope>
58
		</dependency>
59
		<dependency>
60
			<groupId>org.gvsig</groupId>
61
			<artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
62
			<scope>runtime</scope>
63
		</dependency>
64
		<dependency>
65
			<groupId>org.gvsig</groupId>
66
			<artifactId>org.gvsig.symbology.lib.impl</artifactId>
67
			<scope>runtime</scope>
68
		</dependency>
69
		<dependency>
70
			<groupId>org.gvsig</groupId>
71
			<artifactId>org.gvsig.fmap.dal.impl</artifactId>
72
			<scope>runtime</scope>
73
		</dependency>
74
		<dependency>
75
			<groupId>org.gvsig</groupId>
76
			<artifactId>org.gvsig.fmap.dal.spi</artifactId>
77
			<scope>runtime</scope>
78
		</dependency>
79
		<dependency>
80
			<groupId>org.gvsig</groupId>
81
			<artifactId>org.gvsig.fmap.dal.file.shp</artifactId>
82
			<scope>runtime</scope>
83
		</dependency>
84
		<dependency>
85
			<groupId>org.gvsig</groupId>
86
			<artifactId>org.gvsig.fmap.dal.file.dbf</artifactId>
87
			<scope>runtime</scope>
88
		</dependency>
89
		<dependency>
90
			<groupId>org.gvsig</groupId>
91
			<artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
92
			<scope>runtime</scope>
93
		</dependency>
94
		<dependency>
95
			<groupId>org.gvsig</groupId>
96
			<artifactId>org.gvsig.timesupport.lib.api</artifactId>
97
			<scope>runtime</scope>
98
		</dependency>
99
		<dependency>
100
			<groupId>org.gvsig</groupId>
101
			<artifactId>org.gvsig.timesupport.lib.impl</artifactId>
102
			<scope>runtime</scope>
103
		</dependency>
104
		<dependency>
105
			<groupId>org.gvsig</groupId>
106
			<artifactId>org.gvsig.tools.evaluator.sqljep</artifactId>
107
			<scope>runtime</scope>
108
		</dependency>
109
		<dependency>
110
			<groupId>org.gvsig</groupId>
111
			<artifactId>org.gvsig.proj.lib.proj4j</artifactId>
112
			<scope>runtime</scope>
113
		</dependency>
114
		<dependency>
115
			<groupId>org.gvsig</groupId>
116
			<artifactId>
117
				org.gvsig.derivedgeometries.swing.api
118
			</artifactId>
119
		</dependency>
120
		<dependency>
121
			<groupId>org.gvsig</groupId>
122
			<artifactId>
123
				org.gvsig.derivedgeometries.swing.impl
124
			</artifactId>
125
		</dependency>
126
		<dependency>
127
	        <groupId>org.gvsig</groupId>
128
	        <artifactId>org.gvsig.tools.swing.impl</artifactId>
129
        <scope>runtime</scope>
130
    </dependency>
131
	</dependencies>
132
</project>
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.5/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.editing.EditingNotification;
33
import org.gvsig.editing.EditingNotificationManager;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.DataServerExplorer;
37
import org.gvsig.fmap.dal.DataServerExplorerParameters;
38
import org.gvsig.fmap.dal.DataStoreParameters;
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.geom.DataTypes;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.GeometryLocator;
50
import org.gvsig.fmap.geom.GeometryManager;
51
import org.gvsig.fmap.geom.primitive.Point;
52
import org.gvsig.fmap.geom.primitive.Surface;
53
import org.gvsig.fmap.geom.type.GeometryType;
54
import org.gvsig.fmap.mapcontext.MapContextLocator;
55
import org.gvsig.fmap.mapcontext.MapContextManager;
56
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
57
import org.gvsig.fmap.mapcontrol.MapControlLocator;
58
import org.gvsig.tools.task.AbstractMonitorableTask;
59

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

  
63
    private DerivedGeometriesParameters parameters;
64

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

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

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

  
88
        return newLayer.getFeatureStore();
89
    }
90

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

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

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

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

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

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

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

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

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

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

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

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

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

  
164
        EditingNotificationManager editingNotificationManager =
165
            MapControlLocator.getEditingNotificationManager();
166

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

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

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

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

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

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

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

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

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

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

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

  
224
    }
225

  
226
    private boolean isClosed(Surface surface) {
227

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

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

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

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

  
254
        featureStore.edit();
255

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

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

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

Also available in: Unified diff