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 @ 47799
History | View | Annotate | Download (26.7 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 |
@Override
|
252 |
public void backColorChanged(ColorEvent e) { |
253 |
// Do nothing
|
254 |
} |
255 |
|
256 |
public void projectionChanged(ProjectionEvent e) { |
257 |
m_MapLoc.setProjection(e.getNewProjection()); |
258 |
} |
259 |
}; |
260 |
m_MapControl.getViewPort().addViewPortListener(viewPortListener); |
261 |
} |
262 |
} |
263 |
|
264 |
public JConsole getConsolePanel() {
|
265 |
if (console == null) { |
266 |
console = new JConsole(true); |
267 |
// Para distinguir cuando se est? escribiendo sobre la consola y
|
268 |
// cuando no.
|
269 |
console.setJTextName("CADConsole");
|
270 |
} |
271 |
return console;
|
272 |
} |
273 |
|
274 |
private JDockPanel getDockConsole() {
|
275 |
if (dockConsole == null) { |
276 |
dockConsole = new JDockPanel(getConsolePanel());
|
277 |
} |
278 |
return dockConsole;
|
279 |
} |
280 |
|
281 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
282 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
283 |
|
284 |
} |
285 |
|
286 |
public void removeConsoleListener(ResponseListener listener) { |
287 |
consoleResponseAdapter.deleteListener(listener); |
288 |
|
289 |
} |
290 |
|
291 |
public void focusConsole(String text) { |
292 |
getConsolePanel().addResponseText(text); |
293 |
|
294 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
295 |
jeta.requestFocusInWindow(); |
296 |
jeta.setCaretPosition(jeta.getText().length()); |
297 |
|
298 |
} |
299 |
|
300 |
public void hideConsole() { |
301 |
isShowConsole = false;
|
302 |
getDockConsole().setVisible(false);
|
303 |
|
304 |
} |
305 |
|
306 |
public void showConsole() { |
307 |
if (isShowConsole || disableConsole) {
|
308 |
return;
|
309 |
} |
310 |
isShowConsole = true;
|
311 |
getMapControl().remove(getDockConsole()); |
312 |
getMapControl().setLayout(new BorderLayout()); |
313 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH);
|
314 |
getDockConsole().setVisible(true);
|
315 |
|
316 |
} |
317 |
|
318 |
@Override
|
319 |
public Object getProperty(String name) { |
320 |
return this.propertiesHelper.getProperty(name); |
321 |
} |
322 |
|
323 |
@Override
|
324 |
public void setProperty(String name, Object value) { |
325 |
this.propertiesHelper.setProperty(name, value);
|
326 |
} |
327 |
|
328 |
@Override
|
329 |
public Map<String, Object> getProperties() { |
330 |
return this.propertiesHelper.getProperties(); |
331 |
} |
332 |
|
333 |
static class ResponseAdapter implements ResponseListener { |
334 |
|
335 |
private HashMap<String, ResponseListener> spaceListener |
336 |
= new HashMap<String, ResponseListener>(); |
337 |
|
338 |
public void putSpaceListener(String namespace, ResponseListener listener) { |
339 |
spaceListener.put(namespace, listener); |
340 |
} |
341 |
|
342 |
public void acceptResponse(String response) { |
343 |
boolean nameSpace = false; |
344 |
int n = -1; |
345 |
if (response != null) { |
346 |
if ((n = response.indexOf(':')) != -1) { |
347 |
nameSpace = true;
|
348 |
} |
349 |
} |
350 |
|
351 |
if (nameSpace) {
|
352 |
ResponseListener listener |
353 |
= spaceListener.get(response.substring(0, n));
|
354 |
if (listener != null) { |
355 |
listener.acceptResponse(response.substring(n + 1));
|
356 |
} |
357 |
} else {
|
358 |
Iterator<ResponseListener> i
|
359 |
= spaceListener.values().iterator(); |
360 |
while (i.hasNext()) {
|
361 |
ResponseListener listener = i.next(); |
362 |
listener.acceptResponse(response); |
363 |
} |
364 |
} |
365 |
} |
366 |
|
367 |
/**
|
368 |
* @param listener
|
369 |
*/
|
370 |
public void deleteListener(ResponseListener listener) { |
371 |
Iterator<String> i = spaceListener.keySet().iterator(); |
372 |
while (i.hasNext()) {
|
373 |
String namespace = i.next();
|
374 |
ResponseListener l = spaceListener.get(namespace); |
375 |
if (l == listener) {
|
376 |
spaceListener.remove(namespace); |
377 |
} |
378 |
} |
379 |
} |
380 |
|
381 |
} |
382 |
|
383 |
protected void initComponents(MapContext mapContext) { // GEN-BEGIN:initComponents |
384 |
// Remember to activate it
|
385 |
try {
|
386 |
m_MapControl = mapControlManager.createJMapControlPanel(mapContext); |
387 |
m_MapControl.setMapControlDrawer(mapControlManager |
388 |
.createDefaultMapControlDrawer()); |
389 |
} catch (MapControlCreationException e) {
|
390 |
NotificationManager.addError(e); |
391 |
} |
392 |
|
393 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
394 |
m_TOC = new TOC();
|
395 |
this.viewInformationArea.add(m_TOC, "TOC", 0, "ToC", null, "Table of contents"); |
396 |
|
397 |
// Ponemos el localizador
|
398 |
m_MapLoc = new MapOverview(m_MapControl);
|
399 |
try {
|
400 |
m_MapLoc.setMapControlDrawer(mapControlManager |
401 |
.createDefaultMapControlDrawer()); |
402 |
} catch (MapControlCreationException e) {
|
403 |
NotificationManager.addError(e); |
404 |
} |
405 |
removeAll(); |
406 |
tempMainSplit = new ViewSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
407 |
|
408 |
if (windowLayout == null) { |
409 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
410 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
411 |
} |
412 |
|
413 |
if (!isPalette()) {
|
414 |
tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
415 |
tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
416 |
tempSplitToc.setBottomComponent(m_MapLoc); |
417 |
tempSplitToc.setResizeWeight(0.7);
|
418 |
tempMainSplit.setLeftComponent(tempSplitToc); |
419 |
} else {
|
420 |
tempMainSplit.setLeftComponent(this.viewInformationArea.asJComponent());
|
421 |
} |
422 |
m_TOC.setVisible(true);
|
423 |
tempMainSplit.setRightComponent(m_MapControl); |
424 |
this.setLayout(new BorderLayout()); |
425 |
this.add(tempMainSplit, BorderLayout.CENTER); |
426 |
|
427 |
if (windowLayout != null) { |
428 |
try {
|
429 |
tempMainSplit.setDividerLocation(Integer.valueOf(
|
430 |
windowLayout.get("MainDivider.Location")).intValue());
|
431 |
if (windowLayout.get("TOCDivider.Location") != null) { |
432 |
tempSplitToc.setDividerLocation(Integer.valueOf(
|
433 |
windowLayout.get("TOCDivider.Location")).intValue());
|
434 |
} |
435 |
} catch (NumberFormatException ex) { |
436 |
PluginServices.getLogger().error( |
437 |
"Error restoring View properties");
|
438 |
} |
439 |
} |
440 |
|
441 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
442 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
443 |
ZoomOutListener zoomOutListener = new ZoomOutListener(m_MapControl);
|
444 |
m_MapControl.addBehavior("zoomOut", new PointBehavior(zoomOutListener)); |
445 |
|
446 |
// Zoom por rect?ngulo
|
447 |
ZoomInListener zoomInListener = new ZoomInListener(m_MapControl);
|
448 |
m_MapControl.addBehavior("zoomIn", new Behavior[]{ |
449 |
new RectangleBehavior(zoomInListener),
|
450 |
new PointBehavior(zoomOutListener, Behavior.BUTTON_RIGHT)});
|
451 |
|
452 |
// pan
|
453 |
PanListener panListener = new PanListener(m_MapControl);
|
454 |
m_MapControl.addBehavior("pan", new MoveBehavior(panListener,Behavior.BUTTON_LEFT)); |
455 |
|
456 |
// Medir
|
457 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
458 |
m_MapControl.addBehavior("medicion", new PolylineBehavior(mli)); |
459 |
|
460 |
// Area
|
461 |
AreaListener ali = new AreaListener(m_MapControl);
|
462 |
m_MapControl.addBehavior("area", new PolygonBehavior(ali)); |
463 |
|
464 |
// Angulo
|
465 |
AngleGeometryListener agl = new AngleGeometryListener(m_MapControl);
|
466 |
m_MapControl.addBehavior("feature-angle", new TwoLinesBehavior(agl)); |
467 |
|
468 |
// Info por punto
|
469 |
InfoListener il = new InfoListener(m_MapControl);
|
470 |
m_MapControl.addBehavior("info", new PointBehavior(il)); |
471 |
|
472 |
// Identificacion de capa
|
473 |
IdentifyLayerListener ill = new IdentifyLayerListener(m_MapControl);
|
474 |
m_MapControl.addBehavior("identifylayer", new Behavior[] { |
475 |
new PointBehavior(ill),
|
476 |
new RectangleBehavior(ill)
|
477 |
} |
478 |
); |
479 |
|
480 |
// Seleccion por punto
|
481 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
482 |
m_MapControl.addBehavior("pointSelection", new PointBehavior(psl)); |
483 |
|
484 |
// Selecci?n por rect?ngulo
|
485 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
486 |
m_MapControl.addBehavior("rectSelection", new RectangleBehavior(rsl)); |
487 |
|
488 |
// Selecci?n por pol?gono
|
489 |
PolygonSelectListener poligSel = new PolygonSelectListener(m_MapControl);
|
490 |
m_MapControl.addBehavior("polSelection", new PolygonBehavior(poligSel)); |
491 |
|
492 |
m_MapControl.setTool("zoomIn");
|
493 |
|
494 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n
|
495 |
// en la barra de estado
|
496 |
StatusBarListener statusBarListener = new StatusBarListener(m_MapControl);
|
497 |
|
498 |
m_MapControl.addCombinedBehavior(new MouseMovementBehavior(statusBarListener));
|
499 |
m_MapControl.addCombinedBehavior(new MouseWheelBehavior());
|
500 |
m_MapControl.addCombinedBehavior(new MoveBehavior(panListener, Behavior.BUTTON_MIDDLE));
|
501 |
|
502 |
Supplier<Envelope> bboxSupplier = new Supplier<Envelope>() {
|
503 |
@Override
|
504 |
public Envelope get() {
|
505 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
506 |
Document activeView = application.getActiveDocument(ViewManager.TYPENAME);
|
507 |
if( activeView == getDocument() ) {
|
508 |
MapContext mapContext = getMapControl().getMapContext(); |
509 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
510 |
return env;
|
511 |
} |
512 |
return null; |
513 |
} |
514 |
}; |
515 |
m_MapControl.addFocusListener(new FocusAdapter() { |
516 |
@Override
|
517 |
@SuppressWarnings("Convert2Lambda") |
518 |
public void focusGained(FocusEvent e) { |
519 |
DALSwingLocator.getDataSwingManager().setCurrentBoundingBox(new Supplier<Envelope>() {
|
520 |
@Override
|
521 |
public Envelope get() {
|
522 |
MapContext mapContext = getMapControl().getMapContext(); |
523 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
524 |
return env;
|
525 |
} |
526 |
}); |
527 |
} |
528 |
}); |
529 |
m_MapControl.getMapContext().getViewPort().addViewPortListener(new ViewPortListener() {
|
530 |
@Override
|
531 |
@SuppressWarnings("Convert2Lambda") |
532 |
public void extentChanged(ExtentEvent e) { |
533 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
534 |
Document activeView = application.getActiveDocument(ViewManager.TYPENAME);
|
535 |
if (activeView == getDocument()) {
|
536 |
DALSwingLocator.getDataSwingManager().setCurrentBoundingBox(new Supplier<Envelope>() {
|
537 |
@Override
|
538 |
public Envelope get() {
|
539 |
MapContext mapContext = getMapControl().getMapContext(); |
540 |
Envelope env = mapContext.getViewPort().getEnvelope(); |
541 |
return env;
|
542 |
} |
543 |
}); |
544 |
} |
545 |
} |
546 |
|
547 |
@Override
|
548 |
public void backColorChanged(ColorEvent e) { |
549 |
} |
550 |
|
551 |
@Override
|
552 |
public void projectionChanged(ProjectionEvent e) { |
553 |
} |
554 |
}); |
555 |
} |
556 |
|
557 |
public void windowActivated() { |
558 |
super.windowActivated();
|
559 |
|
560 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar(); |
561 |
MapContext mapContext = this.getMapControl().getMapContext();
|
562 |
|
563 |
statusbar.setMessage("units",
|
564 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
565 |
statusbar.setControlValue("view-change-scale",
|
566 |
String.valueOf(mapContext.getScaleView()));
|
567 |
IProjection proj = getMapControl().getViewPort().getProjection(); |
568 |
if (proj != null) { |
569 |
statusbar.setMessage("projection", proj.getAbrev());
|
570 |
} else {
|
571 |
statusbar.setMessage("projection", ""); |
572 |
} |
573 |
} |
574 |
|
575 |
public void windowClosed() { |
576 |
super.windowClosed();
|
577 |
if (viewPortListener != null) { |
578 |
getMapControl().getViewPort().removeViewPortListener( |
579 |
viewPortListener); |
580 |
} |
581 |
if (getMapOverview() != null) { |
582 |
getMapOverview().getViewPort().removeViewPortListener( |
583 |
getMapOverview()); |
584 |
} |
585 |
|
586 |
} |
587 |
|
588 |
public void toPalette() { |
589 |
isPalette = true;
|
590 |
m_MapLoc.setPreferredSize(new Dimension(200, 150)); |
591 |
m_MapLoc.setSize(new Dimension(200, 150)); |
592 |
movp = new MapOverViewPalette(m_MapLoc, this); |
593 |
PluginServices.getMDIManager().addWindow(movp); |
594 |
FLayer[] layers
|
595 |
= getViewDocument().getMapContext().getLayers().getActives(); |
596 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) { |
597 |
if (((FLyrVect) layers[0]).isEditing()) { |
598 |
showConsole(); |
599 |
return;
|
600 |
} |
601 |
} |
602 |
hideConsole(); |
603 |
|
604 |
} |
605 |
|
606 |
public void restore() { |
607 |
isPalette = false;
|
608 |
PluginServices.getMDIManager().closeWindow(movp); |
609 |
FLayer[] layers
|
610 |
= getViewDocument().getMapContext().getLayers().getActives(); |
611 |
if (layers.length > 0 && layers[0] instanceof FLyrVect) { |
612 |
if (((FLyrVect) layers[0]).isEditing()) { |
613 |
showConsole(); |
614 |
return;
|
615 |
} |
616 |
} |
617 |
hideConsole(); |
618 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
619 |
tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
620 |
tempSplitToc.setBottomComponent(m_MapLoc); |
621 |
tempSplitToc.setResizeWeight(0.7);
|
622 |
tempMainSplit.setLeftComponent(tempSplitToc); |
623 |
} |
624 |
|
625 |
/**
|
626 |
* Sets the default map overview background color that will be used in
|
627 |
* subsequent projects.
|
628 |
*
|
629 |
* @param color
|
630 |
* @deprecated use instead
|
631 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
632 |
*/
|
633 |
public static void setDefaultMapOverViewBackColor(Color color) { |
634 |
DefaultProject.getPreferences().setDefaultOverviewBackColor(color); |
635 |
} |
636 |
|
637 |
/**
|
638 |
* Returns the current default map overview background color defined which
|
639 |
* is the color defined when the user does not define any other one
|
640 |
*
|
641 |
* @return java.awt.Color
|
642 |
* @deprecated use instead
|
643 |
* Project.getPreferences().setDefaultMapoverViewBackColor
|
644 |
*/
|
645 |
public static Color getDefaultMapOverViewBackColor() { |
646 |
return DefaultProject.getPreferences().getDefaultOverviewBackColor();
|
647 |
} |
648 |
|
649 |
/**
|
650 |
* Returns the current default view background color defined which is the
|
651 |
* color defined when the user does not define any other one
|
652 |
*
|
653 |
* @return java.awt.Color
|
654 |
* @deprecated use instead Project.getPreferences().getDefaultViewBackColor
|
655 |
*/
|
656 |
public static Color getDefaultBackColor() { |
657 |
return DefaultProject.getPreferences().getDefaultViewBackColor();
|
658 |
} |
659 |
|
660 |
/**
|
661 |
* @param color
|
662 |
* @deprecated use instead Project.getPreferences().setDefaultViewBackColor
|
663 |
*/
|
664 |
public static void setDefaultBackColor(Color color) { |
665 |
DefaultProject.getPreferences().setDefaultViewBackColor(color); |
666 |
} |
667 |
|
668 |
public Object getWindowProfile() { |
669 |
return WindowInfo.EDITOR_PROFILE;
|
670 |
} |
671 |
|
672 |
/* (non-Javadoc)
|
673 |
* @see org.gvsig.tools.observer.Observer#update(org.gvsig.tools.observer.Observable, java.lang.Object)
|
674 |
*/
|
675 |
public void update(final Observable observable, final Object notification) { |
676 |
|
677 |
if (notification instanceof FeatureStoreNotification) { |
678 |
FeatureStoreNotification event |
679 |
= (FeatureStoreNotification) notification; |
680 |
if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
|
681 |
|| event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
682 |
|
683 |
if (!SwingUtilities.isEventDispatchThread()) { |
684 |
SwingUtilities.invokeLater(new Runnable() { |
685 |
public void run() { |
686 |
update(observable, notification); |
687 |
} |
688 |
}); |
689 |
return;
|
690 |
} |
691 |
getMapControl().setTool("zoomIn");
|
692 |
hideConsole(); |
693 |
repaintMap(); |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
private static boolean disableConsole = false; |
699 |
|
700 |
public static void setDisableConsole(boolean disable) { |
701 |
disableConsole = disable; |
702 |
} |
703 |
|
704 |
} |