svn-gvsig-desktop / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / Annotation_Extension.java @ 28605
History | View | Annotate | Download (6.28 KB)
1 | 14807 | jmvivo | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 11536 | caballero | *
|
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | 14807 | jmvivo | * Av. Blasco Ib��ez, 50
|
24 | 11536 | caballero | * 46010 VALENCIA
|
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig; |
||
42 | |||
43 | 13512 | caballero | import javax.swing.ImageIcon; |
44 | 11536 | caballero | |
45 | 13512 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
46 | 11536 | caballero | import com.iver.andami.PluginServices; |
47 | 13512 | caballero | import com.iver.andami.messages.NotificationManager; |
48 | 11536 | caballero | import com.iver.andami.plugins.Extension; |
49 | 13512 | caballero | import com.iver.andami.preferences.IPreference; |
50 | import com.iver.andami.preferences.IPreferenceExtension; |
||
51 | 11536 | caballero | import com.iver.andami.ui.mdiManager.IWindow; |
52 | import com.iver.cit.gvsig.fmap.MapContext; |
||
53 | import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
||
54 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
55 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
56 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
57 | import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard; |
||
58 | import com.iver.cit.gvsig.project.documents.gui.Annotation_ConfigureLabel; |
||
59 | import com.iver.cit.gvsig.project.documents.gui.Annotation_Create; |
||
60 | 13512 | caballero | import com.iver.cit.gvsig.project.documents.gui.Annotation_FieldSelect; |
61 | 11536 | caballero | import com.iver.cit.gvsig.project.documents.gui.Annotation_Open; |
62 | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
||
63 | 21473 | jmvivo | import com.iver.cit.gvsig.project.documents.view.legend.gui.General; |
64 | 13512 | caballero | import com.iver.cit.gvsig.project.documents.view.legend.gui.PanelLegendAnnotation; |
65 | import com.iver.cit.gvsig.project.documents.view.legend.gui.ThemeManagerWindow; |
||
66 | import com.iver.cit.gvsig.project.documents.view.legend.preferences.Annotation_Preferences; |
||
67 | 11536 | caballero | |
68 | /**
|
||
69 | * Extension to create an annotation layer.
|
||
70 | *
|
||
71 | * @author Vicente Caballero Navarro
|
||
72 | */
|
||
73 | 13512 | caballero | public class Annotation_Extension extends Extension implements |
74 | IPreferenceExtension { |
||
75 | private MapContext map = null; |
||
76 | 11536 | caballero | |
77 | 13512 | caballero | private Annotation_Preferences ap = new Annotation_Preferences(); |
78 | 11536 | caballero | |
79 | 13512 | caballero | /**
|
80 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
81 | */
|
||
82 | public void initialize() { |
||
83 | 11536 | caballero | |
84 | 13512 | caballero | AddLayer.addWizard(Annotation_Open.class); |
85 | 16690 | vcaballero | |
86 | 13512 | caballero | ThemeManagerWindow.addPage(PanelLegendAnnotation.class); |
87 | 14807 | jmvivo | |
88 | 16690 | vcaballero | ThemeManagerWindow.setTabEnabledForLayer(General.class, Annotation_Layer.class, true);
|
89 | ThemeManagerWindow.setTabEnabledForLayer(PanelLegendAnnotation.class, Annotation_Layer.class, true);
|
||
90 | 14807 | jmvivo | registerIcons(); |
91 | 13512 | caballero | } |
92 | 11536 | caballero | |
93 | 14807 | jmvivo | private void registerIcons(){ |
94 | 15634 | jmvivo | PluginServices.getIconTheme().registerDefault( |
95 | 14807 | jmvivo | "ext-annotation-pack-graphics",
|
96 | this.getClass().getClassLoader().getResource("images/package_graphics.png") |
||
97 | ); |
||
98 | |||
99 | 15634 | jmvivo | PluginServices.getIconTheme().registerDefault( |
100 | 14807 | jmvivo | "annotation-properties",
|
101 | Annotation_Preferences.class.getClassLoader().getResource("images/AnnotationProperties.png")
|
||
102 | ); |
||
103 | |||
104 | 15634 | jmvivo | PluginServices.getIconTheme().registerDefault( |
105 | 14807 | jmvivo | "annotation-modify",
|
106 | this.getClass().getClassLoader().getResource("images/ModifyAnnotationCursor.png") |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | 13512 | caballero | /**
|
111 | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
||
112 | */
|
||
113 | public void execute(String actionCommand) { |
||
114 | if ("ANNOTATIONLAYER".equals(actionCommand)) { |
||
115 | 14807 | jmvivo | ImageIcon Logo=PluginServices.getIconTheme().get("ext-annotation-pack-graphics"); |
116 | 11536 | caballero | |
117 | 13512 | caballero | SimpleWizard wizard = new SimpleWizard(Logo);
|
118 | 11536 | caballero | |
119 | 13512 | caballero | FLyrVect lv = (FLyrVect) map.getLayers().getActives()[0];
|
120 | Annotation_Layer la=null;
|
||
121 | try {
|
||
122 | la = Annotation_Layer.createLayerFromVect(lv); |
||
123 | } catch (ReadDriverException e) {
|
||
124 | NotificationManager.addError(e); |
||
125 | } |
||
126 | la.setName(lv.getName()); |
||
127 | 11536 | caballero | |
128 | 13512 | caballero | Annotation_FieldSelect panel1 = new Annotation_FieldSelect(wizard
|
129 | .getWizardComponents(), la); |
||
130 | Annotation_ConfigureLabel panel2 = new Annotation_ConfigureLabel(
|
||
131 | wizard.getWizardComponents(), la); |
||
132 | 11536 | caballero | |
133 | 13512 | caballero | wizard.getWizardComponents().addWizardPanel(panel1); |
134 | wizard.getWizardComponents().addWizardPanel(panel2); |
||
135 | 11536 | caballero | |
136 | 13512 | caballero | wizard.getWizardComponents() |
137 | .setFinishAction( |
||
138 | new Annotation_Create(wizard.getWizardComponents(),
|
||
139 | map, la)); |
||
140 | 11536 | caballero | |
141 | 13512 | caballero | wizard.getWindowInfo().setWidth(540);
|
142 | wizard.getWindowInfo().setHeight(380);
|
||
143 | wizard.getWindowInfo().setTitle( |
||
144 | PluginServices.getText(this, "to_annotation")); |
||
145 | 11536 | caballero | |
146 | 13512 | caballero | PluginServices.getMDIManager().addWindow(wizard); |
147 | 11536 | caballero | |
148 | 13512 | caballero | } |
149 | } |
||
150 | 11536 | caballero | |
151 | 13512 | caballero | /**
|
152 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
153 | */
|
||
154 | public boolean isEnabled() { |
||
155 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
156 | 11536 | caballero | |
157 | 13512 | caballero | if ((v != null) |
158 | && v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
|
||
159 | com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) v; |
||
160 | IProjectView model = vista.getModel(); |
||
161 | map = model.getMapContext(); |
||
162 | 11536 | caballero | |
163 | 13512 | caballero | FLayer[] layers = map.getLayers().getActives();
|
164 | 11536 | caballero | |
165 | 13512 | caballero | if (layers.length == 1) { |
166 | if (layers[0].isAvailable() && layers[0] instanceof FLyrVect) { |
||
167 | FLyrVect lv = (FLyrVect) layers[0];
|
||
168 | try {
|
||
169 | SelectableDataSource sds = lv.getSource() |
||
170 | .getRecordset(); |
||
171 | 11536 | caballero | |
172 | 13512 | caballero | if (sds.getFieldCount() > 0) { |
173 | return true; |
||
174 | } |
||
175 | } catch (ReadDriverException e) {
|
||
176 | return false; |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | 11536 | caballero | |
182 | 13512 | caballero | return false; |
183 | } |
||
184 | 11536 | caballero | |
185 | 13512 | caballero | /**
|
186 | * @see com.iver.andami.plugins.IExtension#isVisible()
|
||
187 | */
|
||
188 | public boolean isVisible() { |
||
189 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
190 | 11536 | caballero | |
191 | 13512 | caballero | if (v == null) { |
192 | return false; |
||
193 | } else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) { |
||
194 | return true; |
||
195 | } else {
|
||
196 | return false; |
||
197 | } |
||
198 | } |
||
199 | |||
200 | public IPreference[] getPreferencesPages() { |
||
201 | return new IPreference[] {ap}; |
||
202 | } |
||
203 | 11536 | caballero | } |