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

📄 dynamicpanel.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.cutAndLink;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import net.aetherial.gis.our.ToMap;
import org.w3c.dom.*;
import javax.swing.JPopupMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import net.aetherial.gis.surface.ItemValue;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.Point;
import java.awt.Image;
import java.util.Vector;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class DynamicPanel extends JPanel{
  public CLFrame clf = null;
  private int countPaint =0;
  private Graphics g = null;
  private ToMap tm = new ToMap();
  private boolean init = false;
  private JPopupMenu popup = new JPopupMenu();
  private JMenuItem jMenuItemZoomIn = new JMenuItem();
  private JMenuItem jMenuItemZoomOut = new JMenuItem();
  private int baseX =0,baseY=0;
  private boolean showCut = true;
  private boolean showLink = false;
  private boolean showAllTrack = false;
  private boolean showAllWaypoint = false;
  private boolean showHisWpt = false;
  private Cursor cursorDefault = Cursor.getDefaultCursor();
  private TempDoc tc =null;
  private Node point = null;
  private Node[] alltrk = null;
  private Node[] allwpt = null;
  private Node selectTrk = null;
  private long whenMouseMovedLastTime = 0;

  public DynamicPanel() {

    regetAllWaypoints();
    this.init();
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  public DynamicPanel(CLFrame clf,TempDoc tc) {
    this();
    this.tc = tc;
    this.clf = clf;
  }
  public void setSelectTrk(Node track){
    this.selectTrk = track;
    regetAllTracks();
//    System.out.println("Dynmicpanel Line 71:" + ItemValue.getTracksName(this.selectTrk));
  }
  public void regetAllTracks(){
    Node[] alls = ItemValue.getTracks();
    boolean isFind = false;
    if (alls != null) {
      this.alltrk = new Node[alls.length-1];
      for (int i = 0; i < alltrk.length; i++) {
          if (alls[i] == this.selectTrk) {
            isFind = true;
          }
          if (isFind) {
            alltrk[i] = alls[i+1];
          }else{
            alltrk[i] = alls[i];
          }

      }
    }
    //this.printAllTrks();
  }
  /**
   * 打印获得的alltrks
   */
  private void printAllTrks(){
    String n = "";
    String ln = "\r\n";
    if (this.alltrk == null) {
      n = "alltrk == null" + ln;
    }else{
      for (int i = 0; i < alltrk.length; i++) {
        n = n +"" + (i+1) + "." + ItemValue.getTracksName(alltrk[i]) + ln;
      }
    }
    System.out.println(n);
  }
  public void regetAllWaypoints(){
    this.allwpt = ItemValue.getWaypoint();
  }

  public void init(){
    this.setBackground(Color.white);
    if(g==null){
      //System.out.println("g==null");
      init =false;
      return;
    }
    if(tc.track!=null){
      this.tm.resetAll();
      this.tm.rollMemory(tc.track);
      this.tm.determinScale(this.getWidth(), this.getHeight());
      this.tm.drawTrackLine(g, tc.track);
      this.init = true;
    }
    if(this.showCut == true){
      this.drawWaypoint();
    }
    tm.drawInfo(g);
  }

  public void reset(){
    this.init = false;
    this.repaint();
    tc.resetTempDoc();
    if(this.showCut == true){
      this.drawWaypoint();
    }
    if(this.showLink == true){
      this.drawAnotherTrack();
    }
    this.setShowAllFalse();
  }
  private void reDraw(){
    //System.out.println("reDraw()");
    if(tm.getTrackLine()){
      this.drawTrack(tc.track);
    }
    if((tm.getWaypoint())&&(this.showCut)){
      drawWaypoint();
    }
    if(this.showLink){
      this.drawAnotherTrack();
      this.drawBE();
    }
    if(tc.tadded!=null){
      this.drawTaddedTrack();
    }
    tm.drawInfo(g);
    //////////////////////
    if(showAllTrack){
      this.drawAllTrack();
    }
    if(showAllWaypoint){
      this.drawAllWaypoint();
    }
    if(this.point != null){
      this.drawTrackPoint();
    }
    if (this.showHisWpt) {
      this.drawHisWpt();
    }

    //////////////////////
  }
  public void drawAllTrack(){
    tm.drawAllTracks(g,this.alltrk);
  }
  public void drawTrack(Node node){
    if(node != null){
      this.tm.drawTrackLine(g, node);
    }else{
      System.out.println("Track==null");
    }
  }

  public void drawAnotherTrack(){
    if(tc.tadd != null){
      this.tm.drawTrackLine(g, tc.tadd);
    }else{
      System.out.println("Track==null");
    }
  }

  private void drawTrackBE(Node trackNode,boolean begin){
    if(tc.tadd != null){
      this.tm.drawTrackBEPoint(g,trackNode,begin);
    }else{
      System.out.println("Track==null");
    }
  }

  public void drawBE(){
    if((tc.track != null)&&(tc.tadd != null)){
      drawTrackBE(tc.track, tc.trackBegin);
      drawTrackBE(tc.tadd, tc.taddBegin);
    }else{
      System.out.println("Track==null or tadd == null.");
    }
  }

  public void drawTaddedTrack(){
    tm.drawTaddedTrackLine(this.g, tc.tadded);
    //DrawCartoon dc = new DrawCartoon(g,tm);
    //dc.start();
  }
  public void drawTrackPoint(){
    tm.drawTrackpoint(this.g,point,this);
  }
  public void setPoint(Node point){
    this.point = point;
  }
  private void drawWaypoint(Node node){
    if(node != null){
      this.tm.drawWaypoint(g, node,"");
    }else{
      System.out.println("Waypoint==null");
    }
  }
  private void drawHisWpt(){
    Node[] hiswpt = this.tc.getHisWpt();
    if(hiswpt != null){
      for (int i = 0; i < hiswpt.length; i++) {
        this.tm.drawWaypoint(g, hiswpt[i],"");
      }
    }else{
//      System.out.println("hiswpt==null");
    }
  }

  public void drawAllWaypoint(){
    tm.drawAllWaypoints(g,this.allwpt);
  }
  public void drawWaypoint(){
    if(tc.w1!=null){
      this.drawWaypoint(tc.w1);
    }
    if(tc.w2!=null){
      this.drawWaypoint(tc.w2);
    }
  }

  void findWpt(Node node){
    tm.findWpt(this.getWidth(),this.getHeight(),node);
  }
  public void zoomIn(){
    tm.setScale(tm.getScale()*1.5);
    this.repaint();
  }
  public void zoomOut(){
    tm.setScale(tm.getScale()/1.5);
    this.repaint();
  }
  public void mouseClick(MouseEvent e){

  }
  public void mouseRelease(MouseEvent e){
    // 当鼠标松开时,要记录下这次已经移动的位置
    if(e.isPopupTrigger()){
      popup.show(this,e.getX(), e.getY());
    }
    int tx = e.getX()-this.baseX;
    int ty = e.getY()-this.baseY;
    tm.setMoved(tx,ty);
    this.setCursor(cursorDefault);
  }

  public void this_mousePressed(MouseEvent e) {
    this.baseX =e.getX();
    this.baseY = e.getY();
    Cursor cr = Toolkit.getDefaultToolkit().createCustomCursor(ItemValue.getImage("cursor.gif") , new Point(0,0) ,"MyCursor" );
    this.setCursor( cr );
  }

  public void this_mouseMoved(MouseEvent e) {

  }
  public void mouseDrag(MouseEvent e){
    long whenMouseMovedThisTime = e.getWhen();
    if(whenMouseMovedThisTime - this.whenMouseMovedLastTime > 10){
      int tx = e.getX() - this.baseX;
      int ty = e.getY() - this.baseY;
      tm.setMove(tx, ty);
      this.repaint();
      this.whenMouseMovedLastTime = whenMouseMovedThisTime;
      //System.out.println("MouseDrag-->X:"+e.getX()+",Y:"+e.getY());
    }
  }
  public void popup_actionPerformed(ActionEvent e){
    if(e.getActionCommand().equals("Zoom_In")){
      this.zoomIn();
    }else if(e.getActionCommand().equals("Zoom_Out")){
      this.zoomOut();
    }
  }
  /**
   * Paints this component.
   *
   * @param g the graphics context to use for painting
   * @todo Implement this java.awt.Component method
   */
  public void paint(Graphics g) {
    countPaint++;
    super.paint(g);
    this.g = g;
    if(this.init==false){
      this.init();
    }else{
      reDraw();
    }
    //System.out.println("DynamicPanel.paint() 运行"+countPaint);
  }
  public void setShow(boolean cut){
      //设置是否是cut显示,如果cut显示,设置cut和link里相应的变量,否则就是cut显示。
      //
    if(cut == true){
      this.showCut = true;
      this.showLink = false;
    }else{
      this.showCut = false;
      this.showLink = true;
    }
  }

  public void setShowAllTracksToOther(){
    this.showAllTrack = !this.showAllTrack ;
  }
  public void setShowAllWaypointsToOther(){
    this.showAllWaypoint = !this.showAllWaypoint;
  }
  public void setShowAllFalse(){
    this.showAllTrack =false;
    this.showAllWaypoint = false;

  }
  public void setShowHisWpt(){
    this.showHisWpt = !this.showHisWpt;
  }
  public boolean getShowAllTracks(){
    return this.showAllTrack;
  }
  public boolean getShowAllWaypoints(){
    return this.showAllWaypoint;
  }
  public boolean getShowHisWpt(){
    return this.showHisWpt;
  }

  private void jbInit() throws Exception {
    this.addMouseMotionListener(new DynamicPanel_this_mouseMotionAdapter(this));
    this.addMouseListener(new JPanel_mouseAdapter(this));
    jMenuItemZoomIn.setText("放大");
    jMenuItemZoomIn.addActionListener(new Popup_actionAdapter(this));
    jMenuItemZoomIn.setActionCommand("Zoom_In");
    jMenuItemZoomOut.setText("缩小");
    jMenuItemZoomOut.addActionListener(new Popup_actionAdapter(this));
    jMenuItemZoomOut.setActionCommand("Zoom_Out");
    popup.add(jMenuItemZoomIn);
    popup.add(jMenuItemZoomOut);
  }

}

class DynamicPanel_this_mouseMotionAdapter
    extends MouseMotionAdapter {
  private DynamicPanel adaptee;
  DynamicPanel_this_mouseMotionAdapter(DynamicPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseMoved(MouseEvent e) {
    adaptee.this_mouseMoved(e);
  }

  public void mouseDragged(MouseEvent e){
    adaptee.mouseDrag(e);
  }
}

class JPanel_mouseAdapter
    extends MouseAdapter {
  private DynamicPanel adaptee;
  JPanel_mouseAdapter(DynamicPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.mouseClick(e);
  }
  public void mouseReleased(MouseEvent e) {
    adaptee.mouseRelease(e);
  }
  public void mousePressed(MouseEvent e){
   adaptee.this_mousePressed(e);
  }
}

class Popup_actionAdapter
    implements ActionListener {
  private DynamicPanel adaptee;
  Popup_actionAdapter(DynamicPanel adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.popup_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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