From 2fbaa25d70854de2857d9fa20ac6a34c294a4222 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Wed, 12 Apr 2023 18:56:29 +0200
Subject: GraphUI: Return this on setter/modifier methods for chaining
---
.../classes/com/jogamp/graph/ui/GraphShape.java | 6 +-
src/graphui/classes/com/jogamp/graph/ui/Group.java | 4 +-
src/graphui/classes/com/jogamp/graph/ui/Shape.java | 79 ++++++++++++++++------
.../com/jogamp/graph/ui/shapes/RoundButton.java | 6 +-
4 files changed, 67 insertions(+), 28 deletions(-)
(limited to 'src/graphui/classes/com/jogamp/graph/ui')
diff --git a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java
index 8b142210a..4d2202145 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java
@@ -74,15 +74,17 @@ public abstract class GraphShape extends Shape {
public final int getRenderModes() { return renderModes; }
public final int getQuality() { return regionQuality; }
- public final void setQuality(final int q) {
+ public final GraphShape setQuality(final int q) {
this.regionQuality = q;
if( null != region ) {
region.setQuality(q);
}
+ return this;
}
- public final void setSharpness(final float sharpness) {
+ public final GraphShape setSharpness(final float sharpness) {
this.oshapeSharpness = sharpness;
markShapeDirty();
+ return this;
}
public final float getSharpness() {
return oshapeSharpness;
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java
index 9dd49bdf4..b3ae5b41d 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Group.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java
@@ -80,10 +80,10 @@ public class Group extends Shape implements Container {
}
/** Return current {@link Group.Layout}. */
- public Layout getLayour() { return layouter; }
+ public Layout getLayout() { return layouter; }
/** Set {@link Group.Layout}. */
- public void setLayout(final Layout l) { layouter = l; }
+ public Group setLayout(final Layout l) { layouter = l; return this; }
@Override
public List getShapes() {
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
index e46700f26..63f1a7607 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -146,21 +146,22 @@ public abstract class Shape {
}
/** Set a symbolic name for this shape for identification. Default is -1 for noname. */
- public final void setName(final int name) { this.name = name; }
+ public final Shape setName(final int name) { this.name = name; return this; }
/** Return the optional symbolic name for this shape. */
public final int getName() { return this.name; }
/** Returns true if this shape is enabled and hence visible, otherwise false. */
public final boolean isEnabled() { return enabled; }
/** Enable or disable this shape, i.e. its visibility. */
- public final void setEnabled(final boolean v) { enabled = v; }
+ public final Shape setEnabled(final boolean v) { enabled = v; return this; }
/**
* Sets the {@link #getBounds()} fractional thickness of the debug box ranging [0..1], zero for no debug box (default).
* @param v fractional thickness of {@link #getBounds()} ranging [0..1], zero for no debug box
*/
- public final void setDebugBox(final float v) {
+ public final Shape setDebugBox(final float v) {
dbgbox_thickness = Math.min(1f, Math.max(0f, v));
+ return this;
}
/** Returns true if a debug box has been enabled via {@link #setDebugBox(float)}. */
public final boolean hasDebugBox() { return !FloatUtil.isZero(dbgbox_thickness); }
@@ -203,35 +204,39 @@ public abstract class Shape {
public final void onToggle(final Listener l) { onToggleListener = l; }
/** Move to scaled position. Position ends up in PMVMatrix unmodified. */
- public final void moveTo(final float tx, final float ty, final float tz) {
+ public final Shape moveTo(final float tx, final float ty, final float tz) {
position.set(tx, ty, tz);
if( null != onMoveListener ) {
onMoveListener.run(this);
}
+ return this;
}
/** Move to scaled position. Position ends up in PMVMatrix unmodified. */
- public final void moveTo(final Vec3f t) {
+ public final Shape moveTo(final Vec3f t) {
position.set(t);
if( null != onMoveListener ) {
onMoveListener.run(this);
}
+ return this;
}
/** Move about scaled distance. Position ends up in PMVMatrix unmodified. */
- public final void move(final float dtx, final float dty, final float dtz) {
+ public final Shape move(final float dtx, final float dty, final float dtz) {
position.add(dtx, dty, dtz);
if( null != onMoveListener ) {
onMoveListener.run(this);
}
+ return this;
}
/** Move about scaled distance. Position ends up in PMVMatrix unmodified. */
- public final void move(final Vec3f dt) {
+ public final Shape move(final Vec3f dt) {
position.add(dt);
if( null != onMoveListener ) {
onMoveListener.run(this);
}
+ return this;
}
/** Returns position, i.e. scaled translation as set via {@link #moveTo(float, float, float) or {@link #move(float, float, float)}}. */
@@ -249,8 +254,9 @@ public abstract class Shape {
* Set unscaled rotation origin, aka pivot. Usually the {@link #getBounds()} center and should be set while {@link #validateImpl(GLProfile, GL2ES2)}.
* @param pivot rotation origin
*/
- public final void setRotationPivot(final Vec3f pivot) {
+ public final Shape setRotationPivot(final Vec3f pivot) {
rotPivot.set(pivot);
+ return this;
}
/**
@@ -258,16 +264,18 @@ public abstract class Shape {
* @see #scale(float, float, float)
* @see #getScale()
*/
- public final void setScale(final float sx, final float sy, final float sz) {
+ public final Shape setScale(final float sx, final float sy, final float sz) {
scale.set(sx, sy, sz);
+ return this;
}
/**
* Multiply current scale factor by given scale.
* @see #setScale(float, float, float)
* @see #getScale()
*/
- public final void scale(final float sx, final float sy, final float sz) {
+ public final Shape scale(final float sx, final float sy, final float sz) {
scale.scale(sx, sy, sz);
+ return this;
}
/**
* Returns scale factors.
@@ -769,11 +777,12 @@ public abstract class Shape {
* Default base-color w/o color channel, will be modulated w/ pressed- and toggle color
*
*/
- public final void setColor(final float r, final float g, final float b, final float a) {
+ public final Shape setColor(final float r, final float g, final float b, final float a) {
this.rgbaColor[0] = r;
this.rgbaColor[1] = g;
this.rgbaColor[2] = b;
this.rgbaColor[3] = a;
+ return this;
}
/**
@@ -782,11 +791,12 @@ public abstract class Shape {
* Default pressed color-factor w/o color channel, modulated base-color. 0.75 * 1.2 = 0.9
*
*/
- public final void setPressedColorMod(final float r, final float g, final float b, final float a) {
+ public final Shape setPressedColorMod(final float r, final float g, final float b, final float a) {
this.pressedRGBAModulate[0] = r;
this.pressedRGBAModulate[1] = g;
this.pressedRGBAModulate[2] = b;
this.pressedRGBAModulate[3] = a;
+ return this;
}
/**
@@ -795,11 +805,12 @@ public abstract class Shape {
* Default toggle-on color-factor w/o color channel, modulated base-color. 0.75 * 1.13 ~ 0.85
*
*/
- public final void setToggleOnColorMod(final float r, final float g, final float b, final float a) {
+ public final Shape setToggleOnColorMod(final float r, final float g, final float b, final float a) {
this.toggleOnRGBAModulate[0] = r;
this.toggleOnRGBAModulate[1] = g;
this.toggleOnRGBAModulate[2] = b;
this.toggleOnRGBAModulate[3] = a;
+ return this;
}
/**
@@ -808,11 +819,12 @@ public abstract class Shape {
* Default toggle-off color-factor w/o color channel, modulated base-color. 0.75 * 0.86 ~ 0.65
*
*/
- public final void setToggleOffColorMod(final float r, final float g, final float b, final float a) {
+ public final Shape setToggleOffColorMod(final float r, final float g, final float b, final float a) {
this.toggleOffRGBAModulate[0] = r;
this.toggleOffRGBAModulate[1] = g;
this.toggleOffRGBAModulate[2] = b;
this.toggleOffRGBAModulate[3] = a;
+ return this;
}
@Override
@@ -850,9 +862,10 @@ public abstract class Shape {
// Input
//
- public void setPressed(final boolean b) {
+ public Shape setPressed(final boolean b) {
this.down = b;
markStateDirty();
+ return this;
}
public boolean isPressed() {
return this.down;
@@ -863,8 +876,9 @@ public abstract class Shape {
* @param toggleable
* @see #isInteractive()
*/
- public void setToggleable(final boolean toggleable) {
+ public Shape setToggleable(final boolean toggleable) {
this.toggleable = toggleable;
+ return this;
}
/**
@@ -875,16 +889,20 @@ public abstract class Shape {
public boolean isToggleable() {
return toggleable;
}
- public void setToggle(final boolean v) {
+ public Shape setToggle(final boolean v) {
toggle = v;
markStateDirty();
+ return this;
}
- public void toggle() {
+ public Shape toggle() {
if( isToggleable() ) {
toggle = !toggle;
- onToggleListener.run(this);
+ if( null != onToggleListener ) {
+ onToggleListener.run(this);
+ }
markStateDirty();
}
+ return this;
}
public boolean isToggleOn() { return toggle; }
@@ -897,7 +915,7 @@ public abstract class Shape {
* but excluding programmatic changes.
* @param v new value for {@link #isInteractive()}
*/
- public void setInteractive(final boolean v) { interactive = v; }
+ public Shape setInteractive(final boolean v) { interactive = v; return this; }
/**
* Returns if this shape allows user interaction, see {@link #setInteractive(boolean)}
* @see #setInteractive(boolean)
@@ -912,8 +930,9 @@ public abstract class Shape {
*
* @see #isInteractive()
*/
- public void setDraggable(final boolean draggable) {
+ public Shape setDraggable(final boolean draggable) {
this.draggable = draggable;
+ return this;
}
/**
* Returns if this shape is draggable, a user interaction.
@@ -931,8 +950,9 @@ public abstract class Shape {
*
* @see #isInteractive()
*/
- public void setResizable(final boolean resizable) {
+ public Shape setResizable(final boolean resizable) {
this.resizable = resizable;
+ return this;
}
/**
* Returns if this shape is resiable, a user interaction.
@@ -942,6 +962,21 @@ public abstract class Shape {
return resizable;
}
+ /**
+ * Set whether this shape is draggable and resizable.
+ *
+ * Default draggable and resizable is true.
+ *
+ * @see #setDraggable(boolean)
+ * @see #setResizable(boolean)
+ * @see #isInteractive()
+ */
+ public Shape setDragAndResizeable(final boolean v) {
+ this.draggable = v;
+ this.resizable = v;
+ return this;
+ }
+
public final void addMouseListener(final MouseGestureListener l) {
if(l == null) {
return;
diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/RoundButton.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/RoundButton.java
index a2ab43ae1..4ea154c09 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/shapes/RoundButton.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/RoundButton.java
@@ -60,10 +60,11 @@ public abstract class RoundButton extends GraphShape {
public final float getCorner() { return corner; }
- public void setSize(final float width, final float height) {
+ public RoundButton setSize(final float width, final float height) {
this.width = width;
this.height = height;
markShapeDirty();
+ return this;
}
protected void createSharpOutline(final OutlineShape shape, final float zOffset) {
@@ -109,7 +110,7 @@ public abstract class RoundButton extends GraphShape {
}
/** Set corner size, default is {@link #DEFAULT_CORNER} */
- public void setCorner(final float corner) {
+ public RoundButton setCorner(final float corner) {
if(corner > 1.0f){
this.corner = 1.0f;
}
@@ -120,6 +121,7 @@ public abstract class RoundButton extends GraphShape {
this.corner = corner;
}
markShapeDirty();
+ return this;
}
@Override
--
cgit v1.2.3