?? multiresizecontrolfigure.java
字號:
package drawfigure;
import java.awt.*;
import java.awt.geom.*;
/**
* 擁有8個改變圖形大小控制器的圖形類,子類有RectangleFigure,OvalFigure等,擁有8個控制塊
* SelectFigure也是本類的字類,因為選擇區(qū)域是矩形
*/
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;
}
/**
* 根據(jù)點坐標在哪個選擇塊中,得到改變大小的光標類型
*/
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 + -