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

📄 blocktag.java

📁 FIRE (Flexible Interface Rendering Engine)是一个J2ME上的灵活的图形界面引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			 * As a container i will have a new line before and a new line after my content			 */			if(parentBlockTag!=null)			{// update pointer position of parent				parentBlockTag.increaseBaseLine(baseLine-parentBlockTag.getLineHeight());				parentBlockTag.lineBreak(parentBlockTag.font.getHeight(),true);			}						elementContainer.setPrefSize(containerWidth,baseLine);						return;		}				if( TAG_H1.equals(name) || TAG_H2.equals(name) || TAG_H3.equals(name) || TAG_H4.equals(name) || TAG_H5.equals(name) || TAG_H6.equals(name))		{			lineBreak(font.getHeight(),true);			if(parentBlockTag!=null)			{// update pointer position of parent				parentBlockTag.increaseBaseLine(getBaseLine()-parentBlockTag.getLineHeight());				parentBlockTag.pointerX += containerWidth;			}			elementContainer.setPrefSize(containerWidth,getBaseLine());			return;		}				if(TAG_DIV.equals(name))		{			int baseLine = getBaseLine();			if(parentBlockTag!=null)			{// update pointer position of parent				int lineHeight = getLineHeight();				if(pointerX==0 && lineHeight>0) baseLine -= lineHeight; // ignore last empty line break.				parentBlockTag.increaseBaseLine(baseLine-parentBlockTag.getLineHeight());				parentBlockTag.pointerX += containerWidth;			}			elementContainer.setPrefSize(containerWidth,baseLine);			return;					}				if(TAG_TABLE.equals(name) || TAG_TR.equals(name))		{			if(parentBlockTag!=null)			{// update pointer position of parent				parentBlockTag.increaseBaseLine(getBaseLine()-parentBlockTag.getLineHeight());				parentBlockTag.pointerX += containerWidth;			}			elementContainer.setPrefSize(containerWidth,getBaseLine());			return;		}				if(TAG_FORM.equals(name))		{			int baseLine = getBaseLine();						if(parentBlockTag!=null)			{// update pointer position of parent				parentBlockTag.increaseBaseLine(baseLine-parentBlockTag.getLineHeight());				parentBlockTag.pointerX += containerWidth;			}			elementContainer.setPrefSize(containerWidth,baseLine);			page.setOpenForm(null);			return;		}				if(TAG_HR.equals(name))		{			// prepare the hr image			if(containerWidth>3) //if container width is less than 3 pixels. skip hr.			{				Image hrImage = Image.createImage(containerWidth,2);				Graphics g = hrImage.getGraphics();				g.setColor(foregroundColor);				g.drawLine(0,0,containerWidth-2,0);				ImageComponent imCmp = new ImageComponent(hrImage,containerWidth,2,this.font,"");				copyStyle(imCmp);				handleComponent(this,imCmp); // add the hr image in the container.				lineBreak(2,true);						int baseLine = getBaseLine();				if(parentBlockTag!=null)				{// update pointer position of parent										parentBlockTag.increaseBaseLine(baseLine-parentBlockTag.getLineHeight());					parentBlockTag.pointerX += containerWidth;				}				elementContainer.setPrefSize(containerWidth,baseLine);			}			return;		}				if(TAG_BODY.equals(name))		{			elementContainer.setPrefSize(containerWidth,getBaseLine());			return;		}	}			private void handleHeaderTagStart(Tag parentElement,KXmlParser parser, Font font)	{		inherit(parentElement,true); // first inherit from parents		handleCommonAttributes(parser); // then get extra style from attributes		handleAlignAttributes(parser);		this.font = font;		lineBreak(font.getHeight(),false);		lineBreak(font.getHeight(),true);	}		public void handleText(Tag topLevelTag, String txt)	{				// add a text element 		if(pointerX==0 || !(this.getName().equals(TAG_P) || this.getName().equals(TAG_TR)))// || this.getName().equals(TAG_DIV)|| this.getName().equals(TAG_FORM)) // start of the line for this element. 			txt = StringUtil.trimStart(txt);				if(txt.length()==0) // ignore empty strings outside a paragraph.			return;				int vw = containerWidth;		TextComponent el = new TextComponent(txt,vw,pointerX);		topLevelTag.copyStyle(el);		el.validate();		int lineCount = el.getFormatedText().size();		if(lineCount==0) return;		int fontHeight = topLevelTag.font.getHeight();		// update other primitives on the same line to have the correct height.		updatePrimitivesInLineForPrimitiveHeight(fontHeight);				el.setX(0); // start from the left side of the block element		el.setY(getBaseLine()-fontHeight);		int lastLineWidth = el.getLastLineWidth();		int contentHeight = el.getContentHeight();//		el.setPrefSize(vw,contentHeight);		elementContainer.add(el);				if(lineCount==1)		{			// baseline is the same.			pointerX += lastLineWidth;		}		else		{			setBaseLine(getBaseLine()+(contentHeight-el.getLastLineHeight()));			setLineHeight(el.getLastLineHeight());			pointerX = lastLineWidth;		}				el.setId(topLevelTag.tagId);	}		public void handleComponent(Tag topLevelTag, Component el)	{		el.validate();		int d[] = el.getPrefSize();		int w = d[0];		int h = d[1];				if(pointerX>0 && pointerX+w>containerWidth)		{			lineBreak(topLevelTag.font.getHeight(),false);		}				if(w>containerWidth)		{// the components is larger than the with of this container. The only way to display it is by resizing the container.			increaseContainerWidthBy(w-containerWidth);		}				// update other primitives on the same line to have the correct height.		updatePrimitivesInLineForPrimitiveHeight(h);		el.setX(pointerX); 		el.setY(getBaseLine()-h);		elementContainer.add(el);		// update the pointetX,pointerY.		pointerX += w;				el.setId(topLevelTag.tagId);	}		/**	 * Recursively increase the width of this block tag and all its parents	 * @param diff	 */	private void increaseContainerWidthBy(int diff)	{		BlockTag bt = this;		while(bt!=null && diff>0)		{			diff -= bt.pointerX;			if(diff>0)			{				bt.containerWidth +=diff;				bt= bt.parentBlockTag;			}		}	}		private void updatePrimitivesInLineForPrimitiveHeight(int primitiveHeight)	{		int baseLine = getBaseLine();		int lineHeight = getLineHeight();		if(primitiveHeight>lineHeight) // there may be a component on my left that need rearangement		{ // the new lineHeight will be primitiveHeight and the base line will move lower.			int diff = (primitiveHeight-lineHeight);			for(int i=elementContainer.countComponents()-1;i>=0;--i) // yes there is at least one.			{				Component primitive = (Component)elementContainer.getComponent(i);								if((primitive.getY()+primitive.getContentHeight())!=baseLine) 				{ // done, this primitive ends above current location.					break;				}								if(primitive instanceof TextComponent)				{					TextComponent tp = (TextComponent)primitive;					int lastLineExtraHeight = tp.getLastLineExtraHeight() + diff;					tp.setLastLineExtraHeight(lastLineExtraHeight);					int []d = tp.getPrefSize();					if(d==null) d = tp.getMinSize();					tp.setPrefSize(d[0],d[1]+diff);					tp.validate();				}				else  // if(primitive instanceof ImageComponent || instanceof InputComponent				{					primitive.setY(primitive.getY()+ diff);				}			}			setBaseLine(baseLine +diff);			setLineHeight(primitiveHeight);		}	}		public int getContainerWidth()	{		return containerWidth;	}}

⌨️ 快捷键说明

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