Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TEvenOddColoringTreeTableCellRenderer.java

00001 /*
00002 *  Name:      TEvenOddColoringTreeTableCellRenderer.java
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Tree  and  table cell  renderer  that  displays  different colors
00005 *             depending on row evenness 
00006 *  Date:      $Date: 2003/09/26 23:53:24 $
00007 *  Revision:  $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00028 package org.mpcl.nui.treetable;
00029 
00030 import java.awt.Color;
00031 import java.awt.Component;
00032 import javax.swing.JTable;
00033 import javax.swing.JTree;
00034 import javax.swing.tree.DefaultTreeCellRenderer;
00035 import org.mpcl.nui.TTreeTable;
00036 
00037 
00043 public class TEvenOddColoringTreeTableCellRenderer extends TTreeTableCellRenderer
00044 {
00045 
00047   private Color   tEvenRowColor;
00048 
00050   private Color   tOddRowColor;
00051 
00052 
00053   //
00054   //  C O N S T R U C T O R S
00055   //
00056 
00062   public TEvenOddColoringTreeTableCellRenderer ( TTreeTable tTREE_TABLE     ,
00063                                                  Color      tEVEN_ROW_COLOR ,
00064                                                  Color      tODD_ROW_COLOR  )
00065   {
00066     super (tTREE_TABLE);
00067     tEvenRowColor = tEVEN_ROW_COLOR;
00068     tOddRowColor  = tODD_ROW_COLOR;
00069   }
00070 
00071 
00072   //
00073   //  S E L E C T O R S
00074   //
00075 
00085   public Component getTableCellRendererComponent ( JTable  tTABLE       ,
00086                                                    Object  tVALUE       ,
00087                                                    boolean gIS_SELECTED ,
00088                                                    boolean gHAS_FOCUS   ,
00089                                                    int     iROW         ,
00090                                                    int     iCOLUMN      )
00091   {
00092 
00093     Component   tComponent;
00094 
00095     tComponent =
00096       super.getTableCellRendererComponent ( tTABLE       ,
00097                                             tVALUE       ,
00098                                             gIS_SELECTED ,
00099                                             gHAS_FOCUS   ,
00100                                             iROW         ,
00101                                             iCOLUMN      );
00102     if ( !gIS_SELECTED )
00103     {
00104       if ( (iROW % 2) == 1 )
00105       {
00106         tComponent.setBackground (tEvenRowColor);
00107       }
00108       else
00109       {
00110         if ( tOddRowColor == null )
00111         {
00112           tOddRowColor = tTABLE.getBackground();
00113         }
00114         tComponent.setBackground (tOddRowColor);
00115       }
00116     }
00117     return tComponent;
00118 
00119   }  // getTableCellRendererComponent()
00120 
00131   public Component getTreeCellRendererComponent ( JTree   tTREE        ,
00132                                                   Object  tVALUE       ,
00133                                                   boolean gIS_SELECTED ,
00134                                                   boolean gIS_EXPANDED ,
00135                                                   boolean gIS_LEAF     ,
00136                                                   int     iROW         ,
00137                                                   boolean gHAS_FOCUS   )
00138   {
00139 
00140     DefaultTreeCellRenderer   tTreeCellRenderer;
00141 
00142     tTreeCellRenderer = (DefaultTreeCellRenderer)
00143       super.getTreeCellRendererComponent ( tTREE        ,
00144                                            tVALUE       ,
00145                                            gIS_SELECTED ,
00146                                            gIS_EXPANDED ,
00147                                            gIS_LEAF     ,
00148                                            iROW         ,
00149                                            gHAS_FOCUS   );
00150     if ( !gIS_SELECTED )
00151     {
00152       if ( (iROW % 2) == 1 )
00153       {
00154         tTreeCellRenderer.setBackgroundNonSelectionColor (tEvenRowColor);
00155       }
00156       else
00157       {
00158         if ( tOddRowColor == null )
00159         {
00160           tOddRowColor = tTREE.getBackground();
00161         }
00162         tTreeCellRenderer.setBackgroundNonSelectionColor (tOddRowColor);
00163       }
00164     }
00165     return tTreeCellRenderer;
00166 
00167   }  // getTreeCellRendererComponent()
00168 
00169 }  // class TEvenOddColoringTreeTableCellRenderer

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18