Update RadioButton.java

synchronized ( _myRadioToggles ) { }
This commit is contained in:
GoToLoop 2016-07-21 21:55:19 -03:00 committed by GitHub
parent 1f7cb64986
commit 9278350dda

View File

@ -1,5 +1,3 @@
package controlP5;
/** /**
* controlP5 is a processing gui library. * controlP5 is a processing gui library.
* *
@ -25,12 +23,15 @@ package controlP5;
* *
*/ */
import java.lang.reflect.InvocationTargetException; package controlP5;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import processing.core.PImage; import processing.core.PImage;
import static processing.core.PApplet.min;
/** /**
* A radioButton is a list of toggles that can be turned on or off. radioButton is of type * A radioButton is a list of toggles that can be turned on or off. radioButton is of type
@ -49,23 +50,31 @@ import processing.core.PImage;
*/ */
public class RadioButton extends ControlGroup< RadioButton > { public class RadioButton extends ControlGroup< RadioButton > {
protected List< Toggle > _myRadioToggles; final protected List< Toggle > _myRadioToggles = new ArrayList< >( );
final protected PImage[] images = new PImage[ 3 ];
final protected boolean[] availableImages = new boolean[ 3 ];
protected int spacingRow = 1; protected int spacingRow = 1;
protected int spacingColumn = 1; protected int spacingColumn = 1;
protected int itemsPerRow = -1; protected int itemsPerRow = -1;
protected boolean isMultipleChoice;
protected int itemHeight = 9; protected int itemHeight = 9;
protected int itemWidth = 9; protected int itemWidth = 9;
protected boolean[] availableImages = new boolean[ 3 ];
protected PImage[] images = new PImage[ 3 ];
protected boolean noneSelectedAllowed = true; protected boolean noneSelectedAllowed = true;
private Object _myPlug; protected boolean isMultipleChoice = true;
private String _myPlugName;
protected Object _myPlug;
protected String _myPlugName = "";
protected int alignX = RIGHT_OUTSIDE; protected int alignX = RIGHT_OUTSIDE;
protected int alignY = CENTER; protected int alignY = CENTER;
protected int _myPaddingX = Label.paddingX; protected int _myPaddingX = Label.paddingX;
protected int _myPaddingY = 0; protected int _myPaddingY = 0;
static protected final Class<?>[] CIA = { int[].class };
/** /**
* Convenience constructor to extend RadioButton. * Convenience constructor to extend RadioButton.
* *
@ -75,7 +84,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
*/ */
public RadioButton( ControlP5 theControlP5 , String theName ) { public RadioButton( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 ); this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 );
theControlP5.register( theControlP5.papplet , theName , this ); cp5.register( cp5.papplet , theName , this );
} }
/** /**
@ -86,17 +95,13 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @param theX * @param theX
* @param theY * @param theY
*/ */
public RadioButton( final ControlP5 theControlP5 , final ControllerGroup< ? > theParent , final String theName , final int theX , final int theY ) { public RadioButton( ControlP5 theControlP5 , ControllerGroup< ? extends ControllerGroup< ? > > theParent ,
String theName , int theX , int theY ) {
super( theControlP5 , theParent , theName , theX , theY , 99 , 9 ); super( theControlP5 , theParent , theName , theX , theY , 99 , 9 );
isBarVisible = false; isCollapse = isBarVisible = false;
isCollapse = false;
_myRadioToggles = new ArrayList< Toggle >( );
setItemsPerRow( 1 ); setItemsPerRow( 1 );
_myPlug = cp5.papplet; _myPlug = cp5.papplet;
_myPlugName = getName( ); if ( !ControllerPlug.checkPlug( cp5.papplet , _myPlugName = getName( ) , CIA ) ) _myPlug = cp5.papplet;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
} }
/** /**
@ -105,13 +110,10 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @return * @return
*/ */
public RadioButton addItem( final String theName , final float theValue ) { public RadioButton addItem( final String theName , final float theValue ) {
Toggle t = cp5.addToggle( theName , 0 , 0 , itemWidth , itemHeight ); final Toggle t = cp5.addToggle( theName , 0 , 0 , itemWidth , itemHeight );
t.getCaptionLabel( ).align( alignX , alignY ).setPadding( _myPaddingX , _myPaddingY ); t.getCaptionLabel( ).align( alignX , alignY ).setPadding( _myPaddingX , _myPaddingY );
t.setMode( ControlP5.DEFAULT ); t.setMode( ControlP5.DEFAULT ).setImages( images ).setSize( images[ 0 ] );
t.setImages( images[ 0 ] , images[ 1 ] , images[ 2 ] ); return addItem( t , theValue );
t.setSize( images[ 0 ] );
addItem( t , theValue );
return this;
} }
/** /**
@ -120,11 +122,11 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @return * @return
*/ */
public RadioButton addItem( final Toggle theToggle , final float theValue ) { public RadioButton addItem( final Toggle theToggle , final float theValue ) {
theToggle.setGroup( this ); theToggle.isBroadcast = theToggle.isMoveable = false;
theToggle.isMoveable = false; theToggle.setGroup( this ).setInternalValue( theValue );
theToggle.setInternalValue( theValue ); synchronized ( _myRadioToggles ) {
theToggle.isBroadcast = false; _myRadioToggles.add( theToggle );
_myRadioToggles.add( theToggle ); }
updateLayout( ); updateLayout( );
getColor( ).copyTo( theToggle ); getColor( ).copyTo( theToggle );
theToggle.addListener( this ); theToggle.addListener( this );
@ -137,23 +139,24 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @param theName * @param theName
*/ */
public RadioButton removeItem( final String theName ) { public RadioButton removeItem( final String theName ) {
int n = _myRadioToggles.size( ); if ( theName != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
for ( int i = n-1 ; i >= 0 ; i-- ) { for ( int i = _myRadioToggles.size( ) ; i-- != 0 ; ) {
if ( ( _myRadioToggles.get( i ) ).getName( ).equals( theName ) ) { final Toggle tog = _myRadioToggles.get( i );
( _myRadioToggles.get( i ) ).removeListener( this ); if ( theName.equals( tog.getName( ) ) ) {
_myRadioToggles.get( i ).remove(); tog.removeListener( this ).remove();
_myRadioToggles.remove( i ); _myRadioToggles.remove( i );
}
} }
updateValues( false ).updateLayout( );
} }
updateValues( false );
updateLayout( );
return this; return this;
} }
private void updateAlign( ) { protected RadioButton updateAlign( ) {
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).align( alignX , alignY ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).align( alignX , alignY );
} }
return this;
} }
public RadioButton align( int[] a ) { public RadioButton align( int[] a ) {
@ -163,8 +166,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
public RadioButton align( int theX , int theY ) { public RadioButton align( int theX , int theY ) {
alignX = theX; alignX = theX;
alignY = theY; alignY = theY;
updateAlign( ); return updateAlign( );
return this;
} }
public RadioButton alignX( int theX ) { public RadioButton alignX( int theX ) {
@ -179,11 +181,12 @@ public class RadioButton extends ControlGroup< RadioButton > {
return new int[] { alignX , alignY }; return new int[] { alignX , alignY };
} }
public RadioButton setLabelPadding( int thePaddingX , int thePaddingY ) { public RadioButton setLabelPadding( final int thePaddingX , final int thePaddingY ) {
_myPaddingX = thePaddingX; _myPaddingX = thePaddingX;
_myPaddingY = thePaddingY; _myPaddingY = thePaddingY;
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setPadding( thePaddingX , thePaddingY ); for ( final Toggle tog : _myRadioToggles )
tog.getCaptionLabel( ).setPadding( thePaddingX , thePaddingY );
} }
return this; return this;
} }
@ -196,10 +199,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @return RadioButton * @return RadioButton
*/ */
public RadioButton setImages( PImage theDefaultImage , PImage theOverImage , PImage theActiveImage ) { public RadioButton setImages( PImage theDefaultImage , PImage theOverImage , PImage theActiveImage ) {
setImage( theDefaultImage , DEFAULT ); return setImage( theDefaultImage ).setImage( theOverImage , OVER ).setImage( theActiveImage , ACTIVE );
setImage( theOverImage , OVER );
setImage( theActiveImage , ACTIVE );
return this;
} }
/** /**
@ -216,13 +216,11 @@ public class RadioButton extends ControlGroup< RadioButton > {
* Controller.ACTIVE (active) * Controller.ACTIVE (active)
* @return * @return
*/ */
public RadioButton setImage( PImage theImage , int theState ) { public RadioButton setImage( final PImage theImage , final int theState ) {
if ( theImage != null ) { if ( theImage != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
images[ theState ] = theImage; images[ theState ] = theImage;
availableImages[ theState ] = true; availableImages[ theState ] = true;
for ( int i = 0 ; i < _myRadioToggles.size( ) ; i++ ) { for ( final Toggle tog : _myRadioToggles ) tog.setImage( theImage , theState );
_myRadioToggles.get( i ).setImage( theImage , theState );
}
} }
return this; return this;
} }
@ -232,9 +230,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
} }
public RadioButton setSize( int theWidth , int theHeight ) { public RadioButton setSize( int theWidth , int theHeight ) {
setItemWidth( theWidth ); return setItemWidth( theWidth ).setItemHeight( theHeight );
setItemHeight( theHeight );
return this;
} }
/** /**
@ -244,13 +240,12 @@ public class RadioButton extends ControlGroup< RadioButton > {
* *
* @param theItemHeight * @param theItemHeight
*/ */
public RadioButton setItemHeight( int theItemHeight ) { public RadioButton setItemHeight( final int theItemHeight ) {
itemHeight = theItemHeight; itemHeight = theItemHeight;
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.setHeight( theItemHeight ); for ( final Toggle tog : _myRadioToggles ) tog.setHeight( theItemHeight );
} }
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -260,13 +255,12 @@ public class RadioButton extends ControlGroup< RadioButton > {
* *
* @param theItemWidth * @param theItemWidth
*/ */
public RadioButton setItemWidth( int theItemWidth ) { public RadioButton setItemWidth( final int theItemWidth ) {
itemWidth = theItemWidth; itemWidth = theItemWidth;
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.setWidth( theItemWidth ); for ( final Toggle tog : _myRadioToggles ) tog.setWidth( theItemWidth );
} }
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -279,11 +273,10 @@ public class RadioButton extends ControlGroup< RadioButton > {
return _myRadioToggles.get( theIndex ); return _myRadioToggles.get( theIndex );
} }
public Toggle getItem( String theName ) { public Toggle getItem( final String theName ) {
for ( Toggle t : _myRadioToggles ) { if ( theName != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
if ( theName.equals( t.getName( ) ) ) { for ( final Toggle tog : _myRadioToggles )
return t; if ( theName.equals( tog.getName( ) ) ) return tog;
}
} }
return null; return null;
} }
@ -299,10 +292,8 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @return boolean * @return boolean
*/ */
public boolean getState( int theIndex ) { public boolean getState( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) && theIndex >= 0 ) { return ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ?
return ( ( Toggle ) _myRadioToggles.get( theIndex ) ).getState( ); _myRadioToggles.get( theIndex ).getState( ) : false;
}
return false;
} }
/** /**
@ -311,13 +302,10 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @param theName * @param theName
* @return * @return
*/ */
public boolean getState( String theName ) { public boolean getState( final String theName ) {
int n = _myRadioToggles.size( ); if ( theName != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { for ( final Toggle tog : _myRadioToggles )
Toggle t = _myRadioToggles.get( i ); if ( theName.equals( tog.getName( ) ) ) return tog.getState( );
if ( theName.equals( t.getName( ) ) ) {
return t.getState( );
}
} }
return false; return false;
} }
@ -325,26 +313,19 @@ public class RadioButton extends ControlGroup< RadioButton > {
/** /**
* @exclude * @exclude
*/ */
public void updateLayout( ) { public RadioButton updateLayout( ) {
int nn = 0; synchronized ( _myRadioToggles ) {
int xx = 0; int nn = 0 , xx = 0 , yy = 0;
int yy = 0; for ( final Toggle tog : _myRadioToggles ) {
int n = _myRadioToggles.size( ); set( tog.position , xx , yy );
for ( int i = 0 ; i < n ; i++ ) { _myWidth = xx += tog.getWidth( ) + spacingColumn;
Toggle t = _myRadioToggles.get( i ); if ( ++nn == itemsPerRow ) {
set( t.position , xx , yy ); xx = nn = 0;
yy += tog.getHeight( ) + spacingRow;
xx += t.getWidth( ) + spacingColumn; }
nn++;
if ( nn == itemsPerRow ) {
nn = 0;
_myWidth = xx;
yy += t.getHeight( ) + spacingRow;
xx = 0;
} else {
_myWidth = xx;
} }
} }
return this;
} }
/** /**
@ -355,8 +336,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
*/ */
public RadioButton setItemsPerRow( final int theValue ) { public RadioButton setItemsPerRow( final int theValue ) {
itemsPerRow = theValue; itemsPerRow = theValue;
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -366,8 +346,7 @@ public class RadioButton extends ControlGroup< RadioButton > {
*/ */
public RadioButton setSpacingColumn( final int theSpacing ) { public RadioButton setSpacingColumn( final int theSpacing ) {
spacingColumn = theSpacing; spacingColumn = theSpacing;
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -377,21 +356,24 @@ public class RadioButton extends ControlGroup< RadioButton > {
*/ */
public RadioButton setSpacingRow( final int theSpacing ) { public RadioButton setSpacingRow( final int theSpacing ) {
spacingRow = theSpacing; spacingRow = theSpacing;
updateLayout( ); return updateLayout( );
}
public RadioButton activateAll( ) {
if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
for ( final Toggle tog : _myRadioToggles ) tog.activate( );
updateValues( );
}
return this; return this;
} }
public RadioButton deactivateAll( ) { public RadioButton deactivateAll( ) {
if ( !isMultipleChoice && !noneSelectedAllowed ) { if ( !isMultipleChoice & !noneSelectedAllowed || _myRadioToggles.isEmpty( ) ) return this;
return this; synchronized ( _myRadioToggles ) {
} for ( final Toggle tog : _myRadioToggles ) tog.deactivate( );
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
( ( Toggle ) _myRadioToggles.get( i ) ).deactivate( );
} }
_myValue = -1; _myValue = -1;
updateValues( true ); return updateValues( true );
return this;
} }
/** /**
@ -402,13 +384,13 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @param theIndex * @param theIndex
*/ */
public RadioButton activate( int theIndex ) { public RadioButton activate( int theIndex ) {
int n = _myRadioToggles.size( ); if ( ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ) {
if ( theIndex < n ) { synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { for ( final Toggle tog : _myRadioToggles ) tog.deactivate( );
_myRadioToggles.get( i ).deactivate( );
} }
( ( Toggle ) _myRadioToggles.get( theIndex ) ).activate( ); final Toggle tog = _myRadioToggles.get( theIndex );
_myValue = _myRadioToggles.get( theIndex ).internalValue( ); tog.activate( );
_myValue = tog.internalValue( );
updateValues( true ); updateValues( true );
} }
return this; return this;
@ -418,13 +400,11 @@ public class RadioButton extends ControlGroup< RadioButton > {
* @param theIndex * @param theIndex
*/ */
public RadioButton deactivate( int theIndex ) { public RadioButton deactivate( int theIndex ) {
if ( !isMultipleChoice && !noneSelectedAllowed ) { if ( isMultipleChoice | noneSelectedAllowed &&
return this; ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ) {
} final Toggle tog = _myRadioToggles.get( theIndex );
if ( theIndex < _myRadioToggles.size( ) ) { if ( tog.isActive ) {
Toggle t = _myRadioToggles.get( theIndex ); tog.deactivate( );
if ( t.isActive ) {
t.deactivate( );
_myValue = -1; _myValue = -1;
updateValues( true ); updateValues( true );
} }
@ -437,33 +417,25 @@ public class RadioButton extends ControlGroup< RadioButton > {
* *
* @param theName * @param theName
*/ */
public RadioButton activate( String theName ) { public RadioButton activate( final String theName ) {
int n = _myRadioToggles.size( ); if ( theName != null ) synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { for ( int len = _myRadioToggles.size( ) , i = 0 ; i < len ; ++i )
Toggle t = _myRadioToggles.get( i ); if ( theName.equals( _myRadioToggles.get( i ).getName( ) ) ) return activate( i );
if ( theName.equals( t.getName( ) ) ) {
activate( i );
return this;
}
} }
return this; return this;
} }
/** /**
* Deactivates a RadioButton by name and sets the value of the RadioButton to the default value * Deactivates a RadioButton by name and sets the value of the RadioButton to the default value -1.
* -1.
* *
* @param theName * @param theName
*/ */
public RadioButton deactivate( String theName ) { public RadioButton deactivate( final String theName ) {
int n = _myRadioToggles.size( ); if ( theName != null ) synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { for ( final Toggle tog : _myRadioToggles ) if ( theName.equals( tog.getName( ) ) ) {
Toggle t = _myRadioToggles.get( i ); tog.deactivate( );
if ( theName.equals( t.getName( ) ) ) {
t.deactivate( );
_myValue = -1; _myValue = -1;
updateValues( true ); return updateValues( true );
return this;
} }
} }
return this; return this;
@ -494,79 +466,50 @@ public class RadioButton extends ControlGroup< RadioButton > {
* *
* @exclude * @exclude
*/ */
@ControlP5.Invisible @Override public void controlEvent( ControlEvent theEvent ) { @ControlP5.Invisible @Override public void controlEvent( final ControlEvent theEvent ) {
if ( !isMultipleChoice ) { if ( !isMultipleChoice ) {
if ( noneSelectedAllowed == false && theEvent.getController( ).getValue( ) < 1 ) { final Controller< ? > ctrl = theEvent.getController( );
if ( theEvent.getController( ) instanceof Toggle ) { if ( !noneSelectedAllowed && ctrl.getValue( ) < 1 && ctrl instanceof Toggle ) {
Toggle t = ( ( Toggle ) theEvent.getController( ) ); final Toggle tog = ( Toggle ) ctrl;
boolean b = t.isBroadcast( ); final boolean b = tog.isBroadcast( );
t.setBroadcast( false ); tog.setBroadcast( false ).setState( true ).setBroadcast( b );
t.setState( true ); return;
t.setBroadcast( b );
return;
}
} }
_myValue = -1; if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
int n = _myRadioToggles.size( ); _myValue = -1;
for ( int i = 0 ; i < n ; i++ ) { for ( final Toggle tog : _myRadioToggles )
Toggle t = _myRadioToggles.get( i ); if ( !tog.equals( ctrl ) ) tog.deactivate( );
if ( !t.equals( theEvent.getController( ) ) ) { else if ( tog.isOn( ) ) _myValue = t.internalValue( );
t.deactivate( );
} else {
if ( t.isOn ) {
_myValue = t.internalValue( );
}
}
} }
} }
if ( _myPlug != null ) { if ( _myPlug != null ) try {
try { final Method method = _myPlug.getClass( ).getMethod( _myPlugName , int.class );
Method method = _myPlug.getClass( ).getMethod( _myPlugName , int.class );
method.invoke( _myPlug , ( int ) _myValue ); method.invoke( _myPlug , ( int ) _myValue );
} catch ( SecurityException ex ) { } catch ( SecurityException | IllegalArgumentException | ReflectiveOperationException ex ) {
ex.printStackTrace( ); ex.printStackTrace( );
} catch ( NoSuchMethodException ex ) {
ex.printStackTrace( );
} catch ( IllegalArgumentException ex ) {
ex.printStackTrace( );
} catch ( IllegalAccessException ex ) {
ex.printStackTrace( );
} catch ( InvocationTargetException ex ) {
ex.printStackTrace( );
}
} }
updateValues( true ); updateValues( true );
} }
public RadioButton plugTo( Object theObject ) { public RadioButton plugTo( final Object theObject ) {
_myPlug = theObject; _myPlug = ControllerPlug.checkPlug( theObject , _myPlugName , CIA ) ? theObject : null;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
return this; return this;
} }
public RadioButton plugTo( Object theObject , String thePlugName ) { public RadioButton plugTo( final Object theObject , final String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName; _myPlugName = thePlugName;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) { return plugTo( theObject );
_myPlug = null;
}
return this;
} }
protected void updateValues( boolean theBroadcastFlag ) { protected RadioButton updateValues( final boolean theBroadcastFlag ) {
int n = _myRadioToggles.size( ); if ( _myRadioToggles.isEmpty( ) ) _myArrayValue = new float[ 0 ];
_myArrayValue = new float[ n ]; else synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { int i = 0 , len = _myRadioToggles.size( );
Toggle t = ( ( Toggle ) _myRadioToggles.get( i ) ); _myArrayValue = new float[ len ];
_myArrayValue[ i ] = t.getValue( ); for ( final Toggle tog : _myRadioToggles ) _myArrayValue[ i++ ] = tog.getValue( );
} }
if ( theBroadcastFlag ) { if ( theBroadcastFlag ) cp5.getControlBroadcaster( ).broadcast( new ControlEvent( this ) , FLOAT );
ControlEvent myEvent = new ControlEvent( this ); return this;
cp5.getControlBroadcaster( ).broadcast( myEvent , ControlP5Constants.FLOAT );
}
} }
/** /**
@ -581,47 +524,45 @@ public class RadioButton extends ControlGroup< RadioButton > {
} }
/** /**
* Sets the value for all RadioButton items according to the values of the array passed on. 0 * Sets the value for all RadioButton items according to the values of the array passed on.
* will turn off an item, any other value will turn it on. * 0 will turn off an item, any other value will turn it on.
*/ */
@Override public RadioButton setArrayValue( float[] theArray ) { @Override @SafeVarargs public final T setArrayValue( final float... theArray ) {
for ( int i = 0 ; i < theArray.length ; i++ ) { if ( theArray != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
if ( _myArrayValue[ i ] != theArray[ i ] ) { final int len = min( theArray.length , _myArrayValue.length , _myRadioToggles.size( ) );
if ( theArray[ i ] == 0 ) { for ( int i = 0 ; i < len ; ++i ) if ( theArray[ i ] != _myArrayValue[ i ] ) {
deactivate( i ); if ( theArray[ i ] == 0 ) deactivate( i );
} else { else activate( i );
activate( i );
}
} }
super.setArrayValue( theArray );
} }
super.setArrayValue( theArray ); return me;
return this;
} }
public RadioButton setColorLabels( int theColor ) { public RadioButton setColorLabels( final int theColor ) {
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setColor( theColor ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setColor( theColor );
} }
return this; return this;
} }
public RadioButton hideLabels( ) { public RadioButton hideLabels( ) {
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( false ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setVisible( false );
} }
return this; return this;
} }
public RadioButton showLabels( ) { public RadioButton showLabels( ) {
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( true ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setVisible( true );
} }
return this; return this;
} }
public RadioButton toUpperCase( boolean theValue ) { public RadioButton toUpperCase( final boolean theValue ) {
for ( Toggle t : _myRadioToggles ) { synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).toUpperCase( theValue ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).toUpperCase( theValue );
} }
return this; return this;
} }