package relloc; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import java.awt.Stroke; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.lang.ref.SoftReference; import java.util.Vector; import javax.swing.ImageIcon; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; import BaoWen.Stac; import ColorAndFont.ChooseColor; import ColorAndFont.UIColor; import DrawImage.Drawok; import Frame.AnchorManage; import Frame.AnchorNearby; import Frame.DebugManage; import JNADell.DellJAN; import Judge.JugeNumber; import Method.Bj; import Method.Map_suo_fang; import PbuliClass.FastAddAnc; import PbuliClass.Systems; import PbuliClass.jinternalFrame; import ToolBarS.ToolBarModel; import anchor.Anchor; import anchor.Anchor_Dell; import anchor.Dell_cengao; import circle.Dell_ResultYuang; import circle.Dell_yuang; import circle.ResultYuang; import circle.Yuang; import circle.Yuangvc; import fence.Fences; import fence.kaoqing.Dell_KaoQing; import person.Person; import person.person_Dell; import tbDataModel.RealTrackPoint; import tbDataModel.TbFence; import tbDataModel.TbMap; import tbDataModel.Tb_gas_anchor; import tbDataModel_Dell.Dell_Line; import tbDataModel_Dell.Dell_ReallPoint; import tbDataModel_Dell.Dell_tb_gas_anchor; import tbDataModel_Dell.Dell_yuan; import tbDataModel_Dell.FontChoose; import tbDataModel_Dell.Map_Dell; /**¸ÃÀàÓÃÓÚʵʱÏÔʾ±êǩλÖÃ*/ public class RealLoc extends jinternalFrame implements Runnable { /** * */ private static final long serialVersionUID = 1L; Mycanvas mycanvas=null; double bi=1;//µØÍ¼Ëõ·Å±ÈÀý³õʼֵΪ1ĬÈϲ»Ëõ·Å int countnum=200; Point origin; int x0=0;//µØÍ¼Î»ÖÃX×ø±ê,ͨ¹ý¸Ä±ä´ËÖµ¸Ä±äµØÍ¼Î»Öà int y0=0;//µØÍ¼Î»ÖÃy×ø±ê,ͨ¹ý¸Ä±ä´ËÖµ¸Ä±äµØÍ¼Î»Öà static int x1=0; static int y1=0; int width;//µØÍ¼³õʼ¿í¶È int height;//µØÍ¼³õʼ¸ß¶È int new_width;//µØÍ¼ÐµĿí¶È£¬Í¨¹ý¸Ä±ä´ËÖµ¿ÉÒÔ¸Ä±äµØÍ¼µÄ¿í¶È int new_height;//µØÍ¼Ðµĸ߶ȣ¬Í¨¹ý¸Ä±ä´ËÖµ¿ÉÒÔ¸Ä±äµØÍ¼µÄ¸ß¶È int orix;//µØÍ¼µ±Ç°µÄX×ø±ê int oriy;//µØÍ¼µ±Ç°Y×ø±ê double x_bi;//ͼƬµÄxÏñËØµãºÍʵ¼Ê³¤µÄ±ÈÖµ double y_bi;//ͼƬµÄyÏñËØµãºÍʵ¼Ê¿íµÄ±ÈÖµ double map_true_width;//µØÍ¼Êµ¼Ê³¤¶È double map_true_height;//µØÍ¼Êµ¼Ê¸ß¶È TbMap map=null;//ÉêÃ÷µØÍ¼¶ÔÏó Color color; String mapfloor; int shubiaox; int shubiaoy; int framey;//µ±Ç°Ãæ°å¸ß¶È int framex;//µ±Ç°Ãæ°åµÄ¿í¶È int newOffsetX; int newOffsetY; int shubiao=0;//Êó±êµã»÷µÄ´ÎÊý int[] xy=new int[4]; //µØÍ¼Êµ¼ÊÔ­µã×ø±ê int yuan_x0=0; int yuan_y0=0; //µ±Ç°¹â±êµÄ×ø±ê int guangx=0; int guangy=0; static int sosnum=0; static boolean relocopen=false; int corloc=0; static int sleeptime=300; Graphics2D g2=null; Image sos=new ImageIcon("image/icon/sos.png").getImage(); Image sos1=new ImageIcon("image/icon/sos1.png").getImage(); Image anchor_red=new ImageIcon("image/anchor/red.png").getImage(); Image anchor_yellow=new ImageIcon("image/anchor/ceju.png").getImage(); Image anchor_green=new ImageIcon("image/anchor/lingjin.png").getImage(); Image anchor_off=new ImageIcon("image/anchor/anchoroff.png").getImage(); Image anchor_on=new ImageIcon("image/anchor/anchoron.png").getImage(); Color ancid=ChooseColor.getColo("À¶É«",255); int online=0; int showguijitime=Systems.get_real_track_time(); Color grenn=new Color(50,205,50,150); Color red=new Color(255,105,180,150); boolean showname=Systems.sys().getViewName().equals("1"); boolean showtagid=Systems.sys().getViewTagid().equals("1"); SoftReference sfRefer =null; int clickx=0;//Êó±êµã»÷ʱºòµÄX int clicky=0;//Êó±êµã»÷ʱºòµÄY Stroke stroke=new BasicStroke(2);//ÉèÖû­±Ê /**¹¹Ôì·½·¨*/ public RealLoc(String floor,String mapName) { map=Map_Dell.get_map(floor); mapfloor=map.getFloor(); String mapAdress="image/mapfile/"+map.getMapname(); Image image=new ImageIcon(mapAdress).getImage();//»ñÈ¡µØÍ¼ sfRefer = new SoftReference (image ); map_true_width=map.getX_Truelength(); map_true_height=map.getY_Truewidth(); width=image.getWidth(this); height=image.getHeight(this); new_width=width; new_height=height; x_bi=map_true_width/new_width;//µØÍ¼µÄʵ¼Ê³¤¶ÈºÍеĿí¶È±ÈÖµ y_bi=map_true_height/new_height;//µØÍ¼Êµ¼Ê¸ß¶ÈºÍеĸ߶ȱÈÖµ color=Color.red; Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷ rq.setLayout(new BorderLayout()); rq.setBackground(Color.white); mycanvas=new Mycanvas();//³õʼ»¯»æÍ¼Ãæ°å¶ÔÏó this.setTitle(mapName); this.setFrameIcon(new ImageIcon("image/icon/mapicon.png"));//ÉèÖô°Ìåͼ±ê rq.add(mycanvas,BorderLayout.CENTER); yuan_x0=Map_Dell.get_map(mapfloor).getX0_length(); yuan_y0=Map_Dell.get_map(mapfloor).getY0_width(); startThread();//Æô¶¯Ïß³Ì this.addInternalFrameListener(new InternalFrameListener() { @Override public void internalFrameOpened(InternalFrameEvent e) { } @Override public void internalFrameIconified(InternalFrameEvent e) { sleeptime=2000; relocopen=false; Dell_ReallPoint.clear(); } @Override public void internalFrameDeiconified(InternalFrameEvent e) { sleeptime=300; relocopen=true; } @Override public void internalFrameDeactivated(InternalFrameEvent e) { } @Override public void internalFrameClosing(InternalFrameEvent e) { relocopen=false; sfRefer =null; Tanchu_Menu.setKusubudain(false); } @Override public void internalFrameClosed(InternalFrameEvent e) { } @Override public void internalFrameActivated(InternalFrameEvent e) { } }); } /**Æô¶¯Ï̵߳ķ½·¨*/ public void startThread() { Thread t=new Thread(this); relocopen=true; t.start(); } public void run() { while(true) { try { if(map !=null) { if(relocopen) { mycanvas.repaint(); } } Thread.sleep(sleeptime);//ÐÝÃßʱ¼ä } catch (InterruptedException e) { e.printStackTrace(); } } } /**ÄÚ²¿µÄ»­²¼*/ class Mycanvas extends Canvas implements MouseListener,MouseMotionListener,MouseWheelListener { /** * */ private static final long serialVersionUID = 1L; public void update(Graphics g){ //¸²¸Çupdate·½·¨£¬½ØÈ¡Ä¬Èϵĵ÷Óùý³Ì Image ImageBuffer = createImage(this.getWidth(), this.getHeight()); //´´½¨Í¼Ðλº³åÇø Graphics GraImage = ImageBuffer.getGraphics(); //»ñȡͼÐλº³åÇøµÄͼÐÎÉÏÏÂÎÄ paint(GraImage); //ÓÃpaint·½·¨ÖбàдµÄ»æÍ¼¹ý³Ì¶ÔͼÐλº³åÇø»æÍ¼ GraImage.dispose(); //ÊÍ·ÅͼÐÎÉÏÏÂÎÄ×ÊÔ´ g.drawImage(ImageBuffer, 0, 0, this); //½«Í¼Ðλº³åÇø»æÖƵ½ÆÁÄ»ÉÏ ImageBuffer =null; GraImage =null; } public Mycanvas() { origin = new Point();; addMouseWheelListener(this); addMouseListener(this); addMouseMotionListener(this); } public void paint(Graphics g) { g2=(Graphics2D) g; g2.setColor(getBackground()); g2.fillRect(0,0,this.getSize().width,this.getSize().height); g2.drawImage(sfRefer.get(), x0, y0, new_width, new_height,this); x1=x0; y1=y0; framey=this.getSize().height;//µ±Ç°Ãæ°åµÄ¸ß¶È framex=this.getSize().width; if(true) { //»æÖÆÔ­µã double aa=(-yuan_x0/x_bi)+x0; double bb=(-yuan_y0/y_bi)+y0; int x_newyuan=(int)aa; int y_newyuan=(int)bb; g2.setColor(Color.red); g2.fillOval(x_newyuan-4, y_newyuan-4,8,8); } Vector pervc=person_Dell.getPerson_vector(); if(Stac.isSerchperson()) { String tagid=Stac.getSerchtagid(); if(!tagid.equals("0")) { pervc=person_Dell.serch(tagid); } } //»æÖÆ»ùÕ¾ draw_anchor(g2); draw_gasanchor(g2) ;//»æÖÆÆøÑ¹»ùÕ¾ //»æÖƱêÇ©¶ÔÏó int size=pervc.size(); online=size; if( size!=0) { for(int i=0;i circ=yvc.getYuangs(); int size1=circ.size(); if( size1 !=0) { for(int i=0;i0) { int r1=2*new Double(Math.sqrt(r_h)/x_bi).intValue(); int r2=2*new Double(Math.sqrt(r_h)/y_bi).intValue(); g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.0f)); g2.drawOval(anx-r1/2, any-r2/2,r1,r2); g2.drawImage(Anchor_Dell.getCeju(), anx-15, any-30,30,30,this); } } circ=null; } ResultYuang rsy=Dell_ResultYuang.get_resty(key); String afloor=String.valueOf(rsy.getFloor()); if(afloor.equals(mapfloor)) { g2.setColor(UIColor.getGrenn()); int x=rsy.getX(); int y=rsy.getY(); int anx=get_xpos(mapfloor,x); int any=get_ypos(mapfloor,y); g2.fillOval(anx-7,any-7,14,14); } rsy=null; afloor=null; } } /**»æÖÆÖ±Ïß*/ Drawok.drawyuan(x_bi, y_bi, x0, y0, g2); Drawok.line(x_bi, y_bi, x0, y0, g2); /**»æÖÆÒѾ­´æÔÚµÄΧÀ¸¶ÔÏó**/ if(ToolBarModel.isShowfence()) { Drawok.draw_point_inoutLine(mapfloor,g2); Drawok.fence(mapfloor, x_bi, y_bi, x0, y0,yuan_x0,yuan_y0, g2,bi); Drawok.draw_point_inout(mapfloor, x_bi, y_bi, x0, y0,yuan_x0,yuan_y0,g2); } if (ToolBarModel.getSuanFa()){ Drawok.lineAndArea(mapfloor, x_bi, y_bi, x0, y0,yuan_x0,yuan_y0,g2); } g2=null; } public void mouseReleased(MouseEvent e) {//°´¼üÊÍ·Å clickx=0; clicky=0; setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } public void mousePressed(MouseEvent e) {//°´¼ü°´Ï origin.x = e.getX(); //»ñµÃÊó±êµã»÷ʱºòµÄX×ø±ê origin.y = e.getY();//»ñµÃÊó±êµã»÷ʱºòµÄY×ø±ê orix=x0;//½«µ±Ç°Í¼Æ¬µÄÆðµã×ø±êX¸øorix oriy=y0;//½«µ±Ç°Í¼Æ¬µÄÆðµã×ø±êX¸øoriy int x_cursor=e.getX();//Êó±ê¶ÔÓ¦µÄÏñËØµã int y_cursor=e.getY();//Êó±ê¶ÔÓ¦µÄÏñËØµã shubiaox=(new Double((x_cursor-x0)*x_bi)).intValue();//ÏñËØµã¶ÔÓ¦µÄÊµÊ±×ø±êx shubiaoy=(new Double((y_cursor-y0)*y_bi)).intValue();//ÏñËØµã¶ÔÓ¦µÄÊµÊ±×ø±êy clickx=shubiaox+yuan_x0; clicky=shubiaoy+yuan_y0; } public void mouseExited(MouseEvent e) {//Êó±êÍ˳ö } public void mouseEntered(MouseEvent e) {//Êó±ê½øÈë setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } /**Êó±êµã»÷ʼþ*/ public void mouseClicked(MouseEvent e) {//Êó±êµã»÷ if(e.isMetaDown()){//¼ì²âÊó±êÓÒ¼üµ¥»÷ popupMenu().show(e.getComponent(), e.getX(), e.getY()); }else if(e.getButton()==MouseEvent.BUTTON1){//µã»÷Êó±ê×ó¼ü if(ToolBarModel.isDrawline()) { if(shubiao==0) { xy[0]=shubiaox; xy[1]=shubiaoy; Dell_yuan.insert_yuan(xy[0], xy[1],6,6); shubiao++; }else if(shubiao==1) { xy[2]=shubiaox; xy[3]=shubiaoy; Dell_yuan.insert_yuan(xy[2], xy[3],6,6); //¹´¹É¶¨Àí¼ÆËãб±ßµÄ³¤¶È double a0=xy[2]-xy[0]; double b0=xy[3]-xy[1]; double distance=Math.sqrt(a0*a0+b0*b0); Dell_Line.insert_aline(xy,distance); shubiao=0; } } //¹öÂÖ°´Ï }else if(e.getButton()==MouseEvent.BUTTON2) { DellJAN.SetSetReferencePoint(guangx,guangy); } if(e.getButton()==MouseEvent.BUTTON1 && Tanchu_Menu.isKusubudain()) { if(!Bj.isHavefas()) { FastAddAnc fa=new FastAddAnc("¿ìËÙÔö¼Ó»ùվģʽ"); String id=Bj.getAnc()+""; fa.getAnchorIdFile().setText(id); fa.getPosxFile().setText(guangx+""); fa.getPosyFile().setText(guangy+""); fa.getPoszFile().setText("200"); Bj.setHavefas(true); } } } public void mouseDragged(MouseEvent e) { setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); //Ãæ°åеÄ×ø±êλÖà = ÒÆ¶¯Ç°×ø±êλÖÃ+£¨Êó±êÖ¸Õëµ±Ç°×ø±ê-Êó±ê°´ÏÂʱָÕëµÄλÖã© x0=orix+e.getX()-origin.x; y0=oriy+e.getY()-origin.y; this.repaint(); } public void mouseMoved(MouseEvent e) { int x_cursor=e.getX();//Êó±ê¶ÔÓ¦µÄÏñËØµã int y_cursor=e.getY();//Êó±ê¶ÔÓ¦µÄÏñËØµã shubiaox=(new Double((x_cursor-x0)*x_bi)).intValue();//ÏñËØµã¶ÔÓ¦µÄÊµÊ±×ø±êx shubiaoy=(new Double((y_cursor-y0)*y_bi)).intValue();//ÏñËØµã¶ÔÓ¦µÄÊµÊ±×ø±êy guangx=shubiaox+yuan_x0; guangy=shubiaoy+yuan_y0; clickx=0; clicky=0; } /**Êó±ê¹öÂÖ¹ö¶¯Ê¼þ¼àÌý*/ public void mouseWheelMoved(MouseWheelEvent e) {//Êó±ê¹öÂÖ¹ö¶¯¼àÌý //e.getWheelRotation()>0±íʾÊó±ê¹öÂÖÏòÍâ¹ö¶¯Ð¡ÓÚ0±íʾÏòÄÚ¹ö¶¯ int xh1=e.getX(); int yh1=e.getY(); double bi0=bi; int xr=x0; int yr=y0; if(e.getWheelRotation()>0 && countnum>0 ) {//ËõСͼƬ countnum=countnum-50; bi=Map_suo_fang.get_bi(countnum); } if(e.getWheelRotation()<0 && countnum <600) {//·Å´óͼƬ countnum=countnum+50; bi=Map_suo_fang.get_bi(countnum); } new_width=new Double(width*bi).intValue();//ͼƬеĿí¶È new_height=new Double(height*bi).intValue();//ͼƬÐÂµÄ¸ß¶È x_bi=map_true_width/new_width;//µØÍ¼µÄʵ¼Ê³¤¶ÈºÍеĿí¶È±ÈÖµ y_bi=map_true_height/new_height;//µØÍ¼Êµ¼Ê¸ß¶ÈºÍеĸ߶ȱÈÖµ map.setXb(x_bi); map.setYb(y_bi); //x0=new Double(xh1-width/2*bi).intValue(); //y0=new Double(yh1-height/2*bi).intValue(); x0=new Double(xh1-(xh1-xr)*bi/bi0).intValue(); y0=new Double(yh1-(yh1-yr)*bi/bi0).intValue(); this.repaint(); } } /**µ¯³ö²Ëµ¥À¸*/ public JPopupMenu popupMenu() { JPopupMenu popupMenu = new JPopupMenu();// ´´½¨µ¯³öʽ²Ëµ¥¶ÔÏó popupMenu.setBorderPainted(false); JMenuItem center = new JMenuItem("Ô­µã¾ÓÖÐ");//´´½¨²Ëµ¥Ïî center.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù x0=framex/2; y0=framey/2; mycanvas.repaint(); } }); JMenuItem accolor=new JMenuItem("»ùÕ¾ÑÕÉ«"); accolor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù if(corloc==0) { ancid=ChooseColor.getColo("°×É«",255); corloc=1; }else if(corloc==1) { ancid=ChooseColor.getColo("ºÚÉ«",255); corloc=2; }else if(corloc==2) { ancid=ChooseColor.getColo("ºìÉ«",255); corloc=0; } mycanvas.repaint(); } }); popupMenu.add(center); popupMenu.addSeparator();// Ìí¼Ó·Ö¸ôÏß popupMenu.add(Tanchu_Menu.get_sousuo()); popupMenu.addSeparator(); popupMenu.add(Tanchu_Menu.get_sendtext()); popupMenu.addSeparator(); popupMenu.add(accolor); popupMenu.addSeparator(); popupMenu.add(Tanchu_Menu.get_fastbudian()); popupMenu.addSeparator(); popupMenu.add(Tanchu_Menu.get_clerguiji()); popupMenu.addSeparator(); popupMenu.add(Tanchu_Menu.get_xiangxi()); return popupMenu; } /**»ñÈ¡ÔÚµØÍ¼ÖеÄX×ø±ê*/ public static int get_xpos(String mapfloor, int x){ int a0=Map_Dell.get_map(mapfloor).getX0_length(); double anc_x=x-a0; double x1_bi=Map_Dell.get_map(mapfloor).getXb(); double xx=(anc_x/x1_bi)+x1; int anx=(int)Math.round(xx); return anx; } /**»ñÈ¡ÔÚµØÍ¼ÖеÄY×ø±ê*/ public static int get_ypos(String mapfloor,int y){ int b0=Map_Dell.get_map(mapfloor).getY0_width(); double anc_y=y-b0; double y1_bi=Map_Dell.get_map(mapfloor).getYb(); double yy=(anc_y/y1_bi)+y1; int any=(int)Math.round(yy); return any; } public static boolean isRelocopen() { return relocopen; } /**»æÖƱêÇ©¶ÔÏóµÄ¹ì¼£*/ public void drawguiji(String tagid,Graphics2D g2) { if( showguijitime !=0) { Vector track_vector=Dell_ReallPoint.get_rtpt(tagid); if( track_vector !=null && track_vector.size()!=0) { for(int k=0;k vecnertac=AnchorNearby.getChoose_anchor(); if(vecnertac.size() !=0) { for(int i=0;i gas_anchorvc=Dell_tb_gas_anchor.getGas_anchorvc(); int size=gas_anchorvc.size(); for(int i=0;i kqfc=Fences.get_kaoqing_fences(mapfloor); if(kqfc !=null) {//Èç¹û¿¼ÇÚÇøÓò´æÔÚ int size1=kqfc.size(); int hig=60; if (size1>2){ hig=30*(size1+1); } int j=30; g2.setColor(ChooseColor.getColo("Æ·ºì", 100)); g2.fillRoundRect(50,10,140,hig, 10, 10); g2.setFont(FontChoose.ziti(18)); g2.setColor(Color.white); if(size1 !=0) { for(int i=0;i