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

📄 oneloc.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                int col = m_colForeground;
                m_colForeground = 0xff0000;
                paint(g, inpx, inpy, offx, offy, w, h, zoom);
                m_colForeground = col;
            } else
            {
                int col = m_col;
                m_col = 0xff0000;
                paint(g, inpx, inpy, offx, offy, w, h, zoom);
                m_col = col;
            }
            return;
        }
        if(imageName == null)
            imageName = UtilMidp.getImgUrl(description);
        Image icon = null;
        if(imageName != null)
            icon = IconPool.getImageFromPool("http://j2memap.landspurg.net/img.php?out=png&sizex=30&url=" + UtilMidp.urlEncode(imageName), null, true);
        description = UtilMidp.checkString(description);
        address = UtilMidp.checkString(address);
        String tmp = name + "\n" + description + "\n" + address;
        g.fillRoundRect(x - m_offX, y - (m_heightB + m_offY), m_widthB, m_heightB, 10, 10);
        g.fillTriangle(x + 8, y - 8, x + 10, y - m_offY, x + 15, y - m_offY);
        g.setColor(0);
        g.drawRoundRect(x - m_offX, y - (m_heightB + m_offY), m_widthB, m_heightB, 10, 10);
        g.drawLine(x + 8, y - 8, x + 10, y - m_offY);
        g.drawLine(x + 8, y - 8, x + 15, y - m_offY);
        int lx = (x - m_offX) + 4;
        int ly = (y - (m_offY + m_heightB)) + 2;
        if(icon != null)
        {
            g.drawImage(icon, lx, ly, 20);
            ly += icon.getHeight();
        }
        int nbCarL = (m_widthB - 2) / 5;
        Font f = g.getFont();
        do
        {
            tmp = tmp.trim();
            int pos = tmp.indexOf('\n');
            if(pos == -1)
                pos = tmp.length();
            if(f.substringWidth(tmp, 0, pos) > m_widthB)
            {
                int posTmp;
                for(posTmp = 0; posTmp + 1 < tmp.length() && f.substringWidth(tmp, 0, posTmp + 1) < m_widthB; posTmp++);
                pos = posTmp - 1;
                char c;
                do
                    c = tmp.charAt(posTmp--);
                while(c != '\n' && c != ' ' && c != '-' && c != '.' && posTmp > 0);
                if(posTmp != 0)
                    pos = posTmp + 1;
            }
            g.drawString(tmp.substring(0, pos), lx, ly, 20);
            tmp = tmp.substring(pos);
            ly += stepy;
        } while(tmp.length() > 0 && ly + stepy < y - m_offY);
        g.setColor(0xffffff);
        g.drawLine(x + 10, y - m_offY, x + 15, y - m_offY);
        m_offY = saveY;
    }

    public void run()
    {
        isStarted = true;
        try
        {
            if(iconName != null && iconImage == null)
            {
                for(; getNbThreads() > 2; Thread.sleep(500L));
                incNbThreads();
                if(!iconName.startsWith("http://"))
                {
                    iconImage = IconPool.getImageFromPool(iconName);
                } else
                {
                    HttpConnection cnx = URLFetcher.open(iconName);
                    int rc = cnx.getResponseCode();
                    if(rc != 200)
                    {
                        iconName = null;
                    } else
                    {
                        InputStream is = cnx.openInputStream();
                        iconImage = UtilMidp.ImagecreateImage(is);
                        if(iconImage.getWidth() > 40)
                            iconImage = UtilMidp.getThumbnail(null, 0, 0, iconImage, 40);
                        if(m_theListener != null)
                            m_theListener.iconDownloaded(this);
                    }
                    cnx.close();
                }
                decNbThreads();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            decNbThreads();
            iconName = null;
        }
        isStarted = false;
    }

    public boolean validate()
    {
        px = MapCanvas.xFromLon(m_lon);
        py = MapCanvas.yFromLat(m_lat);
        m_widthB = m_defaultWidth;
        m_heightB = m_defaultHeight;
        return true;
    }

    public void setLonLat(Float inLon, Float inLat)
    {
        m_lon = inLon;
        m_lat = inLat;
        validate();
    }

    public void setPxPy(int inPx, int inPy)
    {
        px = inPx;
        py = inPy;
        m_lon = MapCanvas.convLon(px);
        m_lat = MapCanvas.convLat(py);
    }

    public static OneLoc createFromString(String in)
    {
        int start;
        OneLoc res;
        start = 0;
        res = new OneLoc(new Float(0L), new Float(0L));
        do
        {
            int next = in.indexOf('!', start + 1);
            if(next == -1)
                next = in.length();
            int keyPos = in.indexOf(':', start + 1);
            if(keyPos == -1)
                break;
            String key = in.substring(start, keyPos);
            String val = in.substring(keyPos + 1, next);
            if(key.equals("name"))
                res.name = val;
            else
            if(key.equals("lon"))
                res.m_lon = Float.parse(val, 10);
            else
            if(key.equals("lat"))
                res.m_lat = Float.parse(val, 10);
            else
            if(key.equals("phone"))
                res.phoneNum = val;
            else
            if(key.equals("desc"))
                res.description = val;
            else
            if(key.equals("adr"))
                res.address = val;
            else
            if(key.equals("zoom"))
                res.zoom = Integer.parseInt(val);
            else
            if(key.equals("sat"))
                res.isModeSat = val.equals("true");
            start = next + 1;
        } while(true);
        if(!res.validate())
            return null;
        return res;
//        Exception e;
//        e;
//        return null;
    }

    public void setValue(String name, Object val)
    {
        if(hash == null)
            hash = new Hashtable();
        hash.put(name, val);
    }

    public Object getValue(String name)
    {
        if(name.equals("description"))
            return description;
        if(name.equals("address"))
            return address;
        if(name.equals("name"))
            return name;
        if(hash == null)
            return null;
        else
            return hash.get(name);
    }

    public String saveToString()
    {
        String res = "name:" + name + "!lon:" + m_lon.toString() + "!lat:" + m_lat.toString() + "!desc:" + description + "!adr:" + address + "!phone:" + phoneNum + "!zoom:" + zoom + "!sat:" + isModeSat;
        return res;
    }

    public boolean equals(Object obj)
    {
        OneLoc l = (OneLoc)obj;
        return name.equals(l.name) && px == l.px && py == l.py && description.equals(l.description);
    }

    public OneLoc clone(Float inlon, Float inlat)
    {
        OneLoc res = new OneLoc(inlon, inlat);
        res.copyFrom(this);
        return res;
    }

    public void copyFrom(OneLoc in)
    {
        m_col = in.m_col;
        m_colForeground = in.m_colForeground;
        m_type = in.m_type;
        m_offX = in.m_offX;
        m_offY = in.m_offY;
        iconImage = in.iconImage;
        imageName = in.imageName;
        iconName = in.iconName;
        ima_offx = in.ima_offx;
        ima_offy = in.ima_offy;
        m_widthB = in.m_widthB;
        m_heightB = in.m_heightB;
    }

    public Float m_lon;
    public Float m_lat;
    public int px;
    public int py;
    int m_widthB;
    int m_heightB;
    public static int m_defaultWidth = 90;
    public static int m_defaultHeight = 80;
    int m_offY;
    int m_offX;
    public String name;
    public String description;
    public String phoneNum;
    public String address;
    public String iconName;
    public Image iconImage;
    public String imageName;
    public OneLocListener m_theListener;
    public int zoom;
    public String URL;
    public boolean isModeSat;
    public int ima_offx;
    public int ima_offy;
    public int m_category;
    public static final int ICON_LOC_PIN = 0;
    public static final int ICON_SMALL_PIN = 1;
    public static final int ICON_INVISIBLE = 2;
    public static final int ICON_DIAMOND = 3;
    public static final int ICON_CIRCLE = 4;
    public static final int ICON_IMAGE = 5;
    public static final int ICON_PHOTO = 6;
    public int m_type;
    public int m_col;
    public int m_colForeground;
    private static int nbThreads = 0;
    private boolean isStarted;
    Hashtable hash;

}

⌨️ 快捷键说明

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