svn-gvsig-desktop / 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 @ 47620
History | View | Annotate | Download (26.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.project.documents.view.gui; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.FocusAdapter; |
29 |
import java.awt.event.FocusEvent; |
30 |
import java.beans.PropertyChangeEvent; |
31 |
import java.beans.PropertyChangeListener; |
32 |
import java.util.HashMap; |
33 |
import java.util.Iterator; |
34 |
import java.util.Map; |
35 |
import java.util.function.Supplier; |
36 |
|
37 |
import javax.swing.JSplitPane; |
38 |
import javax.swing.SwingUtilities; |
39 |
|
40 |
import org.cresques.cts.IProjection; |
41 |
|
42 |
import org.gvsig.andami.PluginServices; |
43 |
import org.gvsig.andami.messages.NotificationManager; |
44 |
import org.gvsig.andami.ui.mdiFrame.NewStatusBar; |
45 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
46 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
47 |
import org.gvsig.app.ApplicationLocator; |
48 |
import org.gvsig.app.ApplicationManager; |
49 |
import org.gvsig.app.project.DefaultProject; |
50 |
import org.gvsig.app.project.documents.Document; |
51 |
import org.gvsig.app.project.documents.view.MapOverview; |
52 |
import org.gvsig.app.project.documents.view.ViewDocument; |
53 |
import org.gvsig.app.project.documents.view.ViewManager; |
54 |
import org.gvsig.app.project.documents.view.toc.gui.TOC; |
55 |
import org.gvsig.app.project.documents.view.toolListeners.AngleGeometryListener; |
56 |
import org.gvsig.app.project.documents.view.toolListeners.AreaListener; |
57 |
import org.gvsig.app.project.documents.view.toolListeners.IdentifyLayerListener; |
58 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
59 |
import org.gvsig.app.project.documents.view.toolListeners.MeasureListener; |
60 |
import org.gvsig.app.project.documents.view.toolListeners.PanListener; |
61 |
import org.gvsig.app.project.documents.view.toolListeners.PointSelectListener; |
62 |
import org.gvsig.app.project.documents.view.toolListeners.PolygonSelectListener; |
63 |
import org.gvsig.app.project.documents.view.toolListeners.RectangleSelectListener; |
64 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
65 |
import org.gvsig.app.project.documents.view.toolListeners.ZoomInListener; |
66 |
import org.gvsig.app.project.documents.view.toolListeners.ZoomOutListener; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
68 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
69 |
import org.gvsig.fmap.geom.primitive.Envelope; |
70 |
import org.gvsig.fmap.mapcontext.MapContext; |
71 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
72 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
73 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
74 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
75 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
76 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
77 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
78 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
79 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
80 |
import org.gvsig.fmap.mapcontrol.MapControlCreationException; |
81 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
82 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
83 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.TwoLinesBehavior; |
84 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
85 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
86 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior; |
87 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MoveBehavior; |
88 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
89 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior; |
90 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
91 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior; |
92 |
import org.gvsig.tools.observer.Observable; |
93 |
import org.gvsig.tools.observer.Observer; |
94 |
import org.gvsig.tools.util.PropertiesSupport; |
95 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
96 |
import org.gvsig.utils.console.JConsole; |
97 |
import org.gvsig.utils.console.JDockPanel; |
98 |
import org.gvsig.utils.console.ResponseListener; |
99 |
import org.gvsig.utils.console.jedit.JEditTextArea; |
100 |
|
101 |
/**
|
102 |
* <p>
|
103 |
* <b>Class View</b>. This class represents the gvSIG specific internal window
|
104 |
* where the maps are displayed and where the events coming from the user are
|
105 |
* captured.
|
106 |
* </p>
|
107 |
* <p>
|
108 |
* It is composed by three main visual areas:
|
109 |
* </p>
|
110 |
* <ol>
|
111 |
* <li>
|
112 |
* <b>Map control</b>: the map area located in the right area of the window. It
|
113 |
* takes up the biggest part of the window.</li>
|
114 |
* <li>
|
115 |
* <b>Table of contents (TOC)</b>: is a list of layers displayed in the view.
|
116 |
* The TOC is located on the left-top corner of the View and is the place where
|
117 |
* the user can modify the order, the legends, the visibility and other
|
118 |
* properties of the layers.</li>
|
119 |
* <li>
|
120 |
* <b>Map overview</b>: is a small MapControl located in the left-bottom corner
|
121 |
* of the View where the user can put some layers which summarizes the view. It
|
122 |
* is used to make the navigation easier and faster.</li>
|
123 |
* </ol>
|
124 |
*
|
125 |
* @author 2005- Vicente Caballero
|
126 |
* @author 2009- Joaquin del Cerro
|
127 |
*
|
128 |
*/
|
129 |
public class DefaultViewPanel |
130 |
extends AbstractViewPanel
|
131 |
implements Observer, PropertiesSupport |
132 |
{ |
133 |
|
134 |
/**
|
135 |
*
|
136 |
*/
|
137 |
private static final long serialVersionUID = -4044661458841786519L; |
138 |
|
139 |
private JConsole console;
|
140 |
private JDockPanel dockConsole = null; |
141 |
protected ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
142 |
protected boolean isShowConsole = false; |
143 |
private ViewPortListener viewPortListener;
|
144 |
private PropertiesSupportHelper propertiesHelper;
|
145 |
|
146 |
private static MapControlManager mapControlManager = MapControlLocator |
147 |
.getMapControlManager(); |
148 |
|
149 |
/**
|
150 |
* Creates a new View object. Before being used, the object must be
|
151 |
* initialized.
|
152 |
*
|
153 |
* @see initialize()
|
154 |
*/
|
155 |
public DefaultViewPanel() {
|
156 |
super();
|
157 |
this.propertiesHelper = new PropertiesSupportHelper(); |
158 |
this.propertiesHelper.setProperty("View", this); |
159 |
this.setName("View"); |
160 |
// TODO Remove this when the system lo load libraries is finished
|
161 |
if (mapControlManager == null) { |
162 |
mapControlManager = MapControlLocator.getMapControlManager(); |
163 |
} |
164 |
this.viewInformationArea = new DefaultViewInformationArea(); |
165 |
} |
166 |
|
167 |
public DefaultViewPanel(Document document) { |
168 |
this();
|
169 |
this.initialize(((ViewDocument) document).getMapContext());
|
170 |
this.setDocument(document);
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Create the internal componentes and populate the window with them. If the
|
175 |
* layout properties were set using the
|
176 |
* <code>setWindowData(WindowData)</code> method, the window will be
|
177 |
* populated according to this properties.
|
178 |
* @param mapContext
|
179 |
*/
|
180 |
protected void initialize(MapContext mapContext) { |
181 |
super.initialize();
|
182 |
initComponents(mapContext); |
183 |
hideConsole(); |
184 |
getConsolePanel().addResponseListener(consoleResponseAdapter); |
185 |
} |
186 |
|
187 |
public void setDocument(Document document) { |
188 |
setModel((ViewDocument) document); |
189 |
} |
190 |
|
191 |
public Document getDocument() { |
192 |
return this.modelo; |
193 |
} |
194 |
|
195 |
public void setModel(ViewDocument model) { |
196 |
final ApplicationManager application = ApplicationLocator.getApplicationManager();
|
197 |
this.modelo = model;
|
198 |
// Se registra como listener de cambios en FMap
|
199 |
MapContext fmap = modelo.getMapContext(); |
200 |
|
201 |
FLayers layers = fmap.getLayers(); |
202 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
203 |
if (layers.getLayer(i).isEditing()
|
204 |
&& layers.getLayer(i) instanceof FLyrVect) {
|
205 |
this.showConsole();
|
206 |
} |
207 |
} |
208 |
|
209 |
// Se configura el mapControl
|
210 |
m_TOC.setMapContext(fmap); |
211 |
|
212 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
213 |
if (modelo.getMapOverViewContext() != null) { |
214 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
215 |
} |
216 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
217 |
public void propertyChange(PropertyChangeEvent evt) { |
218 |
if (evt.getPropertyName().equals("name")) { |
219 |
PluginServices.getMDIManager() |
220 |
.getWindowInfo(DefaultViewPanel.this) |
221 |
.setTitle( |
222 |
PluginServices.getText(this, "Vista") + ": " |
223 |
+ (String) evt.getNewValue());
|
224 |
} |
225 |
} |
226 |
}); |
227 |
|
228 |
if (m_MapControl.getViewPort() != null) { |
229 |
viewPortListener = new ViewPortListener() {
|
230 |
public void extentChanged(ExtentEvent e) { |
231 |
try {
|
232 |
Document activeDoc = application.getActiveDocument(ViewManager.TYPENAME);
|
233 |
if(activeDoc != DefaultViewPanel.this.getDocument()) {
|
234 |
return;
|
235 |
} |
236 |
if (PluginServices.getMainFrame() != null) { |
237 |
PluginServices.getMainFrame().getStatusBar().setControlValue( |
238 |
"view-change-scale",
|
239 |
String.valueOf(m_MapControl.getMapContext().getScaleView())
|
240 |
); |
241 |
PluginServices.getMainFrame().getStatusBar().setMessage( |
242 |
"projection",
|
243 |
getMapControl().getViewPort().getProjection().getAbrev() |
244 |
); |
245 |
} |
246 |
} catch(Exception ex) { |
247 |
logger.warn("Problems process 'extentChanged'.",ex);
|
248 |
} |
249 |
} |
250 |
|
251 |
public void backColorChanged(ColorEvent e) { |
252 |
// Do nothing
|
253 |
} |
254 |
|
255 |
public void projectionChanged(ProjectionEvent e) { |
256 |
m_MapLoc.setProjection(e.getNewProjection()); |
257 |
} |
258 |
}; |
259 |
m_MapControl.getViewPort().addViewPortListener(viewPortListener); |
260 |
} |
261 |
} |
262 |
|
263 |
public JConsole getConsolePanel() {
|
264 |
if (console == null) { |
265 |
console = new JConsole(true); |
266 |
// Para distinguir cuando se est? escribiendo sobre la consola y
|
267 |
// cuando no.
|
268 |
console.setJTextName("CADConsole");
|
269 |
} |
270 |
return console;
|
271 |
} |
272 |
|
273 |
private JDockPanel getDockConsole() {
|
274 |
if (dockConsole == null) { |
275 |
dockConsole = new JDockPanel(getConsolePanel());
|
276 |
} |
277 |
return dockConsole;
|
278 |
} |
279 |
|
280 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
281 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
282 |
|
283 |
} |
284 |
|
285 |
public void removeConsoleListener(ResponseListener listener) { |
286 |
consoleResponseAdapter.deleteListener(listener); |
287 |
|
288 |
} |
289 |
|
290 |
public void focusConsole(String text) { |
291 |
getConsolePanel().addResponseText(text); |
292 |
|
293 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
294 |
jeta.requestFocusInWindow(); |
295 |
jeta.setCaretPosition(jeta.getText().length()); |
296 |
|
297 |
} |
298 |
|
299 |
public void hideConsole() { |
300 |
isShowConsole = false;
|
301 |
getDockConsole().setVisible(false);
|
302 |
|
303 |
} |
304 |
|
305 |
public void showConsole() { |
306 |
if (isShowConsole || disableConsole) {
|
307 |
return;
|
308 |
} |
309 |
isShowConsole = true;
|
310 |
getMapControl().remove(getDockConsole()); |
311 |
getMapControl().setLayout(new BorderLayout()); |
312 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH);
|
313 |
getDockConsole().setVisible(true);
|
314 |
|
315 |
} |
316 |
|
317 |
@Override
|
318 |
public Object getProperty(String name) { |
319 |
return this.propertiesHelper.getProperty(name); |
320 |
} |
321 |
|
322 |
@Override
|
323 |
public void setProperty(String name, Object value) { |
324 |
this.propertiesHelper.setProperty(name, value);
|
325 |
} |
326 |
|
327 |
@Override
|
328 |
public Map<String, Object> getProperties() { |
329 |
return this.propertiesHelper.getProperties(); |
330 |
} |
331 |
|
332 |
static class ResponseAdapter implements ResponseListener { |
333 |
|
334 |
private HashMap<String, ResponseListener> spaceListener |
335 |
= new HashMap<String, ResponseListener>(); |
336 |
|
337 |
public void putSpaceListener(String namespace, ResponseListener listener) { |
338 |
spaceListener.put(namespace, listener); |
339 |
} |
340 |
|
341 |
public void acceptResponse(String response) { |
342 |
boolean nameSpace = false; |
343 |
int n = -1; |
344 |
if (response != null) { |
345 |
if ((n = response.indexOf(':')) != -1) { |
346 |
nameSpace = true;
|
347 |
} |
348 |
} |
349 |
|
350 |
if (nameSpace) {
|
351 |
ResponseListener listener |
352 |
= spaceListener.get(response.substring(0, n));
|
353 |
if (listener != null) { |
354 |
listener.acceptResponse(response.substring(n + 1));
|
355 |
} |
356 |
} else {
|
357 |
Iterator<ResponseListener> i
|
358 |
= spaceListener.values().iterator(); |
359 |
while (i.hasNext()) {
|
360 |
ResponseListener listener = i.next(); |
361 |
listener.acceptResponse(response); |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
/**
|
367 |
* @param listener
|
368 |
*/
|
369 |
public void deleteListener(ResponseListener listener) { |
370 |
Iterator<String> i = spaceListener.keySet().iterator(); |
371 |
while (i.hasNext()) {
|
372 |
String namespace = i.next();
|
373 |
ResponseListener l = spaceListener.get(namespace); |
374 |
if (l == listener) {
|
375 |
spaceListener.remove(namespace); |
376 |
} |
377 |
} |
378 |
} |
379 |
|
380 |
} |
381 |
|
382 |
protected void initComponents(MapContext mapContext) { // GEN-BEGIN:initComponents |
383 |
// Remember to activate it
|
384 |
try {
|
385 |
m_MapControl = mapControlManager.createJMapControlPanel(mapContext); |
386 |
m_MapControl.setMapControlDrawer(mapControlManager |
387 |
.createDefaultMapControlDrawer()); |
388 |
} catch (MapControlCreationException e) {
|
389 |
NotificationManager.addError(e); |
390 |
} |
391 |
|
392 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
393 |
m_TOC = new TOC();
|
394 |
this.viewInformationArea.add(m_TOC, "TOC", 0, "ToC", null, "Table of contents"); |
395 |
|
396 |
// Ponemos el localizador
|
397 |
m_MapLoc = new MapOverview(m_MapControl);
|
398 |
try {
|
399 |
m_MapLoc.setMapControlDrawer(mapControlManager |
400 |
.createDefaultMapControlDrawer()); |
401 |
} catch (MapControlCreationException e) {
|
402 |
NotificationManager.addError(e); |
403 |
} |
404 |
removeAll(); |
405 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
406 |
|
407 |
if (windowLayout == null) { |
408 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
409 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
410 |
} |
411 |
|
412 |
if (!isPalette()) {
|
413 |
tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
414 |
tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
415 |
tempSplitToc.setBottomComponent(m_MapLoc); |
416 |
tempSplitToc.setResizeWeight(0.7);
|
417 |
tempMainSplit.setLeftComponent(tempSplitToc); |
418 |
} else {
|
419 |
tempMainSplit.setLeftComponent(this.viewInformationArea.asJComponent());
|
420 |
} |
421 |
m_TOC.setVisible(true);
|
422 |
tempMainSplit.setRightComponent(m_MapControl); |
423 |
this.setLayout(new BorderLayout()); |
424 |
this.add(tempMainSplit, BorderLayout.CENTER); |
425 |
|
426 |
if (windowLayout != null) { |
427 |
try {
|
428 |
tempMainSplit.setDividerLocation(Integer.valueOf(
|
429 |
windowLayout.get("MainDivider.Location")).intValue());
|
430 |
if (windowLayout.get("TOCDivider.Location") != null) { |
431 |
tempSplitToc.setDividerLocation(Integer.valueOf(
|
432 |
windowLayout.get("TOCDivider.Location")).intValue());
|
433 |
} |
434 |
} catch (NumberFormatException ex) { |
435 |
PluginServices.getLogger().error( |
436 |
"Error restoring View properties");
|
437 |
} |
438 |
} |
439 |
|
440 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
441 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
442 |
ZoomOutListener zoomOutListener = new ZoomOutListener(m_MapControl);
|
443 |
m_MapControl.addBehavior("zoomOut", new PointBehavior(zoomOutListener)); |
444 |
|
445 |
// Zoom por rect?ngulo
|
446 |
ZoomInListener zoomInListener = new ZoomInListener(m_MapControl);
|
447 |
m_MapControl.addBehavior("zoomIn", new Behavior[]{ |
448 |
new RectangleBehavior(zoomInListener),
|
449 |
new PointBehavior(zoomOutListener, Behavior.BUTTON_RIGHT)});
|
450 |
|
451 |
// pan
|
452 |
PanListener panListener = new PanListener(m_MapControl);
|
453 |
m_MapControl.addBehavior("pan", new MoveBehavior(panListener,Behavior.BUTTON_LEFT)); |
454 |
|
455 |
// Medir
|
456 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
457 |
m_MapControl.addBehavior("medicion", new PolylineBehavior(mli)); |
458 |
|
459 |
// Area
|
460 |
AreaListener ali = new AreaListener(m_MapControl);
|
461 |
m_MapControl.addBehavior("area", new PolygonBehavior(ali)); |
462 |
|
463 |
// Angulo
|
464 |
AngleGeometryListener agl = new AngleGeometryListener(m_MapControl);
|
465 |
m_MapControl.addBehavior("feature-angle", new TwoLinesBehavior(agl)); |
466 |
|
467 |
// Info por punto
|
468 |
InfoListener il = new InfoListener(m_MapControl);
|
469 |
m_MapControl.addBehavior("info", new PointBehavior(il)); |
470 |
|
471 |
// Identificacion de capa
|
472 |
IdentifyLayerListener ill = new IdentifyLayerListener(m_MapControl);
|
473 |
m_MapControl.addBehavior("identifylayer", new Behavior[] { |
474 |
new PointBehavior(ill),
|
475 |
new RectangleBehavior(ill)
|
476 |
} |
477 |
); |
478 |
|
479 |
// Seleccion por punto
|
480 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
481 |
m_MapControl.addBehavior("pointSelection", new PointBehavior(psl)); |
482 |
|
483 |
// Selecci?n por rect?ngulo
|
484 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
485 |
m_MapControl.addBehavior("rectSelection", new RectangleBehavior(rsl)); |
486 |
|
487 |
// Selecci?n por pol?gono
|
488 |
PolygonSelectListener poligSel = new PolygonSelectListener(m_MapControl);
|
489 |
m_MapControl.addBehavior("polSelection", new PolygonBehavior(poligSel)); |
490 |
|
491 |
m_MapControl.setTool("zoomIn");
|
492 |
|
493 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n
|
494 |
// en la barra de estado
|
495 |
StatusBarListener statusBarListener = new StatusBarListener(m_MapControl);
|
496 |
|
497 |
m_MapControl.addCombinedBehavior(new MouseMovementBehavior(statusBarListener));
|
498 |
m_MapControl.addCombinedBehavior(new MouseWheelBehavior());
|
499 |
m_MapControl.addCombinedBehavior(new MoveBehavior(panListener, Behavior.BUTTON_MIDDLE));
|
500 |
|
501 |
Supplier<Envelope> bboxSupplier = new Supplier<Envelope>() {
|
502 |
@Override
|
503 |
public Envelope get() {
|
504 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
505 |
Document activeView = application.getActiveDocument(ViewManager.TYPENAME);
|
506 |
if( activeView == getDocument() ) {
|
507 |
MapContext mapContext = getMapControl().getMapContext(); |
508 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
509 |
return env;
|
510 |
} |
511 |
return null; |
512 |
} |
513 |
}; |
514 |
m_MapControl.addFocusListener(new FocusAdapter() { |
515 |
@Override
|
516 |
@SuppressWarnings("Convert2Lambda") |
517 |
public void focusGained(FocusEvent e) { |
518 |
DALSwingLocator.getDataSwingManager().setCurrentBoundingBox(new Supplier<Envelope>() {
|
519 |
@Override
|
520 |
public Envelope get() {
|
521 |
MapContext mapContext = getMapControl().getMapContext(); |
522 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
523 |
return env;
|
524 |
} |
525 |
}); |
526 |
} |
527 |
}); |
528 |
m_MapControl.getMapContext().getViewPort().addViewPortListener(new ViewPortListener() {
|
529 |
@Override
|
530 |
@SuppressWarnings("Convert2Lambda") |
531 |
public void extentChanged(ExtentEvent e) { |
532 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
533 |
Document activeView = application.getActiveDocument(ViewManager.TYPENAME);
|
534 |
if (activeView == getDocument()) {
|
535 |
DALSwingLocator.getDataSwingManager().setCurrentBoundingBox(new Supplier<Envelope>() {
|
536 |
@Override
|
537 |
public Envelope get() {
|
538 |
MapContext mapContext = getMapControl().getMapContext(); |
539 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
540 |
return env;
|
541 |
} |
542 |
}); |
543 |
} |
544 |
} |
545 |
|
546 |
@Override
|
547 |
public void backColorChanged(ColorEvent e) { |
548 |
} |
549 |
|
550 |
@Override
|
551 |
public void projectionChanged(ProjectionEvent e) { |
552 |
} |
553 |
}); |
554 |
} |
555 |
|
556 |
public void windowActivated() { |
557 |
super.windowActivated();
|
558 |
|
559 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar(); |
560 |
MapContext mapContext = this.getMapControl().getMapContext();
|
561 |
|
562 |
statusbar.setMessage("units",
|
563 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
564 |
statusbar.setControlValue("view-change-scale",
|
565 |
String.valueOf(mapContext.getScaleView()));
|
566 |
IProjection proj = getMapControl().getViewPort().getProjection(); |
567 |
if (proj != null) { |
568 |
statusbar.setMessage("projection", proj.getAbrev());
|
569 |
} else {
|
570 |
statusbar.setMessage("projection", ""); |
571 |
} |
572 |
} |
573 |
|
574 |
public void windowClosed() { |
575 |
super.windowClosed();
|
576 |
if (viewPortListener != null) { |
577 |
getMapControl().getViewPort().removeViewPortListener( |
578 |
viewPortListener); |
579 |
} |
580 |
if (getMapOverview() != null) { |
581 |
getMapOverview().getViewPort().removeViewPortListener( |
582 |
getMapOverview()); |
583 |
} |
584 |
|
585 |
} |
586 |
|
587 |
public void toPalette() { |
588 |
isPalette = true;
|
589 |
m_MapLoc.setPreferredSize(new Dimension(200, 150)); |
590 |
m_MapLoc.setSize(new Dimension(200, 150)); |
591 |
movp = new MapOverViewPalette(m_MapLoc, this); |
592 |
PluginServices.getMDIManager().addWindow(movp); |
593 |
FLayer[] layers
|
594 |
= getViewDocument().getMapContext().getLayers().getActives(); |
595 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) { |
596 |
if (((FLyrVect) layers[0]).isEditing()) { |
597 |
showConsole(); |
598 |
return;
|
599 |
} |
600 |
} |
601 |
hideConsole(); |
602 |
|
603 |
} |
604 |
|
605 |
public void restore() { |
606 |
isPalette = false;
|
607 |
PluginServices.getMDIManager().closeWindow(movp); |
608 |
FLayer[] layers
|
609 |
= getViewDocument().getMapContext().getLayers().getActives(); |
610 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) { |
611 |
if (((FLyrVect) layers[0]).isEditing()) { |
612 |
showConsole(); |
613 |
return;
|
614 |
} |
615 |
} |
616 |
hideConsole(); |
617 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
618 |
tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
619 |
tempSplitToc.setBottomComponent(m_MapLoc); |
620 |
tempSplitToc.setResizeWeight(0.7);
|
621 |
tempMainSplit.setLeftComponent(tempSplitToc); |
622 |
} |
623 |
|
624 |
/**
|
625 |
* Sets the default map overview background color that will be used in
|
626 |
* subsequent projects.
|
627 |
*
|
628 |
* @param color
|
629 |
* @deprecated use instead
|
630 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
631 |
*/
|
632 |
public static void setDefaultMapOverViewBackColor(Color color) { |
633 |
DefaultProject.getPreferences().setDefaultOverviewBackColor(color); |
634 |
} |
635 |
|
636 |
/**
|
637 |
* Returns the current default map overview background color defined which
|
638 |
* is the color defined when the user does not define any other one
|
639 |
*
|
640 |
* @return java.awt.Color
|
641 |
* @deprecated use instead
|
642 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
643 |
*/
|
644 |
public static Color getDefaultMapOverViewBackColor() { |
645 |
return DefaultProject.getPreferences().getDefaultOverviewBackColor();
|
646 |
} |
647 |
|
648 |
/**
|
649 |
* Returns the current default view background color defined which is the
|
650 |
* color defined when the user does not define any other one
|
651 |
*
|
652 |
* @return java.awt.Color
|
653 |
* @deprecated use instead Project.getPreferences().getDefaultViewBackColor
|
654 |
*/
|
655 |
public static Color getDefaultBackColor() { |
656 |
return DefaultProject.getPreferences().getDefaultViewBackColor();
|
657 |
} |
658 |
|
659 |
/**
|
660 |
* @param color
|
661 |
* @deprecated use instead Project.getPreferences().setDefaultViewBackColor
|
662 |
*/
|
663 |
public static void setDefaultBackColor(Color color) { |
664 |
DefaultProject.getPreferences().setDefaultViewBackColor(color); |
665 |
} |
666 |
|
667 |
public Object getWindowProfile() { |
668 |
return WindowInfo.EDITOR_PROFILE;
|
669 |
} |
670 |
|
671 |
/* (non-Javadoc)
|
672 |
* @see org.gvsig.tools.observer.Observer#update(org.gvsig.tools.observer.Observable, java.lang.Object)
|
673 |
*/
|
674 |
public void update(final Observable observable, final Object notification) { |
675 |
|
676 |
if (notification instanceof FeatureStoreNotification) { |
677 |
FeatureStoreNotification event |
678 |
= (FeatureStoreNotification) notification; |
679 |
if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
|
680 |
|| event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
681 |
|
682 |
if (!SwingUtilities.isEventDispatchThread()) { |
683 |
SwingUtilities.invokeLater(new Runnable() { |
684 |
public void run() { |
685 |
update(observable, notification); |
686 |
} |
687 |
}); |
688 |
return;
|
689 |
} |
690 |
getMapControl().setTool("zoomIn");
|
691 |
hideConsole(); |
692 |
repaintMap(); |
693 |
} |
694 |
} |
695 |
} |
696 |
|
697 |
private static boolean disableConsole = false; |
698 |
|
699 |
public static void setDisableConsole(boolean disable) { |
700 |
disableConsole = disable; |
701 |
} |
702 |
|
703 |
} |