📄 waypoint108.java
字号:
package net.aetherial.gis.garmin;
import java.io.*;
import java.util.*;
import net.aetherial.gis.garmin.*;
import net.aetherial.gis.surface.DialogProgress;
class Waypoint108 extends Waypoint
{
private byte wptClass;
private byte color = (byte) 255;
private byte displOptions;
private byte attributes;
private MapSymbol symbol;
private byte[] subclass;
private Position position;
private float altitude;
private float depth;
private float proxDistance = (float) 0.0;
private String state;
private String coCode;
private String identifier;
private String comment;
private String facility;
private String city;
private String address;
private String junction;
/* Waypoint classes. See wptClass above. */
public static final byte USER_WPT = (byte) 0;
public static final byte AVTN_APT_WPT = (byte) 40;
public static final byte AVTN_INT_WPT = (byte) 41;
public static final byte AVTN_NDB_WPT = (byte) 42;
public static final byte AVTN_VOR_WPT = (byte) 43;
public static final byte AVTN_ARWY_WPT = (byte) 44;
public static final byte AVTN_AINT_WPT = (byte) 45;
public static final byte AVTN_ANDB_WPT = (byte) 46;
public static final byte MAP_PNT_WPT = (byte) 80;
public static final byte MAP_AREA_WPT = (byte) 81;
public static final byte MAP_INT_WPT = (byte) 82;
public static final byte MAP_ADRS_WPT = (byte) 83;
public static final byte MAP_LABEL_WPT = (byte) 84;
public static final byte MAP_LINE_WPT = (byte) 85;
/* Display values. See displOptions above. */
public static final byte DISPL_NONE = (byte) 0;
public static final byte DISPL_NAME = (byte) 1;
public static final byte DISPL_CMNT = (byte) 2;
DialogProgress fp =null;
public Waypoint108 (byte[] contents,DialogProgress fp)
{
this.fp = fp;
ByteArrayInputStream bais = new ByteArrayInputStream (contents);
wptClass = (byte) bais.read ();
color = (byte) bais.read ();
displOptions = (byte) bais.read ();
attributes = (byte) bais.read ();
byte[] symbolBytes = new byte[2];
symbolBytes[0] = (byte) bais.read ();
symbolBytes[1] = (byte) bais.read ();
symbol = new MapSymbol (symbolBytes);
subclass = new byte[18];
for (int i = 0; i < 18; i++)
subclass[i] = (byte) bais.read ();
byte[] latByte = new byte[4];
for (int i = 0; i < latByte.length; i++)
latByte[i] = (byte) bais.read ();
byte[] longByte = new byte [4];
for (int i = 0; i < longByte.length; i++)
longByte[i] = (byte) bais.read();
position = new Position (toLongInt(latByte), toLongInt (longByte));
byte[] floByte = new byte[4];
for (int i = 0; i < floByte.length; i++)
floByte[i] = (byte) bais.read ();
altitude = toFloat (floByte);
for (int i = 0; i < floByte.length; i++)
floByte[i] = (byte) bais.read ();
depth = toFloat (floByte);
for (int i = 0; i < floByte.length; i++)
floByte[i] = (byte) bais.read ();
proxDistance = toFloat (floByte);
try
{
byte[] stateBytes = new byte[2];
stateBytes[0] = (byte) bais.read ();
stateBytes[1] = (byte) bais.read ();
state = new String (stateBytes, 0, stateBytes.length, "US-ASCII");
byte[] coBytes = new byte[2];
coBytes[0] = (byte) bais.read ();
coBytes[1] = (byte) bais.read ();
coCode = new String (coBytes, 0, coBytes.length, "US-ASCII");
}
catch (UnsupportedEncodingException e)
{
state = new String ("");
coCode = new String ("");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
for (byte b = (byte) bais.read (); b != 0 && b != (byte) -1; b = (byte) bais.read ())
{
baos.write (b);
}
byte[] ba = baos.toByteArray ();
try
{
identifier = new String (ba, 0, ba.length, "US-ASCII");
}
catch (UnsupportedEncodingException e)
{
System.out.println (e);
identifier = new String ("");
}
try
{
bais.close ();
}
catch (IOException e)
{
System.out.println (e);
}
GarminGMLDoc.getDocument ();
GarminGMLDoc.addXmlWaypoint(this,altitude);
// GarminGMLDoc.addWaypoint (this);
}
public String printSubclass ()
{
String subclassStr = new String ("");
for (int i = 0; i < 18; i++)
subclassStr = new String (subclassStr+subclass[i]+" ");
return subclassStr;
}
public void printDetails ()
{
// System.out.println ("This is a debugging tool for dumping waypoint details.");
// System.out.println ("Waypoint Class: "+wptClass);
// System.out.println ("Waypoint Color: "+color);
// System.out.println ("Waypoint Display Options: "+displOptions);
// System.out.println ("Waypoint Attributes: "+attributes);
// System.out.println ("Waypoint Symbol: "+symbol.getMapSymbol ());
// System.out.println ("Waypoint Subclass: "+printSubclass ());
// System.out.println ("Waypoint Position: "+position.getDegreeLatitude ()+"."+position.getMinuteLatitude ()+"."+position.getSecondLatitude ()+position.getLatOrientChar ()+", "+position.getDegreeLongitude()+"."+position.getMinuteLongitude ()+"."+position.getSecondLongitude ()+position.getLongOrientChar ());
// System.out.println ("Waypoint Altitude: "+altitude);
// System.out.println ("Waypoint Depth: "+depth);
// System.out.println ("Waypoint Proximity Distance: "+proxDistance);
// System.out.println ("Waypoint State: "+state);
// System.out.println ("Waypoint Country: "+coCode);
// System.out.println ("Waypoint Identifier: "+identifier);
// System.out.println ("Other options will be implemented soon.");
// System.out.println ("");
fp.jTextField1.setText("正在读取航点:"+identifier);
}
public String getIdentifier ()
{
return identifier;
}
public MapSymbol getSymbol ()
{
return symbol;
}
public String getComment ()
{
return comment;
}
public Position getPosition ()
{
return position;
}
public float getProximity ()
{
return proxDistance;
}
private long toLong (byte[] bytes)
{
long l = (long) ((((long) bytes[7]) * Math.pow (2,56)) + (((long) bytes[6]) * Math.pow (2,48)) + (((long) bytes[5]) * Math.pow(2, 40)) + (((long) bytes[4]) * Math.pow (2,32)) + (((long) bytes[3]) * Math.pow (2,24)) + (((long) bytes[2]) * Math.pow(2,16)) + (((long) bytes[1]) * Math.pow(2,8))) + (long) bytes[0];
return l;
}
private double toDouble (byte[] bytes)
{
return Double.longBitsToDouble (toLong (bytes));
}
private long toLongInt (byte[] bytes)
{
long[] ints = new long[4];
for (int i = 0; i < ints.length; i++)
{
if (bytes[i] < 0)
ints[i] = (long) (256 + (int) bytes[i]);
else
ints[i] = (long) bytes[i];
}
for (int i = 0; i < ints.length; i++)
{
ints[i] = (ints[i]) * (long) Math.pow (2, (8 * i));
}
return ints[3] + ints[2] + ints[1] + ints[0];
}
private float toFloat (byte[] bytes)
{
int i = (int) toLongInt (bytes);
float f = Float.intBitsToFloat (i);
if (f > Math.pow (10, 20))
return 0;
else
return f;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -