📄 map.java
字号:
import java.io.*;
import java.util.*;
class coordinate //坐标类
{
double X;
double Y;
}
class rectangle //外接矩阵
{
double x1 = 0;
double y1 = 0;
double x2 = 0;
double y2 = 0;
}
class annoFont //字体类
{
String faceName;
int width;
int height;
int color ;
}
class geometryDisplay
{
int color;
}
class entityType{
String m_name;
annoFont m_annoFont;
geometryDisplay m_geometryDisplay;
entityType()
{
m_annoFont= new annoFont();
m_geometryDisplay= new geometryDisplay();
}
}
class fieldDefine{
String m_fieldName;
long m_length;
boolean isNull;
boolean isUnique;
}
class guNode{
coordinate m_coordinate;
String m_name;
String m_attribute;
}
class guLine{
int n;
Vector V_coordinate;
String m_name;
String m_attribute;
rectangle m_rectangle;
double m_length=0;
}
class guRing{
int m_borders;
Vector V_coordinate;
}
class guPolygon{
int m_rings;
Vector V_guRing;
coordinate m_innerNode;
String m_name;
String m_attribute;
rectangle m_rectangle;
double m_acreage;
}
class guAnnotation{
int m_annoType; //1,2,3
coordinate m_beginNode;
coordinate m_endNode; //no useful if annoType ==1.
int m_angle; //no useful unless annoType == 1.
String m_text;
String m_name;
String m_attribute;
}
class guImage{
coordinate m_position;
String m_file;
String m_name;
String m_attribute;
rectangle m_rectangle;
}
public class map{
public String m_mapName;
public coordinate m_upLeft = new coordinate();
public coordinate m_lowRight = new coordinate();
public double m_mapScale; //no useful
public String m_mapDescription;
public Vector V_entityType = new Vector(50,50);
public Vector V_fieldDefine = new Vector(50,50);
public Vector V_guNode = new Vector(300,100);
public int[] S_guNode;
public Vector V_guLine = new Vector(300,100);
public int[] S_guLine;
public Vector V_guPolygon = new Vector(200,100);
public int[] S_guPolygon;
public Vector V_guAnnotation = new Vector(200,100);
public Vector V_guImage = new Vector(50,50);
public map(String FileName) throws BadFileException{
try{
BufferedReader in= new BufferedReader(new FileReader(FileName));
while(!ReadString(in).equals("HeaderSection"));
while(!ReadString(in).equals("MapName"));
m_mapName=in.readLine();
while(!ReadString(in).equals("MapScope"));
while(!ReadString(in).equals("UpLeft"));
m_upLeft.X=StringToDouble(ReadString(in));
m_upLeft.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("LowRight"));
m_lowRight.X=StringToDouble(ReadString(in));
m_lowRight.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("MapScale"));
m_mapScale=StringToDouble(ReadString(in));
while(!ReadString(in).equals("MapDescription"));
m_mapDescription= in.readLine();
while(!ReadString(in).equals("EntityType"));
int NumOfTypes=StringToInt(ReadString(in));
for(int i=0;i<NumOfTypes;i++) //read the Entity Types
{
entityType entity=new entityType();
while(!ReadString(in).equals("TypeName"));
entity.m_name = ReadString(in);
while(!ReadString(in).equals("AnnoFont"));
while(!ReadString(in).equals("FaceName"));
entity.m_annoFont.faceName = ReadString(in);
while(!ReadString(in).equals("Width"));
entity.m_annoFont.width = StringToInt(ReadString(in));
while(!ReadString(in).equals("Height"));
entity.m_annoFont.height = StringToInt(ReadString(in));
while(!ReadString(in).equals("Color"));
entity.m_annoFont.color = StringToInt(ReadString(in));
while(!ReadString(in).equals("GeometryDisplay"));
while(!ReadString(in).equals("Color"));
entity.m_geometryDisplay.color = StringToInt(ReadString(in));
V_entityType.addElement(entity); //add
}
while(!ReadString(in).equals("FieldDefines"));
int NumOfField = StringToInt(ReadString(in));
for(int i=0;i<NumOfField;i++)
{
fieldDefine FieldDefine = new fieldDefine();
FieldDefine.m_fieldName = ReadString(in);
FieldDefine.m_length = StringToInt(ReadString(in));
FieldDefine.isNull = StringToBoolean(ReadString(in));
FieldDefine.isUnique = StringToBoolean(ReadString(in));
V_fieldDefine.addElement(FieldDefine);
}
while(!ReadString(in).equals("EndSection"))
//read Data
while(!ReadString(in).equals("EntitiesSection"));
for(String temp=ReadString(in);!temp.equals("EndSection");temp=ReadString(in))
{
if(temp.equals("GuNode")) //read node
{
guNode tempNode = new guNode();
tempNode.m_coordinate = new coordinate();
tempNode.m_coordinate.X=StringToDouble(ReadString(in));
tempNode.m_coordinate.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("EntityType"));
tempNode.m_name = ReadString(in);
while(!ReadString(in).equals("AttributeValue"));
tempNode.m_attribute= in.readLine();
V_guNode.addElement(tempNode);
}
else if(temp.equals("GuLine"))
{
guLine tempLine = new guLine();
tempLine.n=StringToInt(ReadString(in));
tempLine.V_coordinate=new Vector(tempLine.n,5);
tempLine.m_rectangle=new rectangle();
coordinate tempCoordinate=new coordinate();
tempCoordinate.X=StringToDouble(ReadString(in));
tempCoordinate.Y=StringToDouble(ReadString(in));
tempLine.V_coordinate.addElement(tempCoordinate);
tempLine.m_rectangle.x1=tempLine.m_rectangle.x2=tempCoordinate.X;
tempLine.m_rectangle.y1=tempLine.m_rectangle.y2=tempCoordinate.Y;
tempCoordinate=new coordinate();
tempCoordinate.X=tempLine.m_rectangle.x1;
tempCoordinate.Y=tempLine.m_rectangle.y1;
for(int i=1;i<tempLine.n;i++)
{
coordinate tempCoordinate1= new coordinate();
tempCoordinate1.X=StringToDouble(ReadString(in));
tempCoordinate1.Y=StringToDouble(ReadString(in));
tempLine.V_coordinate.addElement(tempCoordinate1);
tempLine.m_length+=Math.sqrt((tempCoordinate1.X-tempCoordinate.X)*(tempCoordinate1.X-tempCoordinate.X)+(tempCoordinate1.Y-tempCoordinate.Y)*(tempCoordinate1.Y-tempCoordinate.Y));
tempCoordinate.X=tempCoordinate1.X;
tempCoordinate.Y=tempCoordinate1.Y;
tempLine.m_rectangle.x1 = (tempCoordinate.X<tempLine.m_rectangle.x1)?tempCoordinate.X:tempLine.m_rectangle.x1;
tempLine.m_rectangle.y1 = (tempCoordinate.Y>tempLine.m_rectangle.y1)?tempCoordinate.Y:tempLine.m_rectangle.y1;
tempLine.m_rectangle.x2 = (tempCoordinate.X>tempLine.m_rectangle.x2)?tempCoordinate.X:tempLine.m_rectangle.x2;
tempLine.m_rectangle.y2 = (tempCoordinate.Y<tempLine.m_rectangle.y2)?tempCoordinate.Y:tempLine.m_rectangle.y2;
}
while(!ReadString(in).equals("EntityType"));
tempLine.m_name=ReadString(in);
while(!ReadString(in).equals("AttributeValue"));
tempLine.m_attribute = in.readLine();
V_guLine.addElement(tempLine);
}
else if(temp.equals("GuPolygon"))
{
guPolygon tempPolygon= new guPolygon();
tempPolygon.m_acreage=0;
tempPolygon.m_rings = StringToInt(ReadString(in));
tempPolygon.V_guRing = new Vector(tempPolygon.m_rings ,5);
tempPolygon.m_rectangle = new rectangle();
boolean tag=false;
for(int i=0;i<tempPolygon.m_rings;i++)
{
while(!ReadString(in).equals("GuRing"));
guRing tempRing=new guRing();
tempRing.m_borders=StringToInt(ReadString(in));
tempRing.V_coordinate = new Vector(tempRing.m_borders ,5);
double tempAcreage=0;
coordinate tempCoordinate1=new coordinate();
coordinate tempCoordinate=new coordinate();
tempCoordinate1.X=tempCoordinate.X=StringToDouble(ReadString(in));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -