001: package prefuse.data.column;
002:
003: import java.util.Date;
004:
005: import prefuse.data.DataTypeException;
006: import prefuse.data.event.ColumnListener;
007: import prefuse.data.parser.DataParser;
008:
009: /**
010: * Interface for a data column in a table.
011: *
012: * @author <a href="http://jheer.org">jeffrey heer</a>
013: */
014: public interface Column {
015:
016: // ------------------------------------------------------------------------
017: // Column Metadata
018:
019: /**
020: * Returns the number of rows in this data column
021: * @return the number of rows
022: */
023: public int getRowCount();
024:
025: /**
026: * Sets the number of rows in this data column
027: * @param nrows the number of rows
028: */
029: public void setMaximumRow(int nrows);
030:
031: /**
032: * Indicates if the values in this column are read-only.
033: * @return true if the values can not be edited, false otherwise
034: */
035: public boolean isReadOnly();
036:
037: /**
038: * Sets if the values in this column are read-only
039: * @param readOnly true to ensure the values can not be edited,
040: * false otherwise
041: */
042: public void setReadOnly(boolean readOnly);
043:
044: /**
045: * Indicates if the value at the given row can be edited.
046: * @param row the row to check
047: * @return true is the value can be modified, false otherwise
048: */
049: public boolean isCellEditable(int row);
050:
051: /**
052: * Returns the most specific superclass for the values in the column
053: * @return the Class of the column's data values
054: */
055: public Class getColumnType();
056:
057: /**
058: * Get the data parser used to map String values to and from the values
059: * stored by this Column.
060: * @return the DataParser used by this Column
061: */
062: public DataParser getParser();
063:
064: /**
065: * Set the data parser used to map String values to and from the values
066: * stored by this Column.
067: * @param parser the DataParser to use
068: */
069: public void setParser(DataParser parser);
070:
071: // ------------------------------------------------------------------------
072: // Listener Methods
073:
074: /**
075: * Adds a listener to be notified when this column changes
076: * @param listener the ColumnListener to add
077: */
078: public void addColumnListener(ColumnListener listener);
079:
080: /**
081: * Removes a listener, causing it to no longer be notified of changes
082: * @param listener the ColumnListener to remove
083: */
084: public void removeColumnListener(ColumnListener listener);
085:
086: // ------------------------------------------------------------------------
087: // Data Access Methods
088:
089: /**
090: * Returns the default value for rows that have not been set explicitly.
091: */
092: public Object getDefaultValue();
093:
094: /**
095: * Reverts the specified row back to the column's default value.
096: * @param row
097: */
098: public void revertToDefault(int row);
099:
100: /**
101: * Indicates if the get method can be called without
102: * an exception being thrown for the given type.
103: * @param type the Class of the data type to check
104: * @return true if the type is supported by this column, false otherwise
105: */
106: public boolean canGet(Class type);
107:
108: /**
109: * Indicates if the set method can be called without
110: * an exception being thrown for the given type.
111: * @param type the Class of the data type to check
112: * @return true if the type is supported by this column, false otherwise
113: */
114: public boolean canSet(Class type);
115:
116: /**
117: * Get the data value at the specified row
118: * @param row the row from which to retrieve the value
119: * @return the data value
120: */
121: public Object get(int row);
122:
123: /**
124: * Set the data value at the specified row
125: * @param val the value to set
126: * @param row the row at which to set the value
127: */
128: public void set(Object val, int row) throws DataTypeException;
129:
130: // ------------------------------------------------------------------------
131: // Data Type Convenience Methods
132:
133: // because java's type system can be tedious at times...
134:
135: // -- int -----------------------------------------------------------------
136:
137: /**
138: * Indicates if convenience get method can be called without
139: * an exception being thrown for the int type.
140: * @return true if getInt is supported, false otherwise
141: */
142: public boolean canGetInt();
143:
144: /**
145: * Indicates if convenience set method can be called without
146: * an exception being thrown for the int type.
147: * @return true if setInt is supported, false otherwise
148: */
149: public boolean canSetInt();
150:
151: /**
152: * Get the data value at the specified row as an integer
153: * @param row the row from which to retrieve the value
154: * @return the data value as an integer
155: * @throws DataTypeException if this column does not
156: * support the integer type
157: */
158: public int getInt(int row) throws DataTypeException;
159:
160: /**
161: * Set the data value at the specified row as an integer
162: * @param val the value to set
163: * @param row the row at which to set the value
164: * @throws DataTypeException if this column does not
165: * support the integer type
166: */
167: public void setInt(int val, int row) throws DataTypeException;
168:
169: // -- long ----------------------------------------------------------------
170:
171: /**
172: * Indicates if convenience get method can be called without
173: * an exception being thrown for the long type.
174: * @return true if getLong is supported, false otherwise
175: */
176: public boolean canGetLong();
177:
178: /**
179: * Indicates if convenience set method can be called without
180: * an exception being thrown for the long type.
181: * @return true if setLong is supported, false otherwise
182: */
183: public boolean canSetLong();
184:
185: /**
186: * Get the data value at the specified row as a long
187: * @param row the row from which to retrieve the value
188: * @return the data value as a long
189: * @throws DataTypeException if this column does not
190: * support the long type
191: */
192: public long getLong(int row) throws DataTypeException;
193:
194: /**
195: * Set the data value at the specified row as a long
196: * @param val the value to set
197: * @param row the row at which to set the value
198: * @throws DataTypeException if this column does not
199: * support the long type
200: */
201: public void setLong(long val, int row) throws DataTypeException;
202:
203: // -- float ---------------------------------------------------------------
204:
205: /**
206: * Indicates if convenience get method can be called without
207: * an exception being thrown for the float type.
208: * @return true if getFloat is supported, false otherwise
209: */
210: public boolean canGetFloat();
211:
212: /**
213: * Indicates if convenience set method can be called without
214: * an exception being thrown for the float type.
215: * @return true if setFloat is supported, false otherwise
216: */
217: public boolean canSetFloat();
218:
219: /**
220: * Get the data value at the specified row as a float
221: * @param row the row from which to retrieve the value
222: * @return the data value as a float
223: * @throws DataTypeException if this column does not
224: * support the float type
225: */
226: public float getFloat(int row) throws DataTypeException;
227:
228: /**
229: * Set the data value at the specified row as a float
230: * @param val the value to set
231: * @param row the row at which to set the value
232: * @throws DataTypeException if this column does not
233: * support the float type
234: */
235: public void setFloat(float val, int row) throws DataTypeException;
236:
237: // -- double --------------------------------------------------------------
238:
239: /**
240: * Indicates if convenience get method can be called without
241: * an exception being thrown for the double type.
242: * @return true if getDouble is supported, false otherwise
243: */
244: public boolean canGetDouble();
245:
246: /**
247: * Indicates if convenience set method can be called without
248: * an exception being thrown for the double type.
249: * @return true if setDouble is supported, false otherwise
250: */
251: public boolean canSetDouble();
252:
253: /**
254: * Get the data value at the specified row as a double
255: * @param row the row from which to retrieve the value
256: * @return the data value as a double
257: * @throws DataTypeException if this column does not
258: * support the double type
259: */
260: public double getDouble(int row) throws DataTypeException;
261:
262: /**
263: * Set the data value at the specified row as a double
264: * @param val the value to set
265: * @param row the row at which to set the value
266: * @throws DataTypeException if this column does not
267: * support the double type
268: */
269: public void setDouble(double val, int row) throws DataTypeException;
270:
271: // -- boolean -------------------------------------------------------------
272:
273: /**
274: * Indicates if convenience get method can be called without
275: * an exception being thrown for the boolean type.
276: * @return true if getBoolean is supported, false otherwise
277: */
278: public boolean canGetBoolean();
279:
280: /**
281: * Indicates if convenience set method can be called without
282: * an exception being thrown for the boolean type.
283: * @return true if setBoolean is supported, false otherwise
284: */
285: public boolean canSetBoolean();
286:
287: /**
288: * Get the data value at the specified row as a boolean
289: * @param row the row from which to retrieve the value
290: * @return the data value as a boolean
291: * @throws DataTypeException if this column does not
292: * support the boolean type
293: */
294: public boolean getBoolean(int row) throws DataTypeException;
295:
296: /**
297: * Set the data value at the specified row as a boolean
298: * @param val the value to set
299: * @param row the row at which to set the value
300: * @throws DataTypeException if this column does not
301: * support the boolean type
302: */
303: public void setBoolean(boolean val, int row)
304: throws DataTypeException;
305:
306: // -- String --------------------------------------------------------------
307:
308: /**
309: * Indicates if convenience get method can be called without
310: * an exception being thrown for the String type.
311: * @return true if getString is supported, false otherwise
312: */
313: public boolean canGetString();
314:
315: /**
316: * Indicates if convenience set method can be called without
317: * an exception being thrown for the String type.
318: * @return true if setString is supported, false otherwise
319: */
320: public boolean canSetString();
321:
322: /**
323: * Get the data value at the specified row as a String
324: * @param row the row from which to retrieve the value
325: * @return the data value as a String
326: * @throws DataTypeException if this column does not
327: * support the String type
328: */
329: public String getString(int row) throws DataTypeException;
330:
331: /**
332: * Set the data value at the specified row as a String
333: * @param val the value to set
334: * @param row the row at which to set the value
335: * @throws DataTypeException if this column does not
336: * support the String type
337: */
338: public void setString(String val, int row) throws DataTypeException;
339:
340: // -- Date ----------------------------------------------------------------
341:
342: /**
343: * Indicates if convenience get method can be called without
344: * an exception being thrown for the Date type.
345: * @return true if getDate is supported, false otherwise
346: */
347: public boolean canGetDate();
348:
349: /**
350: * Indicates if convenience set method can be called without
351: * an exception being thrown for the Date type.
352: * @return true if setDate is supported, false otherwise
353: */
354: public boolean canSetDate();
355:
356: /**
357: * Get the data value at the specified row as a Date
358: * @param row the row from which to retrieve the value
359: * @return the data value as a Date
360: * @throws DataTypeException if this column does not
361: * support the Date type
362: */
363: public Date getDate(int row) throws DataTypeException;
364:
365: /**
366: * Set the data value at the specified row as a Date
367: * @param val the value to set
368: * @param row the row at which to set the value
369: * @throws DataTypeException if this column does not
370: * support the Date type
371: */
372: public void setDate(Date val, int row) throws DataTypeException;
373:
374: } // end of interface Column
|