Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featuretable / table / renders / GeometryWKTCellRenderer.java @ 42775

History | View | Annotate | Download (3.19 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {Create a JTable TableModel for a FeatureCollection}
27
 */
28
package org.gvsig.fmap.dal.swing.impl.featuretable.table;
29

    
30
import org.gvsig.fmap.dal.swing.impl.featuretable.table.renders.TextAreaCellRenderer;
31
import org.gvsig.fmap.geom.Geometry;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
/**
36
 * Renderer for cells of type {@link Geometry}, showing it in WKT format.
37
 * 
38
 * @author <a href="mailto:cordin@disid.com">C�sar Ordi�ana</a>
39
 */
40
public class GeometryWKTCellRenderer extends TextAreaCellRenderer {
41

    
42
    private static final Logger logger = LoggerFactory.getLogger(GeometryWKTCellRenderer.class);
43
            
44
    private static final long serialVersionUID = -2470239399517077869L;
45
    
46
    public static final int DEFAULT_MAX_WKT_LENGTH = 800;
47
    
48
    public static final int DEFAULT_MAX_ROW_HEIGHT = 80;
49

    
50
    /**
51
     * Creates a new GeometryWKTCellRenderer, with the default MAX LENGTH fot
52
     * the WKT Strings and the default MAX HEIGHT for rows.
53
     */
54
    public GeometryWKTCellRenderer() {
55
        this(DEFAULT_MAX_WKT_LENGTH, DEFAULT_MAX_ROW_HEIGHT);
56
    }
57

    
58
    /**
59
     * Creates a new GeometryWKTCellRenderer.
60
     * 
61
     * @param maxWKTLength
62
     *            the maximum WTK length to be rendered.
63
     * @param maxRowHeight
64
     *            the maximum row height for the rows with cells rendered with
65
     *            this component
66
     */
67
    public GeometryWKTCellRenderer(int maxWKTLength, int maxRowHeight) {
68
        super(maxWKTLength, maxRowHeight);
69
    }
70

    
71
    @Override
72
    protected String getCellText(Object value, int row, int column) {
73
        if (value != null) {
74
            try {
75
                Geometry geometry = (Geometry) value;
76
                String geomTxt = (String) geometry.convertToWKT();
77
                if (geomTxt.length() > 200) {
78
                    geomTxt = geomTxt.substring(0, 200);
79
                }
80

    
81
                return geomTxt;
82
            } catch (Exception ex) {
83
                // Ojo, habia un warn en lugar de debug; pero puede causar que
84
                // se inserten demasiadas entradas en el log.
85
                logger.debug("Can't convert the geometry to WKT.",ex);
86
                return "#ERROR#";
87
            }
88
        }
89
        return "";
90
    }
91
}