Revision 20779 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/SymbolTable.java
SymbolTable.java | ||
---|---|---|
55 | 55 |
import java.awt.event.MouseAdapter; |
56 | 56 |
import java.awt.event.MouseEvent; |
57 | 57 |
import java.util.ArrayList; |
58 |
import java.util.Hashtable; |
|
58 | 59 |
|
59 | 60 |
import javax.swing.JPanel; |
60 | 61 |
import javax.swing.JScrollPane; |
61 | 62 |
import javax.swing.event.ChangeEvent; |
62 | 63 |
import javax.swing.table.DefaultTableModel; |
64 |
import javax.swing.table.TableCellEditor; |
|
63 | 65 |
import javax.swing.table.TableColumn; |
64 | 66 |
|
65 | 67 |
import com.hardcode.gdbms.engine.values.NullValue; |
... | ... | |
84 | 86 |
*/ |
85 | 87 |
public class SymbolTable extends JPanel { |
86 | 88 |
private static final long serialVersionUID = -8694846716328735113L; |
89 |
private static Hashtable<String,TableCellEditor> cellEditors = new Hashtable<String,TableCellEditor>(); |
|
90 |
|
|
87 | 91 |
public static final String VALUES_TYPE = "values"; |
88 | 92 |
public static final String INTERVALS_TYPE = "intervals"; |
89 | 93 |
private JTable table; |
... | ... | |
108 | 112 |
table.setModel(new MyTableModel()); |
109 | 113 |
table.setPreferredScrollableViewportSize(new Dimension(480, 110)); |
110 | 114 |
|
115 |
initializeCellEditors(); |
|
116 |
|
|
111 | 117 |
// Create the scroll pane and add the table to it. |
112 | 118 |
JScrollPane scrollPane = new JScrollPane(table); |
113 | 119 |
|
114 | 120 |
// Set up column sizes. |
115 | 121 |
// initColumnSizes(table); |
116 | 122 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0)); |
117 |
setUpValueColumn(table, table.getColumnModel().getColumn(1)); |
|
123 |
|
|
124 |
if(cellEditors.get(type) == null) |
|
125 |
throw new Error("Symbol table type not set!"); |
|
126 |
|
|
127 |
setUpValueColumn(table, table.getColumnModel().getColumn(1),cellEditors.get(this.type)); |
|
118 | 128 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2)); |
119 | 129 |
|
120 | 130 |
// Add the scroll pane to this panel. |
... | ... | |
122 | 132 |
table.setRowSelectionAllowed(true); |
123 | 133 |
table.addMouseListener(rightClickActions); |
124 | 134 |
} |
135 |
/** |
|
136 |
* Inicializa los valores de los CellEditors que la SymbolTable poseer? por defecto |
|
137 |
*/ |
|
138 |
private void initializeCellEditors() { |
|
139 |
this.cellEditors.put(this.INTERVALS_TYPE,new IntervalCellEditor()); |
|
140 |
this.cellEditors.put(this.VALUES_TYPE, new ValueCellEditor()); |
|
141 |
} |
|
142 |
/** |
|
143 |
* A?ade un nuevo CellEditor a la lista de disponibles |
|
144 |
* |
|
145 |
* @param key String con el nombre identificativo del CellEditor |
|
146 |
* @param cellEditor CellEditor que va a ser a?adido |
|
147 |
*/ |
|
148 |
public static void addNewCellEditor(String key,TableCellEditor cellEditor ) { |
|
149 |
cellEditors.put(key, cellEditor); |
|
150 |
} |
|
151 |
/** |
|
152 |
* Obtiene el valor de los elementos de una fila seleccionada |
|
153 |
* |
|
154 |
* @return Object[] Array con los objetos de cada una de las columnas de la fila seleccionada |
|
155 |
*/ |
|
156 |
public Object[] getSelectedRowElements() { |
|
157 |
Object[] values = new Object[3]; |
|
125 | 158 |
|
159 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
160 |
int[] selectedRows = table.getSelectedRows(); |
|
161 |
|
|
162 |
if(selectedRows.length != 1) |
|
163 |
return null; |
|
164 |
|
|
165 |
for (int i = 0; i < 3; i++) { |
|
166 |
values[i] = m.getValueAt(selectedRows[0], i); |
|
167 |
} |
|
168 |
|
|
169 |
return values; |
|
170 |
} |
|
126 | 171 |
/** |
127 | 172 |
* A?ade una fila al modelo. |
128 | 173 |
* |
... | ... | |
241 | 286 |
public void removeAllItems() { |
242 | 287 |
table.setModel(new MyTableModel()); |
243 | 288 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0)); |
244 |
setUpValueColumn(table, table.getColumnModel().getColumn(1)); |
|
289 |
setUpValueColumn(table, table.getColumnModel().getColumn(1),cellEditors.get(this.type));
|
|
245 | 290 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2)); |
246 | 291 |
} |
247 | 292 |
|
... | ... | |
267 | 312 |
* Tabla. |
268 | 313 |
* @param column |
269 | 314 |
* Columna. |
315 |
* @param tableCellEditor |
|
270 | 316 |
*/ |
271 |
public void setUpValueColumn(JTable table2, TableColumn column) { |
|
272 |
if (type.equals(INTERVALS_TYPE)) { |
|
273 |
IntervalCellEditor intervaleditor = new IntervalCellEditor(); |
|
274 |
column.setCellEditor(intervaleditor); |
|
275 |
|
|
276 |
} else if (type.equals(VALUES_TYPE)){ |
|
277 |
ValueCellEditor valueeditor = new ValueCellEditor(); |
|
278 |
column.setCellEditor(valueeditor); |
|
279 |
} else { |
|
280 |
throw new Error("Symbol table type not set!"); |
|
281 |
} |
|
317 |
public void setUpValueColumn(JTable table2,TableColumn column, TableCellEditor tableCellEditor) { |
|
318 |
column.setCellEditor(tableCellEditor); |
|
282 | 319 |
} |
283 | 320 |
/** |
284 | 321 |
* Inicializa el cell editor de tipo s?mbolo de la columna que se pasa como |
Also available in: Unified diff