refactored folder structure to a more conventional maven structure

This commit is contained in:
Gabriel Salvador 2023-07-09 14:33:50 +01:00
parent 977fad1799
commit bbc6ce6e6b
438 changed files with 34072 additions and 4419 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="processing">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/processing.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/resources/addons/addons.iml" filepath="$PROJECT_DIR$/resources/addons/addons.iml" />
<module fileurl="file://$PROJECT_DIR$/controlp5.iml" filepath="$PROJECT_DIR$/controlp5.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/examples.iml" filepath="$PROJECT_DIR$/examples/examples.iml" />
<module fileurl="file://$PROJECT_DIR$/resources/resources.iml" filepath="$PROJECT_DIR$/resources/resources.iml" />
</modules>

287
controlP5/Accordion.java Executable file
View File

@ -0,0 +1,287 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* <p>
* An Accordion here is a list of ControlGroups which can be expanded and collapsed.
*
* @see ControllerGroup
* @see ControlGroup
* @example controllers/ControlP5accordion
*/
@SuppressWarnings( "rawtypes" ) public class Accordion extends ControlGroup< Accordion > {
protected int spacing = 1;
protected int minHeight = 100;
protected int itemheight;
protected int _myMode = SINGLE;
public Accordion( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 200 );
theControlP5.register( theControlP5.papplet , theName , this );
}
Accordion( ControlP5 theControlP5 , Tab theTab , String theName , int theX , int theY , int theW ) {
super( theControlP5 , theTab , theName , theX , theY , theW , 9 );
hideBar( );
}
/**
* Adds items of type ControlGroup to the Accordion, only ControlGroups can be added.
*
* @exclude
* @param theGroup
* @return Accordion
*/
public Accordion addItem( ControlGroup< ? > theGroup ) {
theGroup.close( );
theGroup.moveTo( this );
theGroup.activateEvent( true );
theGroup.addListener( this );
theGroup.setMoveable( false );
if ( theGroup.getBackgroundHeight( ) < minHeight ) {
theGroup.setBackgroundHeight( minHeight );
}
controllers.add( theGroup );
updateItems( );
return this;
}
/**
* Removes a ControlGroup from the accordion AND from controlP5 remove(ControllerInterface
* theGroup) overwrites it's super method. if you want to remove a ControlGroup only from the
* accordion, use removeItem(ControlGroup).
*
* @see controlP5.Accordion#removeItem(ControlGroup)
* @return ControllerInterface
*/
@Override public Accordion remove( ControllerInterface< ? > theGroup ) {
if ( theGroup instanceof ControlGroup< ? > ) {
controllers.remove( theGroup );
( ( ControlGroup< ? > ) theGroup ).removeListener( this );
updateItems( );
}
super.remove( theGroup );
return this;
}
/**
* Removes a ControlGroup from the accordion and puts it back into the default tab of controlP5.
* if you dont have access to a ControlGroup via a variable, use
* controlP5.group("theNameOfTheGroup") which will return a
*
* @return Accordion
*/
public Accordion removeItem( ControlGroup< ? > theGroup ) {
if ( theGroup == null ) {
return this;
}
controllers.remove( theGroup );
theGroup.removeListener( this );
theGroup.moveTo( cp5.controlWindow );
updateItems( );
return this;
}
/**
* UpdateItems is called when changes such as remove, change of height is performed on an
* accordion. updateItems() is called automatically for such cases, but by calling updateItems
* manually an update will be forced.
*
* @return Accordion
*/
public Accordion updateItems( ) {
int n = 0;
setWidth( _myWidth );
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
n += ( ( ControlGroup ) cg ).getBarHeight( ) + spacing;
cg.setPosition( 0 , n );
if ( ( ( ControlGroup ) cg ).isOpen( ) ) {
n += ( ( ControlGroup ) cg ).getBackgroundHeight( );
}
}
}
return this;
}
/**
* Sets the minimum height of a collapsed item, default value is 100.
*
* @param theHeight
* @return Accordion
*/
public Accordion setMinItemHeight( int theHeight ) {
minHeight = theHeight;
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
if ( ( ( ControlGroup ) cg ).getBackgroundHeight( ) < minHeight ) {
( ( ControlGroup ) cg ).setBackgroundHeight( minHeight );
}
}
}
updateItems( );
return this;
}
public int getMinItemHeight( ) {
return minHeight;
}
public Accordion setItemHeight( int theHeight ) {
itemheight = theHeight;
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
( ( ControlGroup ) cg ).setBackgroundHeight( itemheight );
}
}
updateItems( );
return this;
}
public int getItemHeight( ) {
return itemheight;
}
@Override public Accordion setWidth( int theWidth ) {
super.setWidth( theWidth );
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
( ( ControlGroup ) cg ).setWidth( theWidth );
}
}
return this;
}
/**
* @exclude {@inheritDoc}
*/
@Override @ControlP5.Invisible public void controlEvent( ControlEvent theEvent ) {
if ( theEvent.isGroup( ) ) {
int n = 0;
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
n += ( ( ControlGroup ) cg ).getBarHeight( ) + spacing;
cg.setPosition( 0 , n );
if ( _myMode == SINGLE ) {
if ( cg == theEvent.getGroup( ) && ( ( ControlGroup ) cg ).isOpen( ) ) {
n += ( ( ControlGroup ) cg ).getBackgroundHeight( );
} else {
( ( ControlGroup ) cg ).close( );
}
} else {
if ( ( ( ControlGroup ) cg ).isOpen( ) ) {
n += ( ( ControlGroup ) cg ).getBackgroundHeight( );
}
}
}
}
}
}
public Accordion open( ) {
int[] n = new int[ controllers.size( ) ];
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
n[ i ] = i;
}
return open( n );
}
public Accordion close( ) {
int[] n = new int[ controllers.size( ) ];
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
n[ i ] = i;
}
return close( n );
}
public Accordion open( int ... theId ) {
if ( theId[ 0 ] == -1 ) {
return open( );
}
int n = 0 , i = 0;
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
boolean a = false;
for ( int j = 0 ; j < theId.length ; j++ ) {
if (theId[j] == i) {
a = true;
break;
}
}
boolean b = ((ControlGroup) cg).isOpen() || a;
i++;
n += ( ( ControlGroup ) cg ).getBarHeight( ) + spacing;
cg.setPosition( 0 , n );
if ( b ) {
n += ( ( ControlGroup ) cg ).getBackgroundHeight( );
( ( ControlGroup ) cg ).open( );
}
}
}
return this;
}
public Accordion close( int ... theId ) {
if ( theId[ 0 ] == -1 ) {
return close( );
}
int n = 0 , i = 0;
for ( ControllerInterface< ? > cg : controllers.get( ) ) {
if ( cg instanceof ControlGroup ) {
boolean a = false;
for ( int j = 0 ; j < theId.length ; j++ ) {
if (theId[j] == i) {
a = true;
break;
}
}
boolean b = !((ControlGroup) cg).isOpen() || a;
i++;
n += ( ( ControlGroup ) cg ).getBarHeight( ) + spacing;
( ( ControlGroup ) cg ).setPosition( 0 , n );
if ( b ) {
( ( ControlGroup ) cg ).close( );
} else {
n += ( ( ControlGroup ) cg ).getBackgroundHeight( );
}
}
}
return this;
}
public Accordion setCollapseMode( int theMode ) {
if ( theMode == 0 ) {
_myMode = SINGLE;
} else {
_myMode = MULTI;
}
return this;
}
}

37
controlP5/Background.java Normal file
View File

@ -0,0 +1,37 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
public class Background extends ControlGroup< Background > {
public Background( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theParent , theName , theX , theY , theW , theH );
hideBar( );
setBackgroundColor( 0x55000000 );
setSize(theW, theH);
}
}

205
controlP5/Bang.java Executable file
View File

@ -0,0 +1,205 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* <p>
* The Bang controller triggers an event when pressed. A bang can only be assigned to a function in
* your program but not to a field like other controllers. Bang extends superclass Controller, for a
* full documentation see the {@link Controller} reference.
*
* @example controllers/ControlP5bang
*/
@ControlP5.Layout public class Bang extends Controller< Bang > {
protected int cnt;
protected int triggerId = PRESSED;
/**
* Convenience constructor to extend Bang.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Bang( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 20 , 20 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Bang( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myCaptionLabel.setPadding( 0 , Label.paddingY ).align( LEFT , BOTTOM_OUTSIDE );
_myValue = 1;
}
@Override protected void onEnter( ) {
cnt = 0;
isActive = true;
}
@Override protected void onLeave( ) {
isActive = false;
}
@Override protected void mousePressed( ) {
if ( triggerId == PRESSED ) {
cnt = -3;
isActive = true;
update( );
}
}
@Override protected void mouseReleased( ) {
if ( triggerId == RELEASE ) {
cnt = -3;
isActive = true;
update( );
}
}
@Override protected void mouseReleasedOutside( ) {
onLeave( );
}
/**
* By default a bang is triggered when the mouse is pressed. use setTriggerEvent(Bang.PRESSED)
* or setTriggerEvent(Bang.RELEASE) to define the action for triggering a bang. currently only
* Bang.PRESSED and Bang.RELEASE are supported.
*
* @param theEventID
* @return Bang
*/
@ControlP5.Layout public Bang setTriggerEvent( int theEventID ) {
triggerId = theEventID;
return this;
}
@ControlP5.Layout public int getTriggerEvent( ) {
return triggerId;
}
/**
* Sets the value of the bang controller. since bang can be true or false, false=0 and true=1
*
* @param theValue float
* @return Bang
*/
@Override public Bang setValue( float theValue ) {
_myValue = theValue;
broadcast( FLOAT );
return this;
}
/**
* @exclude
*/
@Override public Bang update( ) {
return setValue( _myValue );
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public Bang updateDisplayMode( int theMode ) {
updateViewMode( theMode );
return this;
}
/**
* @exclude
*/
@ControlP5.Invisible public Bang updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new BangView( );
break;
case ( IMAGE ):
_myControllerView = new BangImageView( );
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
private class BangView implements ControllerView< Bang > {
public void display( PGraphics theGraphics , Bang theController ) {
if ( isActive ) {
theGraphics.fill( color.getActive( ) );
} else {
theGraphics.fill( color.getForeground( ) );
}
if ( cnt < 0 ) {
theGraphics.fill( color.getForeground( ) );
cnt++;
}
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}
private class BangImageView implements ControllerView< Bang > {
public void display( PGraphics theGraphics , Bang theController ) {
if ( isActive ) {
theGraphics.image( (availableImages[ACTIVE]) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 );
} else {
theGraphics.image( (availableImages[OVER]) ? images[ OVER ] : images[ DEFAULT ] , 0 , 0 );
}
if ( cnt < 0 ) {
theGraphics.image( (availableImages[OVER]) ? images[ OVER ] : images[ DEFAULT ] , 0 , 0 );
cnt++;
}
}
}
/**
* {@inheritDoc}
*
* @exclude
*/
@Override public String getInfo( ) {
return "type:\tBang\n" + super.getInfo( );
}
/**
* @exclude {@inheritDoc}
*/
@Override public String toString( ) {
return super.toString( ) + " [ " + getValue( ) + " ] " + "Bang" + " (" + this.getClass( ).getSuperclass( ) + ")";
}
}

203
controlP5/BitFont.java Executable file
View File

@ -0,0 +1,203 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Constructor;
import java.util.Arrays;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;
public class BitFont extends PFont {
static public final String standard58base64 = "AakACQBgACAEAgQGBggGAgMDBAYDBAIGBQMFBQUFBQUFBQICBAUEBQgFBQUFBQUFBQIFBQQGBQUFBQUFBAUGCAUGBQMFAwYGAwQEBAQEBAQEAgQEAgYEBAQEAwQEBAQGBAQEBAIEBQKgUgghIaUAAIiRMeiZZwwAAANgjjnvmRRKESVzzDGXoqQUvYURQCCAQCCSCAAAAAgAAABEqECleCVFkRAAiLSUWEgoJQAAiSOllEJIKVRiSymllCRFSSlCEVIAQQBBQAARAAAAEAAAACQpgeALJASiIwAQSQipE1BKRS+QSEohhRBSqES1UkopSIqSkkIiFAGwEZOwSaplZGx2VVXVSQIAgeIgSETy4RCSCEnoEONAgJCkd0I6p73QiKilk46RpCQZQoQIAFBVVVOVVFVVVUKqqiqKCACCDyKpiIoAICQJ9FAiCUE8ElUphRRCSqESUUohJSRJSUpECBEAoCrqoiqZqqqqiFRVUiIJAADKI5UQASEgSAoJpSRSCgECUlJKKYSUSiWilEJKSRKRlIgQJABAVVVEVVJVVVUhqaqqQhIACBQixEIBQFBg9AwyRhhDBEIIpGPOCyZl0kXJBJOMGMImEW9owAcbMQmrpKpKxjJiopQdFQAAAAAAAABAAAAAAAAAAIAAAOAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAQIAAAEAQAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAgAAAgCAAAAAgAA";
static public final String standard56base64 = "AeYACQBgACAEAgQGBggHAgMDBgYDBQIFBgMGBgYGBgYGBgIDBAYEBggGBgYGBgYGBgIGBgUIBgYGBgYGBgYGCAYGBgMFAwYHAwUFBQUFAwUFAgMFAggFBQUFBAQEBQUIBQUFBAMEBQKgUgghRwoBAIAcOQ7yOZ/jAADAAXAe5/k+JwqKQlDkPM7jfFGUFEXfwghAQAAICIQUAgAAAAABAAAAQAkVqBSvJFJUEQCQaFHEBBEURQAAiDiiKIqCIIqCkjAWRVEURUQUJUURFCEFIBAAAgEBhAAAAABAAAAAAEikBIIvkFAQOQQAJBIEKU8ARVGiLyCRKAqiIAiioCJUTVEURQERRUmKgkQoAsAd40zcSambY447u5SSUnoSAYBAcRBMRNWHh4iEMAn0II4HBBAk6XuC6HmyL2gISVX0RI9DREoSQRAhAgBIKaW0lFIpKaWUIiSlpJRQhAAg+CCSFBFBACAiEdAHRUgEgfiIqIqiIAqCKAoqQlAWBVEBEZGSpBBCiAAAUgrpJaU0SkoppRBJKckkIxEAAJRHKkIEEACESEKERBERRUEAAVKiKIqCIIqKkhAURUGUREREJEVEECQAgJRSCkkplZJSSilIUkpKKUgEAAKFCHGhAIBAwdHnII5DOA4iIAiB6HGeL3CinOgFRU7gRA7hEDYR8QUJ+MEd40xcSqmkZI6LEWdsknsSAQAAAAAAAAAgAAAAAAAAAACAAACAAwAAAAAAAAAAAAAAQAAAAAAAAAADAwAAAAAABBAAAICAAAAAAIAAJQAAAAAAAAAABAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAACAAAgIAAAAAAYAAA=";
static public final String grixelbase64 = "AnoADABgACAFAgQICAoIAgQEBgYDBQIKCQMICAgICAcICAIDBQYFBwkICAgIBwcICAYHCAcJCAgICAgICAgICggICAQKBAQHBAcHBwcHBQcHAgUHBAoHBwcHBgcGBwcKBwcHBQIFCAJAJeIjkENBAAAAQHzk4wPz5/Pz8QEAAB4ePj8+Pz6fX9AHCgoECvL58fnx+QsKiigo6C8CIAEIIAAAARwgEAoEAAAAAAAABAAAAAAAICIAAZVIUiERBQEAAIAIWlAQSkAQKCgIICCEhAQFBQUFAgFBBCgoMGwoKCgoKAghKCiioCCgEIAKQIAAAAQIgAAgEAAAAAAAABAAAAAAAICIsAUEfwlCRBCkEAAAIUhAQCQBAaCgIEAAAcoUFBQQFAgEBBGgoECpoqCgoKAAhKCgiEREQIIAAgAAAgAQIAACgEAAAAAAAABAAAAAAAAAIrIBEIgkgBBBEEEAAIIgAQGJ/ARAgoKS+AioVFBQQFAgEBBEgEICmZKCgoKCAhCCgiKioIAIBAgA4Pl4fJ7n+YRC8c7H8/F5ni8UiigU+okIAEAg4gOBA0HfhwcEguTDEwL0g/DxAwFAoFJ/PwFBv1/eHwH6CASKCgoKCvJBCAqKCAEBISAgAAAoFAqFQigUikREoVAoFISEUCgiSQgSQgAAgQgSAlEEEQQACAhSANAfUBAhCAiIj2BKBQUFBAUCQUEEKCQQKCzoJ+gHCCEoKCIKBIIAgQAAvlAg9AuhUOgREYVCoVBgEEKhiBghhIgAAAB/SITEEKQQABAgSAFAIEBBhCAgQABByBMUFBAUCAQFEaGgQKCgoICgECCEIJGIRBAEAggCAIRCgVAghEKhSEQUCoVCAUYIhSJihAgiAgAAiCQJFUMQAAgggCAFBIEEBRGCghACAkBAUFBQUCAQFESEggKBgoICkoKCEIIoIgpCCAhACAAQCoVCoRAKhUIRUSgUCgUhISSJSBISiAgAQCDiE4gTQQAgUAB89OcD4uND8PFJAAAEfkE/Pj++gF/Q5wn6BQryCfAJ8kHwQXAnCOEvACIAgM/j8XiCLxQKWUQhz8cXeDgPw52Q7yciAAAAAAIAANgAQAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAgAPg4AcAAAAAACAACAAAAAABEAAAAAAAACAAawAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4ABgAAAAABEAAAAAAAAB4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
protected int characters;
protected int[] charWidth = new int[ 255 ];
protected int charHeight;
protected int[][] chars;
protected int lineHeight = 10;
protected int kerning = 0;
protected int wh;
protected PImage texture;
public static int defaultChar = 32;
public BitFont( byte[] theBytes ) {
super( );
texture = decodeBitFont( theBytes );
make( );
size = lineHeight;
glyphs = new Glyph[ 256 ];
ascii = new int[ 128 ];
Arrays.fill( ascii , -1 );
lazy = false;
ascent = 4;
descent = 4;
glyphCount = 128;
for ( int i = 0 ; i < 128 ; i++ ) {
// unfortunately the PFont.Glyph constructor in
// the android source code is for whatever
// reason protected and not public like in the
// java application source, therefore the
// bitfont will only be used in the java
// application mode until changes to the
// processing core code have been made. see
// issue
// http://code.google.com/p/processing/issues/detail?id=1293
try {
Constructor< PFont.Glyph >[] constructors = ( Constructor< PFont.Glyph >[] ) PFont.Glyph.class.getDeclaredConstructors( );
Constructor< PFont.Glyph > constructor = ( Constructor< PFont.Glyph > ) PFont.Glyph.class.getDeclaredConstructors( )[ 0 ];
constructor.setAccessible( true );
for ( Constructor< PFont.Glyph > c : constructors ) {
c.setAccessible( true );
if ( c.getParameterTypes( ).length == 1 ) {
glyphs[ i ] = c.newInstance( this );
break;
}
}
} catch ( Exception e ) {
System.out.println( e );
}
// as soon as the constructor is public, the
// line below will replace the hack above
// glyphs[i] = new Glyph();
glyphs[ i ].value = i;
if ( glyphs[ i ].value < 128 ) {
ascii[ glyphs[ i ].value ] = i;
}
glyphs[ i ].index = i;
int id = i - 32;
if ( id >= 0 ) {
glyphs[ i ].image = new PImage( charWidth[ id ] , 9 , PConstants.ALPHA );
for ( int n = 0 ; n < chars[ id ].length ; n++ ) {
glyphs[ i ].image.pixels[ n ] = ( chars[ id ][ n ] == 1 ) ? 0xffffffff : 0x00000000;
}
glyphs[ i ].height = 9;
glyphs[ i ].width = charWidth[ id ];
glyphs[ i ].index = i;
glyphs[ i ].value = i;
glyphs[ i ].setWidth = charWidth[ id ];
glyphs[ i ].topExtent = 4;
glyphs[ i ].leftExtent = 0;
} else {
glyphs[ i ].image = new PImage( 1 , 1 );
}
}
}
public Glyph getGlyph( char c ) {
int n = c;
/* if c is out of the BitFont-glyph bounds, return
* the defaultChar glyph (the space char by
* default). */
n = ( n >= 128 ) ? defaultChar : n;
return glyphs[ n ];
}
PImage decodeBitFont( byte[] bytes ) {
PImage tex;
// read width
int w = CP.byteArrayToInt( new byte[] { bytes[ 0 ] , bytes[ 1 ] } );
// read height
int h = CP.byteArrayToInt( new byte[] { bytes[ 2 ] , bytes[ 3 ] } );
// read size of chars
int s = CP.byteArrayToInt( new byte[] { bytes[ 4 ] , bytes[ 5 ] } );
// read first ascii char
int c = CP.byteArrayToInt( new byte[] { bytes[ 6 ] , bytes[ 7 ] } );
tex = new PImage( w , h , PApplet.ALPHA );
// read bytes and write pixels into image
int off = 8 + s;
for ( int i = off ; i < bytes.length ; i++ ) {
for ( int j = 0 ; j < 8 ; j++ ) {
tex.pixels[ ( i - off ) * 8 + j ] = CP.getBit( bytes[ i ] , j ) == 1 ? 0xff000000 : 0xffffffff;
}
}
int cnt = 0 , n = 0 , i = 0;
// add character seperators on top of the texture
for ( i = 0 ; i < s ; i++ ) {
while ( ++cnt != bytes[ i + 8 ] ) {
}
n += cnt;
tex.pixels[ n ] = 0xffff0000;
cnt = 0;
}
return tex;
}
int getHeight( ) {
return texture.height;
}
BitFont make( ) {
charHeight = texture.height;
lineHeight = charHeight;
int currWidth = 0;
for ( int i = 0 ; i < texture.width ; i++ ) {
currWidth++;
if ( texture.pixels[ i ] == 0xffff0000 ) {
charWidth[ characters++ ] = currWidth;
currWidth = 0;
}
}
chars = new int[ characters ][];
int indent = 0;
for ( int i = 0 ; i < characters ; i++ ) {
chars[ i ] = new int[ charWidth[ i ] * charHeight ];
for ( int u = 0 ; u < charWidth[ i ] * charHeight ; u++ ) {
chars[ i ][ u ] = texture.pixels[ indent + ( u / charWidth[ i ] ) * texture.width + ( u % charWidth[ i ] ) ] == 0xff000000 ? 1 : 0;
}
indent += charWidth[ i ];
}
return this;
}
}

316
controlP5/Button.java Executable file
View File

@ -0,0 +1,316 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser
* General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at
* your option) any later version. This library is
* distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* <p>
* A button triggers an event after it has been release.
* Events can be linked to functions and fields inside your
* program/sketch. for a full documentation of this
* controller see the {@link Controller} class.
*
* @example controllers/ControlP5button
*/
public class Button extends Controller< Button > {
protected boolean isPressed;
protected boolean isOn = false;
public static int autoWidth = 69;
public static int autoHeight = 19;
protected int activateBy = RELEASE;
protected boolean isSwitch = false;
/**
* Convenience constructor to extend Button.
*
* @example use/ControlP5extendController
*/
public Button( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Button( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myValue = theDefaultValue;
_myCaptionLabel.align( CENTER , CENTER );
}
/**
* @exclude
*/
public Button( ) {
super( null , null , null , 0 , 0 , 1 , 1 );
}
@Override protected void onEnter( ) {
isActive = true;
}
@Override protected void onLeave( ) {
isActive = false;
setIsInside( false );
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mousePressed( ) {
isActive = getIsInside( );
isPressed = true;
if ( activateBy == PRESSED ) {
activate( );
}
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mouseReleased( ) {
isPressed = false;
if ( activateBy == RELEASE ) {
activate( );
}
isActive = false;
}
/**
* A button can be activated by a mouse PRESSED or mouse
* RELEASE. Default value is RELEASE.
*
* @param theValue use ControlP5.PRESSED or
* ControlP5.RELEASE as parameter
* @return Button
*/
public Button activateBy( int theValue ) {
if ( theValue == PRESS ) {
activateBy = PRESS;
} else {
activateBy = RELEASE;
}
return this;
}
protected void activate( ) {
if ( isActive ) {
isActive = false;
isOn = !isOn;
setValue( _myValue );
}
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mouseReleasedOutside( ) {
mouseReleased( );
}
/**
* {@inheritDoc}
*/
@Override public Button setValue( float theValue ) {
_myValue = theValue;
broadcast( FLOAT );
return this;
}
/**
* {@inheritDoc}
*/
@Override public Button update( ) {
return setValue( _myValue );
}
/**
* Turns a button into a switch, or use a Toggle
* instead.
*
*/
public Button setSwitch( boolean theFlag ) {
isSwitch = theFlag;
if ( isSwitch ) {
_myBroadcastType = BOOLEAN;
} else {
_myBroadcastType = FLOAT;
}
return this;
}
/**
* If the button acts as a switch, setOn will turn on
* the switch. Use
* {@link Button#setSwitch(boolean) setSwitch}
* to turn a Button into a Switch.
*
* @return Button
*/
public Button setOn( ) {
if ( isSwitch ) {
isOn = false;
isActive = true;
activate( );
}
return this;
}
/**
* If the button acts as a switch, setOff will turn off
* the switch. Use
* {@link Button#setSwitch(boolean) setSwitch}
* to turn a Button into a Switch.
*
* @return Button
*/
public Button setOff( ) {
if ( isSwitch ) {
isOn = true;
isActive = true;
activate( );
}
return this;
}
/**
* @return boolean
*/
public boolean isOn( ) {
return isOn;
}
public boolean isSwitch( ) {
return isSwitch;
}
/**
* @return boolean
*/
public boolean isPressed( ) {
return isPressed;
}
/**
* Returns true or false and indicates the switch state
* of the button. {@link setSwitch(boolean) setSwitch}
* should have been set before.
*
* @see Button#setSwitch(boolean)
* @return boolean
*/
public boolean getBooleanValue( ) {
return isOn;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public Button updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
/**
* @exclude
*/
@ControlP5.Invisible public Button updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new ButtonView( );
break;
case ( IMAGE ):
_myControllerView = new ButtonImageView( );
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
private class ButtonView implements ControllerView< Button > {
public void display( PGraphics theGraphics , Button theController ) {
theGraphics.noStroke( );
if ( isOn && isSwitch ) {
theGraphics.fill( color.getActive( ) );
} else {
if ( getIsInside( ) ) {
if ( isPressed ) {
theGraphics.fill( color.getActive( ) );
} else {
theGraphics.fill( color.getForeground( ) );
}
} else {
theGraphics.fill( color.getBackground( ) );
}
}
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}
private class ButtonImageView implements ControllerView< Button > {
public void display( PGraphics theGraphics , Button theController ) {
if ( isOn && isSwitch ) {
theGraphics.image( (availableImages[HIGHLIGHT]) ? images[ HIGHLIGHT ] : images[ DEFAULT ] , 0 , 0 );
return;
}
if ( getIsInside( ) ) {
if ( isPressed ) {
theGraphics.image( (availableImages[ACTIVE]) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 );
} else {
theGraphics.image( (availableImages[OVER]) ? images[ OVER ] : images[ DEFAULT ] , 0 , 0 );
}
} else {
theGraphics.image( images[ DEFAULT ] , 0 , 0 );
}
}
}
/**
* @exclude
*/
@Override public String getInfo( ) {
return "type:\tButton\n" + super.getInfo( );
}
/**
* @exclude
*/
@Override public String toString( ) {
return super.toString( ) + " [ " + getValue( ) + " ] " + "Button" + " (" + this.getClass( ).getSuperclass( ) + ")";
}
}

244
controlP5/ButtonBar.java Normal file
View File

@ -0,0 +1,244 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import static main.java.src2.main.java.controlP5.controlP5.ControlP5.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static main.java.src2.main.java.controlP5.controlP5.ControlP5.s;
import processing.core.PGraphics;
public class ButtonBar extends Controller< ButtonBar > {
public static int autoWidth = 69;
public static int autoHeight = 19;
private final List< Map< String , Object >> items = new ArrayList< Map< String , Object >>( );
/**
* Convenience constructor to extend ButtonBar.
*/
public ButtonBar( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected ButtonBar( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
}
@Override
@ControlP5.Invisible
public ButtonBar updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
public void changeItem( String theItem , String theKey , Object theValue ) {
Map m = modifiableItem( theItem );
if ( !m.equals( Collections.EMPTY_MAP ) ) {
m.put( theKey , theValue );
}
}
private Map modifiableItem( String theItem ) {
if ( theItem != null ) {
for ( Map< String , Object > o : items ) {
if ( theItem.equals( o.get( "name" ) ) ) {
return o;
}
}
}
return Collections.EMPTY_MAP;
}
public Map getItem( String theItem ) {
return Collections.unmodifiableMap( modifiableItem( theItem ) );
}
@ControlP5.Invisible
public ButtonBar updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new ButtonBarView( );
break;
case ( IMAGE ):
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
@Override
public void onClick( ) {
int index = hover( );
if ( index > -1 ) {
for ( Map m : items ) {
m.put( "selected" , false );
}
items.get( index ).put( "selected" , true );
setValue( hover( ) );
}
}
public int hover( ) {
int w = getWidth( ) / ( items.isEmpty( ) ? 1 : items.size( ) );
int h = getHeight( );
for ( int i = 0 ; i < items.size( ) ; i++ ) {
if ( getPointer( ).x( ) >= i * w && getPointer( ).x( ) < ( i + 1 ) * w ) {
return i;
}
}
return -1;
}
private class ButtonBarView implements ControllerView< ButtonBar > {
public void display( PGraphics theGraphics , ButtonBar theController ) {
theGraphics.noStroke( );
theGraphics.fill( color.getBackground( ) );
theGraphics.rect( 0 , 0 , theController.getWidth( ) , theController.getHeight( ) );
int index = hover( );
int w = theController.getWidth( ) / ( items.isEmpty( ) ? 1 : items.size( ) );
int h = theController.getHeight( );
theGraphics.textFont( theController.getValueLabel( ).getFont( ).pfont );
theGraphics.pushMatrix( );
for ( int i = 0 ; i < items.size( ) ; i++ ) {
int c = ControlP5.b( items.get( i ).get( "selected" ) , false ) ? color.getActive( ) : ( isInside( ) && index == i ) ? isMousePressed ? color.getActive( ) : color.getForeground( ) : color.getBackground( );
theGraphics.fill( c );
theGraphics.rect( 0 , 0 , w , h );
theGraphics.fill( theController.getValueLabel( ).getColor( ) );
theController.getValueLabel( ).set( ControlP5.s( items.get( i ).get( "text" ) ) ).align( CENTER , CENTER ).draw( theGraphics , 0 , 0 , w , h );
theGraphics.translate( w , 0 );
}
theGraphics.popMatrix( );
}
}
private Map< String , Object > getDefaultItemMap( String theName , Object theValue ) {
Map< String , Object > item = new HashMap< String , Object >( );
item.put( "name" , theName );
item.put( "text" , theName );
item.put( "value" , theValue );
item.put( "color" , getColor( ) );
item.put( "view" , new CDrawable( ) {
@Override
public void draw( PGraphics theGraphics ) {
}
} );
item.put( "selected" , false );
return item;
}
public ButtonBar addItem( String theName , Object theValue ) {
Map< String , Object > item = getDefaultItemMap( theName , theValue );
items.add( item );
return this;
}
public ButtonBar addItems( String[] theItems ) {
addItems( Arrays.asList( theItems ) );
return this;
}
public ButtonBar addItems( List< String > theItems ) {
for ( int i = 0 ; i < theItems.size( ) ; i++ ) {
addItem(theItems.get( i ), i );
}
return this;
}
public ButtonBar addItems( Map< String , Object > theItems ) {
for ( Map.Entry< String , Object > item : theItems.entrySet( ) ) {
addItem( item.getKey( ) , item.getValue( ) );
}
return this;
}
public ButtonBar setItems( String[] theItems ) {
setItems( Arrays.asList( theItems ) );
return this;
}
public ButtonBar setItems( List< String > theItems ) {
items.clear( );
return addItems( theItems );
}
public ButtonBar setItems( Map< String , Object > theItems ) {
items.clear( );
return addItems( theItems );
}
public ButtonBar removeItems( List< String > theItems ) {
for ( String s : theItems ) {
removeItem( s );
}
return this;
}
public ButtonBar removeItem( String theName ) {
if ( theName != null ) {
List l = new ArrayList( );
for ( Map m : items ) {
if ( theName.equals( m.get( "name" ) ) ) {
l.add( m );
}
}
items.removeAll( l );
}
return this;
}
private Map< String , Object > getItem( int theIndex ) {
return items.get( theIndex );
}
public List getItems( ) {
return Collections.unmodifiableList( items );
}
public ButtonBar clear( ) {
for ( int i = items.size( ) - 1 ; i >= 0 ; i-- ) {
items.remove( i );
}
items.clear( );
return this;
}
}

203
controlP5/CColor.java Executable file
View File

@ -0,0 +1,203 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version. This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.Serializable;
/**
* A CColor instance contains the colors of a controller including the foreground-, background-,
* active-, captionlabel- and valuelabel-colors.
*/
@SuppressWarnings( "serial" )
public class CColor implements Serializable {
private int colorBackground = 0xff003652;
private int colorForeground = 0xff00698c;
private int colorActive = 0xff08a2cf; // 0699C4;
private int colorCaptionLabel = 0xffffffff;
private int colorValueLabel = 0xffffffff;
private int colorBackgroundAlpha = 0xff;
private int colorForegroundAlpha = 0xff;
private int colorActiveAlpha = 0xff; // 0699C4;
private int colorCaptionLabelAlpha = 0xff;
private int colorValueLabelAlpha = 0xff;
private final int alpha = 0xff;
private final int maskA = 0x00ffffff;
int maskR = 0xff00ffff;
int maskG = 0xffff00ff;
int maskB = 0xffffff00;
protected CColor set( CColor theColor ) {
colorBackground = theColor.colorBackground;
colorForeground = theColor.colorForeground;
colorActive = theColor.colorActive;
colorCaptionLabel = theColor.colorCaptionLabel;
colorValueLabel = theColor.colorValueLabel;
colorBackgroundAlpha = theColor.colorBackgroundAlpha;
colorForegroundAlpha = theColor.colorForegroundAlpha;
colorActiveAlpha = theColor.colorActiveAlpha;
colorCaptionLabelAlpha = theColor.colorCaptionLabelAlpha;
colorValueLabelAlpha = theColor.colorValueLabelAlpha;
return this;
}
protected CColor copyTo( ControllerInterface< ? > theControl ) {
theControl.setColorBackground( colorBackground );
theControl.setColorForeground( colorForeground );
theControl.setColorActive( colorActive );
theControl.setColorLabel( colorCaptionLabel );
return this;
}
/**
* @exclude {@inheritDoc}
*/
public String toString( ) {
return ( "bg (" + ( colorBackground >> 16 & 0xff ) + "," + ( colorBackground >> 8 & 0xff ) + "," + ( colorBackground >> 0 & 0xff ) + "), " + "fg (" + ( colorForeground >> 16 & 0xff ) + "," + ( colorForeground >> 8 & 0xff ) + ","
+ ( colorForeground >> 0 & 0xff ) + "), " + "active (" + ( colorActive >> 16 & 0xff ) + "," + ( colorActive >> 8 & 0xff ) + "," + ( colorActive >> 0 & 0xff ) + "), " + "captionlabel (" + ( colorCaptionLabel >> 16 & 0xff ) + ","
+ ( colorCaptionLabel >> 8 & 0xff ) + "," + ( colorCaptionLabel >> 0 & 0xff ) + "), " + "valuelabel (" + ( colorValueLabel >> 16 & 0xff ) + "," + ( colorValueLabel >> 8 & 0xff ) + "," + ( colorValueLabel >> 0 & 0xff ) + ")" );
}
public CColor( ) {
set( ControlP5.getColor( ) );
}
public CColor( int cfg , int cbg , int cactive , int ccl , int cvl ) {
setForeground( cfg );
setBackground( cbg );
setActive( cactive );
setCaptionLabel( ccl );
setValueLabel( cvl );
}
public CColor( CColor theColor ) {
set( theColor );
}
/**
* @exclude
* @param theAlpha
*/
public CColor setAlpha( int theAlpha ) {
System.out.println( "main.java.src2.main.java.controlP5.controlp5.CColor.setAlpha: setting alpha values disabled for this version of controlP5." );
return this;
}
public CColor setForeground( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorForeground = 0xff000000;
} else {
colorForeground = theColor;
}
return this;
}
public CColor setBackground( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorBackground = 0xff000000;
} else {
colorBackground = theColor;
}
return this;
}
public CColor setActive( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorActive = 0xff000000;
} else {
colorActive = theColor;
}
return this;
}
public CColor setCaptionLabel( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorCaptionLabel = 0xff000000;
} else {
colorCaptionLabel = theColor;
}
return this;
}
public CColor setValueLabel( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorValueLabel = 0xff000000;
} else {
colorValueLabel = theColor;
}
return this;
}
public int getAlpha( ) {
return alpha;
}
public int getForeground( ) {
return colorForeground;
}
public int getBackground( ) {
return colorBackground;
}
public int getActive( ) {
return colorActive;
}
public int getCaptionLabel( ) {
return colorCaptionLabel;
}
public int getValueLabel( ) {
return colorValueLabel;
}
/**
* @exclude {@inheritDoc}
*/
public int hashCode( ) {
int result = 23;
result = 37 * result + colorBackground;
result = 37 * result + colorForeground;
result = 37 * result + colorActive;
return result;
}
/**
* @exclude {@inheritDoc}
*/
public boolean equals( Object o ) {
if ( this == o ) {
return true;
}
if ( o == null || getClass( ) != o.getClass( ) ) {
return false;
}
CColor cc = ( CColor ) o;
return colorBackground == cc.colorBackground && colorForeground == cc.colorForeground && colorActive == cc.colorActive && colorCaptionLabel == cc.colorCaptionLabel && colorValueLabel == cc.colorValueLabel;
}
}

37
controlP5/CDrawable.java Executable file
View File

@ -0,0 +1,37 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* The CDrawable interface is used to draw controllers, primarily for internal use.
*/
public interface CDrawable {
void draw( PGraphics theGraphics );
}

377
controlP5/CP.java Executable file
View File

@ -0,0 +1,377 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.List;
public class CP {
/**
* borrowed from http://www.javapractices.com/Topic96.cjp
*
*
* @param aURLFragment String
* @return String
*/
static public String forURL( String aURLFragment ) {
String result = null;
try {
result = URLEncoder.encode( aURLFragment , "UTF-8" );
} catch ( UnsupportedEncodingException ex ) {
throw new RuntimeException( "UTF-8 not supported" , ex );
}
return result;
}
/**
* borrowed from http://www.javapractices.com/Topic96.cjp
*
* @param aTagFragment String
* @return String
*/
static public String forHTMLTag( String aTagFragment ) {
final StringBuffer result = new StringBuffer( );
final StringCharacterIterator iterator = new StringCharacterIterator( aTagFragment );
char character = iterator.current( );
while ( character != CharacterIterator.DONE ) {
if ( character == '<' ) {
result.append( "&lt;" );
} else if ( character == '>' ) {
result.append( "&gt;" );
} else if ( character == '\"' ) {
result.append( "&quot;" );
} else if ( character == '\'' ) {
result.append( "&#039;" );
} else if ( character == '\\' ) {
result.append( "&#092;" );
} else if ( character == '&' ) {
result.append( "&amp;" );
} else {
// the char is not a special one
// add it to the result as is
result.append( character );
}
character = iterator.next( );
}
return result.toString( );
}
/**
* http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=
* display;num=1159828167;start=0#0
*
* @param string String
* @return String
*/
String URLEncode( String string ) {
String output = "";
byte[] input = string.getBytes(StandardCharsets.UTF_8);
for ( int i = 0 ; i < input.length ; i++ ) {
if ( input[ i ] < 0 ) {
// output += ('%' + hex(input[i])); // see hex method in
// processing
} else if ( input[ i ] == 32 ) {
output += '+';
} else {
output += ( char ) ( input[ i ] );
}
}
return output;
}
static public String replace( String theSourceString , String theSearchForString , String theReplaceString ) {
if ( theSourceString.length( ) < 1 ) {
return "";
}
int p = 0;
while ( p < theSourceString.length( ) && ( p = theSourceString.indexOf( theSearchForString , p ) ) >= 0 ) {
theSourceString = theSourceString.substring( 0 , p ) + theReplaceString + theSourceString.substring( p + theSearchForString.length( ));
p += theReplaceString.length( );
}
return theSourceString;
}
/**
* convert a hex number into an int
*
* @param theHex
* @return
*/
static public int parseHex( String theHex ) {
int myLen = theHex.length( );
int a , r , b , g;
switch ( myLen ) {
case ( 8 ):
break;
case ( 6 ):
theHex = "ff" + theHex;
break;
default:
theHex = "ff000000";
break;
}
a = (Integer.valueOf(Integer.parseInt(theHex.substring(0, 2), 16))).intValue( );
r = (Integer.valueOf(Integer.parseInt(theHex.substring(2, 4), 16))).intValue( );
g = (Integer.valueOf(Integer.parseInt(theHex.substring(4, 6), 16))).intValue( );
b = (Integer.valueOf(Integer.parseInt(theHex.substring(6, 8), 16))).intValue( );
return ( a << 24 | r << 16 | g << 8 | b );
}
static public String intToString( int theInt ) {
int a = ( ( theInt >> 24 ) & 0xff );
int r = ( ( theInt >> 16 ) & 0xff );
int g = ( ( theInt >> 8 ) & 0xff );
int b = ( ( theInt >> 0 ) & 0xff );
String sa = ( ( Integer.toHexString( a ) ).length( ) == 1 ) ? "0" + Integer.toHexString( a ) : Integer.toHexString( a );
String sr = ( ( Integer.toHexString( r ) ).length( ) == 1 ) ? "0" + Integer.toHexString( r ) : Integer.toHexString( r );
String sg = ( ( Integer.toHexString( g ) ).length( ) == 1 ) ? "0" + Integer.toHexString( g ) : Integer.toHexString( g );
String sb = ( ( Integer.toHexString( b ) ).length( ) == 1 ) ? "0" + Integer.toHexString( b ) : Integer.toHexString( b );
return sa + sr + sg + sb;
}
/**
* @deprecated
*/
@Deprecated protected boolean save( ControlP5 theControlP5 , String theFilePath ) {
ControlP5.logger( ).info( "Saving ControlP5 settings in XML format has been removed, have a look at controlP5's properties instead." );
return false;
}
/**
* * Convenience method for producing a simple textual representation of an array.
*
* <P>
* The format of the returned <code>String</code> is the same as
* <code>AbstractCollection.toString</code>:
* <ul>
* <li>non-empty array: [blah, blah]
* <li>empty array: []
* <li>null array: null
* </ul>
*
*
* <code>aArray</code> is a possibly-null array whose elements are primitives or objects; arrays
* of arrays are also valid, in which case <code>aArray</code> is rendered in a nested,
* recursive fashion.
*
* @author Jerome Lacoste
* @author www.javapractices.com
*/
static public String arrayToString( Object aArray ) {
if ( aArray == null ) {
return fNULL;
}
checkObjectIsArray( aArray );
StringBuilder result = new StringBuilder( fSTART_CHAR );
int length = Array.getLength( aArray );
for ( int idx = 0 ; idx < length ; ++idx ) {
Object item = Array.get( aArray , idx );
if ( isNonNullArray( item ) ) {
// recursive call!
result.append( arrayToString( item ) );
} else {
result.append( item );
}
if ( !isLastItem( idx , length ) ) {
result.append( fSEPARATOR );
}
}
result.append( fEND_CHAR );
return result.toString( );
}
// PRIVATE //
private static final String fSTART_CHAR = "[";
private static final String fEND_CHAR = "]";
private static final String fSEPARATOR = ", ";
private static final String fNULL = "null";
private static void checkObjectIsArray( Object aArray ) {
if ( !aArray.getClass( ).isArray( ) ) {
throw new IllegalArgumentException( "Object is not an array." );
}
}
private static boolean isNonNullArray( Object aItem ) {
return aItem != null && aItem.getClass( ).isArray( );
}
private static boolean isLastItem( int aIdx , int aLength ) {
return ( aIdx == aLength - 1 );
}
protected static String formatGetClass( Class< ? > c ) {
if ( c == null )
return null;
final String pattern = "class ";
return c.toString( ).startsWith( pattern ) ? c.toString( ).substring( pattern.length( ) ) : c.toString( );
}
static public boolean inside( int[] theRect , float theX , float theY ) {
if ( theRect.length == 4 ) {
return ( theX > theRect[ 0 ] && theX < theRect[ 2 ] && theY > theRect[ 1 ] && theY < theRect[ 3 ] );
} else {
return false;
}
}
/* Base64 static methods to encode and decode
* bytes into a String and back
*
* from
* http://examples.oreilly.com/javacrypt/files/oreilly/jonathan/util/
* http://oreilly.com/catalog/javacrypt/chapter/ch06.html */
static public String encodeBase64( byte[] raw ) {
StringBuffer encoded = new StringBuffer( );
for ( int i = 0 ; i < raw.length ; i += 3 ) {
encoded.append( encodeBlock( raw , i ) );
}
return encoded.toString( );
}
protected static char[] encodeBlock( byte[] raw , int offset ) {
int block = 0;
int slack = raw.length - offset - 1;
int end = ( slack >= 2 ) ? 2 : slack;
for ( int i = 0 ; i <= end ; i++ ) {
byte b = raw[ offset + i ];
int neuter = ( b < 0 ) ? b + 256 : b;
block += neuter << ( 8 * ( 2 - i ) );
}
char[] base64 = new char[ 4 ];
for ( int i = 0 ; i < 4 ; i++ ) {
int sixbit = ( block >>> ( 6 * ( 3 - i ) ) ) & 0x3f;
base64[ i ] = getBase64Char( sixbit );
}
if ( slack < 1 )
base64[ 2 ] = '=';
if ( slack < 2 )
base64[ 3 ] = '=';
return base64;
}
static char getBase64Char( int sixBit ) {
if ( sixBit >= 0 && sixBit <= 25 )
return ( char ) ( 'A' + sixBit );
if ( sixBit >= 26 && sixBit <= 51 )
return ( char ) ( 'a' + ( sixBit - 26 ) );
if ( sixBit >= 52 && sixBit <= 61 )
return ( char ) ( '0' + ( sixBit - 52 ) );
if ( sixBit == 62 )
return '+';
if ( sixBit == 63 )
return '/';
return '?';
}
static public byte[] decodeBase64( String base64 ) {
int pad = 0;
for ( int i = base64.length( ) - 1 ; base64.charAt( i ) == '=' ; i-- )
pad++;
int length = base64.length( ) * 6 / 8 - pad;
byte[] raw = new byte[ length ];
int rawIndex = 0;
for ( int i = 0 ; i < base64.length( ) ; i += 4 ) {
int block = ( getBase64Value( base64.charAt( i ) ) << 18 ) + ( getBase64Value( base64.charAt( i + 1 ) ) << 12 ) + ( getBase64Value( base64.charAt( i + 2 ) ) << 6 ) + ( getBase64Value( base64.charAt( i + 3 ) ) );
for ( int j = 0 ; j < 3 && rawIndex + j < raw.length ; j++ )
raw[ rawIndex + j ] = ( byte ) ( ( block >> ( 8 * ( 2 - j ) ) ) & 0xff );
rawIndex += 3;
}
return raw;
}
static int getBase64Value( char c ) {
if ( c >= 'A' && c <= 'Z' )
return c - 'A';
if ( c >= 'a' && c <= 'z' )
return c - 'a' + 26;
if ( c >= '0' && c <= '9' )
return c - '0' + 52;
if ( c == '+' )
return 62;
if ( c == '/' )
return 63;
if ( c == '=' )
return 0;
return -1;
}
static public int getBit( int theByte , int theIndex ) {
int bitmask = 1 << theIndex;
return ( ( theByte & bitmask ) > 0 ) ? 1 : 0;
}
static public byte setHigh( byte theByte , int theIndex ) {
return ( byte ) ( theByte | ( 1 << theIndex ) );
}
static public byte setLow( byte theByte , int theIndex ) {
return ( byte ) ( theByte & ~ ( 1 << theIndex ) );
}
static public byte[] intToByteArray( int a ) {
byte[] ret = new byte[ 2 ];
ret[ 1 ] = ( byte ) ( a & 0xFF );
ret[ 0 ] = ( byte ) ( ( a >> 8 ) & 0xFF );
//ret[0] = (byte) ((a >> 16) & 0xFF);
//ret[0] = (byte) ((a >> 24) & 0xFF);
return ret;
}
static public int byteArrayToInt( byte[] b ) {
int value = 0;
for ( int i = 0 ; i < 2 ; i++ ) {
int shift = ( 2 - 1 - i ) * 8;
value += ( b[ i ] & 0x00FF ) << shift;
}
return value;
}
static String join( List< String > list , String delimiter ) {
StringBuilder b = new StringBuilder( );
for ( String item : list ) {
b.append( item ).append( delimiter );
}
return b.toString( );
}
}

65
controlP5/CallbackEvent.java Executable file
View File

@ -0,0 +1,65 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* <p>
* A CallbackEvent is send when a controller action such as enter, leave, press, etc has occurs.
*
* @example use/ControlP5callback
*/
public class CallbackEvent {
private final int _myAction;
private final Controller< ? > _myController;
CallbackEvent( Controller< ? > theController , int theAction ) {
_myController = theController;
_myAction = theAction;
}
/**
*
* @return int Returns an int value of either one of the following static variables
* ControlP5.ACTION_PRESS, ControlP5.ACTION_ENTER, ControlP5.ACTION_LEAVE,
* ControlP5.ACTION_RELEASE, ControlP5.ACTION_RELEASEDOUTSIDE,
* ControlP5.ACTION_BROADCAST
*/
public int getAction( ) {
return _myAction;
}
/**
* Returns the Controller that triggered the Callback Event.
*
* @return Controller
*/
public Controller< ? > getController( ) {
return _myController;
}
}

41
controlP5/CallbackListener.java Executable file
View File

@ -0,0 +1,41 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* <p>
* Use a CallbackListener to listen for controller related actions such as pressed, released, etc.
* Callbacks cn be added via the ControlP5.addCallback() methods.
* </p>
*
* @example use/ControlP5callback
* @see ControlP5#addCallback(CallbackListener)
*/
public interface CallbackListener {
void controlEvent( CallbackEvent theEvent );
}

124
controlP5/Canvas.java Executable file
View File

@ -0,0 +1,124 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* Use a Canvas to draw custom graphics into a control
* window or the default sketch window.
*
* The Canvas is an abstract class and must be extended by
* your custom Canvas class, see the ControlP5canvas example
* for details.
*
* @example controllers/ControlP5canvas
*
*/
public abstract class Canvas {
protected ControlWindow _myControlWindow;
public final static int PRE = 0;
public final static int POST = 1;
protected int _myMode = PRE;
public void setup( PGraphics theGraphics ) {
}
// TODO should be called from within ControlWindow when
// calling draw(PGraphics)
public void update( PApplet theApplet ) {
}
/**
* controlWindowCanvas is an abstract class and
* therefore needs to be extended by your class.
* draw(PApplet theApplet) is the only method that needs
* to be overwritten.
*/
public abstract void draw( PGraphics theGraphics );
/**
* move a canvas to another controlWindow
*
* @param theControlWindow
*/
public void moveTo( ControlWindow theControlWindow ) {
if ( _myControlWindow != null ) {
_myControlWindow.removeCanvas( this );
}
theControlWindow.addCanvas( this );
}
/**
* get the drawing mode of a Canvas. this can be PRE or
* POST.
*
* @return
*/
public final int mode( ) {
return _myMode;
}
/**
* set the drawing mode to PRE. PRE is the default.
*/
public final void pre( ) {
setMode( PRE );
}
/**
* set the drawing mode to POST.
*/
public final void post( ) {
setMode( POST );
}
/**
*
* @param theMode
*/
public final void setMode( int theMode ) {
if ( theMode == PRE ) {
_myMode = PRE;
} else {
_myMode = POST;
}
}
protected final void setControlWindow( ControlWindow theControlWindow ) {
_myControlWindow = theControlWindow;
}
public final ControlWindow window( ) {
return _myControlWindow;
}
}

561
controlP5/Chart.java Executable file
View File

@ -0,0 +1,561 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.Iterator;
import java.util.LinkedHashMap;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* Use charts to display float array data as line chart, yet experimental, but see the
* ControlP5chart example for more details.
*
* @example controllers/ControlP5chart
*/
public class Chart extends Controller< Chart > {
public final static int LINE = 0;
public final static int BAR = 1;
public final static int BAR_CENTERED = 2;
public final static int HISTOGRAM = 3;
public final static int PIE = 4;
public final static int AREA = 5;
protected final LinkedHashMap< String , ChartDataSet > _myDataSet;
protected float resolution = 1;
protected float strokeWeight = 1;
protected float _myMin = 0;
protected float _myMax = 1;
/**
* Convenience constructor to extend Chart.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Chart( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 200 , 100 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Chart( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
setRange( 0 , theHeight );
_myDataSet = new LinkedHashMap< String , ChartDataSet >( );
getCaptionLabel( ).align( LEFT, BOTTOM_OUTSIDE ).paddingX = 0;
}
public Chart setRange( float theMin , float theMax ) {
_myMin = theMin;
_myMax = theMax;
return this;
}
public Chart setColors( String theSetIndex , int ... theColors ) {
getDataSet( ).get( theSetIndex ).setColors( theColors );
return this;
}
public Chart addData( ChartData theItem ) {
return addData( getFirstDataSetIndex( ) , theItem );
}
private String getFirstDataSetIndex( ) {
return getDataSet( ).keySet( ).iterator( ).next( );
}
private String getLastDataSetIndex( ) {
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String last = null;
while ( it.hasNext( ) ) {
last = it.next( );
}
return last;
}
public Chart addData( String theSetIndex , ChartData theItem ) {
getDataSet( theSetIndex ).add( theItem );
return this;
}
public Chart addData( float theValue ) {
ChartData cdi = new ChartData( theValue );
getDataSet( getFirstDataSetIndex( ) ).add( cdi );
return this;
}
public Chart addData( String theSetIndex , float theValue ) {
ChartData cdi = new ChartData( theValue );
getDataSet( theSetIndex ).add( cdi );
return this;
}
public Chart addData( ChartDataSet theChartData , float theValue ) {
ChartData cdi = new ChartData( theValue );
theChartData.add( cdi );
return this;
}
// array operations see syntax
// http://www.w3schools.com/jsref/jsref_obj_array.asp
/**
* adds a new float at the beginning of the data set.
*/
public Chart unshift( float theValue ) {
return unshift( getFirstDataSetIndex( ) , theValue );
}
public Chart unshift( String theSetIndex , float theValue ) {
if ( getDataSet( theSetIndex ).size( ) > ( getWidth() / resolution ) ) {
removeLast( theSetIndex );
}
return addFirst( theSetIndex , theValue );
}
public Chart push( float theValue ) {
return push( getFirstDataSetIndex( ) , theValue );
}
public Chart push( String theSetIndex , float theValue ) {
if ( getDataSet( theSetIndex ).size( ) > ( getWidth() / resolution ) ) {
removeFirst( theSetIndex );
}
return addLast( theSetIndex , theValue );
}
public Chart addFirst( float theValue ) {
return addFirst( getFirstDataSetIndex( ) , theValue );
}
public Chart addFirst( String theSetIndex , float theValue ) {
ChartData cdi = new ChartData( theValue );
getDataSet( theSetIndex ).add( 0 , cdi );
return this;
}
public Chart addLast( float theValue ) {
return addLast( getFirstDataSetIndex( ) , theValue );
}
public Chart addLast( String theSetIndex , float theValue ) {
ChartData cdi = new ChartData( theValue );
getDataSet( theSetIndex ).add( cdi );
return this;
}
public Chart removeLast( ) {
return removeLast( getFirstDataSetIndex( ) );
}
public Chart removeLast( String theSetIndex ) {
return removeData( theSetIndex , getDataSet( theSetIndex ).size( ) - 1 );
}
public Chart removeFirst( ) {
return removeFirst( getFirstDataSetIndex( ) );
}
public Chart removeFirst( String theSetIndex ) {
return removeData( theSetIndex , 0 );
}
public Chart removeData( ChartData theItem ) {
removeData( getFirstDataSetIndex( ) , theItem );
return this;
}
public Chart removeData( String theSetIndex , ChartData theItem ) {
getDataSet( theSetIndex ).remove( theItem );
return this;
}
public Chart removeData( int theItemIndex ) {
removeData( getFirstDataSetIndex( ) , theItemIndex );
return this;
}
public Chart removeData( String theSetIndex , int theItemIndex ) {
if ( getDataSet( theSetIndex ).size( ) < 1 ) {
return this;
}
getDataSet( theSetIndex ).remove( theItemIndex );
return this;
}
public Chart setData( int theItemIndex , ChartData theItem ) {
getDataSet( getFirstDataSetIndex( ) ).set( theItemIndex , theItem );
return this;
}
public Chart setData( String theSetItem , int theItemIndex , ChartData theItem ) {
getDataSet( theSetItem ).set( theItemIndex , theItem );
return this;
}
public Chart addDataSet( String theName ) {
getDataSet( ).put( theName , new ChartDataSet( theName ) );
return this;
}
public Chart setDataSet( ChartDataSet theItems ) {
setDataSet( getFirstDataSetIndex( ) , theItems );
return this;
}
public Chart setDataSet( String theSetIndex , ChartDataSet theChartData ) {
getDataSet( ).put( theSetIndex , theChartData );
return this;
}
public Chart removeDataSet( String theIndex ) {
getDataSet( ).remove( theIndex );
return this;
}
public Chart setData( float ... theValues ) {
setData( getFirstDataSetIndex( ) , theValues );
return this;
}
public Chart setData( String theSetIndex , float ... theValues ) {
if ( getDataSet( ).get( theSetIndex ).size( ) != theValues.length ) {
getDataSet( ).get( theSetIndex ).clear( );
for ( int i = 0 ; i < theValues.length ; i++ ) {
getDataSet( ).get( theSetIndex ).add( new ChartData( 0 ) );
}
}
int n = 0;
resolution = ( float ) getWidth() / ( getDataSet( ).get( theSetIndex ).size( ) - 1 );
for ( float f : theValues ) {
getDataSet( ).get( theSetIndex ).get( n++ ).setValue( f );
}
return this;
}
public Chart updateData( float ... theValues ) {
return setData( theValues );
}
public Chart updateData( String theSetIndex , float ... theValues ) {
return setData( theSetIndex , theValues );
}
public LinkedHashMap< String , ChartDataSet > getDataSet( ) {
return _myDataSet;
}
public ChartDataSet getDataSet( String theIndex ) {
return getDataSet( ).get( theIndex );
}
public float[] getValuesFrom( String theIndex ) {
return getDataSet( theIndex ).getValues( );
}
public ChartData getData( String theIndex , int theItemIndex ) {
return getDataSet( theIndex ).get( theItemIndex );
}
public int size( ) {
return getDataSet( ).size( );
}
@Override
public void onEnter( ) {
}
@Override
public void onLeave( ) {
}
@Override
public Chart setValue( float theValue ) {
// TODO Auto-generated method stub
return this;
}
public Chart setStrokeWeight( float theWeight ) {
strokeWeight = theWeight;
for ( ChartDataSet c : getDataSet( ).values( ) ) {
c.setStrokeWeight( theWeight );
}
return this;
}
public float getStrokeWeight( ) {
return strokeWeight;
}
/**
* ?
*
* @param theValue
* @return
*/
public Chart setResolution( int theValue ) {
resolution = theValue;
return this;
}
public int getResolution( ) {
return ( int ) resolution;
}
/**
* @exclude
*/
@Override
@ControlP5.Invisible
public Chart updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
/**
* @exclude
*/
@ControlP5.Invisible
public Chart updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new ChartViewPie( );
break;
case ( IMAGE ):
// _myDisplay = new ChartImageDisplay();
break;
case ( SPRITE ):
// _myDisplay = new ChartSpriteDisplay();
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
public class ChartViewBar implements ControllerView< Chart > {
public void display( PGraphics theGraphics , Chart theController ) {
theGraphics.pushStyle( );
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.noStroke( );
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String index = null;
float o = 0;
while ( it.hasNext( ) ) {
index = it.next( );
float s = getDataSet( index ).size( );
for ( int i = 0 ; i < s ; i++ ) {
theGraphics.fill( getDataSet( index ).getColor( i ) );
float ww = ( ( getWidth() / s ) );
float hh = PApplet.map( getDataSet( index ).get( i ).getValue( ) , _myMin , _myMax , 0 , getHeight( ) );
theGraphics.rect( o + i * ww , getHeight( ) , ( ww / getDataSet( ).size( ) ) , -PApplet.min( getHeight( ) , PApplet.max( 0 , hh ) ) );
}
o += ( ( getWidth() / s ) ) / getDataSet( ).size( );
}
theGraphics.popStyle( );
}
}
public class ChartViewBarCentered implements ControllerView< Chart > {
public void display( PGraphics theGraphics , Chart theController ) {
theGraphics.pushStyle( );
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.noStroke( );
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String index = null;
float o = 0;
int n = 4;
int off = ( getDataSet( ).size( ) - 1 ) * n;
while ( it.hasNext( ) ) {
index = it.next( );
int s = getDataSet( index ).size( );
float step = ( float ) getWidth() / ( float ) ( s );
float ww = step - ( getWidth() % step );
ww -= 1;
ww = PApplet.max( 1 , ww );
for ( int i = 0 ; i < s ; i++ ) {
theGraphics.fill( getDataSet( index ).getColor( i ) );
ww = ( ( getWidth() / s ) * 0.5f );
float hh = PApplet.map( getDataSet( index ).get( i ).getValue( ) , _myMin , _myMax , 0 , getHeight( ) );
theGraphics.rect( -off / 2 + o + i * ( ( getWidth() / s ) ) + ww / 2 , getHeight( ) , ww , -PApplet.min( getHeight( ) , PApplet.max( 0 , hh ) ) );
}
o += n;
}
theGraphics.popStyle( );
}
}
public class ChartViewLine implements ControllerView< Chart > {
public void display( PGraphics theGraphics , Chart theController ) {
theGraphics.pushStyle( );
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.noFill( );
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String index = null;
while ( it.hasNext( ) ) {
index = it.next( );
theGraphics.stroke( getDataSet( index ).getColor( 0 ) );
theGraphics.strokeWeight( getDataSet( index ).getStrokeWeight( ) );
theGraphics.beginShape( );
float res = ( ( float ) getWidth( ) ) / ( getDataSet( index ).size( ) - 1 );
for ( int i = 0 ; i < getDataSet( index ).size( ) ; i++ ) {
float hh = PApplet.map( getDataSet( index ).get( i ).getValue( ) , _myMin , _myMax , getHeight( ) , 0 );
theGraphics.vertex( i * res , PApplet.min( getHeight( ) , PApplet.max( 0 , hh ) ) );
}
theGraphics.endShape( );
}
theGraphics.noStroke( );
theGraphics.popStyle( );
getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController );
}
}
public class ChartViewArea implements ControllerView< Chart > {
public void display( PGraphics theGraphics , Chart theController ) {
theGraphics.pushStyle( );
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.noStroke( );
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String index = null;
while ( it.hasNext( ) ) {
index = it.next( );
float res = ( ( float ) getWidth( ) ) / ( getDataSet( index ).size( ) - 1 );
theGraphics.fill( getDataSet( index ).getColor( 0 ) );
theGraphics.beginShape( );
theGraphics.vertex( 0 , getHeight( ) );
for ( int i = 0 ; i < getDataSet( index ).size( ) ; i++ ) {
float hh = PApplet.map( getDataSet( index ).get( i ).getValue( ) , _myMin , _myMax , getHeight( ) , 0 );
theGraphics.vertex( i * res , PApplet.min( getHeight( ) , PApplet.max( 0 , hh ) ) );
}
theGraphics.vertex( getWidth( ) , getHeight( ) );
theGraphics.endShape( PApplet.CLOSE );
}
theGraphics.noStroke( );
theGraphics.popStyle( );
}
}
public class ChartViewPie implements ControllerView< Chart > {
public void display( PGraphics theGraphics , Chart theController ) {
theGraphics.pushStyle( );
theGraphics.pushMatrix( );
Iterator< String > it = getDataSet( ).keySet( ).iterator( );
String index = null;
while ( it.hasNext( ) ) {
index = it.next( );
float total = 0;
for ( int i = 0 ; i < getDataSet( index ).size( ) ; i++ ) {
total += getDataSet( index ).get( i ).getValue( );
}
float segment = TWO_PI / total;
float angle = -HALF_PI;
theGraphics.noStroke( );
for ( int i = 0 ; i < getDataSet( index ).size( ) ; i++ ) {
theGraphics.fill( getDataSet( index ).getColor( i ) );
float nextAngle = angle + getDataSet( index ).get( i ).getValue( ) * segment;
// a tiny offset to even out render artifacts when in smooth() mode.
float a = PApplet.max( 0 , PApplet.map( getWidth( ) , 0 , 200 , 0.05f , 0.01f ) );
theGraphics.arc( 0 , 0 , getWidth( ) , getHeight( ) , angle - a , nextAngle );
angle = nextAngle;
}
theGraphics.translate( 0 , ( getHeight( ) + 10 ) );
}
theGraphics.popMatrix( );
theGraphics.popStyle( );
}
}
public Chart setView( int theType ) {
switch ( theType ) {
case ( PIE ):
setView( new ChartViewPie( ) );
break;
case ( LINE ):
setView( new ChartViewLine( ) );
break;
case ( BAR ):
setView( new ChartViewBar( ) );
break;
case ( BAR_CENTERED ):
setView( new ChartViewBarCentered( ) );
break;
case ( AREA ):
setView( new ChartViewArea( ) );
break;
default:
System.out.println( "Sorry, this ChartView does not exist" );
break;
}
return this;
}
@Override
public String getInfo( ) {
return "type:\tChart\n" + super.toString( );
}
@Override
public String toString( ) {
return super.toString( ) + " [ " + getValue( ) + " ]" + " Chart " + "(" + this.getClass( ).getSuperclass( ) + ")";
}
}
/* NOTES what is the difference in meaning between chart and graph
* http://answers.yahoo.com/question/index?qid=20090101193325AA3mgMl
*
* more charts to implement: from https://vimeo.com/groups/oaod/videos/60013194 (44:40) scatter
* plot, star plot, histogram, dendrogram, box plot, physical map, tree, 2d 3d isosurfaces table,
* half matrix, graph, hierarchical pie, line graph, numeric matrix, heat map, permutation matrix
* bar graph, radial graph, */

72
controlP5/ChartData.java Executable file
View File

@ -0,0 +1,72 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* Used by Chart, single chart data is stored here including value, (label) text, and color.
*/
public class ChartData {
protected float _myValue;
protected String _myText;
protected int _myColor;
public ChartData( float theValue ) {
this( theValue , "" );
}
public ChartData( float theValue , String theText ) {
_myValue = theValue;
_myText = theText;
}
public void setValue( float theValue ) {
_myValue = theValue;
}
public void setText( String theText ) {
_myText = theText;
}
public float getValue( ) {
return _myValue;
}
public String getText( ) {
return _myText;
}
public void setColor( int theColor ) {
_myColor = theColor;
}
public int getColor( ) {
return _myColor;
}
}

95
controlP5/ChartDataSet.java Executable file
View File

@ -0,0 +1,95 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import java.util.ListIterator;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* Used by Chart, a chart data set is a container to store chart data.
*/
@SuppressWarnings( "serial" )
public class ChartDataSet extends ArrayList< ChartData > {
protected CColor _myColor;
protected float _myStrokeWeight = 1;
protected int[] colors = new int[ 0 ];
protected final String _myName;
public ChartDataSet( String theName ) {
_myName = theName;
_myColor = new CColor( );
}
public CColor getColor( ) {
return _myColor;
}
public ChartDataSet setColors( int ... theColors ) {
colors = theColors;
return this;
}
public int[] getColors( ) {
return colors;
}
public int getColor( int theIndex ) {
if ( colors.length == 0 ) {
return getColor( ).getForeground( );
}
if ( colors.length == 2 ) {
return PGraphics.lerpColor( colors[ 0 ] , colors[ 1 ] , theIndex / ( float ) size( ) , PApplet.RGB );
}
if ( theIndex >= 0 && theIndex < colors.length ) {
return colors[ theIndex ];
}
return getColor( 0 );
}
public ChartDataSet setStrokeWeight( float theStrokeWeight ) {
_myStrokeWeight = theStrokeWeight;
return this;
}
public float getStrokeWeight( ) {
return _myStrokeWeight;
}
public float[] getValues( ) {
float[] v = new float[ size( ) ];
int n = 0;
ListIterator< ChartData > litr = listIterator( );
while ( litr.hasNext( ) ) {
v[ n++ ] = litr.next( ).getValue( );
}
return v;
}
}

615
controlP5/CheckBox.java Executable file
View File

@ -0,0 +1,615 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import processing.core.PImage;
/**
* A multiple-choice radioButton. items are added to a checkBox and can be organized in rows and
* columns. items of a checkBox are of type Toggle.
*
* @example controllers/ControlP5checkBox
*
* @see Toggle
*
*/
public class CheckBox extends ControlGroup< CheckBox > {
private Object _myPlug;
private String _myPlugName;
/**
* Convenience constructor to extend CheckBox.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public CheckBox( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
* A CheckBox should only be added to controlP5 by using controlP5.addCheckBox()
*
* @exclude
* @param theControlP5
* @param theParent
* @param theName
* @param theX
* @param theY
*/
public CheckBox( final ControlP5 theControlP5 , final ControllerGroup< ? > theParent , final String theName , final int theX , final int theY ) {
super( theControlP5 , theParent , theName , theX , theY , 99 , 9 );
isBarVisible = false;
isCollapse = false;
_myRadioToggles = new ArrayList< Toggle >( );
setItemsPerRow( 1 );
isMultipleChoice = true;
_myPlug = cp5.papplet;
_myPlugName = getName( );
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) {
_myPlug = null;
}
}
public final CheckBox activateAll( ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
_myRadioToggles.get( i ).activate( );
}
updateValues( );
return this;
}
/**
* Activates a single checkbox item by index
*/
public final CheckBox activate( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) {
_myRadioToggles.get( theIndex ).activate( );
updateValues( );
}
return this;
}
/**
* deactivate a single checkbox item by index
*/
public final CheckBox deactivate( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) {
_myRadioToggles.get( theIndex ).deactivate( );
updateValues( );
}
return this;
}
/**
* toggle a single checkbox item by index
*/
public final CheckBox toggle( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) ) {
Toggle t = _myRadioToggles.get( theIndex );
if (t.getState()) {
t.deactivate( );
} else {
t.activate( );
}
updateValues( );
}
return this;
}
/**
* deactivate a single checkbox item by name
*/
public final void toggle( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
if (t.getState()) {
t.deactivate( );
} else {
t.activate( );
}
updateValues( );
return;
}
}
}
/**
* Activates a single checkbox item by name
*/
public final CheckBox activate( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
t.activate( );
updateValues( );
return this;
}
}
return this;
}
/**
* Deactivates a single checkbox item by name
*/
public final CheckBox deactivate( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
t.deactivate( );
updateValues( );
return this;
}
}
return this;
}
private final void updateValues( ) {
_myValue = -1;
updateValues( true );
}
/**
* 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.
*/
@Override public CheckBox setArrayValue( float[] theArray ) {
for ( int i = 0 ; i < theArray.length ; i++ ) {
if ( _myArrayValue[ i ] != theArray[ i ] ) {
if ( theArray[ i ] == 0 ) {
_myRadioToggles.get( i ).deactivate( );
} else {
_myRadioToggles.get( i ).activate( );
}
}
}
super.setArrayValue( theArray );
return this;
}
/**
* @exclude {@inheritDoc}
*/
@Override public String 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 theValue
* @return
*/
public CheckBox addItem( final String theName , final float theValue ) {
Toggle t = cp5.addToggle( theName , 0 , 0 , itemWidth , itemHeight );
t.getCaptionLabel( ).align( RIGHT_OUTSIDE , CENTER ).setPadding( Label.paddingX , 0 );
t.setMode(DEFAULT);
t.setImages( images[ 0 ] , images[ 1 ] , images[ 2 ] );
t.setSize( images[ 0 ] );
addItem( t , theValue );
return this;
}
/**
* @param theToggle
* @param theValue
* @return
*/
public CheckBox addItem( final Toggle theToggle , final float theValue ) {
theToggle.setGroup( this );
theToggle.isMoveable = false;
theToggle.setInternalValue( theValue );
theToggle.isBroadcast = false;
_myRadioToggles.add( theToggle );
updateLayout( );
getColor( ).copyTo( theToggle );
theToggle.addListener( this );
updateValues( false );
cp5.removeProperty( theToggle );
return this;
}
/**
* @param theName
*/
public CheckBox removeItem( final String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
if ( ( _myRadioToggles.get( i ) ).getName( ).equals( theName ) ) {
( _myRadioToggles.get( i ) ).removeListener( this );
_myRadioToggles.remove( i );
}
}
updateValues( false );
return this;
}
/**
*
* @param theDefaultImage
* @param theOverImage
* @param theActiveImage
* @return CheckBox
*/
public CheckBox setImages( PImage theDefaultImage , PImage theOverImage , PImage theActiveImage ) {
setImage( theDefaultImage , DEFAULT );
setImage( theOverImage , OVER );
setImage( theActiveImage , ACTIVE );
return this;
}
/**
* @param theImage
*/
public CheckBox setImage( PImage theImage ) {
return setImage( theImage , DEFAULT );
}
/**
* @param theImage
* @param theState
* use Controller.DEFAULT (background), or Controller.OVER (foreground), or
* Controller.ACTIVE (active)
* @return
*/
public CheckBox setImage( PImage theImage , int theState ) {
if ( theImage != null ) {
images[ theState ] = theImage;
availableImages[ theState ] = true;
for ( int i = 0 ; i < _myRadioToggles.size( ) ; i++ ) {
_myRadioToggles.get( i ).setImage( theImage , theState );
}
}
return this;
}
public CheckBox setSize( PImage theImage ) {
return setSize( theImage.width , theImage.height );
}
public CheckBox setSize( int theWidth , int theHeight ) {
setItemWidth( theWidth );
setItemHeight( theHeight );
return this;
}
/**
* set the height of a radioButton/checkBox item. by default the height is 11px. in order to
* recognize a custom height, the itemHeight has to be set before adding items to a
* radioButton/checkBox.
*
* @param theItemHeight
*/
public CheckBox setItemHeight( int theItemHeight ) {
itemHeight = theItemHeight;
for ( Toggle t : _myRadioToggles ) {
t.setHeight( theItemHeight );
}
updateLayout( );
return this;
}
/**
* set the width of a radioButton/checkBox item. by default the width is 11px. in order to
* recognize a custom width, the itemWidth has to be set before adding items to a
* radioButton/checkBox.
*
* @param theItemWidth
*/
public CheckBox setItemWidth( int theItemWidth ) {
itemWidth = theItemWidth;
for ( Toggle t : _myRadioToggles ) {
t.setWidth( theItemWidth );
}
updateLayout( );
return this;
}
/**
* Gets a radio button item by index.
*
* @param theIndex
* @return Toggle
*/
public Toggle getItem( int theIndex ) {
return _myRadioToggles.get( theIndex );
}
public List< Toggle > getItems( ) {
return _myRadioToggles;
}
/**
* Gets the state of an item - this can be true (for on) or false (for off) - by index.
*
* @param theIndex
* @return boolean
*/
public boolean getState( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) && theIndex >= 0 ) {
return _myRadioToggles.get( theIndex ).getState( );
}
return false;
}
/**
* Gets the state of an item - this can be true (for on) or false (for off) - by name.
*
* @param theName
* @return
*/
public boolean getState( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
return t.getState( );
}
}
return false;
}
/**
* @exclude
*/
public void updateLayout( ) {
int nn = 0;
int xx = 0;
int yy = 0;
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
set( t.position , xx , yy );
xx += t.getWidth( ) + spacingColumn;
nn++;
if ( nn == itemsPerRow ) {
nn = 0;
_myWidth = xx;
yy += t.getHeight( ) + spacingRow;
xx = 0;
} else {
_myWidth = xx;
}
}
}
/**
* Items of a radioButton or a checkBox are organized in columns and rows. SetItemsPerRow sets
* the limit of items per row. items exceeding the limit will be pushed to the next row.
*
* @param theValue
*/
public CheckBox setItemsPerRow( final int theValue ) {
itemsPerRow = theValue;
updateLayout( );
return this;
}
/**
* Sets the spacing in pixels between columns.
*
* @param theSpacing
*/
public CheckBox setSpacingColumn( final int theSpacing ) {
spacingColumn = theSpacing;
updateLayout( );
return this;
}
/**
* Sets the spacing in pixels between rows.
*
* @param theSpacing
*/
public CheckBox setSpacingRow( final int theSpacing ) {
spacingRow = theSpacing;
updateLayout( );
return this;
}
public CheckBox deactivateAll( ) {
if ( !isMultipleChoice && !noneSelectedAllowed ) {
return this;
}
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
_myRadioToggles.get( i ).deactivate( );
}
_myValue = -1;
updateValues( true );
return this;
}
/**
* {@inheritDoc}
*
* @exclude
*/
@ControlP5.Invisible @Override public void controlEvent( ControlEvent theEvent ) {
if ( !isMultipleChoice ) {
if ( !noneSelectedAllowed && theEvent.getController( ).getValue( ) < 1 ) {
if ( theEvent.getController( ) instanceof Toggle ) {
Toggle t = ( ( Toggle ) theEvent.getController( ) );
boolean b = t.isBroadcast( );
t.setBroadcast( false );
t.setState( true );
t.setBroadcast( b );
return;
}
}
_myValue = -1;
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( !t.equals( theEvent.getController( ) ) ) {
t.deactivate( );
} else {
if ( t.isOn ) {
_myValue = t.internalValue( );
}
}
}
}
updateValues( true );
if ( _myPlug != null ) {
try {
Method method = _myPlug.getClass( ).getMethod( _myPlugName , float[].class );
method.invoke( _myPlug , getArrayValue( ));
} catch ( SecurityException ex ) {
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 ) {
_myPlug = theObject;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) {
_myPlug = null;
}
return this;
}
public CheckBox plugTo( Object theObject , String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { float[].class } ) ) {
_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 = _myRadioToggles.get( i );
_myArrayValue[ i ] = t.getValue( );
}
if ( theBroadcastFlag ) {
ControlEvent myEvent = new ControlEvent( this );
cp5.getControlBroadcaster( ).broadcast( myEvent , FLOAT);
}
}
/**
* In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this
* is true. setNoneSelectedAllowed does not apply when in multipleChoice mode.
*
* @param theValue
*/
public CheckBox setNoneSelectedAllowed( boolean theValue ) {
noneSelectedAllowed = theValue;
return this;
}
public CheckBox setColorLabels( int theColor ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setColor( theColor );
}
return this;
}
public CheckBox hideLabels( ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( false );
}
return this;
}
public CheckBox showLabels( ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( true );
}
return this;
}
public CheckBox toUpperCase( boolean theValue ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).toUpperCase( theValue );
}
return this;
}
/**
* @deprecated
* @exclude
*/
@Deprecated public CheckBox add( final String theName , final float theValue ) {
return addItem( theName , theValue );
}
}

View File

@ -0,0 +1,33 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
class ColorPalette extends ControlGroup< ColorPalette > {
protected ColorPalette( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
}
}

259
controlP5/ColorPicker.java Executable file
View File

@ -0,0 +1,259 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import processing.core.PGraphics;
/**
* A simple color picker using sliders to adjust RGBA values.
*
* @example controllers/ControlP5colorPicker
*/
public class ColorPicker extends ControlGroup< ColorPicker > {
protected Slider sliderRed;
protected Slider sliderGreen;
protected Slider sliderBlue;
protected Slider sliderAlpha;
protected Canvas currentColor;
private Object _myPlug;
private String _myPlugName;
private boolean broadcast;
/**
* Convenience constructor to extend ColorPicker.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public ColorPicker( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 255 , 10 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected ColorPicker( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
isBarVisible = false;
isCollapse = false;
_myArrayValue = new float[] { 255 , 255 , 255 , 255 };
currentColor = addCanvas( new ColorField( ) );
sliderRed = cp5.addSlider( theName + "-red" , 0 , 255 , 0 , 0 , theWidth , theHeight );
cp5.removeProperty( sliderRed );
sliderRed.setId( 0 );
sliderRed.setBroadcast( false );
sliderRed.addListener( this );
sliderRed.moveTo( this );
sliderRed.setMoveable( false );
sliderRed.setColorBackground( 0xff660000 );
sliderRed.setColorForeground( 0xffaa0000 );
sliderRed.setColorActive( 0xffff0000 );
sliderRed.getCaptionLabel( ).setVisible( false );
sliderRed.setDecimalPrecision( 0 );
sliderRed.setValue( 255 );
sliderGreen = cp5.addSlider( theName + "-green" , 0 , 255 , 0 , theHeight + 1 , theWidth , theHeight );
cp5.removeProperty( sliderGreen );
sliderGreen.setId( 1 );
sliderGreen.setBroadcast( false );
sliderGreen.addListener( this );
sliderGreen.moveTo( this );
sliderGreen.setMoveable( false );
sliderGreen.setColorBackground( 0xff006600 );
sliderGreen.setColorForeground( 0xff00aa00 );
sliderGreen.setColorActive( 0xff00ff00 );
sliderGreen.getCaptionLabel( ).setVisible( false );
sliderGreen.setDecimalPrecision( 0 );
sliderGreen.setValue( 255 );
sliderBlue = cp5.addSlider( theName + "-blue" , 0 , 255 , 0 , ( theHeight + 1 ) * 2 , theWidth , theHeight );
cp5.removeProperty( sliderBlue );
sliderBlue.setId( 2 );
sliderBlue.setBroadcast( false );
sliderBlue.addListener( this );
sliderBlue.moveTo( this );
sliderBlue.setMoveable( false );
sliderBlue.setColorBackground( 0xff000066 );
sliderBlue.setColorForeground( 0xff0000aa );
sliderBlue.setColorActive( 0xff0000ff );
sliderBlue.getCaptionLabel( ).setVisible( false );
sliderBlue.setDecimalPrecision( 0 );
sliderBlue.setValue( 255 );
sliderAlpha = cp5.addSlider( theName + "-alpha" , 0 , 255 , 0 , ( theHeight + 1 ) * 3 , theWidth , theHeight );
cp5.removeProperty( sliderAlpha );
sliderAlpha.setId( 3 );
sliderAlpha.setBroadcast( false );
sliderAlpha.addListener( this );
sliderAlpha.moveTo( this );
sliderAlpha.setMoveable( false );
sliderAlpha.setColorBackground( 0xff666666 );
sliderAlpha.setColorForeground( 0xffaaaaaa );
sliderAlpha.setColorActive( 0xffffffff );
sliderAlpha.getCaptionLabel( ).setVisible( false );
sliderAlpha.setDecimalPrecision( 0 );
sliderAlpha.getValueLabel( ).setColor( 0xff000000 );
sliderAlpha.setValue( 255 );
_myPlug = cp5.papplet;
_myPlugName = getName( );
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
broadcast = true;
}
public ColorPicker plugTo( Object theObject ) {
_myPlug = theObject;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
return this;
}
public ColorPicker plugTo( Object theObject , String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
return this;
}
@Override
@ControlP5.Invisible
public void controlEvent( ControlEvent theEvent ) {
if ( broadcast ) {
_myArrayValue[ theEvent.getId( ) ] = theEvent.getValue( );
broadcast( );
}
}
private ColorPicker broadcast( ) {
ControlEvent ev = new ControlEvent( this );
setValue( getColorValue( ) );
cp5.getControlBroadcaster( ).broadcast( ev , ControlP5Constants.EVENT);
if ( _myPlug != null ) {
try {
Method method = _myPlug.getClass( ).getMethod( _myPlugName , int.class );
method.invoke( _myPlug , getColorValue( ));
} catch ( SecurityException ex ) {
ex.printStackTrace( );
} catch ( NoSuchMethodException ex ) {
ex.printStackTrace( );
} catch ( IllegalArgumentException ex ) {
ex.printStackTrace( );
} catch ( IllegalAccessException ex ) {
ex.printStackTrace( );
} catch ( InvocationTargetException ex ) {
ex.printStackTrace( );
}
}
return this;
}
/**
* Requires an array of size 4 for RGBA
*
* @return ColorPicker
*/
@Override
public ColorPicker setArrayValue( float[] theArray ) {
broadcast = false;
sliderRed.setValue( theArray[ 0 ] );
sliderGreen.setValue( theArray[ 1 ] );
sliderBlue.setValue( theArray[ 2 ] );
sliderAlpha.setValue( theArray[ 3 ] );
broadcast = true;
_myArrayValue = theArray;
return broadcast( );
}
/**
* {@inheritDoc}
*/
@Override
public ColorPicker setColorValue( int theColor ) {
setArrayValue( new float[] { theColor >> 16 & 0xff , theColor >> 8 & 0xff , theColor >> 0 & 0xff , theColor >> 24 & 0xff } );
return this;
}
public int getColorValue( ) {
return 0xffffffff & ( int ) ( _myArrayValue[ 3 ] ) << 24 | ( int ) ( _myArrayValue[ 0 ] ) << 16 | ( int ) ( _myArrayValue[ 1 ] ) << 8 | ( int ) ( _myArrayValue[ 2 ] ) << 0;
}
private class ColorField extends Canvas {
public void draw( PGraphics theGraphics ) {
theGraphics.fill( _myArrayValue[ 0 ] , _myArrayValue[ 1 ] , _myArrayValue[ 2 ] , _myArrayValue[ 3 ] );
theGraphics.rect( 0 , 44 , getWidth( ) , 15 );
}
}
// public ColorPicker setColor(int... theArray) {
// switch (theArray.length) {
// case (1):
// setArrayValue(new float[] { theArray[0], theArray[0], theArray[0], getColorValue() >> 24 &
// 0xff });
// break;
// case (2):
// setArrayValue(new float[] { theArray[0], theArray[0], theArray[0], theArray[1] });
// break;
// case (3):
// setArrayValue(new float[] { theArray[0], theArray[1], theArray[2], getColorValue() >> 24 &
// 0xff });
// break;
// case (4):
// setArrayValue(new float[] { theArray[0], theArray[1], theArray[2], theArray[3] });
// break;
// }
// return this;
// }
/**
* @exclude {@inheritDoc}
*/
@Override
public String getInfo( ) {
return "type:\tColorPicker\n" + super.toString( );
}
}
// some inspiration
// http://www.nbdtech.com/blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
// http://alienryderflex.com/hsp.html

599
controlP5/ColorWheel.java Normal file
View File

@ -0,0 +1,599 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.HashMap;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PGraphics;
public class ColorWheel extends Controller< ColorWheel > {
/* TODO _myColorValue should only be used internally,
* when broadcasting, a composed value based on the hsl
* and alpha value should be distributed, same goes for
* getValue. */
private int _myColorValue = 0xffffffff;
private final Map< String , PGraphics > _myColorResources;
private final float[] _myCursor;
private final float scalar = 0.8f;
private int yoff = 10;
private final boolean isInfo = false;
private final Label _myInfoLabel;
private int drag = NONE;
private final static int NONE = -1;
private final static int SATURATION = 0;
private final static int COLOR = 1;
private final static int ALPHA = 2;
int _sideHandleHeight = 8;
private final double[] hsl = new double[] { 1.0 , 1.0 , 1.0 };
// argb = int ( 0-255 , 0-255 , 0-255 , 0-255 )
// hue = double ( 0.0-1.0 ) 0-360
// saturation = double ( 0.0-1.0 ) 0-100%
// lightness = double ( 0.0-1.0 ) 0-100%
// brightness = double ( 0.0-1.0 ) 0-100%
public ColorWheel( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
public ColorWheel( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myColorResources = new HashMap< String , PGraphics >( );
_myColorResources.put( "default" , cp5.papplet.createGraphics( theWidth , theHeight ) );
_myCursor = new float[] { getWidth( ) / 2 , getHeight( ) / 2 };
_myCaptionLabel.align( LEFT , BOTTOM_OUTSIDE );
_myCaptionLabel.setPaddingX( 0 );
_myInfoLabel = new Label( cp5 , theName + "-info" );
_myInfoLabel.setPaddingX( 4 ).getStyle( ).marginTop = 4;
yoff = ( int ) ( getWidth( ) * 0.05 );
setColorResources( );
}
@Override public void onStartDrag( ) {
checkDrag( );
}
private void checkDrag( ) {
double x = getPointer( ).x( );
double y = getPointer( ).y( ) + yoff;
double xcenter = getWidth( ) / 2;
double ycenter = getHeight( ) / 2;
double d1 = ( ( getWidth( ) / 2 ) * scalar ) + 1;
double d = Math.sqrt( Math.pow( x - xcenter , 2 ) + Math.pow( y - ycenter , 2 ) );
double w = ( getWidth( ) - ( d1 * 2 ) ) / 2;
drag = NONE;
if ( d <= d1 ) {
drag = COLOR;
} else if ( x >= 0 && x <= w ) {
drag = SATURATION;
} else if ( x >= getWidth( ) - w && x <= getWidth( ) ) {
drag = ALPHA;
}
}
public void onEndDrag( ) {
drag = NONE;
}
@Override public void onDrag( ) {
switch ( drag ) {
case ( COLOR ):
double x = getPointer( ).x( );
double y = getPointer( ).y( ) + yoff;
double xcenter = getWidth( ) / 2;
double ycenter = getHeight( ) / 2;
double a = Math.atan2( y - ycenter , x - xcenter );
double d0 = getWidth( ) * 0.1;
double d1 = ( ( getWidth( ) / 2 ) * scalar ) + 1;
double d = Math.sqrt( Math.pow( x - xcenter , 2 ) + Math.pow( y - ycenter , 2 ) );
if ( d >= d1 - 1 ) {
x = ( xcenter + Math.cos( a ) * d1 );
y = ( ycenter + Math.sin( a ) * d1 );
} else if ( d <= d0 ) {
x = ( xcenter + Math.cos( a ) * d0 );
y = ( ycenter + Math.sin( a ) * d0 );
}
set( _myCursor , ( float ) x , ( float ) y );
int xx = ( int ) x;
int yy = ( int ) y;
double[] t = RGBtoHSL( _myColorResources.get( "default" ).get( xx , yy ) );
hsl[ 0 ] = t[ 0 ];
hsl[ 2 ] = t[ 2 ];
_myColorValue = HSLtoRGB( hsl );
setValue( _myColorValue );
break;
case ( SATURATION ):
float s1 = ( getHeight( ) - ( yoff * 2 ) - _sideHandleHeight );
setSaturation( map( getPointer( ).y( ) , 0 , s1 , 1.0 , 0.0 ) );
_myColorValue = HSLtoRGB( hsl );
setValue( _myColorValue );
break;
case ( ALPHA ):
float a1 = ( getHeight( ) - ( yoff * 2 ) - _sideHandleHeight );
setAlpha( ( int ) map( getPointer( ).y( ) , 0 , a1 , 255 , 0 ) );
_myColorValue = HSLtoRGB( hsl );
setValue( _myColorValue );
break;
}
}
@Override public void onPress( ) {
checkDrag( );
}
@Override public void onRelease( ) {
onDrag( );
}
public ColorWheel scrolled( int theRotationValue ) {
if ( isVisible ) {
double x = getPointer( ).x( );
double d1 = ( ( getWidth( ) / 2 ) * scalar ) + 1;
double w = ( getWidth( ) - ( d1 * 2 ) ) / 2;
if ( x >= 0 && x <= w ) {
setSaturation( hsl[ 1 ] + theRotationValue * 0.01 );
_myColorValue = HSLtoRGB( hsl );
setValue( _myColorValue );
} else if ( x >= getWidth( ) - w && x <= getWidth( ) ) {
setAlpha( a( ) + theRotationValue );
}
}
return this;
}
private void setColorResources( ) {
/* for now there is only a default resource but this
* can be extended to support other color models in
* the future. */
PGraphics buffer = _myColorResources.get( "default" );
buffer.beginDraw( );
buffer.background( 0 , 0 );
int w = buffer.width;
int h = buffer.height;
float[] center = new float[] { w / 2 , h / 2 };
int inner_radius = ( int ) ( buffer.width * 0.1 );
int outer_radius = ( int ) ( buffer.width * scalar / 2 );
buffer.fill( 0 );
buffer.ellipseMode( CENTER );
buffer.ellipse( buffer.width / 2 , buffer.height / 2 , buffer.width * scalar + 4 , buffer.width * scalar + 4 );
buffer.fill( 255 );
buffer.ellipse( buffer.width / 2 , buffer.height / 2 , ( inner_radius + 1 ) * 2 , ( inner_radius + 1 ) * 2 );
for ( int y = 0 ; y < h ; y++ ) {
int dy = ( int ) ( y( center ) - y );
for ( int x = 0 ; x < w ; x++ ) {
int dx = ( int ) ( x( center ) - x );
double dist = Math.sqrt( dx * dx + dy * dy );
if ( dist >= inner_radius && dist <= outer_radius ) {
double theta = Math.atan2( dy , dx );
// theta can go from -pi to pi
double hue = ( theta + PI ) / ( TWO_PI );
double sat , val;
if ( dist < ( inner_radius + ( outer_radius - inner_radius ) / 2 ) ) {
sat = map( dist , inner_radius , outer_radius , 0 , 2 );
val = 1;
} else {
sat = 1;
val = map( dist , inner_radius , outer_radius , 2 , 0 );
}
buffer.set( x , y , HSVtoRGB( hue , sat , val ) );
}
}
}
buffer.endDraw( );
}
public void setHue( double theH ) {
hsl[ 0 ] = Math.max( 0 , Math.min( 1 , theH ) );
}
public void setSaturation( double theS ) {
hsl[ 1 ] = Math.max( 0 , Math.min( 1 , theS ) );
}
public void setLightness( double theL ) {
hsl[ 2 ] = Math.max( 0 , Math.min( 1 , theL ) );
}
public ColorWheel setHSL( double theH , double theS , double theL ) {
setHue( theH );
setSaturation( theS );
setLightness( theL );
return this;
}
public int getRGB( ) {
return _myColorValue;
}
public ColorWheel setRGB( int theColor ) {
double[] t = RGBtoHSL( theColor );
hsl[ 0 ] = t[ 0 ];
hsl[ 2 ] = t[ 2 ];
float theta = ( float ) ( t[ 0 ] * TWO_PI ) - PI;
float d0 = getWidth( ) * 0.1f;
float d1 = ( ( getWidth( ) / 2 ) * scalar ) + 1f;
float s = ( float ) map( t[ 2 ] , 0f , 1f , d1 , d0 );
float x = _myColorResources.get( "default" ).width / 2 - ( float ) Math.cos( theta ) * s;
float y = _myColorResources.get( "default" ).height / 2 - ( float ) Math.sin( theta ) * s;
set( _myCursor , x , y );
setSaturation( t[ 1 ] );
// TODO resolve rounding error issue as reported here https://github.com/sojamo/controlp5/issues/21
_myColorValue = HSLtoRGB( hsl );
setValue( _myColorValue );
return this;
}
public ColorWheel setAlpha( int theAlpha ) {
/* TODO */
return this;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public ColorWheel updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
/**
* @exclude
*/
@ControlP5.Invisible public ColorWheel updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
case ( IMAGE ):
case ( CUSTOM ):
_myControllerView = new ColorWheelView( );
default:
break;
}
return this;
}
public int a( ) {
int a = ( _myColorValue & 0xff000000 ) >> 24;
return ( a < 0 ) ? 255 : a;
}
public int r( ) {
return ( _myColorValue & 0x00ff0000 ) >> 16;
}
public int g( ) {
return ( _myColorValue & 0x0000ff00 ) >> 8;
}
public int b( ) {
return ( _myColorValue & 0x000000ff ) >> 0;
}
private class ColorWheelView implements ControllerView< ColorWheel > {
public void display( PGraphics theGraphics , ColorWheel theController ) {
PGraphics buffer = _myColorResources.get( "default" );
theGraphics.fill( 0 , 100 );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.ellipseMode( PApplet.CENTER );
theGraphics.pushMatrix( );
theGraphics.translate( 0 , -yoff );
theGraphics.image( buffer , 0 , 0 );
theGraphics.pushMatrix( );
theGraphics.translate( x( _myCursor ) , y( _myCursor ) );
theGraphics.strokeWeight( 2 );
theGraphics.noFill( );
theGraphics.stroke( 255 , 40 );
theGraphics.ellipse( 1 , 1 , 10 , 10 );
theGraphics.stroke( 250 );
theGraphics.fill( _myColorValue );
theGraphics.ellipse( 0 , 0 , 10 , 10 );
theGraphics.popMatrix( );
theGraphics.noStroke( );
theGraphics.translate( 0 , -yoff );
theGraphics.fill( HSLtoRGB( hsl[ 0 ] , hsl[ 1 ] , hsl[ 2 ] ) );
theGraphics.rect( 0 , getHeight( ) , getWidth( ) , yoff * 2 );
theGraphics.popMatrix( );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
if ( isInfo ) {
_myInfoLabel.setText( String.format( "RGB %d %d %d\nALPHA %d\nHSL %d %.2f %.2f " , r( ) , g( ) , b( ) , a( ) , ( int ) ( hsl[ 0 ] * 360 ) , hsl[ 1 ] , hsl[ 2 ] ) );
_myInfoLabel.draw( theGraphics , 0 , 0 , theController );
}
theGraphics.fill( 255 );
theGraphics.pushMatrix( );
int s = _sideHandleHeight / 2;
float v = ( getHeight( ) - ( yoff * 2 ) - _sideHandleHeight );
theGraphics.translate( 2 , ( int ) map( hsl[ 1 ] , 1 , 0 , 0 , v ) );
theGraphics.triangle( 0 , s , s , 0 , s , _sideHandleHeight );
theGraphics.popMatrix( );
/* TODO alpha handle theGraphics.pushMatrix( );
* theGraphics.translate( getWidth( ) - s - 2 ,
* ( int ) map( a( ) , 255 , 0 , 0 , v ) );
* theGraphics.triangle( s , s , 0 , 0 , 0 ,
* _sideHandleHeight ); theGraphics.popMatrix(
* ); */
}
}
public double[] RGBtoHSL( int theRGB ) {
return RGBtoHSL( theRGB >> 16 & 0xff , theRGB >> 8 & 0xff , theRGB >> 0 & 0xff );
}
/**
*
* @param theR value between 0 and 255
* @param theG value between 0 and 255
* @param theB value between 0 and 255
* @return double[] values h,s,l are between 0-1
*/
public double[] RGBtoHSL( int theR , int theG , int theB ) {
double[] rgb = new double[ 3 ];
rgb[ 0 ] = theR / 255.0;
rgb[ 1 ] = theG / 255.0;
rgb[ 2 ] = theB / 255.0;
double max = Math.max( rgb[ 0 ] , Math.max( rgb[ 1 ] , rgb[ 2 ] ) );
double min = Math.min( rgb[ 0 ] , Math.min( rgb[ 1 ] , rgb[ 2 ] ) );
double h = ( max + min ) / 2;
double s = ( max + min ) / 2;
double l = ( max + min ) / 2;
if ( max == min ) {
h = s = 0; // achromatic
} else {
double d = max - min;
s = l > 0.5 ? ( d / ( 2 - max - min ) ) : ( d / ( max + min ) );
if ( max == rgb[ 0 ] ) {
h = ( rgb[ 1 ] - rgb[ 2 ] ) / d + ( rgb[ 1 ] < rgb[ 2 ] ? 6 : 0 );
} else if ( max == rgb[ 1 ] ) {
h = ( rgb[ 2 ] - rgb[ 0 ] ) / d + 2;
} else if ( max == rgb[ 2 ] ) {
h = ( rgb[ 0 ] - rgb[ 1 ] ) / d + 4;
}
h /= 6;
}
return new double[] { h , s , l };
}
public int HSVtoRGB( double[] hsv ) {
return HSVtoRGB( hsv[ 0 ] , hsv[ 1 ] , hsv[ 2 ] );
}
/**
*
* @param H value between 0-1
* @param S value between 0-1
* @param V value between 0-1
* @return int
*/
public int HSVtoRGB( double H , double S , double V ) {
/* http://viziblr.com/news/2011/12/1/drawing-a-color-
* hue-wheel-with-c.html */
double[] rgb = new double[ 3 ];
if ( H == 1.0 ) {
H = 0.0;
}
double step = 1.0 / 6.0;
double vh = H / step;
int i = ( int ) Math.floor( vh );
double f = vh - i;
double p = V * ( 1.0 - S );
double q = V * ( 1.0 - ( S * f ) );
double t = V * ( 1.0 - ( S * ( 1.0 - f ) ) );
switch ( i ) {
case 0: {
rgb[ 0 ] = V;
rgb[ 1 ] = t;
rgb[ 2 ] = p;
break;
}
case 1: {
rgb[ 0 ] = q;
rgb[ 1 ] = V;
rgb[ 2 ] = p;
break;
}
case 2: {
rgb[ 0 ] = p;
rgb[ 1 ] = V;
rgb[ 2 ] = t;
break;
}
case 3: {
rgb[ 0 ] = p;
rgb[ 1 ] = q;
rgb[ 2 ] = V;
break;
}
case 4: {
rgb[ 0 ] = t;
rgb[ 1 ] = p;
rgb[ 2 ] = V;
break;
}
case 5: {
rgb[ 0 ] = V;
rgb[ 1 ] = p;
rgb[ 2 ] = q;
break;
}
default: {
// not possible - if we get here it is an
// internal error
// throw new ArgumentException();
System.out.println( "hsv to rgb not possible" );
}
}
return ( a( ) << 24 ) | ( ( int ) ( rgb[ 0 ] * 255 ) << 16 ) | ( ( int ) ( rgb[ 1 ] * 255 ) << 8 ) | ( int ) ( rgb[ 2 ] * 255 );
}
public final double[] RGBtoHSV( final int c ) {
return RGBtoHSV( ( c & 0xff0000 ) >> 16 , ( c & 0x00ff00 ) >> 8 , ( c & 0x0000ff ) >> 0 );
}
/**
*
* @param theR value between 0 and 255
* @param theG value between 0 and 255
* @param theB value between 0 and 255
* @return hsv [ hue (0-1) sat (0-1) val (0-1) ]
*/
public final double[] RGBtoHSV( final int theR , final int theG , final double theB ) {
double hue = 0;
double sat = 0;
double val = 0;
final double r = theR / 255.0;
final double g = theG / 255.0;
final double b = theB / 255.0;
double minRGB = Math.min( r , Math.min( g , b ) );
double maxRGB = Math.max( r , Math.max( g , b ) );
// Black-gray-white
if ( minRGB == maxRGB ) {
return new double[] { 0 , 0 , minRGB };
}
// Colors other than black-gray-white:
double d = ( r == minRGB ) ? g - b : ( ( b == minRGB ) ? r - g : b - r );
double h = ( r == minRGB ) ? 3 : ( ( b == minRGB ) ? 1 : 5 );
hue = map( ( h - ( d / ( maxRGB - minRGB ) ) ) , 0 , 6.0 , 0 , 1.0 );
sat = ( maxRGB - minRGB ) / maxRGB;
val = maxRGB;
return new double[] { hue , sat , val };
}
public int HSLtoRGB( final double[] theHSL ) {
if ( theHSL.length == 3 ) {
return HSLtoRGB( theHSL[ 0 ] , theHSL[ 1 ] , theHSL[ 2 ] );
} else {
String message = "HSLtoRGB(double[]) a length of 3 is expected. ";
throw new IllegalArgumentException( message );
}
}
/**
*
* @param h value between 0 and 360
* @param s value between 0 and 100
* @param l) value between 0 and 100
* @param alpha value between 0 and 1
* @return
*/
public int HSLtoRGB( final double h , double s , double l ) {
if ( h < 0.0 || h > 1.0 ) {
String message = "Color parameter outside of expected range - Hue ( 0.0 - 1.0 )";
throw new IllegalArgumentException( message );
}
if ( s < 0.0 || s > 1.0 ) {
String message = "Color parameter outside of expected range - Saturation ( 0.0 - 1.0 )";
throw new IllegalArgumentException( message );
}
if ( l < 0.0 || l > 1.0 ) {
String message = "Color parameter outside of expected range - Luminance ( 0.0 - 1.0 )";
throw new IllegalArgumentException( message );
}
double q = 0;
if ( l < 0.5 ) {
q = l * ( 1 + s );
} else {
q = ( l + s ) - ( s * l );
}
double p = 2 * l - q;
double r = Math.max( 0 , HueToRGB( p , q , h + ( 1.0f / 3.0f ) ) );
double g = Math.max( 0 , HueToRGB( p , q , h ) );
double b = Math.max( 0 , HueToRGB( p , q , h - ( 1.0f / 3.0f ) ) );
return ( 255 << 24 ) | ( ( int ) ( r * 255 ) << 16 ) | ( ( int ) ( g * 255 ) << 8 ) | ( int ) ( b * 255 );
}
private static double HueToRGB( double p , double q , double h ) {
if ( h < 0 )
h += 1;
if ( h > 1 )
h -= 1;
if ( 6 * h < 1 ) {
return p + ( ( q - p ) * 6 * h );
}
if ( 2 * h < 1 ) {
return q;
}
if ( 3 * h < 2 ) {
return p + ( ( q - p ) * 6 * ( ( 2.0f / 3.0f ) - h ) );
}
return p;
}
private final double map( double val , double a1 , double a2 , double b1 , double b2 ) {
return b1 + ( b2 - b1 ) * ( ( val - a1 ) / ( a2 - a1 ) );
}
}

106
controlP5/ControlBehavior.java Executable file
View File

@ -0,0 +1,106 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* The abstract class control behavior allows you to add custom behavior to controllers. Since it is
* an abstract class it must be extended and method update() must be implemented in your custom
* control behavior. how to use ControlBehavior please see the ControlP5behavior example in the
* examples folder.
*
* @example use/ControlP5behavior
*/
public abstract class ControlBehavior {
protected Controller< ? > _myController;
protected float value;
protected boolean isActive = true;
protected void init( Controller< ? > theController ) {
_myController = theController;
}
/**
* Returns the controller this behavior is connected to.
*
* @return Controller
*/
public Controller< ? > getController( ) {
return _myController;
}
public float getValue( ) {
return value;
}
public void setValue( float theValue ) {
value = theValue;
_myController.setValue( value );
}
/**
* When extending ControlBehavior, update() has to be overridden.
*/
public abstract void update( );
/**
* (de)activate the behavior.
*
* @param theFlag
* boolean
*/
public void setActive( boolean theFlag ) {
isActive = theFlag;
}
/**
* check if the behavior is active or not.
*
* @return boolean
*/
public boolean isActive( ) {
return isActive;
}
/**
* @exclude
* @return
*/
@Deprecated
public float value( ) {
return value;
}
/**
* @exclude
*/
@Deprecated
public Controller< ? > controller( ) {
return _myController;
}
}

401
controlP5/ControlBroadcaster.java Executable file
View File

@ -0,0 +1,401 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
/**
* The ControlBroadcaster handles all controller value changes and distributes them accordingly to
* its listeners. The ControlBroadcaster is primarily for internal use only but can be accessed
* through an instance of the ControlP5 class. Instead of accessing the ControlBroadcaster directly,
* use the convenience methods available from the ControlP5 class.
*
* @see ControlP5#getControlBroadcaster()
*/
public class ControlBroadcaster {
private int _myControlEventType = ControlP5Constants.INVALID;
private ControllerPlug _myControlEventPlug = null;
private ControllerPlug _myControllerCallbackEventPlug = null;
private final ControlP5 cp5;
private final String _myEventMethod = "controlEvent";
private final String _myControllerCallbackEventMethod = "controlEvent";
private final ArrayList< ControlListener > _myControlListeners;
private final Set< Entry< CallbackListener , Controller< ? >>> _myControllerCallbackListeners;
private static boolean setPrintStackTrace = true;
private static boolean ignoreErrorMessage = false;
private static final Map< Class< ? > , Field[] > fieldcache = new HashMap< Class< ? > , Field[] >( );
private static final Map< Class< ? > , Method[] > methodcache = new HashMap< Class< ? > , Method[] >( );
boolean broadcast = true;
protected ControlBroadcaster( ControlP5 theControlP5 ) {
cp5 = theControlP5;
_myControlListeners = new ArrayList< ControlListener >( );
_myControllerCallbackListeners = new HashSet< Entry< CallbackListener , Controller< ? >>>( );
_myControlEventPlug = checkObject( cp5.papplet , getEventMethod( ) , new Class[] { ControlEvent.class } );
_myControllerCallbackEventPlug = checkObject( cp5.papplet , _myControllerCallbackEventMethod , new Class[] { CallbackEvent.class } );
if ( _myControlEventPlug != null ) {
_myControlEventType = ControlP5Constants.METHOD;
}
}
public ControlBroadcaster addListener( ControlListener ... theListeners ) {
Collections.addAll(_myControlListeners, theListeners);
return this;
}
public ControlBroadcaster removeListener( ControlListener ... theListeners ) {
for ( ControlListener l : theListeners ) {
_myControlListeners.remove( l );
}
return this;
}
/**
* Returns a ControlListener by index
*
* @param theIndex
* @return
*/
public ControlListener getListener( int theIndex ) {
if ( theIndex < 0 || theIndex >= _myControlListeners.size( ) ) {
return null;
}
return _myControlListeners.get( theIndex );
}
/**
* Returns the size of the ControlListener list
*
* @return
*/
public int listenerSize( ) {
return _myControlListeners.size( );
}
public ControlBroadcaster addCallback( CallbackListener ... theListeners ) {
for ( CallbackListener l : theListeners ) {
_myControllerCallbackListeners.add( new SimpleEntry< CallbackListener , Controller< ? >>( l , new EmptyController( ) ) );
}
return this;
}
public ControlBroadcaster addCallback( CallbackListener theListener ) {
_myControllerCallbackListeners.add( new SimpleEntry< CallbackListener , Controller< ? >>( theListener , new EmptyController( ) ) );
return this;
}
/**
* Adds a CallbackListener for a list of controllers.
*
* @param theListener
* @param theController
*/
public void addCallback( CallbackListener theListener , Controller< ? > ... theController ) {
for ( Controller< ? > c : theController ) {
_myControllerCallbackListeners.add( new SimpleEntry< CallbackListener , Controller< ? >>( theListener , c ) );
}
}
public ControlBroadcaster removeCallback( CallbackListener ... theListeners ) {
for ( CallbackListener c : theListeners ) {
_myControllerCallbackListeners.remove( c );
}
return this;
}
public ControlBroadcaster removeCallback( CallbackListener theListener ) {
_myControllerCallbackListeners.remove( theListener );
return this;
}
/**
* Removes a CallbackListener for a particular controller
*
* @param theController
*/
public ControlBroadcaster removeCallback( Controller< ? > ... theControllers ) {
for ( Controller< ? > c : theControllers ) {
for ( Entry< CallbackListener , Controller< ? >> entry : _myControllerCallbackListeners ) {
if (entry.getValue().equals(c)) {
_myControllerCallbackListeners.remove( entry );
}
}
}
return this;
}
public ControlBroadcaster plug( Object theObject , final String theControllerName , final String theTargetMethod ) {
plug( theObject , cp5.getController( theControllerName ) , theTargetMethod );
return this;
}
public ControlBroadcaster plug( Object theObject , final Controller< ? > theController , final String theTargetMethod ) {
if ( theController != null ) {
ControllerPlug myControllerPlug = checkObject( theObject , theTargetMethod , ControlP5Constants.acceptClassList );
if ( myControllerPlug == null ) {
return this;
} else {
if (!theController.checkControllerPlug(myControllerPlug)) {
theController.addControllerPlug( myControllerPlug );
}
return this;
}
}
return this;
}
static Field[] getFieldsFor( Class< ? > theClass ) {
if ( !fieldcache.containsKey( theClass ) ) {
fieldcache.put( theClass , theClass.getDeclaredFields( ) );
}
return fieldcache.get( theClass );
}
static Method[] getMethodFor( Class< ? > theClass ) {
if ( !methodcache.containsKey( theClass ) ) {
methodcache.put( theClass , theClass.getMethods( ) );
}
return methodcache.get( theClass );
}
protected static ControllerPlug checkObject( final Object theObject , final String theTargetName , final Class< ? >[] theAcceptClassList ) {
Class< ? > myClass = theObject.getClass( );
Method[] myMethods = getMethodFor( myClass );
for ( int i = 0 ; i < myMethods.length ; i++ ) {
if ( ( myMethods[ i ].getName( ) ).equals( theTargetName ) ) {
if ( myMethods[ i ].getParameterTypes( ).length == 1 ) {
// hack to detect controlEvent(CallbackEvent) which is otherwise
// overwritten by controlEvent(ControlEvent)
if ( theAcceptClassList.length == 1 ) {
if ( theAcceptClassList[ 0 ] == CallbackEvent.class ) {
ControllerPlug cp = new ControllerPlug( CallbackEvent.class , theObject , theTargetName , ControlP5Constants.EVENT , -1 );
if ( cp.getMethod( ) == null ) {
return null;
}
return cp;
}
}
if ( myMethods[ i ].getParameterTypes( )[ 0 ] == ControlP5Constants.controlEventClass ) {
return new ControllerPlug( ControlEvent.class , theObject , theTargetName , ControlP5Constants.EVENT , -1 );
}
for ( int j = 0 ; j < theAcceptClassList.length ; j++ ) {
if ( myMethods[ i ].getParameterTypes( )[ 0 ] == theAcceptClassList[ j ] ) {
return new ControllerPlug( theObject , theTargetName , ControlP5Constants.METHOD , j , theAcceptClassList );
}
}
} else if ( myMethods[ i ].getParameterTypes( ).length == 0 ) {
return new ControllerPlug( theObject , theTargetName , ControlP5Constants.METHOD , -1 , theAcceptClassList );
}
break;
}
}
Field[] myFields = getFieldsFor( myClass );
for ( int i = 0 ; i < myFields.length ; i++ ) {
if ( ( myFields[ i ].getName( ) ).equals( theTargetName ) ) {
for ( int j = 0 ; j < theAcceptClassList.length ; j++ ) {
if ( myFields[ i ].getType( ) == theAcceptClassList[ j ] ) {
return new ControllerPlug( theObject , theTargetName , ControlP5Constants.FIELD , j , theAcceptClassList );
}
}
break;
}
}
return null;
}
public ControlBroadcaster broadcast( final ControlEvent theControlEvent , final int theType ) {
if ( broadcast ) {
for ( ControlListener cl : _myControlListeners ) {
cl.controlEvent( theControlEvent );
}
if ( !theControlEvent.isTab( ) && !theControlEvent.isGroup( ) ) {
if ( theControlEvent.getController( ).getControllerPlugList( ).size( ) > 0 ) {
if ( theType == ControlP5Constants.STRING ) {
for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) {
callTarget( cp , theControlEvent.getStringValue( ) );
}
} else if ( theType == ControlP5Constants.ARRAY ) {
} else if ( theType == ControlP5Constants.BOOLEAN ) {
for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) {
Controller controller = theControlEvent.getController( );
if ( controller instanceof Icon ) {
callTarget( cp , ( ( Icon ) controller ).getBooleanValue( ) );
} else if ( controller instanceof Button ) {
callTarget( cp , ( ( Button ) controller ).getBooleanValue( ) );
} else if ( controller instanceof Toggle ) {
callTarget( cp , ( ( Toggle ) controller ).getBooleanValue( ) );
}
}
} else {
for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) {
if ( cp.checkType( ControlP5Constants.EVENT ) ) {
invokeMethod( cp.getObject( ) , cp.getMethod( ) , new Object[] { theControlEvent } );
} else {
callTarget( cp , theControlEvent.getValue( ) );
}
}
}
}
}
if ( _myControlEventType == ControlP5Constants.METHOD ) {
invokeMethod( _myControlEventPlug.getObject( ) , _myControlEventPlug.getMethod( ) , new Object[] { theControlEvent } );
}
}
return this;
}
protected void callTarget( final ControllerPlug thePlug , final float theValue ) {
if ( thePlug.checkType( ControlP5Constants.METHOD ) ) {
invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , thePlug.getMethodParameter( theValue ) );
} else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) {
invokeField( thePlug.getObject( ) , thePlug.getField( ) , thePlug.getFieldParameter( theValue ) );
}
}
protected void callTarget( final ControllerPlug thePlug , final String theValue ) {
if ( thePlug.checkType( ControlP5Constants.METHOD ) ) {
invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , new Object[] { theValue } );
} else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) {
invokeField( thePlug.getObject( ) , thePlug.getField( ) , theValue );
}
}
protected void callTarget( final ControllerPlug thePlug , final boolean theValue ) {
if ( thePlug.checkType( ControlP5Constants.METHOD ) ) {
invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , new Object[] { theValue } );
} else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) {
invokeField( thePlug.getObject( ) , thePlug.getField( ) , theValue );
}
}
private void invokeField( final Object theObject , final Field theField , final Object theParam ) {
try {
theField.set( theObject , theParam );
} catch ( IllegalAccessException e ) {
ControlP5.logger( ).warning( e.toString( ) );
}
}
private void invokeMethod( final Object theObject , final Method theMethod , final Object[] theParam ) {
try {
if ( theParam[ 0 ] == null ) {
theMethod.invoke( theObject);
} else {
theMethod.invoke( theObject , theParam );
}
} catch ( IllegalArgumentException e ) {
ControlP5.logger( ).warning( e.toString( ) );
/**
* TODO thrown when plugging a String method/field.
*/
} catch ( IllegalAccessException e ) {
printMethodError( theMethod , e );
} catch ( InvocationTargetException e ) {
printMethodError( theMethod , e );
} catch ( NullPointerException e ) {
printMethodError( theMethod , e );
}
}
protected String getEventMethod( ) {
return _myEventMethod;
}
protected void invokeAction( CallbackEvent theEvent ) {
boolean invoke;
for ( Entry< CallbackListener , Controller< ? >> entry : _myControllerCallbackListeners ) {
invoke = entry.getValue().getClass().equals(EmptyController.class) || entry.getValue().equals(theEvent.getController());
if ( invoke ) {
entry.getKey( ).controlEvent( theEvent );
}
}
if ( _myControllerCallbackEventPlug != null ) {
invokeMethod( cp5.papplet , _myControllerCallbackEventPlug.getMethod( ) , new Object[] { theEvent } );
}
}
private void printMethodError( Method theMethod , Exception theException ) {
if ( !ignoreErrorMessage ) {
ControlP5.logger( ).severe( "An error occured while forwarding a Controller event, please check your code at " + theMethod.getName( ) + ( !setPrintStackTrace ? " " + "exception: " + theException : "" ) );
if ( setPrintStackTrace ) {
theException.printStackTrace( );
}
}
}
public static void ignoreErrorMessage( boolean theFlag ) {
ignoreErrorMessage = theFlag;
}
public static void setPrintStackTrace( boolean theFlag ) {
setPrintStackTrace = theFlag;
}
private class EmptyController extends Controller< EmptyController > {
protected EmptyController( ) {
this( 0 , 0 );
}
protected EmptyController( int theX , int theY ) {
super( "empty" + ( ( int ) ( Math.random( ) * 1000000 ) ) , theX , theY );
// TODO Auto-generated constructor stub
}
@Override public EmptyController setValue( float theValue ) {
// TODO Auto-generated method stub
return this;
}
}
/**
* @exclude
*/
@Deprecated public void plug( final String theControllerName , final String theTargetMethod ) {
plug( cp5.papplet , theControllerName , theTargetMethod );
}
}

48
controlP5/ControlElement.java Executable file
View File

@ -0,0 +1,48 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Used for automated controller creation using annotations. Very much inspired by Karsten Schmidt's
* (toxi) cp5magic
*
* @example use/ControlP5annotation
*/
@Retention( RetentionPolicy.RUNTIME )
public @interface ControlElement {
String[] properties() default { };
String label() default "";
int x() default -1;
int y() default -1;
}

339
controlP5/ControlEvent.java Executable file
View File

@ -0,0 +1,339 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* A controlEvent is sent to a PApplet or a ControlListener whenever a controller value has changed.
* Events can also be sent when a tab is activated, but by default tab events are disabled and have
* to be enabled with {@link Tab} Tab.activateEvent(). for detailed information see the tab
* documentation.
*
* @example use/ControlP5controlEvent
*/
public class ControlEvent {
public static int UNDEFINDED = -1;
public static int CONTROLLER = 0;
public static int TAB = 1;
public static int GROUP = 2;
protected final ControllerInterface< ? > _myController;
protected boolean isTab;
protected boolean isController;
protected boolean isGroup;
protected int myAction;
/**
*
* @param theController
* Controller
*/
protected ControlEvent( Controller< ? > theController ) {
_myController = theController;
isTab = false;
isController = true;
isGroup = false;
}
/**
* @exclude
* @param theController
* Controller
*/
public ControlEvent( Tab theController ) {
_myController = theController;
isTab = true;
isGroup = false;
isController = false;
}
/**
* @exclude
* @param theController
* Controller
*/
public ControlEvent( ControllerGroup< ? > theController ) {
_myController = theController;
isTab = false;
isGroup = true;
isController = false;
}
public float getValue( ) {
return _myController.getValue( );
}
public String getStringValue( ) {
return _myController.getStringValue( );
}
/**
* Returns a float array, applies to e.g. Range.
*
* @return float[]
*/
public float[] getArrayValue( ) {
return _myController.getArrayValue( );
}
/**
* Returns a float value at a particular index from a controller's array value. No error
* checking available here, will throw ArrayIndexOutOfBOundsException in case of unavailable
* index.
*
* @param theIndex
* @return
*/
public float getArrayValue( int theIndex ) {
return _myController.getArrayValue( )[ theIndex ];
}
/**
* Returns the instance of the controller sending the ControlEvent.
*
* @return Controller
*/
public Controller< ? > getController( ) {
return ( ( Controller< ? > ) _myController );
}
/**
* Returns the tab that triggered the ControlEvent
*
* @return Tab Tab
*/
public Tab getTab( ) {
return ( Tab ) _myController;
}
/**
* Returns the group that evoked the ControlEvent
*
* @return ControlGroup
*/
public ControlGroup< ? > getGroup( ) {
return ( ControlGroup< ? > ) _myController;
}
/**
* Gets the text of the controller's label that has evoked the event.
*
* @return String
*/
public String getLabel( ) {
return ( ( Controller< ? > ) _myController ).getLabel( );
}
/**
* Checks if the ControlEvent was triggered by a tab
*
* @see Tab
* @return boolean
*/
public boolean isTab( ) {
return isTab;
}
/**
* Checks if the ControlEvent was triggered by a controller
*
* @see Controller
* @return boolean
*/
public boolean isController( ) {
return isController;
}
/**
* Checks if the ControlEvent was triggered by a ControlGroup
*
* @see ControllerGroup
* @return boolean
*/
public boolean isGroup( ) {
return isGroup;
}
/**
* returns the controller's name
*
* @return String
*/
public String getName( ) {
return _myController.getName( );
}
/**
* Returns the controller's id, if an id has not been set before the default value -1 will be
* returned.
*
* @return
*/
public int getId( ) {
return _myController.getId( );
}
/**
* @return int returned is ControlP5.CONTROLLER, or ControlP5.TAB, or ControlP5.GROUP
*/
public int getType( ) {
if ( isController ) {
return CONTROLLER;
} else if ( isTab ) {
return TAB;
} else if ( isGroup ) {
return GROUP;
}
return -1;
}
/**
* Checks if the ControlEvent originates from a specific Controller or ControllerGroup.
*
* @param theController
* @return boolean
*/
public boolean isFrom( ControllerInterface< ? > theController ) {
return _myController.equals( theController );
}
/**
* checks if the ControlEvent originates from a specific Controller or ControllerGroup
* identifiable by name.
*
* @param theController
* @return boolean
*/
public boolean isFrom( String theControllerName ) {
return _myController.getName( ).equals( theControllerName );
}
public boolean isAssignableFrom( Class< ? > c ) {
return _myController.getClass( ).isAssignableFrom( c );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public int type( ) {
return getType( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public int id( ) {
return getId( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public String name( ) {
return getName( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public String label( ) {
return getLabel( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public float value( ) {
return getValue( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public String stringValue( ) {
return getStringValue( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public float[] arrayValue( ) {
return getArrayValue( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public Controller< ? > controller( ) {
return getController( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public ControlGroup< ? > group( ) {
return getGroup( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated
public Tab tab( ) {
return getTab( );
}
public String toString( ) {
return "[ ControlEvent from:" + _myController.getClass( ).getSimpleName( ) + " value:" + getValue( ) + " name:" + getName( ) + " ]";
}
}

292
controlP5/ControlFont.java Executable file
View File

@ -0,0 +1,292 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import java.util.List;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
/**
* A ControlFont is a container for a PFont that can be used to customize the font of a label.
* (Designing the Font handling gave me a big headache, especially when it comes to calculating the
* dimensions of a font which are not available at all times but only at certain times. The current
* status I suppose is a good compromise and works for standard font handling cases. For any special
* cases it will be difficult to convince me to make any changes.)
*
* @example extra/ControlP5controlFont
*/
public class ControlFont {
public static boolean DEBUG = false;
/**
* set the RENDER_2X variable to true to double render text, this makes the font look bolder
* especially in OpenGL mode. use: ControlFont.RENDER_2X = true;
*/
public static boolean RENDER_2X;
/**
* renders a PFont twice for better and sharper readability
*/
public static void sharp( ) {
RENDER_2X = true;
}
/**
* sets the rendering of a PFont back to normal and single rendering.
*/
public static void normal( ) {
RENDER_2X = false;
}
PFont pfont;
List< String > txt;
String s = "";
private int top;
private int bottom;
private int center;
private int height;
private int width;
private final int baseline = 0;
private int _myTextHeight = 1;
private final int[] offset = new int[ 2 ];
private int size;
public ControlFont( PFont theFont ) {
this( theFont , checkFontSize( theFont ) );
}
public ControlFont( PFont theFont , int theFontSize ) {
this( theFont , theFontSize , theFontSize + 2 );
}
public ControlFont( PFont theFont , int theFontSize , int theLineHeight ) {
pfont = theFont;
size = theFontSize;
txt = new ArrayList< String >( );
}
static private int checkFontSize( PFont theFont ) {
try {
// was: return theFont.getFont().getSize(); but disappeared with p5 2.0b1
return theFont.getSize( );
} catch ( NullPointerException e ) {
System.out.println( "ControlP5: could not find font-size details for font " + theFont.getName( ) + ", use constructor ControlFont(PFont theFont, int theFontSize) to specify the font size." );
return 10;
}
}
public void init( Label theLabel ) {
// when the font changes, init is called.
// width and height should be adjusted to the updated font here,
// but we need PApplet here to determine the width of the label.
// unfortunately we dont have access to PApplet here, so a change
// might result in a 1-frame-flickr but doesnt necessarily need
// to happen.
}
public void setSize( int theSize ) {
size = theSize;
}
public int getSize( ) {
/* quickfix http://code.google.com/p/controlp5/issues/detail?id=46 first check the pfont
* size then default back to size */
return size;
}
public int getOffset( int theIndex ) {
return offset[ theIndex ];
}
public int getTextHeight( ) {
return _myTextHeight;
}
public int getWidth( ) {
return width;
}
public int getHeight( ) {
return height;
}
public int getCenter( ) {
return center;
}
public int getTop( ) {
return top;
}
public int getBottom( ) {
return bottom;
}
public int getBaseline( ) {
return baseline;
}
public PFont getFont( ) {
return pfont;
}
public void adjust( PGraphics theGraphics , Label theLabel ) {
if ( theLabel.isChanged( ) ) {
theGraphics.textFont( pfont , size );
// the origin of a PFont Label is top left corner, therefore
// the following the following measures have to be calculated
// when a font is changed. we have to do that here since PApplet
// is required to calculate a font's ascent and descent value.
// values are calculated based on the baseline (which is 0),
// therefore center and top are negative values.
// to order to sync the line height with the height of the font,
// the value of lineHeightOffset carries this offset value.
// This becomes necessary when working with multiple lines.
top = -( int ) theGraphics.textAscent( );
bottom = ( int ) theGraphics.textDescent( );
center = -( int ) ( ( -top - bottom ) / 2 );
height = theLabel.isMultiline( ) ? theLabel.getHeight( ) : ( int ) ( theGraphics.textAscent( ) + theGraphics.textDescent( ) );
width = theLabel.isMultiline( ) ? theLabel.getWidth( ) : ( int ) theGraphics.textWidth( theLabel.getTextFormatted( ) );
if ( theLabel.isMultiline( ) ) {
calculateHeight( theGraphics , theLabel );
}
theLabel.setChanged( false );
}
}
private void calculateHeight( PGraphics theGraphics , Label theLabel ) {
txt.clear( );
String myString = theLabel.getTextFormatted( );
String[] paragraphs = myString.split( "\n" );
// does not recognize linebreaks at the end of theString.
myString = "";
for ( String p : paragraphs ) {
String[] words = p.split( "\\s" );
for ( String w : words ) {
if ( theGraphics.textWidth( myString + w ) < width ) {
myString += w + " ";
} else {
txt.add( myString.substring( 0 , PApplet.max( 0 , myString.length( ) - 1 ) ) );
myString = w + " ";
}
}
txt.add( myString.substring( 0 , myString.length( ) - 1 ) );
myString = "";
}
if ( theLabel.getHeight( ) % theLabel.getLineHeight( ) != 0 ) {
txt.add( "" );
}
_myTextHeight = ( PApplet.round( txt.size( ) * theLabel.getLineHeight( ) ) );
int maxLineNum = PApplet.round( theLabel.getHeight( ) / theLabel.getLineHeight( ) );
int offset = ( int ) ( PApplet.max( 0 , txt.size( ) - maxLineNum ) * ( PApplet.abs( theLabel.getOffsetYratio( ) ) ) );
int lim = PApplet.min( txt.size( ) , maxLineNum );
s = "";
for ( int i = 0 ; i < lim ; i++ ) {
s += txt.get( i + offset ) + "\n";
}
}
public int getOverflow( ) {
return ( _myTextHeight - height );
}
public void draw( ControlP5 c , Label theLabel ) {
draw( c.pg , theLabel );
}
public void draw( PGraphics theGraphics , Label theLabel ) {
PFont loadedFont = theGraphics.textFont;
float loadedSize = theGraphics.textSize;
if ( loadedFont == null ) {
theGraphics.textSize( loadedSize ); // forces default font
loadedFont = theGraphics.textFont;
}
int loadedAlign = theGraphics.textAlign;
theGraphics.textFont( pfont , size );
theGraphics.textAlign( theLabel.textAlign );
theGraphics.fill( theLabel.getColor( ) );
if ( theLabel.isMultiline( ) ) {
theGraphics.fill( theLabel.getColor( ) );
theGraphics.textLeading( theLabel.getLineHeight( ) );
theGraphics.text( s , 0 , 0 , theLabel.getWidth( ) , theLabel.getHeight( ) );
} else {
theGraphics.translate( 0 , -top + 1 );
debug( theGraphics , theLabel );
theGraphics.fill( theLabel.getColor( ) );
theGraphics.textLeading( theLabel.getLineHeight( ) );
theGraphics.text( theLabel.getTextFormatted( ) , 0 , 0 );
if ( RENDER_2X ) {
theGraphics.text( theLabel.getTextFormatted( ) , 0 , 0 );
}
}
theGraphics.textFont( loadedFont , loadedSize );
theGraphics.textAlign( loadedAlign );
}
private void debug( PGraphics theGraphics , Label theLabel ) {
if ( DEBUG ) {
theGraphics.stroke( 0 , 255 , 0 ); // BASELINE
theGraphics.line( 0 , getBaseline( ) , theGraphics.textWidth( theLabel.getText( ) ) , getBaseline( ) );
theGraphics.stroke( 0 , 0 , 255 ); // TOP
theGraphics.line( 0 , getTop( ) , theGraphics.textWidth( theLabel.getText( ) ) , getTop( ) );
theGraphics.stroke( 255 , 255 , 0 ); // BOTTOM
theGraphics.line( 0 , getBottom( ) , theGraphics.textWidth( theLabel.getText( ) ) , getBottom( ) );
theGraphics.stroke( 255 , 0 , 0 ); // CENTER
theGraphics.line( 0 , getCenter( ) , theGraphics.textWidth( theLabel.getText( ) ) , getCenter( ) );
theGraphics.stroke( 255 , 128 , 0 ); // CENTER_CAPS
theGraphics.line( 0 , getTop( ) / 2 , theGraphics.textWidth( theLabel.getText( ) ) , getTop( ) / 2 );
theGraphics.noStroke( );
}
}
public static int getWidthFor( String theText , Label theLabel , PGraphics theGraphics ) {
theGraphics.textFont( theLabel.getFont( ).pfont , theLabel.getFont( ).size );
return ( int ) theGraphics.textWidth( theText );
}
}
// textorize, a Ruby-based font rasterizer command line utility for Mac OS X
// http://textorize.org/

199
controlP5/ControlGroup.java Executable file
View File

@ -0,0 +1,199 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import java.util.List;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* <p>
* In previous versions you would use the ControlGroup class
* to bundle controllers in a group. Now please use the
* Group class to do so.
* </p>
* <p>
* ControlGroup extends ControllerGroup, for a list and
* documentation of available methods see the
* {@link ControllerGroup} documentation.
* </p>
*
* @see Group
* @example controllers/ControlP5group
*/
public class ControlGroup< T > extends ControllerGroup< T > implements ControlListener {
protected int _myBackgroundHeight = 0;
protected int _myBackgroundColor = 0x00ffffff;
protected boolean isEventActive = false;
protected List< ControlListener > _myControlListener;
/**
* Convenience constructor to extend ControlGroup.
*/
public ControlGroup( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 100 , 9 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public ControlGroup( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theParent , theName , theX , theY );
_myControlListener = new ArrayList< ControlListener >( );
_myValueLabel = new Label( cp5 , "" );
_myWidth = theW;
_myHeight = theH;
}
@ControlP5.Invisible
public void mousePressed( ) {
if ( isBarVisible && isCollapse ) {
if ( !cp5.isAltDown( ) ) {
isOpen = !isOpen;
if ( isEventActive ) {
final ControlEvent myEvent = new ControlEvent( this );
cp5.getControlBroadcaster( ).broadcast( myEvent , METHOD);
for ( ControlListener cl : _myControlListener ) {
cl.controlEvent( myEvent );
}
}
}
}
}
/**
* activates or deactivates the Event status of a
* ControlGroup.
*/
public T activateEvent( boolean theFlag ) {
isEventActive = theFlag;
return me;
}
public T setSize( int theWidth , int theHeight ) {
super.setSize( theWidth , theHeight );
setBackgroundHeight( theHeight );
return me;
}
public int getBackgroundHeight( ) {
return _myBackgroundHeight;
}
public T setBackgroundHeight( int theHeight ) {
_myBackgroundHeight = theHeight;
return me;
}
public T setBackgroundColor( int theColor ) {
_myBackgroundColor = theColor;
return me;
}
public T setBarHeight( int theHeight ) {
_myHeight = theHeight;
return me;
}
public int getBarHeight( ) {
return _myHeight;
}
@Override
public T updateInternalEvents( PApplet theApplet ) {
if ( isInside && isBarVisible ) {
cp5.getWindow( ).setMouseOverController( this );
}
return me;
}
protected void preDraw( PGraphics theGraphics ) {
if ( isOpen ) {
theGraphics.fill( _myBackgroundColor );
theGraphics.rect( 0 , 0 , _myWidth , _myBackgroundHeight - 1 );
}
}
protected void postDraw( PGraphics theGraphics ) {
if ( isBarVisible ) {
theGraphics.fill( isInside ? color.getForeground( ) : color.getBackground( ) );
theGraphics.rect( 0 , -1 , _myWidth , -_myHeight );
_myLabel.draw( theGraphics , 0 , -_myHeight - 1 , this );
if ( isCollapse && isArrowVisible ) {
theGraphics.fill( _myLabel.getColor( ) );
theGraphics.pushMatrix( );
theGraphics.translate( 2 , 0 );
if ( isOpen ) {
theGraphics.triangle( _myWidth - 10 , -_myHeight / 2 - 3 , _myWidth - 4 , -_myHeight / 2 - 3 , _myWidth - 7 , -_myHeight / 2 );
} else {
theGraphics.triangle( _myWidth - 10 , -_myHeight / 2 , _myWidth - 4 , -_myHeight / 2 , _myWidth - 7 , -_myHeight / 2 - 3 );
}
theGraphics.popMatrix( );
}
}
}
@ControlP5.Invisible
public void controlEvent( ControlEvent theEvent ) {
if ( theEvent.getController( ).getName( ).equals( getName( ) + "close" ) ) {
hide( );
}
}
@ControlP5.Invisible
public String stringValue( ) {
return Float.toString( _myValue );
}
@Override
public String toString( ) {
return super.toString( );
}
@Override
public String getInfo( ) {
return "type:\tControlGroup\n" + super.getInfo( );
}
public T addListener( final ControlListener theListener ) {
_myControlListener.add( theListener );
return me;
}
public T removeListener( final ControlListener theListener ) {
_myControlListener.remove( theListener );
return me;
}
public int listenerSize( ) {
return _myControlListener.size( );
}
}

31
controlP5/ControlKey.java Executable file
View File

@ -0,0 +1,31 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
public interface ControlKey {
void keyEvent();
}

52
controlP5/ControlListener.java Executable file
View File

@ -0,0 +1,52 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* ControlListener is an interface that can be implemented by a custom class to be notified when
* controller values change. To add a ControlListener to a controller use Controller.addListner()
*
* @see Controller#addListener(ControlListener)
* @see CallbackListener
*
* @example use/ControlP5listenerForSingleController
*/
public interface ControlListener {
/**
* controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about
* value changes. Use the CallbackListener to get informed when actions such as pressed,
* release, drag, etc are performed.
*
* @see CallbackListener
* @see CallbackEvent
* @param theEvent
* ControlEvent
* @example ControlP5listener
*/
void controlEvent( ControlEvent theEvent );
}

1455
controlP5/ControlP5.java Executable file

File diff suppressed because it is too large Load Diff

794
controlP5/ControlP5Base.java Executable file
View File

@ -0,0 +1,794 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import processing.core.PApplet;
import processing.event.Event;
import static main.java.src2.main.java.controlP5.controlP5.Controller.*;
/**
* The ControlP5Base supports the ControlP5 class and
* implements all adder methods to add controllers to
* controlP5.
*/
@SuppressWarnings( { "unchecked" , "rawtypes" } ) public class ControlP5Base extends ControlP5Legacy implements ControlP5Constants {
protected ControlP5 cp5;
protected ControllerProperties _myProperties;
private ControllerAutomator _myAutomator;
protected Map< Object , ArrayList< ControllerInterface< ? >>> _myObjectToControllerMap = new HashMap< Object , ArrayList< ControllerInterface< ? >>>( );
protected Map< String , FieldChangedListener > _myFieldChangedListenerMap = new HashMap< String , FieldChangedListener >( );
protected Map< KeyCode , List< ControlKey >> keymap = new HashMap< KeyCode , List< ControlKey >>( );
protected ControllerGroup< ? > currentGroupPointer;
protected boolean isCurrentGroupPointerClosed = true;
protected int autoDirection = ControlP5Constants.HORIZONTAL;
public Tab getDefaultTab( ) {
return ( Tab ) cp5.controlWindow.getTabs( ).get( 1 );
}
protected void init( ControlP5 theControlP5 ) {
super.init( theControlP5 );
cp5 = theControlP5;
_myProperties = new ControllerProperties( cp5 );
_myAutomator = new ControllerAutomator( cp5 );
currentGroupPointer = cp5.controlWindow.getTab( "default" );
}
public ControllerLayout getLayout( ) {
return new ControllerLayout( cp5 );
}
public Tab addTab( String theName ) {
for ( int i = 0 ; i < cp5.getWindow( ).getTabs( ).size( ) ; i++ ) {
if ( cp5.getWindow( ).getTabs( ).get( i ).getName( ).equals( theName ) ) {
return ( Tab ) cp5.getWindow( ).getTabs( ).get( i );
}
}
Tab myTab = new Tab( cp5 , cp5.getWindow( ) , theName );
cp5.getWindow( ).getTabs( ).add( myTab );
return myTab;
}
/**
* A Bang triggers an event without passing a value.
*/
public Bang addBang( final String theName ) {
return addBang( null , theName );
}
public Bang addBang( final Object theObject , final String theName ) {
return addBang( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
/**
* Triggers an event and passing a value.
*/
public Button addButton( String theName ) {
return addButton( null , theName );
}
public Button addButton( final Object theObject , final String theName ) {
return addButton( theObject , theObject != null ? theObject.toString( ) : "" , theName , 1 );
}
public ButtonBar addButtonBar( String theName ) {
return addButtonBar( null , theName );
}
public ButtonBar addButtonBar( final Object theObject , final String theName ) {
return addButtonBar( theObject , theObject != null ? theObject.toString( ) : "" , theName , 1 );
}
/**
* Toggles a boolean field or passes a value when
* triggered.
*/
public Toggle addToggle( final Object theObject , final String theName ) {
return addToggle( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
public Toggle addToggle( final String theName ) {
return addToggle( null , theName );
}
/**
* Adds a default slider with a default width of 100 and
* height of 10. the default value range is from 0-100.
*
* By default it will be added to the default tab of the
* main window. Sliders can be arranged vertically and
* horizontally depending on their width and height. The
* look of a sliders control can either be a bar or a
* handle. you can add tickmarks to a slider or use the
* default free-control setting. A slider can be
* controller by mouse click, drag or mouse-wheel.
*/
public Slider addSlider( String theName ) {
return addSlider( null , theName );
}
public Slider addSlider( Object theObject , String theName ) {
return addSlider( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
/**
* A range controller, a slider that allows control on
* both ends of the slider.
*/
public Range addRange( final String theName ) {
return addRange( theName , 0 , 100 , 0 , 100 , 0 , 0 , 100 , 10 );
}
public Range addRange( final Object theObject , final String theName ) {
return addRange( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 100 , 0 , 100 , 0 , 0 , 100 , 10 );
}
public Numberbox addNumberbox( String theName ) {
return addNumberbox( null , theName );
}
public Numberbox addNumberbox( Object theObject , String theName ) {
return addNumberbox( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
/**
* Knobs can use limited and endless revolutions, custom
* angles and starting points. There are 2 control areas
* for a knob, an area closer to the edge allows
* 'click-and-adjust' control, a click and drag action
* at the inside allows to gradually change the value of
* a know when dragged. A knob can be controller by
* mouse click, drag or mouse-wheel.
*/
public Knob addKnob( String theName ) {
return addKnob( theName , 0 , 100 );
}
public Knob addKnob( Object theObject , String theName ) {
return addKnob( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
/**
* Matrix is a 2-D matrix controller using toggle
* controllers in a rows and a columns setup. useful for
* software drum machines.
*/
public Matrix addMatrix( final String theName ) {
return addMatrix( theName , 10 , 10 , 0 , 0 , 100 , 100 );
}
public Matrix addMatrix( final Object theObject , final String theName ) {
return addMatrix( theObject , theObject != null ? theObject.toString( ) : "" , theName , 10 , 10 , 0 , 0 , 100 , 100 );
}
/**
* Adds a 2D slider to controlP5. A 2D slider is a 2D
* area with 1 cursor returning its xy coordinates.
*/
public Slider2D addSlider2D( final String theName ) {
return addSlider2D( null , theName );
}
public Slider2D addSlider2D( final Object theObject , final String theName ) {
return addSlider2D( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 100 , 0 , 100 , 0 , 0 , 0 , 0 , 100 , 100 );
}
public Textlabel addTextlabel( final String theName ) {
return addTextlabel( theName , "" , 0 , 0 );
}
/**
* A Textarea is a label without any controller
* functionality and can be used to leave notes,
* headlines, etc when extending the dedicated area of
* the Textrea, a scrollbar is added on the right.
*/
public Textarea addTextarea( final String theName ) {
return addTextarea( theName , "" , 0 , 0 , 200 , 100 );
}
// TODO
// addTextarea theObject
/**
* A Textfield allows single line text input. If text
* goes beyond the edges of a Textfield box, the text
* will automatically scroll. Use Arrow keys to navigate
* back and forth.
*/
public Textfield addTextfield( final String theIndex ) {
return addTextfield( theIndex , 0 , 0 , 200 , 20 );
}
public Textfield addTextfield( final Object theObject , final String theIndex ) {
return addTextfield( theObject , theObject != null ? theObject.toString( ) : "" , theIndex , 0 , 0 , 200 , 20 );
}
/**
* Use radio buttons for multiple choice options.
*/
public RadioButton addRadioButton( final String theName ) {
return addRadioButton( null , theName );
}
public RadioButton addRadioButton( final Object theObject , final String theName ) {
return addRadioButton( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 );
}
/**
* Use a checkbox for single choice options.
*/
public CheckBox addCheckBox( final String theName ) {
return addCheckBox( theName , 0 , 0 );
}
public CheckBox addCheckBox( final Object theObject , final String theName ) {
return addCheckBox( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 );
}
/**
* the ScrollableList replaces the DropwdownList and
* ListBox, the type for a ScrollableList can be set
* with setType(ControlP5.DROPDOWN | ControlP5.LIST).
*/
public ScrollableList addScrollableList( final String theName ) {
return addScrollableList( theName , 0 , 0 , 100 , 200 );
}
public ScrollableList addScrollableList( final Object theObject , String theName ) {
return addScrollableList( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 , 100 , 100 );
}
/**
* Multilist is a tree like menu.
*/
public MultiList addMultiList( final String theName ) {
return addMultiList( null , theName );
}
public MultiList addMultiList( final Object theObject , final String theName ) {
return addMultiList( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 , 100 , 100 );
}
public ColorWheel addColorWheel( final String theName ) {
return addColorWheel( null , theName );
}
public ColorWheel addColorWheel( final Object theObject , final String theName ) {
return addColorWheel( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 , 200 );
}
/**
* adds a simple RGBA colorpicker.
*/
public ColorPicker addColorPicker( final String theName ) {
return addColorPicker( null , theName );
}
public ColorPicker addColorPicker( final Object theObject , final String theName ) {
return addColorPicker( theObject , theObject != null ? theObject.toString( ) : "" , theName , 0 , 0 , 255 , 10 );
}
public Println addConsole( Textarea theTextarea ) {
return new Println( theTextarea );
}
/**
* returns the current framerate of the running sketch.
*/
public FrameRate addFrameRate( ) {
FrameRate myController = new FrameRate( cp5 , ( Tab ) cp5.controlWindow.getTabs( ).get( 1 ) , "-" , 0 , 4 );
cp5.register( null , "" , myController );
return myController;
}
/**
* adds chart support to display float array based data.
*/
public Chart addChart( String theName ) {
return addChart( theName , 0 , 0 , 200 , 100 );
}
/**
* A controller group can be used to group controllers
* for a better organization of single controllers.
*/
public Group addGroup( String theName ) {
return addGroup( theName , 0 , 0 );
}
public Group addGroup( final Object theObject , final String theName ) {
return addGroup( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
public Accordion addAccordion( final String theName ) {
return addAccordion( null , "" , theName );
}
public Accordion addAccordion( final Object theObject , final String theName ) {
return addAccordion( theObject , theObject != null ? theObject.toString( ) : "" , theName );
}
protected void setCurrentPointer( ControllerGroup< ? > theGroup ) {
currentGroupPointer = theGroup;
isCurrentGroupPointerClosed = false;
}
protected void releaseCurrentPointer( ControllerGroup< ? > theGroup ) {
if (!isCurrentGroupPointerClosed) {
currentGroupPointer = theGroup;
isCurrentGroupPointerClosed = true;
} else {
ControlP5.logger( ).warning( "use .end() first before using .begin() again." );
}
}
public void setAutoAddDirection( int theDirection ) {
if ( theDirection == ControlP5Constants.HORIZONTAL ) {
autoDirection = ControlP5Constants.HORIZONTAL;
return;
}
autoDirection = ControlP5Constants.VERTICAL;
}
public void setAutoSpacing( ) {
set( Controller.autoSpacing , 10 , 10 );
}
public void setAutoSpacing( float theX , float theY ) {
set( Controller.autoSpacing , theX , theY );
}
public void setAutoSpacing( float theX , float theY , float theZ ) {
setAutoSpacing( theX , theY );
}
@SuppressWarnings( "static-access" ) protected void linebreak( Controller< ? > theController , boolean theFlag , int theW , int theH , float[] theSpacing ) {
if ( x( currentGroupPointer.autoPosition ) + x( theController.autoSpacing ) + theW > cp5.papplet.width ) {
float x = x( currentGroupPointer.autoPosition ) + currentGroupPointer.autoPositionOffsetX;
float y = y( currentGroupPointer.autoPosition ) + currentGroupPointer.tempAutoPositionHeight;
set( currentGroupPointer.autoPosition , x , y );
currentGroupPointer.tempAutoPositionHeight = 0;
Controller.set( theController.position , Controller.x( currentGroupPointer.autoPosition ) , Controller.y( currentGroupPointer.autoPosition ) );
theFlag = false;
}
if (theFlag) {
float y = y( currentGroupPointer.autoPosition ) + currentGroupPointer.tempAutoPositionHeight;
set( currentGroupPointer.autoPosition , currentGroupPointer.autoPositionOffsetX , y );
currentGroupPointer.tempAutoPositionHeight = 0;
} else {
if ( theController instanceof Slider ) {
float x = x( currentGroupPointer.autoPosition ) + theController.getCaptionLabel( ).getWidth( );
float y = y( currentGroupPointer.autoPosition );
set( currentGroupPointer.autoPosition , x , y );
}
float x = x( currentGroupPointer.autoPosition ) + x( theController.autoSpacing ) + theW;
float y = y( currentGroupPointer.autoPosition );
set( currentGroupPointer.autoPosition , x , y );
if ( ( theH + y( theSpacing ) ) > currentGroupPointer.tempAutoPositionHeight ) {
currentGroupPointer.tempAutoPositionHeight = theH + y( theSpacing );
}
}
}
public ControlP5Base addControllersFor( PApplet theApplet ) {
addControllersFor( "" , theApplet );
return cp5;
}
/**
* Adds controllers for a specific object using
* annotations.
* <p>
* Uses a forward slash delimited address, for example:
* </p>
* <p>
* lets say the theAddressSpace parameter is set to
* "hello", and the Object (second parameter) contains
* an annotated field "x", addControllersFor("hello",
* o); will add a controller for field x with address
* /hello/x This address can be used with
* getController("/hello/x") to access the controller of
* that particular Object and field.
* </p>
*/
public ControlP5Base addControllersFor( final String theAddressSpace , Object t ) {
_myAutomator.addControllersFor( theAddressSpace , t );
return cp5;
}
public Object getObjectForController( ControllerInterface theController ) {
for ( Iterator it = _myObjectToControllerMap.entrySet( ).iterator( ) ; it.hasNext( ) ; ) {
Map.Entry entry = ( Map.Entry ) it.next( );
Object key = entry.getKey( );
ArrayList< ControllerInterface > value = ( ArrayList< ControllerInterface > ) entry.getValue( );
for ( ControllerInterface c : value ) {
if ( c.equals( theController ) ) {
return key;
}
}
}
return null;
}
public ControlP5Base setPosition( int theX , int theY , Object o ) {
if ( o != null && _myObjectToControllerMap.containsKey( o ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( o );
for ( ControllerInterface< ? > c : cs ) {
int x = ( int ) x( c.getPosition( ) ) + theX;
int y = ( int ) y( c.getPosition( ) ) + theY;
c.setPosition( x , y );
}
}
return cp5;
}
public ControlP5Base hide( Object theObject ) {
if ( theObject != null && _myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
c.hide( );
}
}
return cp5;
}
public ControlP5Base show( Object theObject ) {
if ( theObject != null && _myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
c.show( );
}
}
return cp5;
}
/**
* for internal use only. use Controller.remove()
* instead.
*
* @param theObject
* @return
*/
public ControlP5Base remove( Object theObject ) {
if ( theObject != null && _myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
c.remove( );
}
}
return cp5;
}
public ControlP5Base setColor( CColor theColor , Object theObject ) {
if ( _myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
c.setColor( theColor );
}
}
return cp5;
}
public ControlP5Base listenTo( String theFieldName , Object theObject ) {
String key = theObject.hashCode( ) + String.valueOf(theFieldName.hashCode( ));
FieldChangedListener value = new FieldChangedListener( cp5 );
value.listenTo( theObject , theFieldName );
_myFieldChangedListenerMap.put( key , value );
return cp5;
}
public ControlP5Base stopListeningTo( String theFieldName , Object theObject ) {
String key = theObject.hashCode( ) + String.valueOf(theFieldName.hashCode( ));
_myFieldChangedListenerMap.remove( key );
return cp5;
}
public ControlP5Base moveTo( ControllerGroup< ? > theController , Object theObject ) {
if ( _myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = _myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
c.moveTo( theController );
}
}
return cp5;
}
/* Properties */
public ControllerProperties getProperties( ) {
return _myProperties;
}
public void removeProperty( ControllerInterface< ? > theController ) {
_myProperties.remove( theController );
}
/**
* prints a list of public methods of requested class
* into the console. You can specify patterns that will
* print methods found with only these particular
* patterns in their name.
* <p>
* printed Format: returnType methodName(parameter type)
*/
public static void printPublicMethodsFor( Class< ? > theClass , String ... thePattern ) {
Set< String > set = getPublicMethodsFor( theClass , true , thePattern );
String str = "";
str += "/**\n";
str += "* ControlP5 " + theClass.getSimpleName( ) + "\n";
str += "*\n";
str += "*\n";
str += "* find a list of public methods available for the " + theClass.getSimpleName( ) + " Controller\n";
str += "* at the bottom of this sketch.\n";
str += "*\n";
str += "* by Andreas Schlegel, 2012\n";
str += "* www.sojamo.de/libraries/controlp5\n";
str += "*\n";
str += "*/\n\n";
str += "/*\n";
str += "a list of all methods available for the " + theClass.getSimpleName( ) + " Controller\n";
str += "use ControlP5.printPublicMethodsFor(" + theClass.getSimpleName( ) + ".class);\n";
str += "to print the following list into the console.\n\n";
str += "You can find further details about class " + theClass.getSimpleName( ) + " in the javadoc.\n\n";
str += "Format:\n";
str += "ClassName : returnType methodName(parameter type)\n\n\n";
for ( String s : set ) {
str += s + "\n";
}
str += "\n\n*/\n\n";
ControlP5Legacy.println( str );
}
public static void printPublicMethodsFor( Class< ? > theClass ) {
printPublicMethodsFor( theClass , "" );
}
public static Set< String > getPublicMethodsFor( Class< ? > theClass ) {
return getPublicMethodsFor( theClass , true , "" );
}
public static Set< String > getPublicMethodsFor( Class< ? > theClass , String ... thePattern ) {
return getPublicMethodsFor( theClass , true , thePattern );
}
public static Set< String > getPublicMethodsFor( Class< ? > theClass , boolean theFlag ) {
return getPublicMethodsFor( theClass , true , "" );
}
public static Set< String > getPublicMethodsFor( Class< ? > theClass , boolean isSuperclass , String ... thePattern ) {
Set< String > s = new TreeSet< String >( );
Class< ? > c = theClass;
while ( c != null ) {
for ( Method method : c.getDeclaredMethods( ) ) {
if ( !method.isAnnotationPresent( Deprecated.class ) && !method.isAnnotationPresent( ControlP5.Invisible.class ) && method.getModifiers( ) == Modifier.PUBLIC ) {
for ( String p : thePattern ) {
if ( p.length( ) > 0 ) {
if ( !method.getName( ).toLowerCase( ).contains( p.toLowerCase( ) ) ) {
continue;
}
}
String params = "";
for ( Class< ? > t : method.getParameterTypes( ) ) {
params += t.getSimpleName( ) + ", ";
}
if ( params.length( ) > 0 ) {
params = params.substring( 0 , params.length( ) - 2 );
}
s.add( c.getCanonicalName( ) + " : " + method.getReturnType( ).getSimpleName( ).replace( "Object" , theClass.getSimpleName( ) ) + " " + method.getName( ) + "(" + params + ") " );
}
}
}
if ( isSuperclass ) {
c = c.getSuperclass( );
} else {
c = null;
}
}
return s;
}
public int getKeyCode( ) {
return cp5.getWindow( ).keyCode;
}
public char getKey( ) {
return cp5.getWindow( ).key;
}
private char[] fromIntToChar( int ... theChar ) {
char[] n = new char[ theChar.length ];
for ( int i = 0 ; i < n.length ; i++ ) {
if ( theChar[ i ] >= 'a' && theChar[ i ] <= 'z' ) {
theChar[ i ] -= 32;
}
n[ i ] = ( char ) theChar[ i ];
}
return n;
}
public ControlP5 removeKeyFor( ControlKey theKey , int ... theChar ) {
removeKeyFor( theKey , fromIntToChar( theChar ) );
return cp5;
}
public ControlP5 mapKeyFor( ControlKey theKey , Object ... os ) {
List< Integer > l = new ArrayList< Integer >( );
for ( Object o : os ) {
if ( o instanceof Integer ) {
l.add(( Integer ) o);
} else if ( o instanceof Character ) {
char c = ( ( Character ) o );
if ( c >= 'a' && c <= 'z' ) {
c -= 32;
}
l.add( ( int ) c );
}
}
char[] n = new char[ l.size( ) ];
for ( int i = 0 ; i < l.size( ) ; i++ ) {
n[ i ] = ( char ) ( ( int ) l.get( i ) );
}
KeyCode kc = new KeyCode( n );
if ( !keymap.containsKey( kc ) ) {
keymap.put( kc , new ArrayList< ControlKey >( ) );
}
keymap.get( kc ).add( theKey );
cp5.enableShortcuts( );
return cp5;
}
public ControlP5 removeKeyFor( ControlKey theKey , char ... theChar ) {
List< ControlKey > l = keymap.get( new KeyCode( theChar ) );
if ( l != null ) {
l.remove( theKey );
}
return cp5;
}
public ControlP5 removeKeysFor( char ... theChar ) {
keymap.remove( new KeyCode( theChar ) );
return cp5;
}
public ControlP5 removeKeysFor( int ... theChar ) {
removeKeysFor( fromIntToChar( theChar ) );
return cp5;
}
protected int modifiers;
public boolean isShiftDown( ) {
return ( modifiers & Event.SHIFT & ( cp5.isShortcuts( ) ? -1 : 1 ) ) != 0;
}
public boolean isControlDown( ) {
return ( modifiers & Event.CTRL & ( cp5.isShortcuts( ) ? -1 : 1 ) ) != 0;
}
public boolean isMetaDown( ) {
return ( modifiers & Event.META & ( cp5.isShortcuts( ) ? -1 : 1 ) ) != 0;
}
public boolean isAltDown( ) {
return ( modifiers & Event.ALT & ( cp5.isShortcuts( ) ? -1 : 1 ) ) != 0;
}
static class KeyCode {
final char[] chars;
KeyCode( char ... theChars ) {
chars = theChars;
Arrays.sort( chars );
}
public String toString( ) {
String s = "";
for ( char c : chars ) {
s += c + "(" + ( ( int ) c ) + ") ";
}
return s;
}
public int size( ) {
return chars.length;
}
public char[] getChars( ) {
return chars;
}
public char get( int theIndex ) {
if ( theIndex >= 0 && theIndex < size( ) ) {
return chars[ theIndex ];
}
return 0;
}
public boolean equals( Object obj ) {
if ( ! ( obj instanceof KeyCode ) ) {
return false;
}
KeyCode k = ( KeyCode ) obj;
if ( k.size( ) != size( ) ) {
return false;
}
for ( int i = 0 ; i < size( ) ; i++ ) {
if ( get( i ) != k.get( i ) ) {
return false;
}
}
return true;
}
boolean contains( char n ) {
for ( char c : chars ) {
if ( n == c ) {
return true;
}
}
return false;
}
public int hashCode( ) {
int hashCode = 0;
int n = 1;
for ( char c : chars ) {
hashCode += c + Math.pow( c , n++ );
}
return hashCode;
}
}
}

191
controlP5/ControlP5Constants.java Executable file
View File

@ -0,0 +1,191 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
/**
* Constant variables used with ControlP5 are stored here.
*/
public interface ControlP5Constants {
String eventMethod = "controlEvent";
boolean VERBOSE = false;
float PI = ( float ) Math.PI;
float TWO_PI = PI * 2;
float HALF_PI = PI / 2;
int INVALID = -1;
int METHOD = 0;
int FIELD = 1;
int EVENT = 2;
int INTEGER = 1;
int FLOAT = 2;
int BOOLEAN = 3;
int STRING = 4;
int ARRAY = 5;
int BITFONT = 100;
Class< ? >[] acceptClassList = { int.class , float.class , boolean.class , String.class };
Class< ? > controlEventClass = ControlEvent.class;
int UP = PApplet.UP; // KeyEvent.VK_UP;
int DOWN = PApplet.DOWN; // KeyEvent.VK_DOWN;
int LEFT = PApplet.LEFT; // KeyEvent.VK_LEFT;
int RIGHT = PApplet.RIGHT; // KeyEvent.VK_RIGHT;
int SHIFT = PApplet.SHIFT; // KeyEvent.VK_SHIFT;
int DELETE = PApplet.DELETE; // KeyEvent.VK_DELETE;
int BACKSPACE = PApplet.BACKSPACE; // KeyEvent.VK_BACK_SPACE;
int ENTER = PApplet.ENTER; // KeyEvent.VK_ENTER;
int ESCAPE = PApplet.ESC; // KeyEvent.VK_ESCAPE;
int ALT = PApplet.ALT; // KeyEvent.VK_ALT;
int CONTROL = PApplet.CONTROL;// KeyEvent.VK_CONTROL;
int COMMANDKEY = 157; // Event.VK_META;
int TAB = PApplet.TAB; // KeyEvent.VK_TAB;
char INCREASE = PApplet.UP;
char DECREASE = PApplet.DOWN;
char SWITCH_FORE = PApplet.LEFT;
char SWITCH_BACK = PApplet.RIGHT;
char SAVE = 'S';
char RESET = 'R';
char PRINT = ' ';
char HIDE = 'H';
char LOAD = 'L';
char MENU = 'M';
char KEYCONTROL = 'K';
int TOP = 101; // PApplet.TOP
int BOTTOM = 102; // PApplet.BOTTOM
int CENTER = 3; // PApplet.CENTER
int BASELINE = 0; // PApplet.BASELINE
int HORIZONTAL = 0;
int VERTICAL = 1;
int DEFAULT = 0;
int OVER = 1;
int ACTIVE = 2;
int HIGHLIGHT = 3;
int IMAGE = 1;
int SPRITE = 2;
int CUSTOM = 3;
int SWITCH = 100;
int MOVE = 0;
int RELEASE = 2;
int RELEASED = 2;
int PRESSED = 1;
int PRESS = 1;
int LINE = 1;
int ELLIPSE = 2;
int ARC = 3;
int INACTIVE = 0;
int WAIT = 1;
int TRANSITION_WAIT_FADEIN = 2;
int FADEIN = 3;
int IDLE = 4;
int FADEOUT = 5;
int DONE = 6;
int SINGLE_COLUMN = 0;
int SINGLE_ROW = 1;
int MULTIPLES = 2;
int LIST = 0;
int DROPDOWN = 1;
int CHECKBOX = 2; /* TODO */
int TREE = 3; /* TODO */
@Deprecated
int ACTION_PRESSED = 1; // MouseEvent.PRESS
int ACTION_PRESS = 1; // MouseEvent.PRESS
@Deprecated
int ACTION_RELEASED = 2; // MouseEvent.RELEASE
int ACTION_RELEASE = 2; // MouseEvent.RELEASE
int ACTION_CLICK = 3; // MouseEvent.CLICK
int ACTION_DRAG = 4; // MouseEvent.DRAG
int ACTION_MOVE = 5; // MouseEvent.MOVE
int ACTION_ENTER = 6; // MouseEvent.ENTER
int ACTION_LEAVE = 7; // MouseEvent.EXIT
int ACTION_EXIT = 7; // MouseEvent.EXIT
int ACTION_WHEEL = 8; // MouseEvent.WHEEL
@Deprecated
int ACTION_RELEASEDOUTSIDE = 9;
int ACTION_RELEASE_OUTSIDE = 9;
int ACTION_START_DRAG = 10;
int ACTION_END_DRAG = 11;
int ACTION_DOUBLE_PRESS = 12;
int ACTION_BROADCAST = 100;
int LEFT_OUTSIDE = 10;
int RIGHT_OUTSIDE = 11;
int TOP_OUTSIDE = 12;
int BOTTOM_OUTSIDE = 13;
int CAPTIONLABEL = 0;
int VALUELABEL = 1;
int SINGLE = 0;
@Deprecated
int ALL = 1;
int MULTI = 1;
/* http://clrs.cc/ */
int NAVY = 0xFF001F3F;
int BLUE = 0xFF0074D9;
int AQUA = 0xFF7FDBFF;
int TEAL = 0xFF39CCCC;
int OLIVE = 0xFF3D9970;
int GREEN = 0xFF2ECC40;
int LIME = 0xFF01FF70;
int YELLOW = 0xFFFFDC00;
int ORANGE = 0xFFFF851B;
int RED = 0xFFFF4136;
int MAROON = 0xFF85144B;
int FUCHSIA = 0xFFF012BE;
int PURPLE = 0xFFB10DC9;
int WHITE = 0xFFFFFFFF;
int SILVER = 0xFFDDDDDD;
int GRAY = 0xFFAAAAAA;
int BLACK = 0xFF111111;
/*fg, bg, active, caption, value ) */
CColor THEME_RETRO = new CColor( 0xff00698c , 0xff003652 , 0xff08a2cf , 0xffffffff , 0xffffffff );
CColor THEME_CP52014 = new CColor( 0xff0074D9 , 0xff002D5A, 0xff00aaff , 0xffffffff , 0xffffffff );
CColor THEME_CP5BLUE = new CColor( 0xff016c9e , 0xff02344d , 0xff00b4ea , 0xffffffff , 0xffffffff );
CColor THEME_RED = new CColor( 0xffaa0000 , 0xff660000 , 0xffff0000 , 0xffffffff , 0xffffffff );
CColor THEME_GREY = new CColor( 0xffeeeeee, 0xffbbbbbb , 0xffffffff , 0xff555555 , 0xff555555 );
CColor THEME_A = new CColor( 0xff00FFC8 , 0xff00D7FF , 0xffffff00 , 0xff00B0FF , 0xff00B0FF );
// other colors: #ff3838 red-salmon; #08ffb4 turquoise; #40afff light-blue; #f3eddb beige;
int standard58 = 0;
int standard56 = 1;
int synt24 = 2;
int grixel = 3;
int J2D = 1;
int P2D = 2;
int P3D = 3;
String JSON = "JSON";
String SERIALIZED = "SERIALIZED";
String delimiter = " ";
String pathdelimiter = "/";
}

View File

@ -0,0 +1,705 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import processing.core.PApplet;
import static main.java.src2.main.java.controlP5.controlP5.Controller.*;
public class ControlP5Legacy {
private ControlP5Base base;
public static boolean DEBUG = false;
void init( ControlP5Base theControlP5 ) {
base = theControlP5;
}
public Spacer addSpacer( final String theName ) {
return addSpacer( theName , 0 , 0 , 100 , 20 );
}
public Spacer addSpacer( final String theName , final int theX , final int theY , final int theW , final int theH ) {
ControllerGroup tab = ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 );
Spacer myController = new Spacer( base.cp5 , tab , theName , theX , theY , theW , theH );
base.cp5.register( null , "" , myController );
return myController;
}
public Background addBackground( final String theName ) {
return addBackground( null , "" , theName , 0 , 0 , 300 , base.cp5.papplet.height );
}
public Background addBackground( Object theObject , final String theIndex , String theName , int theX , int theY , int theW , int theHeight ) {
Background myController = new Background( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theHeight );
base.cp5.register( theObject , theIndex , myController );
return myController;
}
public Button addButton( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
Button myController = new Button( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
myController.getProperty( "value" ).disable( );
return myController;
}
public Icon addIcon( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
Icon myController = new Icon( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
myController.getProperty( "value" ).disable( );
return myController;
}
public ButtonBar addButtonBar( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
ButtonBar myController = new ButtonBar( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
myController.getProperty( "value" ).disable( );
return myController;
}
public Bang addBang( final Object theObject , String theIndex , final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
Bang myController = new Bang( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theWidth , theHeight );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
myController.getProperty( "value" ).disable( );
return myController;
}
public Toggle addToggle( final Object theObject , String theIndex , final String theName , final boolean theDefaultValue , final float theX , final float theY , final int theWidth , final int theHeight ) {
Toggle myController = new Toggle( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , (theDefaultValue) ? 1f : 0f , theX , theY , theWidth , theHeight );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
return myController;
}
public Tooltip addTooltip( ) {
println( "Tooltip is not available with this Version (" , ControlP5.VERSION , ") of ControlP5" );
return null;
}
public Matrix addMatrix( final Object theObject , final String theIndex , final String theName , final int theCellX , final int theCellY , final int theX , final int theY , final int theWidth , final int theHeight ) {
Matrix myController = new Matrix( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theCellX , theCellY , theX , theY , theWidth , theHeight );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "cells" ).registerProperty( "interval" );
return myController;
}
public Matrix addMatrix( final String theName , final int theCellX , final int theCellY , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addMatrix( null , "" , theName , theCellX , theCellY , theX , theY , theWidth , theHeight );
}
public Slider2D addSlider2D( Object theObject , final String theIndex , final String theName , float theMinX , float theMaxX , float theMinY , float theMaxY , float theDefaultValueX , float theDefaultValueY , int theX , int theY , int theW , int theH ) {
Slider2D myController = new Slider2D( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.setMinX( theMinX );
myController.setMaxX( theMaxX );
myController.setMinY( theMinY );
myController.setMaxY( theMaxY );
myController.setArrayValue( new float[] { theDefaultValueX , theDefaultValueY } );
myController.updateValue( );
myController.registerProperty( "arrayValue" ).registerProperty( "minX" ).registerProperty( "maxX" ).registerProperty( "minY" ).registerProperty( "maxY" );
return myController;
}
public Slider addSlider( Object theObject , final String theIndex , final String theName , float theMin , float theMax , float theDefaultValue , int theX , int theY , int theW , int theH ) {
Slider myController = new Slider( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theMin , theMax , theDefaultValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" ).registerProperty( "min" ).registerProperty( "max" );
return myController;
}
public Slider addSlider( String theName , float theMin , float theMax , float theDefaultValue , int theX , int theY , int theW , int theH ) {
return addSlider( null , "" , theName , theMin , theMax , theDefaultValue , theX , theY , theW , theH );
}
public Slider addSlider( final String theName , final float theMin , final float theMax , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addSlider( null , "" , theName , theMin , theMax , theMin , theX , theY , theWidth , theHeight );
}
public Slider addSlider( Object theObject , final String theIndex , final String theName , float theMin , float theMax , int theX , int theY , int theW , int theH ) {
return addSlider( theObject , theIndex , theName , theMin , theMax , theMin , theX , theY , theW , theH );
}
public Range addRange( Object theObject , final String theIndex , String theName , float theMin , float theMax , float theDefaultMinValue , float theDefaultMaxValue , int theX , int theY , int theW , int theH ) {
Range myController = new Range( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theMin , theMax , theDefaultMinValue , theDefaultMaxValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "lowValue" ).registerProperty( "highValue" );
return myController;
}
public Range addRange( String theName , float theMin , float theMax , float theDefaultMinValue , float theDefaultMaxValue , int theX , int theY , int theW , int theH ) {
return addRange( null , "" , theName , theMin , theMax , theDefaultMinValue , theDefaultMaxValue , theX , theY , theW , theH );
}
public Range addRange( final String theName , final float theMin , final float theMax , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addRange( null , "" , theName , theMin , theMax , theMin , theMax , theX , theY , theWidth , theHeight );
}
public Range addRange( final Object theObject , final String theIndex , final String theName , final float theMin , final float theMax , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addRange( theObject , theIndex , theName , theMin , theMax , theMin , theMax , theX , theY , theWidth , theHeight );
}
public Numberbox addNumberbox( final Object theObject , final String theIndex , final String theName , final float theDefaultValue , final int theX , final int theY , final int theWidth , final int theHeight ) {
Numberbox myController = new Numberbox( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theDefaultValue , theX , theY , theWidth , theHeight );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
return myController;
}
public Numberbox addNumberbox( final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addNumberbox( null , "" , theName , Float.NaN , theX , theY , theWidth , theHeight );
}
public Numberbox addNumberbox( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addNumberbox( theObject , theIndex , theName , Float.NaN , theX , theY , theWidth , theHeight );
}
public Numberbox addNumberbox( final String theName , final float theDefaultValue , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addNumberbox( null , "" , theName , theDefaultValue , theX , theY , theWidth , theHeight );
}
public Knob addKnob( final Object theObject , final String theIndex , final String theName , final float theMin , final float theMax , final float theDefaultValue , final int theX , final int theY , final int theDiameter ) {
Knob myController = new Knob( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theMin , theMax , theDefaultValue , theX , theY , theDiameter );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
return myController;
}
public Knob addKnob( final String theName , final float theMin , final float theMax , final int theX , final int theY , final int theDiameter ) {
return addKnob( null , "" , theName , theMin , theMax , theMin , theX , theY , theDiameter );
}
public Knob addKnob( final Object theObject , final String theIndex , final String theName , final float theMin , final float theMax , final int theX , final int theY , final int theDiameter ) {
return addKnob( theObject , theIndex , theName , theMin , theMax , theX , theY , theDiameter );
}
public Knob addKnob( final String theName , final float theMin , final float theMax , final float theDefaultValue , final int theX , final int theY , final int theDiameter ) {
return addKnob( null , "" , theName , theMin , theMax , theDefaultValue , theX , theY , theDiameter );
}
public MultiList addMultiList( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
MultiList myController = new MultiList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theWidth , theHeight );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
return myController;
}
public MultiList addMultiList( final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addMultiList( null , "" , theName , theX , theY , theWidth , theHeight );
}
public Textlabel addLabel( String theIndex ) {
return addTextlabel( theIndex , theIndex , 0 , 0 );
}
public Textlabel addLabel( String theIndex , int theX , int theY ) {
return addTextlabel( theIndex , theIndex , theX , theY );
}
public Textlabel addTextlabel( final Object theObject , final String theIndex , final String theName , final String theText , final int theX , final int theY ) {
Textlabel myController = new Textlabel( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theText , theX , theY );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" ).registerProperty( "stringValue" );
return myController;
}
public Textlabel addTextlabel( final String theName , final String theText , final int theX , final int theY ) {
return addTextlabel( null , "" , theName , theText , theX , theY );
}
public Textlabel addTextlabel( final Object theObject , final String theIndex , final String theName , final String theText ) {
return addTextlabel( theObject , theIndex , theName , theText , 0 , 0 );
}
public Textlabel addTextlabel( final String theName , final String theText ) {
return addTextlabel( null , "" , theName , theText , 0 , 0 );
}
public Textarea addTextarea( final String theName , final String theText , final int theX , final int theY , final int theW , final int theH ) {
Textarea myController = new Textarea( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theText , theX , theY , theW , theH );
base.cp5.register( null , "" , myController );
myController.registerProperty( "text" );
return myController;
}
public Textfield addTextfield( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
Textfield myController = new Textfield( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , "" , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "text" );
return myController;
}
public Textfield addTextfield( final String theName , final int theX , final int theY , final int theW , final int theH ) {
return addTextfield( null , "" , theName , theX , theY , theW , theH );
}
public Textfield addTextfield( final Object theObject , final String theIndex , final String theName ) {
return addTextfield( theObject , theIndex , theName , 0 , 0 , 99 , 19 );
}
public Accordion addAccordion( String theName , int theX , int theY , int theWidth ) {
Accordion myController = new Accordion( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theWidth );
base.cp5.register( null , "" , myController );
return myController;
}
public Accordion addAccordion( final Object theObject , final String theIndex , final String theName ) {
Accordion myController = new Accordion( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , 0 , 0 , 200 );
base.cp5.register( theObject , theIndex , myController );
return myController;
}
public RadioButton addRadioButton( final Object theObject , String theIndex , final String theName , final int theX , final int theY ) {
RadioButton myController = new RadioButton( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "arrayValue" );
return myController;
}
public RadioButton addRadioButton( final String theName , final int theX , final int theY ) {
return addRadioButton( null , "" , theName , theX , theY );
}
/**
* Use radio buttons for multiple choice options.
*/
public RadioButton addRadio( final String theName ) {
return addRadioButton( theName , 0 , 0 );
}
public RadioButton addRadio( final String theName , final int theX , final int theY ) {
RadioButton myController = new RadioButton( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY );
base.cp5.register( null , "" , myController );
myController.registerProperty( "arrayValue" );
return myController;
}
public CheckBox addCheckBox( final Object theObject , final String theIndex , final String theName , final int theX , final int theY ) {
CheckBox myController = new CheckBox( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "arrayValue" );
return myController;
}
public CheckBox addCheckBox( final String theName , final int theX , final int theY ) {
return addCheckBox( null , "" , theName , theX , theY );
}
public ScrollableList addScrollableList( final Object theObject , String theIndex , final String theName ) {
return addScrollableList( theObject , theIndex , theName , 0 , 0 , 100 , 100 );
}
public ScrollableList addScrollableList( final Object theObject , String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
ScrollableList myController = new ScrollableList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
return myController;
}
public ScrollableList addScrollableList( final String theName , final int theX , final int theY , final int theW , final int theH ) {
return addScrollableList( null , "" , theName , theX , theY , theW , theH );
}
/**
* A list box is a list of items a user can choose from.
* When items exceed the dedicated area of a list box, a
* scrollbar is added to the right of the box. the Box
* can be navigated using mouse click, drag and the
* mouse-wheel.
*/
public ListBox addListBox( final String theName ) {
return addListBox( theName , 0 , 0 , 99 , 199 );
}
public ListBox addListBox( final Object theObject , String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
ListBox myController = new ListBox( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "listBoxItems" ).registerProperty( "value" );
return myController;
}
public ListBox addListBox( final String theName , final int theX , final int theY , final int theW , final int theH ) {
return addListBox( null , "" , theName , theX , theY , theW , theH );
}
public DropdownList addDropdownList( final String theName ) {
return addDropdownList( theName , 0 , 0 , 99 , 99 );
}
public DropdownList addDropdownList( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
DropdownList myController = new DropdownList( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "listBoxItems" ).registerProperty( "value" );
return myController;
}
public DropdownList addDropdownList( final String theName , final int theX , final int theY , final int theW , final int theH ) {
return addDropdownList( null , "" , theName , theX , theY , theW , theH );
}
public ColorWheel addColorWheel( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theW ) {
ColorWheel myController = new ColorWheel( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theW );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "arrayValue" );
return myController;
}
public ColorWheel addColorWheel( final String theName , final int theX , final int theY , final int theW ) {
return addColorWheel( null , "" , theName , theX , theY , theW );
}
public ColorPicker addColorPicker( final String theName , final int theX , final int theY , final int theW , final int theH ) {
return addColorPicker( null , "" , theName , theX , theY , theW , theH );
}
public ColorPicker addColorPicker( final Object theObject , final String theIndex , final String theName , final int theX , final int theY , final int theW , final int theH ) {
ColorPicker myController = new ColorPicker( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "arrayValue" );
return myController;
}
public Chart addChart( String theName , int theX , int theY , int theW , int theH ) {
Chart myController = new Chart( base.cp5 , ( Tab ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( null , "" , myController );
return myController;
}
public Group addGroup( Object theObject , final String theIndex , String theName , int theX , int theY , int theW ) {
Group myController = new Group( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , 9 );
base.cp5.register( theObject , theIndex , myController );
return myController;
}
public Group addGroup( Object theObject , String theIndex , String theName , int theX , int theY ) {
return addGroup( theObject , theIndex , theName , theX , theY , 99 );
}
public Group addGroup( String theName , int theX , int theY , int theW ) {
return addGroup( null , "" , theName , theX , theY , theW );
}
public Group addGroup( Object theObject , String theIndex , String theName ) {
return addGroup( theObject , theIndex , theName , 0 , 0 );
}
public Group addGroup( String theName , int theX , int theY ) {
return addGroup( null , "" , theName , theX , theY , 99 );
}
public Textlabel getTextlabel( String theText , int theX , int theY ) {
return new Textlabel( base.cp5 , theText , theX , theY );
}
public Textlabel getTextlabel( ) {
return getTextlabel( "" , 0 , 0 );
}
public Slider addSlider( Object theObject , final String theIndex , String theName ) {
return addSlider( theObject , theIndex , theName , 0 , 100 );
}
public Slider addSlider( String theName , float theMin , float theMax ) {
return addSlider( null , "" , theName , theMin , theMax );
}
public Slider addSlider( Object theObject , final String theIndex , String theName , float theMin , float theMax ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Slider s = addSlider( theObject , theIndex , theName , theMin , theMax , theMin , x , y , Slider.autoWidth , Slider.autoHeight );
base.linebreak( s , false , Slider.autoWidth , Slider.autoHeight , Slider.autoSpacing );
s.moveTo( base.currentGroupPointer );
if ( base.autoDirection == ControlP5Constants.VERTICAL ) {
s.linebreak( );
}
return s;
}
public Button addButton( Object theObject , final String theIndex , String theName ) {
return addButton( theObject , theIndex , theName , 1 );
}
public Button addButton( String theName , float theValue ) {
return addButton( null , "" , theName , theValue );
}
public Button addButton( Object theObject , final String theIndex , String theName , float theValue ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Button b = addButton( theObject , theIndex , theName , theValue , x , y , Button.autoWidth , Button.autoHeight );
base.linebreak( b , false , Button.autoWidth , Button.autoHeight , Button.autoSpacing );
b.moveTo( base.currentGroupPointer );
return b;
}
public ButtonBar addButtonBar( Object theObject , final String theIndex , String theName , float theValue ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
ButtonBar b = addButtonBar( theObject , theIndex , theName , theValue , x , y , Button.autoWidth , Button.autoHeight );
base.linebreak( b , false , Button.autoWidth , Button.autoHeight , Button.autoSpacing );
b.moveTo( base.currentGroupPointer );
return b;
}
public Icon addIcon( Object theObject , final String theIndex , String theName ) {
return addIcon( theObject , theIndex , theName , 1 );
}
public Icon addIcon( String theName , float theValue ) {
return addIcon( null , "" , theName , theValue );
}
public Icon addIcon( Object theObject , final String theIndex , String theName , float theValue ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Icon icon = addIcon( theObject , theIndex , theName , theValue , x , y , Icon.autoWidth , Icon.autoHeight );
base.linebreak( icon , false , Icon.autoWidth , Icon.autoHeight , Icon.autoSpacing );
icon.moveTo( base.currentGroupPointer );
return icon;
}
public Bang addBang( Object theObject , final String theIndex , String theName ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Bang b = addBang( theObject , theIndex , theName , x , y , Bang.autoWidth , Bang.autoHeight );
base.linebreak( b , false , Bang.autoWidth , Bang.autoHeight , Bang.autoSpacing );
b.moveTo( base.currentGroupPointer );
return b;
}
public Toggle addToggle( Object theObject , final String theIndex , String theName ) {
return addToggle( theObject , theIndex , theName , false );
}
public Toggle addToggle( Object theObject , final String theIndex , String theName , boolean theValue ) {
Toggle t = addToggle( theObject , theIndex , theName , theValue , x( base.currentGroupPointer.autoPosition ) , y( base.currentGroupPointer.autoPosition ) , Toggle.autoWidth , Toggle.autoHeight );
base.linebreak( t , false , Toggle.autoWidth , Toggle.autoHeight , t.autoSpacing );
t.moveTo( base.currentGroupPointer );
return t;
}
public Numberbox addNumberbox( Object theObject , final String theIndex , String theName ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Numberbox n = addNumberbox( theObject , theIndex , theName , x , y , Numberbox.autoWidth , Numberbox.autoHeight );
base.linebreak( n , false , Numberbox.autoWidth , Numberbox.autoHeight , n.autoSpacing );
n.moveTo( base.currentGroupPointer );
return n;
}
public Toggle addToggle( String theName , boolean theValue ) {
return addToggle( null , "" , theName , theValue );
}
public Knob addKnob( Object theObject , final String theIndex , String theName , int theMin , int theMax ) {
Knob n = addKnob( theObject , theIndex , theName , theMin , theMax , theMin , ( int ) x( base.currentGroupPointer.autoPosition ) , ( int ) y( base.currentGroupPointer.autoPosition ) , Knob.autoWidth );
base.linebreak( n , false , Knob.autoWidth , Knob.autoHeight , n.autoSpacing );
n.moveTo( base.currentGroupPointer );
return n;
}
public Knob addKnob( Object theObject , final String theIndex , String theName ) {
return addKnob( theObject , theIndex , theName , 0 , 100 );
}
public Knob addKnob( String theName , int theMin , int theMax ) {
return addKnob( null , "" , theName , theMin , theMax );
}
public ControlWindow addControlWindow( String theName ) {
ControlP5.logger( ).warning( "ControlWindow has been disabled currently, please have a look at the changlog.txt file inside the src folder." );
return null;
}
/**
* Adds Controllers by Object reference, currently
* supports Slider, Bang, Button, Knob, Numberbox,
* Toggle, Textlabel, Textfield, Range, Slider2D. For
* internal use rather than on application level.
*/
public < C > C addController( final Object theObject , final String theIndex , final String theName , final Class< C > theClass , int theX , int theY ) {
Controller< ? > c = null;
if ( theClass.equals( Slider.class ) ) {
c = addSlider( theObject , theIndex , theName , 0 , 100 , 0 , 0 , 0 , 99 , 9 );
} else if ( theClass.equals( Bang.class ) ) {
c = addBang( theObject , theIndex , theName , 0 , 0 , 19 , 19 );
} else if ( theClass.equals( Button.class ) ) {
c = addButton( theObject , theIndex , theName , 0 , 0 , 0 , 49 , 19 );
} else if ( theClass.equals( Knob.class ) ) {
c = addKnob( theObject , theIndex , theName , 0 , 100 , 0 , 0 , 0 , 49 );
} else if ( theClass.equals( Numberbox.class ) ) {
c = addNumberbox( theObject , theIndex , theName , 0 , 0 , 0 , 99 , 19 );
} else if ( theClass.equals( Toggle.class ) ) {
c = addToggle( theObject , theIndex , theName , false , 0 , 0 , 49 , 19 );
} else if ( theClass.equals( Textfield.class ) ) {
c = addTextfield( theObject , theIndex , theName , 0 , 0 , 99 , 19 );
} else if ( theClass.equals( Range.class ) ) {
c = addRange( theObject , theIndex , theName , 0 , 100 , 0 , 100 , 0 , 0 , 99 , 9 );
} else if ( theClass.equals( Slider2D.class ) ) {
c = addSlider2D( theObject , theIndex , theName , 0 , 100 , 0 , 100 , 0 , 0 , 0 , 0 , 99 , 99 );
} else if ( theClass.equals( DropdownList.class ) ) {
c = addDropdownList( theObject , theIndex , theName , theX , theY , 199 , 99 );
} else if ( theClass.equals( ListBox.class ) ) {
c = addListBox( theObject , theIndex , theName , theX , theY , 199 , 99 );
} else if ( theClass.equals( ScrollableList.class ) ) {
c = addScrollableList( theObject , theIndex , theName , theX , theY , 199 , 99 );
} else if ( theClass.equals( Textlabel.class ) ) {
c = addTextlabel( theName , "<empty>" );
}
// TODO MultiList, Matrix
c.setPosition( theX , theY );
return ( C ) c;
}
/**
* Use with caution, only for internal use.
*
* @exclude
*/
@ControlP5.Invisible public < C > C addGroup( final Object theObject , final String theIndex , final String theName , final Class< C > theClass , int theX , int theY , int theW , int theH ) {
ControlGroup< ? > c = null;
if ( theClass.equals( RadioButton.class ) ) {
c = addRadioButton( theObject , theIndex , theName , theX , theY );
} else if ( theClass.equals( CheckBox.class ) ) {
c = addCheckBox( theObject , theIndex , theName , theX , theY );
} else if ( theClass.equals( ControlGroup.class ) ) {
c = addGroup( theObject , theIndex , theName , theX , theY );
} else if ( theClass.equals( Group.class ) ) {
c = addGroup( theObject , theIndex , theName , theX , theY );
}
c.setPosition( theX , theY );
c.setWidth( theW );
c.setHeight( theH );
return ( C ) c;
}
public < C > C addController( String theName , Class< C > theClass , int theX , int theY ) {
return addController( null , "" , theName , theClass , theX , theY );
}
static public void println( final Object ... strs ) {
for ( Object str : strs ) {
System.out.print( str + " " );
}
System.out.println( );
}
static public void debug( final Object ... strs ) {
if ( DEBUG ) {
println( strs );
}
}
static public void printerr( final Object ... strs ) {
for ( Object str : strs ) {
System.err.print( str + " " );
}
System.err.println( );
}
@Deprecated public Controller< ? > getController( String theName , Object theObject ) {
if ( base._myObjectToControllerMap.containsKey( theObject ) ) {
ArrayList< ControllerInterface< ? >> cs = base._myObjectToControllerMap.get( theObject );
for ( ControllerInterface< ? > c : cs ) {
if ( c.getName( ).equals( theName ) ) {
return ( Controller< ? > ) c;
}
}
}
return null;
}
@Deprecated public Tab addTab( PApplet theWindow , String theName ) {
return addTab( base.cp5.controlWindow , theName );
}
@Deprecated public Tab addTab( ControlWindow theWindow , String theName ) {
for ( int i = 0 ; i < theWindow.getTabs( ).size( ) ; i++ ) {
if ( theWindow.getTabs( ).get( i ).getName( ).equals( theName ) ) {
return ( Tab ) theWindow.getTabs( ).get( i );
}
}
Tab myTab = new Tab( base.cp5 , theWindow , theName );
theWindow.getTabs( ).add( myTab );
return myTab;
}
@Deprecated public ControlWindow addControlWindow( final String theName , final int theX , final int theY , final int theWidth , final int theHeight , String theRenderer , int theFrameRate ) {
return addControlWindow( theName );
}
@Deprecated public ControlWindow addControlWindow( final String theWindowName , final int theWidth , final int theHeight ) {
return addControlWindow( theWindowName , 100 , 100 , theWidth , theHeight , "" , 30 );
}
@Deprecated public ControlWindow addControlWindow( final String theWindowName , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addControlWindow( theWindowName , theX , theY , theWidth , theHeight , "" , 30 );
}
@Deprecated public ControlWindow addControlWindow( final String theWindowName , final int theX , final int theY , final int theWidth , final int theHeight , final int theFrameRate ) {
return addControlWindow( theWindowName , theX , theY , theWidth , theHeight , "" , theFrameRate );
}
@Deprecated public Slider2D addSlider2D( String theName , int theX , int theY , int theW , int theH ) {
return addSlider2D( null , "" , theName , 0 , theW , 0 , theH , 0 , 0 , theX , theY , theW , theH );
}
@Deprecated public Slider2D addSlider2D( Object theObject , final String theIndex , final String theName , int theX , int theY , int theW , int theH ) {
return addSlider2D( theObject , theIndex , theName , 0 , theW , 0 , theH , 0 , 0 , theX , theY , theW , theH );
}
@Deprecated public Slider2D addSlider2D( String theName , float theMinX , float theMaxX , float theMinY , float theMaxY , float theDefaultValueX , float theDefaultValueY , int theX , int theY , int theW , int theH ) {
return addSlider2D( null , "" , theName , theMinX , theMaxX , theMinY , theMaxY , theDefaultValueX , theDefaultValueY , theX , theY , theW , theH );
}
@Deprecated public Button addButton( final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
return addButton( null , "" , theName , theValue , theX , theY , theW , theH );
}
@Deprecated public Bang addBang( final String theName , final int theX , final int theY ) {
return addBang( null , "" , theName , theX , theY , 20 , 20 );
}
@Deprecated public Bang addBang( final String theName , final int theX , final int theY , final int theWidth , final int theHeight ) {
return addBang( null , "" , theName , theX , theY , theWidth , theHeight );
}
@Deprecated public Toggle addToggle( final String theName , final boolean theDefaultValue , final float theX , final float theY , final int theWidth , final int theHeight ) {
return addToggle( null , "" , theName , theDefaultValue , theX , theY , theWidth , theHeight );
}
@Deprecated public Toggle addToggle( final String theName , final float theX , final float theY , final int theWidth , final int theHeight ) {
return addToggle( null , "" , theName , false , theX , theY , theWidth , theHeight );
}
@Deprecated public Toggle addToggle( final Object theObject , final String theIndex , final String theName , final float theX , final float theY , final int theWidth , final int theHeight ) {
return addToggle( theObject , theIndex , theName , false , theX , theY , theWidth , theHeight );
}
}

150
controlP5/ControlTimer.java Executable file
View File

@ -0,0 +1,150 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* control timer is a timer that can be used for example as a stop watch or a duration timer.
*
* @example controllers/ControlP5timer
*/
public class ControlTimer {
long millisOffset;
int ms, s, m, h, d;
float _mySpeed = 1;
int current, previous;
/**
* create a new control timer, a timer that counts up in time.
*/
public ControlTimer() {
reset();
}
/**
* return a string representation of the current status of the timer.
*
* @return String
*/
public String toString() {
update();
return (((h < 10) ? "0" + h : String.valueOf(h)) + " : " + ((m < 10) ? "0" + m : String.valueOf(m)) + " : " + ((s < 10) ? "0" + s : String.valueOf(s)) // +
// " : "
// +
// ((ms<100) ? "0" + ms: "" +ms)
);
}
/**
* called to update the timer.
*/
public void update() {
current = (int) time();
if (current > previous + 10) {
ms = (int) (current * _mySpeed);
s = (int) (((current * _mySpeed) / 1000));
m = s / 60;
h = m / 60;
d = h / 24;
ms %= 1000;
s %= 60;
m %= 60;
h %= 24;
previous = current;
}
}
/**
* get the time in milliseconds since the timer was started.
*
* @return long
*/
public long time() {
return (System.currentTimeMillis() - millisOffset);
}
/**
* reset the timer.
*/
public void reset() {
millisOffset = System.currentTimeMillis();
current = previous = 0;
s = 0; // Values from 0 - 59
m = 0; // Values from 0 - 59
h = 0; // Values from 0 - 23
update();
}
/**
* set the speed of time, for slow motion or high speed.
*
* @param theSpeed int
*/
public void setSpeedOfTime(float theSpeed) {
_mySpeed = theSpeed;
update();
}
/**
* Get the milliseconds of the timer.
*/
public int millis() {
return ms;
}
/**
* Seconds position of the timer.
*/
public int second() {
return s;
}
/**
* Minutes position of the timer.
*/
public int minute() {
return m;
}
/**
* Hour position of the timer in international format (0-23).
*/
public int hour() {
return h;
}
/**
* day position of the timer.
*/
public int day() {
return d;
}
}

978
controlP5/ControlWindow.java Executable file
View File

@ -0,0 +1,978 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser
* General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at
* your option) any later version. This library is
* distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
import main.java.src2.main.java.controlP5.controlP5.ControlP5Base.KeyCode;
// TODO ! add mouse-button mask for left, center, right; also see Controller #mouse-button ^1
/**
* @example controllers/ControlP5window
*/
public final class ControlWindow {
private ControlP5 cp5;
private Controller< ? > isControllerActive;
public int background = 0x00000000;
private CColor color = new CColor( );
private final String _myName = "main";
private PApplet _myApplet;
private ControllerList _myTabs;
boolean isVisible = true;
private boolean isInit = false;
private boolean isRemove = false;
private CDrawable _myDrawable;
boolean isAutoDraw;
private boolean isUpdate;
private List< Canvas > _myCanvas;
private boolean isDrawBackground = true;
private boolean isUndecorated = false;
private float[] autoPosition = new float[]{ 10 , 30 , 0 };
private float tempAutoPositionHeight = 0;
private boolean rendererNotification = false;
private float[] positionOfTabs = new float[]{ 0 , 0 , 0 };
private int _myFrameCount = 0;
private boolean isMouse = true;
private Pointer _myPointer;
private int mouseWheelMoved = 0;
private final List< ControllerInterface< ? >> mouseoverlist;
private boolean isMouseOver;
int mouseX;
int mouseY;
int pmouseX;
int pmouseY;
private boolean mousePressed;
long mousePressedTime;
long pmousePressedTime;
boolean mouselock;
char key;
int keyCode;
private final int numKeys = 1024;
private boolean[] keys = new boolean[ numKeys ];
private int numOfActiveKeys = 0;
private boolean focused = true;
/**
* @exclude
*/
public ControlWindow( final ControlP5 theControlP5 , final PApplet theApplet ) {
mouseoverlist = new ArrayList< ControllerInterface< ? >>( );
cp5 = theControlP5;
_myApplet = theApplet;
isAutoDraw = true;
init( );
}
private void init() {
_myPointer = new Pointer( );
_myCanvas = new ArrayList< Canvas >( );
_myTabs = new ControllerList( );
_myTabs.add( new Tab( cp5 , this , "global" ) );
_myTabs.add( new Tab( cp5 , this , "default" ) );
activateTab( ( Tab ) _myTabs.get( 1 ) );
/* register a post event that will be called by
* processing after the draw method has been
* finished. */
// processing pre 2.0 will not draw automatically if
// in P3D mode. in earlier versions of
// controlP5 this had been checked here and the user
// had been informed to draw controlP5
// manually by adding cp5.draw() to the sketch's
// draw function. with processing 2.0 and this
// version of controlP5 this notification does no
// longer exist.
if (!isInit) {
_myApplet.registerMethod( "pre" , this );
_myApplet.registerMethod( "draw" , this );
if ( !cp5.isAndroid ) {
_myApplet.registerMethod( "keyEvent" , this );
_myApplet.registerMethod( "mouseEvent" , this );
}
}
mousePressedTime = System.currentTimeMillis( );
pmousePressedTime = System.currentTimeMillis( );
isInit = true;
}
public Tab getCurrentTab( ) {
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
if ( ( ( Tab ) _myTabs.get( i ) ).isActive( ) ) {
return ( Tab ) _myTabs.get( i );
}
}
return null;
}
public ControlWindow activateTab( String theTab ) {
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
if ( _myTabs.get( i ).getName( ).equals( theTab ) ) {
if ( ! ( ( Tab ) _myTabs.get( i ) ).isActive ) {
resetMouseOver( );
}
activateTab( ( Tab ) _myTabs.get( i ) );
}
}
return this;
}
public ControlWindow removeTab( Tab theTab ) {
_myTabs.remove( theTab );
return this;
}
public Tab add( Tab theTab ) {
_myTabs.add( theTab );
return theTab;
}
public Tab addTab( String theTab ) {
return getTab( theTab );
}
ControlWindow activateTab(Tab theTab) {
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
if ( _myTabs.get( i ) == theTab ) {
if ( ! ( ( Tab ) _myTabs.get( i ) ).isActive ) {
resetMouseOver( );
}
( ( Tab ) _myTabs.get( i ) ).setActive( true );
} else {
( ( Tab ) _myTabs.get( i ) ).setActive( false );
}
}
return this;
}
public ControllerList getTabs( ) {
return _myTabs;
}
public Tab getTab( String theTabName ) {
return cp5.getTab( this , theTabName );
}
/**
* Sets the position of the tab bar which is set to 0,0
* by default. to move the tabs to y-position 100, use
* cp5.getWindow().setPositionOfTabs(0,100);
*
*/
public ControlWindow setPositionOfTabs( int theX , int theY ) {
positionOfTabs[0] = theX;
positionOfTabs[1] = theY;
return this;
}
public float[] getPositionOfTabs( ) {
return positionOfTabs;
}
void setAllignmentOfTabs( int theValue , int theWidth ) {
// TODO
}
void setAllignmentOfTabs( int theValue , int theWidth , int theHeight ) {
// TODO
}
void setAllignmentOfTabs( int theValue ) {
// TODO
}
public void remove( ) {
for ( int i = _myTabs.size( ) - 1 ; i >= 0 ; i-- ) {
_myTabs.get( i ).remove( );
}
_myTabs.clear( );
_myTabs.clearDrawable( );
}
/**
* clear the control window, delete all controllers from
* a control window.
*/
public ControlWindow clear( ) {
remove( );
return this;
}
void updateFont(ControlFont theControlFont) {
for ( int i = 0 ; i < _myTabs.size( ) ; i++ ) {
( ( Tab ) _myTabs.get( i ) ).updateFont( theControlFont );
}
}
/**
* @exclude
*/
@ControlP5.Invisible public void updateEvents( ) {
handleMouseOver( );
handleMouseWheelMoved( );
if ( _myTabs.size( ) <= 0 ) {
return;
}
_myTabs.get( 0 ).updateEvents( );
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
_myTabs.get( i ).continuousUpdateEvents( );
if ( ( ( Tab ) _myTabs.get( i ) ).isActive( ) && _myTabs.get( i ).isVisible( ) ) {
_myTabs.get( i ).updateEvents( );
}
}
}
/**
* returns true if the mouse is inside a controller. !!!
* doesnt work for groups yet.
*/
public boolean isMouseOver( ) {
// TODO doesnt work for all groups yet, only ListBox
// and DropdownList.
if ( _myFrameCount + 1 < _myApplet.frameCount ) {
resetMouseOver( );
}
return isVisible && isMouseOver;
}
public boolean isMouseOver( ControllerInterface< ? > theController ) {
return mouseoverlist.contains( theController );
}
public void resetMouseOver( ) {
isMouseOver = false;
for ( int i = mouseoverlist.size( ) - 1 ; i >= 0 ; i-- ) {
mouseoverlist.get( i ).setMouseOver( false );
}
mouseoverlist.clear( );
}
public ControllerInterface< ? > getFirstFromMouseOverList( ) {
if ( getMouseOverList( ).isEmpty( ) ) {
return null;
} else {
return getMouseOverList( ).get( 0 );
}
}
/**
* A list of controllers that are registered with a
* mouseover.
*/
public List< ControllerInterface< ? >> getMouseOverList( ) {
return mouseoverlist;
}
private ControlWindow handleMouseOver( ) {
for ( int i = mouseoverlist.size( ) - 1 ; i >= 0 ; i-- ) {
if ( !mouseoverlist.get( i ).isMouseOver( ) || !isVisible ) {
mouseoverlist.remove( i );
}
}
isMouseOver = mouseoverlist.size( ) > 0;
return this;
}
public ControlWindow removeMouseOverFor( ControllerInterface< ? > theController ) {
mouseoverlist.remove( theController );
return this;
}
ControlWindow setMouseOverController(ControllerInterface<?> theController) {
if ( !mouseoverlist.contains( theController ) && isVisible && theController.isVisible( ) ) {
mouseoverlist.add( theController );
}
isMouseOver = true;
return this;
}
/**
* updates all controllers inside the control window if
* update is enabled.
*
* @exclude
*/
public void update( ) {
_myTabs.get( 0 ).update( );
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
( ( Tab ) _myTabs.get( i ) ).update( );
}
}
/**
* enable or disable the update function of a control
* window.
*/
public void setUpdate( boolean theFlag ) {
isUpdate = theFlag;
for ( int i = 0 ; i < _myTabs.size( ) ; i++ ) {
_myTabs.get( i ).setUpdate( theFlag );
}
}
/**
* check the update status of a control window.
*/
public boolean isUpdate( ) {
return isUpdate;
}
public ControlWindow addCanvas( Canvas theCanvas ) {
_myCanvas.add( theCanvas );
theCanvas.setControlWindow( this );
theCanvas.setup( _myApplet.g );
return this;
}
public ControlWindow removeCanvas( Canvas theCanvas ) {
_myCanvas.remove( theCanvas );
return this;
}
private boolean isReset = false;
public ControlWindow pre( ) {
if ( _myFrameCount + 1 < _myApplet.frameCount ) {
if ( isReset ) {
resetMouseOver( );
isReset = false;
}
} else {
isReset = true;
}
if ( papplet( ).focused != focused ) {
clearKeys( );
mousePressed = false;
focused = papplet( ).focused;
}
return this;
}
boolean pmouseReleased; // Android
boolean pmousePressed; // Android
/**
* when in Android mode, call mouseEvent(int, int,
* boolean).
*/
public void mouseEvent( int theX , int theY , boolean pressed ) {
mouseX = theX - cp5.pgx - cp5.ox;
mouseY = theY - cp5.pgy - cp5.oy;
if ( pressed && !pmousePressed ) {
updateEvents( );
mousePressedEvent( );
pmousePressedTime = mousePressedTime;
mousePressedTime = System.currentTimeMillis( );
pmousePressed = true;
pmouseReleased = false;
} else if ( !pressed && !pmouseReleased ) {
updateEvents( );
mouseReleasedEvent( );
for ( ControllerInterface c : mouseoverlist ) {
if ( c instanceof Controller ) {
final Controller c1 = ( ( Controller ) c );
c1.onLeave( );
c1.onRelease( );
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( c1 , ControlP5.ACTION_LEAVE ) );
c1.callListener( ControlP5.ACTION_LEAVE );
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( c1 , ControlP5.ACTION_RELEASE ) );
c1.callListener( ControlP5.ACTION_RELEASE );
} else if ( c instanceof ControllerGroup ) {
( ( ControllerGroup ) c ).mouseReleased( );
}
}
resetMouseOver( );
pmousePressed = false;
pmouseReleased = true;
}
}
/**
* @exclude
*/
public void mouseEvent( MouseEvent theMouseEvent ) {
if ( isMouse ) {
mouseX = theMouseEvent.getX( ) - cp5.pgx - cp5.ox;
mouseY = theMouseEvent.getY( ) - cp5.pgy - cp5.oy;
if ( theMouseEvent.getAction( ) == MouseEvent.PRESS ) {
mousePressedEvent( );
}
if ( theMouseEvent.getAction( ) == MouseEvent.RELEASE ) {
mouseReleasedEvent( );
}
if ( theMouseEvent.getAction( ) == MouseEvent.WHEEL ) {
setMouseWheelRotation( theMouseEvent.getCount( ) );
}
}
}
public void keyEvent( KeyEvent theKeyEvent ) {
if ( theKeyEvent.getAction( ) == KeyEvent.PRESS ) {
keys[ theKeyEvent.getKeyCode( ) ] = true;
numOfActiveKeys++;
cp5.modifiers = theKeyEvent.getModifiers( );
key = theKeyEvent.getKey( );
keyCode = theKeyEvent.getKeyCode( );
}
if ( theKeyEvent.getAction( ) == KeyEvent.RELEASE ) {
keys[ theKeyEvent.getKeyCode( ) ] = false;
numOfActiveKeys--;
cp5.modifiers = theKeyEvent.getModifiers( );
}
if ( theKeyEvent.getAction( ) == KeyEvent.PRESS && cp5.isShortcuts( ) ) {
int n = 0;
for ( boolean b : keys ) {
n += b ? 1 : 0;
}
char[] c = new char[ n ];
n = 0;
for ( int i = 0 ; i < keys.length ; i++ ) {
if ( keys[ i ] ) {
c[ n++ ] = ( ( char ) i );
}
}
KeyCode code = new KeyCode( c );
if ( cp5.keymap.containsKey( code ) ) {
for ( ControlKey ck : cp5.keymap.get( code ) ) {
ck.keyEvent( );
}
}
}
handleKeyEvent( theKeyEvent );
}
public void clearKeys( ) {
keys = new boolean[ numKeys ];
numOfActiveKeys = 0;
}
// TODO
public void draw( PGraphics pg , int theX , int theY ) {
}
/**
* @exclude draw content.
*/
public void draw( ) {
_myFrameCount = _myApplet.frameCount;
draw( cp5.pg );
}
public void draw( PGraphics pg ) {
pg.pushMatrix( );
pg.translate( cp5.ox , cp5.oy );
if (!cp5.blockDraw) {
if ( cp5.isAndroid ) {
mouseEvent( cp5.papplet.mouseX , cp5.papplet.mouseY , cp5.papplet.mousePressed );
} else {
updateEvents( );
}
if ( isVisible ) {
if ( cp5.isGraphics ) {
pg.beginDraw( );
if ( ( ( background >> 24 ) & 0xff ) != 0 ) {
pg.background( background );
}
}
// TODO save stroke, noStroke, fill, noFill, strokeWeight parameters and restore after drawing controlP5 elements.
int myRectMode = pg.rectMode;
int myEllipseMode = pg.ellipseMode;
int myImageMode = pg.imageMode;
pg.pushStyle( );
pg.rectMode( PConstants.CORNER );
pg.ellipseMode( PConstants.CORNER );
pg.imageMode( PConstants.CORNER );
pg.noStroke( );
if ( _myDrawable != null ) {
_myDrawable.draw( pg );
}
for ( int i = 0 ; i < _myCanvas.size( ) ; i++ ) {
if ( ( _myCanvas.get( i ) ).mode( ) == Canvas.PRE ) {
( _myCanvas.get( i ) ).update( _myApplet );
( _myCanvas.get( i ) ).draw( pg );
}
}
pg.noStroke( );
pg.noFill( );
int myOffsetX = ( int ) getPositionOfTabs( )[0];
int myOffsetY = ( int ) getPositionOfTabs( )[1];
int myHeight = 0;
if ( _myTabs.size( ) > 0 ) {
for ( int i = 1 ; i < _myTabs.size( ) ; i++ ) {
if ( _myTabs.get( i ).isVisible( ) ) {
if ( myHeight < ( ( Tab ) _myTabs.get( i ) ).height( ) ) {
myHeight = ( ( Tab ) _myTabs.get( i ) ).height( );
}
// conflicts with Android, getWidth not found TODO
// if (myOffsetX >
// (papplet().getWidth()) -
// ((Tab)
// _myTabs.get(i)).width()) {
// myOffsetY += myHeight + 1;
// myOffsetX = (int)
// getPositionOfTabs().x;
// myHeight = 0;
// }
( ( Tab ) _myTabs.get( i ) ).setOffset( myOffsetX , myOffsetY );
if ( ( ( Tab ) _myTabs.get( i ) ).isActive( ) ) {
_myTabs.get( i ).draw( pg );
}
if ( ( ( Tab ) _myTabs.get( i ) ).updateLabel( ) ) {
( ( Tab ) _myTabs.get( i ) ).drawLabel( pg );
}
myOffsetX += ( ( Tab ) _myTabs.get( i ) ).width( );
}
}
_myTabs.get( 0 ).draw( pg );
}
for ( int i = 0 ; i < _myCanvas.size( ) ; i++ ) {
if ( ( _myCanvas.get( i ) ).mode( ) == Canvas.POST ) {
( _myCanvas.get( i ) ).draw( pg );
}
}
pmouseX = mouseX;
pmouseY = mouseY;
/* draw Tooltip here. */
cp5.getTooltip( ).draw( this );
pg.rectMode( myRectMode );
pg.ellipseMode( myEllipseMode );
pg.imageMode( myImageMode );
pg.popStyle( );
if ( cp5.isGraphics ) {
pg.endDraw( );
cp5.papplet.image( pg , cp5.pgx , cp5.pgy );
}
}
}
pg.popMatrix( );
}
/**
* Adds a custom context to a ControlWindow. Use a
* custom class which implements the CDrawable interface
*
* @see CDrawable
* @param theDrawable CDrawable
*/
public ControlWindow setContext( CDrawable theDrawable ) {
_myDrawable = theDrawable;
return this;
}
/**
* returns the name of the control window.
*/
public String name( ) {
return _myName;
}
private void mousePressedEvent( ) {
if ( isVisible ) {
mousePressed = true;
pmousePressedTime = mousePressedTime;
mousePressedTime = System.currentTimeMillis( );
for ( int i = 0 ; i < _myTabs.size( ) ; i++ ) {
if ( _myTabs.get( i ).setMousePressed( true ) ) {
mouselock = true;
return;
}
}
}
}
private void mouseReleasedEvent( ) {
if ( isVisible ) {
mousePressed = false;
mouselock = false;
for ( int i = 0 ; i < _myTabs.size( ) ; i++ ) {
_myTabs.get( i ).setMousePressed( false );
}
}
}
void setMouseWheelRotation( int theRotation ) {
if ( isMouseOver( ) ) {
mouseWheelMoved = theRotation;
}
}
@SuppressWarnings( "unchecked" ) private void handleMouseWheelMoved( ) {
if ( mouseWheelMoved != 0 ) {
List< ControllerInterface< ? >> mouselist = new CopyOnWriteArrayList< ControllerInterface< ? >>( mouseoverlist );
for ( ControllerInterface< ? > c : mouselist ) {
if ( c.isVisible( ) ) {
if ( c instanceof Controller ) {
( ( Controller ) c ).onScroll( mouseWheelMoved );
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( ( Controller ) c , ControlP5.ACTION_WHEEL ) );
( ( Controller ) c ).callListener( ControlP5.ACTION_WHEEL );
}
if ( c instanceof ControllerGroup ) {
( ( ControllerGroup ) c ).onScroll( mouseWheelMoved );
}
if ( c instanceof Slider ) {
( ( Slider ) c ).scrolled( mouseWheelMoved );
} else if ( c instanceof Knob ) {
( ( Knob ) c ).scrolled( mouseWheelMoved );
} else if ( c instanceof Numberbox ) {
( ( Numberbox ) c ).scrolled( mouseWheelMoved );
} else if ( c instanceof Textarea ) {
( ( Textarea ) c ).scrolled( mouseWheelMoved );
} else if ( c instanceof ColorWheel ) {
( ( ColorWheel ) c ).scrolled( mouseWheelMoved );
}
break;
}
}
}
mouseWheelMoved = 0;
}
public boolean isMousePressed( ) {
return mousePressed;
}
/**
* @exclude
* @param theKeyEvent KeyEvent
*/
public void handleKeyEvent( KeyEvent theKeyEvent ) {
for ( int i = 0 ; i < _myTabs.size( ) ; i++ ) {
_myTabs.get( i ).keyEvent( theKeyEvent );
}
}
/**
* set the color for the controller while active.
*/
public ControlWindow setColorActive( int theColor ) {
color.setActive( theColor );
for ( int i = 0 ; i < getTabs( ).size( ) ; i++ ) {
( ( Tab ) getTabs( ).get( i ) ).setColorActive( theColor );
}
return this;
}
/**
* set the foreground color of the controller.
*/
public ControlWindow setColorForeground( int theColor ) {
color.setForeground( theColor );
for ( int i = 0 ; i < getTabs( ).size( ) ; i++ ) {
( ( Tab ) getTabs( ).get( i ) ).setColorForeground( theColor );
}
return this;
}
/**
* set the background color of the controller.
*/
public ControlWindow setColorBackground( int theColor ) {
color.setBackground( theColor );
for ( int i = 0 ; i < getTabs( ).size( ) ; i++ ) {
( ( Tab ) getTabs( ).get( i ) ).setColorBackground( theColor );
}
return this;
}
/**
* set the color of the text label of the controller.
*/
public ControlWindow setColorLabel( int theColor ) {
color.setCaptionLabel( theColor );
for ( int i = 0 ; i < getTabs( ).size( ) ; i++ ) {
( ( Tab ) getTabs( ).get( i ) ).setColorLabel( theColor );
}
return this;
}
/**
* set the color of the values.
*/
public ControlWindow setColorValue( int theColor ) {
color.setValueLabel( theColor );
for ( int i = 0 ; i < getTabs( ).size( ) ; i++ ) {
( ( Tab ) getTabs( ).get( i ) ).setColorValue( theColor );
}
return this;
}
/**
* set the background color of the control window.
*/
public ControlWindow setBackground( int theValue ) {
background = theValue;
return this;
}
/**
* get the papplet instance of the ControlWindow.
*/
public PApplet papplet( ) {
return _myApplet;
}
/**
* sets the frame rate of the control window.
*
* @param theFrameRate
* @return ControlWindow
*/
public ControlWindow frameRate( int theFrameRate ) {
_myApplet.frameRate( theFrameRate );
return this;
}
public ControlWindow show( ) {
isVisible = true;
return this;
}
/**
* by default the background of a controlWindow is
* filled with a background color every frame. to enable
* or disable the background from drawing, use
* setDrawBackgorund(true/false).
*
* @param theFlag
* @return ControlWindow
*/
public ControlWindow setDrawBackground( boolean theFlag ) {
isDrawBackground = theFlag;
return this;
}
public boolean isDrawBackground( ) {
return isDrawBackground;
}
public boolean isVisible( ) {
return isVisible;
}
private boolean isControllerActive(Controller<?> theController) {
if ( isControllerActive == null ) {
return false;
}
return isControllerActive.equals( theController );
}
private ControlWindow setControllerActive(Controller<?> theController) {
isControllerActive = theController;
return this;
}
public ControlWindow toggleUndecorated( ) {
setUndecorated( !isUndecorated( ) );
return this;
}
public ControlWindow setUndecorated( boolean theFlag ) {
if ( theFlag != isUndecorated( ) ) {
isUndecorated = theFlag;
//_myApplet.frame.removeNotify( );
//_myApplet.frame.setUndecorated( isUndecorated );
_myApplet.setSize( _myApplet.width , _myApplet.height );
//_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height );
//_myApplet.frame.setSize( _myApplet.width , _myApplet.height );
//_myApplet.frame.addNotify( );
}
return this;
}
public boolean isUndecorated( ) {
return isUndecorated;
}
public ControlWindow setPosition( int theX , int theY ) {
return setLocation( theX , theY );
}
public ControlWindow setLocation( int theX , int theY ) {
//_myApplet.frame.setLocation( theX , theY );
return this;
}
public Pointer getPointer( ) {
return _myPointer;
}
public ControlWindow disablePointer( ) {
_myPointer.disable( );
return this;
}
public ControlWindow enablePointer( ) {
_myPointer.enable( );
return this;
}
/**
* A pointer by default is linked to the mouse and
* stores the x and y position as well as the pressed
* and released state. The pointer can be accessed by
* its getter method {@link ControlWindow#getPointer()}.
* Then use
* {@link ControlWindow#set(int, int)} to
* alter its position or invoke {
* {@link ControlWindow#pressed()} or
* {@link ControlWindow#released()} to change
* its state. To disable the mouse and enable the
* Pointer use {@link ControlWindow#enable()}
* and {@link ControlWindow#disable()} to
* default back to the mouse as input parameter.
*/
// TODO offset against pgx and pgy
public class Pointer {
public Pointer setX( int theX ) {
mouseX = theX;
return this;
}
public Pointer setY( int theY ) {
mouseY = theY;
return this;
}
public int getY( ) {
return mouseY;
}
public int getX( ) {
return mouseX;
}
public int getPreviousX( ) {
return pmouseX;
}
public int getPreviousY( ) {
return pmouseY;
}
public Pointer set( int theX , int theY ) {
setX( theX );
setY( theY );
return this;
}
// TODO mousePressed/mouseReleased are handled wrongly, released is called when moved, for now do not use, instead use set(x,y), pressed(), released()
public Pointer set( int theX , int theY , boolean pressed ) {
setX( theX );
setY( theY );
if ( pressed ) {
if ( !mousePressed ) {
pressed( );
}
} else {
if ( mousePressed ) {
released( );
}
}
return this;
}
public Pointer pressed( ) {
mousePressedEvent( );
return this;
}
public Pointer released( ) {
mouseReleasedEvent( );
return this;
}
public void enable( ) {
isMouse = false;
}
public void disable( ) {
isMouse = true;
}
public boolean isEnabled( ) {
return !isMouse;
}
}
/**
* hide the controllers and tabs of the ControlWindow.
*/
public ControlWindow hide( ) {
isVisible = false;
isMouseOver = false;
return this;
}
}

View File

@ -0,0 +1,34 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
@Deprecated
public abstract class ControlWindowCanvas extends Canvas {
// Wrapper class.
}

2232
controlP5/Controller.java Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Used to convert Annotations into individual controllers this method of creating controllers is
* derived from cp5magic by Karsten Schmidt http://hg.postspectacular.com/cp5magic/wiki/Home
*/
class ControllerAutomator {
static Map< Set< Class< ? >> , Class< ? extends Controller< ? >>> mapping = new HashMap< Set< Class< ? >> , Class< ? extends Controller< ? >>>( );
static {
mapping.put( makeKey( boolean.class ) , Toggle.class );
mapping.put( makeKey( int.class ) , Slider.class );
mapping.put( makeKey( float.class ) , Slider.class );
mapping.put( makeKey( String.class ) , Textfield.class );
}
static Map< String , Class< ? extends ControllerInterface< ? >>> types = new HashMap< String , Class< ? extends ControllerInterface< ? >>>( );
static {
types.put( "slider" , Slider.class );
types.put( "knob" , Knob.class );
types.put( "numberbox" , Numberbox.class );
types.put( "toggle" , Toggle.class );
types.put( "bang" , Bang.class );
types.put( "toggle" , Toggle.class );
types.put( "textfield" , Textfield.class );
types.put( "label" , Textlabel.class );
types.put( "textlabel" , Textlabel.class );
types.put( "list" , ListBox.class );
types.put( "dropdown" , DropdownList.class );
types.put( "scrollable" , ScrollableList.class );
}
static Set< Class< ? >> makeKey( Class< ? > ... cs ) {
Set< Class< ? >> set = new HashSet< Class< ? >>( );
Collections.addAll(set, cs);
return set;
}
private final ControlP5 cp5;
ControllerAutomator( ControlP5 c ) {
cp5 = c;
}
private Object[] getParameters( Class< ? >[] cs , String v ) {
if ( cs[ 0 ] == int.class ) {
return new Object[] { i( v , 0 ) };
} else if ( cs[ 0 ] == float.class ) {
return new Object[] { Float.parseFloat( v ) };
} else if ( cs[ 0 ] == String.class ) {
return new Object[] { v };
} else if ( cs[ 0 ] == boolean.class ) {
return new Object[] { Boolean.parseBoolean( v ) };
}
return new Object[ 0 ];
}
/**
* analyzes an object and adds fields with ControlElement annotations to controlP5.
*
*/
void addControllersFor( final String theAddressSpace , final Object t ) {
System.out.println("OKOK");
if ( t instanceof List< ? > ) {
return;
}
Class< ? > c = t.getClass( );
Field[] fs = c.getFields( );
Method[] ms = c.getMethods( );
Map< ControllerInterface , Integer > controllersIndexed = new HashMap< ControllerInterface , Integer >( );
for ( Method m : ms ) {
int zindex = 0;
if ( m.isAnnotationPresent( ControlElement.class ) ) {
ControlElement ce = m.getAnnotation( ControlElement.class );
Map< String , String > params = new HashMap< String , String >( );
Class< ? extends ControllerInterface< ? >> type = null;
for ( String s : ce.properties( ) ) {
String[] a = s.split( "=" );
if ( a[ 0 ].startsWith( "type" ) ) {
type = types.get( a[ 1 ].toLowerCase( ) );
} else if ( a[ 0 ].equals( "z-index" ) ) {
zindex = i( a[ 1 ] , 0 );
} else {
params.put( "set" + capitalize( a[ 0 ] ) , a[ 1 ] );
}
}
if ( type == null ) {
type = mapping.get( makeKey( m.getParameterTypes( ) ) );
}
if ( type != null ) {
ControllerInterface< ? > cntr = null;
if ( params.containsKey( "setItems" ) ) {
if ( type.equals( ListBox.class ) ) {
cntr = cp5.addScrollableList( t , theAddressSpace , m.getName( ) , ce.x( ) , ce.y( ) , 100 , 100 );
( ( ScrollableList ) cntr ).addItems( params.get( "setItems" ).split( "," ) );
( ( ScrollableList ) cntr ).setOpen( true );
( ( ScrollableList ) cntr ).setType(ScrollableList.LIST);
} else if ( type.equals( DropdownList.class ) ) {
cntr = cp5.addScrollableList( t , theAddressSpace , m.getName( ) , ce.x( ) , ce.y( ) , 100 , 100 );
( ( ScrollableList ) cntr ).addItems( params.get( "setItems" ).split( "," ) );
( ( ScrollableList ) cntr ).setOpen( false );
( ( ScrollableList ) cntr ).setType(ScrollableList.DROPDOWN);
} else if ( type.equals( ScrollableList.class ) ) {
cntr = cp5.addScrollableList( t , theAddressSpace , m.getName( ) , ce.x( ) , ce.y( ) , 100 , 100 );
( ( ScrollableList ) cntr ).addItems( params.get( "setItems" ).split( "," ) );
}
} else {
cntr = cp5.addController( t , theAddressSpace , m.getName( ) , type , ce.x( ) , ce.y( ) );
}
controllersIndexed.put( cntr , zindex );
if ( ce.label( ).length( ) > 0 ) {
cntr.setCaptionLabel( ce.label( ) );
}
for ( Iterator< String > i = params.keySet( ).iterator( ) ; i.hasNext( ) ; ) {
String k = i.next( );
String v = params.get( k );
for ( Method method : cntr.getClass( ).getMethods( ) ) {
if ( method.getName( ).equals( k ) ) {
try {
Object[] os = getParameters( method.getParameterTypes( ) , v );
method.setAccessible( true );
method.invoke( cntr , os );
} catch ( Exception e ) {
/* TODO is thrown when running ControlP5annotation example */
// ControlP5.logger.severe( e.toString( ) );
}
}
}
}
}
}
}
for ( Field f : fs ) {
int zindex = 0;
if ( f.isAnnotationPresent( ControlElement.class ) ) {
ControlElement ce = f.getAnnotation( ControlElement.class );
Map< String , String > params = new HashMap< String , String >( );
Class< ? extends ControllerInterface< ? >> type = null;
for ( String s : ce.properties( ) ) {
String[] a = s.split( "=" );
if ( a[ 0 ].startsWith( "type" ) ) {
type = types.get( a[ 1 ].toLowerCase( ) );
} else if ( a[ 0 ].equals( "z-index" ) ) {
zindex = i( a[ 1 ] , 0 );
} else {
params.put( "set" + capitalize( a[ 0 ] ) , a[ 1 ] );
}
}
ControllerInterface< ? > cntr = null;
f.setAccessible( true );
if ( f.getType( ) == float.class || f.getType( ) == int.class ) {
if ( type == Knob.class ) {
cntr = cp5.addKnob( t , theAddressSpace , f.getName( ) );
} else if ( type == Numberbox.class ) {
cntr = cp5.addNumberbox( t , theAddressSpace , f.getName( ) );
} else {
cntr = cp5.addSlider( t , theAddressSpace , f.getName( ) );
}
try {
if ( f.getType( ) == float.class ) {
cntr.setValue( f.getFloat( t ) );
} else {
cntr.setValue( f.getInt( t ) );
}
} catch ( Exception e ) {
ControlP5.logger.severe( e.toString( ) );
}
} else if ( f.getType( ) == String.class ) {
if ( type == Textlabel.class ) {
String s = "";
try {
s = String.valueOf(f.get(t));
if ( f.get( t ) == null ) {
s = ce.label( );
}
} catch ( Exception e ) {
}
cntr = cp5.addTextlabel( t , theAddressSpace , f.getName( ) , s );
} else {
cntr = cp5.addTextfield( t , theAddressSpace , f.getName( ) );
}
} else if ( f.getType( ) == boolean.class ) {
cntr = cp5.addToggle( t , theAddressSpace , f.getName( ) );
try {
cntr.setValue( f.getBoolean( t ) ? 1 : 0 );
} catch ( Exception e ) {
ControlP5.logger.severe( e.toString( ) );
}
}
if ( cntr != null ) {
controllersIndexed.put( cntr , zindex );
if ( ce.label( ).length( ) > 0 ) {
cntr.setCaptionLabel( ce.label( ) );
}
cntr.setPosition( ce.x( ) , ce.y( ) );
for ( Iterator< String > i = params.keySet( ).iterator( ) ; i.hasNext( ) ; ) {
String k = i.next( );
String v = params.get( k );
for ( Method method : cntr.getClass( ).getMethods( ) ) {
if ( method.getName( ).equals( k ) ) {
try {
Object[] os = getParameters( method.getParameterTypes( ) , v );
method.setAccessible( true );
method.invoke( cntr , os );
} catch ( Exception e ) {
ControlP5.logger.severe( e.toString( ) );
}
}
}
}
}
}
}
/* */
for ( Entry< ControllerInterface , Integer > entry : entriesSortedByValues( controllersIndexed ) ) {
entry.getKey( ).bringToFront( );
}
}
private static < K , V extends Comparable< ? super V >> List< Entry< K , V >> entriesSortedByValues( Map< K , V > map ) {
List< Entry< K , V >> sortedEntries = new ArrayList< Entry< K , V >>( map.entrySet( ) );
Collections.sort( sortedEntries , new Comparator< Entry< K , V >>( ) {
@Override
public int compare( Entry< K , V > e1 , Entry< K , V > e2 ) {
return e1.getValue( ).compareTo( e2.getValue( ) );
}
} );
return sortedEntries;
}
/**
* capitalizes a string.
*
* @param theString
* @return String
*/
static String capitalize( String theString ) {
final StringBuilder result = new StringBuilder( theString.length( ) );
String[] words = theString.split( "\\s" );
for ( int i = 0 , l = words.length ; i < l ; ++i ) {
if ( i > 0 )
result.append( " " );
result.append( Character.toUpperCase( words[ i ].charAt( 0 ) ) ).append( words[ i ].substring( 1 ) );
}
return result.toString( );
}
private int i( String o , int theDefault ) {
return isNumeric( o ) ? Integer.parseInt( o ) : isHex( o ) ? o.length( ) == 6 ? ( int ) Long.parseLong( "FF" + o , 16 ) : ( int ) Long.parseLong( o , 16 ) : theDefault;
}
private boolean isNumeric( String str ) {
return str.matches( "(-|\\+)?\\d+(\\.\\d+)?" );
}
private boolean isHex( String str ) {
// (?:0[xX])?[0-9a-fA-F]+ (This will match with or without 0x prefix)
// System.out.println( "isHex? " + str + " " + str.matches( "[\\dA-Fa-f]+" ) );
return str.matches( "[\\dA-Fa-f]+" );
}
}

View File

@ -0,0 +1,52 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
/**
* The interface ControllerDisplay can be used to define custom displays for
* controllers.
*
* @see controlP5.draw(processing.core.PApplet)
* @see controlP5.setDisplay(ControllerDisplay)
*
*/
@SuppressWarnings("unchecked")
@Deprecated
public interface ControllerDisplay extends ControllerView {
/**
* draws your custom controllers. display() will be called by a controller's
* draw() function and will pass a reference of PApplet as well as the
* Controller itself to your custom display class.
*
* @param theApplet
* @param theController
*/
void display(PApplet theApplet, Controller theController);
}

987
controlP5/ControllerGroup.java Executable file
View File

@ -0,0 +1,987 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
**/
import java.util.ArrayList;
import java.util.List;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
import processing.event.KeyEvent;
/**
* ControllerGroup is an abstract class and is extended by class ControlGroup, Tab, or the ListBox.
*
*/
public abstract class ControllerGroup< T > implements ControllerInterface< T > , ControlP5Constants , ControlListener {
protected float[] position = new float[ 2 ];
protected float[] positionBuffer = new float[ 2 ];
protected float[] absolutePosition = new float[ 2 ];
protected ControllerList controllers;
/* the controller that receives KeyEvents*/
protected Controller<?> activeController;
protected List< ControlListener > _myControlListener;
// protected ControlWindow _myControlWindow;
protected ControlP5 cp5;
protected ControllerGroup< ? > _myParent;
protected String _myName;
protected int _myId = -1;
protected CColor color = new CColor( );
protected boolean isMousePressed = false;
// only applies to the area of the title bar of a group
protected boolean isInside = false;
// applies to the area including controllers, currently only supported for listbox
protected boolean isInsideGroup = false;
protected boolean isVisible = true;
protected boolean isOpen = true;
protected boolean isBarVisible = true;
protected boolean isArrowVisible = true;
protected Button _myCloseButton;
protected boolean isMoveable = true;
protected Label _myLabel;
protected Label _myValueLabel;
protected int _myWidth = 99;
protected int _myHeight = 9;
protected boolean isUpdate;
protected List< Canvas > _myCanvas;
protected float _myValue;
protected String _myStringValue;
protected float[] _myArrayValue;
protected boolean isCollapse = true;
protected int _myPickingColor = 0x6600ffff;
protected float[] autoPosition = new float[] { 10 , 30 };
protected float tempAutoPositionHeight = 0;
protected float autoPositionOffsetX = 10;
private String _myAddress = "";
private boolean mouseover;
protected final T me;
/**
* Convenience constructor to extend ControllerGroup.
*/
public ControllerGroup( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public ControllerGroup( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY ) {
position = new float[] { theX , theY };
cp5 = theControlP5;
me = ( T ) this;
color.set( ( theParent == null ) ? ControlP5.color : theParent.color );
_myName = theName;
controllers = new ControllerList( );
_myCanvas = new ArrayList< Canvas >( );
_myControlListener = new ArrayList< ControlListener >( );
_myLabel = new Label( cp5 , _myName );
_myLabel.setText( _myName );
_myLabel.setColor( color.getCaptionLabel( ) );
_myLabel.align( ControlP5Constants.LEFT , ControlP5Constants.TOP );
setParent( ( theParent == null ) ? this : theParent );
}
protected ControllerGroup( int theX , int theY ) {
position = new float[] { theX , theY };
me = ( T ) this;
controllers = new ControllerList( );
_myCanvas = new ArrayList< Canvas >( );
}
@ControlP5.Invisible public void init( ) {
}
@ControlP5.Invisible @Override public ControllerInterface< ? > getParent( ) {
return _myParent;
}
void setParent( ControllerGroup< ? > theParent ) {
if ( _myParent != null && _myParent != this ) {
_myParent.remove( this );
}
_myParent = theParent;
if ( _myParent != this ) {
_myParent.add( this );
}
set( absolutePosition , x( position ) , y( position ) );
set( absolutePosition , x( absolutePosition ) + x( _myParent.absolutePosition ) , y( absolutePosition ) + y( _myParent.absolutePosition ) );
set( positionBuffer , x( position ) , y( position ) );
if ( cp5.getWindow( ) != null ) {
setMouseOver( false );
}
}
public final T setGroup( ControllerGroup< ? > theGroup ) {
setParent( theGroup );
return me;
}
public final T setGroup( String theName ) {
setParent( cp5.getGroup( theName ) );
return me;
}
public final T moveTo( ControllerGroup< ? > theGroup , Tab theTab , ControlWindow theControlWindow ) {
if ( theGroup != null ) {
setGroup( theGroup );
return me;
}
if ( theControlWindow == null ) {
theControlWindow = cp5.controlWindow;
}
setTab( theControlWindow , theTab.getName( ) );
return me;
}
public final T moveTo( ControllerGroup< ? > theGroup ) {
moveTo( theGroup , null , null );
return me;
}
public final T moveTo( Tab theTab ) {
moveTo( null , theTab , theTab.getWindow( ) );
return me;
}
public T moveTo( PApplet thePApplet ) {
moveTo( cp5.controlWindow );
return me;
}
public T moveTo( ControlWindow theControlWindow ) {
moveTo( null , theControlWindow.getTab( "default" ) , theControlWindow );
return me;
}
public final T moveTo( String theTabName ) {
moveTo( null , cp5.controlWindow.getTab( theTabName ) , cp5.controlWindow );
return me;
}
public final T moveTo( String theTabName , ControlWindow theControlWindow ) {
moveTo( null , theControlWindow.getTab( theTabName ) , theControlWindow );
return me;
}
public final T moveTo( ControlWindow theControlWindow , String theTabName ) {
moveTo( null , theControlWindow.getTab( theTabName ) , theControlWindow );
return me;
}
public final T moveTo( Tab theTab , ControlWindow theControlWindow ) {
moveTo( null , theTab , theControlWindow );
return me;
}
public final T setTab( String theName ) {
setParent( cp5.getTab( theName ) );
return me;
}
public final T setTab( ControlWindow theWindow , String theName ) {
setParent( cp5.getTab( theWindow , theName ) );
return me;
}
public final T setTab( Tab theTab ) {
setParent( theTab );
return me;
}
public Tab getTab( ) {
if ( this instanceof Tab ) {
return ( Tab ) this;
}
if ( _myParent instanceof Tab ) {
return ( Tab ) _myParent;
}
return _myParent.getTab( );
}
protected void updateFont( ControlFont theControlFont ) {
_myLabel.updateFont( theControlFont );
if ( _myValueLabel != null ) {
_myValueLabel.updateFont( theControlFont );
}
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
if ( controllers.get( i ) instanceof Controller< ? > ) {
( ( Controller< ? > ) controllers.get( i ) ).updateFont( theControlFont );
} else {
( ( ControllerGroup< ? > ) controllers.get( i ) ).updateFont( theControlFont );
}
}
}
@ControlP5.Invisible public float[] getAbsolutePosition( ) {
return new float[] { x( absolutePosition ) , y( absolutePosition ) };
}
@ControlP5.Invisible public T setAbsolutePosition( float[] thePos ) {
set( absolutePosition , x( thePos ) , y( thePos ) );
return me;
}
public float[] getPosition( ) {
return new float[] { x( position ) , y( position ) };
}
public T setPosition( float theX , float theY ) {
set( position , ( int ) theX , ( int ) theY );
set( positionBuffer , x( position ) , y( position ) );
updateAbsolutePosition( );
return me;
}
public T setPosition( float[] thePosition ) {
setPosition( x( thePosition ) , y( thePosition ) );
return me;
}
public T updateAbsolutePosition( ) {
set( absolutePosition , x( position ) , y( position ) );
set( absolutePosition , x( absolutePosition ) + x( _myParent.getAbsolutePosition( ) ) , y( absolutePosition ) + y( _myParent.getAbsolutePosition( ) ) );
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
controllers.get( i ).updateAbsolutePosition( );
}
return me;
}
@ControlP5.Invisible public void continuousUpdateEvents( ) {
if ( controllers.size( ) <= 0 ) {
return;
}
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
controllers.get( i ).continuousUpdateEvents( );
}
}
public T update( ) {
if ( controllers.size( ) <= 0 ) {
return me;
}
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
if ( controllers.get( i ).isUpdate( ) ) {
controllers.get( i ).update( );
}
}
return me;
}
/**
* enables or disables the update function of a controller.
*/
@Override public T setUpdate( boolean theFlag ) {
isUpdate = theFlag;
for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
controllers.get( i ).setUpdate( theFlag );
}
return me;
}
/**
* checks the update status of a controller.
*/
public boolean isUpdate( ) {
return isUpdate;
}
@ControlP5.Invisible public T updateEvents( ) {
if ( isOpen ) {
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
controllers.get( i ).updateEvents( );
}
}
if ( isVisible ) {
if ( ( isMousePressed == cp5.getWindow( ).mouselock ) ) {
if ( isMousePressed && cp5.isAltDown( ) && isMoveable ) {
if ( !cp5.isMoveable ) {
set( positionBuffer , x( positionBuffer ) + cp5.getWindow( ).mouseX - cp5.getWindow( ).pmouseX , y( positionBuffer ) + cp5.getWindow( ).mouseY - cp5.getWindow( ).pmouseY );
if ( cp5.isShiftDown( ) ) {
set( position , ( ( ( int ) ( x( positionBuffer ) ) / 10 ) * 10 ) , ( ( ( int ) ( y( positionBuffer ) ) / 10 ) * 10 ) );
} else {
set( position , x( positionBuffer ) , y( positionBuffer ) );
}
updateAbsolutePosition( );
}
} else {
if ( isInside ) {
setMouseOver( true );
}
if ( inside( ) ) {
if ( !isInside ) {
isInside = true;
onEnter( );
setMouseOver( true );
}
} else {
if ( isInside && !isMousePressed ) {
onLeave( );
isInside = false;
setMouseOver( false );
}
}
}
}
}
return me;
}
@ControlP5.Invisible public T updateInternalEvents( PApplet theApplet ) {
return me;
}
public boolean isMouseOver( ) {
mouseover = isInside || isInsideGroup || !isBarVisible;
return mouseover;
}
public T setMouseOver( boolean theFlag ) {
mouseover = isBarVisible && theFlag;
if ( !mouseover ) {
isInside = false;
isInsideGroup = false;
cp5.getWindow( ).removeMouseOverFor( this );
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
controllers.get( i ).setMouseOver( false );
}
} else {
// TODO since inside can be either isInside or isInsideGroup, there are 2 options here,
// which i am not sure how to handle them yet.
cp5.getWindow( ).setMouseOverController( this );
}
return me;
}
@ControlP5.Invisible public final void draw( PGraphics theGraphics ) {
if ( isVisible ) {
theGraphics.pushMatrix( );
theGraphics.translate( x( position ) , y( position ) );
preDraw( theGraphics );
drawControllers( cp5.papplet , theGraphics );
postDraw( theGraphics );
if ( _myValueLabel != null ) {
_myValueLabel.draw( theGraphics , 2 , 2 , this );
}
theGraphics.popMatrix( );
}
}
protected void drawControllers( PApplet theApplet , PGraphics theGraphics ) {
if ( isOpen ) {
for ( Canvas cc : _myCanvas ) {
if ( cc.mode( ) == Canvas.PRE ) {
cc.draw( theGraphics );
}
}
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
if ( ci.isVisible( ) ) {
ci.updateInternalEvents( theApplet );
ci.draw( theGraphics );
}
}
for ( CDrawable cd : controllers.getDrawables( ) ) {
cd.draw( theGraphics );
}
for ( Canvas cc : _myCanvas ) {
if ( cc.mode( ) == Canvas.POST ) {
cc.draw( theGraphics );
}
}
}
}
protected void preDraw( PGraphics theGraphics ) {
}
protected void postDraw( PGraphics theGraphics ) {
}
/**
* Adds a canvas to a controllerGroup such as a tab or group. Use processing's draw methods to
* add visual content.
*/
public Canvas addCanvas( Canvas theCanvas ) {
_myCanvas.add( theCanvas );
// TODO theCanvas.setup( cp5.papplet );
return theCanvas;
}
/**
* Removes a canvas from a controller group.
*/
public T removeCanvas( Canvas theCanvas ) {
_myCanvas.remove( theCanvas );
return me;
}
/**
* Adds a controller to the group, but use Controller.setGroup() instead.
*/
public T add( ControllerInterface< ? > theElement ) {
controllers.add( theElement );
return me;
}
@Override public T bringToFront( ) {
return bringToFront( this );
}
@Override public T bringToFront( ControllerInterface< ? > theController ) {
if ( _myParent instanceof Tab ) {
moveTo( ( Tab ) _myParent );
} else {
_myParent.bringToFront( theController );
}
if ( theController != this ) {
if ( controllers.get( ).contains( theController ) ) {
controllers.remove( theController );
controllers.add( theController );
}
}
return me;
}
/**
* Removes a controller from the group, but use Controller.setGroup() instead.
*/
public T remove( ControllerInterface< ? > theElement ) {
if ( theElement != null ) {
theElement.setMouseOver( false );
}
controllers.remove( theElement );
return me;
}
@ControlP5.Invisible public T addDrawable( CDrawable theElement ) {
controllers.addDrawable( theElement );
return me;
}
public T remove( CDrawable theElement ) {
controllers.removeDrawable( theElement );
return me;
}
/**
* removes the group from controlP5.
*/
public void remove( ) {
cp5.getWindow( ).removeMouseOverFor( this );
if ( _myParent != null ) {
_myParent.remove( this );
}
if ( cp5 != null ) {
cp5.remove( this );
}
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
controllers.get( i ).remove( );
}
controllers.clear( );
controllers.clearDrawable( );
controllers = new ControllerList( );
if ( this instanceof Tab ) {
cp5.getWindow( ).removeTab( ( Tab ) this );
}
}
public String getName( ) {
return _myName;
}
public String getAddress( ) {
return _myAddress;
}
@Override public T setAddress( String theAddress ) {
if ( _myAddress.length( ) == 0 ) {
_myAddress = theAddress;
}
return me;
}
public ControlWindow getWindow( ) {
return cp5.getWindow( );
}
@ControlP5.Invisible public void keyEvent( KeyEvent theEvent ) {
//for ( int i = 0 ; i < controllers.size( ) ; i++ ) {
// ( ( ControllerInterface< ? > ) controllers.get( i ) ).keyEvent( theEvent );
//}
if ( activeController != null ){
activeController.keyEvent(theEvent);
}
}
public ControllerGroup<T> setActiveController(Controller<?> theController){
activeController = theController;
return this;
}
public Controller<?> getActiveController(){
return activeController;
}
public boolean setMousePressed( boolean theStatus ) {
if ( !isVisible ) {
return false;
}
for ( int i = controllers.size( ) - 1 ; i >= 0 ; i-- ) {
if ( controllers.get( i ).setMousePressed( theStatus ) ) {
return true;
}
}
if (theStatus) {
if ( isInside ) {
isMousePressed = true;
mousePressed( );
return true;
}
} else {
if (isMousePressed) {
isMousePressed = false;
mouseReleased( );
}
}
return false;
}
protected void mousePressed( ) {
}
protected void mouseReleased( ) {
}
protected void onEnter( ) {
}
protected void onLeave( ) {
}
protected void onScroll( int theAmount ) {
}
public T setId( int theId ) {
_myId = theId;
return me;
}
public int getId( ) {
return _myId;
}
public T setColor( CColor theColor ) {
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColor( theColor );
}
return me;
}
public T setColorActive( int theColor ) {
color.setActive( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorActive( theColor );
}
return me;
}
public T setColorForeground( int theColor ) {
color.setForeground( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorForeground( theColor );
}
return me;
}
public T setColorBackground( int theColor ) {
color.setBackground( theColor );
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorBackground( theColor );
}
return me;
}
public T setColorLabel( int theColor ) {
color.setCaptionLabel( theColor );
if ( _myLabel != null ) {
_myLabel.setColor( color.getCaptionLabel( ) );
}
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorLabel( theColor );
}
return me;
}
public T setColorValue( int theColor ) {
color.setValueLabel( theColor );
if ( _myValueLabel != null ) {
_myValueLabel.setColor( color.getValueLabel( ) );
}
for ( ControllerInterface< ? > ci : controllers.get( ) ) {
ci.setColorValue( theColor );
}
return me;
}
public T setLabel( String theLabel ) {
_myLabel.set( theLabel );
return me;
}
public boolean isVisible( ) {
if ( _myParent != null && _myParent != this ) {
if (!getParent().isVisible()) {
return false;
}
}
return isVisible;
}
public T setVisible( boolean theFlag ) {
isVisible = theFlag;
return me;
}
public T hide( ) {
isVisible = false;
return me;
}
public T show( ) {
isVisible = true;
return me;
}
/**
* set the moveable status of the group, when false, the group can't be moved.
*/
public T setMoveable( boolean theFlag ) {
isMoveable = theFlag;
return me;
}
public boolean isMoveable( ) {
return isMoveable;
}
public T setOpen( boolean theFlag ) {
isOpen = theFlag;
return me;
}
public boolean isOpen( ) {
return isOpen;
}
public T open( ) {
setOpen( true );
return me;
}
public T close( ) {
setOpen( false );
return me;
}
/**
* TODO redesign or deprecate remove the close button.
*/
@ControlP5.Invisible public T removeCloseButton( ) {
if ( _myCloseButton == null ) {
_myCloseButton.remove( );
}
_myCloseButton = null;
return me;
}
public T setTitle( String theTitle ) {
getCaptionLabel( ).set( theTitle );
return me;
}
public T hideBar( ) {
isBarVisible = false;
return me;
}
public T showBar( ) {
isBarVisible = true;
return me;
}
public boolean isBarVisible( ) {
return isBarVisible;
}
public T hideArrow( ) {
isArrowVisible = false;
return me;
}
public T showArrow( ) {
isArrowVisible = true;
return me;
}
/**
* TODO redesign or deprecate add a close button to the controlbar of this controlGroup.
*/
@ControlP5.Invisible public T addCloseButton( ) {
if ( _myCloseButton == null ) {
_myCloseButton = new Button( cp5 , this , getName( ) + "close" , 1 , _myWidth + 1 , -10 , 12 , 9 );
_myCloseButton.setCaptionLabel( "X" );
_myCloseButton.addListener( this );
}
return me;
}
@ControlP5.Invisible public int getPickingColor( ) {
return _myPickingColor;
}
public CColor getColor( ) {
return color;
}
public T setValue( float theValue ) {
_myValue = theValue;
return me;
}
public float getValue( ) {
return _myValue;
}
public String getStringValue( ) {
return _myStringValue;
}
public T setStringValue( String theValue ) {
_myStringValue = theValue;
return me;
}
public float[] getArrayValue( ) {
return _myArrayValue;
}
public float getArrayValue( int theIndex ) {
if ( theIndex >= 0 && theIndex < _myArrayValue.length ) {
return _myArrayValue[ theIndex ];
} else {
return Float.NaN;
}
}
public T setArrayValue( int theIndex , float theValue ) {
if ( theIndex >= 0 && theIndex < _myArrayValue.length ) {
_myArrayValue[ theIndex ] = theValue;
}
return me;
}
public T setArrayValue( float[] theArray ) {
_myArrayValue = theArray;
return me;
}
public Controller< ? > getController( String theController ) {
return cp5.getController( theController );
}
public T setCaptionLabel( String theValue ) {
getCaptionLabel( ).set( theValue );
return me;
}
public Label getCaptionLabel( ) {
return _myLabel;
}
public Label getValueLabel( ) {
return _myValueLabel;
}
public T enableCollapse( ) {
isCollapse = true;
return me;
}
public T disableCollapse( ) {
isCollapse = false;
return me;
}
public boolean isCollapse( ) {
return isCollapse;
}
public int getWidth( ) {
return _myWidth;
}
public int getHeight( ) {
return _myHeight;
}
public T setWidth( int theWidth ) {
_myWidth = theWidth;
return me;
}
public T setHeight( int theHeight ) {
_myHeight = theHeight;
return me;
}
public T setSize( int theWidth , int theHeight ) {
setWidth( theWidth );
// setHeight(theHeight) will set the Height of the bar therefore will not be used here.
return me;
}
protected boolean inside( ) {
return ( cp5.getWindow( ).mouseX > x( position ) + x( _myParent.absolutePosition ) && cp5.getWindow( ).mouseX < x( position ) + x( _myParent.absolutePosition ) + _myWidth
&& cp5.getWindow( ).mouseY > y( position ) + y( _myParent.absolutePosition ) - _myHeight && cp5.getWindow( ).mouseY < y( position ) + y( _myParent.absolutePosition ) );
}
public ControllerProperty getProperty( String thePropertyName ) {
return cp5.getProperties( ).getProperty( this , thePropertyName );
}
public ControllerProperty getProperty( String theSetter , String theGetter ) {
return cp5.getProperties( ).getProperty( this , theSetter , theGetter );
}
public T registerProperty( String thePropertyName ) {
cp5.getProperties( ).register( this , thePropertyName );
return me;
}
public T registerProperty( String theSetter , String theGetter ) {
cp5.getProperties( ).register( this , theSetter , theGetter );
return me;
}
public T removeProperty( String thePropertyName ) {
cp5.getProperties( ).remove( this , thePropertyName );
return me;
}
public T removeProperty( String theSetter , String theGetter ) {
cp5.getProperties( ).remove( this , theSetter , theGetter );
return me;
}
public void controlEvent( ControlEvent theEvent ) {
}
public T addListener( final ControlListener theListener ) {
_myControlListener.add( theListener );
return me;
}
public T removeListener( final ControlListener theListener ) {
_myControlListener.remove( theListener );
return me;
}
public int listenerSize( ) {
return _myControlListener.size( );
}
@Override public String toString( ) {
return getName( ) + " [" + getClass( ).getSimpleName( ) + "]";
}
public String getInfo( ) {
return "type:\tControllerGroup" + "\nname:\t" + _myName + "\n" + "label:\t" + _myLabel.getText( ) + "\n" + "id:\t" + _myId + "\n" + "value:\t" + _myValue + "\n" + "arrayvalue:\t" + CP.arrayToString( _myArrayValue ) + "\n" + "position:\t"
+ position + "\n" + "absolute:\t" + absolutePosition + "\n" + "width:\t" + getWidth( ) + "\n" + "height:\t" + getHeight( ) + "\n" + "color:\t" + getColor( ) + "\n" + "visible:\t" + isVisible + "\n" + "moveable:\t" + isMoveable + "\n";
}
/**
* convenience method to fill a float array in favor of theArray[0] = 1.2; etc.
* takes a float array and fills it (starting from index 0) with arguments starting from index 1.
*/
static public float[] set( float[] theArray , float ... theValues ) {
if ( theValues.length > theArray.length ) {
System.arraycopy( theValues , 0 , theArray , 0 , theArray.length );
} else {
System.arraycopy( theValues , 0 , theArray , 0 , theValues.length );
}
return theArray;
}
/**
* returns the first element of the float array.
*/
static public float x( float[] theArray ) {
if ( theArray.length > 0 ) {
return theArray[ 0 ];
}
return 0;
}
/**
* returns the second element of the float array.
*/
static public float y( float[] theArray ) {
if ( theArray.length > 1 ) {
return theArray[ 1 ];
}
return 0;
}
@Override public T setFont( PFont thePFont ) {
getValueLabel( ).setFont( thePFont );
getCaptionLabel( ).setFont( thePFont );
return me;
}
@Override public T setFont( ControlFont theFont ) {
getValueLabel( ).setFont( theFont );
getCaptionLabel( ).setFont( theFont );
return me;
}
}

View File

@ -0,0 +1,185 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
import processing.event.KeyEvent;
/**
*
* The ControllerInterface is inherited by all ControllerGroup and Controller classes.
*
*/
public interface ControllerInterface< T > {
@ControlP5.Invisible
void init( );
int getWidth( );
int getHeight( );
T setValue( float theValue );
float getValue( );
T setStringValue( String theValue );
String getStringValue( );
float[] getArrayValue( );
float getArrayValue( int theIndex );
T setArrayValue( int theIndex , float theValue );
T setArrayValue( float[] theArray );
int getId( );
float[] getPosition( );
@ControlP5.Invisible
T setPosition(float theX , float theY );
@ControlP5.Invisible
T setPosition(float[] thePosition );
float[] getAbsolutePosition( );
T setAbsolutePosition( float[] thePosition );
T updateAbsolutePosition( );
ControllerInterface< ? > getParent( );
T update( );
T setUpdate( boolean theFlag );
T bringToFront( );
T bringToFront( ControllerInterface< ? > theController );
boolean isUpdate( );
@ControlP5.Invisible
T updateEvents( );
@ControlP5.Invisible
void continuousUpdateEvents( );
/**
* a method for putting input events like e.g. mouse or keyboard events and queries. this has
* been taken out of the draw method for better overwriting capability.
*
*
*/
@ControlP5.Invisible
T updateInternalEvents(PApplet theApplet );
@ControlP5.Invisible
void draw(PGraphics theGraphics );
T add( ControllerInterface< ? > theElement );
T remove( ControllerInterface< ? > theElement );
void remove( );
String getName( );
String getAddress( );
ControlWindow getWindow( );
Tab getTab( );
boolean setMousePressed( boolean theStatus );
@ControlP5.Invisible
void keyEvent(KeyEvent theEvent );
@ControlP5.Invisible
T setAddress(String theAddress );
T setId( int theValue );
T setLabel( String theString );
T setColorActive( int theColor );
T setColorForeground( int theColor );
T setColorBackground( int theColor );
T setColorLabel( int theColor );
T setColorValue( int theColor );
T setColor( CColor theColor );
CColor getColor( );
T show( );
T hide( );
boolean isVisible( );
T moveTo( ControllerGroup< ? > theGroup , Tab theTab , ControlWindow theWindow );
T moveTo( ControllerGroup< ? > theGroup );
@ControlP5.Invisible
int getPickingColor( );
ControllerProperty getProperty( String thePropertyName );
ControllerProperty getProperty( String theSetter , String theGetter );
T registerProperty( String thePropertyName );
T registerProperty( String theSetter , String theGetter );
T removeProperty( String thePropertyName );
T removeProperty( String theSetter , String theGetter );
boolean isMouseOver( );
T setMouseOver( boolean theFlag );
T setFont( PFont theFont );
T setFont( ControlFont theFont );
T addListener( ControlListener theListener );
T setCaptionLabel( String theValue );
}

180
controlP5/ControllerLayout.java Executable file
View File

@ -0,0 +1,180 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.logging.Logger;
class ControllerLayout {
private final ControlP5 cp5;
public static final Logger logger = Logger.getLogger( ControllerLayout.class.getName( ) );
static {
Map< Class< ? > , Class< ? >> datatypes = new HashMap< Class< ? > , Class< ? >>( );
datatypes.put( Integer.class , int.class );
datatypes.put( Float.class , float.class );
datatypes.put( Boolean.class , boolean.class );
datatypes.put( Character.class , char.class );
datatypes.put( Long.class , long.class );
datatypes.put( Double.class , double.class );
datatypes.put( Byte.class , byte.class );
datatypes.put( CColor.class , CColor.class );
}
ControllerLayout( ControlP5 theControlP5 ) {
cp5 = theControlP5;
}
public void save( String theLayoutPath ) {
theLayoutPath = cp5.checkPropertiesPath( theLayoutPath );
Class< ? >[] classes = new Class< ? >[] { RadioButton.class , ListBox.class , ColorPicker.class , DropdownList.class };
HashSet< ControllerLayoutElement > layoutelements = new HashSet< ControllerLayoutElement >( );
for ( ControllerInterface< ? > c : cp5.getList( ) ) {
if ( !Arrays.asList( classes ).contains( c.getParent( ).getClass( ) ) ) {
layoutelements.add( new ControllerLayoutElement( c ) );
System.out.print( c.getAddress( ) );
System.out.print( " (" + c.getName( ) + ") " );
System.out.print( "\tpos:" + Controller.x( c.getPosition( ) ) + "," + Controller.y( c.getPosition( ) ) );
System.out.print( "\tdim:" + c.getWidth( ) + "," + c.getHeight( ) );
System.out.print( "\tparent:" + c.getParent( ) );
System.out.println( "\tclass:" + c.getClass( ).getSimpleName( ) );
}
}
try {
FileOutputStream fos = new FileOutputStream( theLayoutPath );
ObjectOutputStream oos = new ObjectOutputStream( fos );
logger.info( "Saving layout-items to " + theLayoutPath );
oos.writeInt( layoutelements.size( ) );
for ( ControllerLayoutElement ce : layoutelements ) {
oos.writeObject( ce );
}
oos.flush( );
oos.close( );
fos.close( );
} catch ( Exception e ) {
logger.warning( "Exception during serialization: " + e );
}
}
protected boolean isClassAssignableFromSuperclass( Class< ? > theClass , Class< ? > theSuper ) {
Class< ? > _mySuper = theClass.getSuperclass( );
while ( _mySuper.getSuperclass( ) != null ) {
if ( _mySuper.isAssignableFrom( theSuper ) ) {
return true;
}
_mySuper = _mySuper.getSuperclass( );
}
return false;
}
public void load( String theLayoutPath ) {
theLayoutPath = cp5.checkPropertiesPath( theLayoutPath );
ArrayList< ControllerLayoutElement > list = new ArrayList< ControllerLayoutElement >( );
try {
FileInputStream fis = new FileInputStream( theLayoutPath );
ObjectInputStream ois = new ObjectInputStream( fis );
int size = ois.readInt( );
logger.info( "loading " + size + " layout-items." + fis.getFD( ) );
for ( int i = 0 ; i < size ; i++ ) {
try {
ControllerLayoutElement ce = ( ControllerLayoutElement ) ois.readObject( );
list.add( ce );
} catch ( Exception e ) {
logger.warning( "skipping a property, " + e );
}
}
ois.close( );
} catch ( Exception e ) {
logger.warning( "Exception during deserialization: " + e );
}
for ( ControllerLayoutElement ce : list ) {
/* ControllerInterface ci = cp5.getController(ce.getName());
* if (ci == null) {
* try {
* if (isClassAssignableFromSuperclass(ce.getType(), ControllerGroup.class)) {
* ControllerGroup c = (ControllerGroup) cp5.addGroup(null, "", ce.getName(), ce.getType(), ce.getX(), ce.getY(), ce.getWidth(),
* ce.getHeight());
* c.setWidth(ce.getWidth());
* c.setHeight(ce.getHeight());
* if (c instanceof ListBox) {
* System.out.println("found listbox or dropdownlist!");
* ((ListBox) c).setHeight(200);
* ((ListBox) c).setBarHeight(ce.getHeight());
* }
* } else {
* Controller c = (Controller) cp5.addController(ce.getName(), ce.getType(), ce.getX(), ce.getY());
* c.setWidth(ce.getWidth());
* c.setHeight(ce.getHeight());
* }
* } catch (Exception e) {
*
* }
* }
* ci = cp5.get(ce.getName());
* if (ci != null) {
* ci.setAddress(ce.getAddress());
* System.out.println("name:" + ce.getName() + "\tparent:" + ce.getParent() + "\telement:" + ci + "\ttype:" + ce.getType() + "\t" +
* ce.getHeight());
* } else {
* System.out.println("could not create " + ce.getName() + "," + ce.getType());
* }
* // if(cp5.get(ce.getName()) instanceof DropdownList) {
* // DropdownList dl = (DropdownList)(cp5.get(ce.getName()));
* // dl.setHeight(200);
* // } */
}
for ( ControllerLayoutElement ce : list ) {
/* ControllerInterface ci = cp5.get(ce.getName());
* if (ci != null) {
* ControllerGroup g = cp5.getGroup(ce.getParent());
* if (g == null) {
* g = cp5.getTab(ce.getParent());
* }
* if (g != null) {
* ci.moveTo(g);
* }
* } */
}
}
}

View File

@ -0,0 +1,52 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
class ControllerLayoutElement implements Serializable, Cloneable {
private static final long serialVersionUID = -5006855922546529005L;
private final transient ControllerInterface<?> controller;
private final Class<?> type;
private final Map<String,Object> values;
ControllerLayoutElement(ControllerInterface<?> theController) {
controller = theController;
type = theController.getClass();
values = new HashMap<String,Object>();
}
private void cascade(Object theObject) {
}
}

97
controlP5/ControllerList.java Executable file
View File

@ -0,0 +1,97 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.List;
import java.util.Vector;
/**
* Stores objects of type ControllerInterface and CDrawable, mainly for internal use.
*/
public class ControllerList {
protected List< ControllerInterface< ? >> controllers;
protected List< CDrawable > drawables;
public ControllerList( ) {
controllers = new Vector< ControllerInterface< ? >>( );
drawables = new Vector< CDrawable >( );
}
public void add( ControllerInterface< ? > theController ) {
if (!controllers.contains(theController)) {
controllers.add( theController );
}
}
protected void remove( ControllerInterface< ? > theController ) {
controllers.remove( theController );
}
protected void addDrawable( CDrawable theController ) {
if (!drawables.contains(theController)) {
drawables.add( theController );
}
}
protected void removeDrawable( CDrawable theController ) {
drawables.remove( theController );
}
public ControllerInterface< ? > get( int theIndex ) {
return controllers.get( theIndex );
}
public List< ControllerInterface< ? >> get( ) {
return controllers;
}
public CDrawable getDrawable( int theIndex ) {
return drawables.get( theIndex );
}
public List< CDrawable > getDrawables( ) {
return drawables;
}
public int sizeDrawable( ) {
return drawables.size( );
}
public int size( ) {
return controllers.size( );
}
protected void clear( ) {
controllers.clear( );
}
protected void clearDrawable( ) {
drawables.clear( );
}
}

273
controlP5/ControllerPlug.java Executable file
View File

@ -0,0 +1,273 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import java.security.AccessControlException;
/**
* The ControllerPlug is used to do all the reflection procedures to link a controller to a variable
* or function inside your main application.
*
* @example use/ControlP5plugTo
*/
public class ControllerPlug {
private Object _myObject;
private String _myName;
private Method _myMethod;
private Field _myField;
private int _myType = ControlP5Constants.INVALID;
private Class< ? > _myParameterClass;
private int _myParameterType = -1;
private Object _myValue = null;
private Class< ? >[] _myAcceptClassList;
private Class< ? > _myEventMethodParameter = ControlEvent.class;
public ControllerPlug( final Object theObject , final String theName , final int theType , final int theParameterType , Class< ? >[] theAcceptClassList ) {
set( theObject , theName , theType , theParameterType , theAcceptClassList );
}
ControllerPlug( Class< ? > param , final Object theObject , final String theName , final int theType , final int theParameterType ) {
setEventMethodParameter( param );
set( theObject , theName , theType , theParameterType , null );
}
void setEventMethodParameter( Class< ? > theClass ) {
_myEventMethodParameter = theClass;
}
protected void set( Object theObject ) {
set( theObject , getName( ) , getType( ) , getParameterType( ) , getAcceptClassList( ) );
}
public void set( final Object theObject , final String theName , final int theType , final int theParameterType , final Class< ? >[] theAcceptClassList ) {
_myObject = theObject;
_myName = theName;
_myType = theType;
_myParameterType = theParameterType;
_myAcceptClassList = theAcceptClassList;
Class< ? > myClass = theObject.getClass( );
/* check for methods */
if ( _myType == ControlP5Constants.METHOD ) {
try {
Method[] myMethods = myClass.getMethods( );
for ( int i = 0 ; i < myMethods.length ; i++ ) {
if ( ( myMethods[ i ].getName( ) ).equals( theName ) ) {
if ( myMethods[ i ].getParameterTypes( ).length == 1 ) {
for ( int j = 0 ; j < _myAcceptClassList.length ; j++ ) {
if ( myMethods[ i ].getParameterTypes( )[ 0 ] == _myAcceptClassList[ j ] ) {
_myParameterClass = myMethods[ i ].getParameterTypes( )[ 0 ];
break;
}
}
} else if ( myMethods[ i ].getParameterTypes( ).length == 0 ) {
_myParameterClass = null;
break;
}
break;
}
}
Class< ? >[] myArgs = ( _myParameterClass == null ) ? new Class[] { } : new Class[] { _myParameterClass };
_myMethod = myClass.getMethod( _myName , myArgs );
_myMethod.setAccessible( true );
} catch ( SecurityException e ) {
printSecurityWarning( e );
} catch ( NoSuchMethodException e ) {
if ( _myParameterClass != CallbackEvent.class ) {
ControlP5.logger( ).warning( " plug() failed. If function " + theName + " does exist, make it public. " + e );
}
}
/* check for controlEvent */
} else if ( _myType == ControlP5Constants.EVENT ) {
try {
_myMethod = _myObject.getClass( ).getMethod( _myName , _myEventMethodParameter);
_myMethod.setAccessible( true );
_myParameterClass = _myEventMethodParameter;
} catch ( SecurityException e ) {
printSecurityWarning( e );
} catch ( NoSuchMethodException e ) {
if ( _myEventMethodParameter != CallbackEvent.class ) {
ControlP5.logger( ).warning( " plug() failed " + _myParameterClass + ". If function " + theName + " does exist, make it public. " + e );
}
}
/* check for fields */
} else if ( _myType == ControlP5Constants.FIELD ) {
Field[] myFields = ControlBroadcaster.getFieldsFor( myClass );
for ( int i = 0 ; i < myFields.length ; i++ ) {
if ( myFields[ i ].getName( ).equals( _myName ) ) {
_myParameterClass = myFields[ i ].getType( );
}
}
if ( _myParameterClass != null ) {
/**
* note. when running in applet mode. for some reason setAccessible(true) works for
* methods but not for fields. theAccessControlException is thrown. therefore, make
* fields in your code public.
*/
try {
_myField = myClass.getDeclaredField( _myName );
try {
_myField.setAccessible( true );
} catch ( java.security.AccessControlException e ) {
printSecurityWarning( e );
}
try {
_myValue = ( _myField.get( theObject ) );
} catch ( Exception ex ) {
printSecurityWarning( ex );
}
} catch ( NoSuchFieldException e ) {
ControlP5.logger( ).warning( e.toString( ) );
}
}
}
}
private void printSecurityWarning( Exception e ) {
// AccessControlException required for applets.
if ( e.getClass( ).equals( AccessControlException.class ) ) {
ControlP5.isApplet = true;
ControlP5.logger( ).warning( "You are probably running in applet mode.\n" + "make sure fields and methods in your code are public.\n" + e );
}
}
protected Object getValue( ) {
return _myValue;
}
protected Object getObject( ) {
return _myObject;
}
protected String getName( ) {
return _myName;
}
protected int getType( ) {
return _myType;
}
protected int getParameterType( ) {
return _myParameterType;
}
protected Class< ? >[] getAcceptClassList( ) {
return _myAcceptClassList;
}
protected Class< ? > getClassType( ) {
return _myParameterClass;
}
protected boolean checkType( int theType ) {
return _myType == theType;
}
protected boolean checkName( String theName ) {
return ( _myName.equals( theName ) );
}
private Object get( float theValue ) {
if ( _myParameterClass == float.class ) {
return new Float( theValue );
} else if ( _myParameterClass == int.class ) {
return Integer.valueOf((int) theValue);
} else if ( _myParameterClass == boolean.class ) {
return ( theValue > 0.5 ) ? Boolean.TRUE : Boolean.FALSE;
} else {
return null;
}
}
protected Object getFieldParameter( float theValue ) {
return get( theValue );
}
protected Object[] getMethodParameter( float theValue ) {
return new Object[] { get( theValue ) };
}
protected Method getMethod( ) {
return _myMethod;
}
protected Field getField( ) {
return _myField;
}
static public boolean checkPlug( Object theObject , String thePlugName , Class< ? >[] theArgs ) {
try {
theObject.getClass( ).getMethod( thePlugName , theArgs );
return true;
} catch ( Exception e ) {
return false;
}
}
@Deprecated
protected Class< ? > classType( ) {
return _myParameterClass;
}
@Deprecated
protected Object value( ) {
return _myValue;
}
@Deprecated
protected Object object( ) {
return _myObject;
}
@Deprecated
protected String name( ) {
return _myName;
}
@Deprecated
protected int type( ) {
return _myType;
}
@Deprecated
protected int parameterType( ) {
return _myParameterType;
}
@Deprecated
protected Class< ? >[] acceptClassList( ) {
return _myAcceptClassList;
}
}

View File

@ -0,0 +1,921 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StringReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import processing.core.PApplet;
import processing.data.JSONArray;
import processing.data.JSONObject;
/**
* Values of controllers can be stored inside properties files which can be saved to file or memory.
*
* @example controllers/ControlP5properties
*/
public class ControllerProperties {
public final static int OPEN = 0;
public final static int CLOSE = 1;
public static String defaultName = "controlP5";
PropertiesStorageFormat format;
/**
* all ControllerProperties will be stored inside Map allProperties. ControllerProperties need to be unique or will
* otherwise be overwritten.
*
* A hashSet containing names of PropertiesSets is assigned to each ControllerProperty. HashSets are used instead of
* ArrayList to only allow unique elements.
*/
private final Map< ControllerProperty , HashSet< String >> allProperties;
/**
* A set of unique property-set names.
*/
private final Set< String > allSets;
final ControlP5 controlP5;
private final String _myDefaultSetName = "default";
public static final Logger logger = Logger.getLogger( ControllerProperties.class.getName( ) );
private final Map< String , Set< ControllerProperty >> _mySnapshots;
public ControllerProperties( ControlP5 theControlP5 ) {
controlP5 = theControlP5;
// setFormat( new SerializedFormat( ) );
setFormat( new JSONFormat( ) );
allProperties = new HashMap< ControllerProperty , HashSet< String >>( );
allSets = new HashSet< String >( );
addSet( _myDefaultSetName );
_mySnapshots = new LinkedHashMap< String , Set< ControllerProperty >>( );
}
public Map< ControllerProperty , HashSet< String >> get( ) {
return allProperties;
}
/**
* adds a property based on names of setter and getter methods of a controller.
*
* @param thePropertySetter
* @param thePropertyGetter
*/
public ControllerProperty register( ControllerInterface< ? > theController , String thePropertySetter , String thePropertyGetter ) {
ControllerProperty p = new ControllerProperty( theController , thePropertySetter , thePropertyGetter );
if ( !allProperties.containsKey( p ) ) {
// register a new property with the main properties container
allProperties.put( p , new HashSet< String >( ) );
// register the property wit the default properties set
allProperties.get( p ).add( _myDefaultSetName );
}
return p;
}
/**
* registering a property with only one parameter assumes that there is a setter and getter function present for the
* Controller. register("value") for example would create a property reference to setValue and getValue. Notice that
* the first letter of value is being capitalized.
*
* @param theProperty
* @return
*/
public ControllerProperties register( ControllerInterface< ? > theController , String theProperty ) {
theProperty = Character.toUpperCase( theProperty.charAt( 0 ) ) + theProperty.substring( 1 );
register( theController , "set" + theProperty , "get" + theProperty );
return this;
}
public ControllerProperties remove( ControllerInterface< ? > theController , String theSetter , String theGetter ) {
ControllerProperty cp = new ControllerProperty( theController , theSetter , theGetter );
allProperties.remove( cp );
return this;
}
public ControllerProperties remove( ControllerInterface< ? > theController ) {
ArrayList< ControllerProperty > list = new ArrayList< ControllerProperty >( allProperties.keySet( ) );
for ( ControllerProperty cp : list ) {
if ( cp.getController( ).equals( theController ) ) {
allProperties.remove( cp );
}
}
return this;
}
public ControllerProperties remove( ControllerInterface< ? > theController , String theProperty ) {
return remove( theController , "set" + theProperty , "get" + theProperty );
}
public List< ControllerProperty > get( ControllerInterface< ? > theController ) {
List< ControllerProperty > props = new ArrayList< ControllerProperty >( );
List< ControllerProperty > list = new ArrayList< ControllerProperty >( allProperties.keySet( ) );
for ( ControllerProperty cp : list ) {
if ( cp.getController( ).equals( theController ) ) {
props.add( cp );
}
}
return props;
}
public ControllerProperty getProperty( ControllerInterface< ? > theController , String theSetter , String theGetter ) {
ControllerProperty cp = new ControllerProperty( theController , theSetter , theGetter );
Iterator< ControllerProperty > iter = allProperties.keySet( ).iterator( );
while ( iter.hasNext( ) ) {
ControllerProperty p = iter.next( );
if ( p.equals( cp ) ) {
return p;
}
}
// in case the property has not been registered before, it will be
// registered here automatically - you don't need to call
// Controller.registerProperty() but can use Controller.getProperty()
// instead.
return register( theController , theSetter , theGetter );
}
public ControllerProperty getProperty( ControllerInterface< ? > theController , String theProperty ) {
theProperty = Character.toUpperCase( theProperty.charAt( 0 ) ) + theProperty.substring( 1 );
return getProperty( theController , "set" + theProperty , "get" + theProperty );
}
public HashSet< ControllerProperty > getPropertySet( ControllerInterface< ? > theController ) {
HashSet< ControllerProperty > set = new HashSet< ControllerProperty >( );
Iterator< ControllerProperty > iter = allProperties.keySet( ).iterator( );
while ( iter.hasNext( ) ) {
ControllerProperty p = iter.next( );
if ( p.getController( ).equals( theController ) ) {
set.add( p );
}
}
return set;
}
public ControllerProperties addSet( String theSet ) {
allSets.add( theSet );
return this;
}
/**
* Moves a ControllerProperty from one set to another.
*/
public ControllerProperties move( ControllerProperty theProperty , String fromSet , String toSet ) {
if ( !exists( theProperty ) ) {
return this;
}
if ( allProperties.containsKey( theProperty ) ) {
allProperties.get( theProperty ).remove( fromSet );
addSet( toSet );
allProperties.get( theProperty ).add( toSet );
}
return this;
}
public ControllerProperties move( ControllerInterface< ? > theController , String fromSet , String toSet ) {
HashSet< ControllerProperty > set = getPropertySet( theController );
for ( ControllerProperty cp : set ) {
move( cp , fromSet , toSet );
}
return this;
}
/**
* copies a ControllerProperty from one set to other(s);
*/
public ControllerProperties copy( ControllerProperty theProperty , String ... theSet ) {
if ( !exists( theProperty ) ) {
return this;
}
for ( String s : theSet ) {
allProperties.get( theProperty ).add( s );
if ( !allSets.contains( s ) ) {
addSet( s );
}
}
return this;
}
public ControllerProperties copy( ControllerInterface< ? > theController , String ... theSet ) {
HashSet< ControllerProperty > set = getPropertySet( theController );
for ( ControllerProperty cp : set ) {
copy( cp , theSet );
}
return this;
}
/**
* removes a ControllerProperty from one or multiple sets.
*/
public ControllerProperties remove( ControllerProperty theProperty , String ... theSet ) {
if ( !exists( theProperty ) ) {
return this;
}
for ( String s : theSet ) {
allProperties.get( theProperty ).remove( s );
}
return this;
}
public ControllerProperties remove( ControllerInterface< ? > theController , String ... theSet ) {
HashSet< ControllerProperty > set = getPropertySet( theController );
for ( ControllerProperty cp : set ) {
remove( cp , theSet );
}
return this;
}
/**
* stores a ControllerProperty in one particular set only.
*/
public ControllerProperties only( ControllerProperty theProperty , String theSet ) {
// clear all the set-references for a particular property
allProperties.get( theProperty ).clear( );
// add theSet to the empty collection of sets for this particular
// property
allProperties.get( theProperty ).add( theSet );
return this;
}
ControllerProperties only( ControllerInterface< ? > theController , String ... theSet ) {
return this;
}
private boolean exists( ControllerProperty theProperty ) {
return allProperties.containsKey( theProperty );
}
public ControllerProperties print( ) {
for ( Entry< ControllerProperty , HashSet< String >> entry : allProperties.entrySet( ) ) {
System.out.println( entry.getKey( ) + "\t" + entry.getValue( ) );
}
return this;
}
/**
* deletes a ControllerProperty from all Sets including the default set.
*/
public ControllerProperties delete( ControllerProperty theProperty ) {
if ( !exists( theProperty ) ) {
return this;
}
allProperties.remove( theProperty );
return this;
}
private boolean updatePropertyValue( ControllerProperty theProperty ) {
Method method;
try {
method = theProperty.getController( ).getClass( ).getMethod( theProperty.getGetter( ) );
Object value = method.invoke( theProperty.getController( ) );
theProperty.setType( method.getReturnType( ) );
theProperty.setValue( value );
if ( checkSerializable( value ) ) {
return true;
}
} catch ( Exception e ) {
logger.severe(String.valueOf(e));
}
return false;
}
private boolean checkSerializable( Object theProperty ) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream( );
ObjectOutputStream stream = new ObjectOutputStream( out );
stream.writeObject( theProperty );
stream.close( );
return true;
} catch ( Exception e ) {
return false;
}
}
/**
* logs all registered properties in memory. Here, clones of properties are stored inside a map and can be accessed
* by key using the getLog method.
*
* @see ControllerProperties#getSnapshot(String)
* @param theKey
* @return ControllerProperties
*/
public ControllerProperties setSnapshot( String theKey ) {
Set< ControllerProperty > l = new HashSet< ControllerProperty >( );
for ( ControllerProperty cp : allProperties.keySet( ) ) {
updatePropertyValue( cp );
try {
l.add( ( ControllerProperty ) cp.clone( ) );
} catch ( CloneNotSupportedException e ) {
// TODO Auto-generated catch block
}
}
_mySnapshots.put( theKey , l );
return this;
}
/**
* convenience method, setSnapshot(String) also works here since it will override existing log with the same key.
*/
public ControllerProperties updateSnapshot( String theKey ) {
return setSnapshot( theKey );
}
/**
* removes a snapshot by key.
*/
public ControllerProperties removeSnapshot( String theKey ) {
_mySnapshots.remove( theKey );
return this;
}
ControllerProperties setSnapshot( String theKey , String ... theSets ) {
return this;
}
/**
* saves a snapshot into your sketch's sketch folder.
*/
public ControllerProperties saveSnapshot( String theKey ) {
saveSnapshotAs( controlP5.papplet.sketchPath( theKey ) , theKey );
return this;
}
/**
* saves a snapshot to the file with path given by the first parameter (thePropertiesPath).
*/
public ControllerProperties saveSnapshotAs( String thePropertiesPath , String theKey ) {
Set< ControllerProperty > log = _mySnapshots.get( theKey );
if ( log == null ) {
return this;
}
thePropertiesPath = getPathWithExtension( format , controlP5.checkPropertiesPath( thePropertiesPath ) );
format.compile( log , thePropertiesPath );
return this;
}
private String getPathWithExtension( PropertiesStorageFormat theFormat , String thePropertiesPath ) {
return ( thePropertiesPath.endsWith( "." + theFormat.getExtension( ) ) ) ? thePropertiesPath : thePropertiesPath + "." + theFormat.getExtension( );
}
/**
* restores properties previously stored as snapshot in memory.
*
* @see ControllerProperties#setSnapshot(String)
*/
public ControllerProperties getSnapshot( String theKey ) {
Set< ControllerProperty > l = _mySnapshots.get( theKey );
if ( l != null ) {
for ( ControllerProperty cp : l ) {
ControllerInterface< ? > ci = controlP5.getController( cp.getAddress( ) );
ci = ( ci == null ) ? controlP5.getGroup( cp.getAddress( ) ) : ci;
ControlP5.invoke(ci, cp.getSetter( ) , cp.getValue( ) );
}
}
return this;
}
/**
* properties stored in memory can be accessed by index, getSnapshotIndices() returns the index of the snapshot
* list.
*/
public ArrayList< String > getSnapshotIndices( ) {
return new ArrayList< String >( _mySnapshots.keySet( ) );
}
/**
* load properties from the default properties file 'controlP5.properties'
*/
public boolean load( ) {
return load( controlP5.papplet.sketchPath( defaultName + "." + format.getExtension( ) ) );
}
public boolean load( String thePropertiesPath ) {
return format.load( getPathWithExtension( format , controlP5.checkPropertiesPath( thePropertiesPath ) ) );
}
/**
* use ControllerProperties.SERIALIZED, ControllerProperties.XML or ControllerProperties.JSON as parameter.
*/
public void setFormat( PropertiesStorageFormat theFormat ) {
format = theFormat;
}
public void setFormat( String theFormat ) {
if ( theFormat.equals( ControlP5.JSON ) ) {
setFormat( new JSONFormat( ) );
} else if ( theFormat.equals( ControlP5.SERIALIZED ) ) {
setFormat( new SerializedFormat( ) );
} else {
System.out.println( "sorry format " + theFormat + " does not exist." );
}
}
/**
* saves all registered properties into the default 'controlP5.properties' file into your sketch folder.
*/
public boolean save( ) {
System.out.println( "save properties using format " + format + " (" + format.getExtension( ) + ") " + controlP5.papplet.sketchPath( defaultName ) );
format.compile( allProperties.keySet( ) , getPathWithExtension( format , controlP5.papplet.sketchPath( defaultName ) ) );
return true;
}
/**
* saves all registered properties into a file specified by parameter thePropertiesPath.
*/
public boolean saveAs( final String thePropertiesPath ) {
format.compile( allProperties.keySet( ) , getPathWithExtension( format , controlP5.checkPropertiesPath( thePropertiesPath ) ) );
return true;
}
/**
* saves a list of properties sets into a file specified by parameter thePropertiesPath.
*/
public boolean saveAs( String thePropertiesPath , String ... theSets ) {
thePropertiesPath = controlP5.checkPropertiesPath( thePropertiesPath );
HashSet< ControllerProperty > sets = new HashSet< ControllerProperty >( );
Iterator< ControllerProperty > iter = allProperties.keySet( ).iterator( );
while ( iter.hasNext( ) ) {
ControllerProperty p = iter.next( );
if ( allProperties.containsKey( p ) ) {
HashSet< String > set = allProperties.get( p );
for ( String str : set ) {
for ( String s : theSets ) {
if ( str.equals( s ) ) {
sets.add( p );
}
}
}
}
}
format.compile( sets , getPathWithExtension( format , thePropertiesPath ) );
return true;
}
/**
* @exclude {@inheritDoc}
*/
public String toString( ) {
String s = "";
s += this.getClass( ).getName( ) + "\n";
s += "total num of properties:\t" + allProperties.size( ) + "\n";
for ( ControllerProperty c : allProperties.keySet( ) ) {
s += "\t" + c + "\n";
}
s += "total num of sets:\t\t" + allSets.size( ) + "\n";
for ( String set : allSets ) {
s += "\t" + set + "\n";
}
return s;
}
interface PropertiesStorageFormat {
void compile( Set< ControllerProperty > theProperties , String thePropertiesPath );
boolean load( String thePropertiesPath );
String getExtension( );
}
class XMLFormat implements PropertiesStorageFormat {
public void compile( Set< ControllerProperty > theProperties , String thePropertiesPath ) {
System.out.println( "Dont use the XMLFormat yet, it is not fully implemented with 0.5.9, use SERIALIZED instead." );
System.out.println( "Compiling with XMLFormat" );
StringBuffer xml = new StringBuffer( );
xml.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
xml.append( "<properties name=\"" + thePropertiesPath + "\">\n" );
for ( ControllerProperty cp : theProperties ) {
if ( cp.isActive( ) ) {
updatePropertyValue( cp );
xml.append( getXML( cp ) );
}
}
xml.append( "</properties>" );
controlP5.papplet.saveStrings( thePropertiesPath , PApplet.split( xml.toString( ) , "\n" ) );
System.out.println( "saving xml, " + thePropertiesPath );
}
public String getExtension( ) {
return "xml";
}
public boolean load( String thePropertiesPath ) {
String s;
try {
s = PApplet.join( controlP5.papplet.loadStrings( thePropertiesPath ) , "\n" );
} catch ( Exception e ) {
logger.warning( thePropertiesPath + ", file not found." );
return false;
}
System.out.println( "loading xml \n" + s );
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance( );
DocumentBuilder db = dbf.newDocumentBuilder( );
InputSource is = new InputSource( );
is.setCharacterStream( new StringReader( s ) );
Document doc = db.parse( is );
doc.getDocumentElement( ).normalize( );
NodeList nodeLst = doc.getElementsByTagName( "property" );
for ( int i = 0 ; i < nodeLst.getLength( ) ; i++ ) {
Node node = nodeLst.item( i );
if ( node.getNodeType( ) == Node.ELEMENT_NODE ) {
Element fstElmnt = ( Element ) node;
String myAddress = getElement( fstElmnt , "address" );
String mySetter = getElement( fstElmnt , "setter" );
String myType = getElement( fstElmnt , "type" );
String myValue = getElement( fstElmnt , "value" );
// String myClass = getElement(fstElmnt, "class");
// String myGetter = getElement(fstElmnt, "getter");
try {
System.out.print( "setting controller " + myAddress + " " );
ControllerInterface< ? > ci = controlP5.getController( myAddress );
ci = ( ci == null ) ? controlP5.getGroup( myAddress ) : ci;
System.out.println( ci );
Method method;
try {
Class< ? > c = getClass( myType );
System.out.println( myType + " / " + c );
method = ci.getClass( ).getMethod( mySetter , c);
method.setAccessible( true );
method.invoke( ci , getValue( myValue , myType , c ));
} catch ( Exception e ) {
logger.severe( e.toString( ) );
}
} catch ( Exception e ) {
logger.warning( "skipping a property, " + e );
}
}
}
} catch ( SAXException e ) {
logger.warning( "SAXException, " + e );
return false;
} catch ( IOException e ) {
logger.warning( "IOException, " + e );
return false;
} catch ( ParserConfigurationException e ) {
logger.warning( "ParserConfigurationException, " + e );
return false;
}
return true;
}
private Object getValue( String theValue , String theType , Class< ? > theClass ) {
if ( theClass == int.class ) {
return Integer.parseInt( theValue );
} else if ( theClass == float.class ) {
return Float.parseFloat( theValue );
} else if ( theClass == boolean.class ) {
return Boolean.parseBoolean( theValue );
} else if ( theClass.isArray( ) ) {
System.out.println( "this is an array: " + theType + ", " + theValue + ", " + theClass );
int dim = 0;
while ( true ) {
if ( theType.charAt( dim ) != '[' || dim >= theType.length( ) ) {
break;
}
dim++;
}
} else {
System.out.println( "is array? " + theClass.isArray( ) );
}
return theValue;
}
private Class< ? > getClass( String theType ) {
if ( theType.equals( "int" ) ) {
return int.class;
} else if ( theType.equals( "float" ) ) {
return float.class;
} else if ( theType.equals( "String" ) ) {
return String.class;
}
try {
return Class.forName( theType );
} catch ( ClassNotFoundException e ) {
logger.warning( "ClassNotFoundException, " + e );
}
return null;
}
private String getElement( Element theElement , String theName ) {
NodeList fstNmElmntLst = theElement.getElementsByTagName( theName );
Element fstNmElmnt = ( Element ) fstNmElmntLst.item( 0 );
NodeList fstNm = fstNmElmnt.getChildNodes( );
return fstNm.item( 0 ).getNodeValue( );
}
public String getXML( ControllerProperty theProperty ) {
// Mapping Between JSON and Java Entities
// http://code.google.com/p/json-simple/wiki/MappingBetweenJSONAndJavaEntities
String s = "\t<property>\n";
s += "\t\t<address>" + theProperty.getAddress( ) + "</address>\n";
s += "\t\t<class>" + CP.formatGetClass( theProperty.getController( ).getClass( ) ) + "</class>\n";
s += "\t\t<setter>" + theProperty.getSetter( ) + "</setter>\n";
s += "\t\t<getter>" + theProperty.getGetter( ) + "</getter>\n";
s += "\t\t<type>" + CP.formatGetClass( theProperty.getType( ) ) + "</type>\n";
s += "\t\t<value>" + cdata( OPEN , theProperty.getValue( ).getClass( ) ) + ( theProperty.getValue( ).getClass( ).isArray( ) ? CP.arrayToString( theProperty.getValue( ) ) : theProperty.getValue( ) )
+ cdata( CLOSE , theProperty.getValue( ).getClass( ) ) + "</value>\n";
s += "\t</property>\n";
return s;
}
private String cdata( int a , Class< ? > c ) {
if ( c == String.class || c.isArray( ) ) {
return ( a == OPEN ? "<![CDATA[" : "]]>" );
}
return "";
}
}
public class JSONFormat implements PropertiesStorageFormat {
public void compile( Set< ControllerProperty > theProperties , String thePropertiesPath ) {
long t = System.currentTimeMillis( );
JSONObject json = new JSONObject( );
for ( ControllerProperty cp : theProperties ) {
if ( cp.isActive( ) ) {
if ( updatePropertyValue( cp ) ) {
cp.setId( cp.getController( ).getId( ) );
if ( !json.keys( ).contains( cp.getAddress( ) ) ) {
json.setJSONObject( cp.getAddress( ) , new JSONObject( ) );
}
JSONObject item = json.getJSONObject( cp.getAddress( ) );
String key = cp.getSetter( );
key = Character.toLowerCase( key.charAt( 3 ) ) + key.substring( 4 );
if ( cp.getValue( ) instanceof Number ) {
if ( cp.getValue( ) instanceof Integer ) {
item.setInt( key , ControlP5.i( cp.getValue( ) ) );
} else if ( cp.getValue( ) instanceof Float ) {
item.setFloat( key , ControlP5.f( cp.getValue( ) ) );
} else if ( cp.getValue( ) instanceof Double ) {
item.setDouble( key , ControlP5.d( cp.getValue( ) ) );
}
} else if ( cp.getValue( ) instanceof Boolean ) {
item.setBoolean( key , ControlP5.b( cp.getValue( ) ) );
} else {
if ( cp.getValue( ).getClass( ).isArray( ) ) {
JSONArray arr = new JSONArray( );
if ( cp.getValue( ) instanceof int[] ) {
for ( Object o : ( int[] ) cp.getValue( ) ) {
arr.append( ControlP5.i( o ) );
}
} else if ( cp.getValue( ) instanceof float[] ) {
for ( Object o : ( float[] ) cp.getValue( ) ) {
arr.append( ControlP5.f( o ) );
}
}
item.setJSONArray( key , arr );
} else {
item.setString( key , cp.getValue( ).toString( ) );
}
}
}
}
}
json.save( new File( getPathWithExtension( this , thePropertiesPath ) ) , "" );
}
public String getExtension( ) {
return "json";
}
public boolean load( String thePropertiesPath ) {
JSONReader reader = new JSONReader( controlP5.papplet );
Map< ? , ? > entries = ControlP5.toMap( reader.parse( thePropertiesPath ) );
for ( Map.Entry entry : entries.entrySet( ) ) {
String name = entry.getKey( ).toString( );
Controller c = controlP5.getController( name );
Map< ? , ? > values = ControlP5.toMap( entry.getValue( ) );
for ( Map.Entry value : values.entrySet( ) ) {
String i0 = value.getKey( ).toString( );
String member = "set" + Character.toUpperCase( i0.charAt( 0 ) ) + i0.substring( 1 );
Object i1 = value.getValue( );
if ( i1 instanceof Number ) {
ControlP5.invoke( c , member , ControlP5.f( value.getValue( ) ) );
} else if ( i1 instanceof String ) {
ControlP5.invoke( c , member , ControlP5.s( value.getValue( ) ) );
} else if ( i1 instanceof float[] ) {
ControlP5.invoke( c , member , i1);
} else {
if ( i1 instanceof List ) {
List l = ( List ) i1;
float[] arr = new float[ l.size( ) ];
for ( int i = 0 ; i < l.size( ) ; i++ ) {
arr[ i ] = ControlP5.f( l.get( i ) );
}
ControlP5.invoke( c , member , arr );
} else {
ControlP5.invoke( c , member , value.getValue( ) );
}
}
}
}
return false;
}
}
private class JSONReader {
private final PApplet papplet;
public JSONReader( Object o ) {
if ( o instanceof PApplet ) {
papplet = ( PApplet ) o;
} else {
papplet = null;
System.out.println( "Sorry, argument is not of instance PApplet" );
}
}
public Object parse( String s ) {
if ( s.indexOf( "{" ) >= 0 ) {
return get( JSONObject.parse( s ) , new LinkedHashMap( ) );
} else {
return get( papplet.loadJSONObject( s ) , new LinkedHashMap( ) );
}
}
Object get( Object o , Object m ) {
if ( o instanceof JSONObject ) {
if ( m instanceof Map ) {
Set set = ( ( JSONObject ) o ).keys( );
for ( Object o1 : set ) {
Object o2 = ControlP5.invoke( o , "opt" , o1.toString( ) );
if ( o2 instanceof JSONObject ) {
Map m1 = new LinkedHashMap( );
( ( Map ) m ).put( o1.toString( ) , m1 );
get( o2 , m1 );
} else if ( o2 instanceof JSONArray ) {
List l1 = new ArrayList( );
( ( Map ) m ).put( o1.toString( ) , l1 );
get( o2 , l1 );
} else {
( ( Map ) m ).put( o1.toString( ) , o2 );
}
}
}
} else if ( o instanceof JSONArray ) {
if ( m instanceof List ) {
List l = ( ( List ) m );
int n = 0;
Object o3 = ControlP5.invoke( o , "opt" , n );
while ( o3 != null ) {
if ( o3 instanceof JSONArray ) {
List l1 = new ArrayList( );
l.add( l1 );
get( o3 , l1 );
} else if ( o3 instanceof JSONObject ) {
Map l1 = new LinkedHashMap( );
l.add( l1 );
get( o3 , l1 );
} else {
l.add( o3 );
}
o3 = ControlP5.invoke( o , "opt" , ++n );
}
} else {
System.err.println( "JSONReader type mismatch." );
}
}
return m;
}
}
public class SerializedFormat implements PropertiesStorageFormat {
public boolean load( String thePropertiesPath ) {
try {
FileInputStream fis = new FileInputStream( thePropertiesPath );
ObjectInputStream ois = new ObjectInputStream( fis );
int size = ois.readInt( );
logger.info( "loading " + size + " property-items. " );
for ( int i = 0 ; i < size ; i++ ) {
try {
ControllerProperty cp = ( ControllerProperty ) ois.readObject( );
ControllerInterface< ? > ci = controlP5.getController( cp.getAddress( ) );
ci = ( ci == null ) ? controlP5.getGroup( cp.getAddress( ) ) : ci;
ci.setId( cp.getId( ) );
Method method;
try {
method = ci.getClass( ).getMethod( cp.getSetter( ) , cp.getType( ));
method.setAccessible( true );
method.invoke( ci , cp.getValue( ));
} catch ( Exception e ) {
logger.severe( e.toString( ) );
}
} catch ( Exception e ) {
logger.warning( "skipping a property, " + e );
}
}
ois.close( );
} catch ( Exception e ) {
logger.warning( "Exception during deserialization: " + e );
return false;
}
return true;
}
public String getExtension( ) {
return "ser";
}
public void compile( Set< ControllerProperty > theProperties , String thePropertiesPath ) {
int active = 0;
int total = 0;
HashSet< ControllerProperty > propertiesToBeSaved = new HashSet< ControllerProperty >( );
for ( ControllerProperty cp : theProperties ) {
if ( cp.isActive( ) ) {
if ( updatePropertyValue( cp ) ) {
active++;
cp.setId( cp.getController( ).getId( ) );
propertiesToBeSaved.add( cp );
}
}
total++;
}
int ignored = total - active;
try {
FileOutputStream fos = new FileOutputStream( thePropertiesPath );
ObjectOutputStream oos = new ObjectOutputStream( fos );
logger.info( "Saving property-items to " + thePropertiesPath );
oos.writeInt( active );
for ( ControllerProperty cp : propertiesToBeSaved ) {
if ( cp.isActive( ) ) {
oos.writeObject( cp );
}
}
logger.info( active + " items saved, " + ( ignored ) + " items ignored. Done saving properties." );
oos.flush( );
oos.close( );
fos.close( );
} catch ( Exception e ) {
logger.warning( "Exception during serialization: " + e );
}
}
}
}

173
controlP5/ControllerProperty.java Executable file
View File

@ -0,0 +1,173 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.Serializable;
/**
* A controller property saves the value, address, getter and setter of a registered controller.
*
* @example controllers/ControlP5properties
*/
public class ControllerProperty implements Serializable , Cloneable {
private static final long serialVersionUID = 4506431150330867327L;
private String setter;
private String getter;
private Class< ? > type;
private Object value;
private String address;
private int id;
private transient boolean active;
private transient ControllerInterface< ? > controller;
ControllerProperty( ControllerInterface< ? > theController , String theSetter , String theGetter ) {
setController( theController );
setAddress( theController.getAddress( ) );
setSetter( theSetter );
setGetter( theGetter );
setActive( true );
setId( theController.getId( ) );
}
@Override protected Object clone( ) throws CloneNotSupportedException {
ControllerProperty clone = ( ControllerProperty ) super.clone( );
clone.setSetter( getSetter( ) );
clone.setGetter( getGetter( ) );
clone.setType( getType( ) );
clone.setValue( getValue( ) );
clone.setAddress( getAddress( ) );
clone.setActive( isActive( ) );
clone.setController( getController( ) );
clone.setId( getId( ) );
return clone;
}
/**
* @exclude {@inheritDoc}
*/
@Override public boolean equals( Object o ) {
if ( this == o ) {
return true;
}
if ( o == null || getClass( ) != o.getClass( ) ) {
return false;
}
ControllerProperty p = ( ControllerProperty ) o;
return address.equals(p.address) && setter.equals(p.setter) && getter.equals(p.getter);
}
/**
* @exclude {@inheritDoc}
*/
@Override public int hashCode( ) {
int result = 17;
result = 37 * result + ( address != null ? address.hashCode( ) : 0 );
result = 37 * result + ( setter != null ? setter.hashCode( ) : 0 );
result = 37 * result + ( getter != null ? getter.hashCode( ) : 0 );
return result;
}
public void disable( ) {
active = false;
}
public void enable( ) {
active = true;
}
@Override public String toString( ) {
return address + " " + setter + ", " + getter;
}
void setAddress( String theAddress ) {
address = theAddress;
}
String getAddress( ) {
return address;
}
ControllerInterface< ? > getController( ) {
return controller;
}
void setController( ControllerInterface< ? > theController ) {
controller = theController;
}
Object getValue( ) {
return value;
}
void setValue( Object theValue ) {
value = theValue;
}
Class< ? > getType( ) {
return type;
}
void setType( Class< ? > theType ) {
type = theType;
}
boolean isActive( ) {
return active;
}
void setActive( boolean theValue ) {
active = theValue;
}
String getGetter( ) {
return getter;
}
void setGetter( String theValue ) {
getter = theValue;
}
String getSetter( ) {
return setter;
}
void setSetter( String theValue ) {
setter = theValue;
}
int getId( ) {
return id;
}
void setId( int theValue ) {
id = theValue;
}
}

153
controlP5/ControllerStyle.java Executable file
View File

@ -0,0 +1,153 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.Serializable;
/**
* Labels use the ControllerStyle class to store margin and padding information.
*
* @see Label#getStyle()
*
* @example extra/ControlP5style
*/
public class ControllerStyle implements Serializable {
private static final long serialVersionUID = 3250201688970310633L;
public int paddingTop = 0;
public int paddingRight = 0;
public int paddingBottom = 0;
public int paddingLeft = 0;
public int marginTop = 0;
public int marginRight = 0;
public int marginBottom = 0;
public int marginLeft = 0;
public int background;
public int backgroundWidth = -1;
public int backgroundHeight = -1;
public int color;
public ControllerStyle margin( int theValue ) {
marginTop = theValue;
marginRight = theValue;
marginBottom = theValue;
marginLeft = theValue;
return this;
}
public ControllerStyle padding( int theValue ) {
paddingTop = theValue;
paddingRight = theValue;
paddingBottom = theValue;
paddingLeft = theValue;
return this;
}
public ControllerStyle setPadding( int theTop , int theRight , int theBottom , int theLeft ) {
padding( theTop , theRight , theBottom , theLeft );
return this;
}
public ControllerStyle setPaddingTop( int theValue ) {
paddingTop = theValue;
return this;
}
public ControllerStyle setPaddingBottom( int theValue ) {
paddingBottom = theValue;
return this;
}
public ControllerStyle setPaddingRight( int theValue ) {
paddingRight = theValue;
return this;
}
public ControllerStyle setPaddingLeft( int theValue ) {
paddingLeft = theValue;
return this;
}
public ControllerStyle margin( int theTop , int theRight , int theBottom , int theLeft ) {
marginTop = theTop;
marginRight = theRight;
marginBottom = theBottom;
marginLeft = theLeft;
return this;
}
public ControllerStyle setMargin( int theTop , int theRight , int theBottom , int theLeft ) {
margin( theTop , theRight , theBottom , theLeft );
return this;
}
public ControllerStyle setMarginTop( int theValue ) {
marginTop = theValue;
return this;
}
public ControllerStyle setMarginBottom( int theValue ) {
marginBottom = theValue;
return this;
}
public ControllerStyle setMarginRight( int theValue ) {
marginRight = theValue;
return this;
}
public ControllerStyle setMarginLeft( int theValue ) {
marginLeft = theValue;
return this;
}
public ControllerStyle padding( int theTop , int theRight , int theBottom , int theLeft ) {
paddingTop = theTop;
paddingRight = theRight;
paddingBottom = theBottom;
paddingLeft = theLeft;
return this;
}
public ControllerStyle moveMargin( int theTop , int theRight , int theBottom , int theLeft ) {
marginTop += theTop;
marginRight += theRight;
marginBottom += theBottom;
marginLeft += theLeft;
return this;
}
public ControllerStyle movePadding( int theTop , int theRight , int theBottom , int theLeft ) {
paddingTop += theTop;
paddingRight += theRight;
paddingBottom += theBottom;
paddingLeft += theLeft;
return this;
}
}

50
controlP5/ControllerView.java Executable file
View File

@ -0,0 +1,50 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* The interface ControllerView can be used to define custom displays for controllers.
*
* @see controlP5.draw(processing.core.PApplet)
* @see controlP5.setView(ControlleView)
*
* @example use/ControlP5customDisplay
*/
public interface ControllerView< T > {
/**
* draws your custom controllers. display() will be called by a controller's draw() function and
* will pass a reference of PApplet as well as the Controller itself to your custom display
* class.
*
* @param theApplet
* @param theController
*/
void display( PGraphics theGraphics , T theController );
}

466
controlP5/DropdownList.java Executable file
View File

@ -0,0 +1,466 @@
package main.java.src2.main.java.controlP5.controlP5;
import static main.java.src2.main.java.controlP5.controlP5.ControlP5.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.event.KeyEvent;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
public class DropdownList extends Controller< DropdownList > implements ControlListener {
private int _myType = DROPDOWN;
protected int _myBackgroundColor = 0x00ffffff;
protected int itemHeight = 13;
protected int barHeight = 10;
private float scrollSensitivity = 1;
private boolean isOpen = true;
protected List< Map< String , Object > > items;
protected int itemRange = 5;
protected int itemHover = -1;
private int itemIndexOffset = 0;
private final int itemSpacing = 1;
private int _myDirection = PApplet.DOWN;
private boolean isBarVisible = true;
static public final int LIST = ControlP5.LIST;
static public final int DROPDOWN = ControlP5.DROPDOWN;
static public final int CHECKBOX = ControlP5.CHECKBOX; /* TODO */
static public final int TREE = ControlP5.TREE; /* TODO */
public DropdownList( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 199 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected DropdownList( ControlP5 theControlP5 , ControllerGroup< ? > theGroup , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theGroup , theName , theX , theY , theW , theH );
items = new ArrayList< Map< String , Object > >( );
updateHeight( );
getValueLabel( ).align( PApplet.LEFT , PApplet.CENTER );
}
public boolean isOpen( ) {
return isOpen;
}
public DropdownList open( ) {
return setOpen( true );
}
public DropdownList close( ) {
return setOpen( false );
}
public DropdownList setOpen( boolean b ) {
isOpen = b;
return this;
}
@Override public int getHeight( ) {
return isOpen ? super.getHeight( ) : barHeight;
}
public DropdownList setType( int theType ) {
_myType = theType;
return this;
}
public void setDirection( int theDirection ) {
_myDirection = ( theDirection == PApplet.UP ) ? PApplet.UP : PApplet.DOWN;
}
@Override protected boolean inside( ) {
/* constrain the bounds of the controller to the
* dimensions of the cp5 area, required since
* PGraphics as render area has been introduced. */
float x0 = PApplet.max( 0 , x( position ) + x( _myParent.getAbsolutePosition( ) ) );
float x1 = PApplet.min( cp5.pgw , x( position ) + x( _myParent.getAbsolutePosition( ) ) + getWidth( ) );
float y0 = PApplet.max( 0 , y( position ) + y( _myParent.getAbsolutePosition( ) ) );
float y1 = PApplet.min( cp5.pgh , y( position ) + y( _myParent.getAbsolutePosition( ) ) + getHeight( ) );
if ( y1 < y0 ) {
float ty = y0;
y0 = y1;
y1 = ty;
}
return ( _myControlWindow.mouseX > x0 && _myControlWindow.mouseX < x1 && _myControlWindow.mouseY > ( y1 < y0 ? y1 : y0 ) && _myControlWindow.mouseY < ( y0 < y1 ? y1 : y0 ) );
}
@Override protected void onRelease( ) {
if ( !isDragged ) {
if ( getPointer( ).y( ) >= 0 && getPointer( ).y( ) <= barHeight ) {
setOpen( !isOpen( ) );
} else if ( isOpen ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
// n += itemRange; /* UP */
int index = ( int ) n + itemIndexOffset;
if (index < items.size()) {
Map m = items.get( index );
switch ( _myType ) {
case ( LIST ):
setValue( index );
for ( Object o : items ) {
( ( Map ) o ).put( "state" , false );
}
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
case ( DROPDOWN ):
setValue( index );
setOpen( false );
getCaptionLabel( ).setText( ( m.get( "text" ).toString( ) ) );
break;
case ( CHECKBOX ):
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
}
}
}
}
}
@Override protected void onDrag( ) {
scroll( getPointer( ).dy( ) );
}
@Override protected void onScroll( int theValue ) {
scroll( theValue );
}
private void scroll( int theValue ) {
if ( isOpen ) {
itemIndexOffset += theValue;
itemIndexOffset = ( int ) ( Math.floor( Math.max( 0 , Math.min( itemIndexOffset , items.size( ) - itemRange ) ) ) );
itemHover = -2;
}
}
@Override protected void onLeave( ) {
itemHover = -1;
}
private void updateHover( ) {
if ( getPointer( ).y( ) > barHeight ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
itemHover = ( int ) ( itemIndexOffset + n );
} else {
itemHover = -1;
}
}
@Override protected void onEnter( ) {
updateHover( );
}
@Override protected void onMove( ) {
updateHover( );
}
@Override protected void onEndDrag( ) {
updateHover( );
}
private int updateHeight( ) {
itemRange = ( PApplet.abs( getHeight( ) ) - ( isBarVisible( ) ? barHeight : 0 ) ) / itemHeight;
return itemHeight * ( items.size( ) < itemRange ? items.size( ) : itemRange );
}
public DropdownList setItemHeight( int theHeight ) {
itemHeight = theHeight;
updateHeight( );
return this;
}
public DropdownList setBarHeight( int theHeight ) {
barHeight = theHeight;
updateHeight( );
return this;
}
public int getBarHeight( ) {
return barHeight;
}
public DropdownList setScrollSensitivity( float theSensitivity ) {
scrollSensitivity = theSensitivity;
return this;
}
public DropdownList setBarVisible( boolean b ) {
isBarVisible = b;
updateHeight( );
return this;
}
public boolean isBarVisible( ) {
return isBarVisible;
}
private Map< String , Object > getDefaultItemMap( String theName , Object theValue ) {
Map< String , Object > item = new HashMap< String , Object >( );
item.put( "name" , theName );
item.put( "text" , theName );
item.put( "value" , theValue );
item.put( "color" , getColor( ) );
item.put( "view" , new CDrawable( ) {
@Override public void draw( PGraphics theGraphics ) {
}
} );
item.put( "state" , false );
return item;
}
public DropdownList addItem( String theName , Object theValue ) {
Map< String , Object > item = getDefaultItemMap( theName , theValue );
items.add( item );
return this;
}
public DropdownList addItems( String[] theItems ) {
addItems( Arrays.asList( theItems ) );
return this;
}
public DropdownList addItems( List< String > theItems ) {
for ( int i = 0 ; i < theItems.size( ) ; i++ ) {
addItem(theItems.get( i ), i );
}
return this;
}
public DropdownList addItems( Map< String , Object > theItems ) {
for ( Map.Entry< String , Object > item : theItems.entrySet( ) ) {
addItem( item.getKey( ) , item.getValue( ) );
}
return this;
}
public DropdownList setItems( String[] theItems ) {
setItems( Arrays.asList( theItems ) );
return this;
}
public DropdownList setItems( List< String > theItems ) {
items.clear( );
return addItems( theItems );
}
public DropdownList setItems( Map< String , Object > theItems ) {
items.clear( );
return addItems( theItems );
}
public DropdownList removeItems( List< String > theItems ) {
for ( String s : theItems ) {
removeItem( s );
}
return this;
}
public DropdownList removeItem( String theName ) {
if ( theName != null ) {
List l = new ArrayList( );
for ( Map m : items ) {
if ( theName.equals( m.get( "name" ) ) ) {
l.add( m );
}
}
items.removeAll( l );
}
return this;
}
public void updateItemIndexOffset( ) {
int m1 = items.size( ) > itemRange ? ( itemIndexOffset + itemRange ) : items.size( );
int n = ( m1 - items.size( ) );
if ( n >= 0 ) {
itemIndexOffset -= n;
}
}
public Map< String , Object > getItem( int theIndex ) {
return items.get( theIndex );
}
public Map< String , Object > getItem( String theName ) {
if ( theName != null ) {
for ( Map< String , Object > o : items ) {
if ( theName.equals( o.get( "name" ) ) ) {
return o;
}
}
}
return Collections.EMPTY_MAP;
}
public List getItems( ) {
return Collections.unmodifiableList( items );
}
public DropdownList clear( ) {
for ( int i = items.size( ) - 1 ; i >= 0 ; i-- ) {
items.remove( i );
}
items.clear( );
itemIndexOffset = 0;
return this;
}
@Override public void controlEvent( ControlEvent theEvent ) {
// TODO Auto-generated method stub
}
public DropdownList setBackgroundColor( int theColor ) {
_myBackgroundColor = theColor;
return this;
}
public int getBackgroundColor( ) {
return _myBackgroundColor;
}
@Override @ControlP5.Invisible public DropdownList updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new DropdownListView( );
break;
case ( IMAGE ):
case ( SPRITE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
static public class DropdownListView implements ControllerView< DropdownList > {
public void display( PGraphics g , DropdownList c ) {
// setHeight( -200 ); /* UP */
g.noStroke( );
if ( c.isBarVisible( ) ) {
boolean b = c.itemHover == -1 && c.isInside && !c.isDragged;
g.fill( b ? c.getColor( ).getForeground( ) : c.getColor( ).getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.barHeight );
g.pushMatrix( );
g.translate( c.getWidth( ) - 8 , c.barHeight / 2 - 2 );
g.fill( c.getColor( ).getCaptionLabel( ) );
if ( c.isOpen( ) ) {
g.triangle( -3 , 0 , 3 , 0 , 0 , 3 );
} else {
g.triangle( -3 , 3 , 3 , 3 , 0 , 0 );
}
g.popMatrix( );
c.getCaptionLabel( ).draw( g , 4 , c.barHeight / 2 );
}
if ( c.isOpen( ) ) {
int bar = ( c.isBarVisible( ) ? c.barHeight : 0 );
int h = ( ( c.updateHeight( ) ) );
g.pushMatrix( );
// g.translate( 0 , - ( h + bar +
// c.itemSpacing ) ); /* UP */
g.fill( c.getBackgroundColor( ) );
g.rect( 0 , bar , c.getWidth( ) , h );
g.pushMatrix( );
g.translate( 0 , ( bar == 0 ? 0 : ( c.barHeight + c.itemSpacing ) ) );
/* draw visible items */
c.updateItemIndexOffset( );
int m0 = c.itemIndexOffset;
int m1 = c.items.size( ) > c.itemRange ? ( c.itemIndexOffset + c.itemRange ) : c.items.size( );
for ( int i = m0 ; i < m1 ; i++ ) {
Map< String , Object > item = c.items.get( i );
CColor color = ( CColor ) item.get( "color" );
g.fill( ( b( item.get( "state" ) ) ) ? color.getActive( ) : ( i == c.itemHover ) ? ( c.isMousePressed ? color.getActive( ) : color.getForeground( ) ) : color.getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.itemHeight - 1 );
c.getValueLabel( ).set( item.get( "text" ).toString( ) ).draw( g , 4 , c.itemHeight / 2 );
g.translate( 0 , c.itemHeight );
}
g.popMatrix( );
if ( c.isInside ) {
int m = c.items.size( ) - c.itemRange;
if ( m > 0 ) {
g.fill( c.getColor( ).getCaptionLabel( ) );
g.pushMatrix( );
int s = 4; /* spacing */
int s2 = s / 2;
g.translate( c.getWidth( ) - s , c.barHeight );
int len = ( int ) PApplet.map( ( float ) Math.log( m * 10 ) , 0 , 10 , h , 0 );
int pos = ( int ) ( PApplet.map( c.itemIndexOffset , 0 , m , s2 , h - len - s2 ) );
g.rect( 0 , pos , s2 , len );
g.popMatrix( );
}
}
g.popMatrix( );
}
}
}
public void keyEvent( KeyEvent theKeyEvent ) {
if ( isInside && theKeyEvent.getAction( ) == KeyEvent.PRESS ) {
switch ( theKeyEvent.getKeyCode( ) ) {
case (UP):
scroll( theKeyEvent.isAltDown( ) ? -itemIndexOffset : theKeyEvent.isShiftDown( ) ? -10 : -1 );
updateHover( );
break;
case (DOWN):
scroll( theKeyEvent.isAltDown( ) ? items.size( ) - itemRange : theKeyEvent.isShiftDown( ) ? 10 : 1 );
updateHover( );
break;
case (LEFT):
break;
case (RIGHT):
break;
case (ENTER):
onRelease( );
break;
}
}
}
/* TODO keycontrol: arrows, return dragging moving items
* sorting custom view custom event types */
}

View File

@ -0,0 +1,134 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.Field;
/**
* the FieldChangedListener is used to observe changes of variables that are
* linked to a controller. The FieldChangedListener is for primarily for
* internal use.
*
* @see Controller#listen(boolean)
*/
class FieldChangedListener {
private FieldValue value;
private final ControlP5 controlP5;
public FieldChangedListener(ControlP5 theControlP5) {
controlP5 = theControlP5;
}
/**
* Assigns a listener to a specific field of an object.
*
* this can be done in a more elegant way using generics.
*
* @param theObject
* @param theFieldName
*/
public void listenTo(final Object theObject, final String theFieldName) {
try {
Class<?> c = theObject.getClass();
final Field field = c.getDeclaredField(theFieldName);
field.setAccessible(true);
if (field.getType().isAssignableFrom(Float.TYPE)) {
value = new FieldValue() {
float then;
public void check() {
try {
float now = (Float) field.get(theObject);
if (now != then) {
controlP5.getController(theFieldName, theObject).setValue(now);
then = now;
}
} catch (IllegalAccessException e) {
}
}
};
} else if (field.getType().isAssignableFrom(Integer.TYPE)) {
value = new FieldValue() {
int then;
public void check() {
try {
int now = (Integer) field.get(theObject);
if (now != then) {
controlP5.getController(theFieldName, theObject).setValue(now);
then = now;
}
} catch (IllegalAccessException e) {
}
}
};
} else if (field.getType().isAssignableFrom(Boolean.TYPE)) {
value = new FieldValue() {
boolean then;
public void check() {
try {
boolean now = (Boolean) field.get(theObject);
if (now != then) {
controlP5.getController(theFieldName, theObject).setValue(now ? 1 : 0);
then = now;
}
} catch (IllegalAccessException e) {
}
}
};
} else if (field.getType().isAssignableFrom(String.class)) {
value = new FieldValue() {
String then;
public void check() {
try {
String now = (String) field.get(theObject);
if (!now.equals(then)) {
controlP5.getController(theFieldName, theObject).setStringValue(now);
then = now;
}
} catch (IllegalAccessException e) {
}
}
};
}
} catch (Exception e) {
System.out.println(e);
}
}
void update() {
value.check();
}
}
interface FieldValue {
void check();
}

58
controlP5/FrameRate.java Executable file
View File

@ -0,0 +1,58 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
public class FrameRate extends Textlabel {
private int _myInterval = 10;
private float _myIntervalSum = 0;
private int cnt = 0;
protected FrameRate( final ControlP5 theControlP5 , final Tab theParent , final String theValue , final int theX , final int theY ) {
super( theControlP5 , theParent , "framerate" , "-" , theX , theY );
}
public FrameRate setInterval( int theValue ) {
_myInterval = theValue;
return this;
}
@Override
public void draw( PGraphics theGraphics ) {
if ( ( cnt++ ) % _myInterval == 0 ) {
setText(String.valueOf(PApplet.round(_myIntervalSum / _myInterval)));
_myIntervalSum = 0;
}
_myIntervalSum += cp5.papplet.frameRate;
super.draw( theGraphics );
}
}

43
controlP5/Group.java Executable file
View File

@ -0,0 +1,43 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
public class Group extends ControlGroup< Group > {
/**
* Convenience constructor to extend Group.
*
* @example use/ControlP5extendController
*/
public Group( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 9 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public Group( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theParent , theName , theX , theY , theW , theH );
}
}

405
controlP5/Icon.java Normal file
View File

@ -0,0 +1,405 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
public class Icon extends Controller< Icon > {
protected boolean isPressed;
protected boolean isOn = false;
public static int autoWidth = 69;
public static int autoHeight = 19;
protected int activateBy = ControlP5Constants.RELEASE;
protected boolean isSwitch = false;
protected int roundedCorners = 0;
protected boolean isFill = true;
protected boolean isStroke = false;
protected float scl = 1;
protected int[] fontIcons = new int[] { -1 , -1 , -1 , -1 };
protected boolean isHideBackground = true;
protected float strokeWeight = 1;
protected float scalePressed = 1.0f;
protected float scaleReleased = 1.0f;
public Icon( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Icon( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myValue = theDefaultValue;
_myCaptionLabel.align( ControlP5Constants.CENTER , ControlP5Constants.CENTER );
}
@Override protected void onEnter( ) {
isActive = true;
}
@Override protected void onLeave( ) {
isActive = false;
setIsInside( false );
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mousePressed( ) {
isActive = getIsInside( );
isPressed = true;
if ( activateBy == ControlP5Constants.PRESSED ) {
activate( );
}
scl = scalePressed;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mouseReleased( ) {
isPressed = false;
if ( activateBy == ControlP5Constants.RELEASE ) {
activate( );
}
isActive = false;
scl = scaleReleased;
}
/**
* A Icon can be activated by a mouse PRESSED or mouse
* RELEASE. Default value is RELEASE.
*/
public Icon activateBy( int theValue ) {
if ( theValue == ControlP5Constants.PRESS ) {
activateBy = ControlP5Constants.PRESS;
} else {
activateBy = ControlP5Constants.RELEASE;
}
return this;
}
protected void activate( ) {
if ( isActive ) {
isActive = false;
isOn = !isOn;
setValue( _myValue );
}
}
@Override @ControlP5.Invisible public void mouseReleasedOutside( ) {
mouseReleased( );
}
@Override public Icon setValue( float theValue ) {
_myValue = theValue;
broadcast( ControlP5Constants.FLOAT );
return this;
}
@Override public Icon update( ) {
return setValue( _myValue );
}
/**
* Turns an icon into a switch.
*/
public Icon setSwitch( boolean theFlag ) {
isSwitch = theFlag;
if ( isSwitch ) {
_myBroadcastType = ControlP5Constants.BOOLEAN;
} else {
_myBroadcastType = ControlP5Constants.FLOAT;
}
return this;
}
/**
* If the Icon acts as a switch, setOn will turn on
* the switch. Use
* {@link Icon#setSwitch(boolean) setSwitch}
* to turn a Icon into a Switch.
*/
public Icon setOn( ) {
if ( isSwitch ) {
isOn = false;
isActive = true;
activate( );
}
return this;
}
/**
* If the Icon acts as a switch, setOff will turn off
* the switch. Use
* {@link Icon#setSwitch(boolean) setSwitch}
* to turn a Icon into a Switch.
*/
public Icon setOff( ) {
if ( isSwitch ) {
isOn = true;
isActive = true;
activate( );
}
return this;
}
public boolean isOn( ) {
return isOn;
}
public boolean isSwitch( ) {
return isSwitch;
}
public boolean isPressed( ) {
return isPressed;
}
/**
* Returns true or false and indicates the switch state
* of the Icon. {@link setSwitch(boolean) setSwitch}
* should have been set before.
*/
public boolean getBooleanValue( ) {
return isOn;
}
public Icon setRoundedCorners( int theRadius ) {
roundedCorners = theRadius;
return this;
}
public Icon setFontIconSize( int theSize ) {
_myCaptionLabel.setSize( theSize );
return this;
}
public Icon setFont( PFont thePFont ) {
_myCaptionLabel.setFont( thePFont );
return this;
}
public Icon setFont( PFont thePFont , int theSize ) {
_myCaptionLabel.setFont( thePFont );
setFontIconSize( theSize );
return this;
}
public Icon setFontIndex( int theIndex ) {
_myCaptionLabel.set(String.valueOf((char) theIndex));
return this;
}
public Icon setStroke( boolean theBoolean ) {
isStroke = theBoolean;
return this;
}
public Icon setStrokeWeight( float theStrokeWeight ) {
strokeWeight = theStrokeWeight;
return this;
}
public Icon setFill( boolean theBoolean ) {
isFill = theBoolean;
return this;
}
public Icon setFontIcons( int theStateOff , int theStateOn ) {
setFontIcon( theStateOn , ControlP5Constants.ACTIVE );
setFontIcon( theStateOff , ControlP5Constants.DEFAULT );
return this;
}
public Icon setFontIconOn( int theStateOn ) {
setFontIcon( theStateOn , ControlP5Constants.ACTIVE );
return this;
}
public Icon setFontIconOff( int theStateOff ) {
setFontIcon( theStateOff , ControlP5Constants.DEFAULT );
return this;
}
public Icon setFontIcons( int ... theIds ) {
if ( theIds.length < 3 || theIds.length > 4 ) {
return this;
}
setFontIcon( theIds[ 0 ] , ControlP5Constants.DEFAULT );
setFontIcon( theIds[ 1 ] , ControlP5Constants.OVER );
setFontIcon( theIds[ 2 ] , ControlP5Constants.ACTIVE );
setFontIcon( theIds.length == 3 ? theIds[ 2 ] : theIds[ 3 ] , ControlP5Constants.HIGHLIGHT );
return this;
}
public Icon setFontIcon( int theId ) {
return setFontIcon( theId , ControlP5Constants.DEFAULT );
}
public int getFontIcon( int theState ) {
if ( theState >= 0 && theState < 4 ) {
return fontIcons[ theState ];
} else {
return fontIcons[ ControlP5Constants.DEFAULT ];
}
}
/**
* @param theImage
* @param theState use Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active)
*/
public Icon setFontIcon( int theId , int theState ) {
fontIcons[ theState ] = theId;
updateDisplayMode( ControlP5Constants.DEFAULT );
return this;
}
public Icon hideBackground( ) {
isHideBackground = true;
return this;
}
public Icon showBackground( ) {
isHideBackground = false;
return this;
}
public Icon setScale( float theScalePressed , float theScaleReleased ) {
scalePressed = theScalePressed;
scaleReleased = theScaleReleased;
return this;
}
@Override @ControlP5.Invisible public Icon updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
/**
* @exclude
*/
@ControlP5.Invisible public Icon updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( ControlP5Constants.DEFAULT ):
_myControllerView = new IconView( );
break;
case ( ControlP5Constants.IMAGE ):
_myControllerView = new IconImageView( );
break;
case ( ControlP5Constants.CUSTOM ):
default:
break;
}
return this;
}
private class IconView implements ControllerView< Icon > {
public void display( PGraphics theGraphics , Icon theController ) {
if ( !isHideBackground ) {
if ( isStroke ) {
theGraphics.stroke( color.getBackground( ) );
theGraphics.strokeWeight( strokeWeight );
} else {
theGraphics.noStroke( );
}
if ( isFill ) {
theGraphics.fill( color.getBackground( ) );
} else {
theGraphics.noFill( );
}
}
float w_half = getWidth( ) / 2;
float h_half = getHeight( ) / 2;
theGraphics.translate( w_half , h_half );
theGraphics.scale( scl );
if ( !isHideBackground ) {
if ( roundedCorners == 0 ) {
theGraphics.rect( -w_half , -h_half , getWidth( ) , getHeight( ) );
} else if ( roundedCorners == -1 ) {
theGraphics.ellipseMode(PApplet.CORNER);
theGraphics.ellipse( -w_half , -h_half , getWidth( ) , getHeight( ) );
} else {
theGraphics.rect( -w_half , -h_half , getWidth( ) , getHeight( ) , roundedCorners , roundedCorners , roundedCorners , roundedCorners );
}
}
if ( isSwitch ) {
if ( !isOn ) {
setFontIndex( getFontIcon( ControlP5Constants.ACTIVE ) );
} else {
setFontIndex( getFontIcon( ControlP5Constants.DEFAULT ) );
}
} else {
setFontIndex( getFontIcon( ControlP5Constants.DEFAULT ) );
}
_myCaptionLabel.setColor( isOn && isSwitch || isPressed && !isSwitch ? color.getActive( ) : color.getForeground( ) );
_myCaptionLabel.draw( theGraphics , -( int ) w_half , -( int ) ( h_half * 1.05f ) , theController );
}
}
private class IconImageView implements ControllerView< Icon > {
public void display( PGraphics theGraphics , Icon theController ) {
float w_half = getWidth( ) / 2;
float h_half = getHeight( ) / 2;
theGraphics.translate( w_half , h_half );
theGraphics.scale( scl );
if ( isOn && isSwitch ) {
theGraphics.image( (availableImages[ControlP5Constants.HIGHLIGHT]) ? images[ ControlP5Constants.HIGHLIGHT ] : images[ ControlP5Constants.DEFAULT ] , -w_half , -h_half );
return;
}
if ( getIsInside( ) ) {
if ( isPressed ) {
theGraphics.image( (availableImages[ControlP5Constants.ACTIVE]) ? images[ ControlP5Constants.ACTIVE ] : images[ ControlP5Constants.DEFAULT ] , -w_half , -h_half );
} else {
theGraphics.image( (availableImages[ControlP5Constants.OVER]) ? images[ ControlP5Constants.OVER ] : images[ ControlP5Constants.DEFAULT ] , -w_half , -h_half );
}
} else {
theGraphics.image( images[ ControlP5Constants.DEFAULT ] , -w_half , -h_half );
}
}
}
@Override public String getInfo( ) {
return "type:\tIcon\n" + super.getInfo( );
}
@Override public String toString( ) {
return super.toString( ) + " [ " + getValue( ) + " ] " + "Icon" + " (" + this.getClass( ).getSuperclass( ) + ")";
}
}

568
controlP5/Knob.java Executable file
View File

@ -0,0 +1,568 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* A knob is a circular slider which can be used with a limited and unlimited range. Knobs come in 3
* designs LINE, ARC and ELLIPSE and can be controller with both the mouse and the mouse wheel.
*
* @example controllers/ControlP5knob
*/
public class Knob extends Controller< Knob > {
protected float _myDiameter;
protected float _myRadius;
protected float myAngle;
protected float startAngle;
protected float angleRange;
protected float resolution = 200.0f; // sensitivity.
protected int _myTickMarksNum = 8;
protected boolean isShowTickMarks;
protected boolean isSnapToTickMarks;
protected int myTickMarkLength = 2;
protected float myTickMarkWeight = 1;
protected boolean isShowAngleRange = true;
protected float currentValue;
protected float previousValue;
protected float modifiedValue;
protected boolean isConstrained;
protected int _myDragDirection = HORIZONTAL;
protected int viewStyle = LINE;
public static int autoWidth = 39;
public static int autoHeight = 39;
protected float[] autoSpacing = new float[] { 10 , 20 };
private float scrollSensitivity = 1.0f / resolution;
/**
* Convenience constructor to extend Knob.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Knob( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 100 , 0 , 0 , 0 , autoWidth );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
* @exclude
*/
public Knob( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theMin , float theMax , float theDefaultValue , int theX , int theY , int theWidth ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theWidth );
_myValue = theDefaultValue;
setMin( theMin );
setMax( theMax );
_myDiameter = theWidth;
_myRadius = _myDiameter / 2;
_myUnit = ( _myMax - _myMin ) / TWO_PI;
startAngle = HALF_PI + PI * 0.25f;
angleRange = PI + HALF_PI;
myAngle = startAngle;
isConstrained = true;
getCaptionLabel( ).align( CENTER , BOTTOM_OUTSIDE );
setViewStyle( ARC );
}
@Override public Knob setSize( int theWidth , int theHeight ) {
return setRadius( theWidth / 2 );
}
public Knob setRadius( float theValue ) {
_myRadius = theValue;
_myDiameter = _myRadius * 2;
setWidth( ( int ) _myDiameter );
setHeight( ( int ) _myDiameter );
return this;
}
public float getRadius( ) {
return _myRadius;
}
/**
* The start angle is a value between 0 and TWO_PI. By default the start angle is set to HALF_PI
* + PI * 0.25f
*/
public Knob setStartAngle( float theAngle ) {
startAngle = theAngle;
setInternalValue( modifiedValue );
return this;
}
/**
* get the start angle, 0 is at 3 o'clock.
*/
public float getStartAngle( ) {
return startAngle;
}
/**
* set the range in between which the know operates. By default the range is PI + HALF_PI
*/
public Knob setAngleRange( float theRange ) {
angleRange = theRange;
setInternalValue( modifiedValue );
return this;
}
public float getAngleRange( ) {
return angleRange;
}
public float getAngle( ) {
return myAngle;
}
public boolean isShowAngleRange( ) {
return isShowAngleRange;
}
public Knob setShowAngleRange( boolean theValue ) {
isShowAngleRange = theValue;
return this;
}
/**
* Sets the drag direction, when controlling a knob, parameter is either Controller.HORIZONTAL
* or Controller.VERTICAL.
*
* @param theValue
* must be Controller.HORIZONTAL or Controller.VERTICAL
* @return Knob
*/
public Knob setDragDirection( int theValue ) {
if ( theValue == HORIZONTAL ) {
_myDragDirection = HORIZONTAL;
} else {
_myDragDirection = VERTICAL;
}
return this;
}
/**
* Gets the drag direction which is either Controller.HORIZONTAL or Controller.VERTICAL.
*
* @return int returns Controller.HORIZONTAL or Controller.VERTICAL
*/
public int getDragDirection( ) {
return _myDragDirection;
}
/**
* resolution is a sensitivity value when dragging a knob. the higher the value, the more
* sensitive the dragging.
*/
public Knob setResolution( float theValue ) {
resolution = theValue;
return this;
}
public float getResolution( ) {
return resolution;
}
public Knob setNumberOfTickMarks( int theNumber ) {
_myTickMarksNum = theNumber;
showTickMarks( );
return this;
}
public int getNumberOfTickMarks( ) {
return _myTickMarksNum;
}
public Knob showTickMarks( ) {
isShowTickMarks = true;
return this;
}
public Knob hideTickMarks( ) {
isShowTickMarks = false;
return this;
}
public boolean isShowTickMarks( ) {
return isShowTickMarks;
}
public Knob snapToTickMarks( boolean theFlag ) {
isSnapToTickMarks = theFlag;
update( );
return this;
}
public Knob setTickMarkLength( int theLength ) {
myTickMarkLength = theLength;
return this;
}
public int getTickMarkLength( ) {
return myTickMarkLength;
}
public Knob setTickMarkWeight( float theWeight ) {
myTickMarkWeight = theWeight;
return this;
}
public float getTickMarkWeight( ) {
return myTickMarkWeight;
}
public Knob setConstrained( boolean theValue ) {
isConstrained = theValue;
setShowAngleRange(isConstrained);
return this;
}
public boolean isConstrained( ) {
return isConstrained;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public Knob updateInternalEvents( PApplet theApplet ) {
if ( isMousePressed && !cp5.isAltDown( ) ) {
if ( isActive ) {
float c = ( _myDragDirection == HORIZONTAL ) ? _myControlWindow.mouseX - _myControlWindow.pmouseX : _myControlWindow.mouseY - _myControlWindow.pmouseY;
currentValue += ( c ) / resolution;
if ( isConstrained ) {
currentValue = PApplet.constrain( currentValue , 0 , 1 );
}
setInternalValue( currentValue );
}
}
return this;
}
protected void onEnter( ) {
isActive = true;
}
protected void onLeave( ) {
isActive = false;
}
/**
* @exclude {@inheritDoc}
*/
@Override @ControlP5.Invisible public void mousePressed( ) {
float x = x(_myParent.getAbsolutePosition( )) + x(position) + _myRadius;
float y = y(_myParent.getAbsolutePosition( )) + y(position) + _myRadius;
if ( PApplet.dist( x , y , _myControlWindow.mouseX , _myControlWindow.mouseY ) < _myRadius ) {
isActive = true;
if ( PApplet.dist( x , y , _myControlWindow.mouseX , _myControlWindow.mouseY ) > ( _myRadius * 0.6 ) ) {
myAngle = ( PApplet.atan2( _myControlWindow.mouseY - y , _myControlWindow.mouseX - x ) - startAngle );
if ( myAngle < 0 ) {
myAngle = TWO_PI + myAngle;
}
if ( isConstrained ) {
myAngle %= TWO_PI;
}
currentValue = PApplet.map( myAngle , 0 , angleRange , 0 , 1 );
setInternalValue( currentValue );
}
}
}
/**
* @exclude {@inheritDoc}
*/
@Override @ControlP5.Invisible public void mouseReleasedOutside( ) {
isActive = false;
}
@Override public Knob setMin( float theValue ) {
_myMin = theValue;
return this;
}
@Override public Knob setMax( float theValue ) {
_myMax = theValue;
return this;
}
public Knob setRange( float theMin , float theMax ) {
setMin( theMin );
setMax( theMax );
update( );
return this;
}
protected void setInternalValue( float theValue ) {
modifiedValue = ( isSnapToTickMarks ) ? PApplet.round( ( theValue * _myTickMarksNum ) ) / ( ( float ) _myTickMarksNum ) : theValue;
currentValue = theValue;
myAngle = PApplet.map( isSnapToTickMarks ? modifiedValue : currentValue , 0 , 1 , startAngle , startAngle + angleRange );
if ( isSnapToTickMarks ) {
if ( previousValue != modifiedValue && isSnapToTickMarks ) {
broadcast( FLOAT );
_myValueLabel.set( adjustValue( getValue( ) ) );
previousValue = modifiedValue;
return;
}
}
if ( previousValue != currentValue ) {
broadcast( FLOAT );
_myValueLabel.set( adjustValue( getValue( ) ) );
previousValue = modifiedValue;
}
}
@Override public Knob setValue( float theValue ) {
theValue = PApplet.map( theValue , _myMin , _myMax , 0 , 1 );
if ( isConstrained ) {
theValue = PApplet.constrain( theValue , 0 , 1 );
}
_myValueLabel.set( adjustValue( getValue( ) ) );
setInternalValue( theValue );
return this;
}
@Override public float getValue( ) {
_myValue = PApplet.map( _myTickMarksNum > 0 ? modifiedValue : currentValue , 0 , 1 , _myMin , _myMax );
return _myValue;
}
/**
* Assigns a random value to the controller.
*/
public Knob shuffle( ) {
float r = ( float ) Math.random( );
setValue( PApplet.map( r , 0 , 1 , getMin( ) , getMax( ) ) );
return this;
}
/**
* Sets the sensitivity for the scroll behavior when using the mouse wheel or the scroll
* function of a multi-touch track pad. The smaller the value (closer to 0) the higher the
* sensitivity.
*
* @param theValue
* @return Knob
*/
public Knob setScrollSensitivity( float theValue ) {
scrollSensitivity = theValue;
return this;
}
/**
* Changes the value of the knob when hovering and using the mouse wheel or the scroll function
* of a multi-touch track pad.
*/
@ControlP5.Invisible public Knob scrolled( int theRotationValue ) {
float f = getValue( );
float steps = isSnapToTickMarks ? ( 1.0f / getNumberOfTickMarks( ) ) : scrollSensitivity;
f += ( getMax( ) - getMin( ) ) * ( -theRotationValue * steps );
setValue( f );
return this;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public Knob update( ) {
setValue( _myValue );
return this;
}
/**
* set the display style of a knob. takes parameters Knob.LINE, Knob.ELLIPSE or Knob.ARC.
* default style is Knob.LINE
*
* @param theStyle
* use Knob.LINE, Knob.ELLIPSE or Knob.ARC
* @return Knob
*/
public Knob setViewStyle( int theStyle ) {
viewStyle = theStyle;
return this;
}
public int getViewStyle( ) {
return viewStyle;
}
/**
* @exclude {@inheritDoc}
*/
@Override @ControlP5.Invisible public Knob updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new KnobView( );
break;
case ( SPRITE ):
case ( IMAGE ):
_myControllerView = new KnobView( );
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
class KnobView implements ControllerView< Knob > {
public void display( PGraphics theGraphics , Knob theController ) {
theGraphics.translate( ( int ) getRadius( ) , ( int ) getRadius( ) );
theGraphics.pushMatrix( );
theGraphics.ellipseMode( PApplet.CENTER );
theGraphics.noStroke( );
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.ellipse( 0 , 0 , getRadius( ) * 2 , getRadius( ) * 2 );
theGraphics.popMatrix( );
int c = isActive( ) ? getColor( ).getActive( ) : getColor( ).getForeground( );
theGraphics.pushMatrix( );
if ( getViewStyle( ) == LINE) {
theGraphics.rotate( getAngle( ) );
theGraphics.stroke( c );
theGraphics.strokeWeight( getTickMarkWeight( ) );
theGraphics.line( 0 , 0 , getRadius( ) , 0 );
} else if ( getViewStyle( ) == ELLIPSE) {
theGraphics.rotate( getAngle( ) );
theGraphics.fill( c );
theGraphics.ellipse( getRadius( ) * 0.75f , 0 , getRadius( ) * 0.2f , getRadius( ) * 0.2f );
} else if ( getViewStyle( ) == ARC) {
theGraphics.fill( c );
theGraphics.arc( 0 , 0 , getRadius( ) * 1.8f , getRadius( ) * 1.8f , getStartAngle( ) , getAngle( ) + ( ( getStartAngle( ) == getAngle( ) ) ? 0.06f : 0f ) );
theGraphics.fill( theGraphics.red( getColor( ).getBackground( ) ) , theGraphics.green( getColor( ).getBackground( ) ) , theGraphics.blue( getColor( ).getBackground( ) ) , 255 );
theGraphics.ellipse( 0 , 0 , getRadius( ) * 1.2f , getRadius( ) * 1.2f );
}
theGraphics.popMatrix( );
theGraphics.pushMatrix( );
theGraphics.rotate( getStartAngle( ) );
if ( isShowTickMarks( ) ) {
float step = getAngleRange( ) / getNumberOfTickMarks( );
theGraphics.stroke( getColor( ).getForeground( ) );
theGraphics.strokeWeight( getTickMarkWeight( ) );
for ( int i = 0 ; i <= getNumberOfTickMarks( ) ; i++ ) {
theGraphics.line( getRadius( ) + 2 , 0 , getRadius( ) + getTickMarkLength( ) + 2 , 0 );
theGraphics.rotate( step );
}
} else {
if ( isShowAngleRange( ) ) {
theGraphics.stroke( getColor( ).getForeground( ) );
theGraphics.strokeWeight( getTickMarkWeight( ) );
theGraphics.line( getRadius( ) + 2 , 0 , getRadius( ) + getTickMarkLength( ) + 2 , 0 );
theGraphics.rotate( getAngleRange( ) );
theGraphics.line( getRadius( ) + 2 , 0 , getRadius( ) + getTickMarkLength( ) + 2 , 0 );
}
}
theGraphics.noStroke( );
theGraphics.popMatrix( );
theGraphics.pushMatrix( );
theGraphics.translate( -getWidth( ) / 2 , -getHeight( ) / 2 );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
_myValueLabel.align(CENTER, CENTER);
_myValueLabel.draw( theGraphics , 0 , 0 , theController );
}
theGraphics.popMatrix( );
}
}
/**
* @exclude
* @deprecated
*/
@Deprecated public Knob setOffsetAngle( float theValue ) {
return setStartAngle( theValue );
}
/**
* @exclude
* @deprecated
*/
@Deprecated public float value( ) {
return getValue( );
}
/**
* @exclude
* @deprecated
*/
@Deprecated public Knob setDisplayStyle( int theStyle ) {
viewStyle = theStyle;
return this;
}
/**
* @exclude
* @deprecated
*/
@Deprecated public int getDisplayStyle( ) {
return viewStyle;
}
/**
* @exclude
* @deprecated
*/
@Deprecated @ControlP5.Invisible public Knob setSensitivity( float theValue ) {
scrollSensitivity = theValue;
return this;
}
/**
* @exclude
* @deprecated
*/
@Deprecated public Knob showTickMarks( boolean theFlag ) {
isShowTickMarks = theFlag;
return this;
}
}
/* settings for:
*
* TODO tickmarks: distance from edge
*
* TODO only start-end marks if isLimited and tickmarks are off.
*
* TODO arc: add setter for distance to center + distance to edge currently percental.
*
* TODO enable/disable drag and click control (for endless, click should be disabled).
*
* TODO dragging: add another option to control the knob. currently only linear dragging is
* implemented, add circular dragging (as before) as well */
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#updateInternalEvents(processing.core.PApplet) */

542
controlP5/Label.java Executable file
View File

@ -0,0 +1,542 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser
* General Public License as published by the Free Software
* Foundation; either version 2.1 of the License, or (at
* your option) any later version. This library is
* distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place,
* Suite 330, Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PFont;
import processing.core.PGraphics;
/**
* A custom label using controlP5's BitFonts or PFont based
* ControlFonts.
*
*
* @see ControlFont
* @example controllers/ControlP5Textlabel
*
*/
public class Label implements CDrawable {
public static boolean isToUpperCaseDefault = true;
protected int _myLetterSpacing = 0;
protected boolean isMultiline;
protected boolean isFixedSize;
protected ControllerStyle _myControllerStyle = new ControllerStyle( );
protected boolean isVisible = true;
protected int _myColor = 0xffffffff;
protected boolean isColorBackground;
protected boolean isToUpperCase = isToUpperCaseDefault;
protected boolean changed;
protected int _myColorBackground = 0xffffffff;
protected int _myHeight = -1;
protected int _myWidth = -1;
protected String _myText = "";
protected ControlFont _myFontLabel;
protected int _myLineHeight = 0;
protected int alignX = ControlP5.LEFT;
protected int alignY = ControlP5.LEFT;
protected int textAlign = ControlP5.LEFT;
public static int paddingX = 4;
public static int paddingY = 4;
public int _myPaddingX = paddingX;
public int _myPaddingY = paddingY;
protected Labeltype _myLabeltype;
protected int _myTextHeight = 1;
protected float offsetYratio = 0;
private ControlP5 cp5;
private Label( Label theLabel ) {
_myText = theLabel.getText( );
isToUpperCase = theLabel.isToUpperCase( );
_myLetterSpacing = theLabel.getLetterSpacing( );
_myLineHeight = theLabel.getLineHeight( );
_myFontLabel = theLabel.getFont( );
_myLabeltype = theLabel.getLabeltype( );
}
public Label( ControlP5 theControlP5 , String theValue ) {
init( theControlP5 , theValue , 0 , 0 , _myColor );
}
public Label( ControlP5 theControlP5 , String theValue , int theWidth , int theHeight , int theColor ) {
init( theControlP5 , theValue , theWidth , theHeight , theColor );
}
private void init( ControlP5 theControlP5 , String theValue , int theWidth , int theHeight , int theColor ) {
cp5 = theControlP5;
_myWidth = theWidth;
_myHeight = theHeight;
_myText = theValue;
_myColor = theColor;
setLabeltype( new SinglelineLabel( ) );
setFont( cp5.controlFont );
setLabeltype( new SinglelineLabel( ) );
set( _myText );
_myControllerStyle = new ControllerStyle( );
}
Label setLabeltype( Labeltype theType ) {
_myLabeltype = theType;
return this;
}
Labeltype getLabeltype( ) {
return _myLabeltype;
}
public Label align( int[] a ) {
alignX = a[ 0 ];
alignY = a[ 1 ];
return this;
}
public Label align( int theX , int theY ) {
alignX = theX;
alignY = theY;
return this;
}
public Label alignX( int theX ) {
alignX = theX;
return this;
}
public Label alignY( int theY ) {
alignY = theY;
return this;
}
public int[] getAlign( ) {
return new int[] { alignX , alignY };
}
public Label setPadding( int thePaddingX , int thePaddingY ) {
_myPaddingX = thePaddingX;
_myPaddingY = thePaddingY;
return this;
}
public Label setPaddingX( int thePaddingX ) {
_myPaddingX = thePaddingX;
return this;
}
public Label setPaddingY( int thePaddingY ) {
_myPaddingY = thePaddingY;
return this;
}
public void draw( PGraphics theGraphics , int theX , int theY , ControllerInterface< ? > theController ) {
if ( isVisible ) {
getLabeltype( ).draw( this , theGraphics , theX , theY , theController );
}
}
public void draw( PGraphics theGraphics , int theX , int theY , int theW , int theH ) {
if ( isVisible ) {
getLabeltype( ).draw( this , theGraphics , theX , theY , theW , theH );
}
}
@Override public void draw( PGraphics theGraphics ) {
if ( isVisible ) {
_myFontLabel.adjust( theGraphics , this );
draw( theGraphics , 0 , 0 );
}
}
public void draw( PGraphics theGraphics , int theX , int theY ) {
if ( isVisible ) {
theGraphics.pushMatrix( );
theGraphics.translate( _myControllerStyle.marginLeft , _myControllerStyle.marginTop );
theGraphics.translate( theX , theY );
if ( isColorBackground ) {
float ww = getStyle( ).paddingRight + getStyle( ).paddingLeft;
if ( getStyle( ).backgroundWidth > -1 ) {
ww += _myControllerStyle.backgroundWidth;
} else {
ww += _myFontLabel.getWidth( );
}
float hh = getStyle( ).paddingBottom + getStyle( ).paddingTop;
if ( getStyle( ).backgroundHeight > -1 ) {
hh += getStyle( ).backgroundHeight;
} else {
hh += _myFontLabel.getHeight( );
}
theGraphics.fill( _myColorBackground );
theGraphics.rect( 0 , 1 , ww , hh );
}
theGraphics.translate( _myControllerStyle.paddingLeft , _myControllerStyle.paddingTop );
_myFontLabel.draw( theGraphics , this );
theGraphics.popMatrix( );
}
}
public Label hide( ) {
return setVisible( false );
}
public Label show( ) {
return setVisible( true );
}
public Label setVisible( boolean theValue ) {
isVisible = theValue;
return this;
}
public Label updateFont( ControlFont theFont ) {
return setFont( theFont );
}
public Label set( String theValue ) {
return setText( theValue );
}
public Label setText( String theValue ) {
_myText = theValue;
setChanged( true );
return this;
}
public Label setFixedSize( boolean theValue ) {
isFixedSize = theValue;
return this;
}
public boolean isFixedSize( ) {
return !isMultiline && isFixedSize;
}
public String getText( ) {
return _myText;
}
public String getTextFormatted( ) {
return getLabeltype( ).getTextFormatted( );
}
public ControllerStyle getStyle( ) {
return _myControllerStyle;
}
public Label setWidth( int theWidth ) {
_myWidth = theWidth;
setChanged( true );
return this;
}
public Label setHeight( int theHeight ) {
_myHeight = theHeight;
setChanged( true );
return this;
}
public int getWidth( ) {
return _myLabeltype.getWidth( );
}
public int getHeight( ) {
return _myLabeltype.getHeight( );
}
public int getOverflow( ) {
return getLabeltype( ).getOverflow( );
}
public Label setMultiline( boolean theValue ) {
isMultiline = theValue;
_myLabeltype = ( isMultiline ) ? new MultilineLabel( ) : new SinglelineLabel( );
return this;
}
public Label toUpperCase( boolean theValue ) {
isToUpperCase = theValue;
setChanged( true );
return this;
}
public ControlFont getFont( ) {
return _myFontLabel;
}
public Label setFont( int theBitFontIndex ) {
ControlP5.logger.warning( "BitFont is now of type PFont, use setFont(PFont) instead." );
return this;
}
public Label setFont( PFont thePFont ) {
return setFont( new ControlFont( thePFont ) );
}
public Label setFont( ControlFont theFont ) {
setLineHeight( theFont.getSize( ) );
_myFontLabel = new ControlFont( theFont.getFont( ) , theFont.getSize( ) );
_myFontLabel.init( this );
setChanged( true );
return this;
}
public Label setSize( int theSize ) {
_myFontLabel.setSize( theSize );
return this;
}
protected boolean isChanged( ) {
return changed;
}
protected Label setChanged( boolean theValue ) {
changed = theValue;
return this;
}
Label setTextHeight( int theHeight ) {
_myTextHeight = theHeight;
return this;
}
public int getTextHeight( ) {
return _myFontLabel.getTextHeight( );
}
public int getLineHeight( ) {
return _myLineHeight;
}
public Label setOffsetY( int theValue ) {
return this;
}
public Label setOffsetYratio( float theValue ) {
offsetYratio = theValue;
setChanged( true );
return this;
}
public float getOffsetYratio( ) {
return offsetYratio;
}
public Label setLineHeight( int theValue ) {
_myLineHeight = theValue;
setChanged( true );
return this;
}
public Label setColor( int theValue , boolean theFlag ) {
setColor( theValue );
setFixedSize( theFlag );
return this;
}
public Label setColor( int theColor ) {
_myColor = theColor;
setChanged( true );
return this;
}
public int getColor( ) {
return _myColor;
}
public Label setColorBackground( int theColor ) {
enableColorBackground( );
_myColorBackground = theColor;
return this;
}
public Label disableColorBackground( ) {
isColorBackground = false;
return this;
}
public Label enableColorBackground( ) {
isColorBackground = true;
return this;
}
public int getLetterSpacing( ) {
return _myLetterSpacing;
}
public Label setLetterSpacing( int theValue ) {
_myLetterSpacing = theValue;
setChanged( true );
return this;
}
public boolean isMultiline( ) {
return isMultiline;
}
public boolean isVisible( ) {
return isVisible;
}
public boolean isToUpperCase( ) {
return isToUpperCase;
}
protected Label copy( ) {
return new Label( this );
}
public static void setUpperCaseDefault( boolean theValue ) {
isToUpperCaseDefault = theValue;
}
interface Labeltype {
void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , ControllerInterface< ? > theController );
void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , int theW , int theH );
int getWidth( );
int getHeight( );
int getOverflow( );
String getTextFormatted( );
}
class SinglelineTextfield extends SinglelineLabel {
public String getTextFormatted( ) {
return _myText;
}
}
class SinglelineLabel implements Labeltype {
private void align( PGraphics theGraphics , int theAlignX , int theAlignY , int theW , int theH ) {
int x = 0;
int y = 0;
switch ( theAlignX ) {
case ( ControlP5.CENTER ):
x = ( theW - _myFontLabel.getWidth( ) ) / 2;
break;
case ( ControlP5.LEFT ):
x = _myPaddingX;
break;
case ( ControlP5.RIGHT ):
x = theW - _myFontLabel.getWidth( ) - _myPaddingX;
break;
case ( ControlP5.LEFT_OUTSIDE ):
x = -_myFontLabel.getWidth( ) - _myPaddingX;
break;
case ( ControlP5.RIGHT_OUTSIDE ):
x = theW + _myPaddingX;
break;
}
switch ( theAlignY ) {
case ( ControlP5.CENTER ):
y = theH / 2 + _myFontLabel.getTop( ) - _myFontLabel.getCenter( );
break;
case ( ControlP5.TOP ):
y = 0;
break;
case ( ControlP5.BOTTOM ):
y = theH - _myFontLabel.getHeight( ) - 1;
break;
case ( ControlP5.BASELINE ):
y = theH + _myFontLabel.getTop( ) - 1;
break;
case ( ControlP5.BOTTOM_OUTSIDE ):
y = theH + _myPaddingY;
break;
case ( ControlP5.TOP_OUTSIDE ):
y = -_myFontLabel.getHeight( ) - _myPaddingY;
break;
}
theGraphics.translate( x , y );
}
@Override public void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , int theW , int theH ) {
_myFontLabel.adjust( theGraphics , theLabel );
theGraphics.pushMatrix( );
align( theGraphics , alignX , alignY , theW , theH );
theLabel.draw( theGraphics , theX , theY );
theGraphics.popMatrix( );
}
@Override public void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , ControllerInterface< ? > theController ) {
draw( theLabel , theGraphics , theX , theY , theController.getWidth( ) , theController.getHeight( ) );
}
@Override public int getWidth( ) {
return isFixedSize ? _myWidth : _myFontLabel.getWidth( );
}
@Override public int getHeight( ) {
return _myFontLabel.getHeight( );
}
@Override public int getOverflow( ) {
return -1;
}
@Override public String getTextFormatted( ) {
return ( isToUpperCase ? _myText.toUpperCase( ) : _myText );
}
}
class MultilineLabel implements Labeltype {
@Override public void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , int theW , int theH ) {
_myFontLabel.adjust( theGraphics , theLabel );
theLabel.draw( theGraphics , theX , theY );
}
@Override public void draw( Label theLabel , PGraphics theGraphics , int theX , int theY , ControllerInterface< ? > theController ) {
_myFontLabel.adjust( theGraphics , theLabel );
theLabel.draw( theGraphics , theX , theY );
}
@Override public int getWidth( ) {
return _myWidth;
}
@Override public int getHeight( ) {
return _myHeight;
}
@Override public int getOverflow( ) {
return _myFontLabel.getOverflow( );
}
@Override public String getTextFormatted( ) {
return ( isToUpperCase ? _myText.toUpperCase( ) : _myText );
}
}
}

469
controlP5/ListBox.java Executable file
View File

@ -0,0 +1,469 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import static main.java.src2.main.java.controlP5.controlP5.ControlP5.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.event.KeyEvent;
/**
* A ListBox is a list of vertically aligned items which can be scrolled if required.
*
* @see ListBox
* @example controllers/ControlP5listBox
*/
public class ListBox extends Controller< ListBox > implements ControlListener {
private int _myType = LIST;
protected int _myBackgroundColor = 0x00ffffff;
protected int itemHeight = 13;
protected int barHeight = 10;
private float scrollSensitivity = 1;
private boolean isOpen = true;
protected List< Map< String , Object > > items;
protected int itemRange = 5;
protected int itemHover = -1;
private int itemIndexOffset = 0;
private final int itemSpacing = 1;
private int _myDirection = PApplet.DOWN;
private boolean isBarVisible = true;
static public final int LIST = ControlP5.LIST;
static public final int DROPDOWN = ControlP5.DROPDOWN;
static public final int CHECKBOX = ControlP5.CHECKBOX; /* TODO */
static public final int TREE = ControlP5.TREE; /* TODO */
public ListBox( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 199 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected ListBox( ControlP5 theControlP5 , ControllerGroup< ? > theGroup , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theGroup , theName , theX , theY , theW , theH );
items = new ArrayList< Map< String , Object > >( );
updateHeight( );
}
public boolean isOpen( ) {
return isOpen;
}
public ListBox open( ) {
return setOpen( true );
}
public ListBox close( ) {
return setOpen( false );
}
public ListBox setOpen( boolean b ) {
isOpen = b;
return this;
}
@Override public int getHeight( ) {
return isOpen ? super.getHeight( ) : barHeight;
}
public ListBox setType( int theType ) {
_myType = theType;
return this;
}
public void setDirection( int theDirection ) {
_myDirection = ( theDirection == PApplet.UP ) ? PApplet.UP : PApplet.DOWN;
}
@Override protected boolean inside( ) {
/* constrain the bounds of the controller to the
* dimensions of the cp5 area, required since
* PGraphics as render area has been introduced. */
float x0 = PApplet.max( 0 , x( position ) + x( _myParent.getAbsolutePosition( ) ) );
float x1 = PApplet.min( cp5.pgw , x( position ) + x( _myParent.getAbsolutePosition( ) ) + getWidth( ) );
float y0 = PApplet.max( 0 , y( position ) + y( _myParent.getAbsolutePosition( ) ) );
float y1 = PApplet.min( cp5.pgh , y( position ) + y( _myParent.getAbsolutePosition( ) ) + getHeight( ) );
if ( y1 < y0 ) {
float ty = y0;
y0 = y1;
y1 = ty;
}
return ( _myControlWindow.mouseX > x0 && _myControlWindow.mouseX < x1 && _myControlWindow.mouseY > ( y1 < y0 ? y1 : y0 ) && _myControlWindow.mouseY < ( y0 < y1 ? y1 : y0 ) );
}
@Override protected void onRelease( ) {
if ( !isDragged ) {
if ( getPointer( ).y( ) >= 0 && getPointer( ).y( ) <= barHeight ) {
setOpen( !isOpen( ) );
} else if ( isOpen ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
// n += itemRange; /* UP */
int index = ( int ) n + itemIndexOffset;
Map m = items.get( index );
switch ( _myType ) {
case ( LIST ):
setValue( index );
for ( Object o : items ) {
( ( Map ) o ).put( "state" , false );
}
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
case ( DROPDOWN ):
setValue( index );
setOpen( false );
getCaptionLabel( ).setText( ( m.get( "text" ).toString( ) ) );
break;
case ( CHECKBOX ):
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
}
}
}
}
@Override protected void onDrag( ) {
scroll( getPointer( ).dy( ) );
}
@Override protected void onScroll( int theValue ) {
scroll( theValue );
}
private void scroll( int theValue ) {
if ( isOpen ) {
itemIndexOffset += theValue;
itemIndexOffset = ( int ) ( Math.floor( Math.max( 0 , Math.min( itemIndexOffset , items.size( ) - itemRange ) ) ) );
itemHover = -2;
}
}
@Override protected void onLeave( ) {
itemHover = -1;
}
private void updateHover( ) {
if ( getPointer( ).y( ) > barHeight ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
itemHover = ( int ) ( itemIndexOffset + n );
} else {
itemHover = -1;
}
}
@Override protected void onEnter( ) {
updateHover( );
}
@Override protected void onMove( ) {
updateHover( );
}
@Override protected void onEndDrag( ) {
updateHover( );
}
private int updateHeight( ) {
itemRange = ( PApplet.abs( getHeight( ) ) - ( isBarVisible( ) ? barHeight : 0 ) ) / itemHeight;
return itemHeight * ( items.size( ) < itemRange ? items.size( ) : itemRange );
}
public ListBox setItemHeight( int theHeight ) {
itemHeight = theHeight;
updateHeight( );
return this;
}
public ListBox setBarHeight( int theHeight ) {
barHeight = theHeight;
updateHeight( );
return this;
}
public int getBarHeight( ) {
return barHeight;
}
public ListBox setScrollSensitivity( float theSensitivity ) {
scrollSensitivity = theSensitivity;
return this;
}
public ListBox setBarVisible( boolean b ) {
isBarVisible = b;
updateHeight( );
return this;
}
public boolean isBarVisible( ) {
return isBarVisible;
}
private Map< String , Object > getDefaultItemMap( String theName , Object theValue ) {
Map< String , Object > item = new HashMap< String , Object >( );
item.put( "name" , theName );
item.put( "text" , theName );
item.put( "value" , theValue );
item.put( "color" , getColor( ) );
item.put( "view" , new CDrawable( ) {
@Override public void draw( PGraphics theGraphics ) {
}
} );
item.put( "state" , false );
return item;
}
public ListBox addItem( String theName , Object theValue ) {
Map< String , Object > item = getDefaultItemMap( theName , theValue );
items.add( item );
return this;
}
public ListBox addItems( String[] theItems ) {
addItems( Arrays.asList( theItems ) );
return this;
}
public ListBox addItems( List< String > theItems ) {
for ( int i = 0 ; i < theItems.size( ) ; i++ ) {
addItem(theItems.get( i ), i );
}
return this;
}
public ListBox addItems( Map< String , Object > theItems ) {
for ( Map.Entry< String , Object > item : theItems.entrySet( ) ) {
addItem( item.getKey( ) , item.getValue( ) );
}
return this;
}
public ListBox setItems( String[] theItems ) {
setItems( Arrays.asList( theItems ) );
return this;
}
public ListBox setItems( List< String > theItems ) {
items.clear( );
return addItems( theItems );
}
public ListBox setItems( Map< String , Object > theItems ) {
items.clear( );
return addItems( theItems );
}
public ListBox removeItems( List< String > theItems ) {
for ( String s : theItems ) {
removeItem( s );
}
return this;
}
public ListBox removeItem( String theName ) {
if ( theName != null ) {
List l = new ArrayList( );
for ( Map m : items ) {
if ( theName.equals( m.get( "name" ) ) ) {
l.add( m );
}
}
items.removeAll( l );
}
return this;
}
public void updateItemIndexOffset( ) {
int m1 = items.size( ) > itemRange ? ( itemIndexOffset + itemRange ) : items.size( );
int n = ( m1 - items.size( ) );
if ( n >= 0 ) {
itemIndexOffset -= n;
}
}
public Map< String , Object > getItem( int theIndex ) {
return items.get( theIndex );
}
public Map< String , Object > getItem( String theName ) {
if ( theName != null ) {
for ( Map< String , Object > o : items ) {
if ( theName.equals( o.get( "name" ) ) ) {
return o;
}
}
}
return Collections.EMPTY_MAP;
}
public List getItems( ) {
return Collections.unmodifiableList( items );
}
public ListBox clear( ) {
for ( int i = items.size( ) - 1 ; i >= 0 ; i-- ) {
items.remove( i );
}
items.clear( );
itemIndexOffset = 0;
return this;
}
@Override public void controlEvent( ControlEvent theEvent ) {
// TODO Auto-generated method stub
}
public ListBox setBackgroundColor( int theColor ) {
_myBackgroundColor = theColor;
return this;
}
public int getBackgroundColor( ) {
return _myBackgroundColor;
}
@Override @ControlP5.Invisible public ListBox updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new ListBoxView( );
break;
case ( IMAGE ):
case ( SPRITE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
static public class ListBoxView implements ControllerView< ListBox > {
public void display( PGraphics g , ListBox c ) {
// setHeight( -200 ); /* UP */
g.noStroke( );
if ( c.isBarVisible( ) ) {
boolean b = c.itemHover == -1 && c.isInside && !c.isDragged;
g.fill( b ? c.getColor( ).getForeground( ) : c.getColor( ).getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.barHeight );
g.pushMatrix( );
g.translate( c.getWidth( ) - 8 , c.barHeight / 2 - 2 );
g.fill( c.getColor( ).getCaptionLabel( ) );
if ( c.isOpen( ) ) {
g.triangle( -3 , 0 , 3 , 0 , 0 , 3 );
} else {
g.triangle( -3 , 3 , 3 , 3 , 0 , 0 );
}
g.popMatrix( );
c.getCaptionLabel( ).align( PApplet.LEFT , PApplet.CENTER ).draw( g , 4 , c.barHeight / 2 );
}
if ( c.isOpen( ) ) {
int bar = ( c.isBarVisible( ) ? c.barHeight : 0 );
int h = ( ( c.updateHeight( ) ) );
g.pushMatrix( );
// g.translate( 0 , - ( h + bar +
// c.itemSpacing ) ); /* UP */
g.fill( c.getBackgroundColor( ) );
g.rect( 0 , bar , c.getWidth( ) , h );
g.pushMatrix( );
g.translate( 0 , ( bar == 0 ? 0 : ( c.barHeight + c.itemSpacing ) ) );
/* draw visible items */
c.updateItemIndexOffset( );
int m0 = c.itemIndexOffset;
int m1 = c.items.size( ) > c.itemRange ? ( c.itemIndexOffset + c.itemRange ) : c.items.size( );
for ( int i = m0 ; i < m1 ; i++ ) {
Map< String , Object > item = c.items.get( i );
CColor color = ( CColor ) item.get( "color" );
g.fill( ( ControlP5.b( item.get( "state" ) ) ) ? color.getActive( ) : ( i == c.itemHover ) ? ( c.isMousePressed ? color.getActive( ) : color.getForeground( ) ) : color.getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.itemHeight - 1 );
c.getValueLabel( ).align( PApplet.LEFT , PApplet.CENTER ).set( item.get( "text" ).toString( ) ).draw( g , 4 , c.itemHeight / 2 );
g.translate( 0 , c.itemHeight );
}
g.popMatrix( );
if ( c.isInside ) {
int m = c.items.size( ) - c.itemRange;
if ( m > 0 ) {
g.fill( c.getColor( ).getCaptionLabel( ) );
g.pushMatrix( );
int s = 4; /* spacing */
int s2 = s / 2;
g.translate( c.getWidth( ) - s , c.barHeight );
int len = ( int ) PApplet.map( ( float ) Math.log( m * 10 ) , 0 , 10 , h , 0 );
int pos = ( int ) ( PApplet.map( c.itemIndexOffset , 0 , m , s2 , h - len - s2 ) );
g.rect( 0 , pos , s2 , len );
g.popMatrix( );
}
}
g.popMatrix( );
}
}
}
public void keyEvent( KeyEvent theKeyEvent ) {
if ( isInside && theKeyEvent.getAction( ) == KeyEvent.PRESS ) {
switch ( theKeyEvent.getKeyCode( ) ) {
case (UP):
scroll( theKeyEvent.isAltDown( ) ? -itemIndexOffset : theKeyEvent.isShiftDown( ) ? -10 : -1 );
updateHover( );
break;
case (DOWN):
scroll( theKeyEvent.isAltDown( ) ? items.size( ) - itemRange : theKeyEvent.isShiftDown( ) ? 10 : 1 );
updateHover( );
break;
case (LEFT):
break;
case (RIGHT):
break;
case (ENTER):
onRelease( );
break;
}
}
}
/* TODO keycontrol: arrows, return dragging moving items
* sorting custom view custom event types */
}

422
controlP5/Matrix.java Executable file
View File

@ -0,0 +1,422 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* A matrix is a 2d array with a pointer that traverses through the matrix in a timed interval. if
* an item of a matrix-column is active, the x and y position of the corresponding cell will trigger
* an event and notify the program. see the ControlP5matrix example for more information.
*
* @example controllers/ControlP5matrix
*/
public class Matrix extends Controller< Matrix > {
protected int cnt;
protected int[][] _myCells;
protected int stepX;
protected int stepY;
protected int cellX;
protected int cellY;
protected boolean isPressed;
protected int _myCellX;
protected int _myCellY;
protected int sum;
protected int _myInterval = 100;
protected int currentX = -1;
protected int currentY = -1;
protected int _myMode = SINGLE_ROW;
private Thread t;
protected int gapX = 1;
protected int gapY = 1;
private Object _myPlug;
private String _myPlugName;
private boolean playing = true;
private int bg = 0x00000000;
/**
* Convenience constructor to extend Matrix.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Matrix( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 10 , 10 , 0 , 0 , 100 , 100 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public Matrix( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theCellX , int theCellY , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myInterval = 100;
setGrid( theCellX , theCellY );
_myPlug = cp5.papplet;
_myPlugName = getName( );
_myCaptionLabel.align(LEFT, BOTTOM_OUTSIDE);
_myCaptionLabel.setPadding( 0 , 4 );
runThread( );
}
public Matrix setGrid( int theCellX , int theCellY ) {
_myCellX = theCellX;
_myCellY = theCellY;
sum = _myCellX * _myCellY;
stepX = getWidth( ) / _myCellX;
stepY = getHeight( ) / _myCellY;
_myCells = new int[ _myCellX ][ _myCellY ];
for ( int x = 0 ; x < _myCellX ; x++ ) {
for ( int y = 0 ; y < _myCellY ; y++ ) {
_myCells[ x ][ y ] = 0;
}
}
return this;
}
/**
* set the speed of intervals in millis iterating through the matrix.
*
* @param theInterval int
* @return Matrix
*/
public Matrix setInterval( int theInterval ) {
_myInterval = theInterval;
return this;
}
public int getInterval( ) {
return _myInterval;
}
@ControlP5.Invisible public Matrix updateInternalEvents( PApplet theApplet ) {
setIsInside( inside( ) );
if ( getIsInside( ) ) {
if ( isPressed ) {
int tX = ( int ) ( ( theApplet.mouseX - x( position ) ) / stepX );
int tY = ( int ) ( ( theApplet.mouseY - y( position ) ) / stepY );
if ( tX != currentX || tY != currentY ) {
tX = PApplet.min( PApplet.max( 0 , tX ) , _myCellX );
tY = PApplet.min( PApplet.max( 0 , tY ) , _myCellY );
boolean isMarkerActive = _myCells[tX][tY] == 1;
switch ( _myMode ) {
default:
case ( SINGLE_COLUMN ):
for ( int i = 0 ; i < _myCellY ; i++ ) {
_myCells[ tX ][ i ] = 0;
}
_myCells[ tX ][ tY ] = ( !isMarkerActive ) ? 1 : _myCells[ tX ][ tY ];
break;
case ( SINGLE_ROW ):
for ( int i = 0 ; i < _myCellY ; i++ ) {
_myCells[ tX ][ i ] = 0;
}
_myCells[ tX ][ tY ] = ( !isMarkerActive ) ? 1 : _myCells[ tX ][ tY ];
break;
case ( MULTIPLES ):
_myCells[ tX ][ tY ] = ( _myCells[ tX ][ tY ] == 1 ) ? 0 : 1;
break;
}
currentX = tX;
currentY = tY;
}
}
}
return this;
}
protected void onEnter( ) {
isActive = true;
}
protected void onLeave( ) {
isActive = false;
}
@ControlP5.Invisible public void mousePressed( ) {
isActive = getIsInside( );
if ( getIsInside( ) ) {
isPressed = true;
}
}
protected void mouseReleasedOutside( ) {
mouseReleased( );
}
@ControlP5.Invisible public void mouseReleased( ) {
if ( isActive ) {
isActive = false;
}
isPressed = false;
currentX = -1;
currentY = -1;
}
@Override public Matrix setValue( float theValue ) {
_myValue = theValue;
broadcast( FLOAT );
return this;
}
public Matrix play( ) {
playing = true;
return this;
}
public boolean isPlaying( ) {
return playing;
}
public Matrix pause( ) {
playing = false;
return this;
}
public Matrix stop( ) {
playing = false;
cnt = 0;
return this;
}
public Matrix trigger( int theColumn ) {
if ( theColumn < 0 || theColumn >= _myCells.length ) {
return this;
}
for ( int i = 0 ; i < _myCellY ; i++ ) {
if ( _myCells[ theColumn ][ i ] == 1 ) {
_myValue = 0;
_myValue = ( theColumn << 0 ) + ( i << 8 );
setValue( _myValue );
/* TODO remove printStack and replace with Logger */
try {
Method method = _myPlug.getClass( ).getMethod( _myPlugName , int.class , int.class );
method.setAccessible( true );
method.invoke( _myPlug , theColumn , i );
} catch ( SecurityException ex ) {
ex.printStackTrace( );
} catch ( NoSuchMethodException ex ) {
//ex.printStackTrace( );
} catch ( IllegalArgumentException ex ) {
ex.printStackTrace( );
} catch ( IllegalAccessException ex ) {
ex.printStackTrace( );
} catch ( InvocationTargetException ex ) {
ex.printStackTrace( );
}
}
}
return this;
}
@Override public Matrix update( ) {
return setValue( _myValue );
}
public Matrix setGap( int theX , int theY ) {
gapX = theX;
gapY = theY;
return this;
}
public Matrix plugTo( Object theObject ) {
_myPlug = theObject;
return this;
}
public Matrix plugTo( Object theObject , String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName;
return this;
}
/**
* set the state of a particular cell inside a matrix. use true or false for parameter theValue
*
* @param theX
* @param theY
* @param theValue
* @return Matrix
*/
public Matrix set( int theX , int theY , boolean theValue ) {
_myCells[ theX ][ theY ] = (theValue) ? 1 : 0;
return this;
}
public boolean get( int theX , int theY ) {
return _myCells[theX][theY] == 1;
}
public Matrix clear( ) {
for ( int x = 0 ; x < _myCells.length ; x++ ) {
for ( int y = 0 ; y < _myCells[ x ].length ; y++ ) {
_myCells[ x ][ y ] = 0;
}
}
return this;
}
public static int getX( int thePosition ) {
return ( ( thePosition >> 0 ) & 0xff );
}
public static int getY( int thePosition ) {
return ( ( thePosition >> 8 ) & 0xff );
}
public static int getX( float thePosition ) {
return ( ( ( int ) thePosition >> 0 ) & 0xff );
}
public static int getY( float thePosition ) {
return ( ( ( int ) thePosition >> 8 ) & 0xff );
}
public Matrix setCells( int[][] theCells ) {
setGrid( theCells.length , theCells[ 0 ].length );
_myCells = theCells;
return this;
}
public int[][] getCells( ) {
return _myCells;
}
private void triggerEventFromThread( ) {
if ( playing ) {
cnt += 1;
cnt %= _myCellX;
trigger( cnt );
}
}
private void runThread( ) {
if ( t == null ) {
t = new Thread( getName( ) ) {
public void run( ) {
while ( true ) {
triggerEventFromThread( );
try {
Thread.sleep( _myInterval );
} catch ( InterruptedException e ) {
// throw new RuntimeException(e);
}
}
}
};
t.start( );
}
}
@Override public void remove( ) {
if ( t != null ) {
t.interrupt( );
}
super.remove( );
}
/**
* use setMode to change the cell-activation which by default is ControlP5.SINGLE_ROW, 1 active
* cell per row, but can be changed to ControlP5.SINGLE_COLUMN or ControlP5.MULTIPLES
*
* @param theMode return Matrix
*/
public Matrix setMode( int theMode ) {
_myMode = theMode;
return this;
}
public int getMode( ) {
return _myMode;
}
public Matrix setBackground( int c ) {
bg = 0x00000000;
if ( ( c >> 24 & 0xff ) > 0 ) {
bg = ( c >> 24 ) << 24 | ( c >> 16 ) << 16 | ( c >> 8 ) << 8 | ( c >> 0 ) << 0;
}
return this;
}
@Override @ControlP5.Invisible public Matrix updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new MatrixView( );
break;
case ( IMAGE ):
case ( SPRITE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
class MatrixView implements ControllerView< Matrix > {
public void display( PGraphics theGraphics , Matrix theController ) {
theGraphics.noStroke( );
theGraphics.fill( bg );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
float gx = gapX / 2;
float gy = gapY / 2;
for ( int x = 0 ; x < _myCellX ; x++ ) {
for ( int y = 0 ; y < _myCellY ; y++ ) {
theGraphics.fill( _myCells[ x ][ y ] == 1 ? color.getActive( ) : color.getBackground( ) );
theGraphics.rect( x * stepX + gx , y * stepY + gy , stepX - gapX , stepY - gapY );
}
}
if ( isInside( ) ) {
// TODO
// int x = (int) ((theGraphics.mouseX - position.x) / stepX);
// int y = (int) ((theGraphics.mouseY - position.y) / stepY);
// if (x >= 0 && x < _myCellX && y >= 0 && y < _myCellY) {
// theGraphics.fill(_myCells[x][y] == 1 ? color.getActive() :
// color.getForeground());
// theGraphics.rect(x * stepX, y * stepY, stepX - gapX, stepY - gapY);
// }
}
theGraphics.fill( color.getActive( ) );
theGraphics.rect( cnt * stepX , 0 , 1 , getHeight( ) - gapY );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}
}

270
controlP5/MultiList.java Executable file
View File

@ -0,0 +1,270 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* A Multilist is a multi-menu-tree controller. see the example for more information and how to use.
*
* @example controllers/ControlP5multiList
*
* TODO is currently broken, is this due to replacing PVector with float[]?
*
*/
public class MultiList extends Controller< MultiList > implements MultiListInterface , ControlListener {
/* TODO reflection does not work properly. TODO add an option to remove MultiListButtons */
protected Tab _myTab;
protected boolean isVisible = true;
private int cnt;
protected boolean isOccupied;
protected boolean isUpdateLocation = false;
protected MultiListInterface mostRecent;
protected int[] _myRect = new int[ 4 ];
protected int _myDirection = ControlP5Constants.RIGHT;
public int closeDelay = 30;
protected int _myDefaultButtonHeight = 10;
protected boolean isUpperCase = true;
/**
* Convenience constructor to extend MultiList.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public MultiList( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 19 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public MultiList( ControlP5 theControlP5 , Tab theParent , String theName , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , 0 );
_myDefaultButtonHeight = theHeight;
setup( );
}
public MultiList toUpperCase( boolean theValue ) {
isUpperCase = theValue;
for ( Controller c : getSubelements( ) ) {
c.getCaptionLabel( ).toUpperCase( isUpperCase );
}
return this;
}
@ControlP5.Invisible public void setup( ) {
mostRecent = this;
isVisible = true;
updateRect( Controller.x( position ) , Controller.y( position ) , getWidth( ) , _myDefaultButtonHeight );
}
protected void updateRect( float theX , float theY , float theW , float theH ) {
_myRect = new int[] { ( int ) theX , ( int ) theY , ( int ) theW , ( int ) theH };
}
public int getDirection( ) {
return _myDirection;
}
/**
* TODO does not work.
*
* @param theDirection
*/
void setDirection( int theDirection ) {
_myDirection = ( theDirection == ControlP5Constants.LEFT ) ? ControlP5Constants.LEFT : ControlP5Constants.RIGHT;
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListButton ) getSubelements( ).get( i ) ).setDirection( _myDirection );
}
}
/**
* @param theX
* float
* @param theY
* float
*/
@ControlP5.Invisible public void updateLocation( float theX , float theY ) {
Controller.set( position , theX , theY );
updateRect( Controller.x( position ) , Controller.y( position ) , getWidth( ) , _myDefaultButtonHeight );
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).updateLocation( theX , theY );
}
}
/**
* removes the multilist.
*/
public void remove( ) {
super.remove( );
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
getSubelements( ).get( i ).removeListener( this );
getSubelements( ).get( i ).remove( );
}
}
/**
* adds multilist buttons to the multilist.
*
* @param theName
* String
* @param theValue
* int
* @return MultiListButton
*/
public MultiListButton add( String theName , int theValue ) {
int x = ( int ) Controller.x( position );
int yy = 0;
for ( Controller< ? > c : getSubelements( ) ) {
yy += c.getHeight( ) + 1;
}
int y = ( int ) Controller.y( position ) + yy;// (_myDefaultButtonHeight + 1) * _myChildren.size();
MultiListButton b = new MultiListButton( cp5 , theName , theValue , x , y , getWidth( ) , _myDefaultButtonHeight , this , this );
b.toUpperCase( isUpperCase );
b.isMoveable = false;
cp5.register( null , "" , b );
b.addListener( this );
getSubelements( ).add( b );
b.show( );
updateRect( Controller.x( position ) , Controller.y( position ) , getWidth( ) , ( _myDefaultButtonHeight + 1 ) * getSubelements( ).size( ) );
return b;
}
/**
* @param theEvent
*/
@Override @ControlP5.Invisible public void controlEvent( ControlEvent theEvent ) {
if ( theEvent.getController( ) instanceof MultiListButton ) {
_myValue = theEvent.getController( ).getValue( );
ControlEvent myEvent = new ControlEvent( this );
cp5.getControlBroadcaster( ).broadcast( myEvent , ControlP5Constants.FLOAT);
}
}
/**
* {@inheritDoc}
*/
@Override @ControlP5.Invisible public void draw( PGraphics theGraphics ) {
super.draw( theGraphics );
// TODO update( theGraphics );
}
/**
*
* @param theApplet
* @return boolean
*/
@ControlP5.Invisible public boolean update( PApplet theApplet ) {
if ( !isOccupied ) {
cnt++;
if ( cnt == closeDelay ) {
close( );
}
}
if ( isUpdateLocation ) {
updateLocation( ( _myControlWindow.mouseX - _myControlWindow.pmouseX ) , ( _myControlWindow.mouseY - _myControlWindow.pmouseY ) );
isUpdateLocation = theApplet.mousePressed;
}
if ( isOccupied ) {
if ( theApplet.keyPressed && theApplet.mousePressed ) {
if ( theApplet.keyCode == PApplet.ALT ) {
isUpdateLocation = true;
return true;
}
}
}
return false;
}
/**
*
* @param theFlag
* boolean
*/
@ControlP5.Invisible public void occupied( boolean theFlag ) {
isOccupied = theFlag;
cnt = 0;
}
/**
* @return boolean
*/
@ControlP5.Invisible public boolean observe( ) {
return CP.inside( _myRect , _myControlWindow.mouseX , _myControlWindow.mouseY );
}
/**
* @param theInterface
* MultiListInterface
*/
public void close( MultiListInterface theInterface ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
if ( theInterface != getSubelements( ).get( i )) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).close( );
}
}
}
/**
* {@inheritDoc}
*/
@Override public void close( ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).close( );
}
}
/**
* {@inheritDoc}
*/
@Override public void open( ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).open( );
}
}
/**
* {@inheritDoc}
*/
@Override public MultiList setValue( float theValue ) {
return this;
}
/**
* {@inheritDoc}
*/
@Override public MultiList update( ) {
return setValue( _myValue );
}
}

223
controlP5/MultiListButton.java Executable file
View File

@ -0,0 +1,223 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/**
* Used by MultiList.
*
* @example controllers/ControlP5multiList
* @nosuperclasses Controller Controller
*/
public class MultiListButton extends Button implements MultiListInterface {
// private MultiListInterface parent;
private final Controller parent;
private final MultiList root;
private int[] _myRect = new int[ 4 ];
protected int _myDirection = RIGHT;
private boolean isUpperCase = true;
/**
*
* @param theProperties ControllerProperties
* @param theParent MultiListInterface
* @param theRoot MultiList
*/
protected MultiListButton( ControlP5 theControlP5 , String theName , float theValue , int theX , int theY , int theWidth , int theHeight , Controller theParent , MultiList theRoot ) {
super( theControlP5 , ( ControllerGroup< ? > ) theRoot.getParent( ) , theName , theValue , theX , theY , theWidth , theHeight );
parent = theParent;
root = theRoot;
updateRect( x( position ) , y( position ) , getWidth( ) , getHeight( ) );
_myCaptionLabel.align( LEFT , CENTER );
}
public MultiListButton toUpperCase( boolean theValue ) {
isUpperCase = theValue;
for ( Controller< ? > c : getSubelements( ) ) {
c.getCaptionLabel( ).toUpperCase( isUpperCase );
}
_myCaptionLabel.toUpperCase( isUpperCase );
return this;
}
public void remove( ) {
int myYoffset = 0;
for ( int i = 0 ; i < parent.getSubelements( ).size( ) ; i++ ) {
if ( parent.getSubelements( ).get( i ) == this ) {
myYoffset = getHeight( ) + 1;
}
( ( MultiListButton ) parent.getSubelements( ).get( i ) ).updateLocation( 0 , -myYoffset );
}
if ( _myParent != null ) {
removeListener( root );
_myParent.remove( this );
}
if ( cp5 != null ) {
removeListener( root );
cp5.remove( this );
}
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
getSubelements( ).get( i ).remove( );
}
}
public int getDirection( ) {
return _myDirection;
}
protected void setDirection( int theDirection ) {
_myDirection = theDirection;
}
public void updateRect( float theX , float theY , float theW , float theH ) {
_myRect = new int[] { ( int ) theX , ( int ) theY , ( int ) theW , ( int ) theH };
}
public void updateLocation( float theX , float theY ) {
set( position , theX , theY );
updateRect( x( position ) , y( position ) , getWidth( ) , getHeight( ) );
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).updateLocation( theX , theY );
}
}
/**
* set the width of a multlist button.
*
* @param theWidth int
*/
public MultiListButton setWidth( int theWidth ) {
// negative direction
int dif = ( _myDirection == LEFT ) ? theWidth - getWidth( ) : 0;
super.setWidth( theWidth );
updateLocation( -dif , 0 );
return this;
}
/**
* set the height of a multlist button.
*
* @param theHeight int
*/
public MultiListButton setHeight( int theHeight ) {
int difHeight = getHeight( );
super.setHeight( theHeight );
difHeight = getHeight( ) - difHeight;
int myYoffset = 0;
for ( int i = 0 ; i < parent.getSubelements( ).size( ) ; i++ ) {
if ( parent.getSubelements( ).get( i ) instanceof MultiListInterface ) {
( ( MultiListInterface ) parent.getSubelements( ).get( i ) ).updateLocation( 0 , myYoffset );
if ( ( parent.getSubelements( ).get( i ) ) == this ) {
myYoffset = difHeight;
}
}
}
updateLocation( 0 , 0 );
return this;
}
/**
* add a new button to the sublist of this multilist button.
*
* @param theName String
* @param theValue int
* @return MultiListButton
*/
public MultiListButton add( String theName , float theValue ) {
int myHeight = - ( getHeight( ) + 1 );
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
myHeight += ( getSubelements( ).get( i ) ).getHeight( ) + 1;
}
// negative direction, this is static now, make it dynamic depending on
// the
// location of the list.
int xx = ( ( int ) x( position ) + ( getWidth( ) + 1 ) );
MultiListButton b = new MultiListButton( cp5 , theName , theValue , xx , ( int ) y( position ) + ( getHeight( ) + 1 ) + myHeight , getWidth( ), getHeight( ), this , root );
b.isMoveable = false;
b.toUpperCase( isUpperCase );
b.hide( );
cp5.register( null , "" , b );
b.addListener( root );
getSubelements( ).add( b );
updateRect( xx , y( position ) , getWidth( ) , ( getHeight( ) + 1 ) + myHeight );
return b;
}
protected void onEnter( ) {
if ( !root.isUpdateLocation ) {
isActive = true;
root.occupied( true );
root.mostRecent = this;
if ( parent instanceof MultiListInterface ) {
( ( MultiListInterface ) parent ).close( this );
}
open( );
}
}
protected void onLeave( ) {
if ( parent instanceof MultiListInterface ) {
if ( ! ( ( MultiListInterface ) parent ).observe( ) && !root.isUpdateLocation && root.mostRecent == this ) {
isActive = false;
root.occupied( false );
}
}
}
public void mouseReleasedOutside( ) {
// !!! other than in the Button class, calling mouseReleased here
// conflicts with mouseReleased();
}
public boolean observe( ) {
return CP.inside( _myRect , _myControlWindow.mouseX , _myControlWindow.mouseY );
}
public void close( MultiListInterface theInterface ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
if ( theInterface != getSubelements( ).get( i )) {
( ( MultiListInterface ) getSubelements( ).get( i ) ).close( );
}
}
}
public void close( ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListButton ) getSubelements( ).get( i ) ).close( );
( ( MultiListButton ) getSubelements( ).get( i ) ).hide( );
}
}
public void open( ) {
for ( int i = 0 ; i < getSubelements( ).size( ) ; i++ ) {
( ( MultiListButton ) getSubelements( ).get( i ) ).show( );
}
}
}

View File

@ -0,0 +1,48 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
interface MultiListInterface {
void close( );
void open( );
void close( MultiListInterface theInterface );
boolean observe( );
void updateLocation( float theX , float theY );
void draw( PGraphics theGraphics );
int getDirection( );
MultiListInterface toUpperCase( boolean theValue );
}

View File

@ -0,0 +1,26 @@
package main.java.src2.main.java.controlP5.controlP5;
import processing.event.KeyEvent;
public class MultilineTextfield extends Textfield {
public MultilineTextfield(ControlP5 theControlP5, String theName) {
super(theControlP5, theName);
}
@Override
public void keyEvent(KeyEvent theKeyEvent) {
if (isUserInteraction && isTexfieldActive && isActive && theKeyEvent.getAction() == KeyEvent.PRESS) {
if (ignorelist.contains(cp5.getKeyCode())) {
return;
}
if (cp5.getKeyCode() == ENTER) {
// Append a new line character to the text buffer
_myTextBuffer.insert(_myTextBufferIndex, '\n');
setIndex(_myTextBufferIndex + 1);
} else {
super.keyEvent(theKeyEvent);
}
}
}
}

302
controlP5/Numberbox.java Executable file
View File

@ -0,0 +1,302 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* Click and drag the mouse inside a numberbox and move up and down to change the value of a
* numberbox. By default the value changes when dragging the mouse up and down. use
* setDirection(Controller.HORIZONTAL) to change the mouse control to left and right.
*
* Why do I get -1000000 as initial value when creating a numberbox without a default value? the
* value of a numberbox defaults back to its minValue, which is -1000000. either use a default value
* or link a variable to the numberbox - this is done by giving a float or int variable the same
* name as the numberbox.
*
* Use setMultiplier(float) to change the sensitivity of values increasing/decreasing, by default
* the multiplier is 1.
*
*
* @example controllers/ControlP5numberbox
* @nosuperclasses Controller Controller
*/
public class Numberbox extends Controller< Numberbox > {
protected int cnt;
protected boolean isActive;
public static int LEFT = 0;
public static int UP = 1;
public static int RIGHT = 2;
public static int DOWN = 3;
protected int _myNumberCount = VERTICAL;
protected float _myMultiplier = 1;
public static int autoWidth = 69;
public static int autoHeight = 19;
protected float[] autoSpacing = new float[] { 10 , 20 };
protected float scrollSensitivity = 0.1f;
/**
* Convenience constructor to extend Numberbox.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Numberbox( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
*
* @param theControlP5 ControlP5
* @param theParent Tab
* @param theName String
* @param theDefaultValue float
* @param theX int
* @param theY int
* @param theWidth int
* @param theHeight int
*/
public Numberbox( ControlP5 theControlP5 , Tab theParent , String theName , float theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myMin = -Float.MAX_VALUE;
_myMax = Float.MAX_VALUE;
_myValue = theDefaultValue;
_myValueLabel = new Label( cp5 , String.valueOf(_myValue), theWidth , 12 , color.getValueLabel( ) );
if ( Float.isNaN( _myValue ) ) {
_myValue = 0;
}
}
/* (non-Javadoc)
*
* @see ControllerInterfalce.updateInternalEvents */
@ControlP5.Invisible
public Numberbox updateInternalEvents( PApplet theApplet ) {
if ( isActive ) {
if ( !cp5.isAltDown( ) ) {
if ( _myNumberCount == VERTICAL ) {
setValue( _myValue + ( _myControlWindow.mouseY - _myControlWindow.pmouseY ) * _myMultiplier );
} else {
setValue( _myValue + ( _myControlWindow.mouseX - _myControlWindow.pmouseX ) * _myMultiplier );
}
}
}
return this;
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#mousePressed() */
@Override
@ControlP5.Invisible
public void mousePressed( ) {
isActive = true;
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#mouseReleased() */
@Override
@ControlP5.Invisible
public void mouseReleased( ) {
isActive = false;
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#mouseReleasedOutside() */
@Override
@ControlP5.Invisible
public void mouseReleasedOutside( ) {
mouseReleased( );
}
/**
*
* @param theMultiplier
* @return Numberbox
*/
public Numberbox setMultiplier( float theMultiplier ) {
_myMultiplier = theMultiplier;
return this;
}
/**
*
* @return float
*/
public float getMultiplier( ) {
return _myMultiplier;
}
/**
* set the value of the numberbox.
*
* @param theValue float
* @return Numberbox
*/
@Override
public Numberbox setValue( float theValue ) {
_myValue = theValue;
_myValue = Math.max( _myMin , Math.min( _myMax , _myValue ) );
broadcast( FLOAT );
_myValueLabel.set( adjustValue( _myValue ) );
return this;
}
/**
* assigns a random value to the controller.
*
* @return Numberbox
*/
public Numberbox shuffle( ) {
float r = ( float ) Math.random( );
if ( getMax( ) != Float.MAX_VALUE && getMin( ) != -Float.MAX_VALUE ) {
setValue( PApplet.map( r , 0 , 1 , getMin( ) , getMax( ) ) );
}
return this;
}
public Numberbox setRange( float theMin , float theMax ) {
setMin( theMin );
setMax( theMax );
setValue( getValue( ) );
return this;
}
/**
* sets the sensitivity for the scroll behavior when using the mouse wheel or the scroll
* function of a multi-touch track pad. The smaller the value (closer to 0) the higher the
* sensitivity.
*
* @param theValue
* @return Numberbox
*/
public Numberbox setScrollSensitivity( float theValue ) {
scrollSensitivity = theValue;
return this;
}
/**
* changes the value of the numberbox when hovering and using the mouse wheel or the scroll
* function of a multi-touch track pad.
*
* @param theRotationValue
* @return Numberbox
*/
@ControlP5.Invisible
public Numberbox scrolled( int theRotationValue ) {
float f = getValue( );
f += ( _myMultiplier == 1 ) ? ( theRotationValue * scrollSensitivity ) : theRotationValue * _myMultiplier;
setValue( f );
return this;
}
/**
* set the direction for changing the numberbox value when dragging the mouse. by default this
* is up/down (VERTICAL), use setDirection(Controller.HORIZONTAL) to change to left/right or
* back with setDirection(Controller.VERTICAL).
*
* @param theValue
*/
public Numberbox setDirection( int theValue ) {
if ( theValue == HORIZONTAL || theValue == VERTICAL ) {
_myNumberCount = theValue;
} else {
_myNumberCount = VERTICAL;
}
return this;
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#update() */
@Override
public Numberbox update( ) {
return setValue( _myValue );
}
/**
* {@inheritDoc}
*/
@Override
public Numberbox linebreak( ) {
cp5.linebreak( this , true , autoWidth , autoHeight , autoSpacing );
return this;
}
/**
* {@inheritDoc}
*/
@Override
@ControlP5.Invisible
public Numberbox updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new NumberboxView( );
case ( SPRITE ):
case ( IMAGE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
class NumberboxView implements ControllerView< Numberbox > {
NumberboxView( ) {
_myValueLabel.align( LEFT , CENTER ).setPadding( 0 , Label.paddingY );
_myCaptionLabel.align( LEFT , BOTTOM_OUTSIDE ).setPadding( 0 , Label.paddingY );
}
public void display( PGraphics theGraphics , Numberbox theController ) {
theGraphics.fill( color.getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth() , getHeight() );
theGraphics.fill( ( isActive ) ? color.getActive( ) : color.getForeground( ) );
int h = getHeight() / 2;
theGraphics.triangle( 0 , h - 6 , 6 , h , 0 , h + 6 );
_myValueLabel.draw( theGraphics , 10 , 0 , theController );
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
/**
* @see Numberbox#setScrollSensitivity(float)
*
* @param theValue
* @return
*/
@Deprecated
public Numberbox setSensitivity( float theValue ) {
return setScrollSensitivity( theValue );
}
}

31
controlP5/Pad.java Executable file
View File

@ -0,0 +1,31 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
class Pad {
// pad for placing controllers, like matrix but without the grid
// a sequencer
}

47
controlP5/Pointer.java Executable file
View File

@ -0,0 +1,47 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
public interface Pointer {
int x();
int y();
int px();
int py();
int dx();
int dy();
long pt();
long dt();
long t();
}

108
controlP5/Println.java Executable file
View File

@ -0,0 +1,108 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
public class Println {
int max = -1;
final Textarea c;
String buffer = "";
boolean paused;
public Println(Textarea theTextarea) {
c = theTextarea;
run();
}
public Println setMax(int theMax) {
max = theMax;
return this;
}
private void run() {
try {
final PipedInputStream pi = new PipedInputStream();
final PipedOutputStream po = new PipedOutputStream(pi);
System.setOut(new PrintStream(po, true));
(new Thread() {
public void run() {
final byte[] buf = new byte[1024];
try {
while (true) {
final int len = pi.read(buf);
if (len == -1) {
break;
}
if (!paused) {
if (!c._myScrollbar.isMousePressed) {
c.append(buffer + new String(buf, 0, len), max);
buffer = "";
c.scroll(1);
}
else {
buffer += new String(buf, 0, len);
}
}
}
} catch (IOException e) {
}
}
}).start();
} catch (IOException e) {
System.out.println("Problems setting up console");
}
}
public void clear() {
c.clear();
}
public void pause() {
paused = true;
}
public void play() {
paused = false;
}
}

39
controlP5/Radio.java Executable file
View File

@ -0,0 +1,39 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
/*
* Backwards compatibility, cp5magic for example uses it.
* But if possible, upgrade to RadioButton
*/
public class Radio extends RadioButton {
public Radio( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY ) {
super( theControlP5 , theParent , theName , theX , theY );
}
}

643
controlP5/RadioButton.java Executable file
View File

@ -0,0 +1,643 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import processing.core.PImage;
/**
* A radioButton is a list of toggles that can be turned on or off. radioButton is of type
* ControllerGroup, therefore a controllerPlug can't be set. this means that an event from a
* radioButton can't be forwarded to a method other than controlEvent in a sketch.
*
* a radioButton has 2 sets of values. radioButton.getValue() returns the value of the active
* radioButton item. radioButton.getArrayValue() returns a float array that represents the active
* (1) and inactive (0) items of a radioButton.
*
* ControlP5 CheckBox Toggle
*
* @example controllers/ControlP5radioButton
*
* @nosuperclasses Controller Controller
*/
public class RadioButton extends ControlGroup< RadioButton > {
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;
private Object _myPlug;
private String _myPlugName;
protected int alignX = RIGHT_OUTSIDE;
protected int alignY = CENTER;
protected int _myPaddingX = Label.paddingX;
protected int _myPaddingY = 0;
/**
* Convenience constructor to extend RadioButton.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public RadioButton( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
* @exclude
* @param theControlP5
* @param theParent
* @param theName
* @param theX
* @param theY
*/
public RadioButton( final ControlP5 theControlP5 , final ControllerGroup< ? > theParent , final String theName , final int theX , final int theY ) {
super( theControlP5 , theParent , theName , theX , theY , 99 , 9 );
isBarVisible = false;
isCollapse = false;
_myRadioToggles = new ArrayList< Toggle >( );
setItemsPerRow( 1 );
_myPlug = cp5.papplet;
_myPlugName = getName( );
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
}
/**
* @param theName
* @param theValue
* @return
*/
public RadioButton addItem( final String theName , final float theValue ) {
Toggle t = cp5.addToggle( theName , 0 , 0 , itemWidth , itemHeight );
t.getCaptionLabel( ).align( alignX , alignY ).setPadding( _myPaddingX , _myPaddingY );
t.setMode(DEFAULT);
t.setImages( images[ 0 ] , images[ 1 ] , images[ 2 ] );
t.setSize( images[ 0 ] );
addItem( t , theValue );
return this;
}
/**
* @param theToggle
* @param theValue
* @return
*/
public RadioButton addItem( final Toggle theToggle , final float theValue ) {
theToggle.setGroup( this );
theToggle.isMoveable = false;
theToggle.setInternalValue( theValue );
theToggle.isBroadcast = false;
_myRadioToggles.add( theToggle );
updateLayout( );
getColor( ).copyTo( theToggle );
theToggle.addListener( this );
updateValues( false );
cp5.removeProperty( theToggle );
return this;
}
/**
* @param theName
*/
public RadioButton removeItem( final String theName ) {
int n = _myRadioToggles.size( );
for ( int i = n-1 ; i >= 0 ; i-- ) {
if ( ( _myRadioToggles.get( i ) ).getName( ).equals( theName ) ) {
( _myRadioToggles.get( i ) ).removeListener( this );
_myRadioToggles.get( i ).remove();
_myRadioToggles.remove( i );
}
}
updateValues( false );
updateLayout( );
return this;
}
private void updateAlign( ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).align( alignX , alignY );
}
}
public RadioButton align( int[] a ) {
return align( a[ 0 ] , a[ 1 ] );
}
public RadioButton align( int theX , int theY ) {
alignX = theX;
alignY = theY;
updateAlign( );
return this;
}
public RadioButton alignX( int theX ) {
return align( theX , alignY );
}
public RadioButton alignY( int theY ) {
return align( alignX , theY );
}
public int[] getAlign( ) {
return new int[] { alignX , alignY };
}
public RadioButton setLabelPadding( int thePaddingX , int thePaddingY ) {
_myPaddingX = thePaddingX;
_myPaddingY = thePaddingY;
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setPadding( thePaddingX , thePaddingY );
}
return this;
}
/**
*
* @param theDefaultImage
* @param theOverImage
* @param theActiveImage
* @return RadioButton
*/
public RadioButton setImages( PImage theDefaultImage , PImage theOverImage , PImage theActiveImage ) {
setImage( theDefaultImage , DEFAULT );
setImage( theOverImage , OVER );
setImage( theActiveImage , ACTIVE );
return this;
}
/**
* @param theImage
*/
public RadioButton setImage( PImage theImage ) {
return setImage( theImage , DEFAULT );
}
/**
* @param theImage
* @param theState
* use Controller.DEFAULT (background), or Controller.OVER (foreground), or
* Controller.ACTIVE (active)
* @return
*/
public RadioButton setImage( PImage theImage , int theState ) {
if ( theImage != null ) {
images[ theState ] = theImage;
availableImages[ theState ] = true;
for ( int i = 0 ; i < _myRadioToggles.size( ) ; i++ ) {
_myRadioToggles.get( i ).setImage( theImage , theState );
}
}
return this;
}
public RadioButton setSize( PImage theImage ) {
return setSize( theImage.width , theImage.height );
}
public RadioButton setSize( int theWidth , int theHeight ) {
setItemWidth( theWidth );
setItemHeight( theHeight );
return this;
}
/**
* set the height of a radioButton/checkBox item. by default the height is 11px. in order to
* recognize a custom height, the itemHeight has to be set before adding items to a
* radioButton/checkBox.
*
* @param theItemHeight
*/
public RadioButton setItemHeight( int theItemHeight ) {
itemHeight = theItemHeight;
for ( Toggle t : _myRadioToggles ) {
t.setHeight( theItemHeight );
}
updateLayout( );
return this;
}
/**
* set the width of a radioButton/checkBox item. by default the width is 11px. in order to
* recognize a custom width, the itemWidth has to be set before adding items to a
* radioButton/checkBox.
*
* @param theItemWidth
*/
public RadioButton setItemWidth( int theItemWidth ) {
itemWidth = theItemWidth;
for ( Toggle t : _myRadioToggles ) {
t.setWidth( theItemWidth );
}
updateLayout( );
return this;
}
/**
* Gets a radio button item by index.
*
* @param theIndex
* @return Toggle
*/
public Toggle getItem( int theIndex ) {
return _myRadioToggles.get( theIndex );
}
public Toggle getItem( String theName ) {
for ( Toggle t : _myRadioToggles ) {
if ( theName.equals( t.getName( ) ) ) {
return t;
}
}
return null;
}
public List< Toggle > getItems( ) {
return _myRadioToggles;
}
/**
* Gets the state of an item - this can be true (for on) or false (for off) - by index.
*
* @param theIndex
* @return boolean
*/
public boolean getState( int theIndex ) {
if ( theIndex < _myRadioToggles.size( ) && theIndex >= 0 ) {
return _myRadioToggles.get( theIndex ).getState( );
}
return false;
}
/**
* Gets the state of an item - this can be true (for on) or false (for off) - by name.
*
* @param theName
* @return
*/
public boolean getState( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
return t.getState( );
}
}
return false;
}
/**
* @exclude
*/
public void updateLayout( ) {
int nn = 0;
int xx = 0;
int yy = 0;
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
set( t.position , xx , yy );
xx += t.getWidth( ) + spacingColumn;
nn++;
if ( nn == itemsPerRow ) {
nn = 0;
_myWidth = xx;
yy += t.getHeight( ) + spacingRow;
xx = 0;
} else {
_myWidth = xx;
}
}
}
/**
* Items of a radioButton or a checkBox are organized in columns and rows. SetItemsPerRow sets
* the limit of items per row. items exceeding the limit will be pushed to the next row.
*
* @param theValue
*/
public RadioButton setItemsPerRow( final int theValue ) {
itemsPerRow = theValue;
updateLayout( );
return this;
}
/**
* Sets the spacing in pixels between columns.
*
* @param theSpacing
*/
public RadioButton setSpacingColumn( final int theSpacing ) {
spacingColumn = theSpacing;
updateLayout( );
return this;
}
/**
* Sets the spacing in pixels between rows.
*
* @param theSpacing
*/
public RadioButton setSpacingRow( final int theSpacing ) {
spacingRow = theSpacing;
updateLayout( );
return this;
}
public RadioButton deactivateAll( ) {
if ( !isMultipleChoice && !noneSelectedAllowed ) {
return this;
}
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
_myRadioToggles.get( i ).deactivate( );
}
_myValue = -1;
updateValues( true );
return this;
}
/**
* Deactivates all active RadioButton items and only activates the item corresponding to
* theIndex.
* TODO does not trigger function or value when called by code, fix!
*
* @param theIndex
*/
public RadioButton activate( int theIndex ) {
int n = _myRadioToggles.size( );
if ( theIndex < n ) {
for ( int i = 0 ; i < n ; i++ ) {
_myRadioToggles.get( i ).deactivate( );
}
_myRadioToggles.get( theIndex ).activate( );
_myValue = _myRadioToggles.get( theIndex ).internalValue( );
updateValues( true );
}
return this;
}
/**
* @param theIndex
*/
public RadioButton deactivate( int theIndex ) {
if ( !isMultipleChoice && !noneSelectedAllowed ) {
return this;
}
if ( theIndex < _myRadioToggles.size( ) ) {
Toggle t = _myRadioToggles.get( theIndex );
if ( t.isActive ) {
t.deactivate( );
_myValue = -1;
updateValues( true );
}
}
return this;
}
/**
* Actives an item of the Radio button by name.
*
* @param theName
*/
public RadioButton activate( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
activate( i );
return this;
}
}
return this;
}
/**
* Deactivates a RadioButton by name and sets the value of the RadioButton to the default value
* -1.
*
* @param theName
*/
public RadioButton deactivate( String theName ) {
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( theName.equals( t.getName( ) ) ) {
t.deactivate( );
_myValue = -1;
updateValues( true );
return this;
}
}
return this;
}
/**
* @exclude
* @param theIndex
*/
public RadioButton toggle( int theIndex ) {
// TODO
// boolean itemState = ((Toggle)
// _myRadioToggles.get(theIndex)).getState();
// if (theIndex < _myRadioToggles.size()) {
// Toggle t = ((Toggle) _myRadioToggles.get(theIndex));
// if (t.isActive) {
// t.deactivate();
// _myValue = -1;
// updateValues(true);
// }
// }
ControlP5.logger( ).info( "toggle() not yet implemented, working on it." );
return this;
}
/**
* {@inheritDoc}
*
* @exclude
*/
@ControlP5.Invisible @Override public void controlEvent( ControlEvent theEvent ) {
if ( !isMultipleChoice ) {
if ( !noneSelectedAllowed && theEvent.getController( ).getValue( ) < 1 ) {
if ( theEvent.getController( ) instanceof Toggle ) {
Toggle t = ( ( Toggle ) theEvent.getController( ) );
boolean b = t.isBroadcast( );
t.setBroadcast( false );
t.setState( true );
t.setBroadcast( b );
return;
}
}
_myValue = -1;
int n = _myRadioToggles.size( );
for ( int i = 0 ; i < n ; i++ ) {
Toggle t = _myRadioToggles.get( i );
if ( !t.equals( theEvent.getController( ) ) ) {
t.deactivate( );
} else {
if ( t.isOn ) {
_myValue = t.internalValue( );
}
}
}
}
if ( _myPlug != null ) {
try {
Method method = _myPlug.getClass( ).getMethod( _myPlugName , int.class );
method.invoke( _myPlug , ( int ) _myValue );
} catch ( SecurityException ex ) {
ex.printStackTrace( );
} catch ( NoSuchMethodException ex ) {
ex.printStackTrace( );
} catch ( IllegalArgumentException ex ) {
ex.printStackTrace( );
} catch ( IllegalAccessException ex ) {
ex.printStackTrace( );
} catch ( InvocationTargetException ex ) {
ex.printStackTrace( );
}
}
updateValues( true );
}
public RadioButton plugTo( Object theObject ) {
_myPlug = theObject;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_myPlug = null;
}
return this;
}
public RadioButton plugTo( Object theObject , String thePlugName ) {
_myPlug = theObject;
_myPlugName = thePlugName;
if ( !ControllerPlug.checkPlug( _myPlug , _myPlugName , new Class[] { int.class } ) ) {
_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 = _myRadioToggles.get( i );
_myArrayValue[ i ] = t.getValue( );
}
if ( theBroadcastFlag ) {
ControlEvent myEvent = new ControlEvent( this );
cp5.getControlBroadcaster( ).broadcast( myEvent , FLOAT);
}
}
/**
* In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this
* is true. setNoneSelectedAllowed does not apply when in multipleChoice mode.
*
* @param theValue
*/
public RadioButton setNoneSelectedAllowed( boolean theValue ) {
noneSelectedAllowed = theValue;
return this;
}
/**
* Sets the value for all RadioButton items according to the values of the array passed on. 0
* will turn off an item, any other value will turn it on.
*/
@Override public RadioButton setArrayValue( float[] theArray ) {
for ( int i = 0 ; i < theArray.length ; i++ ) {
if ( _myArrayValue[ i ] != theArray[ i ] ) {
if ( theArray[ i ] == 0 ) {
deactivate( i );
} else {
activate( i );
}
}
}
super.setArrayValue( theArray );
return this;
}
public RadioButton setColorLabels( int theColor ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setColor( theColor );
}
return this;
}
public RadioButton hideLabels( ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( false );
}
return this;
}
public RadioButton showLabels( ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).setVisible( true );
}
return this;
}
public RadioButton toUpperCase( boolean theValue ) {
for ( Toggle t : _myRadioToggles ) {
t.getCaptionLabel( ).toUpperCase( theValue );
}
return this;
}
/**
* @exclude {@inheritDoc}
*/
@Override public String getInfo( ) {
return "type:\tRadioButton\n" + super.getInfo( );
}
/**
* @deprecated
* @exclude
*/
@Deprecated public RadioButton add( final String theName , final float theValue ) {
return addItem( theName , theValue );
}
}

519
controlP5/Range.java Executable file
View File

@ -0,0 +1,519 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import java.util.logging.Level;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
/**
* A range slider works just like a slider but can be adjusted on both ends.
*
* @see Slider
* @example controllers/ControlP5range
* @nosuperclasses Controller Controller
*/
public class Range extends Controller< Range > {
/* TODO if range value is int, value labels do initialize as floats. first click makes them
* display as ints without decimal point */
protected static final int HORIZONTAL = 0;
protected static final int VERTICAL = 1;
protected int _myDirection;
protected float _myValuePosition;
protected boolean isDragging;
protected boolean isDraggable = true;
protected boolean isFirstClick;
protected Label _myHighValueLabel;
protected float _myValueRange;
protected boolean isMinHandle;
protected boolean isMaxHandle;
protected boolean isMoveHandle;
protected float distanceHandle;
protected int handleSize = 10;
protected int minHandle = 0;
protected int maxHandle = 0;
protected int mr = 0;
protected final ArrayList< TickMark > _myTickMarks = new ArrayList< TickMark >( );
protected boolean isShowTickMarks;
protected boolean isSnapToTickMarks;
public static int autoWidth = 99;
public static int autoHeight = 9;
public static float[] autoSpacing = new float[]{ 0 , 5 , 0 };
public int alignValueLabel = ControlP5Constants.CENTER;
protected int _myColorTickMark = 0xffffffff;
private int mode = -1;
/**
* Convenience constructor to extend Range.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Range( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 100 , 0 , 100 , 0 , 0 , 99 , 9 );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
*
* @param theControlP5 ControlP5
* @param theParent ControllerGroup
* @param theName String
* @param theMin float
* @param theMax float
* @param theDefaultValue float
* @param theX int
* @param theY int
* @param theWidth int
* @param theHeight int
*/
@ControlP5.Invisible public Range( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theMin , float theMax , float theDefaultMinValue , float theDefaultMaxValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myArrayValue = new float[] { theDefaultMinValue , theDefaultMaxValue };
_myMin = theMin;
_myMax = theMax;
_myValueRange = _myMax - _myMin;
minHandle = ( int ) PApplet.map( theDefaultMinValue , _myMin , _myMax , handleSize , getWidth( ) - handleSize );
maxHandle = ( int ) PApplet.map( theDefaultMaxValue , _myMin , _myMax , handleSize , getWidth( ) - handleSize );
mr = maxHandle - minHandle;
_myCaptionLabel = new Label( cp5 , theName ).setColor( color.getCaptionLabel( ) ).align( ControlP5Constants.RIGHT_OUTSIDE , ControlP5Constants.CENTER );
_myValueLabel = new Label( cp5 , adjustValue(_myMin)).setColor( color.getValueLabel( ) ).set(adjustValue(theDefaultMinValue)).align( ControlP5Constants.LEFT , ControlP5Constants.CENTER );
_myHighValueLabel = new Label( cp5 , adjustValue( _myMax ) ).setColor( color.getValueLabel( ) ).set(adjustValue(theDefaultMaxValue)).align( ControlP5Constants.RIGHT , ControlP5Constants.CENTER );
_myValue = theDefaultMinValue;
_myDirection = HORIZONTAL;
update( );
}
@Override public Range setColorValueLabel( int theColor ) {
_myValueLabel.setColor( theColor );
_myHighValueLabel.setColor( theColor );
return this;
}
@Override public Range setColorCaptionLabel( int theColor ) {
_myCaptionLabel.setColor( theColor );
return this;
}
public Range setHighValueLabel( final String theLabel ) {
_myHighValueLabel.set( theLabel );
return this;
}
public Range setLowValueLabel( final String theLabel ) {
_myValueLabel.set( theLabel );
return this;
}
@ControlP5.Invisible public Range setSliderMode( int theMode ) {
return this;
}
public Range setHandleSize( int theSize ) {
handleSize = theSize;
setLowValue( _myArrayValue[ 0 ] , false );
setHighValue( _myArrayValue[ 1 ] , false );
mr = maxHandle - minHandle;
return this;
}
@ControlP5.Invisible public Range updateInternalEvents( PApplet theApplet ) {
if ( isVisible ) {
int c = _myControlWindow.mouseX - _myControlWindow.pmouseX;
if ( c == 0 ) {
return this;
}
if ( isMousePressed && !cp5.isAltDown( ) ) {
switch ( mode ) {
case ( ControlP5Constants.LEFT ):
minHandle = PApplet.max( handleSize , PApplet.min( maxHandle , minHandle + c ) );
break;
case ( ControlP5Constants.RIGHT ):
maxHandle = PApplet.max( minHandle , PApplet.min( getWidth( ) - handleSize , maxHandle + c ) );
break;
case ( ControlP5Constants.CENTER ):
minHandle = PApplet.max( handleSize , PApplet.min( getWidth( ) - mr - handleSize , minHandle + c ) );
maxHandle = PApplet.max( minHandle , PApplet.min( getWidth( ) - handleSize , minHandle + mr ) );
break;
}
update( );
}
}
return this;
}
@Override @ControlP5.Invisible
public void mousePressed( ) {
final float posX = Controller.x( _myParent.getAbsolutePosition( ) ) + Controller.x( position );
final float posY = Controller.y( _myParent.getAbsolutePosition( ) ) + Controller.y( position );
if ( _myControlWindow.mouseY < posY || _myControlWindow.mouseY > posY + getHeight( ) ) {
mode = -1;
isMinHandle = isMaxHandle = false;
return;
}
int x0 = ( int ) ( posX + minHandle );
int x1 = ( int ) ( posX + maxHandle );
if ( _myControlWindow.mouseX >= x0 - handleSize && _myControlWindow.mouseX < x0 ) {
mode = ControlP5Constants.LEFT;
isMinHandle = true;
} else if ( _myControlWindow.mouseX >= x1 && _myControlWindow.mouseX < x1 + handleSize ) {
mode = ControlP5Constants.RIGHT;
isMaxHandle = true;
} else if ( _myControlWindow.mouseX > x0 && _myControlWindow.mouseX < x1 && isDraggable ) {
mode = ControlP5Constants.CENTER;
}
}
/**
* set the value of the range-slider. to set the low and high value, use setLowValue and
* setHighValue or setRangeValues
*
* @see #setLowValue(float)
* @see #setHighValue(float)
* @see #setRangeValues(float, float)
*
* @param theValue float
* @return Range
*/
@Override @ControlP5.Invisible public Range setValue( float theValue ) {
_myValue = theValue;
broadcast( ControlP5Constants.ARRAY );
return this;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public Range update( ) {
_myArrayValue[ 0 ] = PApplet.map( minHandle , handleSize , getWidth( ) - handleSize , _myMin , _myMax );
_myArrayValue[ 1 ] = PApplet.map( maxHandle , handleSize , getWidth( ) - handleSize , _myMin , _myMax );
mr = maxHandle - minHandle;
_myHighValueLabel.set( adjustValue( _myArrayValue[ 1 ] ) );
_myValueLabel.set( adjustValue( _myArrayValue[ 0 ] ) );
return setValue( _myValue );
}
@ControlP5.Invisible public Range setDraggable( boolean theFlag ) {
isDraggable = theFlag;
isDragging = theFlag && isDragging;
return this;
}
public float[] getArrayValue( ) {
return _myArrayValue;
}
@Override public Range setArrayValue( float[] theArray ) {
setLowValue( theArray[ 0 ] , false );
setHighValue( theArray[ 1 ] , false );
return update( );
}
@Override public Range setMin( float theValue ) {
_myMin = theValue;
_myValueRange = _myMax - _myMin;
return setLowValue( _myArrayValue[ 0 ] );
}
@Override public Range setMax( float theValue ) {
_myMax = theValue;
_myValueRange = _myMax - _myMin;
return setHighValue( _myArrayValue[ 1 ] );
}
public float getLowValue( ) {
return _myArrayValue[ 0 ];
}
public float getHighValue( ) {
return _myArrayValue[ 1 ];
}
@Override public Range setWidth( int theValue ) {
super.setWidth( theValue );
return this;
}
@Override public Range setHeight( int theValue ) {
super.setHeight( theValue );
return this;
}
@Override @ControlP5.Invisible public void mouseReleased( ) {
isDragging = isMinHandle = isMaxHandle = isMoveHandle = false;
mode = -1;
}
@Override @ControlP5.Invisible public void mouseReleasedOutside( ) {
mouseReleased( );
}
@Override @ControlP5.Invisible public void onLeave( ) {
isMinHandle = false;
isMaxHandle = false;
}
protected void setTickMarks( ) {
System.out.println( "Range Tickmarks not yet supported" );
}
public Range setColorTickMark( int theColor ) {
_myColorTickMark = theColor;
return this;
}
public Range showTickMarks( boolean theFlag ) {
isShowTickMarks = theFlag;
return this;
}
public Range snapToTickMarks( boolean theFlag ) {
isSnapToTickMarks = theFlag;
System.out.println( "Range Tickmarks not yet supported" );
return this;
}
@ControlP5.Invisible public TickMark getTickMark( ) {
System.out.println( "Range Tickmarks not yet supported" );
return null;
}
public ArrayList< TickMark > getTickMarks( ) {
return _myTickMarks;
}
public Range setNumberOfTickMarks( int theNumber ) {
System.out.println( "Range Tickmarks not yet supported" );
_myTickMarks.clear( );
if ( theNumber > 0 ) {
for ( int i = 0 ; i < theNumber ; i++ ) {
_myTickMarks.add( new TickMark( this ) );
}
showTickMarks( true );
snapToTickMarks( true );
} else {
showTickMarks( false );
snapToTickMarks( false );
}
_myUnit = ( _myMax - _myMin ) / ( ( getWidth( ) > getHeight( ) ) ? getWidth( ) - 1 : getHeight( ) - 1 );
setLowValue( _myArrayValue[ 0 ] , false );
setHighValue( _myArrayValue[ 1 ] , false );
return update( );
}
public Range setRange( float theMinValue , float theMaxValue ) {
setMin( theMinValue );
setMax( theMaxValue );
return this;
}
public Range setRangeValues( float theLowValue , float theHighValue ) {
return setArrayValue( new float[] { theLowValue , theHighValue } );
}
private Range setLowValue( float theValue , boolean isUpdate ) {
_myArrayValue[ 0 ] = PApplet.max( _myMin , snapValue( theValue ) );
minHandle = ( int ) PApplet.map( _myArrayValue[ 0 ] , _myMin , _myMax , handleSize , getWidth( ) - handleSize );
return ( isUpdate ) ? update( ) : this;
}
public Range setLowValue( float theValue ) {
return setLowValue( theValue , true );
}
private Range setHighValue( float theValue , boolean isUpdate ) {
_myArrayValue[ 1 ] = PApplet.min( _myMax , snapValue( theValue ) );
maxHandle = ( int ) PApplet.map( _myArrayValue[ 1 ] , _myMin , _myMax , handleSize , getWidth( ) - handleSize );
return ( isUpdate ) ? update( ) : this;
}
public Range setHighValue( float theValue ) {
return setHighValue( theValue , true );
}
protected float snapValue( float theValue ) {
if ( isMousePressed ) {
return theValue;
}
if ( isSnapToTickMarks ) {
_myValuePosition = ( ( theValue - _myMin ) / _myUnit );
float n = PApplet.round( PApplet.map( _myValuePosition , 0 , ( _myDirection == HORIZONTAL ) ? getWidth( ) : getHeight( ) , 0 , _myTickMarks.size( ) - 1 ) );
theValue = PApplet.map( n , 0 , _myTickMarks.size( ) - 1 , _myMin , _myMax );
}
return theValue;
}
@Override @ControlP5.Invisible public Range updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( ControlP5Constants.DEFAULT ):
_myControllerView = new RangeView( );
break;
case ( ControlP5Constants.SPRITE ):
_myControllerView = new RangeSpriteView( );
break;
case ( ControlP5Constants.IMAGE ):
_myControllerView = new RangeImageView( );
break;
case ( ControlP5Constants.CUSTOM ):
default:
break;
}
return this;
}
class RangeSpriteView implements ControllerView< Range > {
public void display( PGraphics theGraphics , Range theController ) {
ControlP5.logger( ).log( Level.INFO , "RangeSpriteDisplay not available." );
}
}
class RangeView implements ControllerView< Range > {
public void display( PGraphics theGraphics , Range theController ) {
int high = mode;
final float posX = Controller.x( _myParent.getAbsolutePosition( ) ) + Controller.x( position );
int x0 = ( int ) ( posX + minHandle );
int x1 = ( int ) ( posX + maxHandle );
if ( isInside( ) && high < 0 ) {
if ( _myControlWindow.mouseX >= x0 - handleSize && _myControlWindow.mouseX < x0 ) {
high = ControlP5Constants.LEFT;
} else if ( _myControlWindow.mouseX >= x1 && _myControlWindow.mouseX < x1 + handleSize ) {
high = ControlP5Constants.RIGHT;
} else if ( _myControlWindow.mouseX > x0 && _myControlWindow.mouseX < x1 && isDraggable ) {
high = ControlP5Constants.CENTER;
}
}
theGraphics.pushMatrix( );
theGraphics.fill( color.getBackground( ) );
theGraphics.noStroke( );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.fill( high == ControlP5Constants.CENTER ? color.getActive( ) : color.getForeground( ) );
if ( isShowTickMarks ) {
int n = handleSize / 2;
theGraphics.rect( minHandle - n , 0 , mr + handleSize , getHeight( ) );
theGraphics.fill( ( isMinHandle || high == ControlP5Constants.LEFT ) ? color.getActive( ) : color.getForeground( ) );
theGraphics.triangle( minHandle - handleSize , 0 , minHandle , 0 , minHandle - n , getHeight( ) );
theGraphics.fill( ( isMaxHandle || high == ControlP5Constants.RIGHT ) ? color.getActive( ) : color.getForeground( ) );
theGraphics.triangle( maxHandle , 0 , maxHandle + handleSize , 0 , maxHandle + n , getHeight( ) );
} else {
theGraphics.rect( minHandle , 0 , mr , getHeight( ) );
theGraphics.fill( ( isMinHandle || high == ControlP5Constants.LEFT ) ? color.getActive( ) : color.getForeground( ) );
theGraphics.rect( ( minHandle - handleSize ) , 0 , handleSize , getHeight( ) );
theGraphics.fill( ( isMaxHandle || high == ControlP5Constants.RIGHT ) ? color.getActive( ) : color.getForeground( ) );
theGraphics.rect( maxHandle , 0 , handleSize , getHeight( ) );
}
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
_myValueLabel.draw( theGraphics , 0 , 0 , theController );
_myHighValueLabel.draw( theGraphics , 0 , 0 , theController );
}
theGraphics.popMatrix( );
if ( isShowTickMarks ) {
theGraphics.pushMatrix( );
float x = ( getWidth( ) - handleSize ) / ( getTickMarks( ).size( ) - 1 );
theGraphics.translate( handleSize / 2 , getHeight( ) );
theGraphics.fill( _myColorTickMark );
for ( TickMark tm : getTickMarks( ) ) {
tm.draw( theGraphics );
theGraphics.translate( x , 0 );
}
theGraphics.popMatrix( );
}
}
}
class RangeImageView implements ControllerView< Range > {
public void display( PGraphics theGraphics , Range theController ) {
ControlP5.logger( ).log( Level.INFO , "RangeImageDisplay not implemented." );
}
}
@Override public Range setFont( PFont thePFont ) {
_myHighValueLabel.setFont( thePFont );
return super.setFont( thePFont );
}
@Override public Range setFont( ControlFont theFont ) {
_myHighValueLabel.setFont( theFont );
return super.setFont( theFont );
}
@Override @ControlP5.Invisible public String toString( ) {
return "type:\tRange\n" + super.toString( );
}
@Deprecated public float lowValue( ) {
return getLowValue( );
}
@Deprecated public float highValue( ) {
return getHighValue( );
}
@Deprecated public float[] arrayValue( ) {
return _myArrayValue;
}
}

View File

@ -0,0 +1,483 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import static main.java.src2.main.java.controlP5.controlP5.ControlP5.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.event.KeyEvent;
/**
* A ScrollableList is a list of vertically aligned items
* which can be scrolled if required.
*
* @example controllers/ControlP5scrollableList
*/
public class ScrollableList extends Controller< ScrollableList > implements ControlListener {
private int _myType = DROPDOWN;
protected int _myBackgroundColor = 0x00ffffff;
protected int itemHeight = 13;
protected int barHeight = 10;
private float scrollSensitivity = 1;
private boolean isOpen = true;
protected List< Map< String , Object > > items;
protected int itemRange = 5;
protected int itemHover = -1;
private int itemIndexOffset = 0;
private final int itemSpacing = 1;
private int _myDirection = PApplet.DOWN;
private boolean isBarVisible = true;
static public final int LIST = ControlP5.LIST;
static public final int DROPDOWN = ControlP5.DROPDOWN;
static public final int CHECKBOX = ControlP5.CHECKBOX; /* TODO */
static public final int TREE = ControlP5.TREE; /* TODO */
public ScrollableList( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 199 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected ScrollableList( ControlP5 theControlP5 , ControllerGroup< ? > theGroup , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theGroup , theName , theX , theY , theW , theH );
items = new ArrayList< Map< String , Object > >( );
updateHeight( );
getValueLabel( ).align( PApplet.LEFT , PApplet.CENTER );
}
public boolean isOpen( ) {
return isOpen;
}
public ScrollableList open( ) {
return setOpen( true );
}
public ScrollableList close( ) {
return setOpen( false );
}
public ScrollableList setOpen( boolean b ) {
isOpen = b;
return this;
}
@Override public int getHeight( ) {
return isOpen ? super.getHeight( ) : barHeight;
}
public ScrollableList setType( int theType ) {
_myType = theType;
return this;
}
public void setDirection( int theDirection ) {
_myDirection = ( theDirection == PApplet.UP ) ? PApplet.UP : PApplet.DOWN;
}
@Override protected boolean inside( ) {
/* constrain the bounds of the controller to the
* dimensions of the cp5 area, required since
* PGraphics as render area has been introduced. */
float x0 = PApplet.max( 0 , x( position ) + x( _myParent.getAbsolutePosition( ) ) );
float x1 = PApplet.min( cp5.pgw , x( position ) + x( _myParent.getAbsolutePosition( ) ) + getWidth( ) );
float y0 = PApplet.max( 0 , y( position ) + y( _myParent.getAbsolutePosition( ) ) );
float y1 = PApplet.min( cp5.pgh , y( position ) + y( _myParent.getAbsolutePosition( ) ) + getHeight( ) );
if ( y1 < y0 ) {
float ty = y0;
y0 = y1;
y1 = ty;
}
return ( _myControlWindow.mouseX > x0 && _myControlWindow.mouseX < x1 && _myControlWindow.mouseY > ( y1 < y0 ? y1 : y0 ) && _myControlWindow.mouseY < ( y0 < y1 ? y1 : y0 ) );
}
@Override protected void onRelease( ) {
if ( !isDragged ) {
if ( getPointer( ).y( ) >= 0 && getPointer( ).y( ) <= barHeight ) {
setOpen( !isOpen( ) );
} else if ( isOpen ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
// n += itemRange; /* UP */
int index = ( int ) n + itemIndexOffset;
updateIndex( index );
}
}
}
private void updateIndex( int theIndex ) {
if ( theIndex >= items.size( ) ) {
return;
}
Map m = items.get( theIndex );
switch ( _myType ) {
case ( LIST ):
super.setValue( theIndex );
for ( Object o : items ) {
( ( Map ) o ).put( "state" , false );
}
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
case ( DROPDOWN ):
super.setValue( theIndex );
setOpen( false );
getCaptionLabel( ).setText( ( m.get( "text" ).toString( ) ) );
break;
case ( CHECKBOX ):
m.put( "state" , !ControlP5.b( m.get( "state" ) ) );
break;
}
}
public ScrollableList setValue( float theValue ) {
updateIndex( ( int ) ( theValue ) );
return this;
}
@Override protected void onDrag( ) {
scroll( getPointer( ).dy( ) );
}
@Override protected void onScroll( int theValue ) {
scroll( theValue );
}
private void scroll( int theValue ) {
if ( isOpen ) {
itemIndexOffset += theValue;
itemIndexOffset = ( int ) ( Math.floor( Math.max( 0 , Math.min( itemIndexOffset , items.size( ) - itemRange ) ) ) );
itemHover = -2;
}
}
@Override protected void onLeave( ) {
itemHover = -1;
}
private void updateHover( ) {
if ( getPointer( ).y( ) > barHeight ) {
double n = Math.floor( ( getPointer( ).y( ) - barHeight ) / itemHeight );
itemHover = ( int ) ( itemIndexOffset + n );
} else {
itemHover = -1;
}
}
@Override protected void onEnter( ) {
updateHover( );
}
@Override protected void onMove( ) {
updateHover( );
}
@Override protected void onEndDrag( ) {
updateHover( );
}
private int updateHeight( ) {
itemRange = ( PApplet.abs( getHeight( ) ) - ( isBarVisible( ) ? barHeight : 0 ) ) / itemHeight;
return itemHeight * ( items.size( ) < itemRange ? items.size( ) : itemRange );
}
public ScrollableList setItemHeight( int theHeight ) {
itemHeight = theHeight;
updateHeight( );
return this;
}
public ScrollableList setBarHeight( int theHeight ) {
barHeight = theHeight;
updateHeight( );
return this;
}
public int getBarHeight( ) {
return barHeight;
}
public ScrollableList setScrollSensitivity( float theSensitivity ) {
scrollSensitivity = theSensitivity;
return this;
}
public ScrollableList setBarVisible( boolean b ) {
isBarVisible = b;
updateHeight( );
return this;
}
public boolean isBarVisible( ) {
return isBarVisible;
}
private Map< String , Object > getDefaultItemMap( String theName , Object theValue ) {
Map< String , Object > item = new HashMap< String , Object >( );
item.put( "name" , theName );
item.put( "text" , theName );
item.put( "value" , theValue );
item.put( "color" , getColor( ) );
item.put( "view" , new CDrawable( ) {
@Override public void draw( PGraphics theGraphics ) {
}
} );
item.put( "state" , false );
return item;
}
public ScrollableList addItem( String theName , Object theValue ) {
Map< String , Object > item = getDefaultItemMap( theName , theValue );
items.add( item );
return this;
}
public ScrollableList addItems( String[] theItems ) {
addItems( Arrays.asList( theItems ) );
return this;
}
public ScrollableList addItems( List< String > theItems ) {
for ( int i = 0 ; i < theItems.size( ) ; i++ ) {
addItem(theItems.get( i ), i );
}
return this;
}
public ScrollableList addItems( Map< String , Object > theItems ) {
for ( Map.Entry< String , Object > item : theItems.entrySet( ) ) {
addItem( item.getKey( ) , item.getValue( ) );
}
return this;
}
public ScrollableList setItems( String[] theItems ) {
setItems( Arrays.asList( theItems ) );
return this;
}
public ScrollableList setItems( List< String > theItems ) {
items.clear( );
return addItems( theItems );
}
public ScrollableList setItems( Map< String , Object > theItems ) {
items.clear( );
return addItems( theItems );
}
public ScrollableList removeItems( List< String > theItems ) {
for ( String s : theItems ) {
removeItem( s );
}
return this;
}
public ScrollableList removeItem( String theName ) {
if ( theName != null ) {
List l = new ArrayList( );
for ( Map m : items ) {
if ( theName.equals( m.get( "name" ) ) ) {
l.add( m );
}
}
items.removeAll( l );
}
return this;
}
public void updateItemIndexOffset( ) {
int m1 = items.size( ) > itemRange ? ( itemIndexOffset + itemRange ) : items.size( );
int n = ( m1 - items.size( ) );
if ( n >= 0 ) {
itemIndexOffset -= n;
}
}
public Map< String , Object > getItem( int theIndex ) {
return items.get( theIndex );
}
public Map< String , Object > getItem( String theName ) {
if ( theName != null ) {
for ( Map< String , Object > o : items ) {
if ( theName.equals( o.get( "name" ) ) ) {
return o;
}
}
}
return Collections.EMPTY_MAP;
}
public List getItems( ) {
return Collections.unmodifiableList( items );
}
public ScrollableList clear( ) {
for ( int i = items.size( ) - 1 ; i >= 0 ; i-- ) {
items.remove( i );
}
items.clear( );
itemIndexOffset = 0;
return this;
}
@Override public void controlEvent( ControlEvent theEvent ) {
// TODO Auto-generated method stub
}
public ScrollableList setBackgroundColor( int theColor ) {
_myBackgroundColor = theColor;
return this;
}
public int getBackgroundColor( ) {
return _myBackgroundColor;
}
@Override @ControlP5.Invisible public ScrollableList updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new ScrollableListView( );
break;
case ( IMAGE ):
case ( SPRITE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
static public class ScrollableListView implements ControllerView< ScrollableList > {
public void display( PGraphics g , ScrollableList c ) {
// setHeight( -200 ); /* UP */
g.noStroke( );
if ( c.isBarVisible( ) ) {
boolean b = c.itemHover == -1 && c.isInside && !c.isDragged;
g.fill( b ? c.getColor( ).getForeground( ) : c.getColor( ).getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.barHeight );
g.pushMatrix( );
g.translate( c.getWidth( ) - 8 , c.barHeight / 2 - 2 );
g.fill( c.getColor( ).getCaptionLabel( ) );
if ( c.isOpen( ) ) {
g.triangle( -3 , 0 , 3 , 0 , 0 , 3 );
} else {
g.triangle( -3 , 3 , 3 , 3 , 0 , 0 );
}
g.popMatrix( );
c.getCaptionLabel( ).draw( g , 4 , c.barHeight / 2 );
}
if ( c.isOpen( ) ) {
int bar = ( c.isBarVisible( ) ? c.barHeight : 0 );
int h = ( ( c.updateHeight( ) ) );
g.pushMatrix( );
// g.translate( 0 , - ( h + bar +
// c.itemSpacing ) ); /* UP */
g.fill( c.getBackgroundColor( ) );
g.rect( 0 , bar , c.getWidth( ) , h );
g.pushMatrix( );
g.translate( 0 , ( bar == 0 ? 0 : ( c.barHeight + c.itemSpacing ) ) );
/* draw visible items */
c.updateItemIndexOffset( );
int m0 = c.itemIndexOffset;
int m1 = c.items.size( ) > c.itemRange ? ( c.itemIndexOffset + c.itemRange ) : c.items.size( );
for ( int i = m0 ; i < m1 ; i++ ) {
Map< String , Object > item = c.items.get( i );
CColor color = ( CColor ) item.get( "color" );
g.fill( ( ControlP5.b( item.get( "state" ) ) ) ? color.getActive( ) : ( i == c.itemHover ) ? ( c.isMousePressed ? color.getActive( ) : color.getForeground( ) ) : color.getBackground( ) );
g.rect( 0 , 0 , c.getWidth( ) , c.itemHeight - 1 );
c.getValueLabel( ).set( item.get( "text" ).toString( ) ).draw( g , 4 , c.itemHeight / 2 );
g.translate( 0 , c.itemHeight );
}
g.popMatrix( );
if ( c.isInside ) {
int m = c.items.size( ) - c.itemRange;
if ( m > 0 ) {
g.fill( c.getColor( ).getCaptionLabel( ) );
g.pushMatrix( );
int s = 4; /* spacing */
int s2 = s / 2;
g.translate( c.getWidth( ) - s , c.barHeight );
int len = ( int ) PApplet.map( ( float ) Math.log( m * 10 ) , 0 , 10 , h , 0 );
int pos = ( int ) ( PApplet.map( c.itemIndexOffset , 0 , m , s2 , h - len - s2 ) );
g.rect( 0 , pos , s2 , len );
g.popMatrix( );
}
}
g.popMatrix( );
}
}
}
public void keyEvent( KeyEvent theKeyEvent ) {
if ( isInside && theKeyEvent.getAction( ) == KeyEvent.PRESS ) {
switch ( theKeyEvent.getKeyCode( ) ) {
case (UP):
scroll( theKeyEvent.isAltDown( ) ? -itemIndexOffset : theKeyEvent.isShiftDown( ) ? -10 : -1 );
updateHover( );
break;
case (DOWN):
scroll( theKeyEvent.isAltDown( ) ? items.size( ) - itemRange : theKeyEvent.isShiftDown( ) ? 10 : 1 );
updateHover( );
break;
case (LEFT):
break;
case (RIGHT):
break;
case (ENTER):
onRelease( );
break;
}
}
}
/* TODO keycontrol: arrows, return dragging moving items
* sorting custom view custom event types */
}

648
controlP5/Slider.java Executable file
View File

@ -0,0 +1,648 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.ArrayList;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* A slider is either used horizontally or vertically. when adding a slider to controlP5, the width
* is compared against the height. if the width is bigger, you get a horizontal slider, is the
* height bigger, you get a vertical slider. a slider can have a fixed slider handle (one end of the
* slider is fixed to the left or bottom side of the controller), or a flexible slider handle (a
* handle you can drag).
*
*
* @example controllers/ControlP5slider
*/
public class Slider extends Controller< Slider > {
public final static int FIX = 1;
public final static int FLEXIBLE = 0;
protected int _mySliderMode = FIX;
protected float _myValuePosition;
protected int _myHandleSize = 0;
protected int _myDefaultHandleSize = 10;
protected int triggerId = PRESSED;
protected ArrayList< TickMark > _myTickMarks = new ArrayList< TickMark >( );
protected boolean isShowTickMarks;
protected boolean isSnapToTickMarks;
protected static int autoWidth = 99;
protected static int autoHeight = 9;
protected float scrollSensitivity = 0.1f;
protected int _myColorTickMark = 0xffffffff;
private SliderView _myView;
protected float _myMinReal = 0;
protected float _myMaxReal = 1;
protected float _myInternalValue = 0;
/**
* Convenience constructor to extend Slider.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Slider( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 100 , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
public Slider( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theMin , float theMax , float theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myMin = 0;
_myMax = 1;
// with _myMinReal and _myMaxReal the range of values can now range
// from big to small (e.g. 255 to 0) as well as from small to big (e.g. 0 to 255)
_myMinReal = theMin;
_myMaxReal = theMax;
_myValue = PApplet.map( theDefaultValue , _myMinReal , _myMaxReal , 0 , 1 );
_myCaptionLabel = new Label( cp5 , theName ).setColor( color.getCaptionLabel( ) );
_myValueLabel = new Label( cp5 , String.valueOf(getValue())).setColor( color.getValueLabel( ) );
setSliderMode( FIX );
}
@ControlP5.Invisible @Override public void init( ) {
// need to override init here since _myValue will only be a
// normalized value here but _myDefaultValue needs to be absolute.
// by normalizing _myValue the range of values can be from 'big-to-small'
// as well as from 'small-to-big'
// in order not to break anything, init() will be overwritten here.
_myDefaultValue = getValue( );
cp5.getControlBroadcaster( ).plug( cp5.papplet , this , _myName );
initControllerValue( );
isInit = cp5.isAutoInitialization;
setValue( _myDefaultValue );
isInit = true;
updateDisplayMode( DEFAULT );
}
/**
* use the slider mode to set the mode of the slider bar, which can be Slider.FLEXIBLE or
* Slider.FIX
*
* @param theMode
* int
*/
public Slider setSliderMode( int theMode ) {
_myView = ( getWidth( ) > getHeight( ) ) ? new SliderViewH( ) : new SliderViewV( );
_myControllerView = ( getWidth( ) > getHeight( ) ) ? new SliderViewH( ) : new SliderViewV( );
_mySliderMode = theMode;
if ( _mySliderMode == FLEXIBLE ) {
_myHandleSize = ( _myDefaultHandleSize >= getHeight( ) / 2 ) ? _myDefaultHandleSize / 2 : _myDefaultHandleSize;
} else {
_myHandleSize = 0;
}
_myView.updateUnit( );
setValue( PApplet.map( _myValue , 0 , 1 , _myMinReal , _myMaxReal ) );
return this;
}
public int getSliderMode( ) {
return _mySliderMode;
}
/**
* sets the size of the Slider handle, by default it is set to either the width or height of the
* slider.
*
* @param theSize
*/
public Slider setHandleSize( int theSize ) {
_myDefaultHandleSize = theSize;
setSliderMode( _mySliderMode );
return this;
}
public int getHandleSize( ) {
return _myHandleSize;
}
/**
* @see ControllerInterface.updateInternalEvents
*
*/
@ControlP5.Invisible public Slider updateInternalEvents( PApplet theApplet ) {
if ( isVisible ) {
if ( isMousePressed && !cp5.isAltDown( ) ) {
_myView.updateInternalEvents( theApplet );
}
}
return this;
}
/**
* the trigger event is set to Slider.PRESSED by default but can be changed to Slider.RELEASE so
* that events are triggered when the slider is released.
*
* @param theEventID
*/
public Slider setTriggerEvent( int theEventID ) {
triggerId = theEventID;
return this;
}
/**
* returns the current trigger event which is either Slider.PRESSED or Slider.RELEASE
*
* @return int
*/
public int getTriggerEvent( ) {
return triggerId;
}
@Override protected void mouseReleasedOutside( ) {
mouseReleased( );
}
@Override protected void mouseReleased( ) {
if ( triggerId == RELEASE ) {
_myView.update( );
broadcast( FLOAT );
}
}
protected Slider snapValue( float theValue ) {
if ( isSnapToTickMarks ) {
_myValuePosition = ( ( _myValue - _myMin ) / _myUnit );
_myView.setSnapValue( );
}
return this;
}
public float getValuePosition( ) {
return _myValuePosition;
}
/**
* set the value of the slider.
*
* @param theValue
* float
*/
@Override public Slider setValue( float theValue ) {
if ( isMousePressed && theValue == getValue( ) ) {
return this;
}
_myInternalValue = theValue;
_myValue = PApplet.map( theValue , _myMinReal , _myMaxReal , 0 , 1 );
snapValue( _myValue );
_myValue = ( _myValue <= _myMin ) ? _myMin : _myValue;
_myValue = ( _myValue >= _myMax ) ? _myMax : _myValue;
_myValuePosition = ( ( _myValue - _myMin ) / _myUnit );
_myValueLabel.set( adjustValue( getValue( ) ) );
if ( triggerId == PRESSED ) {
broadcast( FLOAT );
}
return this;
}
@Override public float getValue( ) {
return PApplet.map( _myValue , 0 , 1 , _myMinReal , _myMaxReal );
}
/**
* assigns a random value to the slider.
*/
public Slider shuffle( ) {
float r = ( float ) Math.random( );
setValue( PApplet.map( r , 0 , 1 , _myMinReal , _myMaxReal ) );
return this;
}
/**
* sets the sensitivity for the scroll behavior when using the mouse wheel or the scroll
* function of a multi-touch track pad. The smaller the value (closer to 0) the higher the
* sensitivity. by default this value is set to 0.1
*
* @param theValue
* @return Slider
*/
public Slider setScrollSensitivity( float theValue ) {
scrollSensitivity = theValue;
return this;
}
/**
* changes the value of the slider when hovering and using the mouse wheel or the scroll
* function of a multi-touch track pad.
*
* @param theRotationValue
* @return Slider
*/
@ControlP5.Invisible public Slider scrolled( int theRotationValue ) {
if ( isVisible ) {
float f = _myValue;
float steps = isSnapToTickMarks ? ( 1.0f / getNumberOfTickMarks( ) ) : scrollSensitivity * 0.1f;
f += ( _myMax - _myMin ) * ( -theRotationValue * steps );
setValue( PApplet.map( f , 0 , 1 , _myMinReal , _myMaxReal ) );
if ( triggerId == RELEASE ) {
broadcast( FLOAT );
}
}
return this;
}
@Override public Slider update( ) {
return setValue( PApplet.map( _myValue , 0 , 1 , _myMinReal , _myMaxReal ) );
}
/**
* sets the minimum value of the slider.
*
* @param theValue
* float
*/
@Override public Slider setMin( float theValue ) {
float f = getValue( );
_myMinReal = theValue;
_myValue = PApplet.map( f , _myMinReal , _myMaxReal , 0 , 1 );
setSliderMode( _mySliderMode );
return this;
}
/**
* set the maximum value of the slider.
*
* @param theValue
* float
*/
@Override public Slider setMax( float theValue ) {
float f = getValue( );
_myMaxReal = theValue;
_myValue = PApplet.map( f , _myMinReal , _myMaxReal , 0 , 1 );
setSliderMode( _mySliderMode );
return this;
}
@Override public float getMin( ) {
return _myMinReal;
}
@Override public float getMax( ) {
return _myMaxReal;
}
public Slider setRange( float theMin , float theMax ) {
float f = _myInternalValue;
_myMinReal = theMin;
_myMaxReal = theMax;
_myValue = PApplet.map( f , _myMinReal , _myMaxReal , 0 , 1 );
setSliderMode( _mySliderMode );
return this;
}
/**
* set the width of the slider.
*
* @param theValue
* int
*/
@Override public Slider setWidth( int theValue ) {
super.setWidth( theValue );
setSliderMode( _mySliderMode );
return this;
}
/**
* set the height of the slider.
*
* @param theValue
* int
*/
@Override public Slider setHeight( int theValue ) {
super.setHeight( theValue );
setSliderMode( _mySliderMode );
return this;
}
@Override public Slider setSize( int theWidth , int theHeight ) {
super.setWidth( theWidth );
setHeight( theHeight );
_myView = ( getWidth( ) > getHeight( ) ) ? new SliderViewH( ) : new SliderViewV( );
return this;
}
/* TODO new implementations follow: http://www.ibm.com/developerworks/java/library/j-dynui/ take
* interface builder as reference */
protected Slider setTickMarks( ) {
return this;
}
/**
* sets the number of tickmarks for a slider, by default tick marks are turned off.
*
* @param theNumber
*/
public Slider setNumberOfTickMarks( int theNumber ) {
_myTickMarks.clear( );
if ( theNumber > 0 ) {
for ( int i = 0 ; i < theNumber ; i++ ) {
_myTickMarks.add( new TickMark( this ) );
}
showTickMarks( true );
snapToTickMarks( true );
setHandleSize( 20 );
} else {
showTickMarks( false );
snapToTickMarks( false );
setHandleSize( _myDefaultHandleSize );
}
setValue( PApplet.map( _myValue , 0 , 1 , _myMinReal , _myMaxReal ) );
return this;
}
/**
* returns the amount of tickmarks available for a slider
*
* @return int
*/
public int getNumberOfTickMarks( ) {
return _myTickMarks.size( );
}
/**
* shows or hides tickmarks for a slider
*
* @param theFlag
* @return Slider
*/
public Slider showTickMarks( boolean theFlag ) {
isShowTickMarks = theFlag;
return this;
}
/**
* enables or disables snap to tick marks.
*
* @param theFlag
* @return Slider
*/
public Slider snapToTickMarks( boolean theFlag ) {
isSnapToTickMarks = theFlag;
return this;
}
/**
* returns an instance of a tickmark by index.
*
* @see TickMark
* @param theIndex
* @return
*/
public TickMark getTickMark( int theIndex ) {
if ( theIndex >= 0 && theIndex < _myTickMarks.size( ) ) {
return _myTickMarks.get( theIndex );
} else {
return null;
}
}
/**
* returns an ArrayList of available tick marks for a slider.
*
* @return ArrayList<TickMark>
*/
public ArrayList< TickMark > getTickMarks( ) {
return _myTickMarks;
}
/**
* {@inheritDoc}
*/
@Override @ControlP5.Invisible public Slider linebreak( ) {
cp5.linebreak( this , true , autoWidth , autoHeight , autoSpacing );
return this;
}
/**
* sets the color of tick marks if enabled. by default the color is set to white.
*
* @param theColor
* @return Slider
*/
public Slider setColorTickMark( int theColor ) {
_myColorTickMark = theColor;
return this;
}
public int getDirection( ) {
return ( _myView instanceof SliderViewH ) ? HORIZONTAL : VERTICAL;
}
/**
* {@inheritDoc}
*/
@Override @ControlP5.Invisible public Slider updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = ( getWidth( ) > getHeight( ) ) ? new SliderViewH( ) : new SliderViewV( );
break;
case ( IMAGE ):
// TODO
break;
case ( SPRITE ):
// TODO
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
private abstract class SliderView implements ControllerView< Slider > {
abstract void updateInternalEvents( PApplet theApplet );
abstract void update( );
abstract void updateUnit( );
abstract void setSnapValue( );
}
private class SliderViewV extends SliderView {
SliderViewV( ) {
_myCaptionLabel.align( LEFT , BOTTOM_OUTSIDE ).setPadding( 0 , Label.paddingY );
_myValueLabel.set(adjustValue(getValue())).align( RIGHT_OUTSIDE , TOP );
}
void setSnapValue( ) {
float n = PApplet.round( PApplet.map( _myValuePosition , 0 , getHeight( ) , 0 , _myTickMarks.size( ) - 1 ) );
_myValue = PApplet.map( n , 0 , _myTickMarks.size( ) - 1 , _myMin , _myMax );
}
void updateUnit( ) {
_myUnit = ( _myMax - _myMin ) / ( getHeight( ) - _myHandleSize );
}
void update( ) {
float f = _myMin + ( - ( _myControlWindow.mouseY - ( y( _myParent.getAbsolutePosition( ) ) + y( position ) ) - getHeight( ) ) ) * _myUnit;
setValue( PApplet.map( f , 0 , 1 , _myMinReal , _myMaxReal ) );
}
void updateInternalEvents( PApplet theApplet ) {
float f = _myMin + ( - ( _myControlWindow.mouseY - ( y( _myParent.getAbsolutePosition( ) ) + y( position ) ) - getHeight( ) ) ) * _myUnit;
setValue( PApplet.map( f , 0 , 1 , _myMinReal , _myMaxReal ) );
}
public void display( PGraphics theGraphics , Slider theController ) {
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.noStroke( );
if ( ( getColor( ).getBackground( ) >> 24 & 0xff ) > 0 ) {
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
}
theGraphics.fill( getIsInside( ) ? getColor( ).getActive( ) : getColor( ).getForeground( ) );
if ( getSliderMode( ) == FIX ) {
theGraphics.rect( 0 , getHeight( ) , getWidth( ) , -getValuePosition( ) );
} else {
if ( isShowTickMarks ) {
theGraphics.triangle( getWidth( ) , getHeight( ) - getValuePosition( ) , getWidth( ) , getHeight( ) - getValuePosition( ) - getHandleSize( ) , 0 , getHeight( ) - getValuePosition( ) - getHandleSize( ) / 2 );
} else {
theGraphics.rect( 0 , getHeight( ) - getValuePosition( ) - getHandleSize( ) , getWidth( ) , getHandleSize( ) );
}
}
if ( isLabelVisible ) {
getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController );
theGraphics.pushMatrix( );
theGraphics.translate( 0 , ( int ) PApplet.map( _myValue , _myMax , _myMin , 0 , getHeight( ) - _myValueLabel.getHeight( ) ) );
getValueLabel( ).draw( theGraphics , 0 , 0 , theController );
theGraphics.popMatrix( );
}
if ( isShowTickMarks ) {
theGraphics.pushMatrix( );
theGraphics.pushStyle( );
theGraphics.translate( -4 , ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 );
theGraphics.fill( _myColorTickMark );
float x = ( getHeight( ) - ( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) ) ) / ( getTickMarks( ).size( ) - 1 );
for ( TickMark tm : getTickMarks( ) ) {
tm.draw( theGraphics , getDirection( ) );
theGraphics.translate( 0 , x );
}
theGraphics.popStyle( );
theGraphics.popMatrix( );
}
}
}
private class SliderViewH extends SliderView {
SliderViewH( ) {
_myCaptionLabel.align( RIGHT_OUTSIDE , CENTER );
_myValueLabel.set(adjustValue(getValue())).align( LEFT , CENTER );
}
void setSnapValue( ) {
float n = PApplet.round( PApplet.map( _myValuePosition , 0 , getWidth( ) , 0 , _myTickMarks.size( ) - 1 ) );
_myValue = PApplet.map( n , 0 , _myTickMarks.size( ) - 1 , _myMin , _myMax );
}
void updateUnit( ) {
_myUnit = ( _myMax - _myMin ) / ( getWidth( ) - _myHandleSize );
}
void update( ) {
float f = _myMin + ( _myControlWindow.mouseX - ( x( _myParent.getAbsolutePosition( ) ) + x( position ) ) ) * _myUnit;
setValue( PApplet.map( f , 0 , 1 , _myMinReal , _myMaxReal ) );
}
void updateInternalEvents( PApplet theApplet ) {
float f = _myMin + ( _myControlWindow.mouseX - ( x( _myParent.getAbsolutePosition( ) ) + x( position ) ) ) * _myUnit;
setValue( PApplet.map( f , 0 , 1 , _myMinReal , _myMaxReal ) );
}
public void display( PGraphics theGraphics , Slider theController ) {
theGraphics.fill( getColor( ).getBackground( ) );
theGraphics.noStroke( );
if ( ( getColor( ).getBackground( ) >> 24 & 0xff ) > 0 ) {
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
}
theGraphics.fill( getIsInside( ) ? getColor( ).getActive( ) : getColor( ).getForeground( ) );
if ( getSliderMode( ) == FIX ) {
theGraphics.rect( 0 , 0 , getValuePosition( ) , getHeight( ) );
} else {
if ( isShowTickMarks ) {
theGraphics.triangle( getValuePosition( ) , 0 , getValuePosition( ) + getHandleSize( ) , 0 , getValuePosition( ) + _myHandleSize / 2 , getHeight( ) );
} else {
theGraphics.rect( getValuePosition( ) , 0 , getHandleSize( ) , getHeight( ) );
}
}
theGraphics.fill( 255 );
if ( isLabelVisible ) {
getValueLabel( ).draw( theGraphics , 0 , 0 , theController );
getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController );
}
if ( isShowTickMarks ) {
theGraphics.pushMatrix( );
// theGraphics.pushStyle( );
theGraphics.translate( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 , getHeight( ) );
theGraphics.fill( _myColorTickMark );
theGraphics.noStroke( );
float x = ( getWidth( ) - ( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) ) ) / ( getTickMarks( ).size( ) - 1 );
for ( TickMark tm : getTickMarks( ) ) {
tm.draw( theGraphics , getDirection( ) );
theGraphics.translate( x , 0 );
}
// theGraphics.popStyle( );
theGraphics.popMatrix( );
}
}
}
@Deprecated public void setSliderBarSize( int theSize ) {
_myDefaultHandleSize = theSize;
setSliderMode( _mySliderMode );
}
/**
* @see Slider#setScrollSensitivity(float)
*
* @param theValue
* @return Slider
*/
@Deprecated public Slider setSensitivity( float theValue ) {
return setScrollSensitivity( theValue );
}
}

287
controlP5/Slider2D.java Executable file
View File

@ -0,0 +1,287 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* The Slider2D allows to control a handle within a 2D area. This controller returns an arrayValue
* with the current xy position of its handle.
*
* @author andreas schlegel
*
* @example controllers/ControlP5slider2D
*
*/
public class Slider2D extends Controller< Slider2D > {
protected int cursorWidth = 6 , cursorHeight = 6;
protected float cursorX , cursorY;
protected float _myMinX , _myMinY;
protected float _myMaxX , _myMaxY;
public boolean isCrosshairs = true;
private String _myValueLabelSeparator = ",";
/**
* Convenience constructor to extend Slider2D.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Slider2D( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 99 , 9 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Slider2D( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myArrayValue = new float[] { 0.0f , 0.0f };
_myMinX = 0;
_myMinY = 0;
_myMaxX = theWidth;
_myMaxY = theHeight;
getCaptionLabel( ).setPadding( 0 , Label.paddingY ).align( LEFT , BOTTOM_OUTSIDE );
getValueLabel( ).setPadding( 0 , Label.paddingY ).align( RIGHT , BOTTOM_OUTSIDE );
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#updateInternalEvents(processing.core.PApplet) */
@ControlP5.Invisible public Slider2D updateInternalEvents( PApplet theApplet ) {
if ( isInside( ) ) {
if ( !cp5.isAltDown( ) ) {
float tX = PApplet.constrain( _myControlWindow.mouseX - ( x( _myParent.getAbsolutePosition( ) ) + x( position ) ) , 0 , getWidth( ) - cursorWidth );
float tY = PApplet.constrain( _myControlWindow.mouseY - ( y( _myParent.getAbsolutePosition( ) ) + y( position ) ) , 0 , getHeight( ) - cursorHeight );
if ( isMousePressed ) {
cursorX = tX;
cursorY = tY;
updateValue( );
}
}
}
return this;
}
Slider2D updateValue( ) {
return setValue( 0 );
}
public Slider2D setMinMax( float theMinX , float theMinY , float theMaxX , float theMaxY ) {
_myMinX = theMinX;
_myMinY = theMinY;
_myMaxX = theMaxX;
_myMaxY = theMaxY;
return setValue( _myArrayValue[ 0 ] , _myArrayValue[ 1 ] );
}
/**
* sets the minimum value for the x-axis
*
* @param theMinX
* @return Slider2D
*/
public Slider2D setMinX( float theMinX ) {
_myMinX = theMinX;
return updateValue( );
}
/**
* sets the minimum value for the y-axis
*
* @param theMinY
* @return Slider2D
*/
public Slider2D setMinY( float theMinY ) {
_myMinY = theMinY;
return updateValue( );
}
/**
* sets the maximum value for the x-axis
*
* @param theMaxX
* @return Slider2D
*/
public Slider2D setMaxX( float theMaxX ) {
_myMaxX = theMaxX;
return updateValue( );
}
/**
* sets the maximum value for the y-axis
*
* @param theMaxY
* @return Slider2D
*/
public Slider2D setMaxY( float theMaxY ) {
_myMaxY = theMaxY;
return updateValue( );
}
public float getMinX( ) {
return _myMinX;
}
public float getMinY( ) {
return _myMinY;
}
public float getMaxX( ) {
return _myMaxX;
}
public float getMaxY( ) {
return _myMaxY;
}
public float getCursorX( ) {
return cursorX;
}
public float getCursorY( ) {
return cursorY;
}
public float getCursorWidth( ) {
return cursorWidth;
}
public float getCursorHeight( ) {
return cursorHeight;
}
public Slider2D disableCrosshair( ) {
isCrosshairs = false;
return this;
}
public Slider2D enableCrosshair( ) {
isCrosshairs = true;
return this;
}
/* (non-Javadoc) TODO see https://forum.processing.org/topic/controlp5-slider2d-questions
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#setArrayValue(float[]) */
@Override public Slider2D setArrayValue( float[] theArray ) {
_myArrayValue = theArray;
float rX = ( getWidth( ) - cursorWidth ) / ( _myMaxX - _myMinX );
float rY = ( getHeight( ) - cursorHeight ) / ( _myMaxY - _myMinY );
cursorX = PApplet.constrain( theArray[ 0 ] * rX , 0 , getWidth( ) - cursorWidth );
cursorY = PApplet.constrain( theArray[ 1 ] * rY , 0 , getHeight( ) - cursorHeight );
return updateValue( );
}
public float[] getArrayValue( ) {
return _myArrayValue;
}
public Slider2D setCursorX( float theValue ) {
return setArrayValue( new float[] { theValue , getArrayValue( )[ 1 ] } );
}
public Slider2D setCursorY( float theValue ) {
return setArrayValue( new float[] { getArrayValue( )[ 0 ] , theValue } );
}
/* (non-Javadoc)
*
* @see main.java.src2.main.java.controlP5.controlp5.Controller#setValue(float) */
public Slider2D setValue( float theValue ) {
_myArrayValue[ 0 ] = cursorX / ( ( float ) ( getWidth( ) - cursorWidth ) / ( float ) getWidth( ) );
_myArrayValue[ 1 ] = cursorY / ( ( float ) ( getHeight( ) - cursorHeight ) / ( float ) getHeight( ) );
_myArrayValue[ 0 ] = PApplet.map( _myArrayValue[ 0 ] , 0 , getWidth( ) , _myMinX , _myMaxX );
_myArrayValue[ 1 ] = PApplet.map( _myArrayValue[ 1 ] , 0 , getHeight( ) , _myMinY , _myMaxY );
_myValueLabel.set( adjustValue( _myArrayValue[ 0 ] , 0 ) + _myValueLabelSeparator + adjustValue( _myArrayValue[ 1 ] , 0 ) );
broadcast( FLOAT );
return this;
}
public Slider2D setValue( float theValue1 , float theValue2 ) {
cursorX = PApplet.map( theValue1 , _myMinX , _myMaxX , 0 , getWidth( ) - cursorWidth );
cursorY = PApplet.map( theValue2 , _myMinY , _myMaxY , 0 , getHeight( ) - cursorHeight );
return setValue( 0 );
}
/**
* assigns a random value to the controller.
*/
public Slider2D shuffle( ) {
float rX = ( float ) Math.random( );
float rY = ( float ) Math.random( );
_myArrayValue[ 0 ] = rX * getWidth( );
_myArrayValue[ 0 ] = rY * getHeight( );
return setValue( 0 );
}
public void setValueLabelSeparator( String theSeparator ) {
_myValueLabelSeparator = theSeparator;
}
/**
* {@inheritDoc}
*/
@Override @ControlP5.Invisible public Slider2D updateDisplayMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new Slider2DView( );
break;
case ( IMAGE ):
case ( SPRITE ):
case ( CUSTOM ):
default:
break;
}
return this;
}
class Slider2DView implements ControllerView< Slider2D > {
public void display( PGraphics theGraphics , Slider2D theController ) {
theGraphics.noStroke( );
theGraphics.fill( theController.getColor( ).getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.fill( theController.isInside ? theController.getColor( ).getActive( ) : theController.getColor( ).getForeground( ) );
theGraphics.rect( ( int ) getCursorX( ) , ( int ) getCursorY( ) , ( int ) getCursorWidth( ) , ( int ) getCursorHeight( ) );
if ( isCrosshairs ) {
theGraphics.rect( 0 , ( int ) ( getCursorY( ) + getCursorHeight( ) / 2 ) , getWidth( ), 1 );
theGraphics.rect( ( int ) ( getCursorX( ) + getCursorWidth( ) / 2 ) , 0 , 1 , getHeight( ));
}
getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController );
getValueLabel( ).draw( theGraphics , 0 , 0 , theController );
}
}
}

67
controlP5/Spacer.java Normal file
View File

@ -0,0 +1,67 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
public class Spacer extends Controller< Spacer > {
private int _myWeight = 1;
public Spacer( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 20 , 20 );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Spacer( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myControllerView = new SpacerView( );
}
public Spacer setWeight( int theWeight ) {
_myWeight = theWeight;
return this;
}
public Spacer setColor( int theColor ) {
getColor( ).setForeground( theColor );
return this;
}
private class SpacerView implements ControllerView< Spacer > {
public void display( PGraphics g , Spacer c ) {
g.fill( c.getColor( ).getForeground( ) );
g.noStroke( );
if ( c.getWidth( ) >= c.getHeight( ) ) {
g.rect( 0 , ( c.getHeight( ) / 2 ) - _myWeight / 2 , c.getWidth( ) , _myWeight );
} else {
g.rect( ( c.getWidth( ) / 2 ) - _myWeight / 2 , 0 , _myWeight , c.getHeight( ) );
}
}
}
}

92
controlP5/TODO Executable file
View File

@ -0,0 +1,92 @@
2014-09-08 Andreas Schlegel
* add glyphicons reference to controlp5.Icon.java http://glyphicons.com
* add useiconic to controlp5.Icon.java https://useiconic.com/open
2014-05-29 Andreas Schlegel
* distinguish between left,center, right mouse click events http://forum.processing.org/two/discussion/5422/controlp5-mousepressed-only-if-mousebutton-left-
2014-04-22 Andreas Schlegel
* javascript version on hold; it is unclear which project processing.js or p5.js will become the default js framework for processing
2013-09-09 Andreas Schlegel
* javascript version
* textinput on android
* color picker used for clicks-and-strokes
* rendering into pgraphics
* add colorwheel
* add ControlFrame with customizable render access
* spacer / separator
2011-03-24 Andreas Schlegel
* finish info to toString conversion
* implement plugTo for ControllerGroups
* BitFontRenderer addBitFont is broken, see the ControlP5bitFont example,
the font is cut off at the bottom, probably something wrong with
the label's PImage height.
2010-08-07 Andreas Schlegel
* fix ControlWindowCanvas.pre(), doesnt work anymore.
2010-07-25 Andreas Schlegel
* Android support, current version conflicts with android java (ControlWindow, PAppletWindow, using Toolkit when loading bit-font, KeyEvents, etc.)
* CColor: alpha handling
* Chart: finish. a chart graph controller to display line, bar, pie and histogram charts.
2010-04-02 Andreas Schlegel
* BitFontRenderer: \n is recognized as a not-supported-character. fix!
* general: processingjs port
* Knob: implement new version of knob
* Textfield: implement new version of textfield
* TextArea: implement new version of TextArea
* Label: implement modifications so that text rendering for P3D works properly
* picking: use an image and color-coding for picking controllers instead mouse-coordinates against rectangular boxes.
* fileChooser conflicts with mouse event.
http://processing.org/discourse/yabb2/YaBB.pl?num=1247162607/0#0
* alt-tab causes problems with dragging functionality.
http://processing.org/discourse/yabb2/YaBB.pl?num=1242718131/0#0
* Multilist, pop out to the left.
* ScrollList, slider on the left option.
* ScrollList: collapse/and hide. add option to hide the scroll-list area but only keep the scrollbar.
* add CheckBoxList
* tab issues as addressed in this post:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1237538493;start=2#2
- moveTo does not work for only a String which would stanbd for the name of a tab
- controlP5.window(this).activateTab("myTab");
controlP5.tab("myTab").mousePressed();
* ControlGroup, set Width of bar. the + - toggle is not updated visually.
* Text -Field, -Label, -Area: customize font
* textarea: when changing the font of the valueLabel, the scrollbar is not updated / does not show even it is required. current hack is: myTextarea.setHeight(myTextarea.valueLabel().height());
* textarea: automatically updating the scrollbar whensetting text with setText() see email from martin froehlich 16.january 2009
* save and load does not work for some controllers.
* loading and saving
* multilist, range, matrix dont load from xml file.
* colorstyle does not save and load.
* labels dont save properly, background color is not saved.
* matrix needs to be redone. develop whole new concept for matrix / synthesizer.
* multitouch support
* controlWindow: add feedback when closing window. see email from henri 5 january 2009
* controllerStyle: see email from johnny rodgers 30 november 2008
* range: see email from hartmut bohnacker 27 november 2008
* textfield: see email from henri 14 october 2008
* save and open file dialog: see email from henri 12 october 2008
* ControlBroadcaster suggestions: see email from aaron mayers 2 october 2008
* pushmatrix / popMatrix : see email from florian 6 june 2008
Lib.pre() { /*other code */ pushMatrix(); }
PApplet.draw() { ... }
Lib.draw() { popMatrix(); /* the lib code, untransformed */ }
DONE
* (done) add setArrayValue to Controller class.
* (done, implemented with TickMark) Slider: snap
* (done) add id() method to ControlEvent
* (done, fixed) fix save/load. saving twice and loading again results in empty.
* (done) add setTitle to ControlWindow http://processing.org/discourse/yabb2/YaBB.pl?num=1245762312/0#0
* (done, now ListBox) redo ScrollList so that it becomes a controller? change the button management of a scrollList.

228
controlP5/Tab.java Executable file
View File

@ -0,0 +1,228 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* Tabs are used to organize controllers. Tabs are arranged horizontally from the top-left corner by
* default, Tab extends ControllerGroup, for more available methods see the ControllerGroup
* documentation. Reposition tabs with {@link ControlWindow#setPositionOfTabs(int, int)}
*
* @example controllers/ControlP5tab
* @nosuperclasses ControllerGroup ControllerGroup
*/
public class Tab extends ControllerGroup< Tab > {
protected int _myOffsetX = -1000;
protected int _myOffsetY = -1000;
protected boolean isActive = false;
private boolean isAlwaysActive = false;
protected boolean isEventActive = false;
protected float _myValue = 0;
protected String _myStringValue = "";
public static int padding = 4;
public boolean autoWidth = true;
/**
*
* @param theControlP5 ControlP5
* @param theControlWindow ControlWindow
* @param theName String
*/
public Tab( ControlP5 theControlP5 , ControlWindow theControlWindow , String theName ) {
super( theControlP5 , null , theName , 0 , 0 );
position = new float[ 2 ];
absolutePosition = new float[ 2 ];
isMoveable = false;
isEventActive = theControlP5.isTabEventsActive;
_myHeight = 16;
_myWidth = _myLabel.getWidth( ) + padding * 2;
_myLabel.align( LEFT , CENTER ).setPadding( 0 , 0 );
}
protected void setOffset( int theValueX , int theValueY ) {
_myOffsetX = theValueX;
_myOffsetY = theValueY;
}
protected int height( ) {
return _myHeight;
}
protected boolean updateLabel( ) {
isInside = inside( );
return cp5.getWindow( ).getTabs( ).size( ) > 2;
}
protected void drawLabel( PGraphics theGraphics ) {
if ( autoWidth ) {
_myWidth = _myLabel.getWidth( ) + padding * 2;
}
theGraphics.pushMatrix( );
theGraphics.pushStyle( );
theGraphics.noStroke( );
theGraphics.fill( isInside ? color.getForeground( ) : color.getBackground( ) );
if ( isActive ) {
theGraphics.fill( color.getActive( ) );
}
theGraphics.translate( _myOffsetX , _myOffsetY );
theGraphics.rect( 0 , 0 , _myWidth - 1 , _myHeight );
_myLabel.draw( theGraphics , padding , 0 , this );
theGraphics.popStyle( );
theGraphics.popMatrix( );
}
/**
* set the label of the group. TODO overwriting COntrollerGroup.setLabel to set the Width of a
* tab after renaming. this should be temporary and fixed in the future.
*
* @param theLabel String
* @return Tab
*/
public Tab setLabel( String theLabel ) {
_myLabel.set( theLabel );
return this;
}
protected int width( ) {
return _myWidth;
}
/**
* @param theWidth
* @return
*/
public Tab setWidth( int theWidth ) {
_myWidth = theWidth + padding;
autoWidth = false;
return this;
}
public Tab setHeight( int theHeight ) {
_myHeight = theHeight;
return this;
}
protected boolean inside( ) {
return ( cp5.getWindow( ).mouseX > _myOffsetX && cp5.getWindow( ).mouseX < _myOffsetX + _myWidth && cp5.getWindow( ).mouseY > _myOffsetY && cp5.getWindow( ).mouseY < _myOffsetY + _myHeight );
}
/**
* {@inheritDoc}
*/
@ControlP5.Invisible public void mousePressed( ) {
cp5.getWindow( ).activateTab( this );
if ( isEventActive ) {
cp5.getControlBroadcaster( ).broadcast( new ControlEvent( this ) , METHOD);
}
}
/**
* Activates a tab.
*
* @param theFlag boolean
*/
public Tab setActive( boolean theFlag ) {
isActive = theFlag;
return this;
}
public Tab setAlwaysActive( boolean theFlag ) {
isAlwaysActive = theFlag;
return this;
}
/**
* checks if a tab is active.
*
* @return boolean
*/
public boolean isActive( ) {
return isAlwaysActive || isActive;
}
public boolean isAlwaysActive( ) {
return isAlwaysActive;
}
@Override public Tab bringToFront( ) {
cp5.getWindow( ).activateTab( this );
return this;
}
/**
* {@inheritDoc}
*/
@Override public Tab moveTo( ControlWindow theWindow ) {
cp5.getWindow( ).removeTab( this );
setTab( theWindow , getName( ) );
return this;
}
/**
* activates or deactivates the Event status of a tab, When activated a tab will send a
* controlEvent to the main application. By default this is disabled.
*
* @param theFlag boolean
* @return Tab
*/
public Tab activateEvent( boolean theFlag ) {
isEventActive = theFlag;
return this;
}
/**
* {@inheritDoc}
*/
@Override public String getStringValue( ) {
return _myStringValue;
}
/**
* {@inheritDoc}
*/
@Override public float getValue( ) {
return _myValue;
}
/**
* {@inheritDoc}
*/
@Override public Tab setValue( float theValue ) {
_myValue = theValue;
return this;
}
@Deprecated public float value( ) {
return _myValue;
}
@Deprecated public String stringValue( ) {
return _myStringValue;
}
}

447
controlP5/Textarea.java Executable file
View File

@ -0,0 +1,447 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.Arrays;
import java.util.List;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
/**
* a textarea can be used to leave notes, it uses the controlP5 BitFont to render text. Scrollbars
* will automatically be added when text extends the visible area. Textarea extends ControllerGroup,
* for more methods available see the ControllerGroup documentation.
*
* @example controllers/ControlP5textarea
*/
public class Textarea extends ControllerGroup< Textarea > implements ControlListener {
protected String _myText;
protected Slider _myScrollbar;
protected int _myColorBackground = 0x000000;
protected boolean isColorBackground = false;
protected float _myScrollValue = 0;
protected boolean isScrollbarVisible = true;
protected int _myBottomOffset = 4;
private final int _myScrollbarWidth = 5;
/**
* Convenience constructor to extend Textarea.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Textarea( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , "" , 0 , 0 , 199 , 99 );
theControlP5.register( theControlP5.papplet , theName , this );
}
/**
*
* @param theControlP5
* ControlP5
* @param theGroup
* ControllerGroup
* @param theName
* String
* @param theText
* String
* @param theX
* int
* @param theY
* int
* @param theW
* int
* @param theH
* int
*/
protected Textarea( ControlP5 theControlP5 , ControllerGroup< ? > theGroup , String theName , String theText , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theGroup , theName , theX , theY );
_myWidth = theW;
_myHeight = theH;
_myText = theText;
setup( );
}
/**
*
* @param theText
* String
* @param theX
* int
* @param theY
* int
*/
public Textarea( String theText , int theX , int theY ) {
super( theX , theY );
_myText = theText;
setup( );
}
private void setup( ) {
_myValueLabel = new Label( cp5 , _myText );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myValueLabel.setWidth(_myWidth);
_myValueLabel.setHeight(_myHeight);
_myValueLabel.setMultiline( true );
_myValueLabel.toUpperCase( false );
_myValueLabel.setColor( color.getValueLabel( ) );
_myScrollbar = new Slider( cp5 , _myParent , getName( ) + "Scroller" , 0 , 1 , 1 , _myWidth - 5 , 0 , 5 , _myHeight );
_myScrollbar.init( );
_myScrollbar.setBroadcast( false );
_myScrollbar.setSliderMode( Slider.FLEXIBLE );
_myScrollbar.isMoveable = false;
_myScrollbar.isLabelVisible = false;
_myScrollbar.setParent( this );
_myScrollbar.addListener( this );
add( _myScrollbar );
setWidth( _myWidth );
setHeight( _myHeight );
_myScrollbar.color.set( color );
_myScrollbar.setColorBackground( 0x00000000 );
_myScrollbar.setHandleSize( 40 );
}
/**
*
* @param theEvent
* ControlEvent
*/
public void controlEvent( ControlEvent theEvent ) {
_myScrollValue = - ( 1 - theEvent.getValue( ) );
scroll( );
}
public Textarea hideScrollbar( ) {
isScrollbarVisible = false;
_myScrollbar.hide( );
return this;
}
public Textarea showScrollbar( ) {
isScrollbarVisible = true;
boolean isScrollbar = _myHeight < ( _myValueLabel.getTextHeight( ) + _myValueLabel.getLineHeight( ) );
if ( isScrollbar ) {
_myScrollbar.show( );
}
return this;
}
public boolean isScrollable( ) {
return _myScrollbar.isVisible( );
}
@Override public Textarea setColorBackground( int theColor ) {
_myColorBackground = theColor;
isColorBackground = true;
return this;
}
public Textarea disableColorBackground( ) {
isColorBackground = false;
return this;
}
public Textarea enableColorBackground( ) {
isColorBackground = true;
return this;
}
/**
* scroll the Textarea remotely. values must range from 0 to 1.
*
* @param theValue
*/
public Textarea scroll( float theValue ) {
_myScrollbar.setValue( 1 - theValue );
return this;
}
/**
* private update method for the scrollbar.
*/
private void scroll( ) {
_myScrollValue = PApplet.min( PApplet.max( -1 , _myScrollValue ) , 0 );
float myLen = _myValueLabel.getTextHeight( ) + _myValueLabel.getLineHeight( );
float myOffset = 0;
boolean isScrollbar = _myHeight < myLen;
if ( isScrollbar ) {
myOffset = _myScrollValue * ( myLen - _myHeight + _myBottomOffset );
}
isScrollbar = isScrollbarVisible && isScrollbar;
_myScrollbar.setVisible( isScrollbar );
_myValueLabel.setOffsetYratio( _myScrollValue );
}
@ControlP5.Invisible public void scrolled( int theStep ) {
if ( _myScrollbar.isVisible( ) ) {
int lines = ( _myValueLabel.getTextHeight( ) / _myValueLabel.getLineHeight( ) );
float step = 1.0f / lines;
scroll( ( 1 - getScrollPosition( ) ) + ( theStep * step ) );
}
}
@ControlP5.Invisible public float getScrollPosition( ) {
return _myScrollbar.getValue( );
}
/**
* set the width of the textarea.
*
* @param theValue
* int
*/
@Override public Textarea setWidth( int theValue ) {
theValue = ( theValue < 10 ) ? 10 : theValue;
_myWidth = theValue;
_myValueLabel.setWidth( _myWidth - _myScrollbarWidth - 10 );
return this;
}
/**
* set the height of the textarea.
*
* @param theValue
* int
*/
@Override public Textarea setHeight( int theValue ) {
theValue = ( theValue < 10 ) ? 10 : theValue;
_myHeight = theValue;
_myValueLabel.setHeight( _myHeight - 2 );
_myScrollbar.setHeight( theValue );
return this;
}
public Textarea setSize( int theWidth , int theHeight ) {
setWidth( theWidth );
setHeight( theHeight );
return this;
}
/**
* set the lineheight of the textarea.
*
* @param theLineHeight
* int
*/
public Textarea setLineHeight( int theLineHeight ) {
_myValueLabel.setLineHeight( theLineHeight );
scroll( );
return this;
}
/**
* set the text color of the textarea.
*
* @param theColor
* int
*/
public Textarea setColor( int theColor ) {
_myValueLabel.setColor( theColor , true );
return this;
}
/**
* returns the instance of the textarea's label.
*
* @return
*/
public Label getValueLabel( ) {
return _myValueLabel;
}
/**
* set the text of the textarea.
*
* @param theText
* String
*/
public Textarea setText( String theText ) {
_myValueLabel.set( theText );
_myScrollValue = ( float ) ( _myHeight ) / ( float ) ( _myValueLabel.getTextHeight( ) );
_myScrollbar.setHeight( _myHeight + _myValueLabel.getStyle( ).paddingTop + _myValueLabel.getStyle( ).paddingBottom );
return this;
}
public Textarea clear( ) {
return setText( "" );
}
public Textarea append( String theText ) {
return setText( getText( ) + theText );
}
public Textarea append( String theText , int max ) {
String str = getText( ) + theText;
if ( max == -1 ) {
return setText( str );
}
List< String > strs = Arrays.asList( str.split( "\n" ) );
return setText( CP.join( strs.subList( Math.max( 0 , strs.size( ) - max ) , strs.size( ) ) , "\n" ) );
}
/**
* returns the text content of the textarea.
*
* @return String
*/
public String getText( ) {
return getStringValue( );
}
@Override protected void preDraw( PGraphics theGraphics ) {
if ( isScrollbarVisible ) {
_myScrollbar.setVisible( _myValueLabel.getOverflow( ) > 1 );
}
if ( _myScrollbar.isVisible( ) || isColorBackground ) {
float x = _myWidth - _myScrollbarWidth + _myValueLabel.getStyle( ).paddingLeft + _myValueLabel.getStyle( ).paddingRight;
float y = y( _myScrollbar.getPosition( ) );
set( _myScrollbar.getPosition( ) , x , y );
if ( !isColorBackground ) {
theGraphics.noFill( );
} else {
int a = _myColorBackground >> 24 & 0xff;
theGraphics.fill( _myColorBackground , a > 0 ? a : 255 );
}
int ww = _myWidth + _myValueLabel.getStyle( ).paddingLeft + _myValueLabel.getStyle( ).paddingRight;
int hh = _myHeight + _myValueLabel.getStyle( ).paddingTop + _myValueLabel.getStyle( ).paddingBottom;
theGraphics.rect( 0 , 0 , ww , hh );
}
}
// !!! add padding to the box.
// padding and margin doesnt work nicely with textarea yet!
protected boolean inside( ) {
return ( cp5.getWindow( ).mouseX > x( position ) + x( _myParent.absolutePosition ) && cp5.getWindow( ).mouseX < x( position ) + x( _myParent.absolutePosition ) + _myWidth
&& cp5.getWindow( ).mouseY > y( position ) + y( _myParent.absolutePosition ) && cp5.getWindow( ).mouseY < y( position ) + y( _myParent.absolutePosition ) + _myHeight );
}
public String getStringValue( ) {
return _myValueLabel.getText( );
}
public Textarea setFont( ControlFont theFont ) {
getValueLabel( ).setFont( theFont );
return this;
}
public Textarea setFont( PFont thePFont ) {
getValueLabel( ).setFont( thePFont );
return this;
}
public Textarea setFont( int theFontIndex ) {
getValueLabel( ).setFont( theFontIndex );
return this;
}
/**
* @param theColor
* @return Textarea
*/
public Textarea setScrollBackground( int theColor ) {
_myScrollbar.setColorBackground( theColor );
return this;
}
/**
* @param theColor
* @return Textarea
*/
public Textarea setScrollForeground( int theColor ) {
_myScrollbar.setColorForeground( theColor );
return this;
}
/**
* @param theColor
* @return Textarea
*/
public Textarea setScrollActive( int theColor ) {
_myScrollbar.setColorActive( theColor );
return this;
}
/**
* @param theColor
* @return Textarea
*/
public Textarea setBorderColor( int theColor ) {
color.setBackground( theColor );
return this;
}
/**
* {@inheritDoc}
*/
@Override public float getValue( ) {
return 0;
}
@Deprecated public float value( ) {
return 0;
}
@Deprecated public String stringValue( ) {
return getStringValue( );
}
@Deprecated public Label valueLabel( ) {
return getValueLabel( );
}
/**
* @exclude
* @deprecated
* @return
*/
@Deprecated public boolean isScrollbarVisible( ) {
return isScrollbarVisible;
}
/**
* @deprecated
* @exclude
* @return
*/
@Deprecated public String text( ) {
return getText( );
}
}
// @todo linebreaking algorithm.
// http://www.leverkruid.eu/GKPLinebreaking/index.html
// found at http://www.texone.org/?p=43

484
controlP5/Textfield.java Executable file
View File

@ -0,0 +1,484 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import main.java.src2.main.java.controlP5.controlP5.events.ReleasedOutsideListener;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.event.Event;
import processing.event.KeyEvent;
/**
* A singleline input textfield, use arrow keys to go back and forth, use backspace to delete
* characters. Using the up and down arrows lets you cycle through the history of the textfield.
*
* This is the best you can get. Font handling, font switching, measuring, left align, right align,
* etc. was giving me a big headache. not perfect, i think this is a good compromise.
*
* @example controllers/ControlP5textfield
* @nosuperclasses Controller Controller
*/
public class Textfield extends Controller< Textfield > implements ReleasedOutsideListener {
/* TODO textspacing does not work properly for bitfonts sometimes first row of pixels in a
* bitfont texture gets cut off */
protected boolean isTexfieldActive;
protected boolean isKeepFocus;
protected StringBuffer _myTextBuffer = new StringBuffer( );
protected int _myTextBufferIndex = 0;
protected int _myTextBufferOverflow = 0;
protected int _myTextBufferIndexPosition = 0;
public static int cursorWidth = 1;
protected Map< Integer , TextfieldCommand > keyMapping;
protected InputFilter _myInputFilter = InputFilter.BITFONT;
protected List< Integer > ignorelist;
protected LinkedList< String > _myHistory;
protected int _myHistoryIndex;
protected int len = 0;
protected int offset = 2;
protected int margin = 2;
protected boolean isPasswordMode;
protected boolean autoclear = true;
protected int _myColorCursor = 0x88ffffff;
protected PGraphics buffer;
public enum InputFilter {
INTEGER(Arrays.asList( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' )), FLOAT(Arrays.asList( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '.' )), BITFONT(Arrays.asList( '\n' , '\r' , ' ' , '!' , '"' , '#' , '$' , '%' ,
'&' , '\'' , '(' , ')' , '*' , '+' , ',' , '-' , '.' , '/' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ':' , ';' , '<' , '=' , '>' , '?' , '@' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' ,
'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , '[' , '\\' , ']' , '^' , '_' , '`' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' ,
'v' , 'w' , 'x' , 'y' , 'z' , '{' , '|' , '}' , '~' )), DEFAULT(new LinkedList< Character >( ));
final List< Character > allowed;
InputFilter( List< Character > theList ) {
allowed = theList;
}
private boolean apply(char theCharater) {
if ( allowed.isEmpty( ) ) {
return true;
} else {
return allowed.contains( theCharater );
}
}
}
/**
* Convenience constructor to extend Textfield.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Textfield( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , "" , 0 , 0 , 199 , 19 );
theControlP5.register( theControlP5.papplet , theName , this );
}
public Textfield( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , String theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myCaptionLabel = new Label( cp5 , theName , 0 , 0 , color.getCaptionLabel( ) );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myCaptionLabel.align(LEFT, BOTTOM_OUTSIDE);
_myCaptionLabel.setPaddingX( 0 );
_myBroadcastType = STRING;
_myValueLabel.setFixedSize( true );
_myValueLabel.set( "" );
_myValueLabel.setWidth( getWidth( ) - margin * 2 );
_myValueLabel.setPadding( 0 , 0 );
_myValueLabel.align( LEFT , CENTER );
_myValueLabel.setColor( color.getValueLabel( ) );
_myValueLabel.toUpperCase( false );
_myValueLabel.setLabeltype( _myValueLabel.new SinglelineTextfield( ) );
_myHistory = new LinkedList< String >( );
_myHistory.addFirst( "" );
setSize( getWidth( ) , getHeight( ) );
keyMapping = new HashMap< Integer , TextfieldCommand >( );
keyMapping.put( ENTER , new Enter( ) );
keyMapping.put( DEFAULT , new InsertCharacter( ) );
keyMapping.put( DELETE , new DeleteCharacter( ) );
keyMapping.put( BACKSPACE , new DeleteCharacter( ) );
keyMapping.put( LEFT , new MoveLeft( ) );
keyMapping.put( RIGHT , new MoveRight( ) );
keyMapping.put( UP , new MoveUp( ) );
keyMapping.put( DOWN , new MoveDown( ) );
ignorelist = new LinkedList< Integer >( );
ignorelist.add( SHIFT );
ignorelist.add( ALT );
ignorelist.add( CONTROL );
ignorelist.add( TAB );
ignorelist.add( COMMANDKEY );
setInputFilter( DEFAULT );
}
@Override public Textfield setWidth( int theWidth ) {
_myValueLabel.setWidth( theWidth );
return super.setWidth( theWidth );
}
@Override public Textfield setHeight( int theHeight ) {
_myValueLabel.setHeight( theHeight );
return super.setHeight( theHeight );
}
public Textfield setFocus( boolean theValue ) {
isTexfieldActive = isActive = theValue;
return this;
}
/**
* check if the textfield is active and in focus.
*
* @return boolean
*/
public boolean isFocus( ) {
return isTexfieldActive;
}
public Textfield keepFocus( boolean theValue ) {
isKeepFocus = theValue;
if ( isKeepFocus ) {
setFocus( true );
}
return this;
}
// public Textfield setFont( PFont thePFont ) {
// getValueLabel( ).setFont( thePFont );
// return this;
// }
//
// public Textfield setFont( ControlFont theFont ) {
// getValueLabel( ).setFont( theFont );
// return this;
// }
public Textfield setFont( int theFont ) {
getValueLabel( ).setFont( theFont );
return this;
}
public Textfield setPasswordMode( boolean theFlag ) {
isPasswordMode = theFlag;
return this;
}
public Textfield setInputFilter( int theInputType ) {
switch ( theInputType ) {
case ( INTEGER ):
_myInputFilter = InputFilter.INTEGER;
break;
case ( FLOAT ):
_myInputFilter = InputFilter.FLOAT;
break;
case ( BITFONT ):
_myInputFilter = InputFilter.BITFONT;
break;
default:
_myInputFilter = InputFilter.DEFAULT;
break;
}
return this;
}
@Override public Textfield setValue( float theValue ) {
// use setText(String) instead
return this;
}
@Override protected void updateFont( ControlFont theControlFont ) {
super.updateFont( theControlFont );
}
public Textfield setValue( String theText ) {
_myTextBuffer = new StringBuffer( theText );
setIndex( _myTextBuffer.length( ) );
return this;
}
public Textfield setText( String theText ) {
return setValue( theText );
}
public Textfield clear( ) {
// create a new text buffer
_myTextBuffer = new StringBuffer( );
// reset the buffer index
setIndex( 0 );
return this;
}
public Textfield setAutoClear( boolean theValue ) {
autoclear = theValue;
return this;
}
public boolean isAutoClear( ) {
return autoclear;
}
@Override protected void mousePressed( ) {
super.mousePressed();
if ( isActive ) {
// TODO System.out.println("adjust cursor");
}
int x = ( int ) ( getControlWindow( ).mouseX - x( getAbsolutePosition( ) ) );
int y = ( int ) ( getControlWindow( ).mouseY - y( getAbsolutePosition( ) ) );
// TODO System.out.println(x + ":" + y);
setFocus( true );
}
@Override public void mouseReleasedOutside( ) {
if (!isKeepFocus) {
isTexfieldActive = isActive = false;
}
}
public int getIndex( ) {
return _myTextBufferIndex;
}
public String getText( ) {
return _myTextBuffer.toString( );
}
public String[] getTextList( ) {
String[] s = new String[ _myHistory.size( ) ];
_myHistory.toArray( s );
return s;
}
public Map<Integer, TextfieldCommand> getKeyMapping() {
return keyMapping;
}
public Textfield setColor(int theColor ) {
getValueLabel( ).setColor( theColor );
return this;
}
public Textfield setColorCursor( int theColor ) {
_myColorCursor = theColor;
return this;
}
@Override public Textfield setSize( int theWidth , int theHeight ) {
super.setSize( theWidth , theHeight );
buffer = cp5.papplet.createGraphics( getWidth( ) , getHeight( ) );
return this;
}
@Override public void draw( PGraphics theGraphics ) {
theGraphics.pushStyle( );
theGraphics.fill( color.getBackground( ) );
theGraphics.pushMatrix( );
theGraphics.translate( x( position ) , y( position ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.noStroke( );
theGraphics.fill( _myColorCursor );
theGraphics.pushMatrix( );
theGraphics.pushStyle( );
buffer.beginDraw( );
buffer.background( 0 , 0 );
final String text = passCheck( getText( ) );
final int textWidth = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
final int dif = PApplet.max( textWidth - _myValueLabel.getWidth( ) , 0 );
final int _myTextBufferIndexPosition = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
_myValueLabel.setText( text );
_myValueLabel.draw( buffer , -dif , 0 , this );
buffer.noStroke( );
if ( isTexfieldActive ) {
if ( !cp5.papplet.keyPressed ) {
buffer.fill( _myColorCursor , PApplet.abs( PApplet.sin( cp5.papplet.frameCount * 0.05f )) * 255 );
} else {
buffer.fill( _myColorCursor );
}
buffer.rect( PApplet.max( 1 , PApplet.min( _myTextBufferIndexPosition , _myValueLabel.getWidth( ) - 3 ) ) , 0 , 1 , getHeight( ) );
}
buffer.endDraw( );
theGraphics.image( buffer , 0 , 0 );
theGraphics.popStyle( );
theGraphics.popMatrix( );
theGraphics.fill( isTexfieldActive ? color.getActive( ) : color.getForeground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , 1 );
theGraphics.rect( 0 , getHeight( ) - 1 , getWidth( ) , 1 );
theGraphics.rect( -1 , 0 , 1 , getHeight( ) );
theGraphics.rect( getWidth( ) , 0 , 1 , getHeight( ) );
_myCaptionLabel.draw( theGraphics , 0 , 0 , this );
theGraphics.popMatrix( );
theGraphics.popStyle( );
}
private String passCheck( String label ) {
if ( !isPasswordMode ) {
return label;
}
String newlabel = "";
for ( int i = 0 ; i < label.length( ) ; i++ ) {
newlabel += "*";
}
return newlabel;
}
public void keyEvent( KeyEvent theKeyEvent ) {
if ( isUserInteraction && isTexfieldActive && isActive && theKeyEvent.getAction( ) == KeyEvent.PRESS ) {
if ( ignorelist.contains( cp5.getKeyCode( ) ) ) {
return;
}
if ( keyMapping.containsKey( cp5.getKeyCode( ) ) ) {
keyMapping.get( cp5.getKeyCode( ) ).execute( );
} else {
keyMapping.get( DEFAULT ).execute( );
}
}
}
/**
* make the controller execute a return event. submit the current content of the texfield.
*
*/
public Textfield submit( ) {
keyMapping.get( ENTER ).execute( );
return this;
}
protected Textfield setIndex( int theIndex ) {
_myTextBufferIndex = theIndex;
return this;
}
class InsertCharacter implements TextfieldCommand {
public void execute( ) {
if ( ( int ) ( cp5.getKey( ) ) == 65535 ) {
return;
}
if ( _myInputFilter.apply( cp5.getKey( ) ) ) {
_myTextBuffer.insert( _myTextBufferIndex , cp5.getKey( ));
setIndex( _myTextBufferIndex + 1 );
}
}
}
class Enter implements TextfieldCommand {
public void execute( ) {
setStringValue( _myTextBuffer.toString( ) );
broadcast( );
// update current buffer with the last item inside the input history
_myHistory.set( _myHistory.size( ) - 1 , _myTextBuffer.toString( ) );
// set the history index to our last item
_myHistoryIndex = _myHistory.size( );
// add a new and empty buffer to the history
_myHistory.add( "" );
if ( autoclear ) {
clear( );
}
}
}
class DeleteCharacter implements TextfieldCommand {
public void execute( ) {
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
_myTextBuffer.deleteCharAt( _myTextBufferIndex - 1 );
setIndex( _myTextBufferIndex - 1 );
}
}
}
class MoveLeft implements TextfieldCommand {
public void execute( ) {
setIndex( ( ( cp5.modifiers & Event.META ) > 0 ) ? 0 : PApplet.max( 0 , _myTextBufferIndex - 1 ) );
}
}
class MoveRight implements TextfieldCommand {
public void execute( ) {
setIndex( ( ( cp5.modifiers & Event.META ) > 0 ) ? _myTextBuffer.length( ) : PApplet.min( _myTextBuffer.length( ) , _myTextBufferIndex + 1 ) );
}
}
class MoveUp implements TextfieldCommand {
public void execute( ) {
if ( _myHistoryIndex == 0 ) {
return;
}
_myHistoryIndex = PApplet.max( 0 , --_myHistoryIndex );
_myTextBuffer = new StringBuffer( _myHistory.get( _myHistoryIndex ) );
setIndex( _myTextBuffer.length( ) );
}
}
class MoveDown implements TextfieldCommand {
public void execute( ) {
if ( _myHistoryIndex >= _myHistory.size( ) - 1 ) {
return;
}
_myHistoryIndex = PApplet.min( _myHistory.size( ) - 1 , ++_myHistoryIndex );
_myTextBuffer = new StringBuffer( _myHistory.get( _myHistoryIndex ) );
setIndex( _myTextBuffer.length( ) );
}
}
}

View File

@ -0,0 +1,5 @@
package main.java.src2.main.java.controlP5.controlP5;
public interface TextfieldCommand {
void execute( );
}

243
controlP5/Textlabel.java Executable file
View File

@ -0,0 +1,243 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.Arrays;
import java.util.List;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
/**
* @example controllers/ControlP5textlabel
* @nosuperclasses Controller Controller Textarea
*/
public class Textlabel extends Controller< Textlabel > {
protected int _myLetterSpacing = 0;
private boolean disabled;
/**
*
* @param theControlP5 ControlP5
* @param theParent Tab
* @param theName String
* @param theValue String
* @param theX int
* @param theY int
*/
protected Textlabel( final ControlP5 theControlP5 , final Tab theParent , final String theName , final String theValue , final int theX , final int theY ) {
super( theControlP5 , theParent , theName , theX , theY , 200 , 20 );
_myStringValue = theValue;
setup( );
}
/**
*
* @param theValue String
* @param theX int
* @param theY int
*/
protected Textlabel( final String theValue , final int theX , final int theY ) {
super( "" , theX , theY );
_myStringValue = theValue;
setup( );
}
protected Textlabel( final String theValue , final int theX , final int theY , final int theW , final int theH , final int theColor ) {
super( "" , theX , theY );
_myStringValue = theValue;
_myValueLabel = new Label( cp5 , _myStringValue , theW , theH , theColor );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myValueLabel.setMultiline( false );
_myValueLabel.toUpperCase( false );
}
public Textlabel( ControlP5 theControlP5 , final String theValue , final int theX , final int theY ) {
super( "" , theX , theY );
cp5 = theControlP5;
_myStringValue = theValue;
_myValueLabel = new Label( cp5 , _myStringValue , 10 , 10 , 0xffffffff );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myValueLabel.set( _myStringValue );
_myValueLabel.setMultiline( false );
_myValueLabel.toUpperCase( false );
}
public Textlabel( ControlP5 theControlP5 , final String theValue , final int theX , final int theY , final int theW , final int theH ) {
super( "" , theX , theY );
cp5 = theControlP5;
_myStringValue = theValue;
_myValueLabel = new Label( cp5 , _myStringValue , theW , theH , 0xffffffff );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myValueLabel.setMultiline( false );
_myValueLabel.toUpperCase( false );
}
protected void setup( ) {
_myValueLabel = new Label( cp5 , _myStringValue );
_myValueLabel.setFont( cp5.controlFont == cp5.defaultFont ? cp5.defaultFontForText : cp5.controlFont );
_myValueLabel.setMultiline( false );
_myValueLabel.toUpperCase( false );
}
@Override public Textlabel setWidth( int theValue ) {
_myValueLabel.setWidth( theValue );
return this;
}
public Textlabel setHeight( int theValue ) {
_myValueLabel.setHeight( theValue );
return this;
}
public void draw( final PApplet theApplet ) {
draw( theApplet.g );
}
@Override public void draw( final PGraphics theGraphics ) {
if ( !disabled ) {
theGraphics.pushMatrix( );
theGraphics.translate( x( position ) , y( position ) );
_myValueLabel.draw( theGraphics , 0 , 0 , this );
theGraphics.popMatrix( );
}
}
public void draw( ) {
draw( cp5.pg );
}
public void draw( int theX , int theY ) {
cp5.papplet.pushMatrix( );
cp5.papplet.translate( theX , theY );
draw( cp5.pg );
cp5.papplet.popMatrix( );
}
public Textlabel setValue( float theValue ) {
return this;
}
public Textlabel setText( final String theText ) {
return setValue( theText );
}
public Textlabel setLineHeight( int theValue ) {
_myValueLabel.setLineHeight( theValue );
return this;
}
public int getLineHeight( ) {
return _myValueLabel.getLineHeight( );
}
public ControllerStyle getStyle() {
return _myValueLabel.getStyle( );
}
public Textlabel append( String theText , int max ) {
String str = _myStringValue + theText;
if ( max == -1 ) {
return setText( str );
}
List< String > strs = Arrays.asList( str.split( "\n" ) );
return setText( CP.join( strs.subList( Math.max( 0 , strs.size( ) - max ) , strs.size( ) ) , "\n" ) );
}
@Override public Textlabel setStringValue( String theValue ) {
return setValue( theValue );
}
public Textlabel setMultiline( final boolean theFlag ) {
_myValueLabel.setMultiline( true );
return this;
}
/**
* set the text of the textlabel.
*
* @param theText String
*/
public Textlabel setValue( final String theText ) {
_myStringValue = theText;
_myValueLabel.set( theText );
setWidth( _myValueLabel.getWidth( ) );
setHeight( _myValueLabel.getHeight( ) );
return this;
}
public Textlabel setColor( int theColor ) {
_myValueLabel.setColor( theColor , true );
return this;
}
/**
* set the letter spacing of the font.
*
* @param theValue int
* @return Textlabel
*/
public Textlabel setLetterSpacing( final int theValue ) {
_myLetterSpacing = theValue;
_myValueLabel.setLetterSpacing( _myLetterSpacing );
return this;
}
public Textlabel setFont( ControlFont theControlFont ) {
getValueLabel( ).setFont( theControlFont );
return this;
}
public Textlabel setFont( PFont thePFont ) {
getValueLabel( ).setFont( thePFont );
return this;
}
protected boolean inside( ) {
return ( _myControlWindow.mouseX > x( position ) + x( _myParent.getAbsolutePosition( ) ) && _myControlWindow.mouseX < x( position ) + x( _myParent.getAbsolutePosition( ) ) + _myValueLabel.getWidth( )
&& _myControlWindow.mouseY > y( position ) + y( _myParent.getAbsolutePosition( ) ) && _myControlWindow.mouseY < y( position ) + y( _myParent.getAbsolutePosition( ) ) + _myValueLabel.getHeight( ) );
}
public Label get( ) {
return _myValueLabel;
}
private void printConstructorError( String theValue ) {
ControlP5
.logger( )
.severe(
"The Textlabel constructor you are using has been deprecated, please use constructor\nnew Textlabel(ControlP5,String,int,int) or\nnew Textlabel(ControlP5,String,int,int,int,int) or\nnew Textlabel(ControlP5,String,int,int,int,int,int,int)\ninstead. The Textlabel with value '"
+ theValue + "' is disabled and will not be rendered." );
}
}

93
controlP5/TickMark.java Executable file
View File

@ -0,0 +1,93 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
/**
* Tickmarks are used by the Slider and Knob controller.
*/
public class TickMark implements CDrawable {
protected Controller< ? > _myParent;
protected int _myLen = 4;
protected Label _myLabel;
protected boolean isLabel;
public TickMark( Controller< ? > theController ) {
_myParent = theController;
}
public void draw( PGraphics theGraphics ) {
draw( theGraphics , ControlP5Constants.HORIZONTAL );
}
public void draw( PGraphics theGraphics , int theDirection ) {
theGraphics.pushMatrix( );
switch ( theDirection ) {
case ( ControlP5Constants.HORIZONTAL ):
theGraphics.translate( 0 , _myLen );
theGraphics.rect( 0 , 0 , 1 , _myLen );
if ( isLabel ) {
_myLabel.draw( theGraphics , 0 , _myLen + 4 , _myParent );
}
break;
case ( ControlP5Constants.VERTICAL ):
theGraphics.translate( -_myLen , 0 );
theGraphics.rect( 0 , 0 , _myLen , 1 );
if ( isLabel ) {
_myLabel.draw( theGraphics , -_myLabel.getWidth( ) , 0 , _myParent );
}
break;
}
theGraphics.popMatrix( );
}
public void setLength( int theLength ) {
_myLen = theLength;
}
public Label setLabel( String theLabeltext ) {
if ( _myLabel == null ) {
_myLabel = new Label( _myParent.cp5 , theLabeltext );
isLabel = true;
} else {
_myLabel.set( theLabeltext );
}
return _myLabel;
}
public Label getLabel( ) {
if ( _myLabel == null ) {
setLabel( "?" );
}
return _myLabel;
}
}

266
controlP5/Toggle.java Executable file
View File

@ -0,0 +1,266 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import processing.core.PGraphics;
import processing.core.PImage;
/**
* a toggle can have two states, true and false, where true has the value 1 and false is 0.
*
* @example controllers/ControlP5toggle
* @nosuperclasses Controller Controller
*/
public class Toggle extends Controller< Toggle > {
protected int cnt;
protected boolean isOn = false;
protected float internalValue = -1;
public static int autoWidth = 39;
public static int autoHeight = 19;
protected float[] autoSpacing = new float[] { 10 , 20 };
/**
* Convenience constructor to extend Toggle.
*
* @example use/ControlP5extendController
* @param theControlP5
* @param theName
*/
public Toggle( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
public Toggle( ControlP5 theControlP5 , Tab theParent , String theName , float theValue , float theX , float theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myValue = theValue;
_myCaptionLabel.align( LEFT , BOTTOM_OUTSIDE ).setPadding( 0 , Label.paddingY );
}
/**
*
* @param theApplet PApplet
*/
@ControlP5.Invisible public void draw( PGraphics theGraphics ) {
theGraphics.pushMatrix( );
theGraphics.translate( x( position ) , y( position ) );
_myControllerView.display( theGraphics , this );
theGraphics.popMatrix( );
}
protected void onEnter( ) {
isActive = true;
}
protected void onLeave( ) {
isActive = false;
}
/**
* {@inheritDoc}
*/
@ControlP5.Invisible public void mousePressed( ) {
setState( !isOn );
isActive = false;
}
/**
* {@inheritDoc}
*/
@Override public Toggle setValue( float theValue ) {
setState(theValue != 0);
return this;
}
/**
* @param theValue
*/
public Toggle setValue( boolean theValue ) {
setValue( (theValue) ? 1 : 0 );
return this;
}
public boolean getBooleanValue( ) {
return getState( );
}
/**
* {@inheritDoc}
*/
@Override public Toggle update( ) {
return setValue( _myValue );
}
/**
* sets the state of the toggle, this can be true or false.
*
* @param theFlag boolean
*/
public Toggle setState( boolean theFlag ) {
isOn = theFlag;
_myValue = (!isOn) ? 0 : 1;
broadcast( FLOAT );
return this;
}
public boolean getState( ) {
return isOn;
}
protected void deactivate( ) {
isOn = false;
_myValue = (!isOn) ? 0 : 1;
}
protected void activate( ) {
isOn = true;
_myValue = (!isOn) ? 0 : 1;
}
/**
* switch the state of a toggle.
*/
public Toggle toggle( ) {
setState(!isOn);
return this;
}
/**
* set the visual mode of a Toggle. use setMode(ControlP5.DEFAULT) or setMode(ControlP5.SWITCH)
*
* @param theMode
*/
public Toggle setMode( int theMode ) {
updateDisplayMode( theMode );
return this;
}
public int getMode( ) {
return _myDisplayMode;
}
/**
* by default a toggle returns 0 (for off) and 1 (for on). the internal value variable can be
* used to store an additional value for a toggle event.
*
* @param theInternalValue
*/
@ControlP5.Invisible public void setInternalValue( float theInternalValue ) {
internalValue = theInternalValue;
}
@ControlP5.Invisible public float internalValue( ) {
return internalValue;
}
/**
* {@inheritDoc}
*/
@Override public Toggle linebreak( ) {
cp5.linebreak( this , true , autoWidth , autoHeight , autoSpacing );
return this;
}
@Override public Toggle setImages( PImage ... theImages ) {
setImage( theImages[ 0 ] , DEFAULT );
setImage( theImages[ 1 ] , ACTIVE );
updateDisplayMode( IMAGE );
return this;
}
/**
* {@inheritDoc}
*/
@Override @ControlP5.Invisible public Toggle updateDisplayMode( int theState ) {
_myDisplayMode = theState;
switch ( theState ) {
case ( DEFAULT ):
_myControllerView = new ToggleView( );
break;
case ( IMAGE ):
_myControllerView = new ToggleImageView( );
break;
case ( SWITCH ):
_myControllerView = new ToggleSwitchView( );
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
class ToggleView implements ControllerView< Toggle > {
public void display( PGraphics theGraphics , Toggle theController ) {
if ( isActive ) {
theGraphics.fill( isOn ? color.getActive( ) : color.getForeground( ) );
} else {
theGraphics.fill( isOn ? color.getActive( ) : color.getBackground( ) );
}
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}
class ToggleImageView implements ControllerView< Toggle > {
public void display( PGraphics theGraphics , Toggle theController ) {
if ( isOn ) {
theGraphics.image( (availableImages[ACTIVE]) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 );
} else {
theGraphics.image( images[ DEFAULT ] , 0 , 0 );
}
}
}
class ToggleSwitchView implements ControllerView< Toggle > {
public void display( PGraphics theGraphics , Toggle theController ) {
theGraphics.fill( color.getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.fill( color.getActive( ) );
if ( isOn ) {
theGraphics.rect( 0 , 0 , getWidth( ) / 2 , getHeight( ) );
} else {
theGraphics.rect( ( getWidth( ) % 2 == 0 ? 0 : 1 ) + getWidth( ) / 2 , 0 , getWidth( ) / 2 , getHeight( ) );
}
if ( isLabelVisible ) {
_myCaptionLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}
}

390
controlP5/Tooltip.java Executable file
View File

@ -0,0 +1,390 @@
package main.java.src2.main.java.controlP5.controlP5;
/**
* controlP5 is a processing gui library.
*
* 2006-2015 by Andreas Schlegel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
* @author Andreas Schlegel (http://www.sojamo.de)
* @modified ##date##
* @version ##version##
*
*/
import java.util.HashMap;
import java.util.Map;
import processing.core.PApplet;
import processing.core.PGraphics;
/**
* A tooltip can be registered for individual controllers
* and is activated on rollover.
*
* @example controllers/ControlP5tooltip
*
*/
public class Tooltip {
private ControllerView< ? > _myView;
private final float[] position = new float[3];
private float[] currentPosition = new float[3];
private float[] previousPosition = new float[3];
private float[] offset = new float[3];
private Controller< ? > _myController;
private long startTime = 0;
private long _myDelayInMillis = 500;
private int _myMode = ControlP5.INACTIVE;
private int _myHeight = 20;
private int _myBackgroundColor = 0xffffffb4;
private int _myMaxAlpha = 255;
private final int _myAlpha = 0;
private final Map< Controller< ? > , String > map;
private Label _myLabel;
private boolean enabled = true;
private int _myBorder;
private final ControlP5 cp5;
private final int _myAlignH = ControlP5.RIGHT;
private int _myColor = 0x00000000;
Tooltip( ControlP5 theControlP5 ) {
cp5 = theControlP5;
position[0] = -1000;
position[1] = -1000;
currentPosition = new float[3];
previousPosition = new float[3];
offset = new float[] { 0 , 24 , 0 };
map = new HashMap< Controller< ? > , String >( );
_myLabel = new Label( cp5 , "tooltip" );
_myLabel.setColor( _myColor );
_myLabel.setPadding( 0 , 0 );
setView( new TooltipView( ) );
setBorder( 4 );
}
/**
* sets the border of the tooltip, the default border is
* 4px.
*
* @param theValue
* @return Tooltip
*/
public Tooltip setBorder( int theValue ) {
_myBorder = theValue;
_myLabel.getStyle( ).setMargin( _myBorder , _myBorder , _myBorder , _myBorder );
return this;
}
/**
* returns the value of the border
*
* @return
*/
public int getBorder( ) {
return _myBorder;
}
/**
* sets the transparency of the default background,
* default value is 200
*
* @param theValue
* @return Tooltip
*/
public Tooltip setAlpha( int theValue ) {
_myMaxAlpha = theValue;
return this;
}
private void updateText( String theText ) {
int n = 1;
for ( char c : theText.toCharArray( ) ) {
if ( c == '\n' ) {
n++;
}
}
if ( _myLabel.getHeight( ) != _myLabel.getLineHeight( ) * n ) {
_myLabel.setHeight( _myLabel.getLineHeight( ) * n );
}
_myLabel.set( theText );
}
/**
* TODO see below
* @param theWindow
*/
void draw( ControlWindow theWindow ) {
// TODO re-implement Tooltip
}
private boolean moved( ) {
return PApplet.abs( PApplet.dist( previousPosition[0] , previousPosition[1] , currentPosition[0] , currentPosition[1] ) ) > 1;
}
/**
* A tooltip is activated when entered by the mouse,
* after a given delay time the Tooltip starts to fade
* in. Use setDelay(long) to adjust the default delay
* time of 1000 millis.
*
* @param theMillis
* @return Tooltip
*/
public Tooltip setDelay( long theMillis ) {
_myDelayInMillis = theMillis;
return this;
}
/**
* a Tooltip is activated when the mouse enters a
* controller.
*
* @param theController
*/
protected void activate( Controller< ? > theController ) {
if ( map.containsKey( theController ) ) {
startTime = System.nanoTime( );
_myController = theController;
currentPosition[0] = theController.getControlWindow( ).mouseX;
currentPosition[1] = theController.getControlWindow( ).mouseY;
updateText( map.get( _myController ) );
_myMode = ControlP5.WAIT;
}
}
protected void deactivate( ) {
deactivate( 1 );
}
protected void deactivate( int theNum ) {
if ( theNum == 0 ) {
if ( _myMode >= ControlP5.IDLE ) {
if ( _myMode < ControlP5.FADEOUT )
startTime = System.nanoTime( );
_myMode = ControlP5.FADEOUT;
}
} else {
_myMode = ( _myMode >= ControlP5.IDLE ) ? ControlP5.FADEOUT : ControlP5.DONE;
}
}
/**
* A custom view can be set for a Tooltip. The default
* view class can be found at the bottom of the Tooltip
* source.
*
* @see ControllerView
* @param theDisplay
* @return Tooltip
*/
public Tooltip setView( ControllerView< ? > theDisplay ) {
_myView = theDisplay;
return this;
}
/**
* registers a controller with the Tooltip, when
* activating the tooltip for a particular controller,
* the registered text (second parameter) will be
* displayed.
*
* @param theController
* @param theText
* @return Tooltip
*/
public Tooltip register( Controller< ? > theController , String theText ) {
map.put( theController , theText );
theController.registerProperty( "setTooltipEnabled" , "isTooltipEnabled" );
return this;
}
public Tooltip register( String theControllerName , String theText ) {
Controller< ? > c = cp5.getController( theControllerName );
if ( c == null ) {
return this;
}
map.put( c , theText );
c.registerProperty( "setTooltipEnabled" , "isTooltipEnabled" );
return this;
}
/**
* removes a controller from the tooltip
*
* @param theController
* @return Tooltip
*/
public Tooltip unregister( Controller< ? > theController ) {
map.remove( theController );
theController.removeProperty( "setTooltipEnabled" , "isTooltipEnabled" );
return this;
}
public Tooltip unregister( String theControllerName ) {
Controller< ? > c = cp5.getController( theControllerName );
if ( c == null ) {
return this;
}
return unregister( c );
}
/**
* with the default display, the width of the tooltip is
* set automatically, therefore setWidth() does not have
* any effect without changing the default display to a
* custom ControllerView.
*
* @see ControllerView
* @see Tooltip#setDisplay(ControllerView)
* @return Tooltip
*/
public Tooltip setWidth( int theWidth ) {
// TODO
// _myWidth = theWidth;
return this;
}
public int getWidth( ) {
return _myLabel.getWidth( );
}
/**
* @see Tooltip#setWidth(int)
* @param theHeight
* @return Tooltip
*/
public Tooltip setHeight( int theHeight ) {
ControlP5.logger( ).warning( "Tooltip.setHeight is disabled with this version" );
_myHeight = theHeight;
return this;
}
/**
* adds an offset to the position of the controller
* relative to the mouse cursor's position. default
* offset is (10,20)
*
* @param theX
* @param theY
* @return Tooltip
*/
public Tooltip setPositionOffset( float theX , float theY ) {
offset[0] = theX;
offset[1] = theY;
return this;
}
/**
* disables the Tooltip on a global level, when
* disabled, tooltip will not respond to any registered
* controller. to disable a tooltip for aparticular
* controller, used unregister(Controller)
*
* @see Tooltip#unregister(Controller)
* @return Tooltip
*/
public Tooltip disable( ) {
enabled = false;
return this;
}
/**
* in case the tooltip is disabled, use enable() to turn
* the tooltip back on.
*
* @return Tooltip
*/
public Tooltip enable( ) {
enabled = true;
return this;
}
/**
* check if the tooltip is enabled or disabled
*
* @return boolean
*/
public boolean isEnabled( ) {
return enabled;
}
/**
* sets the Label to a custom label and replaces the
* default label.
*
* @param theLabel
* @return Tooltip
*/
public Tooltip setLabel( Label theLabel ) {
_myLabel = theLabel;
return this;
}
/**
* returns the current Label
*
* @return Label
*/
public Label getLabel( ) {
return _myLabel;
}
/**
* sets the background color of the tooltip, the default
* color is a dark grey
*
* @param theColor
* @return Tooltip
*/
public Tooltip setColorBackground( int theColor ) {
_myBackgroundColor = theColor;
return this;
}
/**
* sets the text color of the tooltip's label, the
* default color is a white
*
* @param theColor
* @return Tooltip
*/
public Tooltip setColorLabel( int theColor ) {
_myColor = theColor;
_myLabel.setColor( theColor );
return this;
}
class TooltipView implements ControllerView< Controller< ? >> {
public void display( PGraphics theGraphics , Controller< ? > theController ) {
_myHeight = _myLabel.getHeight( );
theGraphics.fill( _myBackgroundColor , _myAlpha );
theGraphics.rect( 0 , 0 , getWidth( ) + _myBorder * 2 , _myHeight + _myBorder * 2 );
theGraphics.pushMatrix( );
if ( _myAlignH == ControlP5.RIGHT ) {
theGraphics.translate( 6 , 0 );
} else {
theGraphics.translate( getWidth( ) - 6 , 0 );
}
theGraphics.triangle( 0 , 0 , 4 , -4 , 8 , 0 );
theGraphics.popMatrix( );
int a = ( int ) ( PApplet.map( _myAlpha , 0 , _myMaxAlpha , 0 , 255 ) );
_myLabel.setColor( a << 24 | ( _myColor >> 16 ) << 16 | ( _myColor >> 8 ) << 8 | ( _myColor >> 0 ) << 0 );
_myLabel.draw( theGraphics , 0 , 0 , theController );
}
}
}

867
controlP5/changeLog.txt Executable file
View File

@ -0,0 +1,867 @@
2016-14-04 Andreas Schlegel <andi at sojamo.de>
mostly bug fixes, see github issues
removed all PVector references, variables, and functions using processing.core.PVector
2015-08-02 Andreas Schlegel <andi at sojamo.de>
changes see github change log
2015-03-29 Andreas Schlegel <andi at sojamo.de>
* src controlP5.ScrollabelList:
fixing ArrayOutOfBounds error as reported on github under issue 3 https://github.com/sojamo/controlp5/issues/3
2014-09-08 Andreas Schlegel <andi at sojamo.de>
* src main.java.src2.main.java.controlP5.controlp5.Icon:
adding Icon class, acts like a button; can be used with images and font-icons
from "Font Awesome".
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Button:
when theButton acts as a switch (setSwitch(true)), the corresponding
method inside a sketch should use type boolean as argument instead of float;
a java.lang.IllegalArgumentException will be thrown in case of a float argument
2014-08-28 Andreas Schlegel <andi at sojamo.de>
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Background:
adding Background class, a convenience class for grouping controllers with
the top bar disabled by default.
2014-07-21 Andreas Schlegel <andi at sojamo.de>
* src main.java.src2.main.java.controlP5.controlp5.Textfield:
making use of a graphics buffer now, simplifies cursor position calculation and
prevents from throwing an ArrayIndexOutOfBoundsException which could occasionally
happen with previous versions.
2014-07-17 Andreas Schlegel <andi at sojamo.de>
* version 2.2.1
* removing PVector dependencies
* removing all deprecated methods
* src main.java.src2.main.java.controlP5.controlp5.ListBox, main.java.src2.main.java.controlP5.controlp5.controlp5.DropdownList:
Due to changes to and deprecation of DropdownList and ListBox, both share the same
source code as ScrollableList. Consequently some functionality got lost though this
should be marginal. In case of any issues occuring due to these changes, please
inform the author. In any case use ScrollableList instead of DropdownList and ListBox.
The major benefit of using a ScrollableList is that an item is now of type Map and
therefore is not limited (as it was the case before) to the implementation of a
ListBoxItem and hence is more flexible as data container.
Do note that ListBox, DropdownList and ScrollableList do extend Controller,
not ControllerGroup
2014-04-27 Andreas Schlegel <andi at sojamo.de>
* version 2.1.6
* preparing for next release.
* src main.java.src2.main.java.controlP5.controlp5.ListBox, main.java.src2.main.java.controlP5.controlp5.controlp5.DropdownList:
deprecated, use ScrollableList instead.
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControlP5Legacy:
repository of functions only kept for backwards compatibility but it is not encouraged
to use the anymore. Use ControlP5Base instead.
* src main.java.src2.main.java.controlP5.controlp5.Controller:
adding onEnter, onLeave, onDrag, onStartDrag, onEndDrag, onWheel, onMove, onClick,
onPress, onDoublePress, onRelease, onReleaseOutside, onChange to register callbacks
for specific events. This is not implemented for classes extending ControllerGroup.
2013-01-23 Andreas Schlegel <andi at sojamo.de>
* version 2.1.5
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControllerProperties:
removing XML format. adding JSON format, JSON format will be the default format instead of the Java Serialization format.
2012-09-22 Andreas Schlegel <andi at sojamo.de>
* version 2.1.3
* src main.java.src2.main.java.controlP5.controlp5.ListBox:
now extends Controller instead of ControlGroup.
2012-09-09 Andreas Schlegel <andi at sojamo.de>
* version 2.1.0
* starting processingjs implementation.
- many controllers will be included:
completed: Bang, Button, CheckBox, ColorPalette, Group, Knob, Label, ListBox, DropdownList, Numberbox, RadioButton,
Range, Slider, Slider2D, Tab, Textfield, Toggle
under construction: Canvas, Chart, ColorPicker, ControllerView, FrameRate, Matrix, Textarea
pending: ButtonBar, Pointer, TickMark, Tooltip
some will be missed: MutiList, Textlabel
and more will be missed: CColor, ControlBehavior, ControllerProperties, ControllerStyle, ControlTimer, ControlWindow
- the BitFont from the Java version will not be ported over to js and the default fontsize will be set to 10
- The automatic binding of functions and variables with the js version did not work as smooth as expected. Currently
only automatic function detection and binding is available. But then why not variables? See my request here:
https://processing-js.lighthouseapp.com/projects/41284/tickets/1972-feature-request-access-sketch-global-variables-from-library
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Slider2D:
changed size of cursor, changed color handling
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Button:
alignment of caption label changed to CENTER,CENTER
* adding PGraphics support instead of only rendering into PApplet directly
* fixing Annotation issue addressed here https://forum.processing.org/topic/controlp5-annotations-24-8-2012#25080000002597047
2012-12-23 Andreas Schlegel <andi at sojamo.de>
* version 2.0.4
* src main.java.src2.main.java.controlP5.controlp5.Textfield.java,main.java.src2.main.java.controlP5.controlp5.ListBox.java,
main.java.src2.main.java.controlP5.controlp5.controlp5.DropdownList.java,main.java.src2.main.java.controlP5.controlp5.ControlWindow.java
main.java.src2.main.java.controlP5.controlp5.ControlP5Base.java:
adjusting to processing's KeyEvent final variable name changes
see issue 69 https://code.google.com/p/controlp5/issues/detail?id=69 (thanks jeff)
* src main.java.src2.main.java.controlP5.controlp5.Textfield.java:
reimplemented password mode (thanks jeff)
2012-10-19 Andreas Schlegel <andi at sojamo.de>
* version 2.0.3
* src main.java.src2.main.java.controlP5.controlp5.Controller.java:
Automatic (PApplet) field recognition for Slider, Knob, Numberbox, Toggle adjusted.
2012-09-17 Andreas Schlegel <andi at sojamo.de>
* version 2.0.2
* major changes to controlP5's font handling. the BitFontRenderer has been removed and the BitFont class
has been introduced. BitFont extends PFont and is the replacement for rendering controlP5's bitfont as
a pfont. this makes font handling way more easier and stable. if this has caused any font rendering
flaws, let me know.
* src controlP5.BitFontRenderer.java:
removed
* src main.java.src2.main.java.controlP5.controlp5.BitFont.java:
added, see above.
2012-09-07 Andreas Schlegel <andi at sojamo.de>
* version 2.0.1
* processing 2.0, time to make some changes, major revision in progress.
The goal should be to make 2.0+ desktop and android compatible, for that java.awt dependencies
will be removed.
starting to remove deprecated methods, fields and classes
* removing all java.awt dependencies.
with each ControlP5 instance there will only be 1 ControlWindow since separate windows/frames have
been removed due to their java.awt dependency. There will be an example of how to make your own
separate Frame when in desktop mode.
* versions starting with 2.0.1 will not be backwards compatible with 1.5.1 and earlier
from this version onwards Android is supported
* src main.java.src2.main.java.controlP5.controlp5.Println.java:
new class added
a console logger that captures the System.out stream and displays it using a Textarea
* src main.java.src2.main.java.controlP5.controlp5.controlp5.FrameRate.java:
new class added
a Textlabel that displays the current or average framerate based on update interval
* src controlP5.BitFontRenderer.java:
using Base64 encoded bitfont source instead of loading gif textures
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Knob.java:
adding value label, ARC is default view now.
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Matrix.java:
adding play(), pause(), stop(), isPlaying(), trigger(int)
* src main.java.src2.main.java.controlP5.controlp5.Controller.java:
all ControllerSprite references (previously deprecated) have been removed
* src controlP5.ControllerSprite.java:
removed
* src controlP5.ControlP5IOHandler.java:
obsolete, removed, all static method transfered to main.java.src2.main.java.controlP5.controlp5.controlp5.CP.java which will handle static method
* src controlP5.ControlWindowKeyListener.java:
obsolete, removed
* src controlP5.PAppletWindow.java:
obsolete, removed, currently there is no support for separate frames other than the main window due to removing java.awt dependencies
* src main.java.src2.main.java.controlP5.controlp5.ControlWindow.java:
removed mouseWheelMoved(MouseWheelEvent e) due to removal of java.awt dependencies
how to use an extra window, see example extra/ControlP5frame
* src controlP5.ControlWindowKeyHandler.java:
obsolete, removed, now handled by controlP5/ControlWindow.java
* src controlP5.CRect.java:
obsolete, removed, was only used by MultiList and MultiListButton - replaced with int array.
* src controlP5.ControlCanvas.java:
obsolete, removed, use main.java.src2.main.java.controlP5.controlp5.Canvas.java instead.
2012-09-07 Andreas Schlegel <andi at sojamo.de>
* version 1.5.1
* This version will be the last version that is stable and fully compatible with processing 1.5.1
due to major changes in the processing 2.0 version, future releases of controlp5 will only be
compatible with the processing 2.0 and higher versions.
The next controlp5 release will continue with version 2.0.1
2012-08-25 Andreas Schlegel <andi at sojamo.de>
* version 0.7.6
* src main.java.src2.main.java.controlP5.controlp5.Textfield.java:
fixing special character issue with e.g. <20>,<2C>,<2C>,<2C>, etc.
backspace, left arrow, right arrow now respond when pressed longer
added isFocus()
implemented issue 56 http://code.google.com/p/controlp5/issues/detail?id=56 , thanks jeff
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControllerAutomator.java:
fixed annotation mapping for methods
added list support for methods
* src main.java.src2.main.java.controlP5.controlp5.CColor.java:
removing alpha masking
* src main.java.src2.main.java.controlP5.controlp5.controlp5.MultiList.java:
Conflict with moving a Multilist from one to another tab
removed field _myChildren. MultiListButtons are now store in the Controller's sublements filed.
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControllerInterface.java:
adding getArrayValue(int), setArrayValue(int, float), setArrayValue(float[]);
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControlP5.java:
adding setBroadcast(boolean) to disable/enable broadcasting of value changes.
2012-05-30 Andreas Schlegel <andi at sojamo.de>
* version 0.7.5
* src main.java.src2.main.java.controlP5.controlp5.Controller.java:
adding empty methods onPress(), onClick(), onRelease(), onReleaseOutside(),
onScroll(int),onMove(),onDrag() for input access when extending a controller.
* adding convenience constructor to Controllers, convenient when extending a Controller.
* adding example use/ControlP5extendController
2012-05-18 Andreas Schlegel <andi at sojamo.de>
* version 0.7.3
* src main.java.src2.main.java.controlP5.controlp5.ControlEvent.java:
adding getArrayValue(int), returns a float value for a given index, does not check for ArrayIndexOutOfBounds
* src main.java.src2.main.java.controlP5.controlp5.Slider.java:
issue 47 http://code.google.com/p/controlp5/issues/detail?id=47 fixed
* src main.java.src2.main.java.controlP5.controlp5.controlp5.CheckBox.java, main.java.src2.main.java.controlP5.controlp5.RadioButton.java:
issue 41 http://code.google.com/p/controlp5/issues/detail?id=41 fixed
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Chart.java:
implemented
* src main.java.src2.main.java.controlP5.controlp5.ControlFont.java:
issue 46 http://code.google.com/p/controlp5/issues/detail?id=46 fixed
* src main.java.src2.main.java.controlP5.controlp5.ControlWindow.java:
sketches using controlP5 running in the browser as Applet did not work anymore, fixed
* src main.java.src2.main.java.controlP5.controlp5.ColorPicker.java:
missing implementation reported in http://forum.processing.org/topic/controlp5-how-to-receive-colorpicker-controlevents fixed
ColorPicker example has been modified accordingly
* src main.java.src2.main.java.controlP5.controlp5.Textfield.java:
issue 44 http://code.google.com/p/controlp5/issues/detail?id=44 fixed
* src controlP5.ControlWindowKeyHandler.java:
issue 49 http://code.google.com/p/controlp5/issues/detail?id=49 fixed, keys boolean array size increased to 525 due to windows key issue
2012-01-15 Andreas Schlegel <andi at sojamo.de>
* version 0.7.0
* src main.java.src2.main.java.controlP5.controlp5.controlp5.ControllerInterface.java, main.java.src2.main.java.controlP5.controlp5.Controller.java,main.java.src2.main.java.controlP5.controlp5.ControllerGroup.java:
adding generic type declaration for object specific method chaining (fluent interface)
* src main.java.src2.main.java.controlP5.controlp5.RadioButton.java:
changed return type for methods addItem from Toggle to RadioButton
changed return type for methods setImage from PImage to RadioButton
2011-10-14 Andreas Schlegel <andi at sojamo.de>
* version 0.6.9
* src main.java.src2.main.java.controlP5.controlp5.controlp5.Textarea.java:
included isScrollable() to adapt to ListBox
2011-10-13 Andreas Schlegel <andi at sojamo.de>
* version 0.6.8
* src main.java.src2.main.java.controlP5.controlp5.ControllerGroup.java, main.java.src2.main.java.controlP5.controlp5.Controller.java:
making addition to isVisible() to check if the parent element is invisible
in which case the child element will return false as well although the visible
state might be true. this fixes an issue with mousewheel scroll being active
for an invisible child controller. The mouseoverlist handling was updated as well.
* src main.java.src2.main.java.controlP5.controlp5.Slider.java:
Slider will only broadcast when there is a change in value when pressed
* src main.java.src2.main.java.controlP5.controlp5.ControlWindow.java:
mouseWheelMoved() now only updates the first item in the mouseoverlist
and then exits the loop
2011-10-12 Andreas Schlegel <andi at sojamo.de>
* version 0.6.7
* examples reorganized and grouped into 3 categories,
controllers, use, extra
2011-10-07 Andreas Schlegel <andi at sojamo.de>
* version 0.6.6
* src controlP5/Textarea.java:
scrollbar pixel offset fixed, setPosition update fixed.
2011-09-22 Andreas Schlegel <andi at sojamo.de>
* version 0.6.5
* src controlP5/ControlWindow.java:
adding removeMouseOverFor() to remove controllers from the mouseoverlist.
Called when a controller or group is removed. Necessary when a controller/group is removed
when clicked or hovered by the mouse.
2011-09-20 Andreas Schlegel <andi at sojamo.de>
* version 0.6.4
* src controlP5/Textfield.java:
adding support for PFont
* javadoc, new design
2011-08-27 Andreas Schlegel <andi at sojamo.de>
* version 0.6.3
* src controlP5/ListBox.java, controlP5/DropdownList.java:
adding mouseover support.
* src controlP5/ControlP5.java:
adding enableMouseWheel(), disableMouseWheel(), isMouseWheel()
by default the mouse wheel is active for Slider, Knob, Numberbox,
ListBox and DropdownList. The MouseWheelListener is handled
by each ControlWindow individually.
* src controlP5/ControlWindow.java:
adding getFrame() to access the frame object of a ControlWindow.
2011-08-25 Andreas Schlegel <andi at sojamo.de>
* version 0.6.2
* src controlP5/ControlP5.java:
removing static from the papplet field, this had consequences for some internal
calls to papplet but do not affect any publicly available methods or constructors
except the Label class which requires a controlP5 instances as it's constructor's
first parameter.
* src controlP5/ControlP5.java:
field keyHandler is now non-static
* src controlP5/Label.java:
adding a ControlP5 parameter to all Label constructors due to changes made
to field controlP5.papplet
* src controlP5/Textlabel.java:
Constructors with the first parameter of type Component have been deprecated
and replaced with constructors using a reference to ControlP5 as first parameter.
if this affects your programs, please make changes accordingly.
2011-08-20 Andreas Schlegel <andi at sojamo.de>
* version 0.6.1
* ongoing internal code refactoring, adding getter and setter methods for
existing methods (which are deprecated accordingly)
* reference cleanup
* preparing for release
* src controlP5/ControllerSprite.java:
deprecated
* src controlP5/ControlCanvas.java:
deprecated, use ControlWindowCanvas instead
* Names of controllers now follows the OSC address pattern specs,
use controlP5.printControllerMap() to see the changed address space.
This has been added to controlP5 since controllers now can be directly
linked to custom objects and not only to the instance of the main program.
http://opensoundcontrol.org/spec-1_0-examples
(OSC Address Parts not included)
2011-06-25 Andreas Schlegel <andi at sojamo.de>
* version 0.6.0
* adding Annotation support, very much inspired by cp5magic by Karsten Schmidt (toxi)
see the ControlP5annotation example for further details
* src controlP5/ControllerAutomator.java:
for internal use only, handles the reflection for the annotation implementation
* src controlP5/FieldChangedListener.java:
for internal use only, listens for changes of variables linked to controllers
(needs to be anabled, disabled by default)
* src controlP5/ScrollList.java:
ScrollList removed, use ListBox.
* src controlP5/ControllerGroup.java:
moveTo(Tab) changed according to issue http://code.google.com/p/controlp5/issues/detail?id=15
* src controlP5/ListBox.java,controlP5/DropdownList.java:
adding mousewheel support.
* src controlP5/CallbackEvent.java, controlP5/CallbackListener.java:
adding new callback event and listener for controller actions such as enter, leave, pressed, released, releasedoutside.
how to use see the ControlP5callback example
* src controlP5/Radio.java:
removed, has been deprecated. Use RadioButton or CheckBox instead.
* src controlP5/ControlWindow.Pointer.java:
adding a pointer class which can be used as replacement for mouse activity. To make use of the Pointer,
disable the mouse first and then set coordinates and events such as released and pressed from your program to
control controllers. see example ControlP5pointer
2011-05-08 Andreas Schlegel <andi at sojamo.de>
* version 0.5.9
* src controlP5/ControllerInterface.java:
adding method float[] arrayValue()
* src controlP5/ListBox.java:
adding addItems(String[]), which allows to add a string array to a ListBox or a DropdownList
automatically resulting in a list of listBoxItems
* src controlP5/ControlEvent.java:
adding method isFrom(String) and isFrom(ControllerInterface) to identify the origin of a Control Event
2011-05-08 Andreas Schlegel <andi at sojamo.de>
* version 0.5.8
* src controlP5/ListBox.java:
Scrollbar (when visible) is now included inside the dimensions of a listbox (and its derivatives).
* src controlP5/Textfield.java:
Frame which surrounds a textfield is back again after being removed in version 0.5.7.
* src controlP5/ListBox.java, controlP5/DropdownList.java:
adding key support. up and down arrows can be used to scroll listbox or dropdownList,
up and down, use shift+up/down for faster scrolling, use alt+up/down to jump to the
top or bottom.
* shuffle
2011-02-14 Andreas Schlegel <andi at sojamo.de>
* version 0.5.7
* src controlP5/Controller.java, controlP5/ControllerGroup.java:
toString now prints out Type, name and value instead of all details including position, etc.
detailed information can now be accessed through method info().
* src controlP5/Controller.java, controlP5/ControllerGroup.java:
adding method info() print out details such as position, visibility, label, id, etc. of
a Controller or ControllerGroup.
* src controlP5/ListBox.java:
adding ControlListeners to ListBox, will also be inherited
by DropdownList.
* src controlP5/ControlWindowKeyHandler.java:
Key combination ALT-L and ALT-S have been removed.
ControlP5 setups cant be saved at this point anymore. But
ControllerProperties have been introduced instead to save
properties for single controllers - how to use ControllerProperties
see the examples and source code of controlP5/ControllerProperties.java
and controlP5/ControllerProperty.java
* src controlP5/Textfield.java:
Introducing a new text-cursor. Frame which surrounds a textfield has been removed.
* src controlP5/Slider.java, Slider2D.java,
controlP5/Knob.java, controlP5/Numberbox.java:
adding shuffle() command, when called, a random value will be set
for the controller.
* src controlP5/Knob.java:
Caption Label was missing, now back.
* controlP5/Slider2D.java:
absolute, relative positioning issue resolved.
see http://forum.processing.org/topic/three-problems-i-m-having-with-controlp5
* src controlP5/ControlP5IOHandler.java:
Loading and saving controllers in xml format has been removed due
to incompletness. Alternatively ControllerProperties are introduced
with this release, see below for more details.
* src controlP5/ControlWindow.java:
Adding setPositionOfTabs() to change the origin of the tab bar.
Use controlP5.window().setPositionOfTabs(PVector) or
controlP5.window().setPositionOfTabs(int,int)
* src controlP5/ControlP5Base.java:
Adding saveProperties(String) and loadProperties(String) to
save and load serialized controller properties inside a file.
The range of controllers implementing save/load properties is yet
limited to Slider, Knob, Numberbox, Toggle, Checkbox,
RadioButton, Textlabel, Matrix,Range, textarea, ListBox, Dropdown,
colorPicker. Properties are currently saved in the java serialization
format but xml and possibily json alternatives are being worked out.
* src controlP5/ControllerProperty.java:
Adding controller property. Controllers can register properties which
can be saved in a serialized format.
* src controlP5/Matrix.java:
Adding setMode(int), please refer to to the documentation which
constants to use - cells can be activated by row, column, many-per-row-and-colum
* src controlP5/CColor.java:
Fields changed from protected to private, use setter and getter
to change color values. CColor is serializable so that instances can
be saved as properties.
* src controlP5/Accordion.java:
Adding new class Accordion, an Accordion allows similar behavior
as a common UI accordion, here it combines ControlGroups where
one or no group can be active at a time.
* src controlP5/CVector3f.java:
Removed. Replaced with processing.core.PVector.
* src controlP5/ControlP5.java:
Removing setFilePath(), setUrlPath(), urlPath(), filePath()
* src controlP5/ControlP5XMLElement.java,
ControlP5/ControlP5XMLParseException:
removed.
* src controlP5/ControlP5.java:
Adding convenience method window() which returns the controlWindow
of the sketch, before one had to use window(PApplet)
2010-11-07 Andreas Schlegel <andi at sojamo.de>
* version 0.5.6
* src/controlP5/ListBox.java:
adding updateListBoxItems() to update color changes.
adding scoll() calls to color related methods to update color
changes for currently active listBox buttons.
* src/controlP5/ListBox.java:
adding item(Controller) to access a ListBoxItem by it's Button reference.
* src/controlP5/ControlWindow.java:
use isMouseOver(Controller), getMouseOverList() to check
if the mouse is inside a specific controller. This does not work for
groups, only for controllers.
2010-10-07 Andreas Schlegel <andi at sojamo.de>
* version 0.5.5
* src/controlP5/ControlP5.java:
enableShortcuts() and disableShortcuts() were interchanged, fixed now.
2010-09-30 Andreas Schlegel <andi at sojamo.de>
* version 0.5.4
* src/controlP5/RadioButton.java:
adding setNoneSelectedAllowed(true/false) default is true.
http://forum.processing.org/topic/controlp5-radiobutton-strange-behaviour
* src/controlP5/DropdownList.java:
renaming PulldownMenu to DropdownList.
* src/controlP5/Range.java
setMin() and setMax() bug fixed.
* src/controlP5/ControlBroadcaster.java:
adding addListner(), removeListener(), getListener()
any object that implements ControlListener can register with the ControlBroadcaster to
receive ControlEvents broadcasted.
* src/controlP5/BitFontRenderer.java:
fixed ArrayIndexOutOfBoundsException
only characters between ASCII 32 and 127 are supported.
* src/controlP5/ControlP5.java:
disabled clear() call (called from within dispose()) when in applet mode.
Reason: all controllers will be cleared due to dispose call
when switching tabs. Fix required.
* src/controlP5/Button.java:
colorForeground and colorActive are reveresed due to adding an active state to buttons
when clicked. Rollovers no display colorForeground, clicked buttons will display
colorActive. This also affects ListBoxItems.
2010-08-18 Andreas Schlegel <andi at sojamo.de>
* version 0.5.3
* src/controlP5/ListBox.java:
adding clear(). clears a ListBox in order to re-filling list.
* src/controlP5/ListBox.java:
changing behavior of a ListBox-Button.
a ListBox-button is clicked, it will call the Button's onLeave()
and setIsInside(false) function to solve problem addressed here:
http://forum.processing.org/topic/controlp5-listbox-loses-mouseclicks
* src/controlP5/ListBox.java:
adding actAsPulldownMenu() to enable/disable pulldown
functionality for a ListBox.
* src/controlP5/PulldownMenu.java:
new Controller, extends ListBox, acts as a pulldown-menu.
2010-08-03 Andreas Schlegel
* version 0.5.2
* Slider2D: a new Controller, 2D slider control.
* Button, Bang, Toggle, : setImage() defines an image for DEFAULT,OVER,ACTIVE,HIGHLIGHT mode.
* Button, Bang, Toggle, : setImages() defines an image for DEFAULT,OVER,ACTIVE,HIGHLIGHT mode.
* Button: adding setSwitch() in order to use a button as a switch (makes toggle obsolete)
* Button: adding booleanValue() returns true or false, useful in case a button is set to be a switch.
* Button: adding setOn() setOff(), useful when button is a switch.
* Toggle: changing default look to ControlP5.SWITCH, an on/off look for toggles. use toggle.setMode(ControlP5.DEFAULT) to reset to the old default look.
* ControllerDisplay: adding interface ControllerDisplay to enable custom displays for a controller.
* Controller: setImage, allows to replace the default look of a controller with an image (PImage).
* Controller: setDisplay allows custom displays for controller. the custom display is called from within a controller's draw function. A custom Display implements interface ControllerDisplay
* Controller: adding lock(), unlock(), isLock(), setMoveable(), isMoveable(), isUserInteraction(), setUserInteraction()
* Controller: adding plugTo(), unplugFrom() (if this causes any problems or error message, please report)
* ControlP5: adding java.util.logging.Logger for logging error, debug, info messages - wrapped in ControlP5.error(), ControlP5.warning(), ControlP5.info(), ControlP5.debug()
* ControlP5: added registerDispose()
* ControlP5: adding setMoveable() and isMoveable() to disable/enable controllers to be moved around.
* ControlP5: adding disableShortcuts(), enableShortcuts() instead of disableKeys() and enableKeys()
* ControlP5: deprecating lock(), unlock(), disableKeys(), enableKeys()
* ControlWindow: adding begin() and end(). this allows to move controllers automatically to the main window or a separate controlWindow.
* Toggle: adding setValue(boolean)
* Matrix: mouseReleasedOutside error fixed.
* ControlWindow: window is now properly removed when closed, thanks henri.
* TextLabel: adding setControlFont()
* Knob: all new.
2010-04-04 Andreas Schlegel
* version 0.5.1
* ControlP5: lock() and unlock() are working again.
* ControlEvent: added function id() to make access to the id of controller, group, tab, etc. easier
* ControlEvent: added function type() for easier distinguishing between the type of Controller the event was triggered from, returns ControlEvent.UNDEFINED, ControlEvent.CONTROLLER, ControlEvent.TAB, ControlEvent.GROUP
* ListBoxItem: adding ListBoxItem to make changes to each item of a listBox especially the color settings of a listBoxItem.
* CColor: now with getter and setter functions, supports changing the value of the alpha channel.
* ControlWindow: adding begin() and end(). this allows to move controllers automatically to the main window or a separate controlWindow.
* ControllerGroup: adding enableCollapse(), disableCollapse(), isCollapse() to enable/disable the collapsing and opening of a controllerGroup e.g. listBox.
2010-03-26 Andreas Schlegel
* version 0.5.0
* making transition to 1.5+, no more java 1.4 support.
* compiling against processing 1.1
* ControlP5: added disableKeys() and enableKeys(), suggested in the discourse. disables and enables keyEvents such as hide/show with ALT-h.
* Toggle: when inactive, the color refers to colorBackground instead of colorForeground now.
* ControlFont: smooth related functions have been disabled and deprecated due to processing 1.1 changes.
* Slider: use alignValueLabel() to position the value label of a slider on TOP, CENTER, or BOTTOM
* example ControlP5quick: new, ControlP5quick shows how to quickly add Controllers with auto-arrangement.
2010-02-16 Andreas Schlegel
* version 0.4.7
* Slider: adding TickMarks and replacing steps with snapToTickMarks().
* ControlWindow: adding setUndecorated(), isUndecorated(), toggleUndecorated()
* ControllerSprite: sprites are now clone-able and state management has been improved, thanks to c.a. church. http://processing.org/discourse/yabb2/YaBB.pl?num=1265905257
* Controller: adding getSprite()
* BitFontRenderer: adding warning for character that are not supported by the BitFontRenderer.
2010-02-06 Andreas Schlegel
* version 0.4.6
* ControlWindow: imageMode was not set back to CENTER/CORNER correctly, now fixed.
0.4.5
* ControllerGroup: adding moveTo(String). will move ControllerGroups such as e.g. Textarea to another tab.
0.4.4
* ControlWindow: imageMode CENTER/CORNER issue fixed.
0.4.3
* Controller.isInside is private now. use setIsInside(true/false) and getIsInside() to access this boolean field.
* trying to solve the problem of overlapping described here:
http://processing.org/discourse/yabb2/YaBB.pl?num=1259885420/0#0
yet not successful, but loops managing the mouseEvents have been reversed from i++ to i--
* CheckBox,RadioButton: adding activateAll, activate, deactivate, getState to CheckBox and RadioButton to be able to control individual items by code.
* CheckBox: adding toggle() to CheckBox to be able to toggle individual items of a checkBox.
* CheckBox,RadioButton: adding setItemHeight(), setItemWidth() to radioButton and checkBox
* Toggle: adding toggle()
0.4.2
-
0.4.1
* Controller: added changeValue() to change the float value of a controller without broadcasting its change as a event.
* Numberbox: added setMultiplier() and multiplier() to customize the value sensitivity.
* Toggle: setLabelVisible() is now working.
* ControlWindow: adding setTitle, showCoordinates, hideCoordinates to ControlWindow. only applies to controlWindows of type PAppletWindow (external window).
* adding Matrix.set
* Controller: Controller.isInside() is public now
* added ControlFont. does not support textarea and textfield yet.
(note: take a look at subversion changelog generator http://ch.tudelft.nl/~arthur/svn2cl/)
0.3.15
* Texfield: textfield scrolls to the left if text is larger than display area.
* Knob: knob setValue issue solved.
* BitFontRenderer: removed getWidth(String theText, int theFontIndex)
is now getWidth(String theText, Label theLabel);
removed getWidth(String theText, int theFontIndex, int theLength))
is now getWidth(String theText, Label theLabel, int theLength));
0.3.14
* ScrollList: adding void hideScrollbar()
adding void showScrollbar()
adding void showScrollbar()
adding void scroll(float)
adding boolean isScrollbarVisible()
* Textarea: adding void hideScrollbar()
adding void showScrollbar()
adding void showScrollbar()
adding void scroll(float)
adding boolean isScrollbarVisible()
* Textfield: textinput now works from a controlWindow
* Label: adding adjust() to fix the cutting off of Labels when changing fonts.
use e.g. mySlider.captionLabel().setFont(ControlP5.grixel).adjust();
0.3.13
* Textfield: adding setAutoClear(true/false) prevents the textfield to be cleared after pressing RETURN.
adding clear(), clears the current textline
adding keepFocus(true/false)
adding getTextList()
adding setAutoClear(true/false)
adding isAutoClear()
adding submit()
0.3.12
* Radio: if deactiveAll is set before the first button is added, the first button will not trigger an event.
* ControlGroup: added method getBackgroundHeight() to get the height of a group's background that has been set before.
* Textfield: fixed bug with clearing the variable myTextline too early.
0.3.11
* Textfield: added method setText to Textfield
* Range: made corrections to Range, _myUnit was not set properly. now fixed. Range remains experimental.
0.3.10
* fixed little issues with setColor, again.
* removed decimal point when setDecimalPrecision(0)
0.3.9
* Range: defaultValue for min shows correct value now.
* Radio: added deactivateAll()
* TextLabel: added setWidth, setHeight
* setColor -Label(), -Active(), -Value(), -Foreground(), -Background(): issues resolved and tested for slider, range, button, knob, sliderlist, multilist, toggle, radio
* Controller: added method setDecimalPrecision(int theNum) to set the decimal precision for floats when displayed as valueLabel. the precision does not apply to the returned float value.
Controller.captionLabel().set("txt") is fixed.
* ControlP5: controlP5.setAutoDraw(true/false) issue is fixed.
* ControlWindow: controlWindow.post() has been deleted.
* Knob: issue with minimum value has been resolved.
how to move a textlabel that has been created with "new" to a tab other than the default:
Tab myTab = controlP5.addTab("new");
Textlabel myTextlabel = new Textlabel(this,"a single textlabel.",20,100,400,200,0xffff0000,ControlP5.synt24);
myTab.addDrawable(myTextlabel);

View File

@ -0,0 +1,6 @@
package main.java.src2.main.java.controlP5.controlP5.events;
public interface ReleasedOutsideListener {
void mouseReleasedOutside( ) ;
}

View File

@ -0,0 +1,132 @@
package main.java.src2.main.java.controlP5.controlP5.layout;
import controlP5.*;
import main.java.src2.main.java.controlP5.controlP5.layout.lang.XMLParser;
import processing.core.PApplet;
import java.lang.reflect.Constructor;
import java.util.*;
public class ControllerFactory {
private final PApplet applet;
private final ControlP5 cp5;
private final Map<String, Class<? extends Controller>> controlMap;
public ControllerFactory(PApplet applet, ControlP5 cp5) {
this.applet = applet;
this.cp5 = cp5;
controlMap = new HashMap<>();
// controlMap.put("Accordion", Accordion.class);
// controlMap.put("Background", Background.class);
// controlMap.put("Canvas", Canvas.class);
// controlMap.put("ChartData", ChartData.class);
// controlMap.put("ChartDataSet", ChartDataSet.class);
// controlMap.put("CheckBox", CheckBox.class);
// controlMap.put("ColorPicker", ColorPicker.class);
// controlMap.put("Group", Group.class);
// controlMap.put("Label", Label.class);
// controlMap.put("RadioButton", RadioButton.class);
// controlMap.put("Textarea", Textarea.class);
// controlMap.put("TickMark", TickMark.class);
// controlMap.put("Tooltip", Tooltip.class);
controlMap.put("Bang", Bang.class);
controlMap.put("Button", Button.class);
controlMap.put("ButtonBar", ButtonBar.class);
controlMap.put("Chart", Chart.class);
controlMap.put("ColorWheel", ColorWheel.class);
controlMap.put("Icon", Icon.class);
controlMap.put("Knob", Knob.class);
controlMap.put("ListBox", ListBox.class);
controlMap.put("Matrix", Matrix.class);
controlMap.put("MultiList", MultiList.class);
controlMap.put("MultilineTextfield", MultilineTextfield.class);
controlMap.put("Numberbox", Numberbox.class);
controlMap.put("Range", Range.class);
controlMap.put("ScrollableList", ScrollableList.class);
controlMap.put("Slider", Slider.class);
controlMap.put("Slider2D", Slider2D.class);
controlMap.put("Spacer", Spacer.class);
controlMap.put("Textfield", Textfield.class);
controlMap.put("Textlabel", Textlabel.class);
controlMap.put("Toggle", Toggle.class);
}
/* creates a controller based on the controlName */
public Controller<?> createController(String controlName) {
Class<? extends Controller> controllerClass = controlMap.get(controlName);
if (controllerClass == null) {
throw new IllegalArgumentException("Invalid control name: " + controlName);
}
try {
//instantiate the controller
Constructor<? extends Controller> constructor = controllerClass.getConstructor(ControlP5.class,String.class);
return constructor.newInstance(cp5,"");
} catch (Exception e) {
throw new RuntimeException("Failed to create control: " + controlName, e);
}
}
public Group createGroup(String groupName) {
return new Group(cp5, groupName);
};
public void configure(Controller<?> controller, String attrName, XMLParser.ValueContext attrValueContext) {
// eg. turn things like '23px' or '35%' into pixels value
int attrValue = getValue(attrValueContext);
switch (attrName) {
case "x":
controller.setPosition(attrValue, controller.getPosition()[1]);
break;
case "y":
controller.setPosition(controller.getPosition()[0], attrValue);
break;
case "width":
controller.setWidth(attrValue);
break;
case "height":
controller.setHeight(attrValue);
break;
case "color":
// Assuming color value is given as a hex string
break;
// case "label":
// controller.setLabel(attrValue);
// break;
// case "visible":
// controller.setVisible(Boolean.parseBoolean(attrValue));
// break;
// case "captionLabel":
// controller.getCaptionLabel().setText(attrValue);
// break;
// case "valueLabel":
// controller.getValueLabel().setText(attrValue);
// break;
default:
System.out.println("Unknown attribute: " + attrName);
}
}
private int getValue(XMLParser.ValueContext ctx) {
String unit = ctx.UNIT().getText();
String value = ctx.NUMBER().getText();
switch (unit) {
case "px":
return Integer.parseInt(value);
case "%":
//get tabs
ControllerList _myTabs = cp5.getWindow().getTabs();
return (int) (Float.parseFloat(value) / 100.0f * _myTabs.get(0).getWidth());
default:
throw new IllegalArgumentException("Unknown unit: " + unit);
}
}
}

View File

@ -0,0 +1,165 @@
package main.java.src2.main.java.controlP5.controlP5.layout;
import main.java.src2.main.java.controlP5.controlP5.ControlP5;
import main.java.src2.main.java.controlP5.controlP5.layout.lang.XMLBaseVisitor;
import main.java.src2.main.java.controlP5.controlP5.layout.lang.XMLLexer;
import main.java.src2.main.java.controlP5.controlP5.layout.lang.XMLParser;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import processing.core.PApplet;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
public class LayoutBuilder {
private final ControlP5 _cp5;
private final PApplet _pApplet;
private final Deque<ElementProps> contextStack = new ArrayDeque<>();
public LayoutBuilder(PApplet pApplet, ControlP5 cp5) {
_cp5 = cp5;
_pApplet = pApplet;
}
public void parseXML(String xml) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(xml);
XMLLexer lexer = new XMLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
XMLParser parser = new XMLParser(tokens);
ParseTree tree = parser.document();
//create walker
ParseTreeWalker walker = new ParseTreeWalker();
XMLVisitor visitor = new XMLVisitor(_pApplet, _cp5);
visitor.visit(tree);
}
private class XMLVisitor extends XMLBaseVisitor {
private final ControlP5 _cp5;
private final PApplet _pApplet;
public XMLVisitor(PApplet pApplet, ControlP5 cp5) {
_cp5 = cp5;
_pApplet = pApplet;
}
//visit first node
@Override
public Object visitDocument(XMLParser.DocumentContext ctx) {
// get width and height from the papplet
int parentWidth = _pApplet.width;
int parentHeight = _pApplet.height;
//visit children
for (int i = 0; i < ctx.children.size(); i++) {
contextStack.push(new ElementProps(parentWidth, parentHeight));
visit(ctx.children.get(i));
contextStack.pop();
}
return null;
}
@Override
public Object visitElement(XMLParser.ElementContext ctx) {
//parent props
ElementProps parentProps = contextStack.peek();
Tag tag = (Tag) visitStartTag(ctx.startTag());
System.out.println("im a " + tag.getName() + " and my parent has " + parentProps.width + " " + parentProps.height);
//visit children
for (int i = 0; i < ctx.children.size(); i++) {
contextStack.push(new ElementProps(parentProps.width/2, parentProps.height/2));
visit(ctx.children.get(i));
contextStack.pop();
}
return null;
}
@Override
public Object visitStartTag(XMLParser.StartTagContext ctx) {
HashMap<String,Attribute<?>> attributes = new HashMap<>();
for (int i = 0; i < ctx.attribute().size() ; i++) {
Attribute<?> attribute = (Attribute<?>) visitAttribute(ctx.attribute(i));
attributes.put(attribute.getName(), attribute);
}
Tag tag = new Tag(ctx.Name().getText(), attributes);
return tag;
}
@Override
public Object visitAttribute(XMLParser.AttributeContext ctx) {
if(ctx.value().STRING() != null){
String name = ctx.Name().getText();
String value = ctx.value().STRING().getText();
return new Attribute<String>(name, value);
}else if(ctx.value().NUMBER() != null) {
String name = ctx.Name().getText();
int value = Integer.parseInt(ctx.value().NUMBER().getText());
return new Attribute<Integer>(name, value);
}
return null;
}
}
private class ElementProps {
int width;
int height;
public ElementProps(int width, int height) {
this.width = width;
this.height = height;
}
}
private class Tag {
private String name;
private HashMap<String,Attribute<?>> attributes;
public Tag(String name, HashMap<String,Attribute<?>> attributes) {
this.name = name;
this.attributes = attributes;
}
public String getName() {
return name;
}
public HashMap<String,Attribute<?>> getAttributes() {
return attributes;
}
}
private class Attribute<T> {
private String name;
private T value;
public Attribute(String name, T value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public T getValue() {
return value;
}
}
}

35
controlP5/layout/XML.g4 Normal file
View File

@ -0,0 +1,35 @@
grammar XML;
document : '<Window>' element+ '</Window>' ;
element : startTag (content )? endTag
| SELF_CLOSING
;
startTag : OPEN Name attribute* CLOSE ;
endTag : OPEN_SLASH Name CLOSE ;
SELF_CLOSING : OPEN Name SLASH_CLOSE ;
attribute : Name EQUALS value ;
content : element | STRING ;
value: STRING
| NUMBER UNIT;
UNIT: 'px' | '%';
WS : [ \t\r\n]+ -> skip;
OPEN : '<' ;
OPEN_SLASH: '</' ;
CLOSE : '>' ;
SLASH_CLOSE: '/>' ;
EQUALS : '=' ;
Name : ALPHA (ALPHA | DIGIT | '.' | '-' | '_')* ;
STRING : '"' ( ~'"' )* '"' | '\'' ( ~'\'' )* '\'' ;
NUMBER : DIGIT+ ;
fragment DIGIT : [0-9] ;
fragment ALPHA : [a-zA-Z] ;

View File

@ -0,0 +1,44 @@
token literal names:
null
'<Window>'
'</Window>'
null
null
null
'<'
'</'
'>'
'/>'
'='
null
null
null
token symbolic names:
null
null
null
SELF_CLOSING
UNIT
WS
OPEN
OPEN_SLASH
CLOSE
SLASH_CLOSE
EQUALS
Name
STRING
NUMBER
rule names:
document
element
startTag
endTag
attribute
content
value
atn:
[4, 1, 13, 59, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 1, 0, 1, 0, 4, 0, 17, 8, 0, 11, 0, 12, 0, 18, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 25, 8, 1, 1, 1, 1, 1, 1, 1, 3, 1, 30, 8, 1, 1, 2, 1, 2, 1, 2, 5, 2, 35, 8, 2, 10, 2, 12, 2, 38, 9, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 3, 5, 52, 8, 5, 1, 6, 1, 6, 1, 6, 3, 6, 57, 8, 6, 1, 6, 0, 0, 7, 0, 2, 4, 6, 8, 10, 12, 0, 0, 57, 0, 14, 1, 0, 0, 0, 2, 29, 1, 0, 0, 0, 4, 31, 1, 0, 0, 0, 6, 41, 1, 0, 0, 0, 8, 45, 1, 0, 0, 0, 10, 51, 1, 0, 0, 0, 12, 56, 1, 0, 0, 0, 14, 16, 5, 1, 0, 0, 15, 17, 3, 2, 1, 0, 16, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 20, 1, 0, 0, 0, 20, 21, 5, 2, 0, 0, 21, 1, 1, 0, 0, 0, 22, 24, 3, 4, 2, 0, 23, 25, 3, 10, 5, 0, 24, 23, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 27, 3, 6, 3, 0, 27, 30, 1, 0, 0, 0, 28, 30, 5, 3, 0, 0, 29, 22, 1, 0, 0, 0, 29, 28, 1, 0, 0, 0, 30, 3, 1, 0, 0, 0, 31, 32, 5, 6, 0, 0, 32, 36, 5, 11, 0, 0, 33, 35, 3, 8, 4, 0, 34, 33, 1, 0, 0, 0, 35, 38, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 39, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 39, 40, 5, 8, 0, 0, 40, 5, 1, 0, 0, 0, 41, 42, 5, 7, 0, 0, 42, 43, 5, 11, 0, 0, 43, 44, 5, 8, 0, 0, 44, 7, 1, 0, 0, 0, 45, 46, 5, 11, 0, 0, 46, 47, 5, 10, 0, 0, 47, 48, 3, 12, 6, 0, 48, 9, 1, 0, 0, 0, 49, 52, 3, 2, 1, 0, 50, 52, 5, 12, 0, 0, 51, 49, 1, 0, 0, 0, 51, 50, 1, 0, 0, 0, 52, 11, 1, 0, 0, 0, 53, 57, 5, 12, 0, 0, 54, 55, 5, 13, 0, 0, 55, 57, 5, 4, 0, 0, 56, 53, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 13, 1, 0, 0, 0, 6, 18, 24, 29, 36, 51, 56]

View File

@ -0,0 +1,20 @@
T__0=1
T__1=2
SELF_CLOSING=3
UNIT=4
WS=5
OPEN=6
OPEN_SLASH=7
CLOSE=8
SLASH_CLOSE=9
EQUALS=10
Name=11
STRING=12
NUMBER=13
'<Window>'=1
'</Window>'=2
'<'=6
'</'=7
'>'=8
'/>'=9
'='=10

View File

@ -0,0 +1,124 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link XMLListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
@SuppressWarnings("CheckReturnValue")
public class XMLBaseListener implements XMLListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDocument(XMLParser.DocumentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDocument(XMLParser.DocumentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterElement(XMLParser.ElementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitElement(XMLParser.ElementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStartTag(XMLParser.StartTagContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStartTag(XMLParser.StartTagContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEndTag(XMLParser.EndTagContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEndTag(XMLParser.EndTagContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAttribute(XMLParser.AttributeContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAttribute(XMLParser.AttributeContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterContent(XMLParser.ContentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitContent(XMLParser.ContentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterValue(XMLParser.ValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitValue(XMLParser.ValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -0,0 +1,64 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link XMLVisitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
@SuppressWarnings("CheckReturnValue")
public class XMLBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements XMLVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDocument(XMLParser.DocumentContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitElement(XMLParser.ElementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStartTag(XMLParser.StartTagContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitEndTag(XMLParser.EndTagContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAttribute(XMLParser.AttributeContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitContent(XMLParser.ContentContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitValue(XMLParser.ValueContext ctx) { return visitChildren(ctx); }
}

View File

@ -0,0 +1,58 @@
token literal names:
null
'<Window>'
'</Window>'
null
null
null
'<'
'</'
'>'
'/>'
'='
null
null
null
token symbolic names:
null
null
null
SELF_CLOSING
UNIT
WS
OPEN
OPEN_SLASH
CLOSE
SLASH_CLOSE
EQUALS
Name
STRING
NUMBER
rule names:
T__0
T__1
SELF_CLOSING
UNIT
WS
OPEN
OPEN_SLASH
CLOSE
SLASH_CLOSE
EQUALS
Name
STRING
NUMBER
DIGIT
ALPHA
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[4, 0, 13, 114, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 3, 3, 58, 8, 3, 1, 4, 4, 4, 61, 8, 4, 11, 4, 12, 4, 62, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 5, 10, 83, 8, 10, 10, 10, 12, 10, 86, 9, 10, 1, 11, 1, 11, 5, 11, 90, 8, 11, 10, 11, 12, 11, 93, 9, 11, 1, 11, 1, 11, 1, 11, 5, 11, 98, 8, 11, 10, 11, 12, 11, 101, 9, 11, 1, 11, 3, 11, 104, 8, 11, 1, 12, 4, 12, 107, 8, 12, 11, 12, 12, 12, 108, 1, 13, 1, 13, 1, 14, 1, 14, 0, 0, 15, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 0, 29, 0, 1, 0, 6, 3, 0, 9, 10, 13, 13, 32, 32, 2, 0, 45, 46, 95, 95, 1, 0, 34, 34, 1, 0, 39, 39, 1, 0, 48, 57, 2, 0, 65, 90, 97, 122, 120, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 1, 31, 1, 0, 0, 0, 3, 40, 1, 0, 0, 0, 5, 50, 1, 0, 0, 0, 7, 57, 1, 0, 0, 0, 9, 60, 1, 0, 0, 0, 11, 66, 1, 0, 0, 0, 13, 68, 1, 0, 0, 0, 15, 71, 1, 0, 0, 0, 17, 73, 1, 0, 0, 0, 19, 76, 1, 0, 0, 0, 21, 78, 1, 0, 0, 0, 23, 103, 1, 0, 0, 0, 25, 106, 1, 0, 0, 0, 27, 110, 1, 0, 0, 0, 29, 112, 1, 0, 0, 0, 31, 32, 5, 60, 0, 0, 32, 33, 5, 87, 0, 0, 33, 34, 5, 105, 0, 0, 34, 35, 5, 110, 0, 0, 35, 36, 5, 100, 0, 0, 36, 37, 5, 111, 0, 0, 37, 38, 5, 119, 0, 0, 38, 39, 5, 62, 0, 0, 39, 2, 1, 0, 0, 0, 40, 41, 5, 60, 0, 0, 41, 42, 5, 47, 0, 0, 42, 43, 5, 87, 0, 0, 43, 44, 5, 105, 0, 0, 44, 45, 5, 110, 0, 0, 45, 46, 5, 100, 0, 0, 46, 47, 5, 111, 0, 0, 47, 48, 5, 119, 0, 0, 48, 49, 5, 62, 0, 0, 49, 4, 1, 0, 0, 0, 50, 51, 3, 11, 5, 0, 51, 52, 3, 21, 10, 0, 52, 53, 3, 17, 8, 0, 53, 6, 1, 0, 0, 0, 54, 55, 5, 112, 0, 0, 55, 58, 5, 120, 0, 0, 56, 58, 5, 37, 0, 0, 57, 54, 1, 0, 0, 0, 57, 56, 1, 0, 0, 0, 58, 8, 1, 0, 0, 0, 59, 61, 7, 0, 0, 0, 60, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 64, 1, 0, 0, 0, 64, 65, 6, 4, 0, 0, 65, 10, 1, 0, 0, 0, 66, 67, 5, 60, 0, 0, 67, 12, 1, 0, 0, 0, 68, 69, 5, 60, 0, 0, 69, 70, 5, 47, 0, 0, 70, 14, 1, 0, 0, 0, 71, 72, 5, 62, 0, 0, 72, 16, 1, 0, 0, 0, 73, 74, 5, 47, 0, 0, 74, 75, 5, 62, 0, 0, 75, 18, 1, 0, 0, 0, 76, 77, 5, 61, 0, 0, 77, 20, 1, 0, 0, 0, 78, 84, 3, 29, 14, 0, 79, 83, 3, 29, 14, 0, 80, 83, 3, 27, 13, 0, 81, 83, 7, 1, 0, 0, 82, 79, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 81, 1, 0, 0, 0, 83, 86, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 22, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 87, 91, 5, 34, 0, 0, 88, 90, 8, 2, 0, 0, 89, 88, 1, 0, 0, 0, 90, 93, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 94, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 94, 104, 5, 34, 0, 0, 95, 99, 5, 39, 0, 0, 96, 98, 8, 3, 0, 0, 97, 96, 1, 0, 0, 0, 98, 101, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 102, 1, 0, 0, 0, 101, 99, 1, 0, 0, 0, 102, 104, 5, 39, 0, 0, 103, 87, 1, 0, 0, 0, 103, 95, 1, 0, 0, 0, 104, 24, 1, 0, 0, 0, 105, 107, 3, 27, 13, 0, 106, 105, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 108, 109, 1, 0, 0, 0, 109, 26, 1, 0, 0, 0, 110, 111, 7, 4, 0, 0, 111, 28, 1, 0, 0, 0, 112, 113, 7, 5, 0, 0, 113, 30, 1, 0, 0, 0, 9, 0, 57, 62, 82, 84, 91, 99, 103, 108, 1, 6, 0, 0]

View File

@ -0,0 +1,185 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class XMLLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.13.0", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, SELF_CLOSING=3, UNIT=4, WS=5, OPEN=6, OPEN_SLASH=7, CLOSE=8,
SLASH_CLOSE=9, EQUALS=10, Name=11, STRING=12, NUMBER=13;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static String[] modeNames = {
"DEFAULT_MODE"
};
private static String[] makeRuleNames() {
return new String[] {
"T__0", "T__1", "SELF_CLOSING", "UNIT", "WS", "OPEN", "OPEN_SLASH", "CLOSE",
"SLASH_CLOSE", "EQUALS", "Name", "STRING", "NUMBER", "DIGIT", "ALPHA"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'<Window>'", "'</Window>'", null, null, null, "'<'", "'</'", "'>'",
"'/>'", "'='"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, "SELF_CLOSING", "UNIT", "WS", "OPEN", "OPEN_SLASH",
"CLOSE", "SLASH_CLOSE", "EQUALS", "Name", "STRING", "NUMBER"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public XMLLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "XML.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getChannelNames() { return channelNames; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\u0004\u0000\rr\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+
"\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+
"\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+
"\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0001"+
"\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+
"\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001"+
"\u0003\u0001\u0003\u0003\u0003:\b\u0003\u0001\u0004\u0004\u0004=\b\u0004"+
"\u000b\u0004\f\u0004>\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001\b\u0001"+
"\b\u0001\b\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\n\u0005\nS\b"+
"\n\n\n\f\nV\t\n\u0001\u000b\u0001\u000b\u0005\u000bZ\b\u000b\n\u000b\f"+
"\u000b]\t\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0005\u000bb\b\u000b"+
"\n\u000b\f\u000be\t\u000b\u0001\u000b\u0003\u000bh\b\u000b\u0001\f\u0004"+
"\fk\b\f\u000b\f\f\fl\u0001\r\u0001\r\u0001\u000e\u0001\u000e\u0000\u0000"+
"\u000f\u0001\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006"+
"\r\u0007\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u0000"+
"\u001d\u0000\u0001\u0000\u0006\u0003\u0000\t\n\r\r \u0002\u0000-.__\u0001"+
"\u0000\"\"\u0001\u0000\'\'\u0001\u000009\u0002\u0000AZazx\u0000\u0001"+
"\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005"+
"\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001"+
"\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000"+
"\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000"+
"\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000"+
"\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000"+
"\u0000\u0000\u0001\u001f\u0001\u0000\u0000\u0000\u0003(\u0001\u0000\u0000"+
"\u0000\u00052\u0001\u0000\u0000\u0000\u00079\u0001\u0000\u0000\u0000\t"+
"<\u0001\u0000\u0000\u0000\u000bB\u0001\u0000\u0000\u0000\rD\u0001\u0000"+
"\u0000\u0000\u000fG\u0001\u0000\u0000\u0000\u0011I\u0001\u0000\u0000\u0000"+
"\u0013L\u0001\u0000\u0000\u0000\u0015N\u0001\u0000\u0000\u0000\u0017g"+
"\u0001\u0000\u0000\u0000\u0019j\u0001\u0000\u0000\u0000\u001bn\u0001\u0000"+
"\u0000\u0000\u001dp\u0001\u0000\u0000\u0000\u001f \u0005<\u0000\u0000"+
" !\u0005W\u0000\u0000!\"\u0005i\u0000\u0000\"#\u0005n\u0000\u0000#$\u0005"+
"d\u0000\u0000$%\u0005o\u0000\u0000%&\u0005w\u0000\u0000&\'\u0005>\u0000"+
"\u0000\'\u0002\u0001\u0000\u0000\u0000()\u0005<\u0000\u0000)*\u0005/\u0000"+
"\u0000*+\u0005W\u0000\u0000+,\u0005i\u0000\u0000,-\u0005n\u0000\u0000"+
"-.\u0005d\u0000\u0000./\u0005o\u0000\u0000/0\u0005w\u0000\u000001\u0005"+
">\u0000\u00001\u0004\u0001\u0000\u0000\u000023\u0003\u000b\u0005\u0000"+
"34\u0003\u0015\n\u000045\u0003\u0011\b\u00005\u0006\u0001\u0000\u0000"+
"\u000067\u0005p\u0000\u00007:\u0005x\u0000\u00008:\u0005%\u0000\u0000"+
"96\u0001\u0000\u0000\u000098\u0001\u0000\u0000\u0000:\b\u0001\u0000\u0000"+
"\u0000;=\u0007\u0000\u0000\u0000<;\u0001\u0000\u0000\u0000=>\u0001\u0000"+
"\u0000\u0000><\u0001\u0000\u0000\u0000>?\u0001\u0000\u0000\u0000?@\u0001"+
"\u0000\u0000\u0000@A\u0006\u0004\u0000\u0000A\n\u0001\u0000\u0000\u0000"+
"BC\u0005<\u0000\u0000C\f\u0001\u0000\u0000\u0000DE\u0005<\u0000\u0000"+
"EF\u0005/\u0000\u0000F\u000e\u0001\u0000\u0000\u0000GH\u0005>\u0000\u0000"+
"H\u0010\u0001\u0000\u0000\u0000IJ\u0005/\u0000\u0000JK\u0005>\u0000\u0000"+
"K\u0012\u0001\u0000\u0000\u0000LM\u0005=\u0000\u0000M\u0014\u0001\u0000"+
"\u0000\u0000NT\u0003\u001d\u000e\u0000OS\u0003\u001d\u000e\u0000PS\u0003"+
"\u001b\r\u0000QS\u0007\u0001\u0000\u0000RO\u0001\u0000\u0000\u0000RP\u0001"+
"\u0000\u0000\u0000RQ\u0001\u0000\u0000\u0000SV\u0001\u0000\u0000\u0000"+
"TR\u0001\u0000\u0000\u0000TU\u0001\u0000\u0000\u0000U\u0016\u0001\u0000"+
"\u0000\u0000VT\u0001\u0000\u0000\u0000W[\u0005\"\u0000\u0000XZ\b\u0002"+
"\u0000\u0000YX\u0001\u0000\u0000\u0000Z]\u0001\u0000\u0000\u0000[Y\u0001"+
"\u0000\u0000\u0000[\\\u0001\u0000\u0000\u0000\\^\u0001\u0000\u0000\u0000"+
"][\u0001\u0000\u0000\u0000^h\u0005\"\u0000\u0000_c\u0005\'\u0000\u0000"+
"`b\b\u0003\u0000\u0000a`\u0001\u0000\u0000\u0000be\u0001\u0000\u0000\u0000"+
"ca\u0001\u0000\u0000\u0000cd\u0001\u0000\u0000\u0000df\u0001\u0000\u0000"+
"\u0000ec\u0001\u0000\u0000\u0000fh\u0005\'\u0000\u0000gW\u0001\u0000\u0000"+
"\u0000g_\u0001\u0000\u0000\u0000h\u0018\u0001\u0000\u0000\u0000ik\u0003"+
"\u001b\r\u0000ji\u0001\u0000\u0000\u0000kl\u0001\u0000\u0000\u0000lj\u0001"+
"\u0000\u0000\u0000lm\u0001\u0000\u0000\u0000m\u001a\u0001\u0000\u0000"+
"\u0000no\u0007\u0004\u0000\u0000o\u001c\u0001\u0000\u0000\u0000pq\u0007"+
"\u0005\u0000\u0000q\u001e\u0001\u0000\u0000\u0000\t\u00009>RT[cgl\u0001"+
"\u0006\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,20 @@
T__0=1
T__1=2
SELF_CLOSING=3
UNIT=4
WS=5
OPEN=6
OPEN_SLASH=7
CLOSE=8
SLASH_CLOSE=9
EQUALS=10
Name=11
STRING=12
NUMBER=13
'<Window>'=1
'</Window>'=2
'<'=6
'</'=7
'>'=8
'/>'=9
'='=10

View File

@ -0,0 +1,80 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link XMLParser}.
*/
public interface XMLListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link XMLParser#document}.
* @param ctx the parse tree
*/
void enterDocument(XMLParser.DocumentContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#document}.
* @param ctx the parse tree
*/
void exitDocument(XMLParser.DocumentContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#element}.
* @param ctx the parse tree
*/
void enterElement(XMLParser.ElementContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#element}.
* @param ctx the parse tree
*/
void exitElement(XMLParser.ElementContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#startTag}.
* @param ctx the parse tree
*/
void enterStartTag(XMLParser.StartTagContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#startTag}.
* @param ctx the parse tree
*/
void exitStartTag(XMLParser.StartTagContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#endTag}.
* @param ctx the parse tree
*/
void enterEndTag(XMLParser.EndTagContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#endTag}.
* @param ctx the parse tree
*/
void exitEndTag(XMLParser.EndTagContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#attribute}.
* @param ctx the parse tree
*/
void enterAttribute(XMLParser.AttributeContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#attribute}.
* @param ctx the parse tree
*/
void exitAttribute(XMLParser.AttributeContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#content}.
* @param ctx the parse tree
*/
void enterContent(XMLParser.ContentContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#content}.
* @param ctx the parse tree
*/
void exitContent(XMLParser.ContentContext ctx);
/**
* Enter a parse tree produced by {@link XMLParser#value}.
* @param ctx the parse tree
*/
void enterValue(XMLParser.ValueContext ctx);
/**
* Exit a parse tree produced by {@link XMLParser#value}.
* @param ctx the parse tree
*/
void exitValue(XMLParser.ValueContext ctx);
}

View File

@ -0,0 +1,578 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class XMLParser extends Parser {
static { RuntimeMetaData.checkVersion("4.13.0", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, SELF_CLOSING=3, UNIT=4, WS=5, OPEN=6, OPEN_SLASH=7, CLOSE=8,
SLASH_CLOSE=9, EQUALS=10, Name=11, STRING=12, NUMBER=13;
public static final int
RULE_document = 0, RULE_element = 1, RULE_startTag = 2, RULE_endTag = 3,
RULE_attribute = 4, RULE_content = 5, RULE_value = 6;
private static String[] makeRuleNames() {
return new String[] {
"document", "element", "startTag", "endTag", "attribute", "content",
"value"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'<Window>'", "'</Window>'", null, null, null, "'<'", "'</'", "'>'",
"'/>'", "'='"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, "SELF_CLOSING", "UNIT", "WS", "OPEN", "OPEN_SLASH",
"CLOSE", "SLASH_CLOSE", "EQUALS", "Name", "STRING", "NUMBER"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "XML.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public XMLParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class DocumentContext extends ParserRuleContext {
public List<ElementContext> element() {
return getRuleContexts(ElementContext.class);
}
public ElementContext element(int i) {
return getRuleContext(ElementContext.class,i);
}
public DocumentContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_document; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterDocument(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitDocument(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitDocument(this);
else return visitor.visitChildren(this);
}
}
public final DocumentContext document() throws RecognitionException {
DocumentContext _localctx = new DocumentContext(_ctx, getState());
enterRule(_localctx, 0, RULE_document);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(14);
match(T__0);
setState(16);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(15);
element();
}
}
setState(18);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==SELF_CLOSING || _la==OPEN );
setState(20);
match(T__1);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ElementContext extends ParserRuleContext {
public StartTagContext startTag() {
return getRuleContext(StartTagContext.class,0);
}
public EndTagContext endTag() {
return getRuleContext(EndTagContext.class,0);
}
public ContentContext content() {
return getRuleContext(ContentContext.class,0);
}
public TerminalNode SELF_CLOSING() { return getToken(XMLParser.SELF_CLOSING, 0); }
public ElementContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_element; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterElement(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitElement(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitElement(this);
else return visitor.visitChildren(this);
}
}
public final ElementContext element() throws RecognitionException {
ElementContext _localctx = new ElementContext(_ctx, getState());
enterRule(_localctx, 2, RULE_element);
int _la;
try {
setState(29);
_errHandler.sync(this);
switch (_input.LA(1)) {
case OPEN:
enterOuterAlt(_localctx, 1);
{
setState(22);
startTag();
setState(24);
_errHandler.sync(this);
_la = _input.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 4168L) != 0)) {
{
setState(23);
content();
}
}
setState(26);
endTag();
}
break;
case SELF_CLOSING:
enterOuterAlt(_localctx, 2);
{
setState(28);
match(SELF_CLOSING);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class StartTagContext extends ParserRuleContext {
public TerminalNode OPEN() { return getToken(XMLParser.OPEN, 0); }
public TerminalNode Name() { return getToken(XMLParser.Name, 0); }
public TerminalNode CLOSE() { return getToken(XMLParser.CLOSE, 0); }
public List<AttributeContext> attribute() {
return getRuleContexts(AttributeContext.class);
}
public AttributeContext attribute(int i) {
return getRuleContext(AttributeContext.class,i);
}
public StartTagContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_startTag; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterStartTag(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitStartTag(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitStartTag(this);
else return visitor.visitChildren(this);
}
}
public final StartTagContext startTag() throws RecognitionException {
StartTagContext _localctx = new StartTagContext(_ctx, getState());
enterRule(_localctx, 4, RULE_startTag);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(31);
match(OPEN);
setState(32);
match(Name);
setState(36);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==Name) {
{
{
setState(33);
attribute();
}
}
setState(38);
_errHandler.sync(this);
_la = _input.LA(1);
}
setState(39);
match(CLOSE);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class EndTagContext extends ParserRuleContext {
public TerminalNode OPEN_SLASH() { return getToken(XMLParser.OPEN_SLASH, 0); }
public TerminalNode Name() { return getToken(XMLParser.Name, 0); }
public TerminalNode CLOSE() { return getToken(XMLParser.CLOSE, 0); }
public EndTagContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_endTag; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterEndTag(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitEndTag(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitEndTag(this);
else return visitor.visitChildren(this);
}
}
public final EndTagContext endTag() throws RecognitionException {
EndTagContext _localctx = new EndTagContext(_ctx, getState());
enterRule(_localctx, 6, RULE_endTag);
try {
enterOuterAlt(_localctx, 1);
{
setState(41);
match(OPEN_SLASH);
setState(42);
match(Name);
setState(43);
match(CLOSE);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class AttributeContext extends ParserRuleContext {
public TerminalNode Name() { return getToken(XMLParser.Name, 0); }
public TerminalNode EQUALS() { return getToken(XMLParser.EQUALS, 0); }
public ValueContext value() {
return getRuleContext(ValueContext.class,0);
}
public AttributeContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_attribute; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterAttribute(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitAttribute(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitAttribute(this);
else return visitor.visitChildren(this);
}
}
public final AttributeContext attribute() throws RecognitionException {
AttributeContext _localctx = new AttributeContext(_ctx, getState());
enterRule(_localctx, 8, RULE_attribute);
try {
enterOuterAlt(_localctx, 1);
{
setState(45);
match(Name);
setState(46);
match(EQUALS);
setState(47);
value();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ContentContext extends ParserRuleContext {
public ElementContext element() {
return getRuleContext(ElementContext.class,0);
}
public TerminalNode STRING() { return getToken(XMLParser.STRING, 0); }
public ContentContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_content; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterContent(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitContent(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitContent(this);
else return visitor.visitChildren(this);
}
}
public final ContentContext content() throws RecognitionException {
ContentContext _localctx = new ContentContext(_ctx, getState());
enterRule(_localctx, 10, RULE_content);
try {
setState(51);
_errHandler.sync(this);
switch (_input.LA(1)) {
case SELF_CLOSING:
case OPEN:
enterOuterAlt(_localctx, 1);
{
setState(49);
element();
}
break;
case STRING:
enterOuterAlt(_localctx, 2);
{
setState(50);
match(STRING);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ValueContext extends ParserRuleContext {
public TerminalNode STRING() { return getToken(XMLParser.STRING, 0); }
public TerminalNode NUMBER() { return getToken(XMLParser.NUMBER, 0); }
public TerminalNode UNIT() { return getToken(XMLParser.UNIT, 0); }
public ValueContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_value; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).enterValue(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof XMLListener ) ((XMLListener)listener).exitValue(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof XMLVisitor ) return ((XMLVisitor<? extends T>)visitor).visitValue(this);
else return visitor.visitChildren(this);
}
}
public final ValueContext value() throws RecognitionException {
ValueContext _localctx = new ValueContext(_ctx, getState());
enterRule(_localctx, 12, RULE_value);
try {
setState(56);
_errHandler.sync(this);
switch (_input.LA(1)) {
case STRING:
enterOuterAlt(_localctx, 1);
{
setState(53);
match(STRING);
}
break;
case NUMBER:
enterOuterAlt(_localctx, 2);
{
setState(54);
match(NUMBER);
setState(55);
match(UNIT);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\r;\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
"\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
"\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0001\u0000\u0001\u0000\u0004"+
"\u0000\u0011\b\u0000\u000b\u0000\f\u0000\u0012\u0001\u0000\u0001\u0000"+
"\u0001\u0001\u0001\u0001\u0003\u0001\u0019\b\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0001\u0003\u0001\u001e\b\u0001\u0001\u0002\u0001\u0002\u0001\u0002"+
"\u0005\u0002#\b\u0002\n\u0002\f\u0002&\t\u0002\u0001\u0002\u0001\u0002"+
"\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004"+
"\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0003\u00054\b\u0005"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0003\u00069\b\u0006\u0001\u0006"+
"\u0000\u0000\u0007\u0000\u0002\u0004\u0006\b\n\f\u0000\u00009\u0000\u000e"+
"\u0001\u0000\u0000\u0000\u0002\u001d\u0001\u0000\u0000\u0000\u0004\u001f"+
"\u0001\u0000\u0000\u0000\u0006)\u0001\u0000\u0000\u0000\b-\u0001\u0000"+
"\u0000\u0000\n3\u0001\u0000\u0000\u0000\f8\u0001\u0000\u0000\u0000\u000e"+
"\u0010\u0005\u0001\u0000\u0000\u000f\u0011\u0003\u0002\u0001\u0000\u0010"+
"\u000f\u0001\u0000\u0000\u0000\u0011\u0012\u0001\u0000\u0000\u0000\u0012"+
"\u0010\u0001\u0000\u0000\u0000\u0012\u0013\u0001\u0000\u0000\u0000\u0013"+
"\u0014\u0001\u0000\u0000\u0000\u0014\u0015\u0005\u0002\u0000\u0000\u0015"+
"\u0001\u0001\u0000\u0000\u0000\u0016\u0018\u0003\u0004\u0002\u0000\u0017"+
"\u0019\u0003\n\u0005\u0000\u0018\u0017\u0001\u0000\u0000\u0000\u0018\u0019"+
"\u0001\u0000\u0000\u0000\u0019\u001a\u0001\u0000\u0000\u0000\u001a\u001b"+
"\u0003\u0006\u0003\u0000\u001b\u001e\u0001\u0000\u0000\u0000\u001c\u001e"+
"\u0005\u0003\u0000\u0000\u001d\u0016\u0001\u0000\u0000\u0000\u001d\u001c"+
"\u0001\u0000\u0000\u0000\u001e\u0003\u0001\u0000\u0000\u0000\u001f \u0005"+
"\u0006\u0000\u0000 $\u0005\u000b\u0000\u0000!#\u0003\b\u0004\u0000\"!"+
"\u0001\u0000\u0000\u0000#&\u0001\u0000\u0000\u0000$\"\u0001\u0000\u0000"+
"\u0000$%\u0001\u0000\u0000\u0000%\'\u0001\u0000\u0000\u0000&$\u0001\u0000"+
"\u0000\u0000\'(\u0005\b\u0000\u0000(\u0005\u0001\u0000\u0000\u0000)*\u0005"+
"\u0007\u0000\u0000*+\u0005\u000b\u0000\u0000+,\u0005\b\u0000\u0000,\u0007"+
"\u0001\u0000\u0000\u0000-.\u0005\u000b\u0000\u0000./\u0005\n\u0000\u0000"+
"/0\u0003\f\u0006\u00000\t\u0001\u0000\u0000\u000014\u0003\u0002\u0001"+
"\u000024\u0005\f\u0000\u000031\u0001\u0000\u0000\u000032\u0001\u0000\u0000"+
"\u00004\u000b\u0001\u0000\u0000\u000059\u0005\f\u0000\u000067\u0005\r"+
"\u0000\u000079\u0005\u0004\u0000\u000085\u0001\u0000\u0000\u000086\u0001"+
"\u0000\u0000\u00009\r\u0001\u0000\u0000\u0000\u0006\u0012\u0018\u001d"+
"$38";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,55 @@
// Generated from XML.g4 by ANTLR 4.13.0
package main.java.src2.main.java.controlP5.controlP5.layout.lang;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link XMLParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface XMLVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by {@link XMLParser#document}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDocument(XMLParser.DocumentContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#element}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitElement(XMLParser.ElementContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#startTag}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitStartTag(XMLParser.StartTagContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#endTag}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitEndTag(XMLParser.EndTagContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#attribute}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAttribute(XMLParser.AttributeContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#content}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitContent(XMLParser.ContentContext ctx);
/**
* Visit a parse tree produced by {@link XMLParser#value}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitValue(XMLParser.ValueContext ctx);
}

16
controlP5/package.html Executable file
View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>controlP5 documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>ControlP5</h1>
<p>ControlP5 (<a href="http://www.sojamo.de/libraries/controlP5" target="_blank">www.sojamo.de/libraries/controlP5</a>) is a library written by Andreas Schlegel for the programming environment <a href="http://www.processing.org" target="_blank">processing</a>. ControlP5 is a GUI and controller library for processing that can be used in authoring, application mode. Controllers including Sliders, Buttons, Toggles, Knobs, Textfields, RadioButtons, Checkboxes amongst others can be easily added to a processing sketch and can be arranged in separate control windows, or can be organized in tabs or groups. The controlP5 source code repository is available on github at <a href="http://github.com/sojamo/controlp5" target="_blank">github.com/sojamo/controlp5</a>.
</p>
<h1>Javascript</h1>
<p>Currently there is no javascript version of ControlP5, though I had started implementing a slimmed down version for processing.js but since it is currently unclear which javascript version, processing.js or p5.js, will become the default js version of processing, controlP5.js is on hold.</p>
</body>
</html>

8
controlp5.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
</component>
</module>

Some files were not shown because too many files have changed in this diff Show More