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 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 41965 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 41965 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 41965 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
20 | 41965 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
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 | 47620 | jjdelcerro | import java.awt.event.FocusAdapter; |
29 | import java.awt.event.FocusEvent; |
||
30 | 40435 | jjdelcerro | import java.beans.PropertyChangeEvent; |
31 | import java.beans.PropertyChangeListener; |
||
32 | import java.util.HashMap; |
||
33 | import java.util.Iterator; |
||
34 | 46010 | jjdelcerro | import java.util.Map; |
35 | 47620 | jjdelcerro | import java.util.function.Supplier; |
36 | 40435 | jjdelcerro | |
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 | 45577 | fdiaz | import org.gvsig.andami.ui.mdiManager.IWindow; |
46 | 40435 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
47 | 45577 | fdiaz | import org.gvsig.app.ApplicationLocator; |
48 | import org.gvsig.app.ApplicationManager; |
||
49 | 40435 | jjdelcerro | 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 | 47489 | fdiaz | import org.gvsig.app.project.documents.view.ViewManager; |
54 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.toc.gui.TOC; |
55 | 45130 | omartinez | import org.gvsig.app.project.documents.view.toolListeners.AngleGeometryListener; |
56 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.toolListeners.AreaListener; |
57 | 46375 | jjdelcerro | import org.gvsig.app.project.documents.view.toolListeners.IdentifyLayerListener; |
58 | 40435 | jjdelcerro | 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 | 47620 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
69 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
70 | 40435 | jjdelcerro | 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 | 47620 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
78 | import org.gvsig.fmap.mapcontext.layers.LayerListener; |
||
79 | 40435 | jjdelcerro | 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 | 45130 | omartinez | import org.gvsig.fmap.mapcontrol.tools.Behavior.TwoLinesBehavior; |
84 | 40435 | jjdelcerro | 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 | 46010 | jjdelcerro | import org.gvsig.tools.util.PropertiesSupport; |
95 | import org.gvsig.tools.util.PropertiesSupportHelper; |
||
96 | 40435 | jjdelcerro | 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 | 41937 | fdiaz | *
|
125 | 40435 | jjdelcerro | * @author 2005- Vicente Caballero
|
126 | * @author 2009- Joaquin del Cerro
|
||
127 | 41937 | fdiaz | *
|
128 | 40435 | jjdelcerro | */
|
129 | 45728 | jjdelcerro | public class DefaultViewPanel |
130 | extends AbstractViewPanel
|
||
131 | 46010 | jjdelcerro | implements Observer, PropertiesSupport |
132 | 45728 | jjdelcerro | { |
133 | 40435 | jjdelcerro | |
134 | 41965 | jjdelcerro | /**
|
135 | *
|
||
136 | */
|
||
137 | private static final long serialVersionUID = -4044661458841786519L; |
||
138 | 41811 | llmarques | |
139 | 41965 | jjdelcerro | private JConsole console;
|
140 | private JDockPanel dockConsole = null; |
||
141 | protected ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
||
142 | protected boolean isShowConsole = false; |
||
143 | private ViewPortListener viewPortListener;
|
||
144 | 46010 | jjdelcerro | private PropertiesSupportHelper propertiesHelper;
|
145 | 40435 | jjdelcerro | |
146 | 41965 | jjdelcerro | private static MapControlManager mapControlManager = MapControlLocator |
147 | .getMapControlManager(); |
||
148 | 40435 | jjdelcerro | |
149 | 41965 | jjdelcerro | /**
|
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 | 46010 | jjdelcerro | this.propertiesHelper = new PropertiesSupportHelper(); |
158 | this.propertiesHelper.setProperty("View", this); |
||
159 | 41965 | jjdelcerro | 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 | 43576 | jjdelcerro | this.viewInformationArea = new DefaultViewInformationArea(); |
165 | 41965 | jjdelcerro | } |
166 | 40435 | jjdelcerro | |
167 | 41965 | jjdelcerro | public DefaultViewPanel(Document document) { |
168 | this();
|
||
169 | this.initialize(((ViewDocument) document).getMapContext());
|
||
170 | this.setDocument(document);
|
||
171 | } |
||
172 | 40435 | jjdelcerro | |
173 | 41965 | jjdelcerro | /**
|
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 | 43100 | jjdelcerro | * @param mapContext
|
179 | 41965 | jjdelcerro | */
|
180 | protected void initialize(MapContext mapContext) { |
||
181 | super.initialize();
|
||
182 | initComponents(mapContext); |
||
183 | hideConsole(); |
||
184 | getConsolePanel().addResponseListener(consoleResponseAdapter); |
||
185 | } |
||
186 | 40435 | jjdelcerro | |
187 | 41965 | jjdelcerro | public void setDocument(Document document) { |
188 | setModel((ViewDocument) document); |
||
189 | } |
||
190 | 40435 | jjdelcerro | |
191 | 41965 | jjdelcerro | public Document getDocument() { |
192 | return this.modelo; |
||
193 | } |
||
194 | 40435 | jjdelcerro | |
195 | 41965 | jjdelcerro | public void setModel(ViewDocument model) { |
196 | 45577 | fdiaz | final ApplicationManager application = ApplicationLocator.getApplicationManager();
|
197 | 41965 | jjdelcerro | this.modelo = model;
|
198 | // Se registra como listener de cambios en FMap
|
||
199 | MapContext fmap = modelo.getMapContext(); |
||
200 | 40435 | jjdelcerro | |
201 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
209 | 41965 | jjdelcerro | // Se configura el mapControl
|
210 | m_TOC.setMapContext(fmap); |
||
211 | 40435 | jjdelcerro | |
212 | 41965 | jjdelcerro | 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 | 45577 | fdiaz | |
228 | 41965 | jjdelcerro | if (m_MapControl.getViewPort() != null) { |
229 | viewPortListener = new ViewPortListener() {
|
||
230 | public void extentChanged(ExtentEvent e) { |
||
231 | 43439 | jjdelcerro | try {
|
232 | 47489 | fdiaz | Document activeDoc = application.getActiveDocument(ViewManager.TYPENAME);
|
233 | if(activeDoc != DefaultViewPanel.this.getDocument()) {
|
||
234 | 45577 | fdiaz | return;
|
235 | } |
||
236 | 43439 | jjdelcerro | if (PluginServices.getMainFrame() != null) { |
237 | 47805 | fdiaz | 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 | 43439 | jjdelcerro | } |
251 | } catch(Exception ex) { |
||
252 | logger.warn("Problems process 'extentChanged'.",ex);
|
||
253 | 41965 | jjdelcerro | } |
254 | } |
||
255 | 40435 | jjdelcerro | |
256 | 47799 | fdiaz | @Override
|
257 | 41965 | jjdelcerro | public void backColorChanged(ColorEvent e) { |
258 | // Do nothing
|
||
259 | } |
||
260 | 40435 | jjdelcerro | |
261 | 41965 | jjdelcerro | public void projectionChanged(ProjectionEvent e) { |
262 | m_MapLoc.setProjection(e.getNewProjection()); |
||
263 | } |
||
264 | }; |
||
265 | m_MapControl.getViewPort().addViewPortListener(viewPortListener); |
||
266 | } |
||
267 | } |
||
268 | 40435 | jjdelcerro | |
269 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
279 | 41965 | jjdelcerro | private JDockPanel getDockConsole() {
|
280 | if (dockConsole == null) { |
||
281 | dockConsole = new JDockPanel(getConsolePanel());
|
||
282 | } |
||
283 | return dockConsole;
|
||
284 | } |
||
285 | 40435 | jjdelcerro | |
286 | 41965 | jjdelcerro | public void addConsoleListener(String prefix, ResponseListener listener) { |
287 | consoleResponseAdapter.putSpaceListener(prefix, listener); |
||
288 | 40435 | jjdelcerro | |
289 | 41965 | jjdelcerro | } |
290 | 40435 | jjdelcerro | |
291 | 41965 | jjdelcerro | public void removeConsoleListener(ResponseListener listener) { |
292 | consoleResponseAdapter.deleteListener(listener); |
||
293 | 40435 | jjdelcerro | |
294 | 41965 | jjdelcerro | } |
295 | 40435 | jjdelcerro | |
296 | 41965 | jjdelcerro | public void focusConsole(String text) { |
297 | getConsolePanel().addResponseText(text); |
||
298 | 40435 | jjdelcerro | |
299 | 41965 | jjdelcerro | JEditTextArea jeta = getConsolePanel().getTxt(); |
300 | jeta.requestFocusInWindow(); |
||
301 | jeta.setCaretPosition(jeta.getText().length()); |
||
302 | 40435 | jjdelcerro | |
303 | 41965 | jjdelcerro | } |
304 | 40435 | jjdelcerro | |
305 | 41965 | jjdelcerro | public void hideConsole() { |
306 | isShowConsole = false;
|
||
307 | getDockConsole().setVisible(false);
|
||
308 | 40435 | jjdelcerro | |
309 | 41965 | jjdelcerro | } |
310 | 40435 | jjdelcerro | |
311 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
321 | 41965 | jjdelcerro | } |
322 | 40435 | jjdelcerro | |
323 | 46010 | jjdelcerro | @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 | 41965 | jjdelcerro | static class ResponseAdapter implements ResponseListener { |
339 | 40435 | jjdelcerro | |
340 | 41965 | jjdelcerro | private HashMap<String, ResponseListener> spaceListener |
341 | = new HashMap<String, ResponseListener>(); |
||
342 | 40435 | jjdelcerro | |
343 | 41965 | jjdelcerro | public void putSpaceListener(String namespace, ResponseListener listener) { |
344 | spaceListener.put(namespace, listener); |
||
345 | } |
||
346 | 40435 | jjdelcerro | |
347 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
356 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
372 | 41965 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
386 | 41965 | jjdelcerro | } |
387 | 40435 | jjdelcerro | |
388 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
398 | 41965 | jjdelcerro | m_MapControl.addExceptionListener(mapControlExceptionListener); |
399 | m_TOC = new TOC();
|
||
400 | 43576 | jjdelcerro | this.viewInformationArea.add(m_TOC, "TOC", 0, "ToC", null, "Table of contents"); |
401 | 40435 | jjdelcerro | |
402 | 41965 | jjdelcerro | // 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 | 40435 | jjdelcerro | |
413 | 41965 | jjdelcerro | if (windowLayout == null) { |
414 | m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
||
415 | tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
||
416 | } |
||
417 | 40435 | jjdelcerro | |
418 | 41965 | jjdelcerro | if (!isPalette()) {
|
419 | tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
||
420 | 43576 | jjdelcerro | tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
421 | 41965 | jjdelcerro | tempSplitToc.setBottomComponent(m_MapLoc); |
422 | tempSplitToc.setResizeWeight(0.7);
|
||
423 | tempMainSplit.setLeftComponent(tempSplitToc); |
||
424 | } else {
|
||
425 | 43576 | jjdelcerro | tempMainSplit.setLeftComponent(this.viewInformationArea.asJComponent());
|
426 | 41965 | jjdelcerro | } |
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 | 40435 | jjdelcerro | tempSplitToc.setDividerLocation(Integer.valueOf(
|
438 | 41965 | jjdelcerro | windowLayout.get("TOCDivider.Location")).intValue());
|
439 | } |
||
440 | } catch (NumberFormatException ex) { |
||
441 | PluginServices.getLogger().error( |
||
442 | "Error restoring View properties");
|
||
443 | } |
||
444 | } |
||
445 | 40435 | jjdelcerro | |
446 | 41965 | jjdelcerro | // 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 | 41973 | jjdelcerro | m_MapControl.addBehavior("zoomOut", new PointBehavior(zoomOutListener)); |
450 | 40435 | jjdelcerro | |
451 | 41965 | jjdelcerro | // Zoom por rect?ngulo
|
452 | ZoomInListener zoomInListener = new ZoomInListener(m_MapControl);
|
||
453 | m_MapControl.addBehavior("zoomIn", new Behavior[]{ |
||
454 | new RectangleBehavior(zoomInListener),
|
||
455 | 41971 | jjdelcerro | new PointBehavior(zoomOutListener, Behavior.BUTTON_RIGHT)});
|
456 | 40435 | jjdelcerro | |
457 | 41965 | jjdelcerro | // pan
|
458 | PanListener panListener = new PanListener(m_MapControl);
|
||
459 | 41971 | jjdelcerro | m_MapControl.addBehavior("pan", new MoveBehavior(panListener,Behavior.BUTTON_LEFT)); |
460 | 40435 | jjdelcerro | |
461 | 41965 | jjdelcerro | // Medir
|
462 | MeasureListener mli = new MeasureListener(m_MapControl);
|
||
463 | 41973 | jjdelcerro | m_MapControl.addBehavior("medicion", new PolylineBehavior(mli)); |
464 | 40435 | jjdelcerro | |
465 | 41965 | jjdelcerro | // Area
|
466 | AreaListener ali = new AreaListener(m_MapControl);
|
||
467 | 41973 | jjdelcerro | m_MapControl.addBehavior("area", new PolygonBehavior(ali)); |
468 | 45130 | omartinez | |
469 | // Angulo
|
||
470 | AngleGeometryListener agl = new AngleGeometryListener(m_MapControl);
|
||
471 | m_MapControl.addBehavior("feature-angle", new TwoLinesBehavior(agl)); |
||
472 | |||
473 | 41965 | jjdelcerro | // Info por punto
|
474 | InfoListener il = new InfoListener(m_MapControl);
|
||
475 | 41973 | jjdelcerro | m_MapControl.addBehavior("info", new PointBehavior(il)); |
476 | 40435 | jjdelcerro | |
477 | 46375 | jjdelcerro | // 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 | 41965 | jjdelcerro | // Seleccion por punto
|
486 | PointSelectListener psl = new PointSelectListener(m_MapControl);
|
||
487 | 41973 | jjdelcerro | m_MapControl.addBehavior("pointSelection", new PointBehavior(psl)); |
488 | 41965 | jjdelcerro | |
489 | // Selecci?n por rect?ngulo
|
||
490 | RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
||
491 | 41973 | jjdelcerro | m_MapControl.addBehavior("rectSelection", new RectangleBehavior(rsl)); |
492 | 40435 | jjdelcerro | |
493 | 41965 | jjdelcerro | // Selecci?n por pol?gono
|
494 | PolygonSelectListener poligSel = new PolygonSelectListener(m_MapControl);
|
||
495 | 41973 | jjdelcerro | m_MapControl.addBehavior("polSelection", new PolygonBehavior(poligSel)); |
496 | 41965 | jjdelcerro | |
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 | 40435 | jjdelcerro | m_MapControl.addCombinedBehavior(new MouseWheelBehavior());
|
505 | 41971 | jjdelcerro | m_MapControl.addCombinedBehavior(new MoveBehavior(panListener, Behavior.BUTTON_MIDDLE));
|
506 | 47620 | jjdelcerro | |
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 | 41965 | jjdelcerro | } |
561 | 40435 | jjdelcerro | |
562 | 41965 | jjdelcerro | public void windowActivated() { |
563 | super.windowActivated();
|
||
564 | 41937 | fdiaz | |
565 | 41965 | jjdelcerro | NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar(); |
566 | MapContext mapContext = this.getMapControl().getMapContext();
|
||
567 | 40435 | jjdelcerro | |
568 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
580 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
591 | 41965 | jjdelcerro | } |
592 | 40435 | jjdelcerro | |
593 | 41965 | jjdelcerro | 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 | 40435 | jjdelcerro | |
609 | 41965 | jjdelcerro | } |
610 | 40435 | jjdelcerro | |
611 | 41965 | jjdelcerro | 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 | 43576 | jjdelcerro | tempSplitToc.setTopComponent(this.viewInformationArea.asJComponent());
|
625 | 41965 | jjdelcerro | tempSplitToc.setBottomComponent(m_MapLoc); |
626 | tempSplitToc.setResizeWeight(0.7);
|
||
627 | tempMainSplit.setLeftComponent(tempSplitToc); |
||
628 | } |
||
629 | 40435 | jjdelcerro | |
630 | 41965 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
642 | 41965 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
654 | 41965 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
665 | 41965 | jjdelcerro | /**
|
666 | 43100 | jjdelcerro | * @param color
|
667 | 41965 | jjdelcerro | * @deprecated use instead Project.getPreferences().setDefaultViewBackColor
|
668 | */
|
||
669 | public static void setDefaultBackColor(Color color) { |
||
670 | DefaultProject.getPreferences().setDefaultViewBackColor(color); |
||
671 | } |
||
672 | 40435 | jjdelcerro | |
673 | 41965 | jjdelcerro | public Object getWindowProfile() { |
674 | return WindowInfo.EDITOR_PROFILE;
|
||
675 | } |
||
676 | 40435 | jjdelcerro | |
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 | 41965 | jjdelcerro | FeatureStoreNotification event |
684 | = (FeatureStoreNotification) notification; |
||
685 | 40435 | jjdelcerro | if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
|
686 | 41965 | jjdelcerro | || event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING) { |
687 | 40435 | jjdelcerro | |
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 | 41937 | fdiaz | |
703 | 41812 | llmarques | private static boolean disableConsole = false; |
704 | 41937 | fdiaz | |
705 | 41965 | jjdelcerro | public static void setDisableConsole(boolean disable) { |
706 | 41812 | llmarques | disableConsole = disable; |
707 | } |
||
708 | 41937 | fdiaz | |
709 | 40435 | jjdelcerro | } |