statemanager.cs
来自「c#设计模式随书源码 c#设计模式随书源码」· CS 代码 · 共 55 行
CS
55 行
using System;
namespace State
{
/// <summary>
/// Summary description for StateManager.
/// </summary>
public class StateManager {
private State currentState;
private RectState rState;
private ArrowState aState;
private CircleState cState;
private FillState fState;
public StateManager(Mediator med) {
//create an instance of each state
rState = new RectState(med);
cState = new CircleState(med);
aState = new ArrowState(med);
fState = new FillState(med);
//and initialize them
//set default state
currentState = aState;
}
//-----
//These methods are called when the toolbuttons are clicked
public void setRect() {
currentState = rState;
}
//-----
public void setCircle() {
currentState = cState;
}
public void setFill() {
currentState = fState;
}
public void setArrow() {
currentState = aState;
}
public void mouseDown(int x, int y) {
currentState.mouseDown (x, y);
}
public void mouseUp(int x, int y) {
currentState.mouseUp (x, y);
}
public void mouseDrag(int x, int y) {
currentState.mouseDrag (x, y);
}
public void selectOne(Drawing d) {
currentState.selectOne (d);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?