root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / StopEditing.java @ 3513
History | View | Annotate | Download (5.01 KB)
1 |
/*
|
---|---|
2 |
* Created on 21-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
21 |
USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig; |
46 |
|
47 |
import java.awt.Component; |
48 |
import java.io.File; |
49 |
|
50 |
import javax.swing.JFileChooser; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.plugins.Extension; |
54 |
import com.iver.cit.gvsig.fmap.FMap; |
55 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 |
import com.iver.cit.gvsig.fmap.drivers.dxf.write.DxfWriter; |
57 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
60 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer; |
61 |
import com.iver.cit.gvsig.gui.View; |
62 |
import com.iver.cit.gvsig.project.ProjectView; |
63 |
import com.iver.utiles.GenericFileFilter; |
64 |
|
65 |
|
66 |
/**
|
67 |
* DOCUMENT ME!
|
68 |
*
|
69 |
* @author Fernando Gonz?lez Cort?s
|
70 |
*/
|
71 |
public class StopEditing implements Extension { |
72 |
/**
|
73 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
74 |
*/
|
75 |
public void inicializar() { |
76 |
} |
77 |
|
78 |
/**
|
79 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
80 |
*/
|
81 |
public void execute(String actionCommand) { |
82 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
83 |
.getActiveView(); |
84 |
|
85 |
if (f.getClass() == View.class) { |
86 |
View vista = (View) f; |
87 |
ProjectView model = vista.getModel(); |
88 |
FMap mapa = model.getMapContext(); |
89 |
EditableVectorialLayer capa = (EditableVectorialLayer) mapa.getLayers() |
90 |
.getActives()[0];
|
91 |
|
92 |
try {
|
93 |
if (actionCommand.equals("STOP")){ |
94 |
File file = null; |
95 |
if (((FLyrVect)capa).getFile()==null){ |
96 |
|
97 |
|
98 |
JFileChooser jfc = new JFileChooser(); |
99 |
jfc.addChoosableFileFilter(new GenericFileFilter("dxf", |
100 |
PluginServices.getText(this, "DxfFiles"))); |
101 |
|
102 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
103 |
file = jfc.getSelectedFile(); |
104 |
|
105 |
if (!(file.getPath().endsWith(".dxf") || |
106 |
file.getPath().endsWith(".DXF"))) {
|
107 |
file = new File(file.getPath() + ".dxf"); |
108 |
} |
109 |
|
110 |
DxfWriter dxfwriter = new DxfWriter();
|
111 |
|
112 |
try {
|
113 |
dxfwriter.write(new IGeometry[0], file); |
114 |
} catch (Exception e3) { |
115 |
e3.printStackTrace(); |
116 |
} |
117 |
} |
118 |
|
119 |
|
120 |
}else{
|
121 |
file=((FLyrVect)capa).getFile(); |
122 |
} |
123 |
|
124 |
capa.stopEdition(file); |
125 |
|
126 |
vista.getMapControl().getMapControl().setTool("zoomIn");
|
127 |
vista.getMapControl().getMapControl().drawMap(false);
|
128 |
|
129 |
}else if (actionCommand.equals("CANCELEDITION")){ |
130 |
capa.cancelEdition(); |
131 |
vista.getMapControl().getMapControl().setTool("zoomIn");
|
132 |
vista.getMapControl().getMapControl().drawMap(false);
|
133 |
}else if (actionCommand.equals("SHOWGRID")){ |
134 |
vista.getMapControl().getCadToolAdapter().setGrid(true);
|
135 |
}else if (actionCommand.equals("HIDEGRID")){ |
136 |
vista.getMapControl().getCadToolAdapter().setGrid(false);
|
137 |
}else if (actionCommand.equals("SETADJUSTGRID")){ |
138 |
vista.getMapControl().getCadToolAdapter().setAdjustGrid(true);
|
139 |
}else if (actionCommand.equals("NOTADJUSTGRID")){ |
140 |
vista.getMapControl().getCadToolAdapter().setAdjustGrid(false);
|
141 |
} |
142 |
} catch (EditionException e) {
|
143 |
e.printStackTrace(); |
144 |
} |
145 |
} |
146 |
} |
147 |
/**
|
148 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
149 |
*/
|
150 |
public boolean isEnabled() { |
151 |
return true; |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
156 |
*/
|
157 |
public boolean isVisible() { |
158 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
159 |
.getActiveView(); |
160 |
|
161 |
if (f == null) { |
162 |
return false; |
163 |
} |
164 |
|
165 |
if (f.getClass() == View.class) { |
166 |
View vista = (View) f; |
167 |
ProjectView model = vista.getModel(); |
168 |
FMap mapa = model.getMapContext(); |
169 |
|
170 |
FLayer[] capas = mapa.getLayers().getActives();
|
171 |
|
172 |
for (int i = 0; i < capas.length; i++) { |
173 |
if (capas[i] instanceof EditableVectorialLayer) { |
174 |
return ((EditableVectorialLayer) capas[i]).isEditing();
|
175 |
} |
176 |
} |
177 |
} |
178 |
|
179 |
return false; |
180 |
} |
181 |
} |