Revision 13

View differences:

org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.swing/org.gvsig.lrs.swing.impl/src/main/java/org/gvsig/lrs/swing/impl/FLayerVectTableModel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.lrs.swing.impl;
24

  
25
import javax.swing.table.AbstractTableModel;
26

  
27
import org.apache.commons.lang3.mutable.MutableInt;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.Feature;
30
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.aggregate.MultiCurve;
34
import org.gvsig.fmap.geom.primitive.Curve;
35
import org.gvsig.fmap.geom.primitive.Point;
36
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
37
import org.gvsig.tools.exception.BaseException;
38
import org.gvsig.tools.visitor.VisitCanceledException;
39
import org.gvsig.tools.visitor.Visitor;
40

  
41
public class FLayerVectTableModel extends AbstractTableModel {
42

  
43
    private static final long serialVersionUID = -2678580144252993562L;
44

  
45
    private String[] columnNames = { "IdRoute", "OrderPoint", "XCoordinate", "YCoordinate", "MCoordinate" };
46
    private Object[][] data;
47
    private FeatureStore featureStore;
48
    private FeatureAttributeDescriptor fadIdRoute;
49

  
50
    public FLayerVectTableModel(FLyrVect fLyrVect, FeatureAttributeDescriptor fadIdRoute) throws BaseException {
51
        this.featureStore = fLyrVect.getFeatureStore();
52
        this.fadIdRoute = fadIdRoute;
53
        this.data = new Object[getRowCount()][getColumnCount()];
54
        fillData(featureStore);
55
    }
56

  
57
    private void fillData(FeatureStore featureStore) throws BaseException {
58
        final MutableInt rowNumber=new MutableInt(0);
59
        featureStore.accept(new Visitor() {
60
            public void visit(Object obj)
61
                throws VisitCanceledException, BaseException {
62
                Feature feature = (Feature) obj;
63
                Geometry geometry=feature.getDefaultGeometry();
64
                if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.CURVE)){
65
                    Curve curve=(Curve) geometry;
66
                    for (int i=0;i<curve.getNumVertices();i++){
67
                        data[rowNumber.getValue()][0]=feature.get(fadIdRoute.getName()); //IDROUTE
68
                        data[rowNumber.getValue()][1]=i; //ORDER
69
                        Point vertex=curve.getVertex(i);
70
                        data[rowNumber.getValue()][2]=vertex.getX(); //XCOORDINATE
71
                        data[rowNumber.getValue()][3]=vertex.getY(); //YCOORDINATE
72
                        //TODO ADD M-COORDINATE
73
                        //data[rowNumber.getValue()][4]=vertex.getM(); //MCOORDINATE
74
                        rowNumber.setValue(rowNumber.getValue()+1);
75
                    }
76
                }
77
                if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)){
78
                    MultiCurve multicurve=(MultiCurve) geometry;
79
                    for (int i=0;i<multicurve.getPrimitivesNumber();i++){
80
                        Curve curve=multicurve.getCurveAt(i);
81
                        for (int j=0;j<curve.getNumVertices();j++){
82
                            data[rowNumber.getValue()][0]=feature.get(fadIdRoute.getName()); //IDROUTE
83
                            data[rowNumber.getValue()][1]=i; //ORDER
84
                            Point vertex=curve.getVertex(j);
85
                            data[rowNumber.getValue()][2]=vertex.getX(); //XCOORDINATE
86
                            data[rowNumber.getValue()][3]=vertex.getY(); //YCOORDINATE
87
                            //TODO ADD M-COORDINATE
88
                            //data[rowNumber.getValue()][4]=vertex.getM(); //MCOORDINATE
89
                            rowNumber.setValue(rowNumber.getValue()+1);
90
                        }
91
                    }
92
                }
93
            }
94
        });
95
    }
96

  
97
    public int getColumnCount() {
98
        return columnNames.length;
99
    }
100

  
101
    public int getRowCount() {
102
        if(featureStore == null){
103
            return 0;
104
        }
105
        try {
106
            final MutableInt rowNumber=new MutableInt(0);
107
            featureStore.accept(new Visitor() {
108
                public void visit(Object obj)
109
                    throws VisitCanceledException, BaseException {
110
                    Feature feature = (Feature) obj;
111
                    Geometry geometry=feature.getDefaultGeometry();
112
                    if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.CURVE)){
113
                        Curve curve=(Curve) geometry;
114
                        rowNumber.setValue(rowNumber.getValue()+curve.getNumVertices());
115
                    }
116
                    if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)){
117
                        MultiCurve multicurve=(MultiCurve) geometry;
118
                        for (int i=0;i<multicurve.getPrimitivesNumber();i++){
119
                            Curve curve=multicurve.getCurveAt(i);
120
                            rowNumber.setValue(rowNumber.getValue()+curve.getNumVertices());
121
                        }
122
                    }
123
                }
124
            });
125
            return rowNumber.getValue();
126
        } catch (Exception e) {
127
            return 0;
128
        }
129
    }
130

  
131
    @Override
132
    public String getColumnName(int col) {
133
        return columnNames[col];
134
    }
135

  
136
    public Object getValueAt(int i, int j) {
137
        return data[i][j];
138
    }
139

  
140
}
org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.swing/org.gvsig.lrs.swing.impl/src/main/java/org/gvsig/lrs/swing/impl/EditRouteCalibrationTableModel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.lrs.swing.impl;
24

  
25
import javax.swing.table.AbstractTableModel;
26

  
27
import com.vividsolutions.jts.geom.CoordinateSequence;
28

  
29
import org.apache.commons.lang3.mutable.MutableInt;
30

  
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.geom.aggregate.MultiCurve;
36
import org.gvsig.fmap.geom.primitive.Curve;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.tools.exception.BaseException;
40
import org.gvsig.tools.visitor.VisitCanceledException;
41
import org.gvsig.tools.visitor.Visitor;
42

  
43
public class EditRouteCalibrationTableModel extends AbstractTableModel {
44

  
45
    private static final long serialVersionUID = -2678580144252993562L;
46

  
47
    private String[] columnNames = { "IdRoute", "OrderPoint", "XCoordinate", "YCoordinate", "MCoordinate" };
48
    private Object[][] data;
49
    private FeatureStore featureStore;
50
    private FeatureAttributeDescriptor fadIdRoute;
51

  
52
    public EditRouteCalibrationTableModel(FLyrVect fLyrVect, FeatureAttributeDescriptor fadIdRoute) throws BaseException {
53
        this.featureStore = fLyrVect.getFeatureStore();
54
        this.fadIdRoute = fadIdRoute;
55
        this.data = new Object[getRowCount()][getColumnCount()];
56
        fillData(featureStore);
57
    }
58

  
59
    private void fillData(FeatureStore featureStore) throws BaseException {
60
        final MutableInt rowNumber=new MutableInt(0);
61
        featureStore.accept(new Visitor() {
62
            public void visit(Object obj)
63
                throws VisitCanceledException, BaseException {
64
                Feature feature = (Feature) obj;
65
                Geometry geometry=feature.getDefaultGeometry();
66
                if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.LINE)){
67
                    Curve curve=(Curve) geometry;
68
                    for (int i=0;i<curve.getNumVertices();i++){
69
                        data[rowNumber.getValue()][0]=feature.get(fadIdRoute.getName()); //IDROUTE
70
                        data[rowNumber.getValue()][1]=i; //ORDER
71
                        Point vertex=curve.getVertex(i);
72
                        data[rowNumber.getValue()][2]=vertex.getX(); //XCOORDINATE
73
                        data[rowNumber.getValue()][3]=vertex.getY(); //YCOORDINATE
74
                        //TODO ADD M-COORDINATE
75
                        data[rowNumber.getValue()][4]=vertex.getCoordinateAt(CoordinateSequence.M); //MCOORDINATE
76
                        rowNumber.setValue(rowNumber.getValue()+1);
77
                    }
78
                }
79
                if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.MULTILINE)){
80
                    MultiCurve multicurve=(MultiCurve) geometry;
81
                    for (int i=0;i<multicurve.getPrimitivesNumber();i++){
82
                        Curve curve=multicurve.getCurveAt(i);
83
                        for (int j=0;j<curve.getNumVertices();j++){
84
                            data[rowNumber.getValue()][0]=feature.get(fadIdRoute.getName()); //IDROUTE
85
                            data[rowNumber.getValue()][1]=i; //ORDER
86
                            Point vertex=curve.getVertex(j);
87
                            data[rowNumber.getValue()][2]=vertex.getX(); //XCOORDINATE
88
                            data[rowNumber.getValue()][3]=vertex.getY(); //YCOORDINATE
89
                            //TODO ADD M-COORDINATE
90
                            data[rowNumber.getValue()][4]=vertex.getCoordinateAt(CoordinateSequence.M); //MCOORDINATE
91
                            rowNumber.setValue(rowNumber.getValue()+1);
92
                        }
93
                    }
94
                }
95
            }
96
        });
97
    }
98

  
99
    public int getColumnCount() {
100
        return columnNames.length;
101
    }
102

  
103
    public int getRowCount() {
104
        if(featureStore == null){
105
            return 0;
106
        }
107
        try {
108
            final MutableInt rowNumber=new MutableInt(0);
109
            featureStore.accept(new Visitor() {
110
                public void visit(Object obj)
111
                    throws VisitCanceledException, BaseException {
112
                    Feature feature = (Feature) obj;
113
                    Geometry geometry=feature.getDefaultGeometry();
114
                    if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.LINE)){
115
                        Curve curve=(Curve) geometry;
116
                        rowNumber.setValue(rowNumber.getValue()+curve.getNumVertices());
117
                    }
118
                    if (geometry.getGeometryType().isTypeOf(Geometry.TYPES.MULTILINE)){
119
                        MultiCurve multicurve=(MultiCurve) geometry;
120
                        for (int i=0;i<multicurve.getPrimitivesNumber();i++){
121
                            Curve curve=multicurve.getCurveAt(i);
122
                            rowNumber.setValue(rowNumber.getValue()+curve.getNumVertices());
123
                        }
124
                    }
125
                }
126
            });
127
            return rowNumber.getValue();
128
        } catch (Exception e) {
129
            return 0;
130
        }
131
    }
132

  
133
    @Override
134
    public String getColumnName(int col) {
135
        return columnNames[col];
136
    }
137

  
138
    public Object getValueAt(int i, int j) {
139
        return data[i][j];
140
    }
141

  
142
}
org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.swing/org.gvsig.lrs.swing.impl/src/main/java/org/gvsig/lrs/swing/impl/JLrsEditRouteCalibrationController.java
219 219

  
220 220

  
221 221
    private void initTblLayerInfo(FLyrVect layer, FeatureAttributeDescriptor selectedIdRoute) throws LrsGettingParametersException{
222
        FLayerVectTableModel tableModel;
222
        EditRouteCalibrationTableModel tableModel;
223 223
        try {
224
            tableModel = new FLayerVectTableModel(layer,selectedIdRoute);
224
            tableModel = new EditRouteCalibrationTableModel(layer,selectedIdRoute);
225 225
            tblLayerInfo.setModel(tableModel);
226 226
        } catch (BaseException e) {
227 227
            logger.error("Error getting table info");

Also available in: Unified diff