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