Update Tab.java

Fix & cleanup **_ControllerGroup_** inheritance in **_Tab_**.
This commit is contained in:
GoToLoop 2016-07-15 04:04:44 -03:00 committed by GitHub
parent 1f7cb64986
commit 1506b77aab
1 changed files with 35 additions and 65 deletions

View File

@ -1,5 +1,3 @@
package controlP5;
/** /**
* controlP5 is a processing gui library. * controlP5 is a processing gui library.
* *
@ -25,6 +23,8 @@ package controlP5;
* *
*/ */
package controlP5;
import processing.core.PGraphics; import processing.core.PGraphics;
/** /**
@ -42,8 +42,6 @@ public class Tab extends ControllerGroup< Tab > {
protected boolean isActive = false; protected boolean isActive = false;
private boolean isAlwaysActive = false; private boolean isAlwaysActive = false;
protected boolean isEventActive = false; protected boolean isEventActive = false;
protected float _myValue = 0;
protected String _myStringValue = "";
public static int padding = 4; public static int padding = 4;
public boolean autoWidth = true; public boolean autoWidth = true;
@ -55,8 +53,6 @@ public class Tab extends ControllerGroup< Tab > {
*/ */
public Tab( ControlP5 theControlP5 , ControlWindow theControlWindow , String theName ) { public Tab( ControlP5 theControlP5 , ControlWindow theControlWindow , String theName ) {
super( theControlP5 , null , theName , 0 , 0 ); super( theControlP5 , null , theName , 0 , 0 );
position = new float[ 2 ];
absolutePosition = new float[ 2 ];
isMoveable = false; isMoveable = false;
isEventActive = theControlP5.isTabEventsActive; isEventActive = theControlP5.isTabEventsActive;
_myHeight = 16; _myHeight = 16;
@ -69,26 +65,22 @@ public class Tab extends ControllerGroup< Tab > {
_myOffsetY = theValueY; _myOffsetY = theValueY;
} }
protected int height( ) { @Deprecated protected int height( ) {
return _myHeight; return getHeight( );
} }
protected boolean updateLabel( ) { protected boolean updateLabel( ) {
isInside = inside( ); isInside = inside( );
return cp5.getWindow( ).getTabs( ).size( ) > 2; return getWindow( ).getTabs( ).size( ) > 2;
} }
protected void drawLabel( PGraphics theGraphics ) { protected void drawLabel( final PGraphics theGraphics ) {
if ( autoWidth ) { if ( autoWidth ) _myWidth = _myLabel.getWidth( ) + 2*padding;
_myWidth = _myLabel.getWidth( ) + padding * 2;
}
theGraphics.pushMatrix( ); theGraphics.pushMatrix( );
theGraphics.pushStyle( ); theGraphics.pushStyle( );
theGraphics.noStroke( ); theGraphics.noStroke( );
theGraphics.fill( isInside ? color.getForeground( ) : color.getBackground( ) ); theGraphics.fill( isInside ? color.getForeground( ) : color.getBackground( ) );
if ( isActive ) { if ( isActive ) theGraphics.fill( color.getActive( ) );
theGraphics.fill( color.getActive( ) );
}
theGraphics.translate( _myOffsetX , _myOffsetY ); theGraphics.translate( _myOffsetX , _myOffsetY );
theGraphics.rect( 0 , 0 , _myWidth - 1 , _myHeight ); theGraphics.rect( 0 , 0 , _myWidth - 1 , _myHeight );
_myLabel.draw( theGraphics , padding , 0 , this ); _myLabel.draw( theGraphics , padding , 0 , this );
@ -103,42 +95,42 @@ public class Tab extends ControllerGroup< Tab > {
* @param theLabel String * @param theLabel String
* @return Tab * @return Tab
*/ */
public Tab setLabel( String theLabel ) { // public Tab setLabel( String theLabel ) {
_myLabel.set( theLabel ); // _myLabel.set( theLabel );
return this; // return this;
} // }
protected int width( ) { @Deprecated protected int width( ) {
return _myWidth; return getWidth( );
} }
/** /**
* @param theWidth * @param theWidth
* @return * @return
*/ */
public Tab setWidth( int theWidth ) { @Override public T setWidth( int theWidth ) {
_myWidth = theWidth + padding; _myWidth = theWidth + padding;
autoWidth = false; autoWidth = false;
return this; return me;
} }
public Tab setHeight( int theHeight ) { // public Tab setHeight( int theHeight ) {
_myHeight = theHeight; // _myHeight = theHeight;
return this; // return this;
} // }
protected boolean inside( ) { @Override protected boolean inside( ) {
return ( cp5.getWindow( ).mouseX > _myOffsetX && cp5.getWindow( ).mouseX < _myOffsetX + _myWidth && cp5.getWindow( ).mouseY > _myOffsetY && cp5.getWindow( ).mouseY < _myOffsetY + _myHeight ); final int mx = getWindow( ).mouseX, my = getWindow( ).mouseY;
return mx > _myOffsetX && mx < _myOffsetX + _myWidth &&
my > _myOffsetY && my < _myOffsetY + _myHeight;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ControlP5.Invisible public void mousePressed( ) { @ControlP5.Invisible @Override public void mousePressed( ) {
cp5.getWindow( ).activateTab( this ); getWindow( ).activateTab( this );
if ( isEventActive ) { if ( isEventActive ) cp5.getControlBroadcaster( ).broadcast( new ControlEvent( this ) , METHOD );
cp5.getControlBroadcaster( ).broadcast( new ControlEvent( this ) , ControlP5Constants.METHOD );
}
} }
/** /**
@ -169,18 +161,17 @@ public class Tab extends ControllerGroup< Tab > {
return isAlwaysActive; return isAlwaysActive;
} }
@Override public Tab bringToFront( ) { @Override public T bringToFront( ) {
cp5.getWindow( ).activateTab( this ); getWindow( ).activateTab( this );
return this; return me;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override public Tab moveTo( ControlWindow theWindow ) { @Override public T moveTo( ControlWindow theControlWindow ) {
cp5.getWindow( ).removeTab( this ); getWindow( ).removeTab( this );
setTab( theWindow , getName( ) ); return setTab( theControlWindow , getName( ) );
return this;
} }
/** /**
@ -195,34 +186,13 @@ public class Tab extends ControllerGroup< Tab > {
return this; 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( ) { @Deprecated public float value( ) {
return _myValue; return getValue( );
} }
@Deprecated public String stringValue( ) { @Deprecated public String stringValue( ) {
return _myStringValue; return getStringValue( );
} }
} }