📄 map.java
字号:
tempCoordinate1.Y=tempCoordinate.Y=StringToDouble(ReadString(in));
tempRing.V_coordinate.addElement(tempCoordinate);
if(!tag){tag=true;
tempPolygon.m_rectangle.x1=tempPolygon.m_rectangle.x2=tempCoordinate.X;
tempPolygon.m_rectangle.y1=tempPolygon.m_rectangle.y2=tempCoordinate.Y;}// first read
for(int j=1;j<tempRing.m_borders;j++)
{
tempCoordinate=new coordinate();
tempCoordinate.X=StringToDouble(ReadString(in));
tempCoordinate.Y=StringToDouble(ReadString(in));
tempRing.V_coordinate.addElement(tempCoordinate);
tempAcreage+=(tempCoordinate1.Y+tempCoordinate.Y)*(tempCoordinate.X-tempCoordinate1.X)/2;
tempCoordinate1.X = tempCoordinate.X;
tempCoordinate1.Y = tempCoordinate.Y;
tempPolygon.m_rectangle.x1 = (tempCoordinate.X<tempPolygon.m_rectangle.x1)?tempCoordinate.X:tempPolygon.m_rectangle.x1;
tempPolygon.m_rectangle.y1 = (tempCoordinate.Y>tempPolygon.m_rectangle.y1)?tempCoordinate.Y:tempPolygon.m_rectangle.y1;
tempPolygon.m_rectangle.x2 = (tempCoordinate.X>tempPolygon.m_rectangle.x2)?tempCoordinate.X:tempPolygon.m_rectangle.x2;
tempPolygon.m_rectangle.y2 = (tempCoordinate.Y<tempPolygon.m_rectangle.y2)?tempCoordinate.Y:tempPolygon.m_rectangle.y2;
}
tempPolygon.V_guRing.addElement(tempRing);
tempPolygon.m_acreage+=Math.abs(tempAcreage);
}
while(!ReadString(in).equals("InnerNode"));
tempPolygon.m_innerNode =new coordinate();
tempPolygon.m_innerNode.X=StringToDouble(ReadString(in));
tempPolygon.m_innerNode.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("EntityType"));
tempPolygon.m_name=ReadString(in);
while(!ReadString(in).equals("AttributeValue"));
tempPolygon.m_attribute = in.readLine();
V_guPolygon.addElement(tempPolygon);
}
else if(temp.equals("GuAnnotation"))
{
guAnnotation tempGuAnnotation=new guAnnotation();
while(!ReadString(in).equals("AnnoType"));
tempGuAnnotation.m_annoType = StringToInt(ReadString(in));
while(!ReadString(in).equals("Position"));
if(tempGuAnnotation.m_annoType==1)
{
while(!ReadString(in).equals("BeginNode"));
tempGuAnnotation.m_beginNode = new coordinate();
tempGuAnnotation.m_beginNode.X=StringToDouble(ReadString(in));
tempGuAnnotation.m_beginNode.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("Angle"));
tempGuAnnotation.m_angle =StringToInt(ReadString(in));
}
else
{
while(!ReadString(in).equals("BeginNode"));
tempGuAnnotation.m_beginNode =new coordinate();
tempGuAnnotation.m_beginNode.X=StringToDouble(ReadString(in));
tempGuAnnotation.m_beginNode.Y=StringToDouble(ReadString(in));
while(!ReadString(in).equals("EndNode"));
tempGuAnnotation.m_endNode =new coordinate();
tempGuAnnotation.m_endNode.X=StringToDouble(ReadString(in));
tempGuAnnotation.m_endNode.Y=StringToDouble(ReadString(in));
}
while(!ReadString(in).equals("Text"));
tempGuAnnotation.m_text =ReadString(in);
while(!ReadString(in).equals("EntityType"));
tempGuAnnotation.m_name =ReadString(in);
while(!ReadString(in).equals("AttributeValue"));
tempGuAnnotation.m_attribute = in.readLine();
V_guAnnotation.addElement(tempGuAnnotation);
}
else if(temp.equals("GuImage"))
{
//add read image here
}
}
S_guNode = new int[V_guNode.size()+1];
S_guNode[0]=-1;
S_guLine = new int[V_guLine.size()+1];
S_guLine[0]=-1;
S_guPolygon = new int[V_guPolygon.size()+1]; //+1是为了设置阀门
S_guPolygon[0]=-1;
//////////test code just for test if read file is OK
//////////
//while(!temp.equals("GuPolygon"))
/// temp=ReadString(in);
/* System.out.println("MapName"+ m_mapName);
System.out.println("MapScope");
System.out.println(" UpLeft: "+ m_upLeft.X+" "+m_upLeft.Y);
System.out.println(" LowRight:"+ m_lowRight.X+" "+m_lowRight.Y);
System.out.println("MapScale"+m_mapScale);
System.out.println("MapDescription"+m_mapDescription);
System.out.println("");
for(int j=0;j<V_entityType.size();j++)
{
entityType entity=(entityType)V_entityType.elementAt(j);
System.out.println(" TypeName: "+entity.m_name );
System.out.println("AnnoFont");
System.out.println(" FaceName: "+entity.m_annoFont.faceName );
System.out.println(" Width: "+entity.m_annoFont.width);
System.out.println(" Height: "+entity.m_annoFont.height);
System.out.println("GeometryDisplay");
System.out.println(" Color: "+entity.m_geometryDisplay.color);
System.out.println("");
}*/
/* for(int j=0;j<V_GuPolygon.size();j++)
{
guPolygon entity=(guPolygon)V_GuPolygon.elementAt(j);
System.out.println(" TypeName: "+entity.name);
//System.out.println("AnnoFont");
//System.out.println(" FaceName: "+entity.Anno_Font.faceName);
//System.out.println(" Width: "+entity.Anno_Font.width);
//System.out.println(" Height: "+entity.Anno_Font.height);
//System.out.println("GeometryDisplay");
///System.out.println(" Color: "+entity.Geometry_Display.color);
System.out.println("");
} */
in.close();
}
catch (BadFileException e)
{
throw e;
}
catch (IOException e){
System.out.println("File access error: "+e);
throw new BadFileException("Not Gum Format File");
}
};
private String ReadString(BufferedReader in) throws BadFileException{
StringBuffer readstr=new StringBuffer();
readstr.setLength(30); //初始化长度为30
try{
char temp=(char)in.read();
while(temp==' ' || temp=='\r' ||temp=='\n')
temp=(char)in.read();
int i=0;
while (temp != ' ' && temp!='\r' && temp!='\n')
{
if(i<30)
readstr.setCharAt(i,temp);
else
readstr.append(temp);
temp = (char)in.read();
if(temp==(char)(-1))
throw new BadFileException("Not Gum Format File");//如果读到文件尾则不是GUM文件
i++;
}
return readstr.toString().trim();
}
catch(Exception e)
{
throw new BadFileException("Not Gum Format File");
}
}
private int StringToInt(String in)
{
int total=0;
int i=0;
int sign =1;
if(in.substring(0,1).equals("-"))
{
i++;
sign=-1;
}
for(;i<in.length();i++)
{
total=total*10+(in.charAt(i)-'0');
}
return total*sign;
}
private long StringToLong(String in)
{
long total=0;
int i=0;
int sign =1;
if(in.substring(0,1).equals("-"))
{
i++;
sign=-1;
}
for(;i<in.length();i++)
{
total=total*10+(in.charAt(i)-'0');
}
return total*sign;
}
private float StringToFloat(String in)
{
float total=0;
int i=0;
int sign =1;
if(in.substring(0,1).equals("-"))
{
i++;
sign=-1;
}
for(;i<in.length();i++)
{
if(in.charAt(i)=='.')
break;
total=(float)total*10+(in.charAt(i)-'0');
}
int tens=1;
for(int j=1;j<in.length()-i;j++)
{
tens*=10;
total+=((float)(in.charAt(i+j)-'0'))/tens;
}
return total*sign;
}
private double StringToDouble(String in)
{
double total=0;
int i=0;
int sign =1;
if(in.substring(0,1).equals("-"))
{
i++;
sign=-1;
}
for(;i<in.length();i++)
{
if(in.charAt(i)=='.')
break;
total=(double)total*10+(in.charAt(i)-'0');
}
int tens=1;
for(int j=1;j<in.length()-i;j++)
{
tens*=10;
total+=((double)(in.charAt(i+j)-'0'))/tens;
}
return total*sign;
}
private boolean StringToBoolean(String in)
{
return in.equals("1")?true:false;
}
}
class BadFileException extends Exception{
public BadFileException(){}
public BadFileException(String msg){super(msg);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -