mirror of
https://github.com/sojamo/controlp5
synced 2025-01-10 12:15:10 +01:00
Merge pull request #1 from GoToLoop/ControllerList-patch-1
Change Vector to ArrayList
This commit is contained in:
commit
2a15aaacbf
@ -1,5 +1,3 @@
|
|||||||
package controlP5;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controlP5 is a processing gui library.
|
* controlP5 is a processing gui library.
|
||||||
*
|
*
|
||||||
@ -22,47 +20,64 @@ package controlP5;
|
|||||||
* @author Andreas Schlegel (http://www.sojamo.de)
|
* @author Andreas Schlegel (http://www.sojamo.de)
|
||||||
* @modified ##date##
|
* @modified ##date##
|
||||||
* @version ##version##
|
* @version ##version##
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package controlP5;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.ArrayList;
|
||||||
|
import java.util.RandomAccess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores objects of type ControllerInterface and CDrawable, mainly for internal use.
|
* Stores objects of type ControllerInterface and CDrawable, mainly for internal use.
|
||||||
*/
|
*/
|
||||||
public class ControllerList {
|
public class ControllerList implements RandomAccess {
|
||||||
|
protected final List< ControllerInterface< ? >> controllers = new ArrayList< >( );
|
||||||
|
protected final List< CDrawable > drawables = new ArrayList< >( );
|
||||||
|
|
||||||
protected List< ControllerInterface< ? >> controllers;
|
public ControllerList add( final ControllerInterface< ? > theController ) {
|
||||||
|
if ( !contains( theController ) ) synchronized ( controllers ) {
|
||||||
protected List< CDrawable > drawables;
|
|
||||||
|
|
||||||
public ControllerList( ) {
|
|
||||||
controllers = new Vector< ControllerInterface< ? >>( );
|
|
||||||
drawables = new Vector< CDrawable >( );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add( ControllerInterface< ? > theController ) {
|
|
||||||
if ( controllers.indexOf( theController ) < 0 ) {
|
|
||||||
controllers.add( theController );
|
controllers.add( theController );
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void remove( ControllerInterface< ? > theController ) {
|
public ControllerList addDrawable( final CDrawable theController ) {
|
||||||
controllers.remove( theController );
|
if ( !containsDrawable( theController ) ) synchronized ( drawables ) {
|
||||||
}
|
|
||||||
|
|
||||||
protected void addDrawable( CDrawable theController ) {
|
|
||||||
if ( drawables.indexOf( theController ) < 0 ) {
|
|
||||||
drawables.add( theController );
|
drawables.add( theController );
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeDrawable( CDrawable theController ) {
|
public ControllerList remove( final ControllerInterface< ? > theController ) {
|
||||||
drawables.remove( theController );
|
if ( !isEmpty( ) ) synchronized ( controllers ) {
|
||||||
|
controllers.remove( theController );
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControllerInterface< ? > get( int theIndex ) {
|
public ControllerList removeDrawable( final CDrawable theController ) {
|
||||||
|
if ( !isEmptyDrawable( ) ) synchronized ( drawables ) {
|
||||||
|
drawables.remove( theController );
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControllerList clear( ) {
|
||||||
|
if ( !isEmpty( ) ) synchronized ( controllers ) {
|
||||||
|
controllers.clear( );
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControllerList clearDrawable( ) {
|
||||||
|
if ( !isEmptyDrawable( ) ) synchronized ( drawables ) {
|
||||||
|
drawables.clear( );
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControllerInterface< ? > get( final int theIndex ) {
|
||||||
return controllers.get( theIndex );
|
return controllers.get( theIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +85,7 @@ public class ControllerList {
|
|||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CDrawable getDrawable( int theIndex ) {
|
public CDrawable getDrawable( final int theIndex ) {
|
||||||
return drawables.get( theIndex );
|
return drawables.get( theIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,20 +93,27 @@ public class ControllerList {
|
|||||||
return drawables;
|
return drawables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int sizeDrawable( ) {
|
public boolean contains( final ControllerInterface< ? > theController ) {
|
||||||
return drawables.size( );
|
return controllers.contains( theController );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsDrawable( final CDrawable theController ) {
|
||||||
|
return drawables.contains( theController );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty( ) {
|
||||||
|
return controllers.isEmpty( );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmptyDrawable( ) {
|
||||||
|
return drawables.isEmpty( );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size( ) {
|
public int size( ) {
|
||||||
return controllers.size( );
|
return controllers.size( );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clear( ) {
|
public int sizeDrawable( ) {
|
||||||
controllers.clear( );
|
return drawables.size( );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void clearDrawable( ) {
|
|
||||||
drawables.clear( );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user