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

📄 gumviewer.java

📁 实现了对GUM类型的图像的放大缩小漫游的功能
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		
		btn_delete = new JButton(LoadImageIcon("delete.gif"));
        btn_delete.setToolTipText("在绘画序列中删除选中文件");
		btn_delete.setBorderPainted(false); 
        btn_delete.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
				int[] Selected=FileList.getSelectedIndices();
				if(Selected.length>0)
				{
					for(int i=0;i<Selected.length;i++)
					{							
						FileNames.removeElementAt(Selected[i]-i);
						FileFullNames.removeElementAt(Selected[i]-i);
						Maps.removeElementAt(Selected[i]-i);
					}
					FileList.clearSelection();
					FileList.updateUI();
					selected=FileList.getSelectedIndices();

					Picture.setImage(null);
					Picture.setPreferredSize(new Dimension(0,0));
					Picture.invalidate();
			
				
					Rectangle myrect=Picture.getVisibleRect();
					myrect.x=myrect.y=0;

						
					Picture.scrollRectToVisible(myrect);
					infoPanel.setImage(null);
					infoPanel.repaint();
					if(m_isshow)
					{
						m_isshow=false;
						pictureScrollPane.setViewportView(intro.myintro);
						intro.myintro.restart();
					}
					System.gc();
				}
            }
        });
        LeftBar.add(btn_delete);
	
	
	}
/***********************************************************
 *          setLeftButtons:设置左边按钮状态
 *                     tag:状态
 *                  返回值:无
 ***********************************************************/	
	public void setLeftButtons(boolean tag)
	{
		btn_up.setEnabled(tag);
		btn_down.setEnabled(tag);
		btn_top.setEnabled(tag);
		btn_buttom.setEnabled(tag);	
		btn_delete.setEnabled(tag); 
	}
	
	
/************************************************************
 * GumFileFilter类  Gum格式文件过滤器 
 ************************************************************/class GumFileFilter extends FileFilter {
    
    public boolean accept(File f) {
        if (f.isDirectory())
            return true;
	else if(f.getName().length()<4)
		return false;
	else if(f.getName().substring(f.getName().length()-4,f.getName().length()).toLowerCase().equals(".gum"))
			return true;
		else
			return false;    }        public String getDescription() {        return "Gum File Format";    }}
/**********************************************************
 * ScrollBarMouseListene  滚动条鼠标事件监视类
 **********************************************************/

    class ScrollBarMouseListener extends MouseInputAdapter {
        public void mouseReleased(MouseEvent e) {
		  if (SwingUtilities.isLeftMouseButton(e)) {
			  Picture.setPosition(HorizontalScrollBar.getValue(),VerticalScrollBar.getValue());
			ReDrawMap();
		  }
		}
	}
/**********************************************************
 * PicturePanelMouseListener 图形显示区域鼠标事件监视类
 **********************************************************/	
	class PicturePanelMouseListener extends MouseInputAdapter{	 		private int x1,y1,x2,y2;
		private int tempx1,tempy1,tempw,temph;
		public void mouseMoved(MouseEvent e)           
		{			if(Picture.img!=null){
			infoPanel.setWhere(e.getX()<=width?e.getX():width,e.getY()<=height?e.getY():height);
			infoPanel.paintWhere();}
		}
	    public void mouseReleased(MouseEvent e) {
			if(Picture.img!=null)
			{
				if(isSelected)
				{
					if(x1>x2)
					{
						int t=x1;
						x1=x2;
						x2=t;
					}
					if(y1>y2)
					{
						int t=y1;
						y1=y2;
						y2=t;
					}				
					if((x2-x1)>10 || (y2-y1)>10)
					{						Rectangle myrect=Picture.getVisibleRect();
						double scale=((double)myrect.width/(x2-x1)<(double)myrect.height/(y2-y1))?(double)myrect.width/(x2-x1):(double)myrect.height/(y2-y1);
						width*=scale;						height*=scale;
							
						if(width<myrect.width)
							x1=0;
						if(height<myrect.height)
							y1=0;	
						if((double)myrect.width/(x2-x1)<(double)myrect.height/(y2-y1))
						{
							myrect.x=(int)(x1*scale);
							myrect.y=(int)((y1+y2)*scale/2-myrect.height/2);
						}
						else
						{
							myrect.x=(int)((x1+x2)*scale/2-myrect.width/2);
							myrect.y=(int)(y1*scale);
						}						
						Picture.setPosition(myrect.x,myrect.y);					
						ReDrawMap();
					}
					else
						Picture.paintImmediately(x1,y1,x2-x1+50,y2-y1+50);				}
				else if(isDragged){					Rectangle trect=Picture.getVisibleRect();						Picture.setPosition(trect.x,trect.y);					ReDrawMap();
					Picture.setCursor(cur_drag1);				}
					}
		}
		public void mousePressed(MouseEvent e) 		{
			if(Picture.img!=null){			if(isDragged){				x1=e.getX();
				y1=e.getY();				Picture.setCursor(cur_drag2);
			}
			else if(isSelected)
			{				x1=x2=e.getX()<width?e.getX():width;				y1=y2=e.getY()<height?e.getY():height;
			}
			}		}		public void mouseClicked(MouseEvent e) 		{
			if (Picture.img!=null)			{				if(!isSelected && !isDragged)
					select(e.getX(),e.getY());			}		}		public void mouseDragged(MouseEvent e) 		{
			if(Picture.img!=null){				infoPanel.setWhere(e.getX()<=width?e.getX():width,e.getY()<=height?e.getY():height);
				infoPanel.paintWhere();				if(isDragged)				{
					infoPanel.setWhere(e.getX()<=width?e.getX():width,e.getY()<=height?e.getY():height);					infoPanel.paintWhere();
					Rectangle trect=Picture.getVisibleRect();				
					trect.x=x1+trect.x-e.getX();
					trect.y=y1+trect.y-e.getY();
					Picture.scrollRectToVisible(trect);					Picture.revalidate();				}				else if(isSelected)				{					Picture.paintImmediately(tempx1,tempy1,tempw+50,temph+50);
					Graphics g=Picture.getGraphics();					x2=e.getX()<width?e.getX():width;					y2=e.getY()<height?e.getY():height;					tempx1=x1<x2?x1:x2;					tempy1=y1<y2?y1:y2;					tempw=x2-x1>0?(x2-x1):(x1-x2);					temph=y2-y1>0?(y2-y1):(y1-y2);
					g.drawRect(tempx1,tempy1,tempw,temph);				}			}				}				}

/***********************************************************
 * PicturePanel类  用于显示图形的区域
 ***********************************************************/
	class PicturePanel extends JPanel{
		private Image img=null;
		private int   x1 = 0;
		private int   y1 = 0;
		private boolean tag=true;
		public  int   m_width,m_height;
	    public void paintComponent(Graphics g){	           super.paintComponent(g);
			if(img!=null && tag)
				g.drawImage(img,x1,y1,this);
		}
		public void setTag(boolean in){tag=in;}
		public void setImage(Image image){img=image;}
		public void setPosition(int x2,int y2)
		{
			x1=x2;
			y1=y2;
		}

		public int getx(){return x1;}

		public int gety(){return y1;}

		public void repaintImmediately(Graphics g)
		{			if(img!=null)
				g.drawImage(img,x1,y1,this);
		}
	}

/***********************************************************
 * InfoPanel 显示小地图信息的区域
 ***********************************************************/
	class InfoPanel extends JPanel
	{
		private Image  img=null;
		private int    x=0;
		private int    y=0;
		private double mapWidth;
		private double mapHeight;
		private int    pwidth;		private int    pheight;		public InfoPanel(int w,int h)		{
			pwidth=w;			pheight=h;
			setDoubleBuffered(true);
			setPreferredSize(new Dimension(w+20, h+70));
		}

		public void paintComponent(Graphics g)
		{			super.paintComponent(g);			if(img!=null){
				g.drawImage(img,20,20,this);
				g.setFont(new  Font("宋体",Font.PLAIN,12));
				g.drawString("地图宽度(像素):"+width,20,pheight+30);
				g.drawString("地图高度(像素):"+height,20,pheight+42);
				g.drawString("地图实际宽度(米):"+mapWidth,20,pheight+54);
				g.drawString("地图实际高度(米):"+mapHeight,20,pheight+66);
			}
		}				public void paintWhere()
		{
			if(img!=null){
				paintImmediately(20, 20, pwidth+30, pheight+30) ;
				x=x>0?x:0;
				y=y>0?y:0;
				Graphics2D g=(Graphics2D)getGraphics();
				g.setFont(new  Font("宋体",Font.PLAIN,12));
				g.setColor(getBackground());
				g.fillRect(0,0,pwidth+100,20);
				g.fillRect(0,0,20,pheight+100);
				g.setColor(Color.black);
				g.drawString(Integer.toString(x),20+(x*pwidth/width),18);
				g.rotate(-3.1415926/2,20,20);
				g.drawString(Integer.toString(y),20-(y*pheight/height),18);
				g.rotate(3.1415926/2,20,20);
				g.drawLine((int)(x*pwidth/width+14),(int)(y*pheight/height+20),(int)(x*pwidth/width+26),(int)(y*pheight/height+20));
				g.drawLine((int)(x*pwidth/width+20),(int)(y*pheight/height+14),(int)(x*pwidth/width+20),(int)(y*pheight/height+26));	
			}		}
		public void setWhere(int x1,int y1)		{			x=x1;			y=y1;		}
		public void setImage(Image image)		{
			img=image;		}		public void setMapSize(double w,double h){ mapWidth=w;mapHeight=h;}
		public int  n_getWidth(){return pwidth;}
		public int  n_getHeight(){return pheight;}
		public void n_setHeight(int h){pheight=h;}	}
	

/***************************************************************
 * SmallPanelMouseListener 小地图信息的区域鼠标事件侦听器
 **************************************************************/
	class SmallPanelMouseListener extends MouseInputAdapter{
		int x1;		int y1;
		public void mouseMoved(MouseEvent e)           
		{
			int x2=(int)((e.getX()-20)*width/infoPanel.n_getWidth());
			x2=x2>0?x2:0;
			x2=x2<width?x2:width;
			
			int y2=(int)((e.getY()-20)*height/infoPanel.n_getHeight());			y2=y2>0?y2:0;
			y2=y2<height?y2:height;			
			infoPanel.setWhere(x2,y2);			infoPanel.paintWhere();
		}
		        public void mouseReleased(MouseEvent e) {			if (SwingUtilities.isLeftMouseButton(e))			{				int x2=(int)((e.getX()-20)*width/infoPanel.n_getWidth());
				int y2=(int)((e.getY()-20)*height/infoPanel.n_getHeight());				if(x2>0 && y2>0 && x2<width && y2<height){					Rectangle trect=Picture.getVisibleRect();	
					int left=x2-Picture.getVisibleRect().width/2;					int up=y2-Picture.getVisibleRect().height/2;					left=left+trect.width<width?left:(width-trect.width);
					left=left>0?left:0;					up=up+trect.height <height?up:(height-trect.height);
					up=up>0?up:0;
					Picture.setPosition(left,up);
					ReDrawMap();
				}			}
		}
		public void mousePressed(MouseEvent e) 		{
			x1=e.getX();
			y1=e.getY();		}		public void mouseClicked(MouseEvent e) 		{
		}		public void mouseDragged(MouseEvent e) 		{
			int x2=(int)((e.getX()-20)*width/infoPanel.n_getWidth());
			x2=x2>0?x2:0;
			x2=x2<width?x2:width;
			
			int y2=(int)((e.getY()-20)*height/infoPanel.n_getHeight());			y2=y2>0?y2:0;
			y2=y2<height?y2:height;			
			infoPanel.setWhere(x2,y2);			infoPanel.paintWhere();		}
}/***********************************************************
 *  DrawSmallThread  小地图绘画线程
 ***********************************************************/
	class DrawSmallThread extends Thread{
		public void run()
		{
			int height=infoPanel.n_getHeight();
			int width=infoPanel.n_getWidth();
			BufferedImage tempimg= new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
			Graphics2D g= (Graphics2D)tempimg.getGraphics() ;
			g.setBackground(m_imgBackground);
			g.clearRect(0,0,width,height);
			for(int p=0;p<selected.length;p++)
			{
				map tempMap=(map)Maps.elementAt(selected[p]);
				double scale=tempMap.m_lowRight.X/width;
				if(smallthreadsetting[0])
					for(int i=0;i<tempMap.V_guPolygon.size();i++)  //画多边形
					{			
						guPolygon tempPolygon=(guPolygon)tempMap.V_guPolygon.elementAt(i);
						entityType tempType=new entityType();
						for(int j=0;j<tempMap.V_entityType.size();j++)
						{
							tempType=(entityType)tempMap.V_entityType.elementAt(j);
							if(tempType.m_name.equals(tempPolygon.m_name))
							{
								g.setColor(new Color(tempType.m_geometryDisplay.color));
								break;
							}
						}
						for(int j=0;j<tempPolygon.V_guRing.size();j++)
						{
							Polygon temp=new Polygon();
							guRing tempRing=(guRing)tempPolygon.V_guRing.elementAt(j);	
							for(int k=0;k<tempRing.V_coordinate.size();k++)
							{
								coordinate tempCoordinate=(coordinate)tempRing.V_coordinate.elementAt(k);
								temp.addPoint((int)(tempCoordinate.X/scale),(int)((tempMap.m_upLeft.Y-tempCoordinate.Y)/scale));
							}
							g.fillPolygon(temp);
						}
				
					}//画多边形结束	
				
				if(smallthreadsetting[1])
					for(int i=0;i<tempMap.V_guLine.size();i++)   //画线
					{
						guLine tempLine=(guLine)tempMap.V_guLine.elementAt(i);
						entityType tempType=new entityType();
						for(int j=0;j<tempMap.V_entityType.size();j++)
						{
							tempType=(entityType)tempMap.V_entityType.elementAt(j);
							if(tempType.m_name.equals(tempLine.m_name))
							{
								g.setColor(new Color(tempType.m_geometryDisplay.color));
								break;
							}
						}
						coordinate from=(coordinate)tempLine.V_coordinate.elementAt(0);
						coordinate to=new coordinate();
						for(int j=1;j<tempLine.V_coordinate.size();j++)
						{
							to=(coordinate)tempLine.V_coordinate.elementAt(j);
							g.drawLine((int)(from.X/scale),(int)((tempMap.m_upLeft.Y-from.Y)/scale),(int)(to.X/scale),(int)((tempMap.m_upLeft.Y-to.Y)/scale));
							from=to;
						}
					}//画线结束
					
				if(smallthreadsetting[2])
					for(int i=0;i<tempMap.V_guNode.size();i++) //画点
					{	
						guNode tempNode=(guNode)tempMap.V_guNode.elementAt(i);
							
						int radii = 1;//(int)(m_radii*width/1000);  //点的半径
							
						entityType tempType=new entityType();
						for(int j=0;j<tempMap.V_entityType.size();j++)
						{
							tempType=(entityType)tempMap.V_entityType.elementAt(j);
							if(tempType.m_name.equals(tempNode.m_name))
							{
								g.setColor(new Color(tempType.m_geometryDisplay.color));
								break;
							}
						}
						g.fillRoundRect((int)(tempNode.m_coordinate.X/scale-radii),(int)((tempMap.m_upLeft.Y-tempNode.m_coordinate.Y)/scale-radii),radii+radii,radii+radii,radii,radii);
					}//画点结束
					
			}
			
			g.dispose();
			infoPanel.setImage((Image)tempimg);
			infoPanel.updateUI();
		}
	}
}

⌨️ 快捷键说明

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