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

📄 bestroadjframe.java

📁 JAVA+MO(for JAVA)开发的基于遗传算法的最短路径源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package mojavaproject;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import com.esri.mo2.ui.tb.ZoomPanToolBar;
import com.esri.mo2.ui.bean.OverviewMap;
import com.esri.mo2.ui.bean.Map;
import com.esri.mo2.ui.toc.TreeToc;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import com.esri.mo2.ui.bean.Layer;
//import java.util.ArrayList;
import BestRoadGA.LineBean;
import Tools.Calculation;
import Bean.HashArray;
//import BestRoadGA.OPAcetateLayer;
import BestRoadGA.*;
import SelectionSet.IDtoSelection;
import com.esri.mo2.map.dpy.FeatureLayer;
//import com.esri.mo2.ui.bean.BasePick;
//import BestRoadGA.FeaturePick;
import com.esri.mo2.cs.geom.Envelope;
import com.esri.mo2.cs.geom.Point;
import com.esri.mo2.data.feat.SelectionSet;
import com.esri.mo2.data.feat.Cursor;
import com.esri.mo2.file.shp.ShapefileFeature;
import com.esri.mo2.cs.geom.Polyline;


public class BestRoadJFrame extends JFrame implements ActionListener{
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();

    JMenuItem momenuitem11 = new JMenuItem();
    JMenuItem momenuitem12 = new JMenuItem();
    JMenuItem momenuitem13 = new JMenuItem();
    JMenuItem momenuitem14 = new JMenuItem();
    JMenuItem momenuitem21 = new JMenuItem();
    JMenuItem momenuitem22 = new JMenuItem();
    JMenu momenu1 = new JMenu();
    JMenuBar momenubar1 = new JMenuBar();
    JMenu momenu2 = new JMenu();
    JMenuBar momenubar2 = new JMenuBar();

    int screenX;
    int screenY;
    int topTag=0;
    int StartPAndEndPTag=0;
    int calBestroadTag=0;
    int displayBestroadTag=0;
    boolean setBEPointTag=false;     //设置最优路径是否开始的标签
    boolean completeSpSetTag=false;  //设置最优路径起点是否完成的标签
    boolean completeEpSetTag=false;  //设置最优路径终点是否完成的标签
    ZoomPanToolBar zoomPanToolBar1 = new ZoomPanToolBar();
    OverviewMap overviewMap1 = new OverviewMap();
    Map map1 = new Map();
    TreeToc treeToc1 = new TreeToc();
    double cursorX,cursorY;
    private boolean adjacencyTable[][]; //存储点与线的邻接表关系,如果线中包含点,则值为1;不包含,为0。
                                        //数组第一个下标表示点的位置,第二个下标表示线的位置。
    com.esri.mo2.map.dpy.FeatureLayer flayer1=null;

    //private ArrayList pointID_arrayList=new ArrayList();
    private LineBean rLine[];
    private int pointID[];
    private com.esri.mo2.cs.geom.Point pointCoord[];
    private int startPointID;       //保存所求的最优路径中起点的ID
    private int endPointID;          //保存所求的最优路径中终点的ID


    private int bestroadLine[];
    //private

    private int pNum=0;     //存储网络图中点集的个数
    private int lNum=0;     //存储网络图中线集的个数

    private static Timer timer=null;//闪烁路径
    //private FlashPath flashPath;

    JSplitPane jSplitPane0 = new JSplitPane();
    JSplitPane jSplitPane1 = new JSplitPane();
    JSplitPane jSplitPane2 = new JSplitPane();
    JSplitPane jSplitPane3 = new JSplitPane();
    JSplitPane jSplitPane5 = new JSplitPane();
    JSplitPane jSplitPane6 = new JSplitPane();


    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JPanel jPanel3 = new JPanel();
    JPanel jPanel4 = new JPanel();
    XYLayout xYLayout1 = new XYLayout();
    XYLayout xYLayout2 = new XYLayout();
    XYLayout xYLayout3 = new XYLayout();
    XYLayout xYLayout4 = new XYLayout();
    Layer layer1 = new Layer();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();

    JProgressBar jProgressBar1 = new JProgressBar();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel7 = new JLabel();
    JTextArea jTextArea1 = new JTextArea();
    JTextArea jTextArea2 = new JTextArea();
    JLabel jLabel8 = new JLabel();
    JLabel jLabel9 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JButton jButton5 = new JButton();

    public BestRoadJFrame() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public class DrawMouseListener extends MouseAdapter{
        public void mousePressed(MouseEvent e){}
        public void mouseDragged(MouseEvent e){}
        public void mouseReleased(MouseEvent e){}
        public void mouseMoved(MouseEvent e){}
        public void mouseClicked(MouseEvent e){
            if(setBEPointTag==true)
            {
                if (completeSpSetTag == false ){
                    cursorX = e.getX();//featurepick
                    cursorY = e.getY();
                    com.esri.mo2.cs.geom.Point cursorPoint=new com.esri.mo2.cs.geom.Point();
                    cursorPoint=map1.transformPixelToWorld(e.getX(),e.getY());
                    cursorX = cursorPoint.getX();
                    cursorY = cursorPoint.getY();
                    com.esri.mo2.cs.geom.Envelope envelope1=new Envelope(cursorX,cursorY,20,20);
                    Cursor cursor;
                    cursor=flayer1.search(envelope1,flayer1.getFeatureClass().getFields());
                    int curnum=0;
                    while(cursor != null && cursor.hasMore())
                    {
                        cursor.next();
                        curnum++;
                    }
                    if(curnum==0)
                    {
                        JLabel lblMessage = new JLabel("没有选中线!");
                        lblMessage.setFont(new Font("宋体",Font.BOLD,16));
                        JOptionPane.showMessageDialog(null,lblMessage,"提示:",JOptionPane.DEFAULT_OPTION);
                    }
                    else if(curnum==1) {

                        cursor = flayer1.search(envelope1,flayer1.getFeatureClass().getFields());
                        ShapefileFeature sfFeature = (ShapefileFeature) cursor.next();
                        Polyline pline=(Polyline)sfFeature.getGeometry();
                        if(pline.size()>0)
                        {
                            com.esri.mo2.cs.geom.Point pointstart=new com.esri.mo2.cs.geom.Point();
                            pointstart = pline.getPath(0).getStartPoint();
                            com.esri.mo2.cs.geom.Point pointend=new com.esri.mo2.cs.geom.Point();
                            pointend = pline.getPath(pline.size() - 1).getEndPoint();
                            Calculation cal=new Calculation();
                            double distance1=cal.calDiatance(cursorPoint,pointstart);
                            double distance2=cal.calDiatance(cursorPoint,pointend);
                            if(distance1<distance2)
                            {
                                startPointID = Integer.parseInt(sfFeature.getValue(1).toString()); //获取字段FNODE_的值

                            }
                            else
                            {
                                startPointID = Integer.parseInt(sfFeature.getValue(2).toString()); //获取字段FNODE_的值

                            }
                            jTextArea1.setText(sfFeature.getValue(5).toString());//设置起点为:线段的FNODE_值
                            jTextArea1.setEditable(false);
                            completeSpSetTag = true;
                        }
                        else
                        {
                            JLabel lblMessage = new JLabel("获取的Polyline为空!");
                            lblMessage.setFont(new Font("宋体", Font.BOLD, 16));
                            JOptionPane.showMessageDialog(null, lblMessage,"提示:", JOptionPane.DEFAULT_OPTION);
                            completeEpSetTag = false;
                            jTextArea2.setText("");
                        }
                    }

                    else if(curnum>1)
                    {
                        JLabel lblMessage = new JLabel("选中了多条线,请重新选取!");
                        lblMessage.setFont(new Font("宋体",Font.BOLD,16));
                        JOptionPane.showMessageDialog(null,lblMessage,"提示:",JOptionPane.DEFAULT_OPTION);
                        completeSpSetTag = false;
                        jTextArea1.setText("");
                    }
                }

                else if (completeSpSetTag == true && completeEpSetTag == false) {

                    com.esri.mo2.cs.geom.Point cursorPoint=new com.esri.mo2.cs.geom.Point();
                    cursorPoint=map1.transformPixelToWorld(e.getX(),e.getY());
                    cursorX = cursorPoint.getX();
                    cursorY = cursorPoint.getY();
                    com.esri.mo2.cs.geom.Envelope envelope1=new Envelope(cursorX,cursorY,20,20);
                    Cursor cursor;
                    cursor=flayer1.search(envelope1,flayer1.getFeatureClass().getFields());
                    int curnum=0;
                    while(cursor != null && cursor.hasMore())
                    {
                        cursor.next();
                        curnum++;
                    }
                    if(curnum==0)
                    {
                        JLabel lblMessage = new JLabel("没有选中线!");
                        lblMessage.setFont(new Font("宋体",Font.BOLD,16));
                        JOptionPane.showMessageDialog(null,lblMessage,"提示:",JOptionPane.DEFAULT_OPTION);
                    }
                    if(curnum==1)
                    {
                    cursor = flayer1.search(envelope1,flayer1.getFeatureClass().getFields());
                    ShapefileFeature sfFeature = (ShapefileFeature) cursor.next();
                    Polyline pline=(Polyline)sfFeature.getGeometry();
                    if(pline.size()>0)
                    {
                        com.esri.mo2.cs.geom.Point pointstart = new com.esri.mo2.cs.geom.Point();
                        pointstart = pline.getPath(0).getStartPoint();
                        com.esri.mo2.cs.geom.Point pointend = new com.esri.mo2.cs.geom.Point();
                        pointend = pline.getPath(pline.size() - 1).getEndPoint();
                        Calculation cal = new Calculation();
                        double distance1 = cal.calElev(cursorPoint,pointstart);
                        double distance2 = cal.calElev(cursorPoint,pointend);

⌨️ 快捷键说明

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