01: package prefuse.data.column;
02:
03: import prefuse.data.DataTypeException;
04: import prefuse.data.event.ColumnListener;
05:
06: /**
07: * Column implementation holding a single, constant value for all rows.
08: *
09: * @author <a href="http://jheer.org">jeffrey heer</a>
10: */
11: public class ConstantColumn extends AbstractColumn {
12:
13: private int m_size;
14:
15: /**
16: * Create a new ConstantColumn.
17: * @param type the data type of this column
18: * @param defaultValue the default value used for all rows
19: */
20: public ConstantColumn(Class type, Object defaultValue) {
21: super (type, defaultValue);
22: }
23:
24: /**
25: * @see prefuse.data.column.Column#getRowCount()
26: */
27: public int getRowCount() {
28: return m_size + 1;
29: }
30:
31: /**
32: * @see prefuse.data.column.Column#setMaximumRow(int)
33: */
34: public void setMaximumRow(int nrows) {
35: m_size = nrows;
36: }
37:
38: /**
39: * @see prefuse.data.column.Column#get(int)
40: */
41: public Object get(int row) {
42: if (row < 0 || row > m_size) {
43: throw new IllegalArgumentException(
44: "Row index out of bounds: " + row);
45: }
46: return super .m_defaultValue;
47: }
48:
49: /**
50: * Unsupported operation.
51: * @see prefuse.data.column.Column#set(java.lang.Object, int)
52: */
53: public void set(Object val, int row) throws DataTypeException {
54: throw new UnsupportedOperationException(
55: "Can't set values on a ConstantColumn");
56: }
57:
58: /**
59: * Returns false.
60: * @see prefuse.data.column.Column#canSet(java.lang.Class)
61: */
62: public boolean canSet(Class type) {
63: return false;
64: }
65:
66: /**
67: * Does nothing.
68: * @see prefuse.data.column.Column#addColumnListener(prefuse.data.event.ColumnListener)
69: */
70: public void addColumnListener(ColumnListener listener) {
71: return; // column can't change, so nothing to listen to
72: }
73:
74: /**
75: * Does nothing.
76: * @see prefuse.data.column.Column#removeColumnListener(prefuse.data.event.ColumnListener)
77: */
78: public void removeColumnListener(ColumnListener listener) {
79: return; // column can't change, so nothing to listen to
80: }
81:
82: } // end of class Constant Column
|