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 | 33274 | jpiera | /* 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 | 37429 | jpiera | import java.util.Locale; |
25 | |||
26 | 33274 | jpiera | 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 | 38194 | vacevedo | import org.gvsig.app.ApplicationLocator; |
37 | import org.gvsig.app.ApplicationManager; |
||
38 | 33274 | jpiera | import org.gvsig.app.project.documents.view.ViewDocument; |
39 | 38194 | vacevedo | import org.gvsig.app.project.documents.view.ViewManager; |
40 | 33274 | jpiera | 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 | 37429 | jpiera | import org.gvsig.i18n.Messages; |
45 | 33278 | jpiera | import org.gvsig.tools.ToolsLocator; |
46 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
47 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
48 | 33274 | jpiera | 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 | 33278 | jpiera | 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 | 37429 | jpiera | |
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 | 33274 | jpiera | } |
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 | 37429 | jpiera | swingManager.registerWindowManager(new GvSIGAnnotationWindowManager());
|
87 | |||
88 | 33274 | jpiera | } |
89 | |||
90 | 38194 | vacevedo | 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 | 33278 | jpiera | |
100 | 38194 | vacevedo | 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 | 33278 | jpiera | |
108 | 38194 | vacevedo | for (int i=0 ; i<actives.length ; i++){ |
109 | if (actives[i] instanceof FLyrVect){ |
||
110 | layer = (FLyrVect)actives[i]; |
||
111 | break;
|
||
112 | 33274 | jpiera | } |
113 | 38194 | vacevedo | } |
114 | return layer;
|
||
115 | } |
||
116 | |||
117 | public void execute(String actionCommand) { |
||
118 | ApplicationManager application = ApplicationLocator.getManager(); |
||
119 | 33278 | jpiera | |
120 | 38194 | vacevedo | ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
121 | if( view == null ) { |
||
122 | return;
|
||
123 | 33274 | jpiera | } |
124 | 38194 | vacevedo | MapContext mapContext = view.getMapContext(); |
125 | FLyrVect layer = getCurrentLayer(mapContext); |
||
126 | if (layer == null){ |
||
127 | return;
|
||
128 | } |
||
129 | showAnnotation(manager, layer.getFeatureStore(), mapContext); |
||
130 | 33274 | jpiera | } |
131 | |||
132 | 38194 | vacevedo | public void showAnnotation(AnnotationManager manager, FeatureStore featureStore, MapContext mapContext) { |
133 | 33274 | jpiera | try {
|
134 | AnnotationCreationService service = |
||
135 | (AnnotationCreationService) manager.getAnnotationCreationService(featureStore); |
||
136 | 38194 | vacevedo | service.setAnnotationCreationFinishAction(new AddLayerFinishAction(mapContext));
|
137 | 33278 | jpiera | |
138 | 33274 | jpiera | JAnnotationCreationServicePanel panel = |
139 | swingManager.createAnnotation(service); |
||
140 | swingManager.getWindowManager().showWindow(panel, "Annotation",
|
||
141 | 36679 | jpiera | AnnotationWindowManager.MODE_WINDOW); |
142 | 33274 | jpiera | |
143 | } catch (ServiceException e) {
|
||
144 | NotificationManager.addError(e); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | public boolean isEnabled() { |
||
149 | 38194 | vacevedo | FLayer layer = getCurrentLayer(); |
150 | if( layer == null ) { |
||
151 | return false; |
||
152 | 33274 | jpiera | } |
153 | 38194 | vacevedo | return true; |
154 | 33274 | jpiera | } |
155 | |||
156 | public boolean isVisible() { |
||
157 | 38194 | vacevedo | ApplicationManager application = ApplicationLocator.getManager(); |
158 | 33274 | jpiera | |
159 | 38194 | vacevedo | ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
160 | if( view == null ) { |
||
161 | 33274 | jpiera | return false; |
162 | } |
||
163 | 38194 | vacevedo | return true; |
164 | 33274 | jpiera | } |
165 | } |