📄 workflowshell.java
字号:
package org.goshawk.workflow.GUI.ShapeShell;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.goshawk.workflow.DoMain.WorkFlowEntity;
import org.goshawk.workflow.GUI.Action.CopyAndPasteShapeShellAction;
import org.goshawk.workflow.GUI.Action.CopyShapeShellAction;
import org.goshawk.workflow.GUI.Action.DeleteShapeShellAction;
import org.goshawk.workflow.GUI.Display.EditorCanvas;
import org.goshawk.workflow.GUI.Display.EditorFrame;
import org.goshawk.workflow.GUI.Display.ShapeMap;
public class WorkFlowShell extends ShapeShell
{
private int height = 60;
private int width = 90;
private Rectangle rect = null;
private PopupMenu popupMenu = null;
private WorkFlowEntity workStep = new WorkFlowEntity();
private TextShell rectHigher = null;
private TextShell rectMiddle = null;
private TextShell rectLower = null;
private Map otherShapes = new HashMap();
private EditorCanvas canvas = EditorFrame.getCanvas();
private ShapeMap shapeMap = canvas.getShapeMap();
public WorkFlowShell()
{
rect = new Rectangle(30,30,width,height);
rectHigher = new TextShell(rect.x,rect.y,width,height/3,"这是一个测试");
rectMiddle = new TextShell(rect.x,rect.y+height/3,width,height/3,"");
rectLower = new TextShell(rect.x,rect.y+(height/3)*2,width,height/3,"");
}
public WorkFlowShell(Rectangle rect)
{
this.rect = rect;
height = rect.height;
width = rect.width;
rectHigher = new TextShell(rect.x,rect.y,width,height/3,"这是一个测试");
rectMiddle = new TextShell(rect.x,rect.y+height/3,width,height/3,"");
rectLower = new TextShell(rect.x,rect.y+(height/3)*2,width,height/3,"");
}
public WorkFlowShell(int x, int y, int width, int height)
{
rect = new Rectangle(x,y,width,height);
rectHigher = new TextShell(rect.x,rect.y,width,height/3,"这是一个测试");
rectMiddle = new TextShell(rect.x,rect.y+height/3,width,height/3,"");
rectLower = new TextShell(rect.x,rect.y+(height/3)*2,width,height/3,"");
}
public Rectangle getRect()
{
return rect;
}
public void setRect(Rectangle rect)
{
this.rect = rect;
}
public Shape getShape()
{
return rect;
}
public void setShape(Shape shape) throws ShapeShellException
{
if(shape==null)
{
this.rect = null;
return ;
}
if(!(shape instanceof Rectangle))
throw new ShapeShellException("输入参数类型必须是java.awt.Rectangle");
this.rect = (Rectangle)shape;
}
public int getHeight()
{
return (int)rect.getHeight();
}
public void setHeight(int height)
{
rect.setFrame(rect.x,rect.y,rect.width,(double)height);
}
public int getWidth()
{
return (int)rect.getWidth();
}
public void setWidth(int width)
{
rect.setFrame(rect.x,rect.y,(double)width,rect.height);
}
public int getX()
{
return (int)rect.x;
}
public void setX(int x)
{
rect.setFrame((double)x,rect.y,rect.width,rect.height);
rectHigher.setX(x);
rectMiddle.setX(x);
rectLower.setX(x);
}
public int getY()
{
return (int)rect.y;
}
public void setY(int y)
{
rect.setFrame(rect.x,(double)y,rect.width,rect.height);
rectHigher.setY(y);
rectMiddle.setY(y+rect.height/3);
rectLower.setY(y+(rect.height/3)*2);
}
public int getCenterX()
{
return (int)rect.getCenterX();
}
public int getCenterY()
{
return (int)rect.getCenterY();
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
if(isSelected)
{
g2.setColor(selectedColor);
g2.draw(new Rectangle(rect.x-3,rect.y-3,rect.width+6,rect.height+6));
}
g2.setColor(unselectColor);
g2.draw(rect);
Collection shapes = otherShapes.values();
if(shapes!=null&&shapes.size()>0)
{
Iterator iter = shapes.iterator();
while(iter.hasNext())
{
ShapeShell shapex = (ShapeShell)iter.next();
ArrowShell arrow = (ArrowShell)shapeMap.get(this.getId()+shapex.getId());
if(arrow!=null)
{
arrow.setStartNode(this);
arrow.setEndNode(shapex);
}
shapeMap.put(this.getId()+shapex.getId(),arrow);
}
}
rectHigher.paint(g2);
rectMiddle.paint(g2);
rectLower.paint(g2);
}
public PopupMenu getPopupMenu()
{
popupMenu = new PopupMenu("1");
MenuItem copyAndPasteItem = new MenuItem("复制并粘贴");
copyAndPasteItem.addActionListener(new CopyAndPasteShapeShellAction());
popupMenu.add(copyAndPasteItem);
MenuItem copyItem = new MenuItem("复制");
copyItem.addActionListener(new CopyShapeShellAction());
popupMenu.add(copyItem);
MenuItem deleteItem = new MenuItem("删除");
if(this.isSelected)
deleteItem.addActionListener(new DeleteShapeShellAction());
else
deleteItem.addActionListener(new DeleteShapeShellAction(this));
popupMenu.add(deleteItem);
return popupMenu;
}
public void setPopupMenu(PopupMenu menu)
{
this.popupMenu = menu;
}
public boolean contains(int x, int y)
{
return this.rect.contains(x,y);
}
public Object clone()
{
WorkFlowShell copy= new WorkFlowShell(rect.x,rect.y,rect.width,rect.height);
copy.getRectHigher().setContent(rectHigher.getContent());
copy.getRectMiddle().setContent(rectMiddle.getContent());
copy.getRectLower().setContent(rectLower.getContent());
return copy;
}
public WorkFlowEntity getWorkStep()
{
return workStep;
}
public void setWorkStep(WorkFlowEntity workStep)
{
this.workStep = workStep;
}
public void editShape(int mousex,int mousey)
{
rectHigher.editShape( mousex, mousey);
rectMiddle.editShape( mousex, mousey);
rectLower.editShape( mousex, mousey);
}
public void addOtherShape(ShapeShell shape)
{
otherShapes.put(shape.getId(),shape);
ArrowShell arrow = new ArrowShell(this,shape);
arrow.setId(this.getId()+shape.getId());
shapeMap.put(arrow.getId(),arrow);
}
public Map getOtherShapes()
{
return otherShapes;
}
public Map setOtherShapes(Map shapes)
{
return otherShapes = shapes;
}
public ShapeShell getOtherShape(String id)
{
return (ShapeShell)otherShapes.get(id);
}
public ShapeShell removeOtherShape(String id)
{
return (ShapeShell)otherShapes.remove(id);
}
public TextShell getRectHigher()
{
return rectHigher;
}
public void setRectHigher(TextShell rectHigher)
{
this.rectHigher = rectHigher;
}
public TextShell getRectLower()
{
return rectLower;
}
public void setRectLower(TextShell rectLower)
{
this.rectLower = rectLower;
}
public TextShell getRectMiddle()
{
return rectMiddle;
}
public void setRectMiddle(TextShell rectMiddle)
{
this.rectMiddle = rectMiddle;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -