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

📄 frametoxml.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.dataType;

import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import net.sourceforge.mlf.metouia.*;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.surface.CreateFile;
import java.io.*;
import net.aetherial.gis.dataType.filter.Filter;
import net.aetherial.gis.surface.DialogProgress;

public class FrameToXml extends JFrame {
  XYLayout xYLayout1 = new XYLayout();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel1 = new JLabel();
  JButton jButton1 = new JButton();
  JTextField jTextField2 = new JTextField();
  JButton jButton2 = new JButton();
  JTextField jTextField3 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JButton jButton3 = new JButton();
  File trk = null,wpt = null;
  public FrameToXml() {
    try {
      jbInit();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  void jbInit() throws Exception {
    this.getContentPane().setLayout(xYLayout1);
    jLabel1.setText("选取航点(wpt)文件:");
    jButton1.setText("选取");
    jButton1.addActionListener(new FrameToXml_jButton1_actionAdapter(this));
    jButton2.setToolTipText("");
    jButton2.setVerifyInputWhenFocusTarget(true);
    jButton2.setText("选取");
    jButton2.addActionListener(new FrameToXml_jButton2_actionAdapter(this));
    jLabel2.setText("选取航迹(trk)文件");
    jLabel3.setText("生成的XML文件");
    jButton3.setText("生成");
    jButton3.addActionListener(new FrameToXml_jButton3_actionAdapter(this));
    jTextField1.setText("");
    jTextField2.setText("");
    jButton4.setText("清空");
    jButton4.addActionListener(new FrameToXml_jButton4_actionAdapter(this));
    this.getContentPane().add(jTextField1, new XYConstraints(42, 32, 195, -1));
    this.getContentPane().add(jLabel1,     new XYConstraints(41, 12, 144, 17));
    this.getContentPane().add(jButton1,  new XYConstraints(250, 31, -1, -1));
    this.getContentPane().add(jTextField2, new XYConstraints(41, 99, 195, -1));
    this.getContentPane().add(jButton2, new XYConstraints(248, 98, -1, -1));
    this.getContentPane().add(jLabel2,   new XYConstraints(41, 80, 106, -1));
    this.getContentPane().add(jLabel3,   new XYConstraints(37, 149, 145, -1));
    this.getContentPane().add(jTextField3, new XYConstraints(37, 170, 292, -1));
    this.getContentPane().add(jButton3,    new XYConstraints(133, 216, -1, -1));
    this.getContentPane().add(jButton4,    new XYConstraints(207, 216, -1, -1));
    //ItemValue.fileChoosePath = "D:\\GIS\\GPS测量数据\\";
  }

  public static void main(String[] args) {
   // try {

   //   UIManager.setLookAndFeel(new Office2003LookAndFeel());
   // }
  //  catch (Exception ex) {
   // }
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    FrameToXml frameToXml = new FrameToXml();
    frameToXml.setSize(600,500);
    frameToXml.setLocation(
        (screenDim.width - 600) / 2,
        (screenDim.height - 500) / 2
        );

    frameToXml.show();
  }

  void jButton1_actionPerformed(ActionEvent e) {

    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setFileFilter(new Filter("wpt"));
    if(!(ItemValue.fileChoosePath.equals(""))){
      fileDialog.setCurrentDirectory(new File(ItemValue.fileChoosePath));
    }
    int result = fileDialog.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
      wpt = fileDialog.getSelectedFile();
      String wptPath = wpt.getAbsolutePath();
      ItemValue.fileChoosePath = wptPath;
      this.jTextField1.setText(wptPath);
      this.jTextField3.setText(wptPath.substring(0,wptPath.length()-4)+".gps");
    }
  }

  void jButton2_actionPerformed(ActionEvent e) {
    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setFileFilter(new Filter("trk"));
    if(!(ItemValue.fileChoosePath.equals(""))){
      fileDialog.setCurrentDirectory(new File(ItemValue.fileChoosePath));
    }
    int result = fileDialog.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
      trk = fileDialog.getSelectedFile();
      this.jTextField2.setText(trk.getAbsolutePath());
    }
  }

  void jButton3_actionPerformed(ActionEvent e) {
    showDialog sd = new showDialog(this);
    sd.start();
  }
  JButton jButton4 = new JButton();

  void jButton4_actionPerformed(ActionEvent e) {
    this.jTextField1.setText("");
   this.jTextField2.setText("");
   this.jTextField3.setText("");
   this.wpt = null;
   this.trk = null;
  }
}

class FrameToXml_jButton1_actionAdapter implements java.awt.event.ActionListener {
  FrameToXml adaptee;

  FrameToXml_jButton1_actionAdapter(FrameToXml adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class FrameToXml_jButton2_actionAdapter implements java.awt.event.ActionListener {
  FrameToXml adaptee;

  FrameToXml_jButton2_actionAdapter(FrameToXml adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class FrameToXml_jButton3_actionAdapter implements java.awt.event.ActionListener {
  FrameToXml adaptee;

  FrameToXml_jButton3_actionAdapter(FrameToXml adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

class FrameToXml_jButton4_actionAdapter implements java.awt.event.ActionListener {
  FrameToXml adaptee;

  FrameToXml_jButton4_actionAdapter(FrameToXml adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton4_actionPerformed(e);
  }
}
class showDialog extends Thread {
  FrameToXml ftx = null;
  showDialog(FrameToXml ftx){
    this.ftx =ftx;
  }
  public void run(){
    DialogProgress dp = new DialogProgress();
    dp.show();
    String xml = "";
    xml = xml+"<?xml version=\"1.0\" encoding=\"UTF-8\"?><GarminDataCollection>\n";
    WptToXml wtx = new WptToXml(ftx.wpt,dp);
    //System.out.println(wpt.getAbsolutePath());
    wtx.refactory();
    xml = xml +wtx.xml;
    //System.out.println(wtx.getXml());
    TrkToXML ttx = new TrkToXML(ftx.trk,dp);
    //System.out.println(trk.getAbsolutePath());
    ttx.refactory(true);
    xml = xml + ttx.xml;
    //System.out.println(ttx.xml);

    xml = xml +"</GarminDataCollection>";

    CreateFile cf = new CreateFile(new File(ftx.jTextField3.getText()));
    dp.jLabel1.setText("正在将内存数据转化为文件...");
    cf.memoryToFile(xml);
    dp.hide();
    JOptionPane.showMessageDialog(ftx,"File create OK!",".trk file or .wpt file to xml file",JOptionPane.INFORMATION_MESSAGE);

  }
}







⌨️ 快捷键说明

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