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

📄 iconpool.java

📁 j2me写的google地图
💻 JAVA
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2008-6-16 11:25:13
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   IconPool.java

package com.eightmotions.util;

import java.io.PrintStream;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Image;

// Referenced classes of package com.eightmotions.util:
//            UtilMidp, URLFetcher

public class IconPool
{

    public IconPool(String inName)
    {
        name = "";
        count = 0;
        inError = false;
        icon = null;
        m_listeners = null;
        name = inName;
    }

    public static Image getImageFromPool(String inUrl, int maxWidth)
    {
        if(inUrl.startsWith("http://"))
            inUrl = "http://mob.8motions.com/mob/img.php?out=png&destWidth=" + maxWidth + "&url=" + UtilMidp.urlEncode(inUrl);
        return getImageFromPool(inUrl, ((String) (null)));
    }

    public static Image getImageFromPool(String inUrl)
    {
        return getImageFromPool(inUrl, ((String) (null)));
    }

    public static Image getImageFromPool(String inUrl, String inDocumentBase)
    {
    	try
    	{
        return getImageFromPool(inUrl, inDocumentBase, false);
        }catch(Exception e){
        	return null;
        }
    }

    public static Image getImageFromPool(String inUrl, String inDocumentBase, boolean isAsync)
    {
    	try
    	{
        if(inUrl == null)
            return null;
        if(!inUrl.startsWith("http://") && inDocumentBase != null)
            inUrl = inDocumentBase + inUrl;
        Image ima;
        ima = (Image)icons.get(inUrl);
        if(ima == null)
        {
            System.out.println("Tryinbg to get:" + inUrl);
            if(inUrl.indexOf(':') != -1)
            {
                System.out.println("Loading from web");
                if(isAsync)
                {
                    final String url = inUrl;
                    Thread t = new Thread(new Runnable() {

                        public void run()
                        {
                            Image ima = IconPool.getImageFromUrl(url);
                            if(ima != null)
                                IconPool.icons.put(url, ima);
                        }

                    });
                    t.start();
                } else
                {
                    ima = getImageFromUrl(inUrl);
                }
            } else
            if(inUrl.length() > 1)
                ima = Image.createImage(inUrl);
            if(ima == null)
                ima = Image.createImage("/wait.png");
            icons.put(inUrl, ima);
            System.out.println("Ima creation ok..");
        }
        return ima;
//        Exception e;
//        e;
//        System.out.println("Error while creating image:" + inUrl);
//        e.printStackTrace();
//        return null;
    	}catch(Exception e)
    	{
    		return null;
    	}
    }

    static Image getImageFromUrl(String inUrl)
    {
        Image ret = null;
        try
        {
            HttpConnection cnx;
            int rc;
            do
            {
                cnx = URLFetcher.open(inUrl);
                rc = cnx.getResponseCode();
                HttpConnection _tmp = cnx;
                if(rc != 307)
                {
                    HttpConnection _tmp1 = cnx;
                    if(rc != 302)
                    {
                        HttpConnection _tmp2 = cnx;
                        if(rc != 301)
                            break;
                    }
                }
                inUrl = cnx.getHeaderField("Location");
                if(!inUrl.startsWith("http://"))
                    inUrl = "http://" + cnx.getHost() + inUrl;
                cnx.close();
            } while(true);
            if(rc == 200)
            {
                java.io.InputStream is = cnx.openInputStream();
                ret = UtilMidp.ImagecreateImage(is);
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return ret;
    }

    String name;
    int count;
    boolean inError;
    public Image icon;
    Vector m_listeners;
    static Hashtable icons = new Hashtable();
    static boolean isStarted = false;

}

⌨️ 快捷键说明

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