@ -1,6 +1,7 @@
package com.fr.design.mainframe ;
package com.fr.design.mainframe ;
import com.fr.design.designer.creator.XCreator ;
import com.fr.design.designer.creator.XCreator ;
import com.fr.design.utils.ComponentUtils ;
import com.fr.stable.Constants ;
import com.fr.stable.Constants ;
import com.fr.stable.GraphDrawHelper ;
import com.fr.stable.GraphDrawHelper ;
@ -23,6 +24,7 @@ public class FormSpacingLineDrawer {
private FormDesigner designer ;
private FormDesigner designer ;
private XCreator hoverCreator = null ;
private XCreator hoverCreator = null ;
private Rectangle selectedRec ;
private Rectangle selectedRec ;
private Rectangle hoveredRec ;
private boolean isMouseMoveEvent = false ;
private boolean isMouseMoveEvent = false ;
public FormSpacingLineDrawer ( FormDesigner designer ) {
public FormSpacingLineDrawer ( FormDesigner designer ) {
@ -38,7 +40,6 @@ public class FormSpacingLineDrawer {
}
}
public void draw ( Graphics g ) {
public void draw ( Graphics g ) {
this . selectedRec = designer . getSelectionModel ( ) . getSelection ( ) . getSelctionBounds ( ) ;
if ( ! isDrawSpacingLine ( ) ) {
if ( ! isDrawSpacingLine ( ) ) {
return ;
return ;
}
}
@ -47,6 +48,9 @@ public class FormSpacingLineDrawer {
return ;
return ;
}
}
this . selectedRec = designer . getSelectionModel ( ) . getSelection ( ) . getRelativeBounds ( ) ;
this . hoveredRec = ComponentUtils . getRelativeBounds ( hoverCreator ) ;
drawHorizontalSpacingLine ( g ) ;
drawHorizontalSpacingLine ( g ) ;
drawVerticalSpacingLine ( g ) ;
drawVerticalSpacingLine ( g ) ;
}
}
@ -158,8 +162,8 @@ public class FormSpacingLineDrawer {
} ;
} ;
AbstractFormParallelLine [ ] hoveredCreatorSides = new AbstractFormParallelLine [ ] {
AbstractFormParallelLine [ ] hoveredCreatorSides = new AbstractFormParallelLine [ ] {
new FormHorizontalParallelLine ( hoverCreator . getY ( ) , hoverCreator . getX ( ) , hoverCreator . getX ( ) + hoverCreator . getWidth ( ) ) ,
new FormHorizontalParallelLine ( hoveredRec . y , hoveredRec . x , hoveredRec . x + hoveredRec . width ) ,
new FormHorizontalParallelLine ( hoverCreator . getY ( ) + hoverCreator . getHeight ( ) , hoverCreator . getX ( ) , hoverCreator . getX ( ) + hoverCreator . getWidth ( ) )
new FormHorizontalParallelLine ( hoveredRec . y + hoveredRec . height , hoveredRec . x , hoveredRec . x + hoveredRec . width )
} ;
} ;
return getNearestSide ( selectedRecSides , hoveredCreatorSides ) ;
return getNearestSide ( selectedRecSides , hoveredCreatorSides ) ;
}
}
@ -171,19 +175,20 @@ public class FormSpacingLineDrawer {
} ;
} ;
AbstractFormParallelLine [ ] hoveredCreatorSides = new AbstractFormParallelLine [ ] {
AbstractFormParallelLine [ ] hoveredCreatorSides = new AbstractFormParallelLine [ ] {
new FormVerticalParallelLine ( hoverCreator . getX ( ) , hoverCreator . getY ( ) , hoverCreator . getY ( ) + hoverCreator . getHeight ( ) ) ,
new FormVerticalParallelLine ( hoveredRec . x , hoveredRec . y , hoveredRec . y + hoveredRec . height ) ,
new FormVerticalParallelLine ( hoverCreator . getX ( ) + hoverCreator . getWidth ( ) , hoverCreator . getY ( ) , hoverCreator . getY ( ) + hoverCreator . getHeight ( ) )
new FormVerticalParallelLine ( hoveredRec . x + hoveredRec . width , hoveredRec . y , hoveredRec . y + hoveredRec . height )
} ;
} ;
return getNearestSide ( selectedRecSides , hoveredCreatorSides ) ;
return getNearestSide ( selectedRecSides , hoveredCreatorSides ) ;
}
}
private AbstractFormParallelLine [ ] getNearestSide ( AbstractFormParallelLine [ ] lines1 , AbstractFormParallelLine [ ] lines2 ) {
private AbstractFormParallelLine [ ] getNearestSide ( AbstractFormParallelLine [ ] lines1 , AbstractFormParallelLine [ ] lines2 ) {
AbstractFormParallelLine [ ] nearestSides = new AbstractFormParallelLine [ 2 ] ;
AbstractFormParallelLine [ ] nearestSides = new AbstractFormParallelLine [ ] { lines1 [ 0 ] , lines 2[ 0 ] } ;
int minDistance = lines1 [ 0 ] . getDistanceWithLine ( lines2 [ 0 ] ) ;
int minDistance = lines1 [ 0 ] . getDistanceWithLine ( lines2 [ 0 ] ) ;
for ( int i = 0 ; i < lines1 . length ; i + + ) {
for ( int i = 0 ; i < lines1 . length ; i + + ) {
for ( int j = 0 ; j < lines2 . length ; j + + ) {
for ( int j = 0 ; j < lines2 . length ; j + + ) {
int distance = lines1 [ i ] . getDistanceWithLine ( lines2 [ j ] ) ;
int distance = lines1 [ i ] . getDistanceWithLine ( lines2 [ j ] ) ;
if ( distance < = minDistance ) {
if ( distance < minDistance ) {
minDistance = distance ;
nearestSides [ 0 ] = lines1 [ i ] ;
nearestSides [ 0 ] = lines1 [ i ] ;
nearestSides [ 1 ] = lines2 [ j ] ;
nearestSides [ 1 ] = lines2 [ j ] ;
}
}