📄 typedrawcontroller.java
字号:
package LYD.Draw;
import java.awt.Graphics;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.awt.Color;
public class TypeDrawController implements ITypeDrawCommand
{
public static int NormalType=0;
public static int DotType=1;
public static int DotDashLine=2;
public static int LineCommand=0;
public static int RectangleCommand=1;
public static int CircleCommand=2;
public static int EllipseCommand=3;
public static int PencilCommand=4;
public static int RubberCommand=5;
protected int currentType=0;
protected boolean bDrawing=false;
protected static Draw rootPane;
protected Line _Line;
protected LYD.Draw.Rectangle _Rectangle;
protected Circle _Circle;
protected Ellipse _Ellipse;
protected Pencil _Pencil;
protected Rubber _Rubber;
protected ITypeDrawCommand currentTypeDraw;
protected static ArrayList altCommand=new ArrayList();
protected static int currentSize=0;
protected static boolean bIsUoing=false;
public TypeDrawController(Draw p)
{
rootPane=p;
_Line=new Line();
_Rectangle=new LYD.Draw.Rectangle();
_Circle=new Circle();
_Ellipse=new Ellipse();
_Pencil=new Pencil();
_Rubber=new Rubber();
currentTypeDraw=_Line;
//currentTypeDraw=new Line();
}
public TypeDrawController(Graphics g)
{
}
//static function
public static Object peek()
{
if(altCommand.size()>0)
return altCommand.get(altCommand.size()-1);
else
return null;
}
public static void addToTop(ITypeDrawCommand c)
{
altCommand.add(c);
currentSize=currentSize+1;
rootPane.setUndoable(true);
}
public static void removeFromTop()
{
if(altCommand.size()>0)
{
altCommand.remove(altCommand.size()-1);
currentSize=currentSize-1;
}
}
public static boolean Redo()
{
if(currentSize<altCommand.size())
{
currentSize=currentSize+1;
rootPane.setUndoable(true);
if(currentSize==altCommand.size())
return (bIsUoing=false);
else
return true;
}
return false;
}
public static boolean Undo()
{
if(currentSize>0)
{
currentSize--;
bIsUoing=true;
rootPane.setRedoable(true);
return !(currentSize==0);
}
return false;
}
public static int getSize()
{
return altCommand.size();
}
public static int getCurrentSize()
{
return currentSize;
}
public static Object get(int i)
{
return altCommand.get(i);
}
//instance function
public boolean getDrawing()
{
return bDrawing;
}
protected void SetITypeDrawCommand(int type)
{
if(type>=0 &&type<6)
{
if(type==currentType)
return;
this.currentType=type;
if(type==0)
this.currentTypeDraw=new Line();
else if(type==1)
this.currentTypeDraw=new Rectangle();
else if(type==2)
this.currentTypeDraw=new Circle();
else if(type==3)
this.currentTypeDraw=new Ellipse();
else if(type==4)
this.currentTypeDraw=new Pencil();
else if(type==5)
this.currentTypeDraw=new Rubber();
currentTypeDraw.setWidth(rootPane.getBrushWidth());
currentTypeDraw.setColor(Draw.foreColor);
}
else
{
Draw.warning("遇到未定义的画笔类型!");
}
}
protected void SetITypeDrawCommand(int _ITypeDrawCommand,int brushType)
{
this.SetITypeDrawCommand(_ITypeDrawCommand);
this.currentTypeDraw.setType(brushType);
}
public void ReDo(Graphics g){}
public void UnDo(){}
public void paintPanel(Graphics g)
{
for(int i=0;i<currentSize;i++){
ITypeDrawCommand c=(ITypeDrawCommand)altCommand.get(i);
c.ReDo(g);
}
}
public void setWidth(int w){currentTypeDraw.setWidth(w);}
public Cursor getCursor(){return currentTypeDraw.getCursor();}
public void setColor(Color c){currentTypeDraw.setColor(c);}
public Color getColor(){return currentTypeDraw.getColor();}
public void setGraphics(Graphics g)
{
this.currentTypeDraw.setGraphics(g);
}
public void setType(int type)
{
if(type>=0 &&type<1)
{
this.currentType=type;
this.currentTypeDraw.setType(currentType);
}
else
{
Draw.warning("遇到未定义的画笔类型!");
}
}
public void mouseReleased(MouseEvent e)
{
currentTypeDraw.mouseReleased(e);
bDrawing=false;
}
public void mousePressed(MouseEvent e)
{
if(bIsUoing)
{
rootPane.setRedoable(false);
while(currentSize<altCommand.size())
{
if(altCommand.size()>0)
altCommand.remove(altCommand.size()-1);
else
break;
}
}
currentTypeDraw.mousePressed(e);
bDrawing=true;
}
public void mouseExited(MouseEvent e)
{
currentTypeDraw.mouseExited(e);
}
public void mouseEntered(MouseEvent e)
{
currentTypeDraw.mouseEntered(e);
}
public void mouseClicked(MouseEvent e)
{
currentTypeDraw.mouseClicked(e);
}
public void mouseMoved(MouseEvent e)
{
currentTypeDraw.mouseMoved(e);
}
public void mouseDragged(MouseEvent e)
{
if(bDrawing)
currentTypeDraw.mouseDragged(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -