ColorCondition.java :  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » userinterface » Java Open Source

Java Open Source » Report » jmagallanes 1.0 
jmagallanes 1.0 » com » calipso » reportgenerator » userinterface » ColorCondition.java
package com.calipso.reportgenerator.userinterface;

import com.calipso.reportgenerator.reportcalculator.expression.Expression;
import com.calipso.reportgenerator.reportcalculator.expression.Context;

import java.awt.*;
/**
 * Clase utiliza para setear las propiedades de los colores con que se quiere pintar la tabla de data
 */
public class ColorCondition {

  private Expression expression;
  private Color color;
  private MetricState metricState;

  /**
   * Construye un nuevo objeto ColorCondition
   * @param expression
   * @param color
   * @param metricState
   */
  public ColorCondition(Expression expression, Color color, MetricState metricState) {
    this.expression = expression;
    this.color = color;
    this.metricState = metricState;
  }
/**
 * Retorna el metricState
 * @return
 */
  public MetricState getMetricState() {
    return metricState;
  }

  /**
   * Retorna la edxpresion
   * @return
   */
  public Expression getExpression() {
    return expression;
  }

  /**
   * Setea una expresion nueva al ColorCondition
   * @param expression
   */

  public void setExpression(Expression expression) {
    this.expression = expression;
  }

  /**
   * Retorna el Color  con que se desa pintar la tabla dataTable
   * @return
   */
  public Color getColor() {
    return color;
  }

  /**
   * Setea un nuevo Color al ColorCondition
   * @param color
   */
  public void setColor(Color color) {
    this.color = color;
  }

  /**
   * Retorna el nombre de la matrica
   * @return
   */
  public String getMetricName() {
    return getMetricState().getName();
  }

  /**
   * Retorna el contexto de la expresion que se dea evaluar
   * @param value
   * @return
   */
  private Context getContext(Object value) {
    Context context = new Context();
    context.add("VALUE", value);
    return context;
  }

  /**
   * verifica si el valor corresponde o esta en la expresion que se esta evaluando
   * @param value
   * @return
   */
  public boolean matches(Object value) {
    if(getExpression() != null){
      return getExpression().valueIn(getContext(value));
    }
    return false;
  }

  /**
   * Retorna el String de la expresion que se esta evaluando
   * @return
   */

  public String toString(){
    if(getExpression() !=null){
      String str = getExpression().toString();
      return str.replaceAll("VALUE", getMetricCaption());
    }
    else{
      return null;
    }
  }

  /**
   * Retorna el caption de la metrica
   * @return
   */
  private String getMetricCaption() {
    return getMetricState().getCaption();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.