svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / extension / FFrameViewExtension.java @ 280
History | View | Annotate | Download (5.21 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.actioninfo.ActionInfoManager; |
30 |
import org.gvsig.andami.messages.NotificationManager; |
31 |
import org.gvsig.andami.plugins.Extension; |
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
33 |
import org.gvsig.app.ApplicationLocator; |
34 |
import org.gvsig.app.ApplicationManager; |
35 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
36 |
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView; |
37 |
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap; |
38 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
39 |
import org.gvsig.fmap.dal.exception.ReadException; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.dataTypes.DataTypes; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
* Extensi?n preparada para controlar las opciones que se pueden realizar sobre
|
47 |
* una vista a?adida en el Layout.
|
48 |
*
|
49 |
* @author Vicente Caballero Navarro
|
50 |
*/
|
51 |
public class FFrameViewExtension extends Extension { |
52 |
|
53 |
private static Logger logger = LoggerFactory.getLogger(FFrameViewExtension.class); |
54 |
|
55 |
/**
|
56 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
57 |
*/
|
58 |
public void initialize() { |
59 |
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String, Object[])
|
64 |
*/
|
65 |
public void execute(String command, Object[] args) { |
66 |
if (command.endsWith("view-change-scale")) { |
67 |
ApplicationManager manager = ApplicationLocator.getManager(); |
68 |
IWindow window = manager.getActiveWindow(); |
69 |
if (!(window instanceof LayoutPanel)) { |
70 |
return;
|
71 |
} |
72 |
LayoutPanel layout = (LayoutPanel) window; |
73 |
try {
|
74 |
if (args.length>0) { |
75 |
Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
76 |
if (layout!=null && |
77 |
layout.getLayoutControl()!=null &&
|
78 |
layout.getLayoutControl().getLayoutFunctions()!=null) {
|
79 |
layout.getLayoutControl().getLayoutFunctions().setScale(scale); |
80 |
} |
81 |
} |
82 |
} catch (Throwable ex) { |
83 |
logger.info("Can't change scale of view.", ex);
|
84 |
ApplicationLocator.getManager().message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
85 |
} |
86 |
} |
87 |
else {
|
88 |
execute(command); |
89 |
} |
90 |
} |
91 |
|
92 |
/**
|
93 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
94 |
*/
|
95 |
public void execute(String s) { |
96 |
LayoutPanel layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
97 |
|
98 |
if (s.compareTo("layout-view-navigation-zoom-in-topoint") == 0) { |
99 |
layout.getLayoutControl().setTool("layoutviewzoomin");
|
100 |
} else if (s.compareTo("layout-view-navigation-zoom-out-topoint") == 0) { |
101 |
layout.getLayoutControl().setTool("layoutviewzoomout");
|
102 |
} else if (s.compareTo("layout-view-navigation-zoom-all") == 0) { |
103 |
try {
|
104 |
layout.getLayoutControl().viewFull(); |
105 |
} catch (ReadException e) {
|
106 |
NotificationManager.addError("Error de Driver", e);
|
107 |
} |
108 |
} |
109 |
else {
|
110 |
return;
|
111 |
} |
112 |
layout.getDocument().setModified(true);
|
113 |
} |
114 |
|
115 |
|
116 |
/**
|
117 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
118 |
*/
|
119 |
public boolean isEnabled() { |
120 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
121 |
if (window instanceof LayoutPanel) { |
122 |
LayoutPanel l = |
123 |
(LayoutPanel) PluginServices.getMDIManager().getActiveWindow(); |
124 |
if (!l.getLayoutContext().isEditable()) {
|
125 |
return false; |
126 |
} |
127 |
IFFrameUseFMap[] fframes = l.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
|
128 |
if (fframes.length==1 && !(fframes[0] instanceof FFrameOverView)) { |
129 |
IFFrameUseFMap fframeview = (IFFrameUseFMap) fframes[0];
|
130 |
if (fframeview.getScaleType()==IFFrameUseFMap.SCALE_TYPE.NORMAL) {
|
131 |
return true; |
132 |
} |
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 |
return true; |
150 |
} else {
|
151 |
return false; |
152 |
} |
153 |
} |
154 |
} |