Revision 134
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.17/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.17/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.17/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.17</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 |
<!-- |
|
50 |
<dependency> |
|
51 |
<groupId>org.gvsig</groupId> |
|
52 |
<artifactId>org.gvsig.fmap.geometry.generalpath</artifactId> |
|
53 |
<scope>runtime</scope> |
|
54 |
</dependency> |
|
55 |
<dependency> |
|
56 |
<groupId>org.gvsig</groupId> |
|
57 |
<artifactId>org.gvsig.fmap.geometry.operation</artifactId> |
|
58 |
<scope>runtime</scope> |
|
59 |
</dependency> |
|
60 |
--> |
|
61 |
<dependency> |
|
62 |
<groupId>org.gvsig</groupId> |
|
63 |
<artifactId>org.gvsig.fmap.mapcontext.impl</artifactId> |
|
64 |
<scope>runtime</scope> |
|
65 |
</dependency> |
|
66 |
<dependency> |
|
67 |
<groupId>org.gvsig</groupId> |
|
68 |
<artifactId>org.gvsig.symbology.lib.impl</artifactId> |
|
69 |
<scope>runtime</scope> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>org.gvsig</groupId> |
|
73 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
74 |
<scope>runtime</scope> |
|
75 |
</dependency> |
|
76 |
<dependency> |
|
77 |
<groupId>org.gvsig</groupId> |
|
78 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
79 |
<scope>runtime</scope> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.gvsig</groupId> |
|
83 |
<artifactId>org.gvsig.fmap.dal.file.shp</artifactId> |
|
84 |
<scope>runtime</scope> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>org.gvsig</groupId> |
|
88 |
<artifactId>org.gvsig.fmap.dal.file.dbf</artifactId> |
|
89 |
<scope>runtime</scope> |
|
90 |
</dependency> |
|
91 |
<dependency> |
|
92 |
<groupId>org.gvsig</groupId> |
|
93 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
94 |
<scope>runtime</scope> |
|
95 |
</dependency> |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
99 |
<scope>runtime</scope> |
|
100 |
</dependency> |
|
101 |
<dependency> |
|
102 |
<groupId>org.gvsig</groupId> |
|
103 |
<artifactId>org.gvsig.timesupport.lib.impl</artifactId> |
|
104 |
<scope>runtime</scope> |
|
105 |
</dependency> |
|
106 |
<dependency> |
|
107 |
<groupId>org.gvsig</groupId> |
|
108 |
<artifactId>org.gvsig.tools.evaluator.sqljep</artifactId> |
|
109 |
<scope>runtime</scope> |
|
110 |
</dependency> |
|
111 |
<dependency> |
|
112 |
<groupId>org.gvsig</groupId> |
|
113 |
<artifactId>org.gvsig.proj.lib.proj4j</artifactId> |
|
114 |
<scope>runtime</scope> |
|
115 |
</dependency> |
|
116 |
<dependency> |
|
117 |
<groupId>org.gvsig</groupId> |
|
118 |
<artifactId> |
|
119 |
org.gvsig.derivedgeometries.swing.api |
|
120 |
</artifactId> |
|
121 |
</dependency> |
|
122 |
<dependency> |
|
123 |
<groupId>org.gvsig</groupId> |
|
124 |
<artifactId> |
|
125 |
org.gvsig.derivedgeometries.swing.impl |
|
126 |
</artifactId> |
|
127 |
</dependency> |
|
128 |
<dependency> |
|
129 |
<groupId>org.gvsig</groupId> |
|
130 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
131 |
<scope>runtime</scope> |
|
132 |
</dependency> |
|
133 |
</dependencies> |
|
134 |
</project> |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.17/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.derivedgeometries.swing.impl.DefaultDerivedGeometriesLibrary |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.17/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.17/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/DerivedGeometriesPanelView.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.views; |
|
24 |
|
|
25 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.FlowLayout; |
|
28 |
|
|
29 |
import javax.swing.JButton; |
|
30 |
import javax.swing.JComponent; |
|
31 |
import javax.swing.JPanel; |
|
32 |
|
|
33 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesLocator; |
|
34 |
import org.gvsig.derivedgeometries.swing.api.DerivedGeometriesManager; |
|
35 |
import org.gvsig.derivedgeometries.swing.api.panels.FeaturesControlPanel; |
|
36 |
import org.gvsig.derivedgeometries.swing.api.panels.LayerAndProcessSelectionPanel; |
|
37 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
38 |
import org.gvsig.tools.ToolsLocator; |
|
39 |
import org.gvsig.tools.i18n.I18nManager; |
|
40 |
|
|
41 |
public class DerivedGeometriesPanelView extends JPanel { |
|
42 |
|
|
43 |
private static final long serialVersionUID = -5574613054191988321L; |
|
44 |
|
|
45 |
private LayerAndProcessSelectionPanel layerAndProcessSelectionPanel; |
|
46 |
|
|
47 |
private FeaturesControlPanel featuresControlPanel; |
|
48 |
|
|
49 |
private JPanel buttonsPanel; |
|
50 |
|
|
51 |
private JButton nextButton; |
|
52 |
|
|
53 |
private JButton cancelButton; |
|
54 |
|
|
55 |
public DerivedGeometriesPanelView(MapControl theMapControl) { |
|
56 |
|
|
57 |
DerivedGeometriesManager manager = |
|
58 |
DerivedGeometriesLocator.getManager(); |
|
59 |
|
|
60 |
this.layerAndProcessSelectionPanel = |
|
61 |
manager.getLayerAndProcessSelectionPanel(theMapControl); |
|
62 |
this.featuresControlPanel = manager.getFeaturesControlPanel(); |
|
63 |
|
|
64 |
initialize(); |
|
65 |
} |
|
66 |
|
|
67 |
private void initialize() { |
|
68 |
setLayout(new BorderLayout()); |
|
69 |
|
|
70 |
add(layerAndProcessSelectionPanel.asJComponent(), BorderLayout.PAGE_START); |
|
71 |
|
|
72 |
add(featuresControlPanel.asJComponent(), BorderLayout.CENTER); |
|
73 |
featuresControlPanel.asJComponent().setVisible(false); |
|
74 |
|
|
75 |
add(getButtonsPanel(), BorderLayout.PAGE_END); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public Dimension getPreferredSize() { |
|
80 |
JComponent c1 = layerAndProcessSelectionPanel.asJComponent(); |
|
81 |
JComponent c2 = featuresControlPanel.asJComponent(); |
|
82 |
|
|
83 |
int with = (int) Math.max(c1.getPreferredSize().getWidth(), c2.getPreferredSize().getWidth()); |
|
84 |
int height = (int) Math.max(c1.getPreferredSize().getHeight(), c2.getPreferredSize().getHeight()); |
|
85 |
return new Dimension(with,height); |
|
86 |
} |
|
87 |
|
|
88 |
private JPanel getButtonsPanel() { |
|
89 |
if (buttonsPanel == null) { |
|
90 |
buttonsPanel = new JPanel(); |
|
91 |
buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
|
92 |
buttonsPanel.add(getNextButton()); |
|
93 |
buttonsPanel.add(getCancelButton()); |
|
94 |
} |
|
95 |
return buttonsPanel; |
|
96 |
} |
|
97 |
|
|
98 |
protected JButton getCancelButton() { |
|
99 |
if (cancelButton == null) { |
|
100 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
101 |
cancelButton = new JButton(i18nManager.getTranslation("_cancel")); |
|
102 |
} |
|
103 |
return cancelButton; |
|
104 |
} |
|
105 |
|
|
106 |
protected JButton getNextButton() { |
|
107 |
if (nextButton == null) { |
|
108 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
109 |
nextButton = new JButton(i18nManager.getTranslation("_next") + " >"); |
|
110 |
} |
|
111 |
return nextButton; |
|
112 |
} |
|
113 |
|
|
114 |
protected LayerAndProcessSelectionPanel getLayerAndProcessSelectionPanel() { |
|
115 |
return layerAndProcessSelectionPanel; |
|
116 |
} |
|
117 |
|
|
118 |
protected FeaturesControlPanel getFeaturesControlPanel() { |
|
119 |
return featuresControlPanel; |
|
120 |
} |
|
121 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.17/org.gvsig.derivedgeometries.swing/org.gvsig.derivedgeometries.swing.impl/src/main/java/org/gvsig/derivedgeometries/swing/impl/views/DefaultDerivedGeometriesSelectionModel.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2014 gvSIG Association |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.derivedgeometries.swing.impl.views; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
import javax.swing.event.EventListenerList; |
|
29 |
import javax.swing.event.ListSelectionEvent; |
|
30 |
import javax.swing.event.ListSelectionListener; |
|
31 |
|
|
32 |
import org.gvsig.derivedgeometries.swing.api.tablemodels.DerivedGeometriesSelectionModel; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.SelectionChangeException; |
|
40 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel; |
|
41 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
42 |
|
|
43 |
public class DefaultDerivedGeometriesSelectionModel implements |
|
44 |
DerivedGeometriesSelectionModel { |
|
45 |
|
|
46 |
protected EventListenerList listenerList = new EventListenerList(); |
|
47 |
|
|
48 |
List<FeatureReference> selectedFeatures; |
|
49 |
|
|
50 |
FeatureTableModel featureTableModel; |
|
51 |
|
|
52 |
private int selectionMode = SINGLE_INTERVAL_SELECTION; |
|
53 |
|
|
54 |
private boolean isAdjusting = false; |
|
55 |
|
|
56 |
private int anchor = -1; |
|
57 |
|
|
58 |
private int lead = -1; |
|
59 |
|
|
60 |
private int currentFirst = -1; |
|
61 |
private int currentLast = -1; |
|
62 |
|
|
63 |
public DefaultDerivedGeometriesSelectionModel( |
|
64 |
FeatureTableModel theFeatureTableModel) { |
|
65 |
|
|
66 |
this.selectedFeatures = new ArrayList<FeatureReference>(); |
|
67 |
this.featureTableModel = theFeatureTableModel; |
|
68 |
|
|
69 |
} |
|
70 |
|
|
71 |
public void addListSelectionListener(ListSelectionListener listener) { |
|
72 |
listenerList.add(ListSelectionListener.class, listener); |
|
73 |
} |
|
74 |
|
|
75 |
public void addSelectionInterval(int index0, int index1) { |
|
76 |
doWithSelection(new FeatureSelectionOperation() { |
|
77 |
|
|
78 |
public void doWithSelection(FeatureSelection selection, int first, |
|
79 |
int last) throws DataException { |
|
80 |
for (int i = first; i <= last; i++) { |
|
81 |
Feature feature = getFeature(i); |
|
82 |
if (!selection.isSelected(feature)) { |
|
83 |
selection.select(feature); |
|
84 |
|
|
85 |
// After add new feature reference, we have to get index |
|
86 |
// of new feature selected within |
|
87 |
// selectedFeatures to keep feature order |
|
88 |
for (int j = 0; j < selectedFeatures.size(); j++) { |
|
89 |
int index = |
|
90 |
getIndexOfFeatureReference(selectedFeatures.get(j)); |
|
91 |
if (i < index) { |
|
92 |
selectedFeatures.add(j, feature.getReference()); |
|
93 |
return; |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
// if new feature has not been added, add it at last |
|
98 |
// position |
|
99 |
selectedFeatures.add(feature.getReference()); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
}, index0, index1, true); |
|
105 |
} |
|
106 |
|
|
107 |
public void clearSelection() { |
|
108 |
try { |
|
109 |
getFeatureSelection().deselectAll(); |
|
110 |
} catch (DataException e) { |
|
111 |
throw new SelectionChangeException(e); |
|
112 |
} |
|
113 |
selectedFeatures.clear(); |
|
114 |
} |
|
115 |
|
|
116 |
public int getAnchorSelectionIndex() { |
|
117 |
return anchor; |
|
118 |
} |
|
119 |
|
|
120 |
private interface FeatureSelectionOperation { |
|
121 |
|
|
122 |
void doWithSelection(FeatureSelection selection, int first, int last) |
|
123 |
throws DataException; |
|
124 |
} |
|
125 |
|
|
126 |
private void doWithSelection(FeatureSelectionOperation operation, |
|
127 |
int index0, int index1, boolean select) { |
|
128 |
// Set the anchor and lead |
|
129 |
anchor = index0; |
|
130 |
lead = index1; |
|
131 |
|
|
132 |
// As index0 <= index1 is no guaranteed, calculate the first and second |
|
133 |
// values |
|
134 |
int first = (index0 <= index1) ? index0 : index1; |
|
135 |
int last = (index0 <= index1) ? index1 : index0; |
|
136 |
|
|
137 |
// If the new selection is not updated don't continue |
|
138 |
if ((currentFirst == first) && (currentLast == last)) { |
|
139 |
return; |
|
140 |
} |
|
141 |
currentFirst = first; |
|
142 |
currentLast = last; |
|
143 |
|
|
144 |
FeatureSelection selection = getFeatureSelection(); |
|
145 |
|
|
146 |
// Perform the selection operation into a complex notification |
|
147 |
selection.beginComplexNotification(); |
|
148 |
try { |
|
149 |
// Is a full select or deselect |
|
150 |
if (first == 00 && last == featureTableModel.getRowCount() - 1) { |
|
151 |
if (!select) { |
|
152 |
selection.deselectAll(); |
|
153 |
selectedFeatures.clear(); |
|
154 |
} else { |
|
155 |
operation.doWithSelection(selection, first, last); |
|
156 |
} |
|
157 |
} else { |
|
158 |
operation.doWithSelection(selection, first, last); |
|
159 |
} |
|
160 |
} catch (DataException e) { |
|
161 |
throw new SelectionChangeException(e); |
|
162 |
} finally { |
|
163 |
selection.endComplexNotification(); |
|
164 |
} |
|
165 |
|
|
166 |
fireValueChanged(first, last, isAdjusting); |
|
167 |
} |
|
168 |
|
|
169 |
protected void fireValueChanged(int firstIndex, int lastIndex, |
|
170 |
boolean isAdjusting) { |
|
171 |
Object[] listeners = listenerList.getListenerList(); |
|
172 |
ListSelectionEvent e = null; |
|
173 |
|
|
174 |
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
175 |
if (listeners[i] == ListSelectionListener.class) { |
|
176 |
if (e == null) { |
|
177 |
e = |
|
178 |
new ListSelectionEvent(this, firstIndex, lastIndex, |
|
179 |
isAdjusting); |
|
180 |
} |
|
181 |
((ListSelectionListener) listeners[i + 1]).valueChanged(e); |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Returns a Feature by table row position. |
|
188 |
*/ |
|
189 |
private Feature getFeature(int index) { |
|
190 |
return featureTableModel.getFeatureAt(index); |
|
191 |
} |
|
192 |
|
|
193 |
private FeatureSelection getFeatureSelection() { |
|
194 |
try { |
|
195 |
return (FeatureSelection) getFeatureStore().getSelection(); |
|
196 |
} catch (DataException ex) { |
|
197 |
throw new SelectionChangeException(ex); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Returns the FeatureStore. |
|
203 |
*/ |
|
204 |
private FeatureStore getFeatureStore() { |
|
205 |
return featureTableModel.getFeatureStore(); |
|
206 |
} |
|
207 |
|
|
208 |
private int getIndexOfFeatureReference(FeatureReference featureReference) { |
|
209 |
|
|
210 |
for (int i = 0; i < featureTableModel.getRowCount(); i++) { |
|
211 |
|
|
212 |
Feature tmpFeature = featureTableModel.getFeatureAt(i); |
|
213 |
FeatureReference tmpFeatureReference = tmpFeature.getReference(); |
|
214 |
if (featureReference.equals(tmpFeatureReference)) { |
|
215 |
return i; |
|
216 |
} |
|
217 |
|
|
218 |
} |
|
219 |
return -1; |
|
220 |
} |
|
221 |
|
|
222 |
public int getLeadSelectionIndex() { |
|
223 |
return lead; |
|
224 |
} |
|
225 |
|
|
226 |
public int getMaxSelectionIndex() { |
|
227 |
int resp = this.getSelectionIndex(true); |
|
228 |
return resp; |
|
229 |
} |
|
230 |
|
|
231 |
public int getMinSelectionIndex() { |
|
232 |
int resp = this.getSelectionIndex(false); |
|
233 |
return resp; |
|
234 |
} |
|
235 |
|
|
236 |
private int getSelectionIndex(boolean last) { |
|
237 |
|
|
238 |
int ind = -1; |
|
239 |
int resp = -1; |
|
240 |
|
|
241 |
FeatureSet fs = null; |
|
242 |
DisposableIterator diter = null; |
|
243 |
|
|
244 |
try { |
|
245 |
FeatureSelection selection = getFeatureSelection(); |
|
246 |
if (!selection.isEmpty()) { |
|
247 |
|
|
248 |
fs = getFeatureStore().getFeatureSet(); |
|
249 |
diter = fs.fastIterator(); |
|
250 |
Feature feat = null; |
|
251 |
while (diter.hasNext()) { |
|
252 |
ind++; |
|
253 |
feat = (Feature) diter.next(); |
|
254 |
if (selection.isSelected(feat)) { |
|
255 |
resp = ind; |
|
256 |
if (!last) { |
|
257 |
break; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
} |
|
263 |
} catch (DataException e) { |
|
264 |
throw new SelectionChangeException(e); |
|
265 |
} finally { |
|
266 |
if (diter != null) { |
|
267 |
diter.dispose(); |
|
268 |
} |
|
269 |
|
|
270 |
if (fs != null) { |
|
271 |
fs.dispose(); |
|
272 |
} |
|
273 |
} |
|
274 |
return resp; |
|
275 |
} |
|
276 |
|
|
277 |
public int getSelectionMode() { |
|
278 |
return selectionMode; |
|
279 |
} |
|
280 |
|
|
281 |
public boolean getValueIsAdjusting() { |
|
282 |
return isAdjusting; |
|
283 |
} |
|
284 |
|
|
285 |
public void insertIndexInterval(int index, int length, boolean before) { |
|
286 |
// Nothing to do |
|
287 |
} |
|
288 |
|
|
289 |
public boolean isSelectedIndex(int index) { |
|
290 |
if (index == -1) { |
|
291 |
return false; |
|
292 |
} |
|
293 |
Feature feature = featureTableModel.getFeatureAt(index); |
|
294 |
return getFeatureSelection().isSelected(feature); |
|
295 |
} |
|
296 |
|
|
297 |
public boolean isSelectionEmpty() { |
|
298 |
try { |
|
299 |
return getFeatureSelection().isEmpty(); |
|
300 |
} catch (DataException ex) { |
|
301 |
throw new SelectionChangeException(ex); |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
public void removeIndexInterval(int index0, int index1) { |
|
306 |
// Nothing to do |
|
307 |
} |
|
308 |
|
|
309 |
public void removeListSelectionListener(ListSelectionListener listener) { |
|
310 |
listenerList.remove(ListSelectionListener.class, listener); |
|
311 |
} |
|
312 |
|
|
313 |
public void removeSelectionInterval(int index0, int index1) { |
|
314 |
doWithSelection(new FeatureSelectionOperation() { |
|
315 |
|
|
316 |
public void doWithSelection(FeatureSelection selection, int first, |
|
317 |
int last) throws DataException { |
|
318 |
for (int i = first; i <= last; i++) { |
|
319 |
Feature feature = getFeature(i); |
|
320 |
if (selection.isSelected(feature)) { |
|
321 |
selection.deselect(feature); |
|
322 |
selectedFeatures.remove(feature.getReference()); |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
326 |
|
|
327 |
}, index0, index1, false); |
|
328 |
|
|
329 |
} |
|
330 |
|
|
331 |
public void setAnchorSelectionIndex(int index) { |
|
332 |
this.anchor = index; |
|
333 |
} |
|
334 |
|
|
335 |
public void setLeadSelectionIndex(int index) { |
|
336 |
this.lead = index; |
|
337 |
} |
|
338 |
|
|
339 |
public void setSelectionInterval(int index0, int index1) { |
|
340 |
|
|
341 |
doWithSelection(new FeatureSelectionOperation() { |
|
342 |
|
|
343 |
public void doWithSelection(FeatureSelection selection, int first, |
|
344 |
int last) throws DataException { |
|
345 |
selection.deselectAll(); |
|
346 |
selectedFeatures.clear(); |
|
347 |
for (int i = first; i <= last; i++) { |
|
348 |
Feature feature = getFeature(i); |
|
349 |
selection.select(feature); |
|
350 |
selectedFeatures.add(feature.getReference()); |
|
351 |
} |
|
352 |
} |
|
353 |
|
|
354 |
}, index0, index1, true); |
|
355 |
} |
|
356 |
|
|
357 |
public void setSelectionMode(int selectionMode) { |
|
358 |
this.selectionMode = selectionMode; |
|
359 |
} |
|
360 |
|
|
361 |
public void setValueIsAdjusting(boolean valueIsAdjusting) { |
|
362 |
if (this.isAdjusting != valueIsAdjusting) { |
|
363 |
this.isAdjusting = valueIsAdjusting; |
|
364 |
if (this.isAdjusting) { |
|
365 |
getFeatureSelection().beginComplexNotification(); |
|
366 |
} else { |
|
367 |
getFeatureSelection().endComplexNotification(); |
|
368 |
} |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
public List<FeatureReference> getSelectedFeatures() { |
|
373 |
return this.selectedFeatures; |
|
374 |
} |
|
375 |
|
|
376 |
public void setSelectedFeatures(List<FeatureReference> list) { |
|
377 |
this.selectedFeatures = list; |
|
378 |
} |
|
379 |
|
|
380 |
} |
org.gvsig.derivedgeometries/tags/org.gvsig.derivedgeometries-1.0.17/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) { |
Also available in: Unified diff