📄 inlinetag.java
字号:
/* * Fire (Flexible Interface Rendering Engine) is a set of graphics widgets for creating GUIs for j2me applications. * Copyright (C) 2006-2008 Bluevibe (www.bluevibe.net) * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *//** * */package gr.fire.browser;import java.util.Vector;import gr.fire.browser.util.Form;import gr.fire.browser.util.MenuCommand;import gr.fire.browser.util.Request;import gr.fire.browser.util.StyleSheet;import gr.fire.browser.util.XmlPullParser;import gr.fire.core.FireScreen;import gr.fire.core.Theme;import gr.fire.ui.ImageComponent;import gr.fire.ui.InputComponent;import gr.fire.util.Log;import gr.fire.util.StringUtil;import javax.microedition.io.HttpConnection;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.TextField;/** * @author padeler * */public class InlineTag extends Tag{ public static final String TAG_A = "a"; public static final String TAG_BR = "br"; public static final String TAG_TR = "tr"; public static final String TAG_TD = "td"; public static final String TAG_IMG = "img"; public static final String TAG_SPAN = "span"; public static final String TAG_B = "b"; public static final String TAG_STRONG = "strong"; public static final String TAG_I = "i"; public static final String TAG_EM = "em"; public static final String TAG_BIG = "big"; public static final String TAG_SMALL= "small"; public static final String TAG_TT= "tt"; public static final String TAG_U= "u"; public static final String TAG_CENTER= "center"; public static final String TAG_INPUT = "input"; public static final String TAG_LABEL= "label"; public static final String TAG_SELECT = "select"; public static final String TAG_OPTION = "option"; public static final String TAG_BUTTON = "button"; public static final String TAG_TEXTAREA= "textarea"; private String name=TAG_NOTSET; public InlineTag() { } public String getName() { return name; } public void inherit(Tag parent) { if(parent!=null) { inheritStyle(parent); // inherit style information if(parent instanceof BlockTag) this.parentBlockTag = (BlockTag)parent; else this.parentBlockTag = parent.parentBlockTag; } } public void handleTagStart(Browser browser, XmlPullParser parser) { name = parser.getName().toLowerCase(); // the name of the tag Tag parentElement = browser.topTag(); // may be a block element or an inline element inherit(parentElement); // first inherit from parents handleCommonAttributes(parser); // then get extra style from attributes if(TAG_A.equals(name)) { // this is a link. String hrefLocation = parser.getAttributeValue("href"); if(hrefLocation!=null) { Theme th = FireScreen.getTheme(); foregroundColor = th.linkColor; font = Font.getFont(font.getFace(),font.getStyle()|Font.STYLE_UNDERLINED,font.getSize()); listener = browser; href = new Command(hrefLocation,Command.OK,1); } return; } if(TAG_IMG.equals(name)) { String imgLocation = parser.getAttributeValue("src"); String alt = parser.getAttributeValue("alt"); if(imgLocation!=null && parentBlockTag!=null) { int width= StyleSheet.calculateLenght(parser.getAttributeValue("width"),parentBlockTag.containerWidth); int height=StyleSheet.calculateLenght(parser.getAttributeValue("height"),FireScreen.getScreen().getHeight()); Log.logInfo("Image Element ["+imgLocation+"]/["+alt+"]: "+width+","+height); Request p=null; Image image=null; try{ p = browser.requestResource(imgLocation,HttpConnection.GET,null,null); if(p!=null) { image = Image.createImage(p.getInputStream()); } }catch(Exception e){ Log.logWarn("Failed to load resource "+imgLocation,e); }finally{ if(p!=null) p.close(); } ImageComponent primitive = new ImageComponent(image,width,height,this.font,alt); copyStyle(primitive); parentBlockTag.handleComponent(this, primitive); } return; } if(TAG_BR.equals(name)) { if(parentBlockTag!=null) { parentBlockTag.lineBreak(parentBlockTag.font.getHeight(),true); } return; } if(TAG_SPAN.equals(name) || TAG_TR.equals(name) || TAG_TD.equals(name)) { handleAlignAttributes(parser); return; } if(TAG_B.equals(name) || TAG_STRONG.equals(name)) { /* * This is a B Inline Element. * As an inline Element i am inside a container. */ font = Font.getFont(font.getFace(),font.getStyle()|Font.STYLE_BOLD,font.getSize()); return; } if(TAG_I.equals(name) || TAG_EM.equals(name)) { /* * This is a I Inline Element. * As an inline Element i am inside a container. */ font = Font.getFont(font.getFace(),font.getStyle()|Font.STYLE_ITALIC,font.getSize()); return; } if(TAG_LABEL.equals(name)) { // nothing to do for labels (ignore "for" attribute until proper DOM is implemented). return; } if(TAG_INPUT.equals(name) || TAG_BUTTON.equals(name)) { Form openForm = browser.getOpenForm(); if(openForm==null || parentBlockTag==null) // ignore input elements outside forms { return; } handleInputComponent(openForm,parser); return; } if(TAG_SELECT.equals(name)) { Form openForm = browser.getOpenForm(); if(openForm==null || parentBlockTag==null) // ignore input elements outside forms { return; } boolean multiple = parser.getAttributeValue("multiple")!=null; boolean enabled = (parser.getAttributeValue("disabled")==null); String name = parser.getAttributeValue("name"); MenuCommand menuCommand = new MenuCommand(name); menuCommand.setEnabled(enabled); menuCommand.setMultiple(multiple); String size = parser.getAttributeValue("size"); if(size!=null) { try{ menuCommand.setSize(Integer.parseInt(size)); }catch(NumberFormatException e) { Log.logWarn("Failed to parse size attribute",e); } } openForm.setMenuCommand(menuCommand); return; } if(TAG_OPTION.equals(name)) { Form openForm = browser.getOpenForm(); if(openForm==null || parentBlockTag==null) // ignore input elements outside forms { return; } MenuCommand menu = openForm.getMenuCommand(); String name=null; if(menu!=null) name = menu.getName(); boolean enabled = (parser.getAttributeValue("disabled")==null); boolean checked = (parser.getAttributeValue("selected")!=null); String value= parser.getAttributeValue("value"); // get the text of the option element int type = parser.next(); String text= ""; if(type==XmlPullParser.TEXT) // text of option element text = parser.getText(); InputComponent option = new InputComponent(InputComponent.SWITCH); option.setLayout(FireScreen.VCENTER|FireScreen.CENTER); option.setChecked(checked); option.setEnabled(enabled); option.setName(name); option.setValue(value); option.setInitialValue(checked?"":null); option.setText(text); option.setMaxWidth(parentBlockTag.getContainerWidth()); copyStyle(option); int []minSize = option.getMinSize(); option.setPrefSize(minSize[0],minSize[1],false); openForm.addInputComponent(option); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -