@ -83,6 +83,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
static List < Display > displays = new ArrayList < Display > ( ) ;
public static Display selectedDisplay = null ;
public static Display draggedDisplay = null ;
public static Point initialDragPoint = null ;
DrawCanvas ( ) throws FontFormatException , IOException {
//loadConfig();
addConfigButton = ImageIO . read ( new File ( "addDisplay.png" ) ) ;
@ -380,6 +381,39 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
@Override
public void mousePressed ( MouseEvent e ) {
Point cursor = GetCursorPosition ( e ) ;
initialDragPoint = cursor ;
selectedDisplay = null ;
for ( int i = 0 ; i < displays . size ( ) ; i + + ) {
Display d = displays . get ( i ) ;
if ( cursor . x > = d . x & &
cursor . x < = d . x + d . width & &
cursor . y > = d . y & &
cursor . y < = d . y + d . height ) {
selectedDisplay = d ;
break ;
}
}
if ( selectedDisplay = = null ) {
MyRobot . FRAME . setCursor ( Cursor . getDefaultCursor ( ) ) ;
DisplayManager . f . setVisible ( false ) ;
} else {
MyRobot . FRAME . setCursor ( new Cursor ( Cursor . MOVE_CURSOR ) ) ;
draggedDisplay = selectedDisplay ;
}
}
private Point GetCursorPosition ( MouseEvent e ) {
Point cursor = e . getPoint ( ) ;
cursor . translate ( - MyRobot . FRAME . getInsets ( ) . left , - MyRobot . FRAME . getInsets ( ) . top ) ;
return cursor ;
}
@Override
public void mouseReleased ( MouseEvent e ) {
Point cursor = GetCursorPosition ( e ) ;
draggedDisplay = null ;
MyRobot . FRAME . setCursor ( Cursor . getDefaultCursor ( ) ) ;
switch ( e . getButton ( ) ) {
case MouseEvent . BUTTON3 : {
selectedDisplay = null ;
@ -420,44 +454,14 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
}
Display previousDisplay = selectedDisplay ;
selectedDisplay = null ;
for ( int i = 0 ; i < displays . size ( ) ; i + + ) {
Display d = displays . get ( i ) ;
if ( cursor . x > = d . x & &
cursor . x < = d . x + d . width & &
cursor . y > = d . y & &
cursor . y < = d . y + d . height ) {
selectedDisplay = d ;
break ;
}
}
if ( selectedDisplay = = null ) {
MyRobot . FRAME . setCursor ( Cursor . getDefaultCursor ( ) ) ;
DisplayManager . f . setVisible ( false ) ;
} else {
MyRobot . FRAME . setCursor ( new Cursor ( Cursor . MOVE_CURSOR ) ) ;
draggedDisplay = selectedDisplay ;
if ( selectedDisplay . equals ( previousDisplay ) ) {
//System.out.println("Double click");
DisplayManager . setupSettings ( selectedDisplay ) ;
}
}
} break ;
}
}
private Point GetCursorPosition ( MouseEvent e ) {
Point cursor = e . getPoint ( ) ;
cursor . translate ( - MyRobot . FRAME . getInsets ( ) . left , - MyRobot . FRAME . getInsets ( ) . top ) ;
return cursor ;
}
@Override
public void mouseReleased ( MouseEvent e ) {
draggedDisplay = null ;
}
@Override
public void mouseEntered ( MouseEvent e ) {
// TODO Auto-generated method stub
@ -474,11 +478,21 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
public void mouseDragged ( MouseEvent e ) {
if ( draggedDisplay ! = null ) {
Point cursor = GetCursorPosition ( e ) ;
if ( initialDragPoint ! = null ) {
if ( ( Math . abs ( cursor . x - initialDragPoint . x ) > 24 | |
Math . abs ( cursor . y - initialDragPoint . y ) > 24 ) ) {
draggedDisplay . x = ( int ) ( Math . floor ( ( cursor . x - draggedDisplay . width / 2 ) / 8 ) * 8 ) ;
draggedDisplay . y = ( int ) ( Math . floor ( ( cursor . y - draggedDisplay . height / 2 ) / 8 ) * 8 ) ;
MyRobot . p . repaint ( ) ;
initialDragPoint = null ;
}
} else {
draggedDisplay . x = ( int ) ( Math . floor ( ( cursor . x - draggedDisplay . width / 2 ) / 8 ) * 8 ) ;
draggedDisplay . y = ( int ) ( Math . floor ( ( cursor . y - draggedDisplay . height / 2 ) / 8 ) * 8 ) ;
MyRobot . p . repaint ( ) ;
}
}
}
@Override
public void mouseMoved ( MouseEvent e ) {