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 @ 37429
History | View | Annotate | Download (5.32 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.project.documents.view.ViewDocument; |
37 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
38 |
import org.gvsig.editing.EditionUtilities; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.mapcontext.MapContext; |
41 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
42 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
43 |
import org.gvsig.i18n.Messages; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
46 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
47 |
import org.gvsig.tools.service.ServiceException; |
48 |
|
49 |
/**
|
50 |
* Andami extension to show Annotation in the application.
|
51 |
*
|
52 |
* @author gvSIG Team
|
53 |
* @version $Id$
|
54 |
*/
|
55 |
public class AnnotationExtension extends Extension { |
56 |
private AnnotationManager manager;
|
57 |
private AnnotationSwingManager swingManager;
|
58 |
|
59 |
public void initialize() { |
60 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
61 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
62 |
|
63 |
ep.append("AnnotationPreferencesPage", "", new AnnotationPreferencesPage()); |
64 |
|
65 |
PluginServices.getIconTheme().registerDefault( |
66 |
"annotation-properties",
|
67 |
AnnotationPreferencesPage.class.getClassLoader().getResource("images/AnnotationProperties.png")
|
68 |
); |
69 |
|
70 |
if (!Messages.hasLocales()) {
|
71 |
Messages.addLocale(Locale.getDefault());
|
72 |
} |
73 |
Messages.addResourceFamily("org.gvsig.annotation.app.extension.i18n.text",
|
74 |
AnnotationExtension.class.getClassLoader(), |
75 |
AnnotationExtension.class.getClass().getName()); |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void postInitialize() { |
80 |
super.postInitialize();
|
81 |
manager = AnnotationLocator.getManager(); |
82 |
// Asignamos el locator e iniciamos la instancia
|
83 |
swingManager = AnnotationSwingLocator.getSwingManager(); |
84 |
|
85 |
swingManager.registerWindowManager(new GvSIGAnnotationWindowManager());
|
86 |
|
87 |
} |
88 |
|
89 |
public void execute(String actionCommand) { |
90 |
org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
91 |
|
92 |
if (window instanceof DefaultViewPanel) { |
93 |
DefaultViewPanel viewPanel = (DefaultViewPanel) window; |
94 |
ViewDocument viewDocument = viewPanel.getModel(); |
95 |
MapContext mapContext = viewDocument.getMapContext(); |
96 |
FLayer[] actives = mapContext.getLayers().getActives();
|
97 |
|
98 |
FLyrVect fLyrVect = null;
|
99 |
for (int i=0 ; i<actives.length ; i++){ |
100 |
if (actives[i] instanceof FLyrVect){ |
101 |
fLyrVect = (FLyrVect)actives[i]; |
102 |
break;
|
103 |
} |
104 |
} |
105 |
|
106 |
if (fLyrVect == null){ |
107 |
return;
|
108 |
} |
109 |
|
110 |
showAnnotation(manager, (FeatureStore)fLyrVect.getDataStore(), viewPanel); |
111 |
} |
112 |
} |
113 |
|
114 |
public void showAnnotation(AnnotationManager manager, FeatureStore featureStore, DefaultViewPanel defaultViewPanel) { |
115 |
try {
|
116 |
AnnotationCreationService service = |
117 |
(AnnotationCreationService) manager.getAnnotationCreationService(featureStore); |
118 |
service.setAnnotationCreationFinishAction(new AddLayerFinishAction(defaultViewPanel));
|
119 |
|
120 |
JAnnotationCreationServicePanel panel = |
121 |
swingManager.createAnnotation(service); |
122 |
swingManager.getWindowManager().showWindow(panel, "Annotation",
|
123 |
AnnotationWindowManager.MODE_WINDOW); |
124 |
|
125 |
} catch (ServiceException e) {
|
126 |
NotificationManager.addError(e); |
127 |
} |
128 |
} |
129 |
|
130 |
public boolean isEnabled() { |
131 |
int status = EditionUtilities.getEditionStatus();
|
132 |
if (( status == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE || status == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
133 |
|| (status == EditionUtilities.EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE)|| (status == EditionUtilities.EDITION_STATUS_MULTIPLE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)) |
134 |
{ |
135 |
return true; |
136 |
} |
137 |
return false; |
138 |
} |
139 |
|
140 |
public boolean isVisible() { |
141 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
142 |
.getActiveWindow(); |
143 |
|
144 |
if (f == null) { |
145 |
return false; |
146 |
} |
147 |
|
148 |
if (f instanceof DefaultViewPanel) { |
149 |
return true; |
150 |
} |
151 |
return false; |
152 |
} |
153 |
} |