root / branches / v10 / extensions / extGraph_predes / src / com / iver / cit / gvsig / SymbolTest.java @ 11094
History | View | Annotate | Download (4.63 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 com.iver.cit.gvsig; |
42 |
|
43 |
import com.iver.andami.PluginServices; |
44 |
import com.iver.andami.plugins.Extension; |
45 |
import com.iver.andami.preferences.IPreference; |
46 |
import com.iver.andami.preferences.IPreferenceExtension; |
47 |
import com.iver.andami.ui.mdiManager.IWindow; |
48 |
import com.iver.cit.gvsig.fmap.DriverException; |
49 |
import com.iver.cit.gvsig.fmap.MapContext; |
50 |
import com.iver.cit.gvsig.fmap.MapControl; |
51 |
import com.iver.cit.gvsig.fmap.core.FShape; |
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
53 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
57 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
58 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
59 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
60 |
import com.iver.cit.gvsig.graph.preferences.RoutePage; |
61 |
import com.iver.cit.gvsig.gvsig.gui.styling.SymbolSelector; |
62 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
63 |
|
64 |
public class SymbolTest extends Extension implements IPreferenceExtension{ |
65 |
private static final IPreference thePreferencePage = new RoutePage(); |
66 |
|
67 |
public void initialize() { |
68 |
// TODO Auto-generated method stub
|
69 |
|
70 |
} |
71 |
|
72 |
public void execute(String actionCommand) { |
73 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
74 |
|
75 |
View v = (View) w; |
76 |
MapControl mCtrl = v.getMapControl(); |
77 |
MapContext mc = mCtrl.getMapContext(); |
78 |
|
79 |
GraphicLayer graphicLayer = mc.getGraphicsLayer(); |
80 |
|
81 |
|
82 |
if (actionCommand.equals("DALE!")) { |
83 |
FLayer lyr = null;
|
84 |
|
85 |
SymbolSelector symSel = new SymbolSelector(null, FShape.POLYGON); |
86 |
PluginServices.getMDIManager().addWindow(symSel); |
87 |
ISymbol sym = symSel.getSymbol(); |
88 |
// DotDensityFillSymbol sym = new DotDensityFillSymbol();
|
89 |
// sym.setDotColor(Color.RED);
|
90 |
// sym.setDotCount(20);
|
91 |
// sym.setDotSize(2);
|
92 |
|
93 |
FLayer[] actives = mc.getLayers().getActives();
|
94 |
for (int i = 0; i < actives.length; i++) { |
95 |
if (actives[i] instanceof FLyrVect) |
96 |
lyr = actives[i]; |
97 |
} |
98 |
if (lyr == null) { |
99 |
System.err.println("no hay capas"); |
100 |
return;
|
101 |
} |
102 |
FLyrVect l = (FLyrVect) lyr; |
103 |
int idSymbol = graphicLayer.addSymbol(sym);
|
104 |
graphicLayer.clearAllGraphics(); |
105 |
try {
|
106 |
SelectableDataSource sds = l.getRecordset(); |
107 |
long rows = sds.getRowCount();
|
108 |
for (int i = 0; i < rows; i++) { |
109 |
IGeometry geom = l.getSource().getShape(i); |
110 |
System.err.println(i+") "+geom.toString()); |
111 |
FGraphic gra = new FGraphic(geom, idSymbol);
|
112 |
graphicLayer.addGraphic(gra); |
113 |
} |
114 |
|
115 |
|
116 |
} catch (DriverException e) {
|
117 |
// TODO Auto-generated catch block
|
118 |
e.printStackTrace(); |
119 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
120 |
// TODO Auto-generated catch block
|
121 |
e.printStackTrace(); |
122 |
} catch (DriverIOException e) {
|
123 |
// TODO Auto-generated catch block
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
mCtrl.drawGraphics(); |
127 |
} else if (actionCommand.equals("CLEAN_GRAPHICS")) { |
128 |
graphicLayer.clearAllGraphics(); |
129 |
} |
130 |
} |
131 |
|
132 |
public boolean isEnabled() { |
133 |
return true; |
134 |
} |
135 |
|
136 |
public boolean isVisible() { |
137 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
138 |
try {
|
139 |
View v = (View) w; |
140 |
MapContext mc = v.getMapControl().getMapContext(); |
141 |
FLayer[] actives = mc.getLayers().getActives();
|
142 |
for (int i = 0; i < actives.length; i++) { |
143 |
if (actives[i] instanceof FLyrVect) |
144 |
return true; |
145 |
} |
146 |
} catch (Exception e) {} |
147 |
return false; |
148 |
} |
149 |
|
150 |
public IPreference getPreferencesPage() {
|
151 |
return thePreferencePage;
|
152 |
} |
153 |
|
154 |
} |