1 package be
.nikiroo
.jexer
;
3 import javax
.swing
.table
.TableModel
;
5 import be
.nikiroo
.jexer
.TTableCellRenderer
.CellRendererMode
;
7 public class TTableColumn
{
8 static private TTableCellRenderer defaultrenderer
= new TTableCellRendererText(
9 CellRendererMode
.NORMAL
);
11 private TableModel model
;
12 private int modelIndex
;
14 private boolean forcedWidth
;
16 private TTableCellRenderer renderer
;
18 /** The auto-computed width of the column (the width of the largest value) */
19 private int autoWidth
;
21 private Object headerValue
;
23 public TTableColumn(int modelIndex
) {
24 this(modelIndex
, null);
27 public TTableColumn(int modelIndex
, String colName
) {
28 this(modelIndex
, colName
, null);
31 // set the width and preferred with the the max data size
32 public TTableColumn(int modelIndex
, Object colValue
, TableModel model
) {
34 this.modelIndex
= modelIndex
;
38 if (colValue
!= null) {
39 setHeaderValue(colValue
);
44 public TTableCellRenderer
getRenderer() {
45 return renderer
!= null ? renderer
: defaultrenderer
;
48 public void setCellRenderer(TTableCellRenderer renderer
) {
49 this.renderer
= renderer
;
53 * Recompute whatever data is displayed by this widget.
55 * Will just update the sizes in this case.
57 public void reflowData() {
60 for (int i
= 0; i
< model
.getRowCount(); i
++) {
61 maxDataSize
= Math
.max(
63 getRenderer().getWidthOf(
64 model
.getValueAt(i
, modelIndex
)));
67 autoWidth
= maxDataSize
;
69 setWidth(maxDataSize
);
78 public int getModelIndex() {
83 * The actual size of the column. This can be auto-computed in some cases.
85 * @return the width (never < 0)
87 public int getWidth() {
92 * Set the actual size of the column or -1 for auto size.
95 * the width (or -1 for auto)
97 public void setWidth(int width
) {
98 forcedWidth
= width
>= 0;
103 this.width
= autoWidth
;
108 * The width was forced by the user (using
109 * {@link TTableColumn#setWidth(int)} with a positive value).
111 * @return TRUE if it was
113 public boolean isForcedWidth() {
117 // not an actual forced width, but does change the width return
118 void expandWidthTo(int width
) {
122 public Object
getHeaderValue() {
126 public void setHeaderValue(Object headerValue
) {
127 this.headerValue
= headerValue
;