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

📄 htmldocument.java.svn-base

📁 开发框架。 一.说明: 此框架的意图是解决手机软件开发中常遇到
💻 SVN-BASE
字号:
package org.gggeye.easymf.ui;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.lcdui.Font;

/**
 * 
 * @author wuhua
 * <a href="http://wuhua.3geye.net">我的博客</a>
 *
 */
public class HtmlDocument {

	Vector views;
	Vector htmlForms;
	

	/**
	 * 获取或设置当前 HTML 文档中 <TITLE> 标记的文本值
	 */
	String title;
 

	// 下面跟绘制有关的参数
	public int width;
	public int height;
	public int position  ;

	public int focusIndex; // 记录焦点索引
	public int index;

	Font font;
	 
 
 

	HtmlDocument() {
		init();
		 
	}

	private void init() {
		views = new Vector();
		htmlForms = new Vector();
		this.focusIndex = 0;
		this.index = 0;
		this.position = 0;
		this.font = Font.getDefaultFont();
		this.width = 0;
		this.height = 0;
	}

	public final void addHtmlForm(HtmlForm _htmlForm){
		this.htmlForms.addElement(_htmlForm);
	}
	
	public final void deleteView(View _view){
		for(int i=_view.index+1; i<views.size(); i++){
			View tView = this.getView(i);
			tView.index -=1;
		}
		this.views.removeElement(_view);
	}
	public final void addView(View _view) {
		_view.index = this.views.size();		
		views.addElement(_view);
		_view.htmlDocument = this;
		this.height = _view.top +  _view.height;
	}

	/**
	 * type -1 down, 1 up;
	 * 
	 * @param type
	 *            byte
	 * @return HtmlElement
	 */
	public final View nextFocusView(byte type) {
		// /int index = -1;
		if (type == Container.VIEW_MOVE_DOWN)
			for (int j = this.focusIndex + 1; j < this.size(); j++) {
				View he = this.getView(j);
				if (he.hasFocus) {
					// this.focusIndex = he.index;
					return he;
				}
			}
		else {
			for (int j = this.focusIndex - 1; j >= 0; j--) {
				View he = this.getView(j);
				if (he.hasFocus) {
					// this.focusIndex = he.index;
					return he;
				}

			}
		}
		return null;
	}

	/**
	 * 获取指定的HtmlElement
	 * @param _index
	 * @return
	 */
	public final View getView(int _index) {
		return  (View) views.elementAt(_index);
		 
	}
	
	/**
	 * 查找非Hidden得HtmlElement元素
	 * 获取可见的HtmlElement
	 * 这个方法不是特别好。
	 * @param _index
	 * @return
	 */
	public final View getViewHtmlElement(int _index) {
		for(int i=_index; i<this.size(); i++){
			View  htmlElement = (View) views.elementAt(i);
			if(htmlElement instanceof HtmlHiddenField){
				continue;
			}
			return htmlElement;
		}
		return null;
		 
	}

	public final View getFocusView() {
		return (View) views.elementAt(this.focusIndex);
	}

	public final int size() {
		return views.size();
	}
	
	public final Vector getNeedLoadImage(){
		Vector vector = new Vector();
		for(int j=0; j<this.views.size(); j++){
			View he = (View) views.elementAt(j);
			if(he instanceof ImageView){
				vector.addElement(he);
			}
		}
		return vector;
	}
	 

	public View findViewByName(String _elementName) {
		if(this.views == null || this.views.size() ==0)
			return null;
		int size = this.views.size();
		for(int i=0; i<size; i++){
			View htmlElement = (View) this.views.elementAt(i);
			if(htmlElement.name!=null && htmlElement.name.equals(_elementName))
				return htmlElement;
		}
		return null;
	}
	
	/**
	 * 获取HtmlForm里面的数据,
	 * 包括Hidden, TextArea等数据
	 * @param _htmlForm
	 * @return
	 */
	public   Hashtable getKeyValues(HtmlForm _htmlForm) {
		Hashtable keyValues = new Hashtable();
		if (_htmlForm != null && _htmlForm.htmlElements.size() > 0) {
			int size = _htmlForm.htmlElements.size();
			for (int i = 0; i < size; i++) {
				View htmlElement = (View) _htmlForm.htmlElements
						.elementAt(i);
				if(htmlElement instanceof HtmlHiddenField){
					String value = htmlElement.value;
					value = value==null?"":value;
					//检查是否是变量
					int index = value.indexOf('$');
					//如果是变量的话,则去查找对应的变量值,非变量,则直接给出值就OK了
					if(index != -1 ){
						value = value.substring(index+2, value.length()-1);
						View varHtmlElement = this.findViewByName(value);
						if(varHtmlElement != null){
							keyValues.put(htmlElement.name,varHtmlElement.value);
						}else{
							keyValues.put(htmlElement.name,"");
						}
					}else{
						keyValues.put(htmlElement.name,htmlElement.value);
					}
					
				}else if(htmlElement instanceof TextArea){
					keyValues.put(htmlElement.name, htmlElement.value);
				}else if(htmlElement instanceof Radio){
					Radio tRadio = (Radio)htmlElement;
					if(tRadio.isCheck)
						keyValues.put(htmlElement.name, htmlElement.value);
				}else if(htmlElement instanceof CheckBox){
					CheckBox tCheckBox = (CheckBox)htmlElement;
					if(tCheckBox.isCheck)
						keyValues.put(htmlElement.name, htmlElement.value);
				}
				
			}
		}
		return keyValues;
	}
	/**
	 * clear views
	 */
	public void reset() {
		this.views.removeAllElements();
	//	this.htmlForms.removeAllElements();
		this.views = null;
		//this.htmlForms = null;
		
		this.focusIndex = 0;
		this.index = 0;
		this.position = 0;
		this.font = Font.getDefaultFont();
		this.width = 0;
		this.height = 0;
		this.views = new Vector();
		//init();
		
	}
}

⌨️ 快捷键说明

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