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