📄 formpanel.java
字号:
comp.setCursor(FPoint.cursor);
return;
}
}
}//end of mouseDragged.
public void mouseMoved(MouseEvent e) {
Component moveComp = e.getComponent();
if (isChangeCursor(moveComp)) {
moveComp.setCursor(FPoint.crosshairCursor);
} else {
moveComp.setCursor(FPoint.defaultCursor);
getForm().setCursor(FPoint.defaultCursor);
FPoint.cursor = FPoint.defaultCursor;
}
}//end of mouseMoved.
private boolean isMe(Component comp) {
if (comp == this) {
return true;
}
return false;
}
private boolean isChangeCursor(Component comp) {
Object bean = getSelectBean();
if (comp != this && bean != null) {
return true;
}
return false;
}//end of isChangeCursor.
private void finishResize(Rectangle reSizeBox) {
if (!(startx == endx && starty == endy)) {
int x = reSizeBox.x - getBox(resizeChild.getParent(),this).x;
int y = reSizeBox.y - getBox(resizeChild.getParent(),this).y;
int w = reSizeBox.width;
int h = reSizeBox.height;
setChildBounds(resizeChild,x,y,w,h);
}
setPointLocation(resizeChild);
ResizeLine.setLineVisible(false);
FPoint.cursor = FPoint.defaultCursor;
resizeChild.getParent().repaint();
resizeChild = null;
}
public static Rectangle getBox(Component child,Component formPanel) {
if (child == null)
return new Rectangle(0,0,0,0);
Rectangle rec = child.getBounds();
int x = rec.x;
int y = rec.y;
while (formPanel != null && child != formPanel) {
child = child.getParent();
if (child != null) {
Point p = child.getLocation();
x = x + p.x;
y = y + p.y;
}
}
return new Rectangle(x,y,rec.width,rec.height);
}//end of getPanelPoint.
public Rectangle getFormBox(Component comp) {
Rectangle rec = getBox(comp,getForm());
rec.x = rec.x - getForm().getLocation().x;
rec.y = rec.y - getForm().getLocation().y;
return rec;
}//end of getFormBox.
//-------getRectangle -------------------------------------
public static Rectangle getRectangle(int sx,int sy,int ex,int ey) {
int x = Math.min(sx, ex);
int y = Math.min(sy, ey);
int w = Math.abs(ex - sx);
int h = Math.abs(ey - sy);
return new Rectangle(x,y,w,h);
}
//--------reSize component ----------------------------------
//-----Component Resize------------------------------------------
// North
// nw +------+------+ ne
// | |
// West + + East
// | |
// sw +------+------+ se
// South
//--------move Component -------------------------------------
public void setPointLocation(Component comp) {
FPoint.setPointLocation(comp);
Rectangle rec = getBox(comp.getParent(),this);
rec = getRecContainer(comp.getParent(),rec);
setPoint(comp,rec);
}
private void setPoint(Component comp,Rectangle rec) {
if (comp == getForm()) {
FPoint.setVisible(true);
} else {
pointBorder(rec);
}
}//end of setPoint.
private void pointBorder(Rectangle recContainer) {
Rectangle nwRec = FPoint.nwPoint.getBounds(); //North-West
Rectangle neRec = FPoint.nePoint.getBounds(); //North-East
Rectangle swRec = FPoint.swPoint.getBounds(); //North-West
Rectangle seRec = FPoint.sePoint.getBounds(); //South-East
Rectangle nRec = FPoint.nPoint.getBounds(); //North
Rectangle eRec = FPoint.ePoint.getBounds(); //East
Rectangle sRec = FPoint.sPoint.getBounds(); //South
Rectangle wRec = FPoint.wPoint.getBounds(); //Weast
if (nwRec.equals(recContainer.intersection(nwRec))) {
FPoint.nwPoint.setVisible(true);
} else {
FPoint.nwPoint.setVisible(false);
}
if (neRec.equals(recContainer.intersection(neRec))) {
FPoint.nePoint.setVisible(true);
} else {
FPoint.nePoint.setVisible(false);
}
if (swRec.equals(recContainer.intersection(swRec))) {
FPoint.swPoint.setVisible(true);
} else {
FPoint.swPoint.setVisible(false);
}
if (seRec.equals(recContainer.intersection(seRec))) {
FPoint.sePoint.setVisible(true);
} else {
FPoint.sePoint.setVisible(false);
}
//--------------------------------------------------
if (nRec.equals(recContainer.intersection(nRec))) {
FPoint.nPoint.setVisible(true);
} else {
FPoint.nPoint.setVisible(false);
}
if (eRec.equals(recContainer.intersection(eRec))) {
FPoint.ePoint.setVisible(true);
} else {
FPoint.ePoint.setVisible(false);
}
if (sRec.equals(recContainer.intersection(sRec))) {
FPoint.sPoint.setVisible(true);
} else {
FPoint.sPoint.setVisible(false);
}
if (wRec.equals(recContainer.intersection(wRec))) {
FPoint.wPoint.setVisible(true);
} else {
FPoint.wPoint.setVisible(false);
}
}
private void setSizeLine(Container container,Rectangle rec) {
ResizeLine.setLineLocation(rec);
rec = getBox(container,this);
rec = getRecContainer(container,rec);
lineBorder(rec);
}
//get border of line. about Container contain Container.
public Rectangle getRecContainer(Component comp,Rectangle rec) {
while (comp != getForm() && comp != this && comp != null) {
comp = comp.getParent();
if (comp != null) {
Rectangle recChild = getBox(comp,this);
if (recChild.intersects(rec)) {
rec = recChild.intersection(rec);
}
}
}
return rec;
}//end of getRecContainer.
private void lineBorder(Rectangle recContainer) {
Rectangle topRec = ResizeLine.topLine.getBounds();
Rectangle bottomRec = ResizeLine.bottomLine.getBounds();
Rectangle leftRec = ResizeLine.leftLine.getBounds();
Rectangle rightRec = ResizeLine.rightLine.getBounds();
if (recContainer.intersects(topRec)) {
topRec = recContainer.intersection(topRec);
ResizeLine.topLine.setBounds(topRec);
ResizeLine.topLine.setVisible(true);
} else {
ResizeLine.topLine.setVisible(false);
}
if (recContainer.intersects(bottomRec)) {
bottomRec = recContainer.intersection(bottomRec);
ResizeLine.bottomLine.setBounds(bottomRec);
ResizeLine.bottomLine.setVisible(true);
} else {
ResizeLine.bottomLine.setVisible(false);
}
if (recContainer.intersects(leftRec)) {
leftRec = recContainer.intersection(leftRec);
ResizeLine.leftLine.setBounds(leftRec);
ResizeLine.leftLine.setVisible(true);
} else {
ResizeLine.leftLine.setVisible(false);
}
if (recContainer.intersects(rightRec)) {
rightRec = recContainer.intersection(rightRec);
ResizeLine.rightLine.setBounds(rightRec);
ResizeLine.rightLine.setVisible(true);
} else {
ResizeLine.rightLine.setVisible(false);
}
}
//move line
private Point getBorderPoint(int ex,int ey,boolean addBean) {
Rectangle rec = getBox(getForm().pContainer,this);
if (addBean) {
rec.x = 0;
rec.y = 0;
}
if (! rec.contains(ex,ey)) {
if (ex <= rec.x) {
ex = rec.x;
} else if (ex >= rec.x + rec.width) {
ex = rec.x + rec.width;
}
if (ey <= rec.y) {
ey = rec.y;
} else if (ey >= rec.y + rec.height){
ey = rec.y + rec.height;
}
}
return new Point(ex,ey);
}//end of getBorderPoint.
private Rectangle getAddBeanRectangle(int sx,int sy,int ex,int ey) {
ex = getBorderPoint(ex,ey,false).x;
ey = getBorderPoint(ex,ey,false).y;
return getRectangle(sx,sy,ex,ey);
}
private Rectangle moveRectangle(int sx,int sy,int ex,int ey) {
ex = getBorderPoint(ex,ey,false).x;
ey = getBorderPoint(ex,ey,false).y;
int movex = ex - sx;
int movey = ey - sy;
Rectangle rec = getBox(selectComponent,this);
return new Rectangle(rec.x+movex,rec.y+movey,rec.width,rec.height);
}
private Rectangle reSizeRectangle(int sx,int sy,int ex,int ey) {
ex = getBorderPoint(ex,ey,false).x;
ey = getBorderPoint(ex,ey,false).y;
return FPoint.getSizeBox(this,ex-sx,ey-sy);
}
private Rectangle getBorder(Rectangle rec) {
Rectangle recBox = getBox(resizeChild.getParent(),this);
if (FPoint.fPoint == FPoint.nwPoint) { //North-west
if (rec.y >= recBox.y + recBox.height) rec.y = rec.y - 5;
if (rec.x >= recBox.x+recBox.width) rec.x = rec.x - 5;
} else if (FPoint.fPoint == FPoint.nePoint) { //North-east
if (rec.y >= recBox.y + recBox.height) rec.y = rec.y - 5;
if (rec.x+rec.width <= recBox.x) rec.width = rec.width + 5;
} else if (FPoint.fPoint == FPoint.swPoint) { //South-west
if (rec.y + rec.height <= recBox.y) rec.height = rec.height + 5;
if (rec.x >= recBox.x+recBox.width) rec.x = rec.x - 5;
} else if (FPoint.fPoint == FPoint.sePoint) { //South-east
if (rec.y + rec.height <= recBox.y) rec.height = rec.height + 5;
if (rec.x+rec.width <= recBox.x) rec.width = rec.width + 5;
} else if (FPoint.fPoint == FPoint.nPoint) { //North
if (rec.y >= recBox.y + recBox.height) rec.y = rec.y - 5;
} else if (FPoint.fPoint == FPoint.ePoint) { //East
if (rec.x+rec.width <= recBox.x) rec.width = rec.width + 5;
} else if (FPoint.fPoint == FPoint.sPoint) { //South
if (rec.y + rec.height <= recBox.y) rec.height = rec.height + 5;
} else if (FPoint.fPoint == FPoint.wPoint) { //West
if (rec.x >= recBox.x+recBox.width) rec.x = rec.x - 5;
}
return rec;
}//end of getBorder.
//move component
private void finishMove(int sx,int sy,int ex,int ey) {
ex = getBorderPoint(ex,ey,false).x;
ey = getBorderPoint(ex,ey,false).y;
Point p = moveChild.getLocation();
moveChild.setLocation(p.x+ex-sx,p.y+ey-sy);
setPointLocation(moveChild);
ResizeLine.setLineVisible(false);
moveChild.getParent().repaint();
moveChild = null;
}
public void setComponent(Container parent,Component child,boolean isContainer) {
getForm().addComponent(parent,child);
recBean = getRectangle(relativeStartX,relativeStartY,relativeEndX,relativeEndY);
setChildBounds(child,recBean.x,recBean.y,recBean.width,recBean.height);
}
public void setChildBounds(Component child, int x, int y, int width, int height) {
// Make sure the child is at least its minimum size.
Dimension minSize = null;
try{
minSize = child.getMinimumSize();
}catch(Exception e){}
if (minSize != null) {
if (minSize.height > height) {
height = minSize.height;
}
if (minSize.width > width) {
width = minSize.width;
}
}
// Make sure the child is under its maximum size.
Dimension maxSize = null;
try{
maxSize = child.getMaximumSize();
}catch(Exception e){}
if (maxSize != null){
if (height > maxSize.height) {
height = maxSize.height;
}
if (width > maxSize.width) {
width = maxSize.width;
}
}
// Now we can set the child's size.
child.setBounds(x, y, width, height);
child.setVisible(true);
child.validate();
}// end of setChildBounds.
private void addComponentOnForm(Component comp) {
Object bean = getSelectBean();
if (startx == endx && starty == endy) {
setSelectBean();
System.out.println(" setSelectBean");
} else if (bean != null && !isMe(comp)) {
if (!(bean instanceof java.awt.Window)) {
getForm().add_Controls(bean);
System.out.println(" add_Controls");
}
}
}
//****************************************************************
public transient PainterForm pForm = null;
public transient MainConsole mainConsole;
public transient int startx = 0;
public transient int starty = 0;
public transient int endx = 0;
public transient int endy = 0;
public transient int relativeStartX = 0;
public transient int relativeStartY = 0;
public transient int relativeEndX = 0;
public transient int relativeEndY = 0;
public transient Component moveChild;
public transient Component resizeChild;
public transient Component selectComponent;
private transient Rectangle recBean;
private transient Rectangle recMove;
private transient Rectangle recSize;
public transient Image backImage;
public transient Image bufferImage;
private transient boolean endRelease = false;
private transient int dragCount = 0;
}//end of FormPanel.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -