org.wings.table.STableColumn Maven / Gradle / Ivy
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings.table;
import javax.swing.*;
import java.io.Serializable;
/**
* STableColumn
*/
public class STableColumn implements Serializable {
protected int modelIndex;
protected Object identifier;
protected Object headerValue;
protected String width;
protected boolean hidden = false;
protected STableCellRenderer headerRenderer;
protected STableCellRenderer cellRenderer;
protected STableCellEditor cellEditor;
/**
* Empty constructor of a table column. Assumes model index 0.
*/
public STableColumn() {
this(0);
}
/**
* Constructs a new table column.
*
* @param modelIndex The index of this column inside the data model.
*/
public STableColumn(int modelIndex) {
this(modelIndex, null, null, null);
}
/**
* Constructs a new table column.
*
* @param modelIndex The index of this column inside the data model.
* @param width The desired width of this column as relative weight. (1 = default)
*/
public STableColumn(int modelIndex, String width) {
this(modelIndex, width, null, null);
}
/**
* Constructs a new table column.
*
* @param modelIndex The index of this column inside the data model.
* @param width The desired width of this column in px.
* @param cellRenderer The renderer for cells in this column
* @param cellEditor The editor for cells in this column
*/
public STableColumn(int modelIndex, String width,
STableCellRenderer cellRenderer,
STableCellEditor cellEditor) {
super();
this.modelIndex = modelIndex;
this.width = width;
this.cellRenderer = cellRenderer;
this.cellEditor = cellEditor;
headerValue = null;
}
/**
* Sets the cmp2 index for this column. The cmp2 index is the
* index of the column in the cmp2 that will be displayed by this
* STableColumn
. As the STableColumn
* is moved around in the view the cmp2 index remains constant.
*
* @param modelIndex the new modelIndex
* bound: true
* description: The cmp2 index.
*/
public void setModelIndex(int modelIndex) {
this.modelIndex = modelIndex;
}
/**
* Returns the cmp2 index for this column.
*
* @return the modelIndex
property
*/
public int getModelIndex() {
return modelIndex;
}
/**
* Sets the STableColumn
's identifier to
* anIdentifier
.
* Note: identifiers are not used by the JTable
,
* they are purely a
* convenience for the external tagging and location of columns.
*
* @param identifier an identifier for this column
* @see #getIdentifier
* bound: true
* description: A unique identifier for this column.
*/
public void setIdentifier(Object identifier) {
this.identifier = identifier;
}
/**
* Returns the identifier
object for this column.
* Note identifiers are not used by JTable
,
* they are purely a convenience for external use.
* If the identifier
is null
,
* getIdentifier()
returns getHeaderValue
* as a default.
*
* @return the identifier
property
* @see #setIdentifier
*/
public Object getIdentifier() {
return (identifier != null) ? identifier : headerValue;
}
/**
* Returns the Object
used as the value for the header
* renderer.
*
* @return the headerValue
property
* @see #setHeaderValue
*/
public Object getHeaderValue() {
return headerValue;
}
/**
* Sets the Object
whose string representation will be
* used as the value for the header for this column.
*/
public void setHeaderValue(Object headerValue) {
this.headerValue = headerValue;
}
//
// Renderers and Editors
//
/**
* Sets the TableCellRenderer
used to draw the
* STableColumn
's header to headerRenderer
.
*
* @param headerRenderer the new headerRenderer
* @see #getHeaderRenderer
* bound: true
* description: The header renderer.
*/
public void setHeaderRenderer(STableCellRenderer headerRenderer) {
this.headerRenderer = headerRenderer;
}
/**
* Returns the TableCellRenderer
used to draw the header of the
* STableColumn
. When the headerRenderer
is
* null
, the JTableHeader
* uses its defaultRenderer
. The default value for a
* headerRenderer
is null
.
*
* @return the headerRenderer
property
* @see #setHeaderRenderer
* @see #setHeaderValue
* @see javax.swing.table.JTableHeader#getDefaultRenderer()
*/
public STableCellRenderer getHeaderRenderer() {
return headerRenderer;
}
/**
* Sets the TableCellRenderer
used by JTable
* to draw individual values for this column.
*
* @param cellRenderer the new cellRenderer
* @see #getCellRenderer bound: true
* description: The renderer to use for cell values.
*/
public void setCellRenderer(STableCellRenderer cellRenderer) {
this.cellRenderer = cellRenderer;
}
/**
* Returns the TableCellRenderer
used by the
* JTable
to draw
* values for this column. The cellRenderer
of the column
* not only controls the visual look for the column, but is also used to
* interpret the value object supplied by the TableModel
.
* When the cellRenderer
is null
,
* the JTable
uses a default renderer based on the
* class of the cells in that column. The default value for a
* cellRenderer
is null
.
*
* @return the cellRenderer
property
* @see #setCellRenderer
* @see JTable#setDefaultRenderer
*/
public STableCellRenderer getCellRenderer() {
return cellRenderer;
}
/**
* Sets the editor to used by when a cell in this column is edited.
*
* @param cellEditor the new cellEditor
* @see #getCellEditor bound: true
* description: The editor to use for cell values.
*/
public void setCellEditor(STableCellEditor cellEditor) {
this.cellEditor = cellEditor;
}
/**
* Returns the TableCellEditor
used by the
* JTable
to edit values for this column. When the
* cellEditor
is null
, the JTable
* uses a default editor based on the
* class of the cells in that column. The default value for a
* cellEditor
is null
.
*
* @return the cellEditor
property
* @see #setCellEditor
* @see JTable#setDefaultEditor
*/
public STableCellEditor getCellEditor() {
return cellEditor;
}
/**
* The widht for this column including the unit
*
* @param width The width
*/
public void setWidth(String width) {
this.width = width;
}
/**
* @return The widht of this column including the unit.
*/
public String getWidth() {
return width;
}
/**
* Indicates if this column is hidden
*
* @return true
if this column is invisible
*/
public boolean isHidden() {
return hidden;
}
/**
* Indicates if this column should be hidden
*
* @param hidden true
if this column should be invisible
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
}