Statistics
| Revision:

svn-gvsig-desktop / branches / FMap_SLD / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DBStrategy.java @ 1772

History | View | Annotate | Download (4 KB)

1
/*
2
 * Created on 08-mar-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *  
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 * 
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 * 
34
 *    or
35
 * 
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 * 
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.fmap.operations.strategies;
45

    
46
import java.awt.Graphics2D;
47
import java.awt.image.BufferedImage;
48
import java.sql.SQLException;
49

    
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.fmap.ViewPort;
52
import com.iver.cit.gvsig.fmap.core.IFeature;
53
import com.iver.cit.gvsig.fmap.core.IGeometry;
54
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
57
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
58
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
59
import com.iver.cit.gvsig.fmap.operations.Cancellable;
60
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
61

    
62
/**
63
 * @author FJP
64
 *
65
 * TODO To change the template for this generated type comment go to
66
 * Window - Preferences - Java - Code Generation - Code and Comments
67
 */
68
public class DBStrategy extends DefaultStrategy {
69

    
70
        public DBStrategy(FLayer capa) {
71
                super(capa);
72
        }
73

    
74

    
75
    /* (non-Javadoc)
76
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
77
     */
78
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
79
        // Nos aprovechamos del SQL para lanzar la consulta
80
        // teniendo en cuenta el boundingbox que toca.
81
        FLayer capa = getCapa();
82
        VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource();
83
        dbAdapter.start();
84
        String strEPSG = viewPort.getProjection().getAbrev().substring(5);
85
        IFeatureIterator geomIt = dbAdapter.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG);
86
        VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
87
        try {
88
            while (geomIt.hasNext())
89
            {
90
                    if (cancel.isCanceled()) {
91
                        dbAdapter.stop();
92
                            break;
93
                    }
94
                    IFeature feat = geomIt.next();
95
                IGeometry geom = feat.getGeometry();
96
                // TODO: CORREGIR LO DE LOS SIMBOLOS
97
                // Es probable que necesitemos generar un Feature
98
                // (Geometr?a + Atributos) para que opere con esa feature
99
                // el gestor de leyendas. A la leyenda le pasar?amos un
100
                // feature, y nos devolver? la colecci?n de s?mbolos a 
101
                // aplicar. Similar a lo de "processStylers" de GT2 
102
                geom.draw(g,viewPort,l.getDefaultSymbol());
103
            }
104
        } catch (SQLException e) {
105
            e.printStackTrace();
106
            throw new DriverException(e);
107
        }
108
        dbAdapter.stop();
109
        
110
    }
111
    
112

    
113
}