/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias;

import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Textbox;

public class MyTextboxCustom extends Textbox {

	private boolean isLowerCase = false;
	private boolean isUpperCase = false;

	public MyTextboxCustom() {
		getDefiniedStyle();
	}

	@Override
	public String getValue() throws WrongValueException {
		if (isLowerCase) {
			return super.getValue().toLowerCase().trim();
		} else if (isUpperCase) {
			return super.getValue().toUpperCase().trim();
		}
		return super.getValue().trim();
	}

	@Override
	public void setValue(String value) throws WrongValueException {
		if (value == null) {
			super.setValue(value);
		} else {
			if (isLowerCase) {
				super.setValue(value.toLowerCase().trim());
			} else if (isUpperCase) {
				super.setValue(value.toUpperCase().trim());
			} else {
				super.setValue(value.trim());
			}

		}
	}

	@Override
	public String getText() throws WrongValueException {
		if (isLowerCase) {
			return super.getText().toLowerCase().trim();
		} else if (isUpperCase) {
			return super.getText().toUpperCase().trim();
		}
		return super.getText().trim();
	}

	@Override
	public void setText(String value) throws WrongValueException {
		if (value == null) {
			super.setText(value);
		} else {

			if (isLowerCase) {
				super.setText(value.toLowerCase().trim());
			} else if (isUpperCase) {
				super.setText(value.toUpperCase().trim());
			} else {
				super.setText(value.trim());
			}

		}
	}

	private void getDefiniedStyle() {
		if (isLowerCase) {
			this.setStyle("text-transform:lowercase;");
		} else if (isUpperCase) {
			this.setStyle("text-transform:uppercase;");
		}else{
			this.setStyle(null);
		}
	}
	
	public boolean isLowerCase() {
		return isLowerCase;
	}

	public void setIsLowerCase(boolean isLowerCase) {
		this.isLowerCase = isLowerCase;
		getDefiniedStyle();
	}

	public boolean isUpperCase() {
		return isUpperCase;
	}

	public void setIsUpperCase(boolean isUpperCase) {
		this.isUpperCase = isUpperCase;
		getDefiniedStyle();
	}

}
