|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractTableModel
CoverageTableModel
public class CoverageTableModel
A Swing Table Model listing coverages entries. An instance
of CoverageTableModel typically contains the coverages available in a particular layer,
but this is not required.
This class also provides support for undo/redo operations, and can render the table cells in different colors according whatever the coverage file exists (the name of missing files are written in red) and if the coverage has been previously visited.
The code below shows how to use this table model in a Swing application:
Layer layer = coverageDatabase.getLayer("MyLayer");
CoverageTableModel model = new CoverageTableModel(layer.getCoverageReferences(null), null);
JTable table = new JTable(model);
// Enable cell coloring (optional).
TableCellRenderer renderer = new CoverageTableModel.CellRenderer();
view.setDefaultRenderer(String.class, renderer);
view.setDefaultRenderer(Date.class, renderer);
// Enable undo/redo manager (optional).
UndoManager undoManager = new UndoManager();
model.addUndoableEditListener(undoManager);
// Show the table in a frame.
JFrame frame = new JFrame(layer.getName());
frame.add(table);
frame.pack();
frame.setVisible(true);
If a undo manager has been setup, the application can invoke the UndoManager.undo()
and UndoManager.redo() methods.
Multi-threading
Like most Swing class, this class shall not be assumed thread-safe. This class
is designed for usage from the event dispatcher thread, unless otherwise specified.
CoverageList,
Serialized Form
| coverage/geotk-coverage-sql (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
CoverageTableModel.CellRenderer
A Table Cell Renderer for coloring the cells in a table using the Coverage Table Model. |
| Field Summary |
|---|
| Fields inherited from class AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
CoverageTableModel(Collection<? extends GridCoverageReference> refs,
Locale locale)
Creates a new table model initialized to the content of the given collection. |
|
CoverageTableModel(CoverageTableModel table)
Creates a new table initialized to the content of the given model. |
|
CoverageTableModel(Locale locale)
Creates a new, initially empty, table model. |
|
| Method Summary | |
|---|---|
void |
addUndoableEditListener(UndoableEditListener listener)
Adds a new object to inform every time a undoable action has been performed. |
Transferable |
copy(int[] rows)
Returns a transferable which can be set to the clipboard. |
Class<?> |
getColumnClass(int column)
Returns the type of cell values in the column at the given index. |
int |
getColumnCount()
Returns the number of columns in the model. |
String |
getColumnName(int column)
Returns the column name at the given index. |
protected String |
getCoverageName(GridCoverageReference entry)
Returns the coverage name to write in the table cell. |
String[] |
getCoverageNames()
Returns the name of all coverages in this table model. |
String[] |
getCoverageNames(int... rows)
Returns the name of coverages at the given row indices in this table model. |
GridCoverageReference |
getCoverageReferenceAt(int row)
Returns the coverage reference at the given row index. |
GridCoverageReference[] |
getCoverageReferences()
Returns all coverage references listed by this table model. |
int |
getRowCount()
Returns the number of rows in the model. |
TimeZone |
getTimeZone()
Returns the current timezone used for formatting dates. |
Object |
getValueAt(int row,
int column)
Returns the cell value at the given row and column. |
int[] |
indexOf(String... names)
Returns the row indices of coverage references having the given name. |
void |
remove(GridCoverageReference... toRemove)
Removes one or many coverage references from this table. |
void |
remove(int... rows)
Removes one or many rows from this table. |
void |
removeUndoableEditListener(UndoableEditListener listener)
Removes an object from the list of listeners to inform about undoable actions. |
void |
setCoverageReferences(Collection<? extends GridCoverageReference> references)
Sets the content of this table model to the given collection of coverage references. |
void |
setTimeZone(TimeZone timezone)
Sets the timezone to use for formatting dates. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CoverageTableModel(Locale locale)
setTimeZone(TimeZone) after construction.
locale - The locale for column titles and cell formatting, or
null for the default locale.
public CoverageTableModel(Collection<? extends GridCoverageReference> refs,
Locale locale)
setTimeZone(TimeZone) after construction.
refs - References to the coverages to put in the list, or null if none.locale - The locale for column titles and cell formatting, or
null for the default locale.public CoverageTableModel(CoverageTableModel table)
table - The table model to copy.| Method Detail |
|---|
public void setCoverageReferences(Collection<? extends GridCoverageReference> references)
references - The new collection of coverage references.public GridCoverageReference[] getCoverageReferences()
Note: If a call to GridCoverageReference.read
is planed, consider using the reference returned by getCoverageReferenceAt(int)
instead.
null).public GridCoverageReference getCoverageReferenceAt(int row)
GridCoverageReference.read succeed or not, and will apply a color on the corresponding
table cell accordingly.
row - The index of the desired coverage reference.
public String[] getCoverageNames()
getCoverageName(GridCoverageReference) and are usually unique for a given
layer.
null).public String[] getCoverageNames(int... rows)
getCoverageName(GridCoverageReference) and are usually unique
for a given layer.
rows - The rows for which to get the coverage names.
rows.length.public int[] indexOf(String... names)
getCoverageName(GridCoverageReference)
method do. This method is the converse of getCoverageNames(int[]).
If no image is found for a given name, the indices of the corresponding element in the returned array is set to -1.
names - The coverage reference names.
names.length. The array may contains -1 values for image not found.public void remove(int... rows)
rows - The rows to remove.public void remove(GridCoverageReference... toRemove)
toRemove - The coverage references to remove.public Transferable copy(int[] rows)
Transferable tr = model.copy(rows); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); cb.setContents(tr, owner);
rows - The indices of the rows to copy in the transferable object.
public int getRowCount()
public int getColumnCount()
public String getColumnName(int column)
getColumnName in interface TableModelgetColumnName in class AbstractTableModelpublic Class<?> getColumnClass(int column)
getColumnClass in interface TableModelgetColumnClass in class AbstractTableModelcolumn - The column index.
public Object getValueAt(int row,
int column)
row - The 0-based row index.column - The 0-based column index.
protected String getCoverageName(GridCoverageReference entry)
GridCoverageReference.getName(). Subclasses can override this method in order to
build the name differently.
entry - The coverage reference for which to get the name.
public TimeZone getTimeZone()
public void setTimeZone(TimeZone timezone)
timezone - The new timezone to use.public void addUndoableEditListener(UndoableEditListener listener)
listener - The listener to add.public void removeUndoableEditListener(UndoableEditListener listener)
listener - The listener to remove.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||