svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / data / feature / swing / table / GeometryWKTCellEditor.java @ 25894
History | View | Annotate | Download (4.18 KB)
1 | 25894 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Gobernment (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 {DiSiD Technologies} {{Task}}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.data.feature.swing.table; |
||
28 | |||
29 | import java.awt.event.ActionEvent; |
||
30 | import java.awt.event.ItemEvent; |
||
31 | import java.util.EventObject; |
||
32 | |||
33 | import javax.swing.DefaultCellEditor; |
||
34 | |||
35 | import org.gvsig.fmap.geom.Geometry; |
||
36 | import org.gvsig.fmap.geom.operation.fromwkt.FromWKT; |
||
37 | import org.gvsig.fmap.geom.operation.fromwkt.FromWKTGeometryOperationContext; |
||
38 | import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
||
39 | import org.gvsig.fmap.geom.primitive.NullGeometry; |
||
40 | |||
41 | /**
|
||
42 | * Editor for cells of type Geometry.
|
||
43 | *
|
||
44 | * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
||
45 | */
|
||
46 | public class GeometryWKTCellEditor extends TextAreaCellEditor { |
||
47 | |||
48 | private static final long serialVersionUID = -2296004227902843851L; |
||
49 | private final Geometry nullGeometry = new NullGeometry(); |
||
50 | |||
51 | public GeometryWKTCellEditor() {
|
||
52 | super();
|
||
53 | delegate = new GeometryToWKTDelegate(delegate);
|
||
54 | } |
||
55 | |||
56 | @Override
|
||
57 | public Object getCellEditorValue() { |
||
58 | String wkt = (String) super.getCellEditorValue(); |
||
59 | FromWKTGeometryOperationContext context = new FromWKTGeometryOperationContext(
|
||
60 | wkt, null);
|
||
61 | |||
62 | try {
|
||
63 | return nullGeometry.invokeOperation(FromWKT.CODE, context);
|
||
64 | } catch (Exception ex) { |
||
65 | throw new WKTToGeometryException(wkt, ex); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | @SuppressWarnings("serial") |
||
70 | private class GeometryToWKTDelegate extends |
||
71 | DefaultCellEditor.EditorDelegate {
|
||
72 | private DefaultCellEditor.EditorDelegate delegate; |
||
73 | |||
74 | public GeometryToWKTDelegate(DefaultCellEditor.EditorDelegate delegate) { |
||
75 | this.delegate = delegate;
|
||
76 | } |
||
77 | |||
78 | public void setValue(Object value) { |
||
79 | String strValue = ""; |
||
80 | |||
81 | if (value != null) { |
||
82 | try {
|
||
83 | Geometry geometry = (Geometry) value; |
||
84 | strValue = (String) geometry.invokeOperation(ToWKT.CODE,
|
||
85 | null);
|
||
86 | } catch (Exception ex) { |
||
87 | throw new GeometryToWKTException(ex); |
||
88 | } |
||
89 | } |
||
90 | delegate.setValue(strValue); |
||
91 | } |
||
92 | |||
93 | public void actionPerformed(ActionEvent e) { |
||
94 | delegate.actionPerformed(e); |
||
95 | } |
||
96 | |||
97 | public void cancelCellEditing() { |
||
98 | delegate.cancelCellEditing(); |
||
99 | } |
||
100 | |||
101 | public boolean equals(Object obj) { |
||
102 | return delegate.equals(obj);
|
||
103 | } |
||
104 | |||
105 | public Object getCellEditorValue() { |
||
106 | return delegate.getCellEditorValue();
|
||
107 | } |
||
108 | |||
109 | public int hashCode() { |
||
110 | return delegate.hashCode();
|
||
111 | } |
||
112 | |||
113 | public boolean isCellEditable(EventObject anEvent) { |
||
114 | return delegate.isCellEditable(anEvent);
|
||
115 | } |
||
116 | |||
117 | public void itemStateChanged(ItemEvent e) { |
||
118 | delegate.itemStateChanged(e); |
||
119 | } |
||
120 | |||
121 | public boolean shouldSelectCell(EventObject anEvent) { |
||
122 | return delegate.shouldSelectCell(anEvent);
|
||
123 | } |
||
124 | |||
125 | public boolean startCellEditing(EventObject anEvent) { |
||
126 | return delegate.startCellEditing(anEvent);
|
||
127 | } |
||
128 | |||
129 | public boolean stopCellEditing() { |
||
130 | return delegate.stopCellEditing();
|
||
131 | } |
||
132 | |||
133 | public String toString() { |
||
134 | return delegate.toString();
|
||
135 | } |
||
136 | } |
||
137 | } |