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