Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / TableResultsModel.java @ 27140

History | View | Annotate | Download (4.34 KB)

1 26843 vsanjaime
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (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
 * 2009 Prodevelop S.L  vsanjaime   programador
26
 */
27
28
package org.gvsig.geocoding.gui;
29
30
import javax.swing.table.AbstractTableModel;
31
32
import org.cresques.cts.IProjection;
33 26851 vsanjaime
import org.gvsig.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35 26843 vsanjaime
import org.gvsig.geocoding.results.GeocoLocationSet;
36
import org.gvsig.geocoding.results.OpGeocoLocation;
37
import org.gvsig.geocoding.utils.GeocoUtils;
38
39
import com.iver.andami.PluginServices;
40
import com.iver.cit.gvsig.project.documents.view.gui.View;
41
42
public class TableResultsModel extends AbstractTableModel {
43
44
        private static final long serialVersionUID = 1L;
45
        private PluginServices ps = PluginServices.getPluginServices(this);
46
        private String[] columnNames = new String[5];;
47
        private Object[][] data = new Object[0][5];
48
49
        public TableResultsModel() {
50 26851 vsanjaime
                columnNames[0] = ps.getText("fsel");
51
                columnNames[1] = ps.getText("fquality");
52
                columnNames[2] = ps.getText("faccuracy");
53 26843 vsanjaime
                View view = GeocoUtils.getCurrentView();
54
                if (view != null) {
55
                        MapContext context = view.getModel().getMapContext();
56
                        MapControl mControl = new MapControl();
57
                        mControl.setMapContext(context);
58
                        IProjection proj = mControl.getProjection();
59 26851 vsanjaime
                        if (proj.isProjected()) {
60
                                columnNames[3] = ps.getText("fx");
61
                                columnNames[4] = ps.getText("fy");
62
                        } else {
63
                                columnNames[3] = ps.getText("flong");
64
                                columnNames[4] = ps.getText("flat");
65 26843 vsanjaime
                        }
66 26851 vsanjaime
                } else {
67
                        columnNames[3] = ps.getText("fx");
68
                        columnNames[4] = ps.getText("fy");
69
                }
70 26843 vsanjaime
        }
71
72
        public int getColumnCount() {
73
                return columnNames.length;
74
        }
75
76
        public int getRowCount() {
77
                return data.length;
78
        }
79
80
        public String getColumnName(int col) {
81
                return columnNames[col];
82
        }
83
84
        public Object getValueAt(int row, int col) {
85
                return data[row][col];
86
        }
87
88
        /*
89
         * JTable uses this method to determine the default renderer/ editor for
90
         * each cell. If we didn't implement this method, then the last column would
91
         * contain text ("true"/"false"), rather than a check box.
92
         */
93
        public Class getColumnClass(int c) {
94
                return getValueAt(0, c).getClass();
95
        }
96
97
        /*
98
         * Don't need to implement this method unless your table's editable.
99
         */
100
        public boolean isCellEditable(int row, int col) {
101
                // Note that the data/cell address is constant,
102
                // no matter where the cell appears onscreen.
103
                if (col == 0) {
104
                        return true;
105
                } else {
106
                        return false;
107
                }
108
        }
109
110
        /*
111
         * Don't need to implement this method unless your table's data can change.
112
         */
113
        public void setValueAt(Object value, int row, int col) {
114
                data[row][col] = value;
115
                fireTableCellUpdated(row, col);
116
        }
117
118
        /**
119
         *
120
         * @param loc
121
         */
122
        public void setGeocoLocationSet(GeocoLocationSet loc, int maxResults) {
123
                int num = loc.size();
124
                if (loc.size() > maxResults) {
125
                        num = maxResults;
126
                }
127
                data = new Object[num][5];
128
                for (int i = 0; i < num; i++) {
129
                        OpGeocoLocation optional = loc.getOpGeocoLocation(i);
130
                        Boolean sel = new Boolean(optional.isSelected());
131
                        Integer qua = new Integer(optional.getQuality());
132
                        Integer accu = new Integer(optional.getAccuracy());
133
                        Double x = new Double(optional.getX());
134
                        Double y = new Double(optional.getY());
135
                        data[i][0] = sel;
136
                        data[i][1] = qua;
137
                        data[i][2] = accu;
138
                        data[i][3] = x;
139
                        data[i][4] = y;
140
                }
141
                fireTableDataChanged();
142 26851 vsanjaime
        }
143
144 26843 vsanjaime
        /**
145 26851 vsanjaime
         * This method sort
146 26843 vsanjaime
         *
147
         * @param column
148
         */
149
        public void sort(int column) {
150
151
        }
152
153
}