Revision 5702 trunk/extensions/extGeoreferencing/src/org/gvsig/georeferencing/gui/pointsTable/TablePointsPanel.java
TablePointsPanel.java | ||
---|---|---|
12 | 12 |
import java.awt.event.MouseAdapter; |
13 | 13 |
import java.awt.event.MouseEvent; |
14 | 14 |
|
15 |
import javax.swing.AbstractCellEditor; |
|
16 |
import javax.swing.JCheckBox; |
|
15 | 17 |
import javax.swing.JOptionPane; |
16 | 18 |
import javax.swing.JPanel; |
17 | 19 |
import javax.swing.JScrollPane; |
18 | 20 |
import javax.swing.JTable; |
21 |
import javax.swing.SwingConstants; |
|
22 |
import javax.swing.SwingUtilities; |
|
19 | 23 |
import javax.swing.table.DefaultTableModel; |
24 |
import javax.swing.table.TableCellEditor; |
|
25 |
import javax.swing.table.TableCellRenderer; |
|
26 |
import javax.swing.table.TableColumn; |
|
20 | 27 |
|
21 | 28 |
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog; |
22 | 29 |
|
... | ... | |
41 | 48 |
private FLyrPoints lyrPoints = null; |
42 | 49 |
private int lastIndexSelection = -1; |
43 | 50 |
private boolean disableEvent = false; |
44 |
final static String[] columnNames = {"N?", "X", "Y", |
|
51 |
final static String[] columnNames = {"", "N?", "X", "Y",
|
|
45 | 52 |
"X'", "Y'", "Error X", |
46 | 53 |
"Error Y", "RMS"}; |
47 | 54 |
private PointTable table = null; |
... | ... | |
82 | 89 |
|
83 | 90 |
table.addMouseListener(new MouseAdapter() { |
84 | 91 |
public void mouseClicked(MouseEvent e) { |
92 |
//Al seleccionar una fila de la tabla se cambia al punto correspondiente. |
|
85 | 93 |
tableControlerPanel.setSelectedIndex(table.getSelectedRow()); |
86 |
parent.getPointManager().selectPoint(table.getSelectedRow(), parent); |
|
87 |
tableControlerPanel.checkArrows(); |
|
94 |
parent.getPointManager().selectPoint(table.getSelectedRow(), parent); |
|
95 |
tableControlerPanel.checkArrows(); |
|
96 |
|
|
97 |
//Si hemos pinchado el checkBox cambiamos el valor de este y ponemos activo/desactivo el punto |
|
98 |
if(table.getSelectedColumn() == 0){ |
|
99 |
boolean value = (((Boolean)tabModel.getValueAt(table.getSelectedRow(), 0)).booleanValue()); |
|
100 |
//tabModel.setValueAt(new Boolean(!value), table.getSelectedRow(), 0); |
|
101 |
try{ |
|
102 |
parent.deactivatePanel((com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView(), new JCheckBox("", !value)); |
|
103 |
}catch(ClassCastException exc){ |
|
104 |
//Si no podemos obtener la vista dejamos el control como estaba |
|
105 |
tabModel.setValueAt(new Boolean(value), table.getSelectedRow(), 0); |
|
106 |
return; |
|
107 |
}catch(Exception exc){ |
|
108 |
//Si no podemos obtener la vista dejamos el control como estaba |
|
109 |
tabModel.setValueAt(new Boolean(value), table.getSelectedRow(), 0); |
|
110 |
return; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
88 | 114 |
} |
89 | 115 |
}); |
90 | 116 |
|
91 | 117 |
scrollPane = new JScrollPane(table); |
118 |
|
|
119 |
TableColumn column = null; |
|
120 |
for (int i = 0; i < table.getModel().getColumnCount(); i++) { |
|
121 |
column = table.getColumnModel().getColumn(i); |
|
122 |
if(i == 0){ |
|
123 |
column.setCellRenderer(new CheckColumnRenderer()); |
|
124 |
column.setCellEditor(new CheckColumnEditor()); |
|
125 |
column.setMaxWidth(19); |
|
126 |
column.setMinWidth(19); |
|
127 |
} |
|
128 |
if(i == 1){ |
|
129 |
column.setMaxWidth(25); |
|
130 |
column.setMinWidth(25); |
|
131 |
} |
|
132 |
if((i == 2) || (i == 3)){ |
|
133 |
column.setMinWidth(50); |
|
134 |
column.setMaxWidth(140); |
|
135 |
} |
|
136 |
if((i == 4) || (i == 5)){ |
|
137 |
column.setMinWidth(80); |
|
138 |
column.setMaxWidth(190); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
92 | 142 |
add(scrollPane); |
93 | 143 |
} |
94 | 144 |
|
... | ... | |
99 | 149 |
public class TableModelPoint extends DefaultTableModel { |
100 | 150 |
|
101 | 151 |
public TableModelPoint(){ |
102 |
super(new Object[0][8], columnNames);
|
|
152 |
super(new Object[0][9], columnNames);
|
|
103 | 153 |
} |
104 | 154 |
|
105 | 155 |
public int getColumnCount() { |
... | ... | |
111 | 161 |
} |
112 | 162 |
|
113 | 163 |
public Class getColumnClass(int c) { |
114 |
return String.class; |
|
164 |
if (c == 0) |
|
165 |
return Boolean.class; |
|
166 |
return String.class; |
|
115 | 167 |
} |
116 | 168 |
|
117 | 169 |
public void addNew() { |
118 |
super.addRow(new Object[] {"", "", "", "", "", "", "", ""}); |
|
170 |
super.addRow(new Object[] {new Boolean(true), "", "", "", "", "", "", "", ""});
|
|
119 | 171 |
} |
120 | 172 |
|
121 | 173 |
public void setValueAt(Object value, int row, int col) { |
... | ... | |
127 | 179 |
* las celdas de los puntos. |
128 | 180 |
*/ |
129 | 181 |
public boolean isCellEditable(int row, int col){ |
130 |
if(col >=1 && col <=4) |
|
131 |
return true; |
|
132 | 182 |
return false; |
133 | 183 |
} |
184 |
} |
|
185 |
|
|
186 |
class CheckColumnRenderer extends JCheckBox implements TableCellRenderer { |
|
187 |
final private static long serialVersionUID = -3370601314380922368L; |
|
134 | 188 |
|
135 |
|
|
189 |
public Component getTableCellRendererComponent(JTable table, |
|
190 |
Object value, |
|
191 |
boolean isSelected, |
|
192 |
boolean hasFocus, |
|
193 |
int row, int column) { |
|
194 |
if (value == null) { |
|
195 |
this.setSelected(false); |
|
196 |
} |
|
197 |
|
|
198 |
Boolean ValueAsBoolean = (Boolean) value; |
|
199 |
this.setSelected(ValueAsBoolean.booleanValue()); |
|
200 |
this.setHorizontalAlignment(SwingConstants.CENTER); |
|
201 |
|
|
202 |
return this; |
|
203 |
} |
|
136 | 204 |
} |
205 |
|
|
206 |
class CheckColumnEditor extends AbstractCellEditor implements TableCellEditor { |
|
207 |
final private static long serialVersionUID = -3370601314380922368L; |
|
208 |
public JCheckBox checkBox; |
|
209 |
|
|
210 |
public CheckColumnEditor() { |
|
211 |
super(); |
|
212 |
checkBox = new JCheckBox(); |
|
213 |
checkBox.addActionListener(new ActionListener() { |
|
214 |
public void actionPerformed(ActionEvent event) { |
|
215 |
//checkBox.setSelected(!checkBox.isSelected()); |
|
216 |
fireEditingStopped(); |
|
217 |
} |
|
218 |
}); |
|
219 |
} |
|
220 |
|
|
221 |
public Component getTableCellEditorComponent(JTable table, Object obj, |
|
222 |
boolean isSelected, |
|
223 |
int row, int col) { |
|
224 |
checkBox.setHorizontalAlignment(SwingUtilities.CENTER); |
|
225 |
|
|
226 |
Boolean lValueAsBoolean = (Boolean) obj; |
|
227 |
checkBox.setSelected(lValueAsBoolean.booleanValue()); |
|
228 |
|
|
229 |
return checkBox; |
|
230 |
} |
|
231 |
|
|
232 |
public Object getCellEditorValue() { |
|
233 |
return new Boolean(checkBox.isSelected()); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
137 | 237 |
/** |
138 | 238 |
* @return Returns the table. |
139 | 239 |
*/ |
... | ... | |
228 | 328 |
* @throws NoSuchFieldException |
229 | 329 |
*/ |
230 | 330 |
private void checkInfoPointText(int nPunto)throws NoSuchFieldException{ |
231 |
if( getJTable().getTable().getValueAt(nPunto, 0).toString().equals("") || |
|
232 |
getJTable().getTable().getValueAt(nPunto, 1).toString().equals("") || |
|
331 |
if( getJTable().getTable().getValueAt(nPunto, 1).toString().equals("") || |
|
233 | 332 |
getJTable().getTable().getValueAt(nPunto, 2).toString().equals("") || |
234 | 333 |
getJTable().getTable().getValueAt(nPunto, 3).toString().equals("") || |
235 |
getJTable().getTable().getValueAt(nPunto, 4).toString().equals("") ){ |
|
334 |
getJTable().getTable().getValueAt(nPunto, 4).toString().equals("") || |
|
335 |
getJTable().getTable().getValueAt(nPunto, 5).toString().equals("") ){ |
|
236 | 336 |
disableEvent = true; |
237 | 337 |
tableControlerPanel.setSelectedIndex(lastIndexSelection); |
238 | 338 |
disableEvent = false; |
Also available in: Unified diff