View Javadoc

    1   package baseCode.gui.table;
    2
    3   import java.awt.Component;
    4   import java.awt.Dimension;
    5   import java.awt.Font;
    6   import java.awt.Graphics;
    7
    8   import javax.swing.JTable;
    9   import javax.swing.table.JTableHeader;
    10  import javax.swing.table.TableCellRenderer;
    11
    12  import baseCode.graphics.text.Util;
    13
    14  /***
    15   * @author Will Braynen
    16   * @version $Id: JVerticalHeaderRenderer.java,v 1.2 2004/07/27 03:18:58 pavlidis Exp $
    17   */
    18  public class JVerticalHeaderRenderer extends JTableHeader implements
    19        TableCellRenderer {
    20
    21     String m_columnName;
    22     final int PREFERRED_HEIGHT = 80;
    23     final int MAX_TEXT_LENGTH = 12;
    24
    25     // This method is called each time a column header
    26     // using this renderer needs to be rendered.
    27     public Component getTableCellRendererComponent( JTable table, Object value,
    28           boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex ) {
    29        // 'value' is column header value of column 'vColIndex'
    30        // rowIndex is always -1
    31        // isSelected is always false
    32        // hasFocus is always false
    33
    34        // Configure the component with the specified value
    35        m_columnName = value.toString();
    36
    37        // Set tool tip if desired
    38        setToolTipText( m_columnName );
    39
    40        // Since the renderer is a component, return itself
    41        return this;
    42     }
    43
    44     protected void paintComponent( Graphics g ) {
    45
    46        super.paintComponent( g );
    47        Font font = getFont();
    48
    49        if ( m_columnName.length() > MAX_TEXT_LENGTH ) {
    50           m_columnName = m_columnName.substring( 0, MAX_TEXT_LENGTH );
    51
    52        }
    53        int x = getSize().width - 4;
    54        int y = getSize().height - 4;
    55        Util.drawVerticalString( g, m_columnName, font, x, y );
    56     }
    57
    58     public Dimension getPreferredSize() {
    59
    60        return new Dimension( super.getPreferredSize().width, PREFERRED_HEIGHT );
    61     }
    62
    63     // The following methods override the defaults for performance reasons
    64     public void validate() {
    65     }
    66
    67     public void revalidate() {
    68     }
    69
    70     protected void firePropertyChange( String propertyName, Object oldValue,
    71           Object newValue ) {
    72     }
    73
    74     public void firePropertyChange( String propertyName, boolean oldValue,
    75           boolean newValue ) {
    76     }
    77  }