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

📄 mainpane.java

📁 时空图计算和编辑程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			this.ShowMsgPane("已经转至可写模式,您现在可以对工作画面进行编辑了.",true);
			if(detailloc==null)return;
			Square square[]=myGrid.getAllIns();
			for(int i=0;i<square.length;i++)
			{
				square[i].setLocation(detailloc[i]);
			}
			detailloc=null;
			repaint();
			return;
		}
		String cmd=e.getActionCommand().trim();
		MenuBarEvent(cmd);
		MenuEvent(cmd);
		FunEvent(cmd);
	}
	/*
	 * 功能事件
	 * */
	public void FunEvent(String str)
	{//功能事件
		//FUNSTR={"优化图像","时空图计算","保存计算结果","去除指令间隙","添加至记录","察看优化方案"}; ;
		if(str.equals(FUNSTR[0]))
		{//优化图像
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("您的工作画面内还没有有效的元素,请编辑后再进行优化.",true);
				return;
			}
			if(!isEditable)
			{
				this.ShowMsgPane("为了您的工作文件安全,目前不可进行图像优化,请转至可写状态",true);
				return;
			}
			detailloc=myGrid.DivisionDetail();
			repaint();
			SetEditable(false);
			return;
		}
		if(str.equals(FUNSTR[1]))
		{//时空图计算
			String result=myGrid.outputResult();
			if(result==null)
			{
				this.ShowMsgPane("不能产生有效的计算结果,请检查您的工作图像是否有元素.",true);
				return;
			}
			this.ShowResaultPane(result,true);
			return;
		}
		if(str.equals(FUNSTR[2]))
		{//保存结果
			SaveReport();
			return;
		}
		if(str.equals(FUNSTR[3]))
		{//去除间隙
			myGrid.NoDivision();
			repaint(0,0,getWidth(),getHeight());
			return;
		}
		if(str.equals(FUNSTR[4]))
		{//添加记录
			if(!isEditable)
			{
				this.ShowMsgPane("为了您的工作文件安全,目前不可进行记录保存,请转至可写状态",true);
				return;
			}
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("当前画面没有可储存的元素,请编辑后再进行保存记录",true);
				return;
			}
			if(rcdpane.addRecord(myGrid.output()))
				this.ShowMsgPane("当前记录已被添加至历史记录",true);
			else
				this.ShowMsgPane("当前记录与已有记录重复,添加记录失败",true);
			return;
		}
		if(str.equals(FUNSTR[5]))
		{//察看优化方案
			ShowImage(myGrid.outputDivSample());
			return;
		}
		if(str.equals(FUNSTR[6])){
		//建立计算
			if(myGrid.size()!=0)
			{
				condlg.ShowDialog("当前工作画面还未保存,建立计算?");
				if(!condlg.isConfirm())return;
			}
			taskdlg.setVisible(true);
			int amount=taskdlg.getAmount(),
				time=taskdlg.getTime(),
				evenum=taskdlg.getEveNum();
			if(amount<0)
			{
				this.ShowMsgPane("建立计算失败,请检查您输入的初始数据是否合法,例如:周期小于最小周期.",true);
				return;
			}
			String serial=myGrid.CreatCauculator(amount,time,evenum);
			if(serial==null)
			{
				this.ShowMsgPane("建立计算失败,请检查您输入的初始数据是否合法,例如:周期小于最小周期.",true);
				return;
			}
			this.StartupNew(serial);
			this.ShowResaultPane(myGrid.outputResult(),true);
			this.ShowMsgPane("计算任务已完成,请检查结果输出面板核对您的计算任务是否正确.",true);
			return;
		}
	}
	/*
	 * 菜单条事件
	 * */
	public void MenuBarEvent(String str)
	{//按钮事件
		//BTNSTR={"新建文件","保存文件","打开文件","导出图像","导出优化图像","批量导出数据"}
		if(!isEditable)
		{
			this.ShowMsgPane("为了您的工作文件安全,菜单栏当前不可操作,请转至可写状态",true);
			return;
		}
		if(str.equals(BTNSTR[0]))
		{//新建文件
			CreateNewImage();
			return;
		}
		if(str.equals(BTNSTR[1]))
		{//保存
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("您的工作画面内还没有有效的元素,请编辑后再保存.",true);
				return;
			}
			SaveRecord();
			return;
		}
		if(str.equals(BTNSTR[2]))
		{//打开		
			LoadRecord();
			repaint();
			return;
		}
		if(str.equals(BTNSTR[3]))
		{//导出图像
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("您的工作画面内还没有有效的元素,请编辑后再导出图像.",true);
				return;
			}
			SaveImage(myGrid.outputReportImage());
			return;
		}
		if(str.equals(BTNSTR[4]))
		{//导出细化
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("您的工作画面内还没有有效的元素,请编辑后再导出细化.",true);
				return;
			}
			SaveImage(myGrid.outputReportImage2());
			repaint();
			return;
		}
		if(str.equals(BTNSTR[5]))
		{//批量导出数据
			if(!isEditable)
			{
				this.ShowMsgPane("当前状态不可导出数据,轻转至可写状态",true);
				return;
			}
			if(myGrid.size()==0)
			{
				this.ShowMsgPane("您的工作画面内还没有有效的元素,请编辑后再保存.",true);
				return;
			}
			ExportAll();	
			return;
		}
	}
	public Point detailloc[];//细化前位置
	/*
	 * 菜单事件
	 * */
	public int colormode=0;
	public static final int FORECOLOR=1;
	public static final int BACKCOLOR=2;
	public void MenuEvent(String str)
	{//菜单事件
		//ITEMSTR={"创建指令","创建N个指令","删除","背景颜色","前景颜色","显示输出面板","显示颜色面板","显示记录面板"};//item文字

		if(str.equals(ITEMSTR[0]))
		{//创建
			int num=myGrid.CreateIns(1,clickpnt.x-picX,clickpnt.y);
			if(num==0)
				this.ShowMsgPane("当前位置创建指令失败,请检查该位置对于创建指令任务的有效性.",true);
			repaint(0,0,getWidth(),getHeight());
		}
		if(str.equals(ITEMSTR[1]))
		{//创建
			int gx=(clickpnt.x-picX-Global.START_X)/Global.LENGTH,gy=(ZeroY-clickpnt.y)/Global.LENGTH;
			talker.setTitle("在网格("+gx+","+gy+")处创建指令");
			talker.setContent("1");
			talker.setVisible(true);
			String txt=talker.getContent();
			int number=0;
			if(txt!=null)
			{
				try{
					number=Integer.parseInt(txt.trim());
				}catch(Exception e){
					this.ShowMsgPane("创建过程在输入处失败,请检查输入数字的有效性.",true);
					return;
				}
			}else
			{
				this.ShowMsgPane("创建数字不能为空,请您检查输入数据的有效性",true);
				return;
			}
			int num=myGrid.CreateIns(number,clickpnt.x-picX,clickpnt.y);
			double rate=(double)((int)((double)num*1000/number))/1000;
			this.ShowMsgPane("预计创建"+number+"个指令,实际创建"+num+"个,创建成功率:"+rate,true);
			repaint(0,0,getWidth(),getHeight());
			return;
		}
		if(str.equals(ITEMSTR[2]))
		{//删除
			if(pickins!=null && pickins.length!=0)
			{//捡拾者如果不为0则
				for(int i=0;i<pickins.length;i++)
					myGrid.removeIns(pickins[i]);
				pickins=null;
			}
			if(actins!=null)
			{//如果活跃
				myGrid.removeIns(actins);
				actins=null;
			}
			this.ShowMsgPane("所选择的指令已删除",true);
			repaint();
			return;
		}
		/*if(str.equals(ITEMSTR[3]))
		{//属性
			if(actins!=null)
			{//如果活跃
				ShowParaPane(actins,true);
			}		
			//this.ShowMsgPane("所选择的指令已删除",true);
			//repaint();
			return;
		}*/
		if(str.equals(ITEMSTR[3]))
		{//显示背景颜色
			ShowColorPane(true);
			colormode=BACKCOLOR;
			if(pickins!=null && pickins.length!=0)
			{//捡拾者如果不为0则
				colorpane.forecolor=pickins[0].backcolor;
				colorpane.setColor(pickins[0].backcolor);
			}
			if(actins!=null)
			{//如果活跃
				colorpane.forecolor=actins.backcolor;
				colorpane.setColor(actins.backcolor);
			}
			return;
		}
		if(str.equals(ITEMSTR[4]))
		{//显示前景颜色
			ShowColorPane(true);
			colormode=FORECOLOR;
			if(pickins!=null && pickins.length!=0)
			{//捡拾者如果不为0则
				colorpane.forecolor=pickins[0].forecolor;
				colorpane.setColor(pickins[0].forecolor);
			}
			if(actins!=null)
			{//如果活跃
				colorpane.forecolor=actins.forecolor;
				colorpane.setColor(actins.forecolor);
			}
			return;
		}
	/*	if(str.equals(ITEMSTR[6]))
		{//显示消息面板
			this.ShowMsgPane(null,true);
			//this.ShowColorPane(true);
			//this.ShowResaultPane(null,true);
			return;
		}*/
		if(str.equals(ITEMSTR[5]))
		{//显示输出面板
			this.ShowResaultPane(null,true);
			//this.ShowColorPane(true);
			//this.ShowResaultPane(null,true);
			return;
		}
		if(str.equals(ITEMSTR[6]))
		{//显示颜色面板
			this.ShowColorPane(true);
			//this.ShowColorPane(true);
			//this.ShowResaultPane(null,true);
			return;
		}
		if(str.equals(ITEMSTR[7]))
		{//显示记录面板
			this.ShowRecordPane(true);
			return;
		}
	}
	
	/*
	 * 鼠标处理区
	 * */
	private Point mousepnt=new Point();//鼠标事件记录点
	private Point curpnt=new Point();//当前点
	private Dimension divsize=new Dimension();//差距尺寸
	private Point foreloc=new Point();//前标签位置
	private Point clickpnt=new Point();//右键点击位置
	public void MouseClicked(MouseEvent e)
	{//鼠标单击
		//colorpane.setColor(new Color(offimage.getRGB(e.getX()-picX,e.getY())));
		Square stmp=myGrid.getIns(e.getX(),e.getY());
		switch(e.getButton())
		{
		case MouseEvent.BUTTON1:
			pickins=null;
			MarkIns(stmp,true);
			repaint(0,0,getWidth(),getHeight());
			break;
		case MouseEvent.BUTTON3:
			clickpnt.setLocation(e.getX(),e.getY());
			//检查弹出menu
			MenuItemCheck(e.getX()-picX,e.getY());
			menu.show(this,e.getX(),e.getY());
			break;
		}		
	}
	public void MenuItemCheck(int x,int y)
	{//检查Item弹出
//		ITEMSTR={"创建","删除","属性","背景颜色","前景颜色"};
		Square stmp=myGrid.getIns(x,y);
		//检查是否有
		if(stmp!=null){
			item[0].setEnabled(false);
			item[1].setEnabled(false);
			item[2].setEnabled(isEditable);
			item[3].setEnabled(true);
			item[4].setEnabled(true);
			//item[5].setEnabled(true);
			actins=stmp;
		}
		else
		{
			actins=null;
			item[0].setEnabled(isEditable);
			item[1].setEnabled(isEditable);
			item[2].setEnabled(false);
			item[3].setEnabled(false);
			item[4].setEnabled(false);
			//item[5].setEnabled(false);
		}
	}
	public void MousePressed(MouseEvent e)
	{//鼠标按下
		if(e.getButton()!=MouseEvent.BUTTON1)return;
		actins=myGrid.getIns(e.getX()-picX,e.getY());
		mousepnt.setLocation(e.getX()-picX,e.getY());
		curpnt.setLocation(mousepnt);
		if(actins==null)picked=true;
		else
		{
			MarkIns(actins,true);
			foreloc.setLocation(actins.getLocation());
			divsize.setSize(mousepnt.x-actins.getX(),mousepnt.y-actins.getY());
		}
		repaint(0,0,getWidth(),getHeight());
	}
	public void MouseReleased(MouseEvent e)
	{//鼠标释放
		if(e.getButton()!=MouseEvent.BUTTON1)return;
		//如果为捡取程序
		if(picked)
		{//检查
			pickins=myGrid.getIns(new Rectangle(mousepnt.x,mousepnt.y,curpnt.x-mousepnt.x,curpnt.y-mousepnt.y));
			if(pickins!=null)
			{
				for(int i=0;i<pickins.length;i++)
					pickins[i].selected=true;
				picked=false;
			}
		}else if(actins!=null)
		{//如果有活动标签
			//定位当前标签
			//Point stmp=myGrid.getGrid(actins.getLocation());
			//Point gtmp=myGrid.getGrid(e.getX()-picX,e.getY());
			//int gx=gtmp.x-(ZeroY/Global.LENGTH-gtmp.y)%4+1,

⌨️ 快捷键说明

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