/**
 * Copyright 2014
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loon
 * @author cping
 * @email：javachenpeng@yahoo.com
 * @version 0.4.2
 */
package loon.component.table;

import loon.canvas.LColor;
import loon.component.table.LTable.BindIcon;
import loon.font.IFont;
import loon.font.LFont;
import loon.geom.Alignment;
import loon.geom.Dimension;
import loon.opengl.GLEx;

public class TextCellRenderer implements ICellRenderer {

	private IFont font = LFont.getDefaultFont();
	private LColor textColor = LColor.white;
	private Alignment alignment = Alignment.LEFT;

	public void paint(GLEx g, Object value, int x, int y, int width, int height) {
		if (value instanceof BindIcon) {
			int size = font.getHeight() - 4;
			BindIcon icon = (BindIcon) value;
			String s = icon.name;
			s = font.confineLength(s, width - size - 4);
			int entryOffset = 4 + alignment.alignX(width - 4,
					font.stringWidth(s));
			g.setColor(textColor);
			if (icon.texture != null) {
				g.draw(icon.texture, x + 4, y + (font.getHeight() - size) / 2,
						size, size);
				font.drawString(g, s, x + size + entryOffset + 4, y - 4);
			} else {
				font.drawString(g, s, x + entryOffset, y - 4);
			}
		} else {
			String s = value.toString();
			s = font.confineLength(s, width - 4);
			int entryOffset = 4 + alignment.alignX(width - 4,
					font.stringWidth(s));
			g.setColor(textColor);
			font.drawString(g, s, x + entryOffset, y - 4);
		}
	}

	public void setFont(IFont font) {
		this.font = font;
	}

	public void setTextColor(LColor textColor) {
		this.textColor = textColor;
	}

	public Dimension getCellContentSize(Object value) {
		if (value == null) {
			return null;
		}
		String s = value.toString();
		return new Dimension(font.stringWidth(s), font.getHeight());
	}
}

@@ -1437,34 +1437,8 @@
 ));%0A
-%09%09%09g.setColor(textColor);%0A
 %09%09%09i
@@ -1605,24 +1605,41 @@
 t + 4, y - 4
+,%0A%09%09%09%09%09%09textColor
 );%0A%09%09%09%7D else
@@ -1685,24 +1685,35 @@
 ffset, y - 4
+, textColor
 );%0A%09%09%09%7D%0A%09%09%7D 
@@ -1876,34 +1876,8 @@
 ));%0A
-%09%09%09g.setColor(textColor);%0A
 %09%09%09f
@@ -1915,24 +1915,35 @@
 ffset, y - 4
+, textColor
 );%0A%09%09%7D%0A%09%7D%0A%0A%09

fix bugs