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

📄 shapemapexecutor.java

📁 一个可视化编辑器的基础结构
💻 JAVA
字号:
package org.goshawk.workflow.GUI.Display;

import java.util.Collection;
import java.util.Iterator;

import org.goshawk.workflow.GUI.MouseCommand.MouseCommand;
import org.goshawk.workflow.GUI.ShapeShell.RectangleShell;
import org.goshawk.workflow.GUI.ShapeShell.ShapeShell;

public class ShapeMapExecutor
{
	ShapeMap shapeMap = null;
	public ShapeMapExecutor(ShapeMap shapeMap)
	{
		this.shapeMap = shapeMap;
	}
	
	public void selectCheckWithMouse(int mousex,int mousey)
	{
		shapeMap = EditorFrame.getCanvas().getShapeMap();
		int count = 0;
		Collection shapeSet = shapeMap.values();
		Iterator iter = shapeSet.iterator();
		while(iter.hasNext())
		{
			ShapeShell shape = (ShapeShell)iter.next();
			if(shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable()&&shape.isFirst())
			{
				shape.setSelected(shape.contains(mousex,mousey));
				if(shape.contains(mousex,mousey))
				{
					count++;
				}
			}
			
		}
		shapeMap.setSelected(count>0);
		shapeMap.setMultiSelected(count>1);
	}
	
	public void refresh()
	{
		shapeMap = EditorFrame.getCanvas().getShapeMap();
		int count = 0;
		Collection shapeSet = shapeMap.values();
		Iterator iter = shapeSet.iterator();
		while(iter.hasNext())
		{
			ShapeShell shape = (ShapeShell)iter.next();
			if(shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable()&&shape.isFirst())
			{
				if(shape.isSelected())
				{
					count++;
				}
			}
			
		}
		shapeMap.setSelected(count>0);
		shapeMap.setMultiSelected(count>1);
	}
	
	public void selectCheckWithCutRect(int x,int y,int endx,int endy)
	{
		shapeMap = EditorFrame.getCanvas().getShapeMap();
		RectangleShell rectArea = (RectangleShell)shapeMap.get(MouseCommand.RECT_AREA);
		if(rectArea!=null)
		{
			int count = 0;
			Collection shapeSet = shapeMap.values();
			Iterator iter = shapeSet.iterator();
			while(iter.hasNext())
			{
				ShapeShell shape = (ShapeShell)iter.next();
				if(shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable())
				{
					int centerX = shape.getCenterX();
					int centerY = shape.getCenterY();
					shape.setSelected((x<centerX && endx>centerX)&&(y<centerY && endy>centerY));
					count++;
				}
			}
			shapeMap.setSelected(count>0);
			shapeMap.setMultiSelected(count>1);
		}
	}
	
	/**
	 * 该函数判断鼠标是否在某个图形上
	 * forSelected :ture只判断被选择图形;false:判断所有图形
	 *  **/
	public boolean isMouseInShapes(int mousex,int mousey,boolean forSelected)
	{
		shapeMap = EditorFrame.getCanvas().getShapeMap();
		Collection shapeSet = shapeMap.values();
		Iterator iter = shapeSet.iterator();
		boolean isInSelectedShapes = false;
		while(iter.hasNext())
		{
			ShapeShell shape = (ShapeShell)iter.next();
			boolean condition = false;
			if(forSelected)
				condition = shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable()&&shape.isSelected();
			else
				condition = shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable();
			if(condition)
			{
				
				isInSelectedShapes = shape.contains(mousex,mousey);
				if(isInSelectedShapes)
					return true;
			}
		}
		return false;
	}
	
	public void moveShape(int movex,int movey)
	{
		Collection shapeSet = shapeMap.values();
		Iterator iter = shapeSet.iterator();
		while(iter.hasNext())
		{
			int windowWidth = EditorFrame.getInstance().getSize().width-25;
			int windowHeight = EditorFrame.getInstance().getSize().height-45;
			ShapeShell shape = (ShapeShell)iter.next();
			if(shape!=null&&shape.isSelected())
			{
				int newx = shape.getX()+movex;
				int newy = shape.getY()+movey;
				if(newx>=0 && newx<=windowWidth)
					shape.setX(newx);
				if(newy>=0 && newy<=windowHeight)
					shape.setY(newy);
			}
		}
	}
	
	public ShapeShell getShapeWithMouse(int mousex,int mousey,boolean forSelected)
	{
		Collection shapeSet = shapeMap.values();
		Iterator iter = shapeSet.iterator();
		boolean isInSelectedShapes = false;
		while(iter.hasNext())
		{
			ShapeShell shape = (ShapeShell)iter.next();
			boolean condition = false;
			if(forSelected)
				condition = shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable()&&shape.isSelected();
			else
				condition = shape!=null&&!shape.getId().equals(MouseCommand.RECT_AREA)&&shape.isSelectable();
			if(condition)
			{

				isInSelectedShapes = shape.contains(mousex,mousey);
				if(isInSelectedShapes)
					return shape;
			}
		}
		return null;
	}

}

⌨️ 快捷键说明

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