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