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

📄 trbilde.java.svn-base

📁 利用J2ME编写的手机应用程序。 功能包括显示图片
💻 SVN-BASE
字号:
package test;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.kxml2.io.KXmlParser;
import wFramework.Map;
import wFramework.MapInputListener;
import wFramework.MapOverlay;
import wFramework.MapOverlayIcon;
import wFramework.MapOverlayPolygon;
import wFramework.Polygon;
import wFramework.ResultSet;
import wFramework.TimerListener;
import wFramework.Util;
import wFramework.XMLConnection;
import wFramework.XMLConnectionListener;
import wFramework.wFramework;

public class TrBilde extends MapOverlay implements XMLConnectionListener, TimerListener, MapInputListener
{
	private static int colors[] = null;
	private static int colorindex = 0;
	
	private int filehandle;
	private String tittel;
	private String beskrivelse;
	private Polygon polygon;
	private Map map;
	private MapOverlayIcon moIcon;
	private MapOverlayPolygon moPoly;
	private boolean visible;
	private Image bilde, bildeStor;
	public static Image background = null;
	private static Font smallFont = null;
	private int color;
	private wFramework wf;
	
	private int yscroll;
	private int renderheight;

	public TrBilde(wFramework wf, Map map, ResultSet rs)
	{
		super(map, null, null);
		this.wf = wf;
		this.map = map;
		bilde = null;
		bildeStor = null;
		filehandle = rs.getInt("bilde");
		tittel = rs.getString("tittel");
		beskrivelse = rs.getString("beskrivelse");
		polygon = rs.getPolygon("pos");
		visible = false;
		yscroll = 0;
		
		moPoly = new MapOverlayPolygon(map, null, polygon, null);
		moIcon = new MapOverlayIcon(map, polygon.getPoint(0), this);
		map.addOverlay(moIcon);
		renderheight = map.getHeight();
		
		if (background == null)
		{
			int w = map.getWidth();
			int h = map.getHeight();
			int bg[] = new int[w * h];			
			for (int i = 0; i < w * h; i++)
				bg[i] = 0xC0FFFFFF;
			background = Image.createRGBImage(bg, w, h, true);			
			smallFont = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN, Font.SIZE_SMALL);
		}
		
		if (colors == null)
		{
			colors = new int[16];
			colors[0] = 0xFFFF0000;
			colors[1] = 0xFF00FF00;
			colors[2] = 0xFF0000FF;
			colors[3] = 0xFFFFFF00;
			colors[4] = 0xFFFF00FF;
			colors[5] = 0xFF00FFFF;
			colors[6] = 0xFF800000;
			colors[7] = 0xFF008000;
			colors[8] = 0xFF000080;
			colors[9] = 0xFF808000;
			colors[10] = 0xFF800080;
			colors[11] = 0xFF008080;
			colors[12] = 0xFFFF8000;
			colors[13] = 0xFF80FF00;
			colors[14] = 0xFFFF0080;
			colors[15] = 0xFF8000FF;
		}
		
		color = colors[colorindex % colors.length];
		colorindex++;
		
		moPoly.setColor(color);
		
		XMLConnection c = new XMLConnection(this);
		String xml = wf.getSession().buildXML("<fileget filehandle='"+filehandle+"'><fileoperation><imageoperation outformat='png' imcommand='-resize 16x16'/></fileoperation></fileget>");
		c.getImage(wf.getBaseURL(), xml, new Integer(0));
	}
	
	public void paint(Graphics g)
	{
		int y = 2 + yscroll;
		g.setColor(0x00);
		g.drawImage(background, 0, 0, Graphics.TOP | Graphics.LEFT);

		y += Util.drawMultiLineString(g, tittel, 2, y, map.getWidth() - 4, map.getHeight()) + 2;		
		
		if (this.bildeStor != null)
		{
			int cx = bildeStor.getWidth();
			int cy = bildeStor.getHeight();
			g.drawImage(bildeStor, map.getWidth() / 2 - cx / 2, y, Graphics.LEFT | Graphics.TOP);			
			y += cy + 2;
		}

		Font prevFont = g.getFont();
		g.setFont(smallFont);
		renderheight = 2 + (y - yscroll) + Util.drawMultiLineString(g, beskrivelse, 2, y, map.getWidth() - 4, map.getHeight());
		renderheight = Math.max(renderheight, map.getHeight());
		g.setFont(prevFont);
	}
	
	public boolean isVisible()
	{
		return visible;
	}
	
	public void show()
	{
		if (visible) return;
		map.addOverlay(this);
		map.addKeyListener(this);
		map.disableCursor();
		visible = true;

		int w = map.getWidth() - 16;
		int h = map.getHeight() - 100;
		
		XMLConnection c = new XMLConnection(this);
		String xml = wf.getSession().buildXML("<fileget filehandle='"+filehandle+"'><fileoperation><imageoperation outformat='png' imcommand='-resize "+String.valueOf(w)+"x"+String.valueOf(h)+"'/></fileoperation></fileget>");
		c.getImage(wf.getBaseURL(), xml, new Integer(1));
	}
	
	public void hide()
	{
		if (!visible) return;
		map.removeOverlay(this);
		map.removeKeyListener(this);
		map.enableCursor();
		visible = false;
		bildeStor = null;
	}

	public MapOverlayPolygon getPolygonOverlay()
	{
		return moPoly;
	}
	
	public String toString()
	{
		return tittel;
	}

	public void xmlFailure(String error, Object param) {
	}

	public void xmlImageSuccess(Image image, Object param) 
	{
		if (((Integer)param).intValue() == 0)
		{
			bilde = Util.addBorderGlow(image, color, 4);
			moIcon.setIcon(bilde);
		}
		else
			bildeStor = Util.addBorderGlow(image, 0xFF808080, 12);
		map.repaint();
	}

	public void xmlSuccess(KXmlParser xml, Object param) throws Exception {
	}

	public void hitTimer() {
		// TODO Auto-generated method stub
		
	}

	public void onKeyPressed(int key) 
	{
		switch (key)
		{
			case Canvas.UP:
				yscroll = Math.min(yscroll + smallFont.getHeight(), 0);
				map.repaint();
				break;
			case Canvas.DOWN:
				yscroll = Math.max(yscroll - smallFont.getHeight(), map.getHeight() - renderheight);
				map.repaint();
				break;		
		}
	}
}

⌨️ 快捷键说明

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