Revision 41965
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/gui/DefaultViewPanel.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 |
|
|
25 | 23 |
package org.gvsig.app.project.documents.view.gui; |
26 | 24 |
|
27 | 25 |
import java.awt.BorderLayout; |
... | ... | |
65 | 63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
66 | 64 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
67 | 65 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
68 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
69 | 66 |
import org.gvsig.fmap.mapcontrol.MapControlCreationException; |
70 | 67 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
71 | 68 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
72 |
import org.gvsig.fmap.mapcontrol.tools.ZoomOutRightButtonListener; |
|
73 | 69 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
74 | 70 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
75 | 71 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior; |
76 | 72 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior; |
77 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveWithMiddleButtonBehavior; |
|
78 | 73 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
79 | 74 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior; |
80 | 75 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
... | ... | |
115 | 110 |
* |
116 | 111 |
*/ |
117 | 112 |
public class DefaultViewPanel extends AbstractViewPanel implements Observer { |
118 |
/** |
|
119 |
* |
|
120 |
*/ |
|
121 |
private static final long serialVersionUID = -4044661458841786519L; |
|
122 | 113 |
|
123 |
private JConsole console; |
|
124 |
private JDockPanel dockConsole = null; |
|
125 |
protected ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
|
126 |
protected boolean isShowConsole = false; |
|
127 |
private ViewPortListener viewPortListener; |
|
114 |
/** |
|
115 |
* |
|
116 |
*/ |
|
117 |
private static final long serialVersionUID = -4044661458841786519L; |
|
128 | 118 |
|
129 |
private static MapControlManager mapControlManager = MapControlLocator |
|
130 |
.getMapControlManager(); |
|
119 |
private JConsole console; |
|
120 |
private JDockPanel dockConsole = null; |
|
121 |
protected ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
|
122 |
protected boolean isShowConsole = false; |
|
123 |
private ViewPortListener viewPortListener; |
|
131 | 124 |
|
132 |
/** |
|
133 |
* Creates a new View object. Before being used, the object must be |
|
134 |
* initialized. |
|
135 |
* |
|
136 |
* @see initialize() |
|
137 |
*/ |
|
138 |
public DefaultViewPanel() { |
|
139 |
super(); |
|
140 |
this.setName("View"); |
|
141 |
// TODO Remove this when the system lo load libraries is finished |
|
142 |
if (mapControlManager == null) { |
|
143 |
mapControlManager = MapControlLocator.getMapControlManager(); |
|
144 |
} |
|
145 |
} |
|
125 |
private static MapControlManager mapControlManager = MapControlLocator |
|
126 |
.getMapControlManager(); |
|
146 | 127 |
|
147 |
public DefaultViewPanel(Document document) { |
|
148 |
this(); |
|
149 |
this.initialize(((ViewDocument)document).getMapContext()); |
|
150 |
this.setDocument(document); |
|
151 |
} |
|
128 |
/** |
|
129 |
* Creates a new View object. Before being used, the object must be |
|
130 |
* initialized. |
|
131 |
* |
|
132 |
* @see initialize() |
|
133 |
*/ |
|
134 |
public DefaultViewPanel() { |
|
135 |
super(); |
|
136 |
this.setName("View"); |
|
137 |
// TODO Remove this when the system lo load libraries is finished |
|
138 |
if (mapControlManager == null) { |
|
139 |
mapControlManager = MapControlLocator.getMapControlManager(); |
|
140 |
} |
|
141 |
} |
|
152 | 142 |
|
153 |
/** |
|
154 |
* Create the internal componentes and populate the window with them. |
|
155 |
* If the layout properties were set using the |
|
156 |
* <code>setWindowData(WindowData)</code> method, the window will be |
|
157 |
* populated according to this properties. |
|
158 |
*/ |
|
159 |
protected void initialize(MapContext mapContext) { |
|
160 |
super.initialize(); |
|
161 |
initComponents(mapContext); |
|
162 |
hideConsole(); |
|
163 |
getConsolePanel().addResponseListener(consoleResponseAdapter); |
|
164 |
} |
|
143 |
public DefaultViewPanel(Document document) { |
|
144 |
this(); |
|
145 |
this.initialize(((ViewDocument) document).getMapContext()); |
|
146 |
this.setDocument(document); |
|
147 |
} |
|
165 | 148 |
|
166 |
public void setDocument(Document document) { |
|
167 |
setModel((ViewDocument) document); |
|
168 |
} |
|
149 |
/** |
|
150 |
* Create the internal componentes and populate the window with them. If the |
|
151 |
* layout properties were set using the |
|
152 |
* <code>setWindowData(WindowData)</code> method, the window will be |
|
153 |
* populated according to this properties. |
|
154 |
*/ |
|
155 |
protected void initialize(MapContext mapContext) { |
|
156 |
super.initialize(); |
|
157 |
initComponents(mapContext); |
|
158 |
hideConsole(); |
|
159 |
getConsolePanel().addResponseListener(consoleResponseAdapter); |
|
160 |
} |
|
169 | 161 |
|
170 |
public Document getDocument() {
|
|
171 |
return this.modelo;
|
|
172 |
}
|
|
162 |
public void setDocument(Document document) {
|
|
163 |
setModel((ViewDocument) document);
|
|
164 |
}
|
|
173 | 165 |
|
174 |
public void setModel(ViewDocument model) { |
|
175 |
this.modelo = model; |
|
176 |
// Se registra como listener de cambios en FMap |
|
177 |
MapContext fmap = modelo.getMapContext(); |
|
166 |
public Document getDocument() { |
|
167 |
return this.modelo; |
|
168 |
} |
|
178 | 169 |
|
179 |
FLayers layers = fmap.getLayers(); |
|
180 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
181 |
if (layers.getLayer(i).isEditing() |
|
182 |
&& layers.getLayer(i) instanceof FLyrVect) { |
|
183 |
this.showConsole(); |
|
184 |
} |
|
185 |
} |
|
170 |
public void setModel(ViewDocument model) { |
|
171 |
this.modelo = model; |
|
172 |
// Se registra como listener de cambios en FMap |
|
173 |
MapContext fmap = modelo.getMapContext(); |
|
186 | 174 |
|
187 |
// Se configura el mapControl |
|
188 |
m_TOC.setMapContext(fmap); |
|
189 |
m_MapControl.getMapContext().getLayers().addLegendListener(m_TOC); |
|
175 |
FLayers layers = fmap.getLayers(); |
|
176 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
177 |
if (layers.getLayer(i).isEditing() |
|
178 |
&& layers.getLayer(i) instanceof FLyrVect) { |
|
179 |
this.showConsole(); |
|
180 |
} |
|
181 |
} |
|
190 | 182 |
|
191 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
|
192 |
if (modelo.getMapOverViewContext() != null) { |
|
193 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
|
194 |
} |
|
195 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
|
196 |
public void propertyChange(PropertyChangeEvent evt) { |
|
197 |
if (evt.getPropertyName().equals("name")) { |
|
198 |
PluginServices.getMDIManager() |
|
199 |
.getWindowInfo(DefaultViewPanel.this) |
|
200 |
.setTitle( |
|
201 |
PluginServices.getText(this, "Vista") + ": " |
|
202 |
+ (String) evt.getNewValue()); |
|
203 |
} |
|
204 |
} |
|
205 |
}); |
|
206 |
if (m_MapControl.getViewPort() != null) { |
|
207 |
viewPortListener = new ViewPortListener() { |
|
208 |
public void extentChanged(ExtentEvent e) { |
|
209 |
if (PluginServices.getMainFrame() != null) { |
|
210 |
PluginServices |
|
211 |
.getMainFrame() |
|
212 |
.getStatusBar() |
|
213 |
.setControlValue( |
|
214 |
"view-change-scale", |
|
215 |
String.valueOf(m_MapControl |
|
216 |
.getMapContext().getScaleView())); |
|
217 |
PluginServices |
|
218 |
.getMainFrame() |
|
219 |
.getStatusBar() |
|
220 |
.setMessage( |
|
221 |
"projection", |
|
222 |
getMapControl().getViewPort() |
|
223 |
.getProjection().getAbrev()); |
|
224 |
} |
|
225 |
} |
|
183 |
// Se configura el mapControl |
|
184 |
m_TOC.setMapContext(fmap); |
|
185 |
m_MapControl.getMapContext().getLayers().addLegendListener(m_TOC); |
|
226 | 186 |
|
227 |
public void backColorChanged(ColorEvent e) { |
|
228 |
// Do nothing |
|
229 |
} |
|
187 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
|
188 |
if (modelo.getMapOverViewContext() != null) { |
|
189 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
|
190 |
} |
|
191 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
|
192 |
public void propertyChange(PropertyChangeEvent evt) { |
|
193 |
if (evt.getPropertyName().equals("name")) { |
|
194 |
PluginServices.getMDIManager() |
|
195 |
.getWindowInfo(DefaultViewPanel.this) |
|
196 |
.setTitle( |
|
197 |
PluginServices.getText(this, "Vista") + ": " |
|
198 |
+ (String) evt.getNewValue()); |
|
199 |
} |
|
200 |
} |
|
201 |
}); |
|
202 |
if (m_MapControl.getViewPort() != null) { |
|
203 |
viewPortListener = new ViewPortListener() { |
|
204 |
public void extentChanged(ExtentEvent e) { |
|
205 |
if (PluginServices.getMainFrame() != null) { |
|
206 |
PluginServices |
|
207 |
.getMainFrame() |
|
208 |
.getStatusBar() |
|
209 |
.setControlValue( |
|
210 |
"view-change-scale", |
|
211 |
String.valueOf(m_MapControl |
|
212 |
.getMapContext().getScaleView())); |
|
213 |
PluginServices |
|
214 |
.getMainFrame() |
|
215 |
.getStatusBar() |
|
216 |
.setMessage( |
|
217 |
"projection", |
|
218 |
getMapControl().getViewPort() |
|
219 |
.getProjection().getAbrev()); |
|
220 |
} |
|
221 |
} |
|
230 | 222 |
|
231 |
public void projectionChanged(ProjectionEvent e) { |
|
232 |
m_MapLoc.setProjection(e.getNewProjection()); |
|
233 |
} |
|
234 |
}; |
|
235 |
m_MapControl.getViewPort().addViewPortListener(viewPortListener); |
|
236 |
} |
|
237 |
} |
|
223 |
public void backColorChanged(ColorEvent e) { |
|
224 |
// Do nothing |
|
225 |
} |
|
238 | 226 |
|
239 |
public JConsole getConsolePanel() { |
|
240 |
if (console == null) { |
|
241 |
console = new JConsole(true); |
|
242 |
// Para distinguir cuando se est? escribiendo sobre la consola y |
|
243 |
// cuando no. |
|
244 |
console.setJTextName("CADConsole"); |
|
245 |
} |
|
246 |
return console; |
|
247 |
} |
|
227 |
public void projectionChanged(ProjectionEvent e) { |
|
228 |
m_MapLoc.setProjection(e.getNewProjection()); |
|
229 |
} |
|
230 |
}; |
|
231 |
m_MapControl.getViewPort().addViewPortListener(viewPortListener); |
|
232 |
} |
|
233 |
} |
|
248 | 234 |
|
249 |
private JDockPanel getDockConsole() { |
|
250 |
if (dockConsole == null) { |
|
251 |
dockConsole = new JDockPanel(getConsolePanel()); |
|
252 |
} |
|
253 |
return dockConsole; |
|
254 |
} |
|
235 |
public JConsole getConsolePanel() { |
|
236 |
if (console == null) { |
|
237 |
console = new JConsole(true); |
|
238 |
// Para distinguir cuando se est? escribiendo sobre la consola y |
|
239 |
// cuando no. |
|
240 |
console.setJTextName("CADConsole"); |
|
241 |
} |
|
242 |
return console; |
|
243 |
} |
|
255 | 244 |
|
256 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
|
257 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
|
245 |
private JDockPanel getDockConsole() { |
|
246 |
if (dockConsole == null) { |
|
247 |
dockConsole = new JDockPanel(getConsolePanel()); |
|
248 |
} |
|
249 |
return dockConsole; |
|
250 |
} |
|
258 | 251 |
|
259 |
} |
|
252 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
|
253 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
|
260 | 254 |
|
261 |
public void removeConsoleListener(ResponseListener listener) { |
|
262 |
consoleResponseAdapter.deleteListener(listener); |
|
255 |
} |
|
263 | 256 |
|
264 |
} |
|
257 |
public void removeConsoleListener(ResponseListener listener) { |
|
258 |
consoleResponseAdapter.deleteListener(listener); |
|
265 | 259 |
|
266 |
public void focusConsole(String text) { |
|
267 |
getConsolePanel().addResponseText(text); |
|
260 |
} |
|
268 | 261 |
|
269 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
|
270 |
jeta.requestFocusInWindow(); |
|
271 |
jeta.setCaretPosition(jeta.getText().length()); |
|
262 |
public void focusConsole(String text) { |
|
263 |
getConsolePanel().addResponseText(text); |
|
272 | 264 |
|
273 |
} |
|
265 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
|
266 |
jeta.requestFocusInWindow(); |
|
267 |
jeta.setCaretPosition(jeta.getText().length()); |
|
274 | 268 |
|
275 |
public void hideConsole() { |
|
276 |
isShowConsole = false; |
|
277 |
getDockConsole().setVisible(false); |
|
269 |
} |
|
278 | 270 |
|
279 |
} |
|
271 |
public void hideConsole() { |
|
272 |
isShowConsole = false; |
|
273 |
getDockConsole().setVisible(false); |
|
280 | 274 |
|
281 |
public void showConsole() { |
|
282 |
if (isShowConsole || disableConsole) { |
|
283 |
return; |
|
284 |
} |
|
285 |
isShowConsole = true; |
|
286 |
getMapControl().remove(getDockConsole()); |
|
287 |
getMapControl().setLayout(new BorderLayout()); |
|
288 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH); |
|
289 |
getDockConsole().setVisible(true); |
|
275 |
} |
|
290 | 276 |
|
291 |
} |
|
277 |
public void showConsole() { |
|
278 |
if (isShowConsole || disableConsole) { |
|
279 |
return; |
|
280 |
} |
|
281 |
isShowConsole = true; |
|
282 |
getMapControl().remove(getDockConsole()); |
|
283 |
getMapControl().setLayout(new BorderLayout()); |
|
284 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH); |
|
285 |
getDockConsole().setVisible(true); |
|
292 | 286 |
|
293 |
static class ResponseAdapter implements ResponseListener {
|
|
287 |
}
|
|
294 | 288 |
|
295 |
private HashMap<String, ResponseListener> spaceListener = |
|
296 |
new HashMap<String, ResponseListener>(); |
|
289 |
static class ResponseAdapter implements ResponseListener { |
|
297 | 290 |
|
298 |
public void putSpaceListener(String namespace, ResponseListener listener) { |
|
299 |
spaceListener.put(namespace, listener); |
|
300 |
} |
|
291 |
private HashMap<String, ResponseListener> spaceListener |
|
292 |
= new HashMap<String, ResponseListener>(); |
|
301 | 293 |
|
302 |
public void acceptResponse(String response) { |
|
303 |
boolean nameSpace = false; |
|
304 |
int n = -1; |
|
305 |
if (response != null) { |
|
306 |
if ((n = response.indexOf(':')) != -1) { |
|
307 |
nameSpace = true; |
|
308 |
} |
|
309 |
} |
|
294 |
public void putSpaceListener(String namespace, ResponseListener listener) { |
|
295 |
spaceListener.put(namespace, listener); |
|
296 |
} |
|
310 | 297 |
|
311 |
if (nameSpace) { |
|
312 |
ResponseListener listener = |
|
313 |
spaceListener.get(response.substring(0, n)); |
|
314 |
if (listener != null) { |
|
315 |
listener.acceptResponse(response.substring(n + 1)); |
|
316 |
} |
|
317 |
} else { |
|
318 |
Iterator<ResponseListener> i = |
|
319 |
spaceListener.values().iterator(); |
|
320 |
while (i.hasNext()) { |
|
321 |
ResponseListener listener = i.next(); |
|
322 |
listener.acceptResponse(response); |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
298 |
public void acceptResponse(String response) { |
|
299 |
boolean nameSpace = false; |
|
300 |
int n = -1; |
|
301 |
if (response != null) { |
|
302 |
if ((n = response.indexOf(':')) != -1) { |
|
303 |
nameSpace = true; |
|
304 |
} |
|
305 |
} |
|
326 | 306 |
|
327 |
/** |
|
328 |
* @param listener |
|
329 |
*/ |
|
330 |
public void deleteListener(ResponseListener listener) { |
|
331 |
Iterator<String> i = spaceListener.keySet().iterator(); |
|
332 |
while (i.hasNext()) { |
|
333 |
String namespace = i.next(); |
|
334 |
ResponseListener l = spaceListener.get(namespace); |
|
335 |
if (l == listener) { |
|
336 |
spaceListener.remove(namespace); |
|
337 |
} |
|
338 |
} |
|
339 |
} |
|
307 |
if (nameSpace) { |
|
308 |
ResponseListener listener |
|
309 |
= spaceListener.get(response.substring(0, n)); |
|
310 |
if (listener != null) { |
|
311 |
listener.acceptResponse(response.substring(n + 1)); |
|
312 |
} |
|
313 |
} else { |
|
314 |
Iterator<ResponseListener> i |
|
315 |
= spaceListener.values().iterator(); |
|
316 |
while (i.hasNext()) { |
|
317 |
ResponseListener listener = i.next(); |
|
318 |
listener.acceptResponse(response); |
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
340 | 322 |
|
341 |
} |
|
323 |
/** |
|
324 |
* @param listener |
|
325 |
*/ |
|
326 |
public void deleteListener(ResponseListener listener) { |
|
327 |
Iterator<String> i = spaceListener.keySet().iterator(); |
|
328 |
while (i.hasNext()) { |
|
329 |
String namespace = i.next(); |
|
330 |
ResponseListener l = spaceListener.get(namespace); |
|
331 |
if (l == listener) { |
|
332 |
spaceListener.remove(namespace); |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
342 | 336 |
|
343 |
protected void initComponents(MapContext mapContext) { // GEN-BEGIN:initComponents |
|
344 |
// Remember to activate it |
|
345 |
try { |
|
346 |
m_MapControl = mapControlManager.createJMapControlPanel(mapContext); |
|
347 |
m_MapControl.setMapControlDrawer(mapControlManager |
|
348 |
.createDefaultMapControlDrawer()); |
|
349 |
} catch (MapControlCreationException e) { |
|
350 |
NotificationManager.addError(e); |
|
351 |
} |
|
337 |
} |
|
352 | 338 |
|
353 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
|
354 |
m_TOC = new TOC(); |
|
339 |
protected void initComponents(MapContext mapContext) { // GEN-BEGIN:initComponents |
|
340 |
// Remember to activate it |
|
341 |
try { |
|
342 |
m_MapControl = mapControlManager.createJMapControlPanel(mapContext); |
|
343 |
m_MapControl.setMapControlDrawer(mapControlManager |
|
344 |
.createDefaultMapControlDrawer()); |
|
345 |
} catch (MapControlCreationException e) { |
|
346 |
NotificationManager.addError(e); |
|
347 |
} |
|
355 | 348 |
|
356 |
// Ponemos el localizador |
|
357 |
m_MapLoc = new MapOverview(m_MapControl); |
|
358 |
try { |
|
359 |
m_MapLoc.setMapControlDrawer(mapControlManager |
|
360 |
.createDefaultMapControlDrawer()); |
|
361 |
} catch (MapControlCreationException e) { |
|
362 |
NotificationManager.addError(e); |
|
363 |
} |
|
364 |
removeAll(); |
|
365 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
|
349 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
|
350 |
m_TOC = new TOC(); |
|
366 | 351 |
|
367 |
if (windowLayout == null) { |
|
368 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
|
369 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
|
370 |
} |
|
352 |
// Ponemos el localizador |
|
353 |
m_MapLoc = new MapOverview(m_MapControl); |
|
354 |
try { |
|
355 |
m_MapLoc.setMapControlDrawer(mapControlManager |
|
356 |
.createDefaultMapControlDrawer()); |
|
357 |
} catch (MapControlCreationException e) { |
|
358 |
NotificationManager.addError(e); |
|
359 |
} |
|
360 |
removeAll(); |
|
361 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
|
371 | 362 |
|
372 |
if (!isPalette()) { |
|
373 |
tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
|
374 |
tempSplitToc.setTopComponent(m_TOC); |
|
375 |
tempSplitToc.setBottomComponent(m_MapLoc); |
|
376 |
tempSplitToc.setResizeWeight(0.7); |
|
377 |
tempMainSplit.setLeftComponent(tempSplitToc); |
|
378 |
} else { |
|
379 |
tempMainSplit.setLeftComponent(m_TOC); |
|
380 |
} |
|
381 |
m_TOC.setVisible(true); |
|
382 |
tempMainSplit.setRightComponent(m_MapControl); |
|
383 |
this.setLayout(new BorderLayout()); |
|
384 |
this.add(tempMainSplit, BorderLayout.CENTER); |
|
363 |
if (windowLayout == null) { |
|
364 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
|
365 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
|
366 |
} |
|
385 | 367 |
|
386 |
if (windowLayout != null) { |
|
387 |
try { |
|
388 |
tempMainSplit.setDividerLocation(Integer.valueOf( |
|
389 |
windowLayout.get("MainDivider.Location")).intValue()); |
|
390 |
if (windowLayout.get("TOCDivider.Location") != null) { |
|
368 |
if (!isPalette()) { |
|
369 |
tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
|
370 |
tempSplitToc.setTopComponent(m_TOC); |
|
371 |
tempSplitToc.setBottomComponent(m_MapLoc); |
|
372 |
tempSplitToc.setResizeWeight(0.7); |
|
373 |
tempMainSplit.setLeftComponent(tempSplitToc); |
|
374 |
} else { |
|
375 |
tempMainSplit.setLeftComponent(m_TOC); |
|
376 |
} |
|
377 |
m_TOC.setVisible(true); |
|
378 |
tempMainSplit.setRightComponent(m_MapControl); |
|
379 |
this.setLayout(new BorderLayout()); |
|
380 |
this.add(tempMainSplit, BorderLayout.CENTER); |
|
381 |
|
|
382 |
if (windowLayout != null) { |
|
383 |
try { |
|
384 |
tempMainSplit.setDividerLocation(Integer.valueOf( |
|
385 |
windowLayout.get("MainDivider.Location")).intValue()); |
|
386 |
if (windowLayout.get("TOCDivider.Location") != null) { |
|
391 | 387 |
tempSplitToc.setDividerLocation(Integer.valueOf( |
392 |
windowLayout.get("TOCDivider.Location")).intValue()); |
|
393 |
}
|
|
394 |
} catch (NumberFormatException ex) {
|
|
395 |
PluginServices.getLogger().error(
|
|
396 |
"Error restoring View properties");
|
|
397 |
}
|
|
398 |
}
|
|
388 |
windowLayout.get("TOCDivider.Location")).intValue());
|
|
389 |
}
|
|
390 |
} catch (NumberFormatException ex) {
|
|
391 |
PluginServices.getLogger().error(
|
|
392 |
"Error restoring View properties");
|
|
393 |
}
|
|
394 |
}
|
|
399 | 395 |
|
400 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n |
|
401 |
// en la barra de estado |
|
402 |
StatusBarListener sbl = new StatusBarListener(m_MapControl); |
|
396 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s). |
|
397 |
// No es dibujando un rect?ngulo, es solo pinchando. |
|
398 |
ZoomOutListener zoomOutListener = new ZoomOutListener(m_MapControl); |
|
399 |
m_MapControl.addBehavior("zoomOut", new Behavior[]{ |
|
400 |
new PointBehavior(zoomOutListener)}); |
|
403 | 401 |
|
404 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s). |
|
405 |
// No es dibujando un rect?ngulo, es solo pinchando. |
|
402 |
// Zoom por rect?ngulo |
|
403 |
ZoomInListener zoomInListener = new ZoomInListener(m_MapControl); |
|
404 |
m_MapControl.addBehavior("zoomIn", new Behavior[]{ |
|
405 |
new RectangleBehavior(zoomInListener), |
|
406 |
new PointBehavior(zoomOutListener, PointBehavior.RIGHT)}); |
|
406 | 407 |
|
407 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl); |
|
408 |
// pan |
|
409 |
PanListener panListener = new PanListener(m_MapControl); |
|
410 |
m_MapControl.addBehavior("pan", new Behavior[]{new MoveBehavior(panListener)}); |
|
408 | 411 |
|
409 |
m_MapControl.addBehavior("zoomOut", new Behavior[] { |
|
410 |
new PointBehavior(zol)}); |
|
411 |
|
|
412 |
// pan |
|
413 |
|
|
414 |
PanListener pl = new PanListener(m_MapControl); |
|
415 |
m_MapControl.addBehavior("pan", new Behavior[] { new MoveBehavior(pl)}); |
|
416 |
|
|
417 |
// Medir |
|
418 |
|
|
419 |
MeasureListener mli = new MeasureListener(m_MapControl); |
|
420 |
m_MapControl.addBehavior("medicion", new Behavior[] { |
|
412 |
// Medir |
|
413 |
MeasureListener mli = new MeasureListener(m_MapControl); |
|
414 |
m_MapControl.addBehavior("medicion", new Behavior[]{ |
|
421 | 415 |
new PolylineBehavior(mli)}); |
422 | 416 |
|
423 |
// Area |
|
424 |
|
|
425 |
AreaListener ali = new AreaListener(m_MapControl); |
|
426 |
m_MapControl.addBehavior("area", new Behavior[] { |
|
417 |
// Area |
|
418 |
AreaListener ali = new AreaListener(m_MapControl); |
|
419 |
m_MapControl.addBehavior("area", new Behavior[]{ |
|
427 | 420 |
new PolygonBehavior(ali)}); |
428 | 421 |
|
429 |
// Seleccion por punto |
|
430 |
PointSelectListener psl = new PointSelectListener(m_MapControl); |
|
431 |
m_MapControl.addBehavior("pointSelection", new Behavior[] { |
|
432 |
new PointBehavior(psl)}); |
|
433 |
|
|
434 |
// Info por punto |
|
435 |
InfoListener il = new InfoListener(m_MapControl); |
|
436 |
m_MapControl.addBehavior("info", new Behavior[] { |
|
422 |
// Info por punto |
|
423 |
InfoListener il = new InfoListener(m_MapControl); |
|
424 |
m_MapControl.addBehavior("info", new Behavior[]{ |
|
437 | 425 |
new PointBehavior(il)}); |
438 | 426 |
|
439 |
// Selecci?n por rect?ngulo |
|
440 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl); |
|
441 |
m_MapControl.addBehavior("rectSelection", new Behavior[] { |
|
427 |
// Seleccion por punto |
|
428 |
PointSelectListener psl = new PointSelectListener(m_MapControl); |
|
429 |
m_MapControl.addBehavior("pointSelection", new Behavior[]{ |
|
430 |
new PointBehavior(psl)}); |
|
431 |
|
|
432 |
// Selecci?n por rect?ngulo |
|
433 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl); |
|
434 |
m_MapControl.addBehavior("rectSelection", new Behavior[]{ |
|
442 | 435 |
new RectangleBehavior(rsl)}); |
443 | 436 |
|
444 |
// Selecci?n por pol?gono |
|
445 |
PolygonSelectListener poligSel = |
|
446 |
new PolygonSelectListener(m_MapControl); |
|
447 |
m_MapControl.addBehavior("polSelection", new Behavior[] { |
|
437 |
// Selecci?n por pol?gono |
|
438 |
PolygonSelectListener poligSel = new PolygonSelectListener(m_MapControl); |
|
439 |
m_MapControl.addBehavior("polSelection", new Behavior[]{ |
|
448 | 440 |
new PolygonBehavior(poligSel)}); |
449 | 441 |
|
450 |
// Zoom por rect?ngulo |
|
451 |
ZoomInListener zil = new ZoomInListener(m_MapControl); |
|
452 |
m_MapControl.addBehavior("zoomIn", new Behavior[] { |
|
453 |
new RectangleBehavior(zil), new PointBehavior(zol,PointBehavior.RIGHT)}); |
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
m_MapControl.setTool("zoomIn"); |
|
458 |
|
|
459 |
|
|
460 |
m_MapControl.addCombinedBehavior(new MouseMovementBehavior(sbl)); |
|
442 |
|
|
443 |
|
|
444 |
m_MapControl.setTool("zoomIn"); |
|
445 |
|
|
446 |
|
|
447 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n |
|
448 |
// en la barra de estado |
|
449 |
StatusBarListener statusBarListener = new StatusBarListener(m_MapControl); |
|
450 |
|
|
451 |
m_MapControl.addCombinedBehavior(new MouseMovementBehavior(statusBarListener)); |
|
461 | 452 |
m_MapControl.addCombinedBehavior(new MouseWheelBehavior()); |
462 |
m_MapControl.addCombinedBehavior(new MoveBehavior(pl,MoveBehavior.MIDDLE));
|
|
463 |
}
|
|
453 |
m_MapControl.addCombinedBehavior(new MoveBehavior(panListener, MoveBehavior.MIDDLE));
|
|
454 |
}
|
|
464 | 455 |
|
465 |
public void windowActivated() {
|
|
466 |
super.windowActivated();
|
|
456 |
public void windowActivated() {
|
|
457 |
super.windowActivated();
|
|
467 | 458 |
|
468 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar();
|
|
469 |
MapContext mapContext = this.getMapControl().getMapContext();
|
|
459 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar();
|
|
460 |
MapContext mapContext = this.getMapControl().getMapContext();
|
|
470 | 461 |
|
471 |
statusbar.setMessage("units",
|
|
472 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
|
473 |
statusbar.setControlValue("view-change-scale",
|
|
474 |
String.valueOf(mapContext.getScaleView()));
|
|
475 |
IProjection proj = getMapControl().getViewPort().getProjection();
|
|
476 |
if (proj != null) {
|
|
477 |
statusbar.setMessage("projection", proj.getAbrev());
|
|
478 |
} else {
|
|
479 |
statusbar.setMessage("projection", "");
|
|
480 |
}
|
|
481 |
}
|
|
462 |
statusbar.setMessage("units",
|
|
463 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
|
464 |
statusbar.setControlValue("view-change-scale",
|
|
465 |
String.valueOf(mapContext.getScaleView()));
|
|
466 |
IProjection proj = getMapControl().getViewPort().getProjection();
|
|
467 |
if (proj != null) {
|
|
468 |
statusbar.setMessage("projection", proj.getAbrev());
|
|
469 |
} else {
|
|
470 |
statusbar.setMessage("projection", "");
|
|
471 |
}
|
|
472 |
}
|
|
482 | 473 |
|
483 |
public void windowClosed() {
|
|
484 |
super.windowClosed();
|
|
485 |
if (viewPortListener != null) {
|
|
486 |
getMapControl().getViewPort().removeViewPortListener(
|
|
487 |
viewPortListener);
|
|
488 |
}
|
|
489 |
if (getMapOverview() != null) {
|
|
490 |
getMapOverview().getViewPort().removeViewPortListener(
|
|
491 |
getMapOverview());
|
|
492 |
}
|
|
474 |
public void windowClosed() {
|
|
475 |
super.windowClosed();
|
|
476 |
if (viewPortListener != null) {
|
|
477 |
getMapControl().getViewPort().removeViewPortListener(
|
|
478 |
viewPortListener);
|
|
479 |
}
|
|
480 |
if (getMapOverview() != null) {
|
|
481 |
getMapOverview().getViewPort().removeViewPortListener(
|
|
482 |
getMapOverview());
|
|
483 |
}
|
|
493 | 484 |
|
494 |
}
|
|
485 |
}
|
|
495 | 486 |
|
496 |
public void toPalette() {
|
|
497 |
isPalette = true;
|
|
498 |
m_MapLoc.setPreferredSize(new Dimension(200, 150));
|
|
499 |
m_MapLoc.setSize(new Dimension(200, 150));
|
|
500 |
movp = new MapOverViewPalette(m_MapLoc, this);
|
|
501 |
PluginServices.getMDIManager().addWindow(movp);
|
|
502 |
FLayer[] layers =
|
|
503 |
getViewDocument().getMapContext().getLayers().getActives(); |
|
504 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) {
|
|
505 |
if (((FLyrVect) layers[0]).isEditing()) {
|
|
506 |
showConsole();
|
|
507 |
return;
|
|
508 |
}
|
|
509 |
}
|
|
510 |
hideConsole();
|
|
487 |
public void toPalette() {
|
|
488 |
isPalette = true;
|
|
489 |
m_MapLoc.setPreferredSize(new Dimension(200, 150));
|
|
490 |
m_MapLoc.setSize(new Dimension(200, 150));
|
|
491 |
movp = new MapOverViewPalette(m_MapLoc, this);
|
|
492 |
PluginServices.getMDIManager().addWindow(movp);
|
|
493 |
FLayer[] layers |
|
494 |
= getViewDocument().getMapContext().getLayers().getActives();
|
|
495 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) {
|
|
496 |
if (((FLyrVect) layers[0]).isEditing()) {
|
|
497 |
showConsole();
|
|
498 |
return;
|
|
499 |
}
|
|
500 |
}
|
|
501 |
hideConsole();
|
|
511 | 502 |
|
512 |
}
|
|
503 |
}
|
|
513 | 504 |
|
514 |
public void restore() {
|
|
515 |
isPalette = false;
|
|
516 |
PluginServices.getMDIManager().closeWindow(movp);
|
|
517 |
FLayer[] layers =
|
|
518 |
getViewDocument().getMapContext().getLayers().getActives(); |
|
519 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) {
|
|
520 |
if (((FLyrVect) layers[0]).isEditing()) {
|
|
521 |
showConsole();
|
|
522 |
return;
|
|
523 |
}
|
|
524 |
}
|
|
525 |
hideConsole();
|
|
526 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
527 |
tempSplitToc.setTopComponent(m_TOC);
|
|
528 |
tempSplitToc.setBottomComponent(m_MapLoc);
|
|
529 |
tempSplitToc.setResizeWeight(0.7);
|
|
530 |
tempMainSplit.setLeftComponent(tempSplitToc);
|
|
531 |
}
|
|
505 |
public void restore() {
|
|
506 |
isPalette = false;
|
|
507 |
PluginServices.getMDIManager().closeWindow(movp);
|
|
508 |
FLayer[] layers |
|
509 |
= getViewDocument().getMapContext().getLayers().getActives();
|
|
510 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) {
|
|
511 |
if (((FLyrVect) layers[0]).isEditing()) {
|
|
512 |
showConsole();
|
|
513 |
return;
|
|
514 |
}
|
|
515 |
}
|
|
516 |
hideConsole();
|
|
517 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
518 |
tempSplitToc.setTopComponent(m_TOC);
|
|
519 |
tempSplitToc.setBottomComponent(m_MapLoc);
|
|
520 |
tempSplitToc.setResizeWeight(0.7);
|
|
521 |
tempMainSplit.setLeftComponent(tempSplitToc);
|
|
522 |
}
|
|
532 | 523 |
|
533 |
/**
|
|
534 |
* Sets the default map overview background color that will be used in
|
|
535 |
* subsequent projects.
|
|
536 |
*
|
|
537 |
* @param color
|
|
538 |
* @deprecated use instead
|
|
539 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
|
540 |
*/
|
|
541 |
public static void setDefaultMapOverViewBackColor(Color color) {
|
|
542 |
DefaultProject.getPreferences().setDefaultOverviewBackColor(color);
|
|
543 |
}
|
|
524 |
/**
|
|
525 |
* Sets the default map overview background color that will be used in
|
|
526 |
* subsequent projects.
|
|
527 |
*
|
|
528 |
* @param color
|
|
529 |
* @deprecated use instead
|
|
530 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
|
531 |
*/
|
|
532 |
public static void setDefaultMapOverViewBackColor(Color color) {
|
|
533 |
DefaultProject.getPreferences().setDefaultOverviewBackColor(color);
|
|
534 |
}
|
|
544 | 535 |
|
545 |
/**
|
|
546 |
* Returns the current default map overview background color defined which
|
|
547 |
* is the color defined when the user does not define any other one
|
|
548 |
*
|
|
549 |
* @return java.awt.Color
|
|
550 |
* @deprecated use instead
|
|
551 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
|
552 |
*/
|
|
553 |
public static Color getDefaultMapOverViewBackColor() {
|
|
554 |
return DefaultProject.getPreferences().getDefaultOverviewBackColor();
|
|
555 |
}
|
|
536 |
/**
|
|
537 |
* Returns the current default map overview background color defined which
|
|
538 |
* is the color defined when the user does not define any other one
|
|
539 |
*
|
|
540 |
* @return java.awt.Color
|
|
541 |
* @deprecated use instead
|
|
542 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
|
543 |
*/
|
|
544 |
public static Color getDefaultMapOverViewBackColor() {
|
|
545 |
return DefaultProject.getPreferences().getDefaultOverviewBackColor();
|
|
546 |
}
|
|
556 | 547 |
|
557 |
/**
|
|
558 |
* Returns the current default view background color defined which is the
|
|
559 |
* color defined when the user does not define any other one
|
|
560 |
*
|
|
561 |
* @return java.awt.Color
|
|
562 |
* @deprecated use instead Project.getPreferences().getDefaultViewBackColor
|
|
563 |
*/
|
|
564 |
public static Color getDefaultBackColor() {
|
|
565 |
return DefaultProject.getPreferences().getDefaultViewBackColor();
|
|
566 |
}
|
|
548 |
/**
|
|
549 |
* Returns the current default view background color defined which is the
|
|
550 |
* color defined when the user does not define any other one
|
|
551 |
*
|
|
552 |
* @return java.awt.Color
|
|
553 |
* @deprecated use instead Project.getPreferences().getDefaultViewBackColor
|
|
554 |
*/
|
|
555 |
public static Color getDefaultBackColor() {
|
|
556 |
return DefaultProject.getPreferences().getDefaultViewBackColor();
|
|
557 |
}
|
|
567 | 558 |
|
568 |
/**
|
|
569 |
* @deprecated use instead Project.getPreferences().setDefaultViewBackColor
|
|
570 |
*/
|
|
571 |
public static void setDefaultBackColor(Color color) {
|
|
572 |
DefaultProject.getPreferences().setDefaultViewBackColor(color);
|
|
573 |
}
|
|
559 |
/**
|
|
560 |
* @deprecated use instead Project.getPreferences().setDefaultViewBackColor
|
|
561 |
*/
|
|
562 |
public static void setDefaultBackColor(Color color) {
|
|
563 |
DefaultProject.getPreferences().setDefaultViewBackColor(color);
|
|
564 |
}
|
|
574 | 565 |
|
575 |
public Object getWindowProfile() {
|
|
576 |
return WindowInfo.EDITOR_PROFILE;
|
|
577 |
}
|
|
566 |
public Object getWindowProfile() {
|
|
567 |
return WindowInfo.EDITOR_PROFILE;
|
|
568 |
}
|
|
578 | 569 |
|
579 | 570 |
/* (non-Javadoc) |
580 | 571 |
* @see org.gvsig.tools.observer.Observer#update(org.gvsig.tools.observer.Observable, java.lang.Object) |
... | ... | |
582 | 573 |
public void update(final Observable observable, final Object notification) { |
583 | 574 |
|
584 | 575 |
if (notification instanceof FeatureStoreNotification) { |
585 |
FeatureStoreNotification event =
|
|
586 |
(FeatureStoreNotification) notification; |
|
576 |
FeatureStoreNotification event |
|
577 |
= (FeatureStoreNotification) notification;
|
|
587 | 578 |
if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING |
588 |
|| event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
|
579 |
|| event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) {
|
|
589 | 580 |
|
590 | 581 |
if (!SwingUtilities.isEventDispatchThread()) { |
591 | 582 |
SwingUtilities.invokeLater(new Runnable() { |
... | ... | |
604 | 595 |
|
605 | 596 |
private static boolean disableConsole = false; |
606 | 597 |
|
607 |
public static void setDisableConsole(boolean disable){ |
|
598 |
public static void setDisableConsole(boolean disable) {
|
|
608 | 599 |
disableConsole = disable; |
609 | 600 |
} |
610 | 601 |
|
Also available in: Unified diff