svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / TablePointsPanel.java @ 4641
History | View | Annotate | Download (12.9 KB)
1 |
package com.iver.cit.gvsig.gui.Panels; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.GridBagConstraints; |
8 |
import java.awt.GridBagLayout; |
9 |
import java.awt.GridLayout; |
10 |
import java.awt.event.ActionEvent; |
11 |
import java.awt.event.ActionListener; |
12 |
import java.awt.event.MouseAdapter; |
13 |
import java.awt.event.MouseEvent; |
14 |
|
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JOptionPane; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.JScrollPane; |
19 |
import javax.swing.JTable; |
20 |
import javax.swing.table.DefaultTableModel; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
26 |
import com.iver.cit.gvsig.gui.View; |
27 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
28 |
public class TablePointsPanel extends JPanel implements ActionListener{ |
29 |
|
30 |
private GeoreferencingDialog parent = null; |
31 |
|
32 |
private JPanel pTable = null; |
33 |
private JPanel pPointSelection = null; |
34 |
private TableControlerPanel tableControlerPanel = null; |
35 |
|
36 |
private int widthGeneralPanel = 380, heightGeneralPanel = 160; |
37 |
private int widthSupPanel = 370, heightSupPanel = 125; |
38 |
private int widthInfPanel = 375, heightInfPanel = 27; |
39 |
private int widthTable = 375, heightTable = 110; |
40 |
|
41 |
private FLyrPoints lyrPoints = null; |
42 |
private int lastIndexSelection = -1; |
43 |
private boolean disableEvent = false; |
44 |
|
45 |
final static String[] columnNames = {"N?", |
46 |
"X",
|
47 |
"Y",
|
48 |
"X'",
|
49 |
"Y'",
|
50 |
"Error X",
|
51 |
"Error Y",
|
52 |
"RMS"};
|
53 |
|
54 |
private PointTable table = null; |
55 |
|
56 |
|
57 |
|
58 |
/**
|
59 |
* This is the default constructor
|
60 |
*/
|
61 |
public TablePointsPanel(GeoreferencingDialog p) {
|
62 |
super();
|
63 |
this.parent = p;
|
64 |
initialize(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* This method initializes this
|
69 |
*
|
70 |
* @return void
|
71 |
*/
|
72 |
private void initialize() { |
73 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
74 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
75 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
76 |
this.setLayout(new GridBagLayout()); |
77 |
this.setPreferredSize(new java.awt.Dimension(widthGeneralPanel, heightGeneralPanel)); |
78 |
this.setSize(new java.awt.Dimension(widthGeneralPanel, heightGeneralPanel)); |
79 |
this.setLocation(new java.awt.Point(0,0)); |
80 |
gridBagConstraints1.gridx = 0;
|
81 |
gridBagConstraints1.gridy = 0;
|
82 |
gridBagConstraints1.insets = new java.awt.Insets(2,0,2,0); |
83 |
gridBagConstraints2.gridx = 0;
|
84 |
gridBagConstraints2.gridy = 1;
|
85 |
gridBagConstraints2.insets = new java.awt.Insets(5,0,5,0); |
86 |
gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH; |
87 |
gridBagConstraints5.gridx = 0;
|
88 |
gridBagConstraints5.gridy = 1;
|
89 |
gridBagConstraints5.insets = new java.awt.Insets(1,0,1,0); |
90 |
this.add(getPTable(), gridBagConstraints1);
|
91 |
this.add(getPPointSelection(), gridBagConstraints5);
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* This method initializes jPanel
|
96 |
*
|
97 |
* @return javax.swing.JPanel
|
98 |
*/
|
99 |
public JPanel getPTable() { |
100 |
if (pTable == null) { |
101 |
BorderLayout borderLayout4 = new BorderLayout(); |
102 |
pTable = new JPanel(); |
103 |
pTable.setLayout(borderLayout4); |
104 |
pTable.setSize(new java.awt.Dimension(widthSupPanel,heightSupPanel));
|
105 |
pTable.setPreferredSize(new java.awt.Dimension(widthSupPanel,heightSupPanel));
|
106 |
pTable.add(getJTable(), BorderLayout.CENTER);
|
107 |
} |
108 |
return pTable;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* This method initializes jPanel1
|
113 |
*
|
114 |
* @return javax.swing.JPanel
|
115 |
*/
|
116 |
public JPanel getPPointSelection() { |
117 |
if (pPointSelection == null) { |
118 |
pPointSelection = new JPanel(); |
119 |
pPointSelection.setPreferredSize(new java.awt.Dimension(widthInfPanel, heightInfPanel));
|
120 |
if(this.tableControlerPanel == null){ |
121 |
FlowLayout flowLayout1 = new FlowLayout(); |
122 |
FlowLayout flowLayout = new FlowLayout(); |
123 |
FlowLayout flowLayout6 = new FlowLayout(); |
124 |
pPointSelection.setLayout(flowLayout6); |
125 |
tableControlerPanel = new TableControlerPanel();
|
126 |
tableControlerPanel.setLayout(flowLayout1); |
127 |
flowLayout1.setVgap(1);
|
128 |
flowLayout1.setHgap(0);
|
129 |
flowLayout6.setAlignment(java.awt.FlowLayout.LEFT); |
130 |
flowLayout6.setHgap(3);
|
131 |
flowLayout6.setVgap(1);
|
132 |
pPointSelection.add(tableControlerPanel, null);
|
133 |
pPointSelection.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
134 |
tableControlerPanel.getBFirst().addActionListener(this);
|
135 |
tableControlerPanel.getBLast().addActionListener(this);
|
136 |
tableControlerPanel.getBNext().addActionListener(this);
|
137 |
tableControlerPanel.getBPrev().addActionListener(this);
|
138 |
tableControlerPanel.getBNew().setVisible(false);
|
139 |
tableControlerPanel.getCPoint().addActionListener(this);
|
140 |
} |
141 |
} |
142 |
return pPointSelection;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Actualiza el n?mero de puntos del combo a partir de los contenidos en
|
147 |
* la capa de puntos. Esta funci?n es usada desde otros paneles que cambien
|
148 |
* el punto seleccionado para comunicar a la tabla la nueva selecci?n.
|
149 |
*/
|
150 |
public void updateComboPoint(int pointSelected){ |
151 |
try{
|
152 |
loadLyrPoint(); |
153 |
}catch(InstantiationException exc){ |
154 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
155 |
PluginServices.getText(this, "error_capa_puntos")); |
156 |
return;
|
157 |
} |
158 |
|
159 |
disableEvent = true;
|
160 |
tableControlerPanel.setNItems(lyrPoints.getCountPoints()); |
161 |
tableControlerPanel.getCPoint().setSelectedIndex(pointSelected); |
162 |
getJTable().getTable().setRowSelectionInterval(pointSelected, pointSelected); |
163 |
tableControlerPanel.checkArrows(); |
164 |
disableEvent = false;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* Obtiene una capa de puntos. Si no existe crea una.
|
169 |
* @return
|
170 |
*/
|
171 |
private void loadLyrPoint() throws InstantiationException{ |
172 |
|
173 |
if(lyrPoints == null){ |
174 |
if(lyrPoints == null){ |
175 |
lyrPoints = this.parent.getLyrPoints();
|
176 |
if(lyrPoints == null) |
177 |
throw new InstantiationException(); |
178 |
} |
179 |
} |
180 |
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Comprueba si los valores de un punto en los campos de la tabla est?n
|
185 |
* vacios y lanza una excepci?n si hay alguno sin informaci?n.
|
186 |
* @throws NoSuchFieldException
|
187 |
*/
|
188 |
private void checkInfoPointText(int nPunto)throws NoSuchFieldException{ |
189 |
if( getJTable().getTable().getValueAt(nPunto, 0).toString().equals("") || |
190 |
getJTable().getTable().getValueAt(nPunto, 1).toString().equals("") || |
191 |
getJTable().getTable().getValueAt(nPunto, 2).toString().equals("") || |
192 |
getJTable().getTable().getValueAt(nPunto, 3).toString().equals("") || |
193 |
getJTable().getTable().getValueAt(nPunto, 4).toString().equals("") ){ |
194 |
disableEvent = true;
|
195 |
tableControlerPanel.setSelectedIndex(lastIndexSelection); |
196 |
disableEvent = false;
|
197 |
throw new NoSuchFieldException(); |
198 |
} |
199 |
} |
200 |
/**
|
201 |
* Cuando pasamos de un punto a otro
|
202 |
* <UL>
|
203 |
* <LI>Cargamos la capa de puntos si no est? cargada todavia</LI>
|
204 |
* <LI>Comprobamos que el punto desde el que partimos no tenga campos inicio o fin vacios</LI>
|
205 |
* <LI>Seleccionamos en el combo en nuevo punto</LI>
|
206 |
* <LI>Cargamos la informaci?n del nuevo punto en los JTextField, mini imagen y seleccionamos la fila de la tabla</LI>
|
207 |
* <LI>Chequeamos la flechas para activar o desactivar las que toquen.</LI>
|
208 |
* </UL>
|
209 |
* @param changeSelection Cambia la posici?n seleccionada del combo si es true
|
210 |
* @param pos Posici?n a la que cambia el combo si el parametro chageSelection es true
|
211 |
*/
|
212 |
private void changePoint(boolean changeSelection, int pos){ |
213 |
disableEvent = true;
|
214 |
try{
|
215 |
loadLyrPoint(); |
216 |
checkInfoPointText(pos); |
217 |
if(changeSelection){
|
218 |
lastIndexSelection = pos; |
219 |
tableControlerPanel.setSelectedIndex(pos); |
220 |
} |
221 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), parent); |
222 |
tableControlerPanel.checkArrows(); |
223 |
}catch(NoSuchFieldException exc){ |
224 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
225 |
PluginServices.getText(this, "coordenadas_vacias")); |
226 |
}catch(InstantiationException exc){ |
227 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
228 |
PluginServices.getText(this, "error_capa_puntos")); |
229 |
} |
230 |
disableEvent = false;
|
231 |
} |
232 |
|
233 |
/* (non-Javadoc)
|
234 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
235 |
*/
|
236 |
public void actionPerformed(ActionEvent e) { |
237 |
//Bot?n de ir al punto inicial
|
238 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
239 |
if(tableControlerPanel.getItemCount() >= 1) |
240 |
changePoint(true, 0); |
241 |
} |
242 |
|
243 |
//Bot?n de ir al punto anterior
|
244 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
245 |
if(tableControlerPanel.getSelectedIndex() != 0) |
246 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
247 |
} |
248 |
|
249 |
//Bot?n de ir al punto siguiente
|
250 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
251 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
252 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
253 |
|
254 |
} |
255 |
|
256 |
//Bot?n de ir al punto final
|
257 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
258 |
if(tableControlerPanel.getItemCount() >= 1) |
259 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
260 |
} |
261 |
|
262 |
//Combo de selecci?n de punto
|
263 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
264 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
265 |
if(!disableEvent){
|
266 |
changePoint(true,tableControlerPanel.getSelectedIndex());
|
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
} |
272 |
/**
|
273 |
* This method initializes jTable
|
274 |
*
|
275 |
* @return javax.swing.JTable
|
276 |
*/
|
277 |
public PointTable getJTable() {
|
278 |
if (table == null) { |
279 |
table = new PointTable();
|
280 |
table.setSize(new java.awt.Dimension(widthTable, heightTable));
|
281 |
table.setPreferredSize(new java.awt.Dimension(widthTable, heightTable));
|
282 |
} |
283 |
return table;
|
284 |
} |
285 |
|
286 |
/**
|
287 |
* Elimina todas las filas de la tabla.
|
288 |
*/
|
289 |
public void clearTable(){ |
290 |
int l = table.getTable().getRowCount();
|
291 |
for(int i=0;i<l;i++) |
292 |
((DefaultTableModel)table.getTable().getModel()).removeRow(0); |
293 |
} |
294 |
|
295 |
/**
|
296 |
* @return Returns the tableControlerPanel.
|
297 |
*/
|
298 |
public TableControlerPanel getTableControlerPanel() {
|
299 |
return tableControlerPanel;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* Asigna una tabla
|
304 |
* @param table
|
305 |
*/
|
306 |
public void setTable(PointTable table){ |
307 |
this.table = table;
|
308 |
table.setSize(new java.awt.Dimension(widthTable, heightTable));
|
309 |
table.setPreferredSize(new java.awt.Dimension(widthTable, heightTable));
|
310 |
} |
311 |
|
312 |
/**
|
313 |
* Calculo del nuevo tama?o a partir de un frame redimensionado
|
314 |
* @param w Ancho del frame
|
315 |
* @param h Alto del frame
|
316 |
*/
|
317 |
public void newFrameSize(int w, int h){ |
318 |
int newWidth = w;
|
319 |
|
320 |
this.setSize(new java.awt.Dimension(newWidth, heightGeneralPanel)); |
321 |
this.setPreferredSize(new java.awt.Dimension(newWidth, heightGeneralPanel)); |
322 |
|
323 |
getPTable().setSize(new java.awt.Dimension((int)(0.98*newWidth),heightSupPanel)); |
324 |
getPTable().setPreferredSize(new java.awt.Dimension((int)(0.98*newWidth),heightSupPanel)); |
325 |
|
326 |
getJTable().setSize(new java.awt.Dimension((int)(0.98*newWidth), heightTable)); |
327 |
getJTable().setPreferredSize(new java.awt.Dimension((int)(0.98*newWidth), heightTable)); |
328 |
|
329 |
getPPointSelection().setSize(new java.awt.Dimension((int)(0.98*newWidth), heightInfPanel)); |
330 |
} |
331 |
|
332 |
public class PointTable extends JPanel { |
333 |
|
334 |
private JTable table = null; |
335 |
private JScrollPane scrollPane = null; |
336 |
|
337 |
private TableModelPoint tabModel = null; |
338 |
|
339 |
public TableModelPoint getTableModel(){
|
340 |
return tabModel;
|
341 |
} |
342 |
|
343 |
public PointTable() {
|
344 |
super(new GridLayout(1,0)); |
345 |
|
346 |
tabModel = new TableModelPoint();
|
347 |
table = new JTable(tabModel); |
348 |
table.setPreferredScrollableViewportSize(new Dimension(500, 70)); |
349 |
|
350 |
|
351 |
table.addMouseListener(new MouseAdapter() { |
352 |
public void mouseClicked(MouseEvent e) { |
353 |
|
354 |
} |
355 |
}); |
356 |
|
357 |
scrollPane = new JScrollPane(table); |
358 |
add(scrollPane); |
359 |
} |
360 |
|
361 |
/**
|
362 |
* TableModel del JTable que contiene los puntos con sus errores
|
363 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
364 |
*
|
365 |
*/
|
366 |
public class TableModelPoint extends DefaultTableModel { |
367 |
|
368 |
public TableModelPoint(){
|
369 |
super(new Object[0][8], columnNames); |
370 |
} |
371 |
|
372 |
public int getColumnCount() { |
373 |
return columnNames.length;
|
374 |
} |
375 |
|
376 |
public String getColumnName(int col) { |
377 |
return columnNames[col];
|
378 |
} |
379 |
|
380 |
public Class getColumnClass(int c) { |
381 |
return String.class; |
382 |
} |
383 |
|
384 |
public void addNew() { |
385 |
super.addRow(new Object[] {"", "", "", "", "", "", "", ""}); |
386 |
} |
387 |
|
388 |
public void setValueAt(Object value, int row, int col) { |
389 |
super.setValueAt(value, row, col);
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* Devuelve true si la celda es editable. Solo son editables
|
394 |
* las celdas de los puntos.
|
395 |
*/
|
396 |
public boolean isCellEditable(int row, int col){ |
397 |
if(col >=1 && col <=4) |
398 |
return true; |
399 |
return false; |
400 |
} |
401 |
|
402 |
|
403 |
} |
404 |
/**
|
405 |
* @return Returns the table.
|
406 |
*/
|
407 |
public JTable getTable() { |
408 |
return table;
|
409 |
} |
410 |
} |
411 |
|
412 |
} |