TableColumn.java
Upload User: itadmin8
Upload Date: 2020-11-25
Package Size: 9004k
Code Size: 10k
Development Platform:

Java

  1. /* 
  2.  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
  3.  * Copyright (C) 2002-2005 NextApp, Inc.
  4.  *
  5.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6.  *
  7.  * The contents of this file are subject to the Mozilla Public License Version
  8.  * 1.1 (the "License"); you may not use this file except in compliance with
  9.  * the License. You may obtain a copy of the License at
  10.  * http://www.mozilla.org/MPL/
  11.  *
  12.  * Software distributed under the License is distributed on an "AS IS" basis,
  13.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14.  * for the specific language governing rights and limitations under the
  15.  * License.
  16.  *
  17.  * Alternatively, the contents of this file may be used under the terms of
  18.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  19.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  20.  * in which case the provisions of the GPL or the LGPL are applicable instead
  21.  * of those above. If you wish to allow use of your version of this file only
  22.  * under the terms of either the GPL or the LGPL, and not to allow others to
  23.  * use your version of this file under the terms of the MPL, indicate your
  24.  * decision by deleting the provisions above and replace them with the notice
  25.  * and other provisions required by the GPL or the LGPL. If you do not delete
  26.  * the provisions above, a recipient may use your version of this file under
  27.  * the terms of any one of the MPL, the GPL or the LGPL.
  28.  */
  29. package nextapp.echo2.app.table;
  30. import java.beans.PropertyChangeListener;
  31. import java.beans.PropertyChangeSupport;
  32. import java.io.Serializable;
  33. import nextapp.echo2.app.Extent;
  34. /**
  35.  * A description of a single column of a <code>Table</code>.
  36.  */
  37. public class TableColumn 
  38. implements Serializable {
  39.     public static final String CELL_RENDERER_CHANGED_PROPERTY = "cellRenderer";
  40.     public static final String HEADER_RENDERER_CHANGED_PROPERTY = "headerRenderer";
  41.     public static final String HEADER_VALUE_CHANGED_PROPERTY = "headerValue";
  42.     public static final String IDENTIFIER_CHANGED_PROPERTY = "identifier";
  43.     public static final String MODEL_INDEX_CHANGED_PROPERTY = "modelIndex";
  44.     public static final String WIDTH_CHANGED_PROPERTY = "width";
  45.     
  46.     private Extent width;
  47.     private TableCellRenderer cellRenderer;
  48.     private TableCellRenderer headerRenderer;
  49.     private Object headerValue;
  50.     private int modelIndex;
  51.     private Object identifier;
  52.     private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  53.     
  54.     /**
  55.      * Creates a <code>TableColumn</code> with the specified model index, 
  56.      * undefined width, and undefined cell and header renderers.
  57.      *
  58.      * @param modelIndex the column index of model data visualized by this 
  59.      *        column
  60.      */
  61.     public TableColumn(int modelIndex) {
  62.         this(modelIndex, null, null, null);
  63.     }
  64.     
  65.     /**
  66.      * Creates a TableColumn with the specified model index and width, 
  67.      * and undefined cell and header renderers.
  68.      * 
  69.      * @param modelIndex the column index of model data visualized by this 
  70.      *        column
  71.      * @param width the column width
  72.      */
  73.     public TableColumn(int modelIndex, Extent width) {
  74.         this(modelIndex, width, null, null);
  75.     }
  76.     /**
  77.      * Creates a TableColumn with the specified model index, width, 
  78.      * and cell and header renderers.
  79.      * 
  80.      * @param modelIndex the column index of model data visualized by this 
  81.      *        column
  82.      * @param width the column width
  83.      * @param cellRenderer the renderer to use for rendering model values
  84.      * @param headerRenderer the renderer to use for rendering the header cell
  85.      */
  86.     public TableColumn(int modelIndex, Extent width, TableCellRenderer cellRenderer, TableCellRenderer headerRenderer) {        
  87.         super();
  88.         
  89.         this.modelIndex = modelIndex;
  90.         this.width = width;
  91.         setCellRenderer(cellRenderer);
  92.         setHeaderRenderer(headerRenderer);
  93.     }
  94.     
  95.     /**
  96.      * Adds a <code>PropertyChangeListener</code> to be notified
  97.      * of property changes to the column.
  98.      *
  99.      * @param l the listener to add
  100.      */
  101.     public void addPropertyChangeListener(PropertyChangeListener l) {
  102.         pcs.addPropertyChangeListener(l);
  103.     }
  104.     
  105.     /** 
  106.      * Retrieves the <code>TableCellRenderer</code> used to render values
  107.      * contained in the column.  The value of this property may be null,
  108.      * in which case the table should revert to using its default cell
  109.      * renderer.
  110.      *
  111.      * @return the cell renderer for this column
  112.      */
  113.     public TableCellRenderer getCellRenderer() {
  114.         return cellRenderer;
  115.     }
  116.     
  117.     /**
  118.      * Returns the <code>TableCellRenderer</code> used to render the
  119.      * header cell of this column.  The value of this property may be null,
  120.      * in which case the table should revert to using its default cell
  121.      * renderer.
  122.      *
  123.      * @return the header cell renderer for this column
  124.      */
  125.     public TableCellRenderer getHeaderRenderer() {
  126.         return headerRenderer;
  127.     }
  128.     
  129.     /** 
  130.      * Returns the header value for this column.  The header value is the 
  131.      * object that will be provided to the header renderer to produce
  132.      * a component that will be used as the table header for this column.
  133.      *
  134.      * @return the header value for this column
  135.      */
  136.     public Object getHeaderValue() {
  137.         return headerValue;
  138.     }
  139.     
  140.     /**
  141.      * Returns the identifier for this column.   Each table column may have
  142.      * an identifier.  Identifiers are provided as a convenience to the
  143.      * application developer, and are neither used nor required by the
  144.      * <code>Table</code> component.
  145.      *
  146.      * @return the identifier for this column
  147.      */
  148.     public Object getIdentifier() {
  149.         return identifier;
  150.     }
  151.     
  152.     /**
  153.      * Returns the column index of the model which this 
  154.      * <code>TableColumn</code> represents.  
  155.      * This value is independent of the column's position within the column 
  156.      * model, such that columns may be displayed in an arbitrary order.
  157.      *
  158.      * @return the index of the column in the model
  159.      */
  160.     public int getModelIndex() {
  161.         return modelIndex;
  162.     }
  163.     
  164.     /** 
  165.      * Returns the width of the column.
  166.      * This property supports <code>Extent</code>s with
  167.      * fixed or percentile units.
  168.      *
  169.      * @return the width
  170.      */
  171.     public Extent getWidth() {
  172.         return width;
  173.     }
  174.     
  175.     /**
  176.      * Removes a <code>PropertyChangeListener</code> from being notified
  177.      * of property changes to the column. 
  178.      *
  179.      * @param l the listener to remove
  180.      */
  181.     public void removePropertyChangeListener(PropertyChangeListener l) {
  182.         pcs.removePropertyChangeListener(l);
  183.     }
  184.     
  185.     /** 
  186.      * Sets the <code>TableCellRenderer</code> used to render values
  187.      * contained in the column.  The value of this property may be null,
  188.      * in which case the table should revert to using its default cell
  189.      * renderer.
  190.      *
  191.      * @param newValue the new cell renderer
  192.      */
  193.     public void setCellRenderer(TableCellRenderer newValue) {
  194.         TableCellRenderer oldValue = cellRenderer;
  195.         cellRenderer = newValue;
  196.         pcs.firePropertyChange(CELL_RENDERER_CHANGED_PROPERTY, oldValue, newValue);
  197.     }
  198.     
  199.     /** 
  200.      * Sets the <code>TableCellRenderer</code> used to render the
  201.      * header cell of this column.  The value of this property may be null,
  202.      * in which case the table should revert to using its default cell
  203.      * renderer.
  204.      *
  205.      * @param newValue the new header cell renderer
  206.      */
  207.     public void setHeaderRenderer(TableCellRenderer newValue) {
  208.         TableCellRenderer oldValue = headerRenderer;
  209.         headerRenderer = newValue;
  210.         pcs.firePropertyChange(HEADER_RENDERER_CHANGED_PROPERTY, oldValue, newValue);
  211.     }
  212.     
  213.     /** 
  214.      * Sets the header value for this column.  The header value is the 
  215.      * object that will be provided to the header renderer to produce
  216.      * a component that will be used as the table header for this column.
  217.      *
  218.      * @param newValue the new header value
  219.      */
  220.     public void setHeaderValue(Object newValue) {
  221.         Object oldValue = headerValue;
  222.         headerValue = newValue;
  223.         pcs.firePropertyChange(HEADER_VALUE_CHANGED_PROPERTY, oldValue, newValue);
  224.     }
  225.     
  226.     /**
  227.      * Sets the identifier for this column.  Each table column may have
  228.      * an identifier.  Identifiers are provided as a convenience to the
  229.      * application developer, and are neither used nor required by the
  230.      * Table component.
  231.      *
  232.      * @param newValue The new identifier for this column.
  233.      */
  234.     public void setIdentifier(Object newValue) {
  235.         Object oldValue = identifier;
  236.         identifier = newValue;
  237.         pcs.firePropertyChange(IDENTIFIER_CHANGED_PROPERTY, oldValue, newValue);
  238.     }
  239.     
  240.     /**
  241.      * Sets the index of the column in the <code>TableModel</code> which
  242.      * this <code>TableColumn</code> object represents.  This value is
  243.      * independent of the column's position within the column model, such that
  244.      * columns may be displayed in an arbitrary order.
  245.      *
  246.      * @param newValue the index of the column in the model
  247.      */
  248.     public void setModelIndex(int newValue) {
  249.         int oldValue = modelIndex;
  250.         modelIndex = newValue;
  251.         pcs.firePropertyChange(MODEL_INDEX_CHANGED_PROPERTY, oldValue, newValue);
  252.     }
  253.     
  254.     /** 
  255.      * Sets the width of the column.
  256.      * This property supports <code>Extent</code>s with
  257.      * fixed or percentile units.
  258.      *
  259.      * @param newValue the new width
  260.      */
  261.     public void setWidth(Extent newValue) {
  262.         Extent oldValue = width;
  263.         width = newValue;
  264.         pcs.firePropertyChange(WIDTH_CHANGED_PROPERTY, oldValue, newValue);
  265.     }
  266. }