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

📄 choicepopup.java

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

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

public class ChoicePopup extends Component {
	private String label;

	private Vector stringElements = new Vector();

	private PopUp choiceBox = null;

	private int choiceBoxposx, choiceBoxposy;

	protected boolean choiceBoxShow = false;

	private int selectedIndex = -1;

	public ChoicePopup(String s) {
		super.ifCommand = true;
		label = s;
		width = LScreen.screenWidth - 10;
		choiceBox = new PopUp(s);

	}

	public ChoicePopup(String s, String[] strElements) {
		this(s);
		for (int i = 0; i < strElements.length; i++) {
			stringElements.addElement(strElements[i]);
			choiceBox.add(new Row(null, strElements[i], choiceBox.panelWidth));
		}

	}

	private int getLabelWidth() {
		return LScreen.wrapTextFont.charsWidth(label.toCharArray(), 0, label
				.length()) + 2;
	}

	private int getLabelHeight() {
		return LScreen.wrapTextFont.getHeight() + 2;
	}

	public void append(String choice) {
		if (choice != null) {
			stringElements.addElement(choice);
			Row r = new Row(null, choice, choiceBox.panelWidth);
			r.ifCommand = true;
			choiceBox.add(r);
		} else {
			LScreen.error("choicepopup can't append null choice elements!");
		}
	}

	public void adjustLayout() {
		choiceBoxposx = posx + getLabelWidth() + 3;
		choiceBoxposy = posy + getLabelHeight();
		choiceBox.setPosx(choiceBoxposx);
		choiceBox.setPosy(choiceBoxposy);
		choiceBox.panelWidth = width - getLabelWidth() - 2;
		choiceBox.panelHeight = 50;
		choiceBox.setBorder(true);
		choiceBox.adjustLayout();
	}

	public int getFocusy() {
		return posy;
	}

	public int getHeight() {
		height = getLabelHeight();
		return height;
	}

	public int getWidth() {
		return width;
	}

	public boolean keyEvent(int keyCode) {
		needRepaint = false;
		if (choiceBoxShow) {
			if (keyCode == LUIConfig.FIRE) {
				selectedIndex = choiceBox.getRowPointer();
				choiceBoxShow = false;
				needRepaint = true;
			} else {
				needRepaint = choiceBox.keyEvent(keyCode);
			}

		} else {
			if (keyCode == LUIConfig.FIRE) {
				choiceBoxShow = true;
				reset();
				adjustLayout();
				needRepaint = true;
			} else {

			}
		}
		return needRepaint;
	}

	public void paint(Graphics g) {
		if (g == null) {
			LScreen.error("choicepopup graphic is null!");
			return;
		} else {

			g.setColor(0x000000);
			if (isBorder) {
				g.drawRect(posx, posy, width, height);
			}
			g.drawRect(choiceBoxposx - 2, posy + 2, choiceBox.panelWidth - 9,
					height - 4);
			g.drawString(label, posx + 1, posy + 1, 0);
			if (getSelectedString() != null) {
				g.drawString(getSelectedString(), choiceBoxposx, posy + 1, 0);
			}

			if (choiceBoxShow) {
				int originalClipx = g.getClipX();
				int originalClipy = g.getClipY();
				int originalClipWidth = g.getClipWidth();
				int originalClipHeight = g.getClipHeight();
				choiceBox.paint(g);
				g.setClip(originalClipx, originalClipy, originalClipWidth,
						originalClipHeight);
				if (isOnFocus) {

					g.setColor(0x000000);
					g.fillRect(posx + width - 8, posy, 8, height);

				}

			} else {

				g.setColor(0x000000);
				g.fillRect(posx + width - 8, posy, 8, height);
				g.setColor(0xffffff);
				g.fillTriangle(posx + width - 8, posy + 5, posx + width,
						posy + 5, posx + width - 4, posy + height - 2);

			}

		}
	}

	public void reset() {
		if (choiceBox != null) {
			choiceBox.reset();
		}
		selectedIndex=-1;
	}

	public String getLabel() {

		return label;
	}

	public int size() {
		return stringElements.size();
	}

	public String getString(int nb) {
		if (nb < 0 || nb >= stringElements.size() - 1) {
			LScreen.error("getString() parameter invalid!");
			return null;
		} else {
			return (String) stringElements.elementAt(nb);
		}
	}

	public String getSelectedString() {
		if (selectedIndex < 0) {
			LScreen.warning("nothing being chosen");
			return null;
		}
		return (String) stringElements.elementAt(selectedIndex);
	}

}

⌨️ 快捷键说明

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