📄 textshell.java
字号:
package org.goshawk.workflow.GUI.ShapeShell;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.TextField;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.util.Map;
import org.goshawk.workflow.DoMain.WorkFlowEntity;
import org.goshawk.workflow.GUI.Action.TextShellAction;
import org.goshawk.workflow.GUI.Display.EditorFrame;
public class TextShell extends ContentShapeShell
{
private int height = 20;
private int width = 90;
private Rectangle rect = null;
private String content = null;
private WorkFlowEntity workStep = new WorkFlowEntity();
public TextShell()
{
rect = new Rectangle(30,30,width,height);
}
public TextShell(Rectangle rect,String content)
{
this.rect = rect;
height = rect.height;
width = rect.width;
this.content = content;
}
public TextShell(int x, int y, int width, int height,String content)
{
rect = new Rectangle(x,y,width,height);
this.height = height;
this.width = width;
this.content = content;
//editShape();
}
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);
}
public int getY()
{
return (int)rect.y;
}
public void setY(int y)
{
rect.setFrame(rect.x,(double)y,rect.width,rect.height);
}
public int getCenterX()
{
return (int)rect.getCenterX();
}
public int getCenterY()
{
return (int)rect.getCenterY();
}
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
Font font = Font.decode(content);
FontRenderContext render = new FontRenderContext(new AffineTransform(),false,false );
Rectangle2D stringRect = font.getStringBounds(content,render);
g2.drawString(content,(float) (this.getX()+(this.getWidth()-stringRect.getWidth())/2),(float) (this.getY()+stringRect.getHeight()));
g2.draw(rect);
//editShape();
}
public PopupMenu getPopupMenu()
{
return null;
}
public void setPopupMenu(PopupMenu menu)
{
System.out.println("这个方法是无效的");
}
public boolean contains(int x, int y)
{
return this.rect.contains(x,y);
}
public Object clone()
{
return new RectangleShell(rect.x,rect.y,rect.width,rect.height);
}
public WorkFlowEntity getWorkStep()
{
return workStep;
}
public void setWorkStep(WorkFlowEntity workStep)
{
this.workStep = workStep;
}
public void editShape(int mousex,int mousey)
{
if(rect.contains(mousex,mousey))
{
TextField text = new TextField(content);
text.addFocusListener(new TextShellAction(this));
EditorFrame.getCanvas().removeAll();
EditorFrame.getCanvas().add(text);
EditorFrame.getInstance().show();
text.setBounds(rect.x+1,rect.y+1,rect.width-2,rect.height-2);
}
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content = content;
}
public void addOtherShape(ShapeShell shape)
{
}
public Map getOtherShapes()
{
return null;
}
public Map setOtherShapes(Map shapes)
{
return null;
}
public ShapeShell getOtherShape(String id)
{
return null;
}
public ShapeShell removeOtherShape(String id)
{
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -