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

📄 qoptionpane.java

📁 j2me 高级UI
💻 JAVA
字号:
/**
 * QDialog 解释
 * Qdialog是QUI组件中的一个轻量级Component组件
 * 继承规则	extends QItem
 * 绘画规则	预留顶端12像素 做为标题栏
 * 			预留底部(16+2+size)像素 16按钮+下空格(size+2)像素
 * 文字区域  右侧 x + 4 + size * 4 +4 ~ x+width-4
 * */
package org.qui.conmponent;

import java.util.Vector;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.qui.image.JiugongDiv;
import org.qui.info.Attribute;
import org.qui.manager.QItem;
import org.qui.manager.UIManager;
import org.qui.util.StringEx;

public class QOptionPane extends QItem {

	public static final int WARN_DIALOG = 0;

	public static final int ERROR_DIALOG = 1;

	public static final int INFORMATION_DIALOG = 2;

	public static final int QUESTION_DIALOG = 3;

	public static final int SIZE_SMALL = 0;

	public static final int SIZE_MEDIUM = 1;

	public static final int SIZE_LARGE = 2;

	private int size = 2;//2--32 1--24 0--16

//	public static void showMessageDialog(String title,String text,int style,int width,int height){
//		
//	}
//	
//	public static void showMessageDialog(String title,String text,int style,int x,int y,int width,int height){
//		
//	}
	public QOptionPane(int x, int y, int width, int height, int style, int size) {
		super(x, y, width, height);
		this.size = size;
		if(style==WARN_DIALOG){
			option_icon=UIManager.option_icon_warn;
		}else if(style==ERROR_DIALOG){
			option_icon=UIManager.option_icon_error;
		}else if(style==INFORMATION_DIALOG){
			option_icon=UIManager.option_icon_info;
		}else if(style==QUESTION_DIALOG){
			option_icon=UIManager.option_icon_ques;
		}
	}
	
	private Image option_icon = null;

	public int btn_width = 72;

	public int btn_height = 24;

	public void drawFocus(Graphics g) {

	}
	private Vector mesg = null;

	public void setMessage(String mesg) {
		this.mesg = StringEx.lineCast(mesg, width - size * 8 - 20- option_icon.getWidth(), Font.getDefaultFont());
		// 自适应因为字改变高度(宽度不能自适应)
		if ((height - size * 2 - 32) < this.mesg.size()	* Font.getDefaultFont().getHeight()) {
			height = this.mesg.size() * Font.getDefaultFont().getHeight() + 32+ size * 2;
		}
	}

	public Vector getMessage() {
		return mesg;
	}

	public void paint(Graphics g) {
		// 背景
		g.setColor(Attribute.option_backR,Attribute.option_backG,Attribute.option_backB);
		g.fillRect(x + ui.offx, y + ui.offy, width, height);
		// 标题
		g.setColor(Attribute.title_backR,Attribute.title_backG,Attribute.title_backB);
		g.fillRect(x + ui.offx, y + ui.offy, width, 12);
		g.setColor(255, 255, 255);
		g.drawLine(x + ui.offx + width - 9, y + ui.offy + 3, x + ui.offx + width - 3, y + ui.offy + 9);
		g.drawLine(x + ui.offx + width - 9, y + ui.offy + 9, x + ui.offx + width - 3, y + ui.offy + 3);
		// 前景
		// 第1/4处画符号
		g.drawImage(option_icon, x + ui.offx + 4 + size * 4, y + ui.offy + height / 2 - size * 5 - 18,Graphics.LEFT | Graphics.TOP);
		// 内容(内容区域 (x + 4 + size * 4,y+12+4))
		g.setFont(Font.getDefaultFont());
		g.setColor(fr, fg, fb);
		if (mesg != null) {
			int length = mesg.size();
			for (int i = 0; i < length; i++) {
				g.drawString("" + mesg.elementAt(i), x + ui.offx + size * 8 + 8+ option_icon.getWidth(), y + ui.offy + (height - size - 30 - Font.getDefaultFont().getHeight()* (length - 1)) / 2	+ Font.getDefaultFont().getHeight() * i, Graphics.LEFT| Graphics.TOP);
			}
		}
		// 按钮(默认72*24)
		if(focus){
			if(keyPressed){
				JiugongDiv.drawJiuGong(g, UIManager.button_focus_pressed, x +ui.offx+btn_offx+ (width-btn_width)/2, y + ui.offy +btn_offy + height -fontHeight/2-btn_height/2- 6, btn_width, btn_height);
			}else{
				JiugongDiv.drawJiuGong(g, UIManager.button_focus, x +ui.offx+btn_offx+ (width-btn_width)/2, y + ui.offy +btn_offy + height -fontHeight/2-btn_height/2- 6, btn_width, btn_height);
			}
		}else {
			JiugongDiv.drawJiuGong(g, UIManager.button_normal, x +ui.offx+btn_offx+ (width-btn_width)/2, y + ui.offy +btn_offy + height -fontHeight/2-btn_height/2- 6, btn_width, btn_height);
		}
		// 按钮文字
		g.setColor(fr, fg, fb);
		g.drawString("OK", x + ui.offx +btn_offx+ width / 2, y + ui.offy +btn_offy+ height - 6,	Graphics.BOTTOM | Graphics.HCENTER);
		//if focus
		if(focus){
			JiugongDiv.drawJiuGong(g, UIManager.light, x + ui.offx - 8, y + ui.offy - 8, width+16,height+16);
		}
	}
	
	private int btn_offx=0;
	
	private int btn_offy=0;
	
	public void keyPressed(int keyCode) {
		if(Attribute.skin==Attribute.SKIN_PLAIN){
			btn_offx++;
			btn_offy++;
		}
		super.keyPressed(keyCode);
	}

	public void keyReleased(int keyCode) {
		if(Attribute.skin==Attribute.SKIN_PLAIN){
			btn_offx--;
			btn_offy--;
		}
		super.keyReleased(keyCode);
	}

}

⌨️ 快捷键说明

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