svn-document-layout / branches / usability_v2 / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / extension / FFrameViewExtension.java @ 140
History | View | Annotate | Download (5.63 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.extension; |
23 |
|
24 |
import javax.swing.JOptionPane; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.PluginsLocator; |
28 |
import org.gvsig.andami.PluginsManager; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.app.ApplicationLocator; |
33 |
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView; |
34 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
35 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
36 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
37 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
38 |
import org.gvsig.fmap.dal.exception.ReadException; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dataTypes.DataTypes; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
/**
|
45 |
* Extensi?n preparada para controlar las opciones que se pueden realizar sobre
|
46 |
* una vista a?adida en el Layout.
|
47 |
*
|
48 |
* @author Vicente Caballero Navarro
|
49 |
*/
|
50 |
public class FFrameViewExtension extends Extension { |
51 |
|
52 |
private LayoutPanel layout = null; |
53 |
private static Logger logger = LoggerFactory.getLogger(FFrameViewExtension.class); |
54 |
//.info("Can't change scale of view.", ex);
|
55 |
|
56 |
/**
|
57 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
58 |
*/
|
59 |
public void initialize() { |
60 |
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String, Object[])
|
65 |
*/
|
66 |
public void execute(String command, Object[] args) { |
67 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
68 |
if (command.endsWith("view-change-scale")) { |
69 |
try {
|
70 |
if (args.length>0) { |
71 |
Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
72 |
if (layout!=null && |
73 |
layout.getLayoutControl()!=null &&
|
74 |
layout.getLayoutControl().getLayoutFunctions()!=null) {
|
75 |
layout.getLayoutControl().getLayoutFunctions().setScale(scale); |
76 |
} |
77 |
} |
78 |
} catch (Throwable ex) { |
79 |
logger.info("Can't change scale of view.", ex);
|
80 |
ApplicationLocator.getManager().message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
81 |
} |
82 |
} |
83 |
else {
|
84 |
execute(command); |
85 |
} |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
90 |
*/
|
91 |
public void execute(String s) { |
92 |
layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
93 |
|
94 |
if (s.compareTo("layout-view-navigation-zoom-in-topoint") == 0) { |
95 |
layout.getLayoutControl().setTool("layoutviewzoomin");
|
96 |
} else if (s.compareTo("layout-view-navigation-zoom-out-topoint") == 0) { |
97 |
layout.getLayoutControl().setTool("layoutviewzoomout");
|
98 |
} else if (s.compareTo("layout-view-navigation-zoom-all") == 0) { |
99 |
try {
|
100 |
layout.getLayoutControl().viewFull(); |
101 |
} catch (ReadException e) {
|
102 |
NotificationManager.addError("Error de Driver", e);
|
103 |
} |
104 |
} else if (s.compareTo("layout-view-navigation-pan") == 0) { |
105 |
layout.getLayoutControl().setTool("layoutviewpan");
|
106 |
} else if (s.compareTo("layout-view-add-layer") == 0) { |
107 |
PluginsManager manager = PluginsLocator.getManager(); |
108 |
AddLayer plugin = (AddLayer) manager.getExtension(AddLayer.class); |
109 |
IFFrameUseFMap[] fframes = this.layout.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class); |
110 |
if (fframes.length>0) { |
111 |
plugin.addLayers(fframes[0].getMapContext());
|
112 |
fframes[0].refresh();
|
113 |
} |
114 |
} |
115 |
layout.getDocument().setModified(true);
|
116 |
} |
117 |
|
118 |
|
119 |
/**
|
120 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
121 |
*/
|
122 |
public boolean isEnabled() { |
123 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
124 |
if (window instanceof LayoutPanel) { |
125 |
LayoutPanel l = |
126 |
(LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
127 |
if (!l.getLayoutContext().isEditable()) {
|
128 |
return false; |
129 |
} |
130 |
IFFrameUseFMap[] fframes = l.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
|
131 |
if (fframes.length==1 && !(fframes[0] instanceof FFrameOverView)) { |
132 |
return true; |
133 |
} |
134 |
} |
135 |
return false; |
136 |
} |
137 |
|
138 |
/**
|
139 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
140 |
*/
|
141 |
public boolean isVisible() { |
142 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
143 |
|
144 |
if (f == null) { |
145 |
return false; |
146 |
} |
147 |
|
148 |
if (f instanceof LayoutPanel) { |
149 |
// Layout layout = (Layout) f;
|
150 |
|
151 |
return true; // layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() |
152 |
// > 0;
|
153 |
} else {
|
154 |
return false; |
155 |
} |
156 |
} |
157 |
} |