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

📄 square.java

📁 时空图计算和编辑程序
💻 JAVA
字号:
package data2;
import java.awt.*;
import java.util.ArrayList;
import data2.Global;
import java.awt.image.*;
public class Square {

	/**
	 * 新的命令写法
	 */
	public static final String SEPRETOR="/";
	public static final String SEPRETOR2=":";
	//数据
	public int number=0;//指令号码
	public Color backcolor=Color.ORANGE;//背景色
	public Color forecolor=Color.BLACK;//前景色
	public Color selecolor=new Color(0,60,255,60);//选中颜色
	public boolean selected=false;//选中
	//public boolean locked=false;//锁定
	private Point location=new Point();//左上角坐标
	//private Dimension gSize=new Dimension(4,4);//网格尺寸
	//private int[][]grid=new int[gSize.width][gSize.height];//网格
	public static final int S1=0;//第一行指令
	public static final int S2=1;//第二行指令
	public static final int S3=2;//第三行指令
	public static final int S4=3;//第四行指令
	private int  row[]={1,1,1,1};//每行有效晶圆数量
	private MyCell cell0[]=null;
	private MyCell cell1[]=null;
	private MyCell cell2[]=null;
	private MyCell cell3[]=null;
	private ArrayList celllst=new ArrayList();//队列
	public Component container;
	//图像数据
//	/private MyCell[] cell=new MyCell[4];
	private int lastX,lastY;
	private int startX=0;
	public Square(int index)
	{//初始化
		number=index;
		initCell();
		//初始化坐标
		setLocation(Global.START_X,0);
	}
	public Square(int []r)
	{//初始化
		row=r;
		initCell();
		//初始化坐标
		setLocation(Global.START_X,0);
	}
	public Square(String serial)
	{//初始化
		input(serial);
	}
	public void initCell()
	{//初始化cell
		
		cell0=new MyCell[row[0]];
		initCell(cell0,0,3);
		cell1=new MyCell[row[1]];
		initCell(cell1,row[0],2);
		cell2=new MyCell[row[2]];
		initCell(cell2,row[1]+row[0],1);
		cell3=new MyCell[row[3]];
		initCell(cell3,row[2]+row[1]+row[0],0); 
//		清空
		celllst.clear();
		for(int i=0;i<row[0];i++)
			celllst.add(cell0[i]);
		for(int i=0;i<row[1];i++)
			celllst.add(cell1[i]);
		for(int i=0;i<row[2];i++)
			celllst.add(cell2[i]);
		for(int i=0;i<row[3];i++)
			celllst.add(cell3[i]);
	/*	for(int i=0;i<celllst.size();i++)
		{//晶圆移动
			MyCell ctmp=(MyCell)celllst.get(i);
		}*/
	}
	private void initCell(MyCell[] cell,int x,int y)
	{//初始化晶圆
		for(int i=0;i<cell.length;i++){
			cell[i]=new MyCell();
			cell[i].gridloc.setLocation(x+i,y);
		}
	}
	//位置函数
	public void setLocation(int x,int y)
	{//设定位置
		for(int i=0;i<celllst.size();i++)
		{//晶圆移动
			MyCell ctmp=(MyCell)celllst.get(i);
			ctmp.setLocation(x+ctmp.getGridX()*Global.LENGTH,y+ctmp.getGridY()*Global.LENGTH);
		}
		//本身移动
		location.setLocation(x,y);
		startX=(x-Global.START_X)/Global.LENGTH;
		lastX=cell3[row[3]-1].getX()+Global.LENGTH;
		lastY=cell3[row[3]-1].getY();
	}
	public void setLocation(Point p)
	{//设定位置
		setLocation(p.x,p.y);
	}
	public Point getLocation(){return location;}
	public int getX(){return location.x;}
	public int getY(){return location.y;}
	public Point getCenter(){
		int x=location.x+getWidth()/2,
			y=location.y+getHeight()/2;
		return new Point(x,y);
	}
	//网格编辑
	public int getWidth(){
		return (row[0]+row[1]+row[2]+row[3])*Global.LENGTH;}
	public int getHeight(){return 4*Global.LENGTH;}
	public void setGrid(int r,int value)
	{//设定指定位置的网格
		if(r*(4-r)<0)return;
		row[r]=value;
	}
	public int getGrid(int r)
	{//返回指定格的状态
		return row[r];
	}
	public int[] getGrid(){return row;}
	public MyCell[] getMyCell(int row)
	{//返回制定行的晶圆
		switch(row)
		{
		case S1:
			return cell0;
		case S2:
			return cell1;
		case S3:
			return cell2;
		case S4:
			return cell3;
		}
		return null;
	}
	public void setLocation(int index,int x,int y)
	{//根据index设定制定层的
		MyCell cell[]=getMyCell(index);
		if(cell==null)return;
		//设定位置
		for(int i=0;i<cell.length;i++)
			cell[i].setLocation(x+i*Global.LENGTH,y);
	}
	public int getX(int index)
	{//获得某曾指令
		MyCell cell[]=getMyCell(index);
		if(cell==null)return -1;
		return cell[0].getX();
	}
	public int getY(int index)
	{//获得某曾指令
		MyCell cell[]=getMyCell(index);
		if(cell==null)return -1;
		return cell[0].getY();
	}
	public Point[] getAllLoc()
	{//获取全部的点
		Point p[]=new Point[celllst.size()];
		for(int i=0;i<p.length;i++)
		{
			p[i]=new Point(((MyCell)celllst.get(i)).getLocation());
		}
		return p;
	}
	public int getStartX()
	{
		return startX;
	}
	public int getEndX()
	{
		return startX+celllst.size();
	}
	//图形绘制
	public boolean contains(int x,int y)
	{//检查该点是否在区域内
		for(int i=0;i<celllst.size();i++)
		{
			MyCell ctmp=(MyCell)celllst.get(i);
			if(ctmp.contains(x,y))return true;
		}
		return false;
	}
	public Rectangle getBounds()
	{//导出区域
		int minX=cell0[0].getX(),width=celllst.size()*Global.LENGTH,minY=1000,maxY=0,height;
		for(int i=0;i<celllst.size();i++)
		{//计算值
			MyCell cell=(MyCell)celllst.get(i);
			if(cell.getY()<minY)
				minY=cell.getY();
			if(cell.getY()>maxY)
				maxY=cell.getY();
				
		}
		height=maxY-minY+Global.LENGTH;
		return new Rectangle(minX,minY,width,height);
	}
	public void paint(Graphics2D g)
	{//绘制
		//绘制字符
		g.setColor(backcolor);
		g.drawLine(lastX,lastY+Global.LENGTH-1,lastX,lastY-Global.LENGTH);
		g.drawString("t "+(startX+celllst.size()),lastX+2,lastY-Global.LENGTH+14);
/*		if(locked)
			g.drawString("locked",lastX-36,lastY);*/
		for(int i=0;i<celllst.size();i++)
		{//绘制晶圆
			((MyCell)celllst.get(i)).paint(g);
		}
	}
	//输出
	public BufferedImage  getImage()
	{//输出图像
		Rectangle r=getBounds();
		BufferedImage image=new BufferedImage(r.width+1,r.height+1,BufferedImage.TYPE_INT_ARGB_PRE);
		Graphics2D g2=image.createGraphics();
		//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		int x[]=new int[4],y[]=new int[4];
		for(int i=0;i<4;i++){
			x[i]=getX(i)-r.x;
			y[i]=getY(i)-r.y;
		}
		Square stmp=new Square(output());
		stmp.setLocation(0,0);
		for(int i=0;i<4;i++)
		{
			stmp.setLocation(i,x[i],y[i]);
		}
		stmp.paint(g2);
		g2.dispose();
		return image;
	}
	public String output()
	{//序列化输出
		StringBuffer str=new StringBuffer(number+SEPRETOR);
		//位置
		str.append(location.x+SEPRETOR+location.y+SEPRETOR);
		//前景色
		str.append(backcolor.getRGB()+SEPRETOR);
		//背景色
		str.append(forecolor.getRGB()+SEPRETOR);
		//选中
		str.append((selected?1:-1)+SEPRETOR);
		//尺寸row
		for(int i=0;i<row.length;i++)
			str.append(row[i]+SEPRETOR2);
		return str.toString();
	}
	public void input(String str)
	{//序列化输入
		String cmd[]=str.split(SEPRETOR);
		int[] args=new int[cmd.length];
		int [] row2=new int[4];
		try{
			for(int i=0;i<6;i++)
				args[i]=Integer.parseInt(cmd[i]);
			String str2[]=cmd[6].split(SEPRETOR2);
			for(int i=0;i<str2.length;i++)
				row2[i]=Integer.parseInt(str2[i]);
		}catch(Exception e){}
		//数字
		number=args[0];		
		//前景色
		backcolor=new Color(args[3]);
		//背景色
		forecolor=new Color(args[4]);
		//选中
		selected=args[5]>0;
		//尺寸
		for(int i=0;i<4;i++)
		{//初始化元素
			setGrid(i,row2[i]);
		}
		//init
		initCell();
//		位置
		setLocation(args[1],args[2]);
	}
	
	public class MyCell{
		/**
	 	*单元格
	 	*/
		//RoundRectangle2D.Double myShape2=new RoundRectangle2D.Double(0,0,Global.LENGTH,Global.LENGTH,10,10);
		public Rectangle myShape2=new Rectangle(0,0,Global.LENGTH,Global.LENGTH);
		//public Rectangel myShape=new Rectangle(0,0,Global.LENGTH,Global.LENGTH);
		public Point myloc=new Point();
		private Point gridloc=new Point();//网格位置
		public BufferedImage myImage;//我的图像
		public void setLocation(int x,int y)
		{//设定坐标
			myShape2.translate(x-myloc.x,y-myloc.y);
			//myShape2.setRoundRect(x,y,Global.LENGTH,Global.LENGTH,10,10);
			myloc.setLocation(x,y);
			
		}
		public int getX(){return myloc.x;}
		public int getY(){return myloc.y;}
		public Point getLocation(){return  myloc;}
		public int getGridX(){return gridloc.x;}
		public int getGridY(){return gridloc.y;}
		public boolean contains(int x,int y)
		{//检测点是否在晶圆内
			return myShape2.contains(x,y);
		}
		public void initMyImage()
		{//初始化透明蒙板
			myImage=new BufferedImage(Global.LENGTH,Global.LENGTH,BufferedImage.TYPE_4BYTE_ABGR_PRE);
			Graphics2D g=myImage.createGraphics();
			//绘制
			Color color1=new Color(0,0,0,0);
			Color color2=new Color(255,255,255,128);
			GradientPaint p1=new GradientPaint(0,0,color1,Global.LENGTH/2,Global.LENGTH/2,color2,true);
			g.setPaint(p1);
			g.fillRect(0,0,Global.LENGTH,Global.LENGTH);
			g.dispose();
		}
		public void paint(Graphics2D g)
		{//绘制
			g.setColor(backcolor);
			g.fillRoundRect(myloc.x+2,myloc.y+2,Global.LENGTH-3,Global.LENGTH-3,8,8);
			//g.drawRoundRect(myloc.x+2,myloc.y+2,Global.LENGTH-3,Global.LENGTH-3,8,8);
			//绘制玻璃化效果
			if(myImage==null && container!=null)
			{
				initMyImage();
			}
			if(myImage!=null)
				g.drawImage(myImage,myloc.x,myloc.y,container);
			g.setColor(forecolor);
			g.drawString(""+number,myloc.x+Global.LENGTH/2-3,myloc.y+Global.LENGTH/2+6);
			if(selected){
				g.setColor(selecolor);
				g.fill(myShape2);
			}
		}
	}

}

⌨️ 快捷键说明

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