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