root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / StopEditingToShp.java @ 3695
History | View | Annotate | Download (7.35 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.io.File; |
5 |
|
6 |
import javax.swing.JFileChooser; |
7 |
|
8 |
import com.iver.andami.PluginServices; |
9 |
import com.iver.andami.plugins.Extension; |
10 |
import com.iver.cit.gvsig.fmap.FMap; |
11 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
12 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
13 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
14 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
15 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
17 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
18 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
19 |
import com.iver.cit.gvsig.gui.View; |
20 |
import com.iver.cit.gvsig.project.ProjectView; |
21 |
|
22 |
|
23 |
/**
|
24 |
* DOCUMENT ME!
|
25 |
*
|
26 |
* @author Vicente Caballero Navarro
|
27 |
*/
|
28 |
public class StopEditingToShp implements Extension { |
29 |
/**
|
30 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
31 |
*/
|
32 |
public void inicializar() { |
33 |
} |
34 |
|
35 |
/**
|
36 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
37 |
*/
|
38 |
public void execute(String s) { |
39 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
40 |
.getActiveView(); |
41 |
|
42 |
View vista = (View) f; |
43 |
ProjectView model = vista.getModel(); |
44 |
FMap mapa = model.getMapContext(); |
45 |
FLayers layers = mapa.getLayers(); |
46 |
if (s.equals("STOPEDITING")){ |
47 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
48 |
if (layers.getLayer(i) instanceof FLyrVect && |
49 |
layers.getLayer(i).isEditing()) { |
50 |
FLyrVect lv = (FLyrVect) layers.getLayer(i); |
51 |
stopEditing(lv); |
52 |
|
53 |
return;
|
54 |
} |
55 |
} |
56 |
}else if (s.equals("CANCELEDITING")){ |
57 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
58 |
if (layers.getLayer(i) instanceof FLyrVect && |
59 |
layers.getLayer(i).isEditing()) { |
60 |
FLyrVect lv = (FLyrVect) layers.getLayer(i); |
61 |
//stopEditing(lv);
|
62 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) ((FLyrVect) layers.getLayer(i)).getSource(); |
63 |
lv.setSource(vea.getOriginalAdapter()); |
64 |
lv.setEditing(false);
|
65 |
return;
|
66 |
} |
67 |
} |
68 |
} |
69 |
PluginServices.getMainFrame().enableControls(); |
70 |
/* try {
|
71 |
if (actionCommand.equals("STOP")){
|
72 |
File file = null;
|
73 |
if (((FLyrVect)capa).getFile()==null){
|
74 |
JFileChooser jfc = new JFileChooser();
|
75 |
jfc.addChoosableFileFilter(new GenericFileFilter("dxf",
|
76 |
PluginServices.getText(this, "DxfFiles")));
|
77 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
78 |
file = jfc.getSelectedFile();
|
79 |
if (!(file.getPath().endsWith(".dxf") ||
|
80 |
file.getPath().endsWith(".DXF"))) {
|
81 |
file = new File(file.getPath() + ".dxf");
|
82 |
}
|
83 |
DxfWriter dxfwriter = new DxfWriter();
|
84 |
try {
|
85 |
dxfwriter.write(new IGeometry[0], file);
|
86 |
} catch (Exception e3) {
|
87 |
e3.printStackTrace();
|
88 |
}
|
89 |
}
|
90 |
}else{
|
91 |
file=((FLyrVect)capa).getFile();
|
92 |
}
|
93 |
capa.stopEdition(file);
|
94 |
vista.getMapControl().getMapControl().setTool("zoomIn");
|
95 |
vista.getMapControl().getMapControl().drawMap(false);
|
96 |
}else if (actionCommand.equals("CANCELEDITION")){
|
97 |
capa.cancelEdition();
|
98 |
vista.getMapControl().getMapControl().setTool("zoomIn");
|
99 |
vista.getMapControl().getMapControl().drawMap(false);
|
100 |
}else if (actionCommand.equals("SHOWGRID")){
|
101 |
vista.getMapControl().getCadToolAdapter().setGrid(true);
|
102 |
}else if (actionCommand.equals("HIDEGRID")){
|
103 |
vista.getMapControl().getCadToolAdapter().setGrid(false);
|
104 |
}else if (actionCommand.equals("SETADJUSTGRID")){
|
105 |
vista.getMapControl().getCadToolAdapter().setAdjustGrid(true);
|
106 |
}else if (actionCommand.equals("NOTADJUSTGRID")){
|
107 |
vista.getMapControl().getCadToolAdapter().setAdjustGrid(false);
|
108 |
}
|
109 |
} catch (EditionException e) {
|
110 |
e.printStackTrace();
|
111 |
}
|
112 |
}*/
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
117 |
*/
|
118 |
public boolean isEnabled() { |
119 |
return true; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* DOCUMENT ME!
|
124 |
*/
|
125 |
public void stopEditing(FLyrVect layer) { |
126 |
try {
|
127 |
JFileChooser jfc = new JFileChooser(); |
128 |
|
129 |
// if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
130 |
/* FLyrVect layer = (FLyrVect) test.createLayer("prueba",
|
131 |
(VectorialFileDriver) driverManager.getDriver(
|
132 |
"gvSIG shp driver"), original,
|
133 |
ProjectionPool.get("EPSG:23030"));
|
134 |
*/
|
135 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
136 |
File newFile = jfc.getSelectedFile();
|
137 |
|
138 |
ShpWriter writer = new ShpWriter(newFile, layer);
|
139 |
/* writer.preProcess();
|
140 |
|
141 |
VectorialAdapter adapter = layer.getSource();
|
142 |
|
143 |
for (int i = 0; i < adapter.getShapeCount(); i++) {
|
144 |
IFeature feat = adapter.getFeature(i);
|
145 |
IRowEdited editFeat = new DefaultRowEdited(feat,
|
146 |
IRowEdited.STATUS_MODIFIED);
|
147 |
writer.process(editFeat);
|
148 |
}
|
149 |
|
150 |
writer.postProcess();
|
151 |
*/
|
152 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
153 |
vea.stopEdition(writer); |
154 |
layer.setSource(vea.getOriginalAdapter()); |
155 |
layer.setEditing(false);
|
156 |
} |
157 |
//}
|
158 |
} catch (Exception e) { |
159 |
e.printStackTrace(); |
160 |
} |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
165 |
*/
|
166 |
public boolean isVisible() { |
167 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
168 |
.getActiveView(); |
169 |
|
170 |
if (f == null) { |
171 |
return false; |
172 |
} |
173 |
|
174 |
if (f.getClass() == View.class) { |
175 |
View vista = (View) f; |
176 |
ProjectView model = vista.getModel(); |
177 |
FMap mapa = model.getMapContext(); |
178 |
|
179 |
FLayers capas = mapa.getLayers(); |
180 |
|
181 |
for (int i = 0; i < capas.getLayersCount(); i++) { |
182 |
if (capas.getLayer(i) instanceof FLyrVect && |
183 |
capas.getLayer(i).isEditing()) { |
184 |
return true; |
185 |
} |
186 |
} |
187 |
|
188 |
return false; |
189 |
} |
190 |
|
191 |
return false; |
192 |
} |
193 |
} |