root / trunk / extensions / extHyperlink / src / org / gvsig / hyperlink / LinkControls.java @ 28132
History | View | Annotate | Download (8.15 KB)
1 |
/*
|
---|---|
2 |
* Created on 01-jun-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.gvsig.hyperlink; |
48 |
|
49 |
import org.apache.log4j.Logger; |
50 |
import org.gvsig.hyperlink.actions.ImgFormat; |
51 |
import org.gvsig.hyperlink.actions.LoadRasterLayer; |
52 |
import org.gvsig.hyperlink.actions.LoadVectorLayer; |
53 |
import org.gvsig.hyperlink.actions.PdfFormat; |
54 |
import org.gvsig.hyperlink.actions.SvgFormat; |
55 |
import org.gvsig.hyperlink.actions.TxtFormat; |
56 |
import org.gvsig.hyperlink.config.LayerLinkConfig; |
57 |
import org.gvsig.hyperlink.config.gui.ConfigTab; |
58 |
import org.gvsig.hyperlink.layers.ManagerRegistry; |
59 |
import org.gvsig.hyperlink.layers.VectLayerManager; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.andami.plugins.Extension; |
63 |
import com.iver.cit.gvsig.fmap.MapContext; |
64 |
import com.iver.cit.gvsig.fmap.MapControl; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
67 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
68 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
69 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
70 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
71 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.General; |
72 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ThemeManagerWindow; |
73 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
74 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
75 |
|
76 |
|
77 |
/**
|
78 |
* Extensi?n para gestionar los hiperlinks.
|
79 |
*
|
80 |
* @author Cesar Martinez Izquierdo
|
81 |
* @author Vicente Caballero Navarro
|
82 |
*/
|
83 |
public class LinkControls extends Extension { |
84 |
private static Logger logger = Logger.getLogger(LinkControls.class.getName()); |
85 |
ManagerRegistry layerManager; |
86 |
public static final String LAYERPROPERTYNAME = "org.gvsig.hyperlink.config"; |
87 |
public static final String TOOLNAME = "org.gvsig.hyperlink.tool"; |
88 |
public static final String ACTIONSEXTENSIONPOINT = "HyperLinkAction"; |
89 |
|
90 |
private static final int LEGACY_IMAGE_TYPE = 0; |
91 |
private static final int LEGACY_HTML_TYPE = 1; |
92 |
private static final int LEGACY_PDF_TYPE = 2; |
93 |
private static final int LEGACY_SVG_TYPE = 3; |
94 |
|
95 |
/*
|
96 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
97 |
*/
|
98 |
public void execute(String s) { |
99 |
View view = (View) PluginServices.getMDIManager().getActiveWindow(); |
100 |
MapControl mapCtrl = view.getMapControl(); |
101 |
logger.debug("Comand : " + s);
|
102 |
|
103 |
if (s.compareTo("HYPERLINK") == 0) { |
104 |
initTool(view); |
105 |
mapCtrl.setTool(TOOLNAME); |
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Inits the tool for the provided view.
|
111 |
* @param view
|
112 |
*/
|
113 |
public void initTool(View view) { |
114 |
MapControl mapCtrl = view.getMapControl(); |
115 |
if (view.getMapControl().getNamesMapTools().get(TOOLNAME) == null) { |
116 |
mapCtrl.addMapTool(TOOLNAME, new PointBehavior(new LinkListener(mapCtrl, layerManager))); |
117 |
loadLegacyConfig(view); |
118 |
} |
119 |
} |
120 |
|
121 |
public void loadLegacyConfig(View view) { |
122 |
LayersIterator iterator = new LayersIterator(view.getMapControl().getMapContext().getLayers());
|
123 |
while (iterator.hasNext()) {
|
124 |
FLayer layer = iterator.nextLayer(); |
125 |
loadLegacyConfig(layer); |
126 |
} |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Returns a LayerLinkConfig object if an old-style or new-style hyperlink was found and configured,
|
131 |
* or null otherwise.
|
132 |
* @param layer
|
133 |
*/
|
134 |
public LayerLinkConfig loadLegacyConfig(FLayer layer) {
|
135 |
LayerLinkConfig layerConfig = (LayerLinkConfig) layer.getProperty(LinkControls.LAYERPROPERTYNAME); |
136 |
if (layerConfig!=null) { // don't apply compatibility if the layer already has new 1.9.0 configuration |
137 |
return layerConfig;
|
138 |
} |
139 |
Object fName = layer.getProperty("legacy.hyperlink.selectedField"); |
140 |
if (fName!=null && fName instanceof String) { |
141 |
String fieldName = (String) fName; |
142 |
Object extObj = layer.getProperty("legacy.hyperlink.extension"); |
143 |
String extension = null; |
144 |
if (extObj!=null && extObj instanceof String) { |
145 |
extension = (String) extObj;
|
146 |
} |
147 |
Object typeObj = layer.getProperty("legacy.hyperlink.type"); |
148 |
int type = -1; |
149 |
if (typeObj!=null && typeObj instanceof Integer) { |
150 |
type = ((Integer) typeObj).intValue();
|
151 |
} |
152 |
LayerLinkConfig config = new LayerLinkConfig();
|
153 |
config.setEnabled(true);
|
154 |
config.addLink(getLegacyActionCode(type), fieldName, extension); |
155 |
layer.setProperty(LinkControls.LAYERPROPERTYNAME, config); |
156 |
return config;
|
157 |
} |
158 |
return null; |
159 |
} |
160 |
|
161 |
private String getLegacyActionCode(int type) { |
162 |
switch (type) {
|
163 |
case LEGACY_IMAGE_TYPE:
|
164 |
return ImgFormat.actionCode;
|
165 |
case LEGACY_PDF_TYPE:
|
166 |
return PdfFormat.actionCode;
|
167 |
case LEGACY_SVG_TYPE:
|
168 |
return SvgFormat.actionCode;
|
169 |
case LEGACY_HTML_TYPE:
|
170 |
default:
|
171 |
return TxtFormat.actionCode;
|
172 |
} |
173 |
} |
174 |
|
175 |
/*
|
176 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
177 |
*/
|
178 |
public boolean isVisible() { |
179 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
180 |
.getActiveWindow(); |
181 |
|
182 |
if (f == null) { |
183 |
return false; |
184 |
} |
185 |
|
186 |
if (f instanceof View) { |
187 |
|
188 |
MapContext mapa = ((View) f).getModel().getMapContext();
|
189 |
|
190 |
return mapa.getLayers().getLayersCount() > 0; |
191 |
} else {
|
192 |
return false; |
193 |
} |
194 |
} |
195 |
|
196 |
/*
|
197 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
198 |
*/
|
199 |
public boolean isEnabled() { |
200 |
View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
201 |
|
202 |
if (f == null) { |
203 |
return false; |
204 |
} |
205 |
|
206 |
if (f instanceof com.iver.cit.gvsig.project.documents.view.gui.BaseView) { |
207 |
com.iver.cit.gvsig.project.documents.view.gui.BaseView view = (com.iver.cit.gvsig.project.documents.view.gui.BaseView) f; |
208 |
IProjectView model = view.getModel(); |
209 |
|
210 |
if (model != null && |
211 |
model.getMapContext()!=null &&
|
212 |
model.getMapContext().getLayers().getVisibles().length>0)
|
213 |
return true; |
214 |
else
|
215 |
return false; |
216 |
|
217 |
} |
218 |
return true; |
219 |
} |
220 |
|
221 |
/*
|
222 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
223 |
*/
|
224 |
public void initialize() { |
225 |
registerLayers(); |
226 |
registerActions(); |
227 |
registerConfigPanel(); |
228 |
} |
229 |
|
230 |
private void registerLayers() { |
231 |
layerManager = new ManagerRegistry();
|
232 |
layerManager.put(FLyrVect.class, VectLayerManager.class); |
233 |
} |
234 |
|
235 |
public ManagerRegistry getLayerManager() {
|
236 |
return layerManager;
|
237 |
} |
238 |
|
239 |
private void registerActions(){ |
240 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
241 |
ILinkActionManager tmpAction = new TxtFormat();
|
242 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
243 |
tmpAction = new ImgFormat();
|
244 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
245 |
tmpAction = new PdfFormat();
|
246 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
247 |
tmpAction = new LoadRasterLayer();
|
248 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
249 |
tmpAction = new LoadVectorLayer();
|
250 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
251 |
tmpAction = new SvgFormat();
|
252 |
extensionPoints.add(ACTIONSEXTENSIONPOINT, tmpAction.getActionCode(), tmpAction); |
253 |
} |
254 |
|
255 |
private void registerConfigPanel() { |
256 |
// pages
|
257 |
ThemeManagerWindow.addPage(ConfigTab.class); |
258 |
|
259 |
ThemeManagerWindow.setTabEnabledForLayer(ConfigTab.class, FLyrVect.class, true);
|
260 |
} |
261 |
} |