root / trunk / extensions / extSymbology / src / org / gvsig / symbology / SingleLabelingExtension.java @ 20768
History | View | Annotate | Download (4.35 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* Av. Blasco Ib??ez, 50
|
24 |
* 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 org.gvsig.symbology; |
42 |
|
43 |
import java.sql.Date; |
44 |
|
45 |
import org.gvsig.symbology.fmap.tools.SingleLabelingBehavior; |
46 |
import org.gvsig.symbology.fmap.tools.SingleLabelingTool; |
47 |
import org.gvsig.symbology.gui.SingleLabelingConfigPanel; |
48 |
|
49 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.messages.NotificationManager; |
52 |
import com.iver.andami.plugins.Extension; |
53 |
import com.iver.cit.gvsig.fmap.core.ILabelable; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
56 |
import com.iver.cit.gvsig.fmap.tools.RectangleSelectionListener; |
57 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
58 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
59 |
/**
|
60 |
*
|
61 |
* SingleLabelingExtension.java
|
62 |
*
|
63 |
* Extension that allows the user to see a custom label over the feature
|
64 |
* that she/he selects
|
65 |
*
|
66 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Feb 28, 2008
|
67 |
*
|
68 |
*/
|
69 |
public class SingleLabelingExtension extends Extension { |
70 |
|
71 |
public void execute(String actionCommand) { |
72 |
if ("SINGLE_LABELING_TOOL".equals(actionCommand)) { |
73 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
74 |
FLayers layers = v.getMapControl().getMapContext().getLayers(); |
75 |
ILabelable[] labelableElements = new ILabelable[layers.getActives().length]; |
76 |
for (int i = 0; i < labelableElements.length; i++) { |
77 |
labelableElements[i] = (ILabelable) layers.getActives()[i]; |
78 |
|
79 |
} |
80 |
v.getMapControl().addMapTool("single-labeling",
|
81 |
new SingleLabelingBehavior(
|
82 |
new SingleLabelingTool(
|
83 |
v.getMapControl(), |
84 |
labelableElements) |
85 |
) |
86 |
); |
87 |
v.getMapControl().setTool("single-labeling");
|
88 |
} else if ("SINGLE_LABELING_SETUP".equals(actionCommand)) { |
89 |
try {
|
90 |
PluginServices.getMDIManager().addWindow( |
91 |
new SingleLabelingConfigPanel((ILabelable)
|
92 |
((View) PluginServices.getMDIManager().getActiveWindow()).
|
93 |
getMapControl().getMapContext().getLayers().getActives()[0]));
|
94 |
} catch (ReadDriverException e) {
|
95 |
// TODO Auto-generated catch block
|
96 |
NotificationManager.addError( |
97 |
PluginServices.getText(this, "could_not_retrieve_field_names")+ |
98 |
" "+ new Date(System.currentTimeMillis()).toString(), e); |
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
public void initialize() { |
104 |
PluginServices.getIconTheme().registerDefault( |
105 |
"single-labeling-tool",
|
106 |
getClass().getClassLoader().getResource("images/single-labeling-tool.gif")
|
107 |
); |
108 |
PluginServices.getIconTheme().registerDefault( |
109 |
"single-labeling-tool-config",
|
110 |
getClass().getClassLoader().getResource("images/single-labeling-tool-config.gif")
|
111 |
); |
112 |
|
113 |
} |
114 |
|
115 |
public boolean isEnabled() { |
116 |
return true; |
117 |
} |
118 |
|
119 |
public boolean isVisible() { |
120 |
if (PluginServices.getMDIManager().getActiveWindow() instanceof View) { |
121 |
View v = (View) PluginServices.getMDIManager().getActiveWindow(); |
122 |
FLayers layers = v.getMapControl().getMapContext().getLayers(); |
123 |
if (layers.getLayersCount() == 0) |
124 |
return false; |
125 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
126 |
FLayer layer = layers.getLayer(i); |
127 |
if (layer.isAvailable() &&
|
128 |
layer.isActive() && |
129 |
!(layer instanceof ILabelable))
|
130 |
return false; |
131 |
} |
132 |
return true; |
133 |
} |
134 |
return false; |
135 |
} |
136 |
|
137 |
} |