📄 multiresizecontrolfigure.java
字号:
package drawfigure;
import java.awt.*;
import java.awt.geom.*;
/**
* 拥有8个改变图形大小控制器的图形类,子类有RectangleFigure,OvalFigure等,拥有8个控制块
* SelectFigure也是本类的字类,因为选择区域是矩形
*/
public abstract class MultiResizeControlFigure extends Figure{
/**
* 控制块
*/
private ControlRect ctrlRectN,ctrlRectS,ctrlRectW,ctrlRectE;
private ControlRect ctrlRectNW,ctrlRectNE,ctrlRectSW,ctrlRectSE;
public MultiResizeControlFigure(){
super();
}
public MultiResizeControlFigure(Point2D p){
super(p);
}
public void setStartPoint(Point2D p){
super.setStartPoint(p);
if((getStartPoint()!=null)&&(getEndPoint()!=null)){
setCtrlRectsByBounds(getBounds());
}
}
public void setEndPoint(Point2D p){
super.setEndPoint(p);
if((getStartPoint()!=null)&&(getEndPoint()!=null)){
setCtrlRectsByBounds(getBounds());
}
}
/**
*通过边界线确定控制块
*/
public void setCtrlRectsByBounds(Rectangle2D bound){
double x1,y1,x2,y2,width,height;
x1=bound.getX();
y1=bound.getY();
width=bound.getWidth();
height=bound.getHeight();
x2=x1+width;
y2=y1+height;
ctrlRectN=new ControlRect(x1+width/2,y1,ControlRect.TOP_POSITION);
ctrlRectS=new ControlRect(x1+width/2,y2,ControlRect.BOTTOM_POSITION);
ctrlRectW=new ControlRect(x1,y1+height/2,ControlRect.LEFT_POSITION);
ctrlRectE=new ControlRect(x2,y1+height/2,ControlRect.RIGHT_POSITION);
ctrlRectNW=new ControlRect(x1,y1,ControlRect.LEFT_TOP_POSITION);
ctrlRectNE=new ControlRect(x2,y1,ControlRect.RIGHT_TOP_POSITION);
ctrlRectSW=new ControlRect(x1,y2,ControlRect.LEFT_BOTTOM_POSITION);
ctrlRectSE=new ControlRect(x2,y2,ControlRect.RIGHT_BOTTOM_POSITION);
}
/*
* (non-Javadoc)
* @see drawfigure.Figure#pointInside(java.awt.Point)
*/
public abstract boolean pointInside(Point2D p);
/*
* (non-Javadoc)
* @see drawfigure.Figure#pointInResizeControl(java.awt.Point2D)
*/
public ControlRect getControlRect(Point2D p){
if(ctrlRectN.pointInside(p))return ctrlRectN;
if(ctrlRectS.pointInside(p))return ctrlRectS;
if(ctrlRectW.pointInside(p))return ctrlRectW;
if(ctrlRectE.pointInside(p))return ctrlRectE;
if(ctrlRectNW.pointInside(p))return ctrlRectNW;
if(ctrlRectNE.pointInside(p))return ctrlRectNE;
if(ctrlRectSW.pointInside(p))return ctrlRectSW;
if(ctrlRectSE.pointInside(p))return ctrlRectSE;
return null;
}
public boolean pointInControlRect(Point2D p){
if(getControlRect(p)!=null)return true;
return false;
}
/**
* 根据点坐标在哪个选择块中,得到改变大小的光标类型
*/
public abstract void draw(Graphics g);
public void drawCtrlRects(Graphics g){
ctrlRectN.paint(g);
ctrlRectS.paint(g);
ctrlRectW.paint(g);
ctrlRectE.paint(g);
ctrlRectNW.paint(g);
ctrlRectNE.paint(g);
ctrlRectSW.paint(g);
ctrlRectSE.paint(g);
}
/*
* (non-Javadoc)
* @see drawfigure.Figure#getCursor(java.awt.Point)
*/
/* public Cursor getCursor(Point2D p){
ControlRect ctrl=getControlRect(p);
if(ctrl!=null){
return ctrl.getCursor();
}
return new Cursor(Cursor.DEFAULT_CURSOR);
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -