📄 tomap.java
字号:
package net.aetherial.gis.our;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.w3c.dom.*;
import net.aetherial.gis.surface.*;
import net.aetherial.gis.cutAndLink.DynamicPanel;
import net.aetherial.gis.dataType.WptType;
/*
*ToMap tm = new ToMap();
*tm.rollMemory(trackNode);
*tm.determinScale(width.height);
*
*
*/
public class ToMap {
//Graphics g = null;
//private int count =0;
private int width=0,height=0;
private double x1 = 0.0 ,x2 = 0.0 ,y1 = 0.0 ,y2 = 0.0 ;//x1=north,x2=south,y1=east,y2=west;
private double scale =0.0;//缩放比例
private int widthMove=0,heightMove =0;
private int widthStart = 0,heightStart =0;
private int widthMid = 0,heightMid =0;
private int h = 0,w = 0;
//////////////////////////////////////
private boolean drawTrackLine = false;
private boolean drawWaypoint = false;
/////////////////////////////////////
public ToMap() {
this.resetAll();
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void setHW(){
h = heightMid+heightStart+heightMove;
w = widthMid+widthStart+widthMove;
/*
System.out.println("**********setHW()**************setHW");
System.out.println("widthMid="+widthMid+"\nwidthStart="+widthStart+"\nwidthMove="+widthMove);
System.out.println("heightMid="+heightMid+",heightStart="+heightStart+",heightMove="+heightMove);
System.out.println("h="+h+",w="+w);
System.out.println("******************************");
*/
}
public boolean getTrackLine(){
return this.drawTrackLine;
}
public boolean getWaypoint(){
return this.drawWaypoint;
}
private void getXYCorrect(String xtemp,String ytemp){
double xt = Double.parseDouble(xtemp);
double yt = Double.parseDouble(ytemp);
if(xt<0){
xt = 0 - xt;
}
if(yt<0){
yt = 0 - yt;
}
if(xt>x1){
x1 = xt;
}
if(x2 ==0.0){
x2 = xt;
}
if(xt<x2){
x2 = xt;
}
if(yt>y1){
y1 = yt;
}
if(y2 == 0.0){
y2 = yt;
}
if(yt<y2){
y2 = yt;
}
}
public void resetAll(){
this.drawTrackLine =false;
this.drawWaypoint = false;
//this.widthMid = 0;
this.widthMove =0;
this.widthStart =0;
//this.heightMid =0;
this.heightMove =0;
this.heightStart =0;
width = 0;
height = 0;
x1 = 0.0;
x2 = 0.0;
y1 = 0.0;
y2 = 0.0; //x1=north,x2=south,y1=east,y2=west;
scale = 0.0; //缩放比例
//widthMove = 0;
//heightMove = 0;
this.setHW();
}
public void resetXY(){
x1 = 0.0;
x2 = 0.0;
y1 = 0.0;
y2 = 0.0; //x1=north,x2=south,y1=east,y2=west;
}
private void resetMove(){
this.heightMove = 0;
this.widthMove = 0;
}
public void rollMemory(){//得到最上最左,最下最右的点,以用来决定缩放比例
Node[] alltrk = ItemValue.getTracks();
NodeList nl;
String xTemp ="0.0",yTemp="0.0";
if(alltrk != null){
for (int i = 0; i < alltrk.length; i++) {
nl = ItemValue.getTracksPoint(alltrk[i]);
for(int j=0;j<nl.getLength();j++){
xTemp = ItemValue.getTracksPointX(nl.item(j));
yTemp = ItemValue.getTracksPointY(nl.item(j));
getXYCorrect(xTemp,yTemp);
}
}
}
}
public void rollMemory(Node trackNode) {
//给定一个trackNode,得到最上最左,最下最右的点,以用来决定缩放比例
//这个方法是只显示一个航迹的时候使用
//如果有两条或者多条航迹,分别调用两次或者多次就可以了
//*注意:如果画多条航迹的话,请重新调用determinScale(int width,int height)方法
NodeList nl;
String xTemp = "0.0", yTemp = "0.0";
if (trackNode != null) {
nl = ItemValue.getTracksPoint(trackNode);
for (int j = 0; j < nl.getLength(); j++) {
xTemp = ItemValue.getTracksPointX(nl.item(j));
yTemp = ItemValue.getTracksPointY(nl.item(j));
getXYCorrect(xTemp, yTemp);
}
}
// x1 = 0.0 ,x2 = 0.0 ,y1 = 0.0 ,y2 = 0.0
//System.out.println("After rollMemory,x1="+x1+",x2="+x2+",y1="+y1+",y2="+y2);
}
public void setMove(int x,int y){
this.widthMove = y;
this.heightMove = x;
this.setHW();
}
public void setMoved(int x,int y){
this.widthStart = y + widthStart;
this.heightStart = x + heightStart;
this.resetMove();
}
public void setScale(double scale){
this.scale = scale;
}
public double getScale(){
return this.scale;
}
public void determinScale(int width,int height){//width is jpanel's width and as like heigth
this.height = height;
this.width = width;
//System.out.println("******Panel height="+height+",width="+width);
double xScale = (x1-x2)/height;
double yScale = (y1-y2)/width;
//System.out.println("xScale="+xScale+",yScale="+yScale + ",in ToMap at method determinScale(int width,int height)");
//double temp;
if(((xScale == 0.0))&&((yScale == 0.0))){
this.scale = 10000.0;
}else{
if (xScale > yScale) {
scale = 1 / xScale;
//temp = (y1-y2)*scale;//得到宽度
//this.heightMid = (int)temp/2;
//System.out.println("******Panel widthMid="+widthMid);
//this.widthMove =Integer.parseInt((new Double(temp/2)).longValue()+"");//宽度一半的整数部分就是要移动的横轴
}
else {
scale = 1 / yScale;
//this.heightMid =
//temp = (x1-x2)*scale;//得到高度
//this.widthMid = (int)temp/2;
//System.out.println("******Panel heightMid="+heightMid);
//this.heightMove =Integer.parseInt((new Double(temp/2)).longValue()+"");//宽度一半的整数部分就是要移动的纵轴
}
}
widthMid = this.width/2-(int)((Math.abs(y1-y2)/2)*scale);
heightMid = this.height/2-(int)((Math.abs(x2-x1)/2)*scale);
this.setHW();
//System.out.println("Scale:" + this.scale + ",in ToMap at method determinScale(int width,int height)");
//System.out.println("scale:"+scale);
//System.out.println("After determinScale,height="+(x1-x2)*scale+",width="+(y2-y1)*scale);
}
private double getY(String Y){
return (y1-Math.abs(Double.parseDouble(Y)));
}
private double getX(String X){
return (Double.parseDouble(X)-x2);
}
private void drawTracksPoint(String xtemp,String ytemp,Graphics g){
double xt = (Double.parseDouble(xtemp)-x2);
double yt = (y1-Math.abs(Double.parseDouble(ytemp)));
xt = xt*scale;
yt = yt*scale;
int x = Integer.parseInt((new Double(xt)).longValue()+"");
int y = Integer.parseInt((new Double(yt)).longValue()+"");
g.fillOval(x+h-2,y+w-2,4,4);
//g.fillOval(y+widthMove,x+heightMove,size,size);
}
private void drawTracksBEPoint(String xtemp,String ytemp,Graphics g,boolean begin){
g.setColor(Color.BLUE);
double xt = (Double.parseDouble(xtemp)-x2);
double yt = (y1-Math.abs(Double.parseDouble(ytemp)));
xt = xt*scale;
yt = yt*scale;
int x = Integer.parseInt((new Double(xt)).longValue()+"");
int y = Integer.parseInt((new Double(yt)).longValue()+"");
g.fillOval(x+h-3,y+w-3,6,6);
g.drawString(begin?"起点":"终点", x + h + 4, y + w + 4);
//g.fillOval(y+widthMove,x+heightMove,size,size);
}
private void drawTracksPointLine(String xtemp1,String ytemp1,String xtemp2,String ytemp2,Graphics g){
//g.setColor(Color.BLUE);
double xt1 = (Double.parseDouble(xtemp1)-x2);
double yt1 = (y1-Math.abs(Double.parseDouble(ytemp1)));
double xt2 = (Double.parseDouble(xtemp2)-x2);
double yt2 = (y1-Math.abs(Double.parseDouble(ytemp2)));
xt1 = xt1*scale;
yt1 = yt1*scale;
xt2 = xt2*scale;
yt2 = yt2*scale;
int x1 = Integer.parseInt((new Double(xt1)).longValue()+"");
int y1 = Integer.parseInt((new Double(yt1)).longValue()+"");
int x2 = Integer.parseInt((new Double(xt2)).longValue()+"");
int y2 = Integer.parseInt((new Double(yt2)).longValue()+"");
//g.drawOval(x1+heightMove,y1+widthMove,1,1);
g.drawLine(x1+h,y1+w,x2+h,y2+w);
//System.out.println("g.drawLine("+x1+heightMove+","+y1+widthMove+","+x2+heightMove+","+y2+widthMove+");");
}
public void drawTracks(Graphics g){
g.setColor(Color.BLUE);
Node[] alltrk = ItemValue.getTracks();
NodeList nl;
String xTemp ="0.0",yTemp="0.0";
if(alltrk != null){
for (int i = 0; i < alltrk.length; i++) {
nl = ItemValue.getTracksPoint(alltrk[i]);
for(int j=0;j<nl.getLength();j++){
xTemp = ItemValue.getTracksPointX(nl.item(j));
yTemp = ItemValue.getTracksPointY(nl.item(j));
this.drawTracksPoint(xTemp,yTemp,g);
}
}
}
this.drawTrackLine =true;
}
public void drawTracks(Graphics g, int trackPos) {
g.setColor(Color.RED);
ItemValue iv = new ItemValue();
int[] pos = iv.getPosition("track");
Node node = null;
NodeList nl;
String xTemp = "0.0", yTemp = "0.0";
if (pos.length > 0) {
node = iv.getTracks(pos[trackPos]);
nl = iv.getTracksPoint(node);
for (int j = 0; j < nl.getLength(); j++) {
xTemp = iv.getTracksPointX(nl.item(j));
yTemp = iv.getTracksPointY(nl.item(j));
this.drawTracksPoint(xTemp, yTemp, g);
}
}
}
public void drawAllTracks(Graphics g,Node[] alltrk){
if (alltrk != null) {
for(int i =0;i<alltrk.length;i++){
if (ItemValue.isTemp) {
this.drawTrackLine(g,alltrk[i],Color.GREEN);
}else{
this.drawTrackLine(g,alltrk[i],Color.BLUE);
}
}
}
}
public void drawTrackLine(Graphics g, Node trackNode) {
//这里单独绘制一条航迹,如果要画多条,继续调用此方法就行
NodeList nl;
boolean drawBegin = false;
String xTemp = "0.0", yTemp = "0.0",lastX = "0.0", lastY = "0.0";
if (trackNode != null) {
nl = ItemValue.getTracksPoint(trackNode);
for (int j = 0; j < nl.getLength(); j++) {
xTemp = ItemValue.getTracksPointX(nl.item(j));
yTemp = ItemValue.getTracksPointY(nl.item(j));
if(j == ((int)nl.getLength()/2)){
this.drawTrackName(xTemp,yTemp,ItemValue.getTracksName(trackNode)+ "[" + ItemValue.getTracks_ld_original_number(trackNode)+"]",g);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -