1
2
3
4
5
6
7
8
9
10
11 package de.jaret.util.ui.table.model.simple;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import de.jaret.util.ui.table.model.AbstractJaretTableModel;
17 import de.jaret.util.ui.table.model.IColumn;
18 import de.jaret.util.ui.table.model.IRow;
19
20 /***
21 * Imlpementation of a very simple table model for the jaret table. The model is formed of hash maps holding objects,
22 * allowing storage of values at arbitrary indizes.
23 *
24 * @author kliem
25 * @version $Id: SimpleJaretTableModel.java 385 2007-04-29 20:31:49Z olk $
26 */
27 public class SimpleJaretTableModel extends AbstractJaretTableModel {
28 /*** map holding the columns. */
29 private Map<Integer, SimpleColumn> _cols = new HashMap<Integer, SimpleColumn>();
30 /*** map holding the rows. */
31 private Map<Integer, SimpleRow> _rows = new HashMap<Integer, SimpleRow>();
32 /*** current maximum of the col indizes. */
33 private int _colCount = -1;
34 /*** current maximum of the row indizes. */
35 private int _rowCount = -1;
36
37 /***
38 * Set a value.
39 *
40 * @param colIdx index of the column (x)
41 * @param rowIdx index of the row (y)
42 * @param value value
43 */
44 public void setValueAt(int colIdx, int rowIdx, Object value) {
45 IColumn col = getColumn(colIdx);
46 IRow row = getRow(rowIdx);
47 col.setValue(row, value);
48 }
49
50 /***
51 * Get a value.
52 *
53 * @param colIdx index of the column (x)
54 * @param rowIdx index of the row (y)
55 * @return value at the given index or <code>null</code> if none present
56 */
57 public Object getValueAt(int colIdx, int rowIdx) {
58 IColumn col = getColumn(colIdx);
59 return col.getValue(getRow(rowIdx));
60 }
61
62 /***
63 * Set the header label for a column.
64 *
65 * @param colIdx index
66 * @param label label to set
67 */
68 public void setHeaderLabel(int colIdx, String label) {
69 ((SimpleColumn) getColumn(colIdx)).setHeaderLabel(label);
70 }
71
72 /***
73 * {@inheritDoc}
74 */
75 public IColumn getColumn(int idx) {
76 SimpleColumn col = _cols.get(idx);
77 if (col == null) {
78 col = new SimpleColumn(idx, this);
79 _cols.put(idx, col);
80
81 _colCount = Math.max(_colCount, idx);
82 }
83 return col;
84 }
85
86 /***
87 * {@inheritDoc}
88 */
89 public int getColumnCount() {
90 return _colCount + 1;
91 }
92
93 /***
94 * {@inheritDoc}
95 */
96 public IRow getRow(int idx) {
97 SimpleRow row = _rows.get(idx);
98 if (row == null) {
99 row = new SimpleRow(idx);
100 _rows.put(idx, row);
101
102 _rowCount = Math.max(_rowCount, idx);
103 }
104 return row;
105 }
106
107 /***
108 * {@inheritDoc}
109 */
110 public int getRowCount() {
111 return _rowCount + 1;
112 }
113
114 /***
115 * {@inheritDoc}
116 */
117 public void cellChanged(IRow row, SimpleColumn column, Object value) {
118 fireCellChanged(row, column);
119 }
120
121 /***
122 * {@inheritDoc} addColumn is not implementable for the SimpleModel; does nothing.
123 */
124 public void addColumn(IColumn column) {
125
126 }
127
128
129 }