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

📄 panel.java

📁 wap浏览器 日程安排 Rss 棋牌游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.core;import gr.fire.ui.ScrollAnimation;import gr.fire.util.Log;import java.util.Vector;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;/** * A Panel is a special type of Container. It can contain container.  *  * @author padeler *  */public class Panel extends Container{	public static final int VERTICAL_SCROLLBAR = 0x00000001;	public static final int HORIZONTAL_SCROLLBAR = 0x00000100;	public static final int NO_SCROLLBAR = 0x00000000;	private int scrollBarPolicy = 0x00000000;// no scrollbars	private Container container = null;	private boolean showDecorations = false;	private int scrollX,scrollY;		int viewPortWidth, viewPortHeight;		private boolean viewPortPositionChanged = true;// when this is true , all													// the panel needs repaint.		private boolean closeOnOutofBoundsPointerEvents=true; // controls if this panel should close when the user taps outside its bounding box. 	private Theme theme;	private Image decorTopImage, decorBottomImage;	private Vector focusableComponents = null;		private int decorLeft=0,decorTop=0,decorRight,decorBottom;			public Panel(Container cnt, int scrollbarPolicy, boolean showDecorations)	{		setFocusable(true);		this.scrollBarPolicy = scrollbarPolicy;		this.showDecorations = showDecorations;		set(cnt);		theme = FireScreen.getTheme();	}	public Panel(int scrollBarPolicy)	{		this(null, scrollBarPolicy, false);	}	public Panel()	{		this(null, 0x00000000, false);	}	public void paint(Graphics g)	{		int originalTrX = g.getTranslateX();		int originalTrY = g.getTranslateY();		int originalClipX = g.getClipX();		int originalClipY = g.getClipY();		int originalClipWidth = g.getClipWidth();		int originalClipHeight = g.getClipHeight();		if (viewPortPositionChanged)		{			g.setColor(0xFFFFFFFF);			g.fillRect(decorLeft, decorTop, viewPortWidth, viewPortHeight);			viewPortPositionChanged = false;		}		// g.setColor(0x00000000);		// g.fillRect(width-decorRight, 0, decorRight, height);		Component cmp = container;		if (cmp != null) // draw only visible components		{			if (cmp.valid == false)			{ // my component needs validation. This means that its size may				// have changed.				FireScreen.getScreen().inValidateTopLevelContainer();				return;			}			if (cmp.intersects(originalClipX, originalClipY, originalClipWidth, originalClipHeight))			{				if(showDecorations)					g.clipRect(decorLeft, decorTop, viewPortWidth, viewPortHeight); // clip to the viewport									g.clipRect(cmp.x, cmp.y, cmp.width, cmp.height);				g.translate(cmp.x, cmp.y);				if (cmp.animation == null)					cmp.paint(g);				else					cmp.animation.paint(g);				// return to the coordinates of this component.				g.translate(originalTrX - g.getTranslateX(), originalTrY - g.getTranslateY());				g.setClip(originalClipX, originalClipY, originalClipWidth, originalClipHeight);			}		}				if (showDecorations) // this panel has decorations		{			if(originalClipY < decorTop)				drawDecorTop(g);			if((originalClipY + originalClipHeight) > (height - decorBottom))				drawDecorBottom(g);			if(originalClipX < decorLeft)				drawDecorLeft(g);			if((originalClipX + originalClipWidth) > (width - decorRight))				drawDecorRight(g);					}		else		{			g.setColor(theme.borderColor);			g.drawRect(0,0,width-1,height-1);		}				drawScrollbars(g);	}		private void drawScrollbars(Graphics g)	{		if(container!=null)		{			if ((scrollBarPolicy & VERTICAL_SCROLLBAR) == VERTICAL_SCROLLBAR && container.height > viewPortHeight)			{ // draw vertical scrollbar				int rightHeight = height - decorBottom - decorTop;				g.setColor(theme.scrollColor);				int vpPosY = getViewPortPositionY();				scrollY = (rightHeight * (100 * (vpPosY + viewPortHeight / 2)) / container.height) / 100;				int tl = theme.scrollLenght / 2;				if (scrollY < tl || vpPosY == 0)					scrollY = tl;				else if (scrollY > rightHeight - tl || vpPosY == container.height - viewPortHeight)					scrollY = rightHeight - tl;						g.fillRect(width - theme.scrollSize + 1, decorTop + scrollY - tl, theme.scrollSize - 1, theme.scrollLenght);			}						if ((scrollBarPolicy & HORIZONTAL_SCROLLBAR) == HORIZONTAL_SCROLLBAR && container.width > viewPortWidth)			{ // draw vertical scrollbar				int bottomWidth = width - decorLeft - decorRight;				// draw scroll bar area.				g.setColor(theme.scrollRulerColor1);				g.drawRect(decorLeft, height - decorBottom, bottomWidth, theme.scrollSize);					g.setColor(theme.scrollRulerColor2);				g.drawLine(decorLeft + 1, height - decorBottom + 1, bottomWidth - 1, height - decorBottom + 1);				g.setColor(theme.scrollColor);				int vpPosX = getViewPortPositionX();				scrollX = (bottomWidth * (100 * (vpPosX + viewPortWidth / 2)) / container.width) / 100;				int tl = theme.scrollLenght / 2;				if (scrollX < tl || vpPosX == 0)					scrollX = tl;				else if (scrollX > bottomWidth - tl || vpPosX == container.width - viewPortWidth)					scrollX = bottomWidth - tl;					g.fillRect(decorLeft + scrollX - tl, height - decorBottom + 1, theme.scrollLenght, theme.scrollSize - 1);			}		}	}	private void drawDecorTop(Graphics g)	{		if (decorTop == 0)			return;		if (decorTopImage == null)		{			decorTopImage = Image.createImage(width, decorTop);			Graphics dg = decorTopImage.getGraphics();			Image texture = theme.getDecorTopTexture();			if (texture == null)			{				dg.setColor(theme.decorTopColor);				dg.fillRect(0, 0, width, decorTop);			} else			{ // tile the decoration texture to fill the decorTopImage				int tw = texture.getWidth();				int th = texture.getHeight();				for (int y = 0; y < (decorTop / th) + 1; ++y)				{					for (int x = 0; x < (width / tw) + 1; ++x)					{						dg.drawImage(texture, x * tw, y * th, Graphics.TOP | Graphics.LEFT);					}				}			}			// draw logo.			Image l = theme.getLogo();			if (l != null)			{				switch (theme.logoPossition)				{				case FireScreen.RIGHT:					dg.drawImage(l, width - l.getWidth(), 0, Graphics.TOP | Graphics.LEFT);					break;				case FireScreen.LEFT:					dg.drawImage(l, 0, 0, Graphics.TOP | Graphics.LEFT);					break;				case FireScreen.CENTER:					dg.drawImage(l, width / 2 - l.getWidth() / 2, 0, Graphics.TOP | Graphics.LEFT);					break;				}			}		}		g.drawImage(decorTopImage, 0, 0, Graphics.TOP | Graphics.LEFT);	}	private void drawDecorBottom(Graphics g)	{		if (decorBottom == 0)			return;		if (decorBottomImage == null)		{			decorBottomImage = Image.createImage(width, decorBottom);			Graphics dg = decorBottomImage.getGraphics();			Image texture = theme.getDecorBottomTexture();			if (texture == null)			{				dg.setColor(theme.decorBottomColor);				dg.fillRect(0, 0, width, decorBottom);			} else			{ // tile the decoration texture to fill the decorTopImage				int tw = texture.getWidth();				int th = texture.getHeight();				for (int y = 0; y < (decorBottom / th) + 1; ++y)				{					for (int x = 0; x < (width / tw) + 1; ++x)					{						dg.drawImage(texture, x * tw, y * th, Graphics.TOP | Graphics.LEFT);					}				}			}		}		g.drawImage(decorBottomImage, 0, height - decorBottom, Graphics.TOP | Graphics.LEFT);	}	private void drawDecorLeft(Graphics g)	{		if (decorLeft == 0)			return;		Image texture = theme.getDecorLeftTexture();		if (texture == null)		{			g.setColor(theme.decorLeftColor);			g.fillRect(0, decorTop, decorLeft, height - decorBottom - decorTop);		} else		{ // FIXME		}	}	private void drawDecorRight(Graphics g)	{		int rightHeight = height - decorBottom - decorTop;		Image texture = theme.getDecorRightTexture();		if (texture == null && decorRight>0)		{			g.setColor(theme.decorRightColor);			g.fillRect(width - decorRight, decorTop, decorRight, rightHeight);		} else		{ // no side texture supported by this panel implementation.					}	}	public void validate()	{		theme = FireScreen.getTheme();		if(showDecorations)		{			decorLeft = theme.decorLeft;			decorTop = theme.decorTop;			decorBottom = theme.decorBottom;			decorRight = theme.decorRight;		}		else		{			decorLeft=0;			decorTop=0;			decorBottom=0;			decorRight=0;		}				focusableComponents=null;		decorBottomImage = null;		decorTopImage = null;		int[] d = getPrefSize();		if (d == null)		{			d = getMinSize();		}		width = d[0];		height = d[1];		if (container == null)		{			valid = true;			return;		}		viewPortHeight = height - decorBottom - decorTop;		viewPortWidth = width - decorLeft - decorRight;		container.x = decorLeft;		container.y = decorTop;		if (scrollBarPolicy == NO_SCROLLBAR)		{ // no scrollbars, container is bounded on both dimensions			container.setPrefSize(viewPortWidth, viewPortHeight,false);			container.layoutManager.layoutContainer(container); // layout the																// container.			container.validate(); // validate the container			valid = true;			return;		}		if (container.getPrefSize() == null)		{ // let the layout manager calculate the prefSize.			container.layoutManager.layoutContainer(container); // layout the																// container.		}		int []tmpPs = container.getPrefSize();		int []ps = new int[]{tmpPs[0], tmpPs[1]};		if (ps[1]< viewPortHeight)			ps[1]= viewPortHeight;		if (ps[0]< viewPortWidth)			ps[0]= viewPortWidth;		// container.width=viewPortWidth;		// container.height=viewPortHeight;		//				if ((scrollBarPolicy & VERTICAL_SCROLLBAR) != VERTICAL_SCROLLBAR) // bounded																			// vertically		{ // show verticall scrollbars this means that the container has			// unbounded height			ps[1] = viewPortHeight;		}		if ((scrollBarPolicy & HORIZONTAL_SCROLLBAR) != HORIZONTAL_SCROLLBAR) // bounded																				// horizontally		{ // show horizontal scrollbars this means that the container has			// unbounded width			ps[0] = viewPortWidth;		}		container.setPrefSize(ps[0],ps[1],false); // set the new prefered size		container.layoutManager.layoutContainer(container); // layout the															// container.		container.validate(); // validate the container		valid = true;		Log.logInfo("My Dimensions: " + width + "," + height);		Log.logInfo("ViewPort Dimensions: " + viewPortWidth + "," + viewPortHeight);		Log.logInfo("Container Dimensions: " + container.width + "," + container.height);	}	/**	 * A Panel can have at most one container at any given time.	 * 	 * @param container	 */	public void set(Container container)	{

⌨️ 快捷键说明

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