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

📄 mifloader.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        omgs.add(omp);                        action = PROCESS_MULTIPLE;                    }                }                break SWITCH;            case PROCESS_MULTIPLE:                multicnt++;                if (multicnt > multiple) { // No more multiples so we                    // can pushback                    pushback = true;                    multiple = 0;                    action = PROCESS_POST_PLINE;                    break SWITCH;                }                number = Integer.parseInt(tok);                count = 0;                ptarray = new float[number + number];                action = PROCESS_PLINE;                break SWITCH;            case PROCESS_POST_PLINE:                if (isSame(tok, PEN_WORD)) {                    if (ismultiple) {                        processPenWord(st, omgs);                    } else {                        processPenWord(st, omp);                    }                } else if (isSame(tok, SMOOTH_WORD)) {                    // Smooth unimplemented                } else {                    ismultiple = false;                    pushback = true;                    action = PROCESS_DATA;                }                break SWITCH;            // SCN to support lines            case PROCESS_POST_LINE:                if (isSame(tok, PEN_WORD)) {                    processPenWord(st, oml);                    aList.add(oml);                } else {                    ismultiple = false;                    pushback = true;                    action = PROCESS_DATA;                }                break SWITCH;            case PROCESS_REGION_HEADER: // This processes the number                // at the top of each region                // sub-block                multicnt++;                if (multicnt > multiple) {                    multiple = 0;                    action = PROCESS_POST_REGION;                    // Add this point the region is finished so add                    // the                    // vector contents to list                    int len = omgs.size();                    for (int i = 0; i < len; i++) {                        aList.add((OMGraphic) omgs.elementAt(i));                    }                    break SWITCH;                }                number = Integer.parseInt(tok);                count = 0;                ptarray = new float[number + number];                latpts = new float[number];                lonpts = new float[number];                action = PROCESS_REGION;                break SWITCH;            case PROCESS_REGION:                idx = count + count;                lonpts[count] = ptarray[idx + 1] = Float.parseFloat(tok);                latpts[count] = ptarray[idx] = Float.parseFloat(st.nextToken());                count++;                if (count == number) {                    // This polygon is complete so add it and process                    // the next                    // Use this code if we just want polygons which is                    // much                    // faster                    if (accurate) {                        omgs.add(new OMSubtraction(latpts, lonpts));                    } else {                        // Produces accurate MapInfo type rendering                        // but very                        // slow with complex regions like streets                        int end = latpts.length - 1;                        for (int i = 0; i < end; i++) {                            omgs.add(new OMLine(latpts[i], lonpts[i], latpts[i + 1], lonpts[i + 1], OMGraphic.LINETYPE_STRAIGHT));                        }                        omgs.add(new OMLine(latpts[end], lonpts[end], latpts[0], lonpts[0], OMGraphic.LINETYPE_STRAIGHT));                    }                    action = PROCESS_REGION_HEADER;                }                break SWITCH;            // There is one pen,brush,center block at the end of a            // region            case PROCESS_POST_REGION:                if (isSame(tok, PEN_WORD)) {                    processPenWord(st, omgs);                } else if (isSame(tok, BRUSH_WORD)) {                    processBrushWord(st, omgs);                } else if (isSame(tok, CENTER_WORD)) {                } else {                    pushback = true;                    action = PROCESS_DATA;                }                break SWITCH;            } // end of switch        } // end of while loop        br.close();        return aList;    }    /*     * Processes an instance of the Pen directive for a single     * OMGraphic     */    private void processPenWord(StringTokenizer st, OMGraphic omg) {        if (omg == null)            return;        int width = Integer.parseInt(st.nextToken());        omg.setStroke(new BasicStroke(width));        /* int pattern = */Integer.parseInt(st.nextToken());        Color col = convertColor(Integer.parseInt(st.nextToken()));        omg.setLinePaint(col);    }    /*     * Processes an instance of the Pen directive for a vector of     * OMGraphics     */    private void processPenWord(StringTokenizer st, Vector vals) {        int width = Integer.parseInt(st.nextToken());        /* int pattern = */Integer.parseInt(st.nextToken());        Color col = convertColor(Integer.parseInt(st.nextToken()));        int len = vals.size();        OMGraphic omg = null;        for (int i = 0; i < len; i++) {            omg = (OMGraphic) vals.elementAt(i);            omg.setLinePaint(col);            omg.setStroke(new BasicStroke(width));        }    }    /*     * Processes an instance of the Brush directive     */    private void processBrushWord(StringTokenizer st, Vector vals) {        int pattern = Integer.parseInt(st.nextToken());        Color foreground = convertColor(Integer.parseInt(st.nextToken()));        /*         * background appears to be ignored by MapInfo but I grab it         * anyway         *///        Color background = null;//        if (st.hasMoreTokens()) {//            background = convertColor(Integer.parseInt(st.nextToken()));//        }          int len = vals.size();        OMGraphic omg;        for (int i = 0; i < len; i++) {            omg = (OMGraphic) vals.elementAt(i);            omg.setLinePaint(foreground);            switch (pattern) {            case 1:                break; // No fill so do nothing            case 2:                omg.setFillPaint(foreground);                break;            }        }    }    /**     * process the MIF SYMBOL element.     *      * The MIF format for SYMBOL element is <code>     *  SYMBOL (shape, color, size, fontname, fontstyle, rotation)     * </code>     * or <code>     *  SYMBOL (filename, color, size, customstyle)     * </code>     *      * currently only the color attribute is considered and a default     * OMPoint symbol and size is adopted.     *      * @param st tokenizer containing the "SYMBOL" MIF elements     * @param omg the OMGraphic object to attribute with the setting     *        from the MIF line     */    private void processSymbolWord(StringTokenizer st, OMPoint omg) {        /*String symbolStr = */st.nextToken(); // should be "SYMBOL"        /*int symbol = */Integer.parseInt(st.nextToken());        Color color = convertColor(Integer.parseInt(st.nextToken()));        /*int size = */Integer.parseInt(st.nextToken());        omg.setFillPaint(color);    }    /**     * process the MIF FONT element. currently only PLAIN (0),     * BOLD(1), ITALIC (2) and BOLD ITALIC(3) are supported. Font size     * is hardcoded to 10, and backcolor is ignored.     *      * The MIF format for FONT is <code>     *  FONT ("fontname", style, size, forecolor [, backcolor] )     * </code>     *      * Within a MIF file size will always be 0, it's up to the     * renderer to determine the size. Background color is optional     *      * style is detemined as follows, to specify 2 or more style     * attributes, add the values from each style, e.g. BOLD ALLCAPS =     * 513     *      * value style =================== 0 PLAIN 1 BOLD 2 ITALIC 4     * UNDERLINE 16 OUTLINE 32 SHADOW 256 HALO 512 ALL CAPS 1024     * Expanded     *      *      * @param st tokenizer containing the "FONT" MIF elements     * @param omTxt the OMGraphic object to attribute with the setting     *        from the MIF line     */    private void processFontWord(StringTokenizer st, OMText omTxt) {        /*String fontStr = */st.nextToken(); // should be "FONT"        String fontName = st.nextToken();        int style = Integer.parseInt(st.nextToken());        /*int size = */Integer.parseInt(st.nextToken());        Color foreColor = convertColor(Integer.parseInt(st.nextToken()));        // last token is optional background color//        Color bgColor = null;//        if (st.hasMoreTokens()) {//            bgColor = convertColor(Integer.parseInt(st.nextToken()));//        }        int fontStyle = Font.PLAIN;        switch (style) {        case 0:            fontStyle = Font.PLAIN;            break;        case 1:            fontStyle = Font.BOLD;            break;        case 2:            fontStyle = Font.ITALIC;            break;        case 3:            fontStyle = Font.BOLD & Font.ITALIC;            break;        }        omTxt.setFillPaint(foreColor);        omTxt.setFont(new Font(fontName.substring(1, fontName.length() - 1), fontStyle, 10));    }    /*     * Creates a tokenizer for each line of input     */    private StringTokenizer getTokens(BufferedReader br) throws IOException {        String line;        WHILE: while ((line = br.readLine()) != null) {            if (line.equals(""))                continue WHILE; // skip blank lines            // should return the tokenizer as soon as we have a line            return new StringTokenizer(line, " \t\n\r\f,()");        }        return null;    }    /*     * Utility for doing case independant string comparisons... it's     * neater this way     */    private boolean isSame(String str1, String str2) {        if (str1.equalsIgnoreCase(str2)) {            return true;        } else {            return false;        }    }    /*     * Converts MIF file color to Java Color object     */    private Color convertColor(int val) {        int red = 0;        int green = 0;        int blue = 0;        int rem = val;        if (rem >= 65536) {            red = rem / 65536;            rem = rem - red * 65536;        }        if (rem >= 255) {            green = rem / 256;            rem = rem - green * 256;        }        if (rem > 0)            blue = rem;        return new Color(red, green, blue);    }}/* Last line of file */

⌨️ 快捷键说明

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