root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.app.jcrs / org.gvsig.projection.app.jcrs.common / src / main / java / org / gvsig / crs / gui / panels / CrsRecentsPanel.java @ 578
History | View | Annotate | Download (8.84 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica 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 Ibez, 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.Dimension; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
|
49 |
|
50 |
|
51 |
import javax.swing.Action; |
52 |
import javax.swing.BorderFactory; |
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JLabel; |
55 |
import javax.swing.JPanel; |
56 |
import javax.swing.JScrollPane; |
57 |
import javax.swing.JTable; |
58 |
import javax.swing.ListSelectionModel; |
59 |
import javax.swing.table.DefaultTableModel; |
60 |
import javax.swing.table.TableColumn; |
61 |
|
62 |
import org.cresques.cts.IProjection; |
63 |
import org.gvsig.andami.PluginServices; |
64 |
import org.gvsig.app.gui.TableSorter; |
65 |
import org.gvsig.crs.CrsException; |
66 |
import org.gvsig.crs.CrsFactory; |
67 |
import org.gvsig.crs.ICrs; |
68 |
import org.gvsig.crs.persistence.CrsData; |
69 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
70 |
import org.slf4j.Logger; |
71 |
import org.slf4j.LoggerFactory; |
72 |
|
73 |
|
74 |
/**
|
75 |
* Clase que genera el panel de recientes
|
76 |
*
|
77 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
|
78 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
79 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
80 |
*
|
81 |
*/
|
82 |
public class CrsRecentsPanel extends JPanel implements ActionListener { |
83 |
|
84 |
public static final Logger logger = LoggerFactory.getLogger(CrsRecentsPanel.class); |
85 |
|
86 |
/**
|
87 |
*
|
88 |
*/
|
89 |
private static final long serialVersionUID = 1L; |
90 |
|
91 |
public JTable jTable = null; |
92 |
private JScrollPane jScrollPane = null; |
93 |
private JButton infoCrs=null; |
94 |
public DefaultTableModel dtm = null; |
95 |
public TableSorter sorter = null; |
96 |
private CrsData crsDataArray[] = null; |
97 |
|
98 |
public int selectedRowTable = -1; |
99 |
private String authority = null; |
100 |
private int codeCRS = -1; |
101 |
private ICrs crs = null; |
102 |
|
103 |
public CrsRecentsPanel() {
|
104 |
super();
|
105 |
initialize(); |
106 |
} |
107 |
|
108 |
private void initialize(){ |
109 |
this.setLayout(new BorderLayout()); |
110 |
JPanel p=new JPanel(new FlowLayout(FlowLayout.LEFT,15,15)); |
111 |
p.add(getJLabel()); |
112 |
this.add(p, BorderLayout.NORTH); |
113 |
this.add(getJScrollPane(), BorderLayout.CENTER); |
114 |
JPanel pSouth=new JPanel(new FlowLayout(FlowLayout.RIGHT,5,5)); |
115 |
pSouth.add(getInfoCrs()); |
116 |
this.add(pSouth,BorderLayout.SOUTH); |
117 |
} |
118 |
|
119 |
private JLabel getJLabel(){ |
120 |
JLabel label = new JLabel(); |
121 |
label.setText(PluginServices.getText(this, "ultimos_crs_utilizados")+":"); |
122 |
return label;
|
123 |
} |
124 |
/**
|
125 |
* Inicializa el panel que contiene la tabla con los crs
|
126 |
* @return
|
127 |
*/
|
128 |
private JScrollPane getJScrollPane() { |
129 |
if (jScrollPane == null) { |
130 |
jScrollPane = new JScrollPane(); |
131 |
jScrollPane.setBorder( |
132 |
BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3,3,3,3),jScrollPane.getBorder())); |
133 |
jScrollPane.setViewportView(getJTable()); |
134 |
} |
135 |
return jScrollPane;
|
136 |
} |
137 |
/**
|
138 |
* Inicializa la tabla que contiene los crs
|
139 |
* @return
|
140 |
*/
|
141 |
public JTable getJTable() { |
142 |
if (jTable == null) { |
143 |
String[] columnNames= {PluginServices.getText(this,"repository"), |
144 |
PluginServices.getText(this,"codigo"), |
145 |
PluginServices.getText(this,"nombre")}; |
146 |
Object[][]data = {}; |
147 |
dtm = new DefaultTableModel(data, columnNames) |
148 |
{ |
149 |
private static final long serialVersionUID = 1L; |
150 |
public boolean isCellEditable(int row, int column) { |
151 |
return false; |
152 |
} |
153 |
/*
|
154 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
155 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
156 |
* actual al seleccionar una fila (non-Javadoc)
|
157 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
158 |
*/
|
159 |
public Class getColumnClass(int column) |
160 |
{ |
161 |
return getValueAt(0, column).getClass(); |
162 |
} |
163 |
}; |
164 |
sorter = new TableSorter(dtm);
|
165 |
|
166 |
jTable = new JTable(sorter); |
167 |
sorter.setTableHeader(jTable.getTableHeader()); |
168 |
jTable.setCellSelectionEnabled(false);
|
169 |
jTable.setRowSelectionAllowed(true);
|
170 |
jTable.setColumnSelectionAllowed(false);
|
171 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
172 |
TableColumn column = null; |
173 |
for (int i = 0; i < 3; i++) { |
174 |
column = jTable.getColumnModel().getColumn(i); |
175 |
if (i == 0) { |
176 |
column.setPreferredWidth(80); //code column is shorter |
177 |
}else if (i == 2) { |
178 |
column.setPreferredWidth(275);
|
179 |
} |
180 |
else {
|
181 |
column.setPreferredWidth(140);
|
182 |
} |
183 |
} |
184 |
} |
185 |
return jTable;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Inicializa el botn que obtiene la informacin del CRS
|
190 |
* @return
|
191 |
*/
|
192 |
public JButton getInfoCrs() { |
193 |
if(infoCrs == null) { |
194 |
infoCrs = new JButton(); |
195 |
infoCrs.setPreferredSize(new Dimension(85,20)); |
196 |
infoCrs.setText(PluginServices.getText(this,"infocrs")); |
197 |
infoCrs.setMnemonic('I');
|
198 |
infoCrs.setEnabled(false);
|
199 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
200 |
infoCrs.addActionListener(this);
|
201 |
} |
202 |
return infoCrs;
|
203 |
} |
204 |
public ICrs getProjection() {
|
205 |
return crs;
|
206 |
} |
207 |
|
208 |
public void setCodeCRS(int code) { |
209 |
codeCRS = code; |
210 |
} |
211 |
|
212 |
public int getCodeCRS() { |
213 |
return codeCRS;
|
214 |
} |
215 |
|
216 |
public void setProjection(IProjection crs) { |
217 |
//setCrs((ICrs) crs);
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Carga en la tabla los CRSs leidos del sistema de persistencia.
|
222 |
*/
|
223 |
public void loadRecents(){ |
224 |
|
225 |
// Eliminar filas en cada nueva bsqueda
|
226 |
int numRow = dtm.getRowCount();
|
227 |
while (numRow != 0) { |
228 |
numRow = numRow - 1;
|
229 |
dtm.removeRow(numRow); |
230 |
} |
231 |
|
232 |
RecentCRSsPersistence persistence = new RecentCRSsPersistence();
|
233 |
crsDataArray = persistence.getArrayOfCrsData(); |
234 |
boolean available = true; |
235 |
for (int iRow = crsDataArray.length - 1; iRow >= 0; iRow--) { |
236 |
if (crsDataArray[iRow].getAuthority() != null) { |
237 |
Object row[] = |
238 |
{ crsDataArray[iRow].getAuthority(), Integer.toString(crsDataArray[iRow].getCode()),
|
239 |
crsDataArray[iRow].getName() }; |
240 |
if (crsDataArray[iRow].getAuthority().equals(PluginServices.getText(this, "USR"))) { |
241 |
available = isUSR(crsDataArray[iRow].getCode()); |
242 |
} |
243 |
if (available) {
|
244 |
dtm.addRow(row); |
245 |
} else {
|
246 |
available = true;
|
247 |
} |
248 |
} |
249 |
} |
250 |
|
251 |
/*
|
252 |
/*Seleccionar el primer registro.
|
253 |
*/
|
254 |
int numr = dtm.getRowCount();
|
255 |
if (numr != 0 ) |
256 |
this.getJTable().setRowSelectionInterval(0,0); |
257 |
} |
258 |
|
259 |
/**
|
260 |
* metodo que nos indica si un crs de usuario esta o no en la base de datos de usuario
|
261 |
* @param code
|
262 |
* @return
|
263 |
*/
|
264 |
public boolean isUSR(int code) { |
265 |
NewCRSPanel usr = new NewCRSPanel();
|
266 |
return usr.isInBD(code);
|
267 |
} |
268 |
|
269 |
public ICrs getCrs() {
|
270 |
return crs;
|
271 |
} |
272 |
|
273 |
public void initCrs(){ |
274 |
|
275 |
selectedRowTable = getJTable().getSelectedRow(); |
276 |
Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1)); |
277 |
setAuthority((String)sorter.getValueAt(selectedRowTable,0)+":"+(String)sorter.getValueAt(selectedRowTable,1)); |
278 |
|
279 |
codeCRS = Integer.parseInt((String)sorter.getValueAt(selectedRowTable,1)); |
280 |
try {
|
281 |
crs = new CrsFactory().getCRS(getAuthority());
|
282 |
} catch (CrsException e) {
|
283 |
logger.error("Can't create CRS from authority ("+this.authority+").",e); |
284 |
|
285 |
} |
286 |
} |
287 |
|
288 |
public String getAuthority() { |
289 |
return authority;
|
290 |
} |
291 |
|
292 |
public void setAuthority(String aut) { |
293 |
this.authority = aut;
|
294 |
} |
295 |
|
296 |
public void actionPerformed(ActionEvent e) { |
297 |
/*Si el objeto que genera el evento es el JButton 'InfoCrs'
|
298 |
se muestra la informacin ralicionada con el Crs seleccionado en la tabla*/
|
299 |
if (e.getSource() == this.getInfoCrs()) { |
300 |
String[] aut = getAuthority().split(":"); |
301 |
InfoCRSPanel info = new InfoCRSPanel(aut[0], getCodeCRS()); |
302 |
PluginServices.getMDIManager().addWindow(info); |
303 |
} |
304 |
|
305 |
} |
306 |
|
307 |
} |