fpoint.java
来自「一个简单的visio程序。」· Java 代码 · 共 543 行 · 第 1/2 页
JAVA
543 行
if (isFocusPoint(object)) {
setMoveCursor(object);
}
}
public void mousePressed(java.awt.event.MouseEvent event) {
FocusPoint_MousePress(event);
}
public void mouseReleased(java.awt.event.MouseEvent event) {
FocusPoint_MouseRelease(event);
}
}
public void FocusPoint_MouseExited(MouseEvent event) {
if (isDrag) {
isDrag = false;
Component comp = event.getComponent();
int x = event.getX() + comp.getLocation().x;
int y = event.getY() + comp.getLocation().y;
event = new MouseEvent(formPanel,
event.MOUSE_MOVED,
event.getWhen(),
event.getModifiers(),x,y,
event.getClickCount(),
event.isPopupTrigger());
formPanel.dispatchEvent(event);
}
}
void FocusPoint_MousePress(MouseEvent event) {
Object object = event.getSource();
if (isFocusPoint(object)) {
fPoint = object;
Component comp = event.getComponent();
formPanel.startx = event.getX() + comp.getLocation().x;
formPanel.starty = event.getY() + comp.getLocation().y;
formPanel.endx = formPanel.startx;
formPanel.endy = formPanel.starty;
formPanel.resizeChild = focusComponent;
formPanel.moveChild = null;
formPanel.pForm.pContainer = focusComponent.getParent();
setPressCursor(object);
int rightKey = event.getModifiers();
if (rightKey == InputEvent.BUTTON1_MASK) {
setVisible(false);
formPanel.leftKey = true;
}
}
}
void FocusPoint_MouseRelease(MouseEvent event) {
Object object = event.getSource();
Component comp = event.getComponent();
endx = event.getX();
endy = event.getY();
int x = endx + comp.getLocation().x;
int y = endy + comp.getLocation().y;
if (isFocusPoint(object)) {
disPatchEvent(event,x,y);
}
}
//dispatch event to formPanel.
private void disPatchEvent(MouseEvent event,int x,int y) {
event = new MouseEvent(formPanel,
event.getID(),
event.getWhen(),
event.getModifiers(),x,y,
event.getClickCount(),
event.isPopupTrigger());
formPanel.dispatchEvent(event);
}
//---set focus point location------------------------------------
private static void setLocation(Rectangle compRec) {
int x = compRec.x;
int y = compRec.y;
int width = compRec.width;
int height= compRec.height;
//--1--------- North-West
int nwx = x - 7;
int nwy = y - 7;
nwPoint.setLocation(nwx,nwy);
//--2--------- North-East
int nex = x + width;
int ney = y - 7;
//--3--------- South-West
int swx = x - 7;
int swy = y + height;
//--4--------- South-East
int sex = x + width;
int sey = y + height;
//--5--------- North
int nx = x + width/2 - 2 - 1;
int ny = y -7;
//--6--------- East
int ex = x + width;
int ey = y + height/2-2;
//--7-------- South
int sx = x + width/2 - 2 -1;
int sy = y + height;
//--8--------- West
int wx = x - 7;
int wy = y + height/2-2;
//-------set location of point--------------------------
nwPoint.setLocation(nwx,nwy);
nePoint.setLocation(nex,ney);
swPoint.setLocation(swx,swy);
sePoint.setLocation(sex,sey);
nPoint.setLocation(nx,ny);
ePoint.setLocation(ex,ey);
sPoint.setLocation(sx,sy);
wPoint.setLocation(wx,wy);
}//end of setLocation.
public static boolean cursorCheck() {
if (cursor == nResizeCursor ||
cursor == wResizeCursor ||
cursor == sResizeCursor ||
cursor == eResizeCursor ||
cursor == nwResizeCursor ||
cursor == neResizeCursor ||
cursor == swResizeCursor ||
cursor == seResizeCursor) {
return true;
}
return false;
} //end of curosrCheck.
//-----Component Resize------------------------------------------
// North
// wn +------+------+ ne
// | |
// West + + East
// | |
// ws +------+------+ se
// South
public static Rectangle getSizeBox(FormPanel form,int mx, int my) {
Rectangle rec = form.resizeChild.getBounds();
int x = form.getBox(form.resizeChild,form).x;
int y = form.getBox(form.resizeChild,form).y;
int w = rec.width;
int h = rec.height;
Dimension minSize = null;
int newheight=y+h;
int newwidth =x+w;
try {
minSize = form.resizeChild.getMinimumSize();
}catch(Exception e) {}
if (minSize != null) {
newheight=y+h-minSize.height;
newwidth =x+w-minSize.width;
}
if (cursor == nwResizeCursor) {
w = w - mx;
h = h - my;
x = x + mx;
y = y + my;
if (y >= newheight) {
y = newheight;
}
if (x >= newwidth) {
x = newwidth;
}
} else if (cursor == swResizeCursor){
w = w - mx;
h = my + h;
x = x + mx;
if (x >= newwidth) {
x = newwidth;
}
} else if (cursor == neResizeCursor){
w = mx + w;
h = h - my;
y = y + my;
if (y >= newheight) {
y = newheight;
}
} else if (cursor == seResizeCursor){
w = mx + w;
h = my + h;
} else if (cursor == nResizeCursor){
h = h - my;
y = y + my;
if (y >= newheight) {
y=newheight;
}
} else if (cursor == sResizeCursor) {
h = my + h;
} else if (cursor == wResizeCursor){
w = w - mx;
x = x + mx;
if (x >= newwidth) {
x=newwidth;
}
} else if (cursor == eResizeCursor){
w = w + mx;
}
if (minSize != null) {
if (h < minSize.height ) {
h = minSize.height;
}
if (w < minSize.width) {
w = minSize.width;
}
}
return new Rectangle(x, y, w, h);
}//end of getSizeBox.
//---Focus Point-------------------------------------------------
public static transient FocusPoint nwPoint = null; //North-West
public static transient FocusPoint nePoint = null; //North-East
public static transient FocusPoint swPoint = null; //North-West
public static transient FocusPoint sePoint = null; //South-East
public static transient FocusPoint nPoint = null; //North
public static transient FocusPoint ePoint = null; //East
public static transient FocusPoint sPoint = null; //South
public static transient FocusPoint wPoint = null; //Weast
public static transient Object fPoint = null;
//---Resize Cursor--------------------------------------------------
public static transient Cursor nwResizeCursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
public static transient Cursor neResizeCursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
public static transient Cursor swResizeCursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
public static transient Cursor seResizeCursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
public static transient Cursor nResizeCursor = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
public static transient Cursor eResizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
public static transient Cursor sResizeCursor = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
public static transient Cursor wResizeCursor = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
//---crosshair Cursor--------------------------------------------------
public static transient Cursor crosshairCursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
//---default Cursor--------------------------------------------------
public static transient Cursor defaultCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
//---Resize Cursor----------------------------------------------------
public static transient Cursor resizeCursor = defaultCursor;
public static transient Cursor cursor = defaultCursor;
//---Resize ----------------------------------------------------------
public static transient int startx = 0;
public static transient int starty = 0;
private static transient int endx = 0;
private static transient int endy = 0;
public static transient Rectangle reSizeRec;
private static transient Component focusComponent = null;
private FormPanel formPanel;
private boolean isDrag = false;
}//end of JFocusPoint.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?