Update CheckBox.java

synchronized ( _myRadioToggles )
This commit is contained in:
GoToLoop 2016-07-16 21:51:44 -03:00 committed by GitHub
parent 1f7cb64986
commit 192dd048e2
1 changed files with 184 additions and 274 deletions

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.util.ArrayList;
import java.util.List;
import processing.core.PImage;
import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList;
import processing.core.PImage;
import static processing.core.PApplet.min;
/** /**
* A multiple-choice radioButton. items are added to a checkBox and can be organized in rows and * A multiple-choice radioButton. items are added to a checkBox and can be organized in rows and
@ -43,9 +44,23 @@ import processing.core.PImage;
*/ */
public class CheckBox extends ControlGroup< CheckBox > { public class CheckBox extends ControlGroup< CheckBox > {
private Object _myPlug; final protected List< Toggle > _myRadioToggles = new ArrayList< >( );
private String _myPlugName; final protected PImage[] images = new PImage[ 3 ];
final protected boolean[] availableImages = new boolean[ 3 ];
protected int spacingRow = 1;
protected int spacingColumn = 1;
protected int itemsPerRow = -1;
protected int itemHeight = 9;
protected int itemWidth = 9;
protected boolean noneSelectedAllowed = true;
protected boolean isMultipleChoice;
protected Object _myPlug;
protected String _myPlugName;
/** /**
* Convenience constructor to extend CheckBox. * Convenience constructor to extend CheckBox.
@ -56,7 +71,7 @@ public class CheckBox extends ControlGroup< CheckBox > {
*/ */
public CheckBox( ControlP5 theControlP5 , String theName ) { public CheckBox( 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 );
} }
/** /**
@ -69,34 +84,29 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @param theX * @param theX
* @param theY * @param theY
*/ */
public CheckBox( final ControlP5 theControlP5 , final ControllerGroup< ? > theParent , final String theName , final int theX , final int theY ) { public CheckBox( 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 );
isMultipleChoice = true; isMultipleChoice = true;
_myPlug = cp5.papplet; setItemsPerRow( 1 );
_myPlugName = getName( ); if ( ControllerPlug.checkPlug( cp5.papplet , _myPlugName = getName( ) ,
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) { new Class[] { float[].class } ) ) _myPlug = cp5.papplet;
_myPlug = null;
}
} }
public final CheckBox activateAll( ) { public CheckBox activateAll( ) {
int n = _myRadioToggles.size( ); if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; i++ ) { for ( final Toggle tog : _myRadioToggles ) tog.activate( );
_myRadioToggles.get( i ).activate( ); updateValues( );
} }
updateValues( );
return this; return this;
} }
/** /**
* Activates a single checkbox item by index * Activates a single checkbox item by index
*/ */
public final CheckBox activate( int theIndex ) { public CheckBox activate( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) { if ( ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ) {
_myRadioToggles.get( theIndex ).activate( ); _myRadioToggles.get( theIndex ).activate( );
updateValues( ); updateValues( );
} }
@ -104,10 +114,10 @@ public class CheckBox extends ControlGroup< CheckBox > {
} }
/** /**
* deactivate a single checkbox item by index * Deactivates a single checkbox item by index
*/ */
public final CheckBox deactivate( int theIndex ) { public CheckBox deactivate( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) { if ( ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ) {
_myRadioToggles.get( theIndex ).deactivate( ); _myRadioToggles.get( theIndex ).deactivate( );
updateValues( ); updateValues( );
} }
@ -115,51 +125,40 @@ public class CheckBox extends ControlGroup< CheckBox > {
} }
/** /**
* toggle a single checkbox item by index * Toggles a single checkbox item by index
*/ */
public final CheckBox toggle( int theIndex ) { public CheckBox toggle( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) { if ( ( theIndex = Math.abs( theIndex ) ) < _myRadioToggles.size( ) ) {
Toggle t = _myRadioToggles.get( theIndex ); final Toggle tog = _myRadioToggles.get( theIndex );
if ( t.getState( ) == true ) { if ( tog.getState( ) ) tog.deactivate( );
t.deactivate( ); else tog.activate( );
} else {
t.activate( );
}
updateValues( ); updateValues( );
} }
return this; return this;
} }
/** /**
* deactivate a single checkbox item by name * Toggles a single checkbox item by name
*/ */
public final void toggle( String theName ) { public CheckBox toggle( 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 ) if ( theName.equals( tog.getName( ) ) ) {
Toggle t = _myRadioToggles.get( i ); if ( tog.getState( ) ) tog.deactivate( );
if ( theName.equals( t.getName( ) ) ) { else tog.activate( );
if ( t.getState( ) == true ) { return updateValues( );
t.deactivate( );
} else {
t.activate( );
}
updateValues( );
return;
} }
} }
return this;
} }
/** /**
* Activates a single checkbox item by name * Activates a single checkbox item by name
*/ */
public final CheckBox activate( String theName ) { public CheckBox activate( 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 ) if ( theName.equals( tog.getName( ) ) ) {
Toggle t = _myRadioToggles.get( i ); tog.activate( );
if ( theName.equals( t.getName( ) ) ) { return updateValues( );
t.activate( );
updateValues( );
return this;
} }
} }
return this; return this;
@ -168,40 +167,46 @@ public class CheckBox extends ControlGroup< CheckBox > {
/** /**
* Deactivates a single checkbox item by name * Deactivates a single checkbox item by name
*/ */
public final CheckBox deactivate( String theName ) { public CheckBox deactivate( 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 ) if ( theName.equals( tog.getName( ) ) ) {
Toggle t = _myRadioToggles.get( i ); tog.deactivate( );
if ( theName.equals( t.getName( ) ) ) { return updateValues( );
t.deactivate( );
updateValues( );
return this;
} }
} }
return this; return this;
} }
private final void updateValues( ) { @ControlP5.Invisible protected CheckBox updateValues( ) {
_myValue = -1; _myValue = -1;
updateValues( true ); return updateValues( true );
}
protected CheckBox updateValues( final boolean theBroadcastFlag ) {
if ( _myRadioToggles.isEmpty( ) ) _myArrayValue = new float[ 0 ];
else synchronized ( _myRadioToggles ) {
int i = 0 , len = _myRadioToggles.size( );
_myArrayValue = new float[ len ];
for ( final Toggle tog : _myRadioToggles ) _myArrayValue[ i++ ] = tog.getValue( );
}
if ( theBroadcastFlag ) cp5.getControlBroadcaster( ).broadcast( new ControlEvent( this ) , FLOAT );
return this;
} }
/** /**
* Sets the value for all CheckBox items according to the values of the array passed on. 0 will * Sets the value for all CheckBox items according to the values of the array passed on. 0 will
* turn off an item, any other value will turn it on. * turn off an item, any other value will turn it on.
*/ */
@Override public CheckBox 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 ] ) {
_myRadioToggles.get( i ).deactivate( ); if ( theArray[ i ] == 0 ) _myRadioToggles.get( i ).deactivate( );
} else { else _myRadioToggles.get( i ).activate( );
_myRadioToggles.get( i ).activate( );
}
} }
super.setArrayValue( theArray );
} }
super.setArrayValue( theArray ); return me;
return this;
} }
/** /**
@ -211,46 +216,16 @@ public class CheckBox extends ControlGroup< CheckBox > {
return "type:\tCheckBox\n" + super.getInfo( ); return "type:\tCheckBox\n" + super.getInfo( );
} }
/**
* @exclude {@inheritDoc}
*/
@Override public String toString( ) {
return super.toString( );
}
protected List< Toggle > _myRadioToggles;
protected int spacingRow = 1;
protected int spacingColumn = 1;
protected int itemsPerRow = -1;
protected boolean isMultipleChoice;
protected int itemHeight = 9;
protected int itemWidth = 9;
protected boolean[] availableImages = new boolean[ 3 ];
protected PImage[] images = new PImage[ 3 ];
protected boolean noneSelectedAllowed = true;
/** /**
* @param theName * @param theName
* @param theValue * @param theValue
* @return * @return
*/ */
public CheckBox addItem( final String theName , final float theValue ) { public CheckBox 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( RIGHT_OUTSIDE , CENTER ).setPadding( Label.paddingX , 0 ); t.getCaptionLabel( ).align( RIGHT_OUTSIDE , CENTER ).setPadding( Label.paddingX , 0 );
t.setMode( ControlP5.DEFAULT ); t.setMode( ControlP5.DEFAULT ).setImages( images );
t.setImages( images[ 0 ] , images[ 1 ] , images[ 2 ] ); return addItem( t , theValue );
t.setSize( images[ 0 ] );
addItem( t , theValue );
return this;
} }
/** /**
@ -259,11 +234,11 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @return * @return
*/ */
public CheckBox addItem( final Toggle theToggle , final float theValue ) { public CheckBox 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 );
@ -276,14 +251,16 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @param theName * @param theName
*/ */
public CheckBox removeItem( final String theName ) { public CheckBox removeItem( final String theName ) {
int n = _myRadioToggles.size( ); if ( theName != null && !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
for ( int i = 0 ; i < n ; 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.remove( i ); tog.removeListener( this );
_myRadioToggles.remove( i );
}
} }
updateValues( false );
} }
updateValues( false );
return this; return this;
} }
@ -295,10 +272,7 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @return CheckBox * @return CheckBox
*/ */
public CheckBox setImages( PImage theDefaultImage , PImage theOverImage , PImage theActiveImage ) { public CheckBox 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;
} }
/** /**
@ -315,13 +289,11 @@ public class CheckBox extends ControlGroup< CheckBox > {
* Controller.ACTIVE (active) * Controller.ACTIVE (active)
* @return * @return
*/ */
public CheckBox setImage( PImage theImage , int theState ) { public CheckBox 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;
} }
@ -331,41 +303,37 @@ public class CheckBox extends ControlGroup< CheckBox > {
} }
public CheckBox setSize( int theWidth , int theHeight ) { public CheckBox setSize( int theWidth , int theHeight ) {
setItemWidth( theWidth ); return setItemWidth( theWidth ).setItemHeight( theHeight );
setItemHeight( theHeight );
return this;
} }
/** /**
* set the height of a radioButton/checkBox item. by default the height is 11px. in order to * Sets the height of a radioButton/checkBox item. by default the height is 11px.
* recognize a custom height, the itemHeight has to be set before adding items to a * In order to recognize a custom height, the itemHeight has to be set
* radioButton/checkBox. * before adding items to a radioButton/checkBox.
* *
* @param theItemHeight * @param theItemHeight
*/ */
public CheckBox setItemHeight( int theItemHeight ) { public CheckBox setItemHeight( final int theItemHeight ) {
itemHeight = theItemHeight; itemHeight = theItemHeight;
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.setHeight( theItemHeight ); for ( final Toggle tog : _myRadioToggles ) tog.setHeight( theItemHeight );
} }
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
* set the width of a radioButton/checkBox item. by default the width is 11px. in order to * Sets the width of a radioButton/checkBox item. by default the width is 11px.
* recognize a custom width, the itemWidth has to be set before adding items to a * In order to recognize a custom width, the itemWidth has to be set
* radioButton/checkBox. * before adding items to a radioButton/checkBox.
* *
* @param theItemWidth * @param theItemWidth
*/ */
public CheckBox setItemWidth( int theItemWidth ) { public CheckBox setItemWidth( final int theItemWidth ) {
itemWidth = theItemWidth; itemWidth = theItemWidth;
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.setWidth( theItemWidth ); for ( final Toggle tog : _myRadioToggles ) tog.setWidth( theItemWidth );
} }
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -389,10 +357,8 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @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;
} }
/** /**
@ -401,13 +367,10 @@ public class CheckBox extends ControlGroup< CheckBox > {
* @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;
} }
@ -415,38 +378,31 @@ public class CheckBox extends ControlGroup< CheckBox > {
/** /**
* @exclude * @exclude
*/ */
public void updateLayout( ) { public CheckBox updateLayout( ) {
int nn = 0; if ( !_myRadioToggles.isEmpty( ) ) 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;
} }
/** /**
* Items of a radioButton or a checkBox are organized in columns and rows. SetItemsPerRow sets * Items of a RadioButton or a CheckBox are organized in columns and rows.
* the limit of items per row. items exceeding the limit will be pushed to the next row. * setItemsPerRow() sets the limit of items per row.
* Items exceeding the limit will be pushed to the next row.
* *
* @param theValue * @param theValue
*/ */
public CheckBox setItemsPerRow( final int theValue ) { public CheckBox setItemsPerRow( final int theValue ) {
itemsPerRow = theValue; itemsPerRow = theValue;
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -454,10 +410,9 @@ public class CheckBox extends ControlGroup< CheckBox > {
* *
* @param theSpacing * @param theSpacing
*/ */
public CheckBox setSpacingColumn( final int theSpacing ) { public CheckBox setSpacingColumn( final int theSpacingCol ) {
spacingColumn = theSpacing; spacingColumn = theSpacingCol;
updateLayout( ); return updateLayout( );
return this;
} }
/** /**
@ -465,23 +420,18 @@ public class CheckBox extends ControlGroup< CheckBox > {
* *
* @param theSpacing * @param theSpacing
*/ */
public CheckBox setSpacingRow( final int theSpacing ) { public CheckBox setSpacingRow( final int theSpacingRow ) {
spacingRow = theSpacing; spacingRow = theSpacingRow;
updateLayout( ); return updateLayout( );
return this;
} }
public CheckBox deactivateAll( ) { public CheckBox 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;
} }
/** /**
@ -489,85 +439,45 @@ public class CheckBox extends ControlGroup< CheckBox > {
* *
* @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( );
}
}
} }
} }
updateValues( true ); updateValues( true );
if ( _myPlug != null ) { if ( _myPlug != null ) try {
try { final Method method = _myPlug.getClass( ).getMethod( _myPlugName , float[].class );
Method method = _myPlug.getClass( ).getMethod( _myPlugName , float[].class ); method.invoke( _myPlug , getArrayValue( ) );
method.invoke( _myPlug , ( float[] ) getArrayValue( ) ); } catch ( SecurityException | IllegalArgumentException | ReflectiveOperationException ex ) {
} catch ( SecurityException 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( );
}
} }
} }
public CheckBox plugTo( Object theObject ) { public CheckBox plugTo( final Object theObject ) {
_myPlug = theObject; _myPlug = ControllerPlug.checkPlug( theObject , _myPlugName , new Class[] { float[].class } )
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) { ? theObject : null;
_myPlug = null;
}
return this; return this;
} }
public CheckBox plugTo( Object theObject , String thePlugName ) { public CheckBox plugTo( final Object theObject , final String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName; _myPlugName = thePlugName;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) { return plugTo( theObject );
_myPlug = null;
}
return this;
}
protected void updateValues( boolean theBroadcastFlag ) {
int n = _myRadioToggles.size( );
_myArrayValue = new float[ n ];
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = ( ( Toggle ) _myRadioToggles.get( i ) );
_myArrayValue[ i ] = t.getValue( );
}
if ( theBroadcastFlag ) {
ControlEvent myEvent = new ControlEvent( this );
cp5.getControlBroadcaster( ).broadcast( myEvent , ControlP5Constants.FLOAT );
}
} }
/** /**
* In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this * In order to always have 1 item selected, use setNoneSelectedAllowed(false).
* is true. setNoneSelectedAllowed does not apply when in multipleChoice mode. * By default this is true. setNoneSelectedAllowed() does not apply when in multipleChoice mode.
* *
* @param theValue * @param theValue
*/ */
@ -576,30 +486,30 @@ public class CheckBox extends ControlGroup< CheckBox > {
return this; return this;
} }
public CheckBox setColorLabels( int theColor ) { public CheckBox setColorLabels( final int theColor ) {
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setColor( theColor ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setColor( theColor );
} }
return this; return this;
} }
public CheckBox hideLabels( ) { public CheckBox hideLabels( ) {
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( false ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setVisible( false );
} }
return this; return this;
} }
public CheckBox showLabels( ) { public CheckBox showLabels( ) {
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( true ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).setVisible( true );
} }
return this; return this;
} }
public CheckBox toUpperCase( boolean theValue ) { public CheckBox toUpperCase( boolean theValue ) {
for ( Toggle t : _myRadioToggles ) { if ( !_myRadioToggles.isEmpty( ) ) synchronized ( _myRadioToggles ) {
t.getCaptionLabel( ).toUpperCase( theValue ); for ( final Toggle tog : _myRadioToggles ) tog.getCaptionLabel( ).toUpperCase( theValue );
} }
return this; return this;
} }