Package net.xoetrope.registry

Source Code of net.xoetrope.registry.TableColumnCustomizer

package net.xoetrope.registry;

import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import net.xoetrope.swing.XTable;
import net.xoetrope.xui.helper.ReflectionHelper;

/**
* Apply a customization to the columns of an JTable, XTable2 or
* other derivative
*
* <p> Copyright (c) Xoetrope Ltd., 2002-2006</p>
* <p> License: see License.txt</p>
*/
public class TableColumnCustomizer implements CustomizationAdapter
{
  /**
   * Creates a new instance of TableColumnCustomizer
   */
  public TableColumnCustomizer()
  {
  }
 
  /**
   * Apply a value to a component
   * @param methodName the method name to use in applying the property
   * @param comp the component being modified
   * @param values the values being set
   * @param scope the scope of the adapter, or the range of items for which it
   * applies the property
   * @return 0 on success
   */
  public int adapt( String methodName, Object comp, Object[] values, String scope )
  {
    XTable table = (XTable)comp;
    TableColumnModel columnModel = table.getColumnModel();
    int numColumns = columnModel.getColumnCount();
   
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    int pos;
    if (( scope != null ) && (( pos = scope.indexOf( '-' )) >= 0 )){
      if ( pos > 0 )
        min = Integer.parseInt( scope.substring( 0, pos ));
      else
        min = 0;

      if ( pos < ( scope.length() -1 ))
        max = Integer.parseInt( scope.substring( pos+1 ));
      else
        max = numColumns;
    }

    for ( int i = 0; i < numColumns; i++ ) {
      if (( scope == null ) ||
          (( i >= min ) && ( i <= max )) ||
          ( scope.equals( "*" )) ||
          ( scope.equals( "N" ) && ( i == numColumns-1 )) ||
          ( scope.equals( Integer.toString( i )))
         ) {       
        TableColumn tc = columnModel.getColumn( i );
        ReflectionHelper.setViaReflection( methodName, tc, values );
      }
    }
    return 0;
  }
}
TOP

Related Classes of net.xoetrope.registry.TableColumnCustomizer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.