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

📄 mainpane.java

📁 时空图计算和编辑程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package my_cpt;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.util.Calendar;

import javax.swing.Timer;
import javax.imageio.ImageIO;

import super_cpt.*;
import data2.*;
public class MainPane extends Panel implements AdjustmentListener,
MouseWheelListener,ActionListener,IActionExcutor{

	/**
	 * 主面板
	 */
	//控件
	protected static final String [] ITEMSTR={"创建指令","创建N个指令","删除","背景颜色","前景颜色","显示输出面板","显示颜色面板","显示记录面板"};//item文字
	//protected static final String [] BTNSTR={"新建文件","保存文件","打开文件","时空图计算","优化图像","导出计算结果","导出图像","导出优化图像","批量导出数据"};//按钮文字
	protected static final String [] BTNSTR={"新建文件","保存文件","打开文件","导出图像","导出优化图像","批量导出数据"};//按钮文字
	protected static final String [] FUNSTR={"优化图像","时空图计算","保存计算结果","去除指令间隙","添加至记录","察看优化方案","建立计算任务"}; 
	protected Scrollbar scroll=new Scrollbar(Scrollbar.HORIZONTAL);//水平滚动条
	protected PopupMenu menu=new PopupMenu();//弹出菜
	protected MenuItem item[]=new MenuItem[ITEMSTR.length];
	//protected SuperPane btnpane=new SuperPane("控制面板");//按钮面板
	protected FileDialog chooser;
	protected TalkDialog talker;
	protected ColorPane colorpane=new ColorPane();//颜色面板
	public MessagePane msgpane=new MessagePane();//消息面板
	//protected ParaPane parapane=new ParaPane();//属性面板
	public Frame father;//爹
	public Timer timer=new Timer(20,this);//计时器
	protected ImageView viewer[]=new ImageView[5];//图像浏览
	protected InitDialog initdlg;
	protected StateBtn editbtn=new StateBtn("切换至可写");
	protected StateBtn readbtn=new StateBtn("切换至只读");
	protected ConsolePane conpane=new ConsolePane();
	protected RecordPane rcdpane;
	protected TaskDialog taskdlg;
	protected ConfirmDialog condlg;
	//数据
	public Grid myGrid;//我的网格
	public Square actins;//活动标签
	public Square []pickins=null;//捡取的标签
	public boolean picked=false;//是否为选择状态
	//图像
	public BufferedImage backimage;
	public BufferedImage offimage;
	public Graphics2D offG;
	private final static Color selecolor=new Color(128,128,128,90);//选中颜色
	private final static Color unablecolor=new Color(128,128,128,40);//不可用情况颜色
	private int picX=0;//图像位置
	private int ZeroY=0;//图像纵坐标
	public	Dimension picSize=new Dimension();//生成图像尺寸
	public boolean isEditable=true;
	public boolean isbool=true;
	public MainPane(Frame f)
	{
		father=f;
		chooser=new FileDialog(f);
		initdlg=new InitDialog(f);
		talker=new TalkDialog(f);
		taskdlg=new TaskDialog(f);
		condlg=new ConfirmDialog(f);
		this.setLayout(null);
		this.addMouseListener(new MouseAdapter(){
			public void mousePressed(MouseEvent e)
			{//鼠标按下
				if(!isEditable)
				{
					//ShowMsgPane("您当前所处的状态不可编辑,请转换至编辑模式",true);
					return;
				}
				MousePressed(e);
			}
			public void mouseReleased(MouseEvent e)
			{
				if(!isEditable)
				{
					//ShowMsgPane("您当前所处的状态不可编辑,请转换至编辑模式",true);
					return;
				}
				MouseReleased(e);
			}
			public void mouseClicked(MouseEvent e)
			{
				if(!isEditable && e.getButton()==MouseEvent.BUTTON1)
				{
					ShowMsgPane("您当前所处的状态不可编辑,请转换至编辑模式",true);
					return;
				}
				MouseClicked(e);
			}
		});
		this.addMouseMotionListener(new MouseMotionAdapter(){
			
			public void mouseDragged(MouseEvent e)
			{
				if(!isEditable)
				{
					//ShowMsgPane("您当前所处的状态不可编辑,请转换至编辑模式",true);
					return;
				}
				MouseDragged(e);
			}
		});
		this.addMouseWheelListener(this);
		//加载控件
		init();
		//this.CreateNewImage();
	}
	public void init()
	{//初始化控件
		rcdpane=new RecordPane(father);
		add(colorpane);
		//add(parapane);
		add(rcdpane);
		add(conpane);
		add(scroll);
		add(menu);
		add(editbtn);
		add(readbtn);
		scroll.addAdjustmentListener(this);
		//初始化Menu
		for(int i=0;i<ITEMSTR.length;i++)
		{
			item[i]=new MenuItem(ITEMSTR[i]);
			item[i].addActionListener(this);
			menu.add(item[i]);
			if(i==item.length-4)
				menu.addSeparator();
		}
		
		//menubtn
		SuperBtn btn;
		int x=1;
		for(int i=0;i<BTNSTR.length;i++)
		{
			btn=new SuperBtn(BTNSTR[i]);
			btn.setBounds(x,3,BTNSTR[i].length()*16,16);
			x=btn.getX()+btn.getWidth();
			btn.addActionListener(this);
			add(btn);
		}
		//funbtn
		//readbtn.setBounds(Global.START_X+1,Global.LENGTH*2,82,20);
		//editbtn.setBounds(Global.START_X+1,readbtn.getY()+readbtn.getHeight()+5,82,20);
		int fy=0,fw=100;
		readbtn.setBounds(Global.START_X+1,Global.LENGTH*2,fw,20);
		editbtn.setBounds(Global.START_X+1,readbtn.getY()+readbtn.getHeight()+5,fw,20);
		for(int i=0;i<FUNSTR.length;i++)
		{
			StateBtn btmp=new StateBtn(FUNSTR[i]);
			//btmp.setBounds(Global.START_X+1,editbtn.getY()+editbtn.getHeight()+5+25*i,FUNSTR[i].length()*14+13,20);
			btmp.setBounds(Global.START_X+1,editbtn.getY()+editbtn.getHeight()+5+25*i,fw,20);
			btmp.addActionListener(this);
			add(btmp);
			fy=btmp.getY()+btmp.getHeight()+5;
		}		
		//colorpane
		colorpane.setExecutor(this);
		//viewer
		for(int i=0;i<viewer.length;i++)
		{
			viewer[i]=new ImageView(ImageView.UNVISIBLE);
		}
		//编辑按钮
		readbtn.addActionListener(this);
		editbtn.addActionListener(this);
		SetEditable(true);
		//conpane
		conpane.setExecutor(this);
		//rcdpane
		rcdpane.setExecutor(this);
	}
	public int [] style={1,1,1,1};
	public void StartupNew(int width,int s[])
	{//开始新的绘制
		if(width<getWidth())
			width=getWidth();
		picSize.setSize(width,getHeight());
		//刷新大小
		//风格
		style=s;
		//清除grid
		myGrid=null;
		//重绘界面
		offimage=null;
		backimage=null;
		repaint();
		//激活编辑
		SetEditable(true);
		detailloc=null;
		//清空
		if(msgpane!=null)
			msgpane.Clear();
		conpane.clear();
		rcdpane.Clear();
		repaint();
		
	}
	public void StartupNew(String serialstr)
	{//通过序列化字符串开始新的图像
		myGrid.input(serialstr);
		int width=myGrid.size.width,height=myGrid.size.height+Global.LENGTH*2;
		if(width<getWidth())
			width=getWidth();
		//if(height<getHeight());
		picSize.setSize(width,height);
		//重绘界面
		offimage=null;
		backimage=null;
		repaint();
		//激活编辑
		SetEditable(true);
		detailloc=null;
		//清空
		if(msgpane!=null)
			msgpane.Clear();
		conpane.clear();
		rcdpane.Clear();
		repaint();
	}
	
	/**
	 * 动画显示区
	 * */
	public Component actcmp=null;//活动组件
	public int direction;
	public boolean isOpen=true;
	public void Confirm(Component cmp,String str)
	{//加载记录
		if(cmp==rcdpane)
		{//如果是记录面板
			//StartupNew(str);
			myGrid.input(str);
			repaint();
			this.ShowMsgPane("新的记录已经加载,请检验记录是否符合您的要求",true);
		}
	}
	public void Confirm(Component cmp,int dir,boolean bool)
	{//确认并开始动画效果
		if(cmp==colorpane)
		{//颜色面板
			if(pickins!=null && pickins.length!=0)
			{//捡拾者如果不为0则
				for(int i=0;i<pickins.length;i++)
				{
					if(colormode==BACKCOLOR)
						pickins[i].backcolor=colorpane.getColor();
					else
						pickins[i].forecolor=colorpane.getColor();
				}
				pickins=null;
			}
			if(actins!=null)
			{//如果活跃
				if(colormode==BACKCOLOR)
					actins.backcolor=colorpane.getColor();
				else
					actins.forecolor=colorpane.getColor();
				actins=null;
			}
			repaint();
			ShowColorPane(bool);
		}
		if(cmp==msgpane)
		{//消息面板
			ShowMsgPane(null,false);
		}
		/*if(cmp==parapane)
		{//消息面板
			ShowParaPane(null,false);
		}*/
		if(cmp==conpane)
		{//输出面板
			//System.out.println("herhe");
			ShowResaultPane(null,false);
		}
		if(cmp==rcdpane)
		{//记录面板
			ShowRecordPane(false);
		}
	}
	public void Animation(Component cmp,int dir,boolean isopen)
	{//动画过程
		int div=(isopen)?20:-20,x=cmp.getX(),y=cmp.getY();
		boolean isgo=true;//是否继续
		switch(dir)
		{
		case SuperPane.BUTTOM:
			y=y-div;
			if(y<getHeight()-cmp.getHeight())
			{
				y=getHeight()-cmp.getHeight();
				isgo=false;	
			}
			if(y>getHeight())
			{
				y=getHeight();
				isgo=false;
			}
			break;
		case SuperPane.TOP:
			y=y+div;
			if(y>0)
			{
				y=0;
				isgo=false;	
			}
			if(y<-cmp.getHeight())
			{
				y=-cmp.getHeight();
				isgo=false;
			}
			break;
		case SuperPane.LEFT:
			x=x+div;
			if(x>0)
			{
				x=0;
				isgo=false;	
			}
			if(x<-cmp.getWidth())
			{
				x=-cmp.getWidth();
				isgo=false;	
			}
			break;
		case SuperPane.RIGHT:
			x=x-div;
			if(x<getWidth()-cmp.getWidth())
			{
				x=getWidth()-cmp.getWidth();
				isgo=false;	
			}
			if(x>getWidth())
			{
				x=getWidth();
				isgo=false;
			}
			break;
		}
		cmp.setLocation(x,y);
		if(!isgo)timer.stop();
	}
	public void ShowAnimation(Component cmp,int dir,boolean isopen)
	{//显示动画
		actcmp=cmp;
		direction=dir;
		isOpen=isopen;
		timer.start();
	}
	public void ShowColorPane(boolean isopen)
	{//显示颜色面板
		ShowAnimation(colorpane,colorpane.HidenSide,isopen);
	}
	public void ShowMsgPane(String msg,boolean isopen)
	{//显示消息面板
		if(msg!=null)
			msgpane.ShowMessage(msg);
		//ShowAnimation(msgpane,IActionExcutor.LEFT,isopen);
	}
	public void ShowResaultPane(String text,boolean isopen)
	{//显示结果输出面板
		if(text!=null){
			conpane.showText(text);
		}
		ShowAnimation(conpane,conpane.HidenSide,isopen);
	}
	public void ShowRecordPane(boolean isopen)
	{//显示记录面板
		ShowAnimation(rcdpane,rcdpane.HidenSide,isopen);
	}
	/*****************************/
	//显示初始化面板
	
	/*****************************/
	/**
	 * 事件函数处理区
	 * */
	public void actionPerformed(ActionEvent e)
	{//按钮
		if(e.getSource()==timer)
		{
			Animation(actcmp,direction,isOpen);
			return;
		}
		if(e.getSource()==readbtn)
		{
			SetEditable(false);
			this.ShowMsgPane("已经转至只读模式,请注意不要进行危及您工作画面的操作.",true);
			return;
		}
		if(e.getSource()==editbtn)
		{//转换至只写
			SetEditable(true);

⌨️ 快捷键说明

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