root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / CrsRecentsPanel.java @ 10786
History | View | Annotate | Download (6.23 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs.gui.panels; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.FlowLayout; |
45 |
|
46 |
|
47 |
import javax.swing.BorderFactory; |
48 |
import javax.swing.JLabel; |
49 |
import javax.swing.JPanel; |
50 |
import javax.swing.JScrollPane; |
51 |
import javax.swing.JTable; |
52 |
import javax.swing.ListSelectionModel; |
53 |
|
54 |
import javax.swing.table.DefaultTableModel; |
55 |
import javax.swing.table.TableColumn; |
56 |
|
57 |
import org.cresques.cts.IProjection; |
58 |
import org.gvsig.crs.CrsException; |
59 |
import org.gvsig.crs.CrsFactory; |
60 |
import org.gvsig.crs.ICrs; |
61 |
import org.gvsig.crs.persistence.CrsData; |
62 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
63 |
|
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.cit.gvsig.gui.TableSorter; |
66 |
|
67 |
/**
|
68 |
* Clase que genera el panel de recientes
|
69 |
*
|
70 |
* @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
|
71 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
72 |
* @author Luisa Marina Fern?ndez (luisam.fernandez@uclm.es)
|
73 |
*
|
74 |
*/
|
75 |
public class CrsRecentsPanel extends JPanel { |
76 |
|
77 |
/**
|
78 |
*
|
79 |
*/
|
80 |
private static final long serialVersionUID = 1L; |
81 |
|
82 |
public JTable jTable = null; |
83 |
private JScrollPane jScrollPane = null; |
84 |
public DefaultTableModel dtm = null; |
85 |
public TableSorter sorter = null; |
86 |
private CrsData crsDataArray[] = null; |
87 |
|
88 |
public int selectedRowTable = -1; |
89 |
private String authority = null; |
90 |
private int codeCRS = -1; |
91 |
private ICrs crs = null; |
92 |
|
93 |
public CrsRecentsPanel() {
|
94 |
super();
|
95 |
initialize(); |
96 |
} |
97 |
|
98 |
private void initialize(){ |
99 |
this.setLayout(new BorderLayout()); |
100 |
JPanel p=new JPanel(new FlowLayout(FlowLayout.LEFT,15,15)); |
101 |
p.add(getJLabel()); |
102 |
this.add(p, BorderLayout.NORTH); |
103 |
this.add(getJScrollPane(), BorderLayout.CENTER); |
104 |
} |
105 |
|
106 |
private JLabel getJLabel(){ |
107 |
JLabel label = new JLabel(); |
108 |
label.setText(PluginServices.getText(this, "ultimos_crs_utilizados")+":"); |
109 |
return label;
|
110 |
} |
111 |
/**
|
112 |
* Inicializa el panel que contiene la tabla con los crs
|
113 |
* @return
|
114 |
*/
|
115 |
private JScrollPane getJScrollPane() { |
116 |
if (jScrollPane == null) { |
117 |
jScrollPane = new JScrollPane(); |
118 |
jScrollPane.setBorder( |
119 |
BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3,3,3,3),jScrollPane.getBorder())); |
120 |
jScrollPane.setViewportView(getJTable()); |
121 |
} |
122 |
return jScrollPane;
|
123 |
} |
124 |
/**
|
125 |
* Inicializa la tabla que contiene los crs
|
126 |
* @return
|
127 |
*/
|
128 |
public JTable getJTable() { |
129 |
if (jTable == null) { |
130 |
String[] columnNames= {PluginServices.getText(this,"fuente"), |
131 |
PluginServices.getText(this,"codigo"), |
132 |
PluginServices.getText(this,"nombre")}; |
133 |
Object[][]data = {}; |
134 |
dtm = new DefaultTableModel(data, columnNames) |
135 |
{ |
136 |
private static final long serialVersionUID = 1L; |
137 |
public boolean isCellEditable(int row, int column) { |
138 |
return false; |
139 |
} |
140 |
/*
|
141 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
142 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
143 |
* actual al seleccionar una fila (non-Javadoc)
|
144 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
145 |
*/
|
146 |
public Class getColumnClass(int column) |
147 |
{ |
148 |
return getValueAt(0, column).getClass(); |
149 |
} |
150 |
}; |
151 |
sorter = new TableSorter(dtm);
|
152 |
|
153 |
jTable = new JTable(sorter); |
154 |
sorter.setTableHeader(jTable.getTableHeader()); |
155 |
jTable.setCellSelectionEnabled(false);
|
156 |
jTable.setRowSelectionAllowed(true);
|
157 |
jTable.setColumnSelectionAllowed(false);
|
158 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
159 |
TableColumn column = null; |
160 |
for (int i = 0; i < 3; i++) { |
161 |
column = jTable.getColumnModel().getColumn(i); |
162 |
if (i == 0) { |
163 |
column.setPreferredWidth(60); //code column is shorter |
164 |
}else if (i == 2) { |
165 |
column.setPreferredWidth(275);
|
166 |
} |
167 |
else {
|
168 |
column.setPreferredWidth(160);
|
169 |
} |
170 |
} |
171 |
} |
172 |
return jTable;
|
173 |
} |
174 |
|
175 |
public ICrs getProjection() {
|
176 |
return crs;
|
177 |
} |
178 |
|
179 |
public void setCodeCRS(int code) { |
180 |
codeCRS = code; |
181 |
} |
182 |
|
183 |
public int getCodeCRS() { |
184 |
return codeCRS;
|
185 |
} |
186 |
|
187 |
public void setProjection(IProjection crs) { |
188 |
//setCrs((ICrs) crs);
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Carga en la tabla los CRSs leidos del sistema de persistencia.
|
193 |
*/
|
194 |
public void loadRecents(){ |
195 |
RecentCRSsPersistence persistence = new RecentCRSsPersistence();
|
196 |
crsDataArray = persistence.getArrayOfCrsData(); |
197 |
|
198 |
for (int iRow = crsDataArray.length-1;iRow>=0;iRow--){ |
199 |
Object row[] ={crsDataArray[iRow].getAuthority(),Integer.toString(crsDataArray[iRow].getCode()),crsDataArray[iRow].getName()}; |
200 |
dtm.addRow(row); |
201 |
} |
202 |
|
203 |
/*
|
204 |
/*Seleccionar el primer registro.
|
205 |
*/
|
206 |
int numr = dtm.getRowCount();
|
207 |
if (numr != 0 ) |
208 |
this.getJTable().setRowSelectionInterval(0,0); |
209 |
} |
210 |
|
211 |
public ICrs getCrs() {
|
212 |
return crs;
|
213 |
} |
214 |
|
215 |
public void initCrs(){ |
216 |
|
217 |
selectedRowTable = getJTable().getSelectedRow(); |
218 |
Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1)); |
219 |
authority = (String)sorter.getValueAt(selectedRowTable,0); |
220 |
codeCRS = Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1)); |
221 |
try {
|
222 |
crs = new CrsFactory().getCRS(authority+":"+String.valueOf(codeCRS)); |
223 |
} catch (CrsException e) {
|
224 |
e.printStackTrace(); |
225 |
} |
226 |
} |
227 |
|
228 |
} |