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 @ 42806
History | View | Annotate | Download (3.18 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2008 {DiSiD Technologies} {Create a JTable TableModel for a FeatureCollection}
|
||
27 | */
|
||
28 | 42806 | fdiaz | package org.gvsig.fmap.dal.swing.impl.featuretable.table.renders; |
29 | 40435 | jjdelcerro | |
30 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretable.table.renders.TextAreaCellRenderer; |
31 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
32 | 41462 | jjdelcerro | import org.slf4j.Logger; |
33 | import org.slf4j.LoggerFactory; |
||
34 | 40435 | jjdelcerro | |
35 | /**
|
||
36 | * Renderer for cells of type {@link Geometry}, showing it in WKT format.
|
||
37 | 42806 | fdiaz | *
|
38 | 40435 | jjdelcerro | * @author <a href="mailto:cordin@disid.com">C�sar Ordi�ana</a>
|
39 | */
|
||
40 | public class GeometryWKTCellRenderer extends TextAreaCellRenderer { |
||
41 | |||
42 | 41462 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(GeometryWKTCellRenderer.class); |
43 | 42806 | fdiaz | |
44 | 40435 | jjdelcerro | private static final long serialVersionUID = -2470239399517077869L; |
45 | 42806 | fdiaz | |
46 | 40435 | jjdelcerro | public static final int DEFAULT_MAX_WKT_LENGTH = 800; |
47 | 42806 | fdiaz | |
48 | 40435 | jjdelcerro | 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 | 42806 | fdiaz | *
|
61 | 40435 | jjdelcerro | * @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 | 41921 | jjdelcerro | // 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 | 41462 | jjdelcerro | return "#ERROR#"; |
87 | 40435 | jjdelcerro | } |
88 | } |
||
89 | return ""; |
||
90 | } |
||
91 | } |