⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 row.java

📁 手机资源管理系统
💻 JAVA
字号:
package com.cuit.lui;

import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Row extends Component {
	private Image icon;

	private String text;

	private Vector strings;

	private String label;

	private int posx, posy;

	private int rowWidth = LScreen.screenWidth;

	private int textWidth = rowWidth-15;

	private int rowHeight;

	private int iconAlignment = LScreen.LEFT;

	private int textAlignment = LScreen.RIGHT;

	private int iconOffsetx, iconOffsety;

	private int textOffsetx = 5, textOffsety = 0;

	private int lineSpace = 2;

	private Font rowFont = LUIConfig.DEFAULT_WRAP_FONT;

	private Font lableFont = LUIConfig.DEFAULT_WRAP_FONT;

	private int borderColor = LUIConfig.DEFAULT_ROW_BORDER_COLOR;

	private int textColor = LUIConfig.DEFAULT_TEXT_COLOR;

	private int textBGColor = LUIConfig.DEFAULT_TEXTBG_COLOR;

	private boolean isEditable = false;

	private boolean isTraversable = false;

	private boolean isAlert = false;

	public Row() {
		icon = null;
		text = null;
		label = null;
	}

	public Row(Image i) {
		if (i == null) {
			LScreen.warning("row icon parameter is null");

		}
		icon = i;
		text = null;
		label = null;
		rowHeight = getHeight();
		// setBorder(true);
	}

	public Row(String t) {
		if (t == null)
			LScreen.warning("row text parameter is null");
		text = t;
		icon = null;
		label = null;
		setTextWidth(rowWidth);
		strings = LScreen.wrapText(t, rowWidth);
		rowHeight = getHeight();
		// setBorder(true);
	}

	public Row(String t, int w) {
		if (t == null)
			LScreen.warning("row text parameter is null");
		text = t;
		icon = null;
		label = null;
		setTextWidth(w);
		strings = LScreen.wrapText(t, textWidth);
		rowHeight = getHeight();
		// setBorder(true);
	}

	public Row(Image i, String t) {
		if (i == null) {
			LScreen.warning("row icon parameter is null");

		}
		if (t == null)
			LScreen.warning("row text parameter is null");
		icon = i;
		text = t;
		label = null;
		strings = LScreen.wrapText(t, getTextWidth());
		rowHeight = getHeight();
		// setBorder(true);
	}

	public Row(Image i, String t, int w) {
		if (i == null) {
			LScreen.warning("row icon parameter is null");

		}
		if (t == null)
			LScreen.warning("row text parameter is null");
		icon = i;
		text = t;
		label = null;
		setTextWidth(w);
		setIconAlign(LScreen.LEFT);
		strings = LScreen.wrapText(t, textWidth);
		rowHeight = getHeight();
		// setBorder(true);
	}

	public void paint(Graphics g) {
		if (g == null) {
			LScreen.warning("row graphic is null!");
			return;
		}
		LScreen.console("painting row...");

		if (isBorder) {
			g.setColor(borderColor);
			g.drawRect(posx, posy, rowWidth, rowHeight);
		}

		if (icon == null) {
			LScreen.console("icon is null");
			if (isOnFocus && ifCommand) {
				g.setColor(textBGColor);
				int textHeight = (lineSpace + rowFont.getHeight())
						* strings.size() - lineSpace;
				g.fillRect(posx + textOffsetx, posy + textOffsety + 2,
						textWidth, textHeight - 2);
			}
			if (isAlert) {
				g.setColor(0x0fff0000);
			} else {
				g.setColor(textColor);
			}

			for (int i = 0; i < strings.size(); i++) {

				g.drawString((String) strings.elementAt(i), posx + textOffsetx,
						posy + textOffsety + (lineSpace + rowFont.getHeight())
								* i, 0);

			}

		} else {
			if (iconAlignment == LScreen.LEFT) {
				g.drawImage(icon, posx + iconOffsetx, posy + iconOffsety, 0);
				LScreen.console("draw image left---------------------");
				if (isOnFocus && ifCommand) {
					g.setColor(textBGColor);
					int textHeight = (lineSpace + rowFont.getHeight())
							* strings.size() - lineSpace;
					g.fillRect(posx + iconOffsetx + getIconHeight()
							+ textOffsetx, posy + textOffsety + 2, textWidth,
							textHeight - 2);
				}
				if (isAlert) {
					g.setColor(0x0fff0000);
				} else {
					g.setColor(textColor);
				}
				for (int i = 0; i < strings.size(); i++) {
					g.drawString((String) strings.elementAt(i), posx
							+ iconOffsetx + getIconHeight() + textOffsetx, posy
							+ textOffsety + (rowFont.getHeight() + lineSpace)
							* i, 0);
				}

			} else {
				if (isOnFocus && ifCommand) {
					g.setColor(textBGColor);
					int textHeight = (lineSpace + rowFont.getHeight())
							* strings.size() - lineSpace;
					g.fillRect(posx + textOffsetx, posy + textOffsety + 2,
							textWidth, textHeight - 2);
				}
				if (isAlert) {
					g.setColor(0x0fff0000);
				} else {
					g.setColor(textColor);
				}
				for (int i = 0; i < strings.size(); i++) {
					g.drawString((String) strings.elementAt(i), posx
							+ textOffsetx, posy + textOffsety
							+ (rowFont.getHeight() + lineSpace) * i, 0);
				}
				LScreen.console("draw image right---------------------");
				g.drawImage(icon, posx + textOffsetx + textWidth + iconOffsetx,
						posy + iconOffsety, 0);

			}
		}

	}

	public boolean keyEvent(int keyCode) {
		System.out.println("listened");

		generateEvent();
		return needRepaint;
	}

	public void addCommand(Command c) {
		super.addCommand(c);
		isTraversable = true;
	}

	public void setIcon(Image i) {
		icon = i;
	}

	public void setText(String s) {
		text = s;
		strings=LScreen.wrapText(text, textWidth);
		adjustLayout();
	}

	public void setPosx(int x) {
		posx = x;
	}

	public void setPosy(int y) {
		posy = y;
	}

	public void setIconAlign(int a) {
		iconAlignment = a;
	}

	public void setIconOffsetx(int x) {
		if (x < 0) {
			LScreen.warning("icon offsetx <0 !");
			return;
		}
		iconOffsetx = x;
	}

	public void setIconOffsety(int y) {
		if (y < 0) {
			LScreen.warning("icon offsetx <0 !");
			return;
		}
		iconOffsety = y;
	}

	public void setTextAlign(int t) {
		textAlignment = t;
	}

	public void setTextOffsetx(int x) {
		if (x < 0) {
			LScreen.warning("text offsetx <0 !");
			return;
		}
		textOffsetx = x;
	}

	public void setTextOffsety(int y) {
		if (y < 0) {
			LScreen.warning("text offsety <0 !");
			return;
		}
		textOffsety = y;
	}

	public void setTextWidth(int w) {
		if (w + getIconWidth() > rowWidth) {
			LScreen.warning("setTextWidth : w parm is too large!");
			textWidth = rowWidth - getIconWidth();
		}

		textWidth = w;
	}

	public void setEditable(boolean b) {
		isEditable = b;
	}

	public void setRowFont(Font f) {
		rowFont = f;
	}

	public void setLineSpace(int i) {
		lineSpace = i;
	}

	public int getIconAlign() {
		return iconAlignment;
	}

	public int getTextAlign() {
		return textAlignment;
	}

	public boolean getEditable() {
		return isEditable;
	}

	public int getTextWidth() {
		return textWidth;
	}

	public int getIconWidth() {
		if (icon == null) {
			LScreen.warning("icon is null");
			return 0;
		}
		return icon.getWidth();
	}

	public int getIconHeight() {
		if (icon == null) {
			LScreen.warning("icon is null");
			return 0;
		}
		return icon.getHeight();
	}

	public int getHeight() {
		if (text == null && icon != null) {
			rowHeight = iconOffsety + getIconHeight();
		} else if (icon == null && text != null) {
			rowHeight = textOffsety + strings.size() * rowFont.getHeight();
		} else {
			int textHeight = textOffsety + strings.size() * rowFont.getHeight()
					+ (strings.size() - 1) * lineSpace;
			int imageHeight = iconOffsety + getIconHeight();
			rowHeight = (textHeight > imageHeight) ? textHeight : imageHeight;

		}
		return rowHeight;
	}

	public int getWidth() {
		return getIconWidth() + textWidth;
	}

	public int getPosx() {
		return posx;
	}

	public int getPosy() {
		return posy;
	}

	public boolean isTraversable() {
		return isTraversable;
	}

	public void adjustLayout() {
		getWidth();
		getHeight();
	}

	public int getFocusy() {
		return getPosy();
	}

	public String getText() {
		return text;
	}

	public Image getIcon() {
		return icon;
	}

	protected void setAlert(boolean b) {
		isAlert = b;
	}

	public void reset() {
		isBorder = false;
		isOnFocus = false;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -