@ -103,14 +103,11 @@ public class WidgetBoundPane extends BasicPane {
}
public void populate ( ) {
if ( ratioLockedButton = = null ) {
Rectangle bounds = new Rectangle ( creator . getBounds ( ) ) ;
if ( ratioLockedButton ! = null ) {
// 临时禁止尺寸比例锁定,关掉widthSpinner/heightSpinner之间的数值关联,以更新其高度和宽度值
ratioLockedButton . setLocked ( false ) ;
}
width . setValue ( bounds . width ) ;
height . setValue ( bounds . height ) ;
if ( ratioLockedButton ! = null ) {
} else {
ratioLockedButton . populate ( creator ) ;
}
}
@ -213,8 +210,7 @@ public class WidgetBoundPane extends BasicPane {
private final UISpinner mWidthSpinner ;
private final UISpinner mHeightSpinner ;
protected double width4Backup = 0 ;
protected double height4Backup = 0 ;
protected double aspectRatioBackup = 0 ;
public AspectRatioLockedButton ( UISpinner widthSpinner , UISpinner heightSpinner ) {
setUI ( new BasicButtonUI ( ) ) ;
@ -229,12 +225,16 @@ public class WidgetBoundPane extends BasicPane {
addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
// 改变图标icon
setLocked ( ! isLocked ( ) ) ;
double width = mWidthSpinner . getValue ( ) ;
double height = mHeightSpinner . getValue ( ) ;
boolean nextLocked = ! isLocked ( ) ;
if ( isLocked ( ) & & isLockEnabled ( ) ) {
width4Backup = mWidthSpinner . getValue ( ) ;
height4Backup = mHeightSpinner . getValue ( ) ;
if ( nextLocked & & width > 0 & & height > 0 ) {
setLocked ( true ) ;
aspectRatioBackup = width / height ;
} else {
setLocked ( false ) ;
aspectRatioBackup = - 1 ;
}
if ( globalNameListener ! = null ) {
@ -250,16 +250,26 @@ public class WidgetBoundPane extends BasicPane {
mWidthSpinner . addChangeListener ( new ChangeListener ( ) {
@Override
public void stateChanged ( ChangeEvent e ) {
if ( isLockEnabled ( ) & & isLocked ( ) & & width4Backup > 0 & & height4Backup > 0 ) {
mHeightSpinner . setValue ( mWidthSpinner . getValue ( ) * height4Backup / width4Backup , false ) ;
if ( isLockEnabled ( ) & & isLocked ( ) ) {
if ( mWidthSpinner . getValue ( ) = = 0 ) {
setLocked ( false ) ;
aspectRatioBackup = - 1 ;
} else if ( aspectRatioBackup > 0 ) {
double value = mWidthSpinner . getValue ( ) / aspectRatioBackup ;
mHeightSpinner . setValue ( Math . round ( value ) , false ) ;
}
}
}
} ) ;
mHeightSpinner . addChangeListener ( new ChangeListener ( ) {
@Override
public void stateChanged ( ChangeEvent e ) {
if ( isLockEnabled ( ) & & isLocked ( ) & & width4Backup > 0 & & height4Backup > 0 ) {
mWidthSpinner . setValue ( mHeightSpinner . getValue ( ) * width4Backup / height4Backup , false ) ;
if ( isLockEnabled ( ) & & isLocked ( ) ) {
setLocked ( false ) ;
aspectRatioBackup = - 1 ;
} else if ( aspectRatioBackup > 0 ) {
double value = mHeightSpinner . getValue ( ) * aspectRatioBackup ;
mWidthSpinner . setValue ( Math . round ( value ) , false ) ;
}
}
} ) ;
@ -301,14 +311,26 @@ public class WidgetBoundPane extends BasicPane {
public void populate ( XCreator creator ) {
Rectangle bounds = new Rectangle ( creator . getBounds ( ) ) ;
width4Backup = bounds . width ;
height4Backup = bounds . height ;
Widget widget = creator . toData ( ) ;
aspectRatioBackup = widget . getAspectRatioBackup ( ) ;
setLocked ( widget . isAspectRatioLocked ( ) ) ;
mWidthSpinner . setValue ( bounds . width , false ) ;
mHeightSpinner . setValue ( bounds . height , false ) ;
}
public void update ( XCreator creator ) {
creator . toData ( ) . setAspectRatioLocked ( this . isLocked ( ) ) ;
Widget widget = creator . toData ( ) ;
if ( widget ! = null ) {
if ( this . isLocked ( ) ) {
widget . setAspectRatioLocked ( true ) ;
widget . setAspectRatioBackup ( this . aspectRatioBackup ) ;
} else {
widget . setAspectRatioLocked ( false ) ;
widget . setAspectRatioBackup ( - 1 . 0 ) ;
}
}
}
@Override