root / branches / v2_0_0_prep / extensions / org.gvsig.annotation.app / org.gvsig.annotation.app.extension / src / main / java / org / gvsig / annotation / app / extension / AnnotationExtension.java @ 38194
History | View | Annotate | Download (5.38 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.annotation.app.extension; |
23 |
|
24 |
import java.util.Locale; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.messages.NotificationManager; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.annotation.AnnotationCreationService; |
30 |
import org.gvsig.annotation.AnnotationLocator; |
31 |
import org.gvsig.annotation.AnnotationManager; |
32 |
import org.gvsig.annotation.swing.AnnotationSwingLocator; |
33 |
import org.gvsig.annotation.swing.AnnotationSwingManager; |
34 |
import org.gvsig.annotation.swing.AnnotationWindowManager; |
35 |
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.ApplicationManager; |
38 |
import org.gvsig.app.project.documents.view.ViewDocument; |
39 |
import org.gvsig.app.project.documents.view.ViewManager; |
40 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
43 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
44 |
import org.gvsig.i18n.Messages; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
47 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
48 |
import org.gvsig.tools.service.ServiceException; |
49 |
|
50 |
/**
|
51 |
* Andami extension to show Annotation in the application.
|
52 |
*
|
53 |
* @author gvSIG Team
|
54 |
* @version $Id$
|
55 |
*/
|
56 |
public class AnnotationExtension extends Extension { |
57 |
private AnnotationManager manager;
|
58 |
private AnnotationSwingManager swingManager;
|
59 |
|
60 |
public void initialize() { |
61 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
62 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
63 |
|
64 |
ep.append("AnnotationPreferencesPage", "", new AnnotationPreferencesPage()); |
65 |
|
66 |
PluginServices.getIconTheme().registerDefault( |
67 |
"annotation-properties",
|
68 |
AnnotationPreferencesPage.class.getClassLoader().getResource("images/AnnotationProperties.png")
|
69 |
); |
70 |
|
71 |
if (!Messages.hasLocales()) {
|
72 |
Messages.addLocale(Locale.getDefault());
|
73 |
} |
74 |
Messages.addResourceFamily("org.gvsig.annotation.app.extension.i18n.text",
|
75 |
AnnotationExtension.class.getClassLoader(), |
76 |
AnnotationExtension.class.getClass().getName()); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void postInitialize() { |
81 |
super.postInitialize();
|
82 |
manager = AnnotationLocator.getManager(); |
83 |
// Asignamos el locator e iniciamos la instancia
|
84 |
swingManager = AnnotationSwingLocator.getSwingManager(); |
85 |
|
86 |
swingManager.registerWindowManager(new GvSIGAnnotationWindowManager());
|
87 |
|
88 |
} |
89 |
|
90 |
private FLyrVect getCurrentLayer() {
|
91 |
return this.getCurrentLayer(null); |
92 |
} |
93 |
|
94 |
private FLyrVect getCurrentLayer(MapContext mapContext) {
|
95 |
FLyrVect layer = null;
|
96 |
|
97 |
if( mapContext == null ) { |
98 |
ApplicationManager application = ApplicationLocator.getManager(); |
99 |
|
100 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
101 |
if( view == null ) { |
102 |
return null; |
103 |
} |
104 |
mapContext = view.getMapContext(); |
105 |
} |
106 |
FLayer[] actives = mapContext.getLayers().getActives();
|
107 |
|
108 |
for (int i=0 ; i<actives.length ; i++){ |
109 |
if (actives[i] instanceof FLyrVect){ |
110 |
layer = (FLyrVect)actives[i]; |
111 |
break;
|
112 |
} |
113 |
} |
114 |
return layer;
|
115 |
} |
116 |
|
117 |
public void execute(String actionCommand) { |
118 |
ApplicationManager application = ApplicationLocator.getManager(); |
119 |
|
120 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
121 |
if( view == null ) { |
122 |
return;
|
123 |
} |
124 |
MapContext mapContext = view.getMapContext(); |
125 |
FLyrVect layer = getCurrentLayer(mapContext); |
126 |
if (layer == null){ |
127 |
return;
|
128 |
} |
129 |
showAnnotation(manager, layer.getFeatureStore(), mapContext); |
130 |
} |
131 |
|
132 |
public void showAnnotation(AnnotationManager manager, FeatureStore featureStore, MapContext mapContext) { |
133 |
try {
|
134 |
AnnotationCreationService service = |
135 |
(AnnotationCreationService) manager.getAnnotationCreationService(featureStore); |
136 |
service.setAnnotationCreationFinishAction(new AddLayerFinishAction(mapContext));
|
137 |
|
138 |
JAnnotationCreationServicePanel panel = |
139 |
swingManager.createAnnotation(service); |
140 |
swingManager.getWindowManager().showWindow(panel, "Annotation",
|
141 |
AnnotationWindowManager.MODE_WINDOW); |
142 |
|
143 |
} catch (ServiceException e) {
|
144 |
NotificationManager.addError(e); |
145 |
} |
146 |
} |
147 |
|
148 |
public boolean isEnabled() { |
149 |
FLayer layer = getCurrentLayer(); |
150 |
if( layer == null ) { |
151 |
return false; |
152 |
} |
153 |
return true; |
154 |
} |
155 |
|
156 |
public boolean isVisible() { |
157 |
ApplicationManager application = ApplicationLocator.getManager(); |
158 |
|
159 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
160 |
if( view == null ) { |
161 |
return false; |
162 |
} |
163 |
return true; |
164 |
} |
165 |
} |