Statistics
| Revision:

root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / SymbolTest.java @ 8648

History | View | Annotate | Download (4.19 KB)

1 8588 jaume
/* 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.v02.FConstant;
57
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
58
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
61
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
62
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
63
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
64
import com.iver.cit.gvsig.gvsig.gui.styling.SymbolSelector;
65
import com.iver.cit.gvsig.project.documents.view.gui.View;
66
67
public class SymbolTest extends Extension {
68
69
        public void initialize() {
70
                // TODO Auto-generated method stub
71
72
        }
73
74
        public void execute(String actionCommand) {
75
                FLayer lyr = null;
76
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
77
                View v = (View) w;
78
79
                SymbolSelector symSel = new SymbolSelector(null, FShape.POLYGON);
80
                PluginServices.getMDIManager().addWindow(symSel);
81
                ISymbol sym = symSel.getSymbol();
82
83
84
                MapControl mCtrl = v.getMapControl();
85
                MapContext mc = mCtrl.getMapContext();
86
                FLayer[] actives = mc.getLayers().getActives();
87
                for (int i = 0; i < actives.length; i++) {
88
                        if (actives[i] instanceof FLyrVect)
89
                                lyr = actives[i];
90
                }
91
                if (lyr == null) {
92
                        System.err.println("no hay capas");
93
                        return;
94
                }
95
                FLyrVect l = (FLyrVect) lyr;
96
                GraphicLayer graphicLayer = mc.getGraphicsLayer();
97
                int idSymbol = graphicLayer.addSymbol(sym);
98
                graphicLayer.clearAllGraphics();
99
                try {
100
                        SelectableDataSource sds = l.getRecordset();
101
                        long rows = sds.getRowCount();
102
                        for (int i = 0; i < rows; i++) {
103
                                IGeometry geom = l.getSource().getShape(i);
104
                                System.err.println(i+") "+geom.toString());
105
                                FGraphic gra = new FGraphic(geom, idSymbol);
106
                                graphicLayer.addGraphic(gra);
107
                        }
108
109
110
                } catch (DriverException e) {
111
                        // TODO Auto-generated catch block
112
                        e.printStackTrace();
113
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
114
                        // TODO Auto-generated catch block
115
                        e.printStackTrace();
116
                } catch (DriverIOException e) {
117
                        // TODO Auto-generated catch block
118
                        e.printStackTrace();
119
                }
120
                mCtrl.drawGraphics();
121
122
        }
123
124
        public boolean isEnabled() {
125
                return true;
126
        }
127
128
        public boolean isVisible() {
129
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
130
                try {
131
                        View v = (View) w;
132
                        MapContext mc = v.getMapControl().getMapContext();
133
                        FLayer[] actives = mc.getLayers().getActives();
134
                        for (int i = 0; i < actives.length; i++) {
135
                                if (actives[i] instanceof FLyrVect)
136
                                        return true;
137
                        }
138
                } catch (Exception e) {}
139
                return false;
140
        }
141
142
}