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