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

📄 e00parser.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/e00/E00Parser.java,v $// $RCSfile: E00Parser.java,v $// $Revision: 1.5.2.3 $// $Date: 2005/08/11 21:03:30 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.e00;import com.bbn.openmap.layer.location.BasicLocation;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.util.Debug;import java.awt.Color;import java.awt.Font;import java.awt.Paint;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;/** * A parser for an E00 file. Description of the Class parses an E00 * file and provides as result an OMGraphicList containing up to 3 * OMGraphicLists: *  * <pre> *  *   - arcs : OMPoly read in ARC records *   - labs : BasicLocations read in LAB records *   - tx7  : OMPolys and BasicLocation read in TX7 records *   * </pre> *  * PAl,LOG,SIN,PRJ,TOL records are ignored. <br> * From IFO records (if available) :<br>- each arc gets an AppObject * including the type and a value (generally an altitude) <br>- each * lab gets an AppObject including the type, 2 values and the String * to display if available - the type is used to decide the color, * from the Color array. Color and String may be also extracted from * PAT or AAT records. <br> *  * This software is provided as it is. No warranty of any kind, and in * particular I don't know at all if it meets e00 file specification. * It works quite good on files from GIS data depot . *  *  * @author paricaud */public class E00Parser {    protected OMGraphicList labs, arcs, tx7;    protected BufferedReader isr;    protected String prefix;    protected int narc = 1, npoint = 1, unClosedCount = 0;    protected Paint[] ArcColors = defaultColors;    protected Paint[] LabColors = defaultColors;    protected Paint tx7Color;    protected Paint SelectTX7Color, SelectLabColor, SelectArcColor, LabTextColor;    protected Font labFont, tx7Font;    protected OMGraphic LabMarker;    protected Color defaultcolor = Color.blue;    public final static Color[] defaultColors = { Color.black, Color.blue, Color.cyan,            Color.darkGray, Color.gray, Color.green, Color.lightGray,            Color.magenta, Color.orange, Color.pink, Color.red, Color.white,            Color.yellow };    protected static E00Record infoRecord = new E00Record(new int[] { 0, 30, 34, 38, 42,            46, 56 }, new int[] { 20, 20, 50, 50, 50, 50 }, null);    protected static E00Record itemRecord = new E00Record(new int[] { 0, 14, 19, 21, 26,            28, 32, 34, 37, 39, 43, 47, 49, 69 }, new int[] { 20, 50, 50, 50,            50, 50, 50, 50, 50, 50, 50, 50, 50 }, null);    /**     * Constructor for the E00Parser object     *      * @param mdname File Name to parse     * @exception IOException     * @since     */    public E00Parser(String mdname) throws IOException {        isr = new BufferedReader(new FileReader(mdname));        setPrefix(mdname);    }    /**     * Constructor for the E00Parser object     *      * @param f File to parse     * @exception IOException     * @since     */    public E00Parser(File f) throws IOException {        isr = new BufferedReader(new FileReader(f));        setPrefix(f.getName());    }    /**     * Sets the Prefix attribute of the E00Parser object     *      * @param S The new Prefix value     * @since     */    public void setPrefix(String S) {        int n = S.indexOf('.');        if (n == -1)            prefix = S.toUpperCase();        else            prefix = S.substring(0, n).toUpperCase();    }    /**     * Sets the Colors attribute of the E00Parser object     *      * @param ArcColors Paint array for arcs     * @param LabColors Paint array for labs marker     * @param tx7Color Paint for tx7     * @param SelectTX7Color Paint for tx7 when selected     * @param SelectLabColor Paint for labs when selected (not working ?)     * @param SelectArcColor Paint for arcs when selected     * @param LabTextColor Paint for labs text . If null, text has     *        same paint as marker     * @since     */    public void setPaints(Paint[] ArcColors, Paint[] LabColors, Paint tx7Color,                          Paint SelectTX7Color, Paint SelectLabColor,                          Paint SelectArcColor, Paint LabTextColor) {        this.ArcColors = (ArcColors == null) ? defaultColors : ArcColors;        this.LabColors = (LabColors == null) ? defaultColors : LabColors;        this.tx7Color = tx7Color;        this.SelectTX7Color = SelectTX7Color;        this.SelectLabColor = SelectLabColor;        this.SelectArcColor = SelectArcColor;        this.LabTextColor = LabTextColor;    }    /**     * Sets the Fonts attribute of the E00Parser object     *      * @param labFont font for labs text     * @param tx7Font font for tx7 text     * @since     */    public void setFonts(Font labFont, Font tx7Font) {        this.labFont = labFont;        this.tx7Font = tx7Font;    }    /**     * Sets the LabMarker attribute of the E00Parser object     *      * @param marker The new LabMarker value     * @since     */    public void setLabMarker(OMGraphic marker) {        LabMarker = marker;    }    /**     * Gets the result of the parse process     *      * @return The OMGraphics value     * @exception IOException     * @since     */    public OMGraphicList getOMGraphics() throws IOException {        OMGraphicList WV = new OMGraphicList();        isr.readLine();        while (true) {            String S = isr.readLine();            if (S == null)                break;            //System.out.println("E00 "+S);            if (S.startsWith("ARC"))                readARC();            else if (S.startsWith("LAB"))                readLAB();            else if (S.startsWith("IFO"))                readIFO();            else if (S.startsWith("LOG"))                readLOG();            else if (S.startsWith("PRJ"))                readPRJ();            else if (S.startsWith("CNT"))                readCNT();            else if (S.startsWith("PAL"))                readPAL();            else if (S.startsWith("SIN"))                readSIN();            else if (S.startsWith("TOL"))                readTOL();            else if (S.startsWith("TX7"))                readTX7();            else if (S.startsWith("EOS"))                break;            //System.out.println("E00 "+S+" fin");        }        if (labs != null) {            labs.setAppObject("LABS");            WV.add(labs);        }        if (arcs != null) {            arcs.setAppObject("ARCS");            WV.add(arcs);        }        if (tx7 != null) {            tx7.setAppObject("TX7");            WV.add(tx7);        }        return WV;    }    /**     * Gets the LabMarker attribute of the E00Parser object     *      * @return The LabMarker value     * @since     */    public OMGraphic getLabMarker() {        return LabMarker;    }    /**     * read from a string an array of int each float being represented     * by l characters     *      * @param S the String to parse     * @param l the length of int representation     * @param I Description of Parameter     * @since     */    void parseString(String S, int[] I, int l) {        int i = 0;        for (int j = 0; i < I.length && j < S.length(); j += l)            I[i++] = Integer.parseInt(S.substring(j, j + l).trim());    }    /**     * read from a string an array of float each float being     * represented by 14 characters     *      * @param S the String to parse     * @param F the float array receiving the result     * @since     */    void parseString(String S, float[] F) {        int i = 0;        for (int j = 0; i < F.length && j < S.length(); j += 14)            F[i++] = Float.parseFloat(S.substring(j, j + 14).trim());    }    /**     * read SIN records (in fact does nothing)     *      * @exception IOException     * @since     */    void readSIN() throws IOException {        while (true) {            String S = isr.readLine();            if (S == null)                return;            if (S.startsWith("EOX"))                return;        }    }    /**     * read CNT records (in fact does nothing)     *      * @exception IOException     * @since     */    void readCNT() throws IOException {        int[] header = new int[1];        while (true) {            String S = isr.readLine();            if (S == null)                break;            parseString(S, header, 10);            int n = header[0];            if (n == -1)                break;            for (int i = 0; i < n; i++)                isr.readLine();        }    }    /**     * read TOL records (in fact does nothing)     *      * @exception IOException     * @since     */    void readTOL() throws IOException {        int[] header = new int[1];        while (true) {            String S = isr.readLine();            if (S == null)                break;            parseString(S, header, 10);            if (header[0] == -1)                break;        }    }    /**     * read PAL records (in fact does nothing)     *      * @exception IOException     * @since     */    void readPAL() throws IOException {        int[] header = new int[1];        while (true) {            String S = isr.readLine();            if (S == null)                break;            parseString(S, header, 10);            int n = header[0];            if (n == -1)                break;            for (int i = 0; i < n; i += 2)                isr.readLine();        }    }    /**     * read TX7 records     *      * @exception IOException     * @since     */    void readTX7() throws IOException {        Debug.message("e00", "E00: read TX7");        tx7 = new OMGraphicList();        int[] header = new int[8];        float[] coords = new float[2];        isr.readLine();        while (true) {            String S = isr.readLine();            if (S == null)                break;            parseString(S, header, 10);            if (header[0] == -1)                break;            int n = header[2];            for (int i = 0; i < 8; i++)                isr.readLine();            float[] llpoints = new float[2 * n];            int k = 0;            for (int j = 0; j < n; j++) {                S = isr.readLine();                if (S == null)                    return;                parseString(S, coords);                llpoints[k++] = coords[1];                llpoints[k++] = coords[0];            }            S = isr.readLine();            /*             * OMPoly P = new OMPoly(llpoints,             * OMGraphic.DECIMAL_DEGREES,             * OMGraphic.LINETYPE_STRAIGHT); / llpoints is so             * transformed to radians P.setLinePaint(Color.red);             * tx7.add(P); BasicLocation bl = new             * BasicLocation(coords[1], coords[0], S, null);             * bl.setShowLocation(true); bl.setShowName(true);             * tx7.add(bl);             */            TX7 t = new TX7(llpoints, S, false, tx7Font);            // decimal degrees            if (tx7Color != null)                t.setLinePaint(tx7Color);            if (SelectTX7Color != null)                t.setSelectPaint(SelectTX7Color);            tx7.add(t);        }    }    /**     * read LOG records (in fact does nothing)     *      * @exception IOException     * @since     */    void readLOG() throws IOException {        while (true) {            String S = isr.readLine();            if (S == null)                return;            if (S.startsWith("EOL"))                return;        }    }    /**     * read PRJ records (in fact does nothing)     *      * @exception IOException     * @since     */    void readPRJ() throws IOException {        while (true) {            String S = isr.readLine();            if (S == null)                return;            if (S.startsWith("EOP"))                return;        }    }    /**     * read LAB records     *      * @exception IOException     * @since     */    void readLAB() throws IOException {        Debug.message("e00", "E00: read LAB");        labs = new OMGraphicList();        float[] coords = new float[2];        int[] header = new int[1];        while (true) {            String S = isr.readLine();            if (S == null)                break;            parseString(S, header, 10);            int id = header[0];            if (id == -1)                break;            S = isr.readLine();            if (S == null)                break;            parseString(S, coords);            //System.out.println("E00: point n

⌨️ 快捷键说明

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