8000 Slider, range and color arguments by kamil-orwat-vmltech · Pull Request #82 · wttech/acm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Slider, range and color arguments #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public enum ArgumentType {
STRING,
TEXT,
SELECT,
MULTISELECT
MULTISELECT,
COLOR,
NUMBER_RANGE
}
26 changes: 26 additions & 0 deletions core/src/main/java/com/vml/es/aem/acm/core/code/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,32 @@ public void integerNumber(String name, Closure<IntegerArgument> options) {
add(argument);
}

public void color(String name) {
color(name, null);
}

public void color(String name, Closure<ColorArgument> options) {
ColorArgument argument = new ColorArgument(name);
8000 GroovyUtils.with(argument, options);
add(argument);
}

public void integerRange(String name, Closure<IntegerRangeArgument> options) {
IntegerRangeArgument argument = new IntegerRangeArgument(name);
GroovyUtils.with(argument, options);
add(argument);
}

public void decimalRange(String name) {
decimalRange(name, null);
}

public void decimalRange(String name, Closure<DecimalRangeArgument> options) {
DecimalRangeArgument argument = new DecimalRangeArgument(name);
GroovyUtils.with(argument, options);
add(argument);
}

public void decimalNumber(String name) {
decimalNumber(name, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.vml.es.aem.acm.core.code.arg;

import com.vml.es.aem.acm.core.code.Argument;
import com.vml.es.aem.acm.core.code.ArgumentType;
import java.util.Arrays;

public class ColorArgument extends Argument<String> {
private ColorArgument.Format format = ColorArgument.Format.RGBA;

public ColorArgument(String name) {
super(name, ArgumentType.COLOR);
}

public Format getFormat() {
return format;
}

public void setFormat(String format) {
this.format = ColorArgument.Format.of(format);
}

public void setFormat(ColorArgument.Format format) {
this.format = format;
}

public void hex() {
this.format = ColorArgument.Format.HEX;
}

public void hsl() {
this.format = ColorArgument.Format.HSL;
}

public void rgba() {
this.format = ColorArgument.Format.RGBA;
}

public void hsb() {
this.format = ColorArgument.Format.HSB;
}

public enum Format {
HEX,
HSL,
RGBA,
HSB;

public static ColorArgument.Format of(String name) {
return Arrays.stream(ColorArgument.Format.values())
.filter(r -> r.name().equalsIgnoreCase(name))
.findFirst()
.orElseThrow(() ->
new IllegalArgumentException(String.format("Color format '%s' is not supported!", name)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import com.vml.es.aem.acm.core.code.Argument;
import com.vml.es.aem.acm.core.code.ArgumentType;
import java.math.BigDecimal;
import java.util.Arrays;

public class DecimalArgument extends Argument<BigDecimal> {

private BigDecimal min;

private BigDecimal max;

private Display display = Display.INPUT;

private BigDecimal step;

public DecimalArgument(String name) {
super(name, ArgumentType.DECIMAL);
}
Expand All @@ -29,4 +34,43 @@ public BigDecimal getMax() {
public void setMax(BigDecimal max) {
this.max = max;
}

public void input() {
this.display = Display.INPUT;
}

public void slider() {
this.display = Display.SLIDER;
}

public void slider(BigDecimal min, BigDecimal max) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work with ints, doubles, strings when passed from groovy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, only decimals, but I think it's expected if we want type safety?

this.display = Display.SLIDER;
this.min = min;
this.max = max;
}

public Display getDisplay() {
return display;
}

public BigDecimal getStep() {
return step;
}

public void setStep(BigDecimal step) {
this.step = step;
}

public enum Display {
INPUT,
SLIDER;

public static DecimalArgument.Display of(String name) {
return Arrays.stream(DecimalArgument.Display.values())
.filter(r -> r.name().equalsIgnoreCase(name))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
String.format("Decimal argument cannot be displayed as '%s'!", name)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.vml.es.aem.acm.core.code.arg;

import com.vml.es.aem.acm.core.code.Argument;
import com.vml.es.aem.acm.core.code.ArgumentType;
import com.vml.es.aem.acm.core.util.RangeArgumentObject;
import java.math.BigDecimal;
import java.util.List;

public class DecimalRangeArgument extends Argument<RangeArgumentObject<BigDecimal>> {
private BigDecimal min;

private BigDecimal max;

private BigDecimal step;

public DecimalRangeArgument(String name) {
super(name, ArgumentType.NUMBER_RANGE);
}

public void setValue(List<BigDecimal> value) {
if (value.size() != 2) {
throw new IllegalArgumentException(
String.format("Range value must be a list of two elements but specified '%s'!", value));
}
super.setValue(new RangeArgumentObject<>(value.get(0), value.get(1)));
}

public BigDecimal getMin() {
return min;
}

public void setMin(BigDecimal min) {
this.min = min;
}

public BigDecimal getStep() {
return step;
}

public void setStep(BigDecimal step) {
this.step = step;
}

public BigDecimal getMax() {
return max;
}

public void setMax(BigDecimal max) {
this.max = max;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import com.vml.es.aem.acm.core.code.Argument;
import com.vml.es.aem.acm.core.code.ArgumentType;
import java.util.Arrays;

public class IntegerArgument extends Argument<Integer> {

private Integer min;

private Integer max;

private Display display = Display.INPUT;

private Integer step;

public IntegerArgument(String name) {
super(name, ArgumentType.INTEGER);
}
Expand All @@ -28,4 +33,43 @@ public Integer getMax() {
public void setMax(Integer max) {
this.max = max;
}

public void input() {
this.display = Display.INPUT;
}

public void slider() {
this.display = Display.SLIDER;
}

public void slider(Integer min, Integer max) {
this.display = Display.SLIDER;
this.min = min;
this.max = max;
}

public Display getDisplay() {
return display;
}

public Integer getStep() {
return step;
}

public void setStep(Integer step) {
this.step = step;
}

public enum Display {
INPUT,
SLIDER;

public static IntegerArgument.Display of(String name) {
return Arrays.stream(IntegerArgument.Display.values())
.filter(r -> r.name().equalsIgnoreCase(name))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
String.format("Decimal argument cannot be displayed as '%s'!", name)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.vml.es.aem.acm.core.code.arg;

import com.vml.es.aem.acm.core.code.Argument;
import com.vml.es.aem.acm.core.code.ArgumentType;
import com.vml.es.aem.acm.core.util.RangeArgumentObject;
import java.util.List;

public class IntegerRangeArgument extends Argument<RangeArgumentObject<Integer>> {
private Integer min;

private Integer max;

private Integer step;

public IntegerRangeArgument(String name) {
super(name, ArgumentType.NUMBER_RANGE);
}

public void setValue(List<Integer> value) {
if (value.size() != 2) {
throw new IllegalArgumentException(
String.format("Range value must be a list of two elements but specified '%s'!", value));
}
super.setValue(new RangeArgumentObject<>(value.get(0), value.get(1)));
}

public Integer getMin() {
return min;
}

public void setMin(Integer min) {
this.min = min;
}

public Integer getStep() {
return step;
}

public void setStep(Integer step) {
this.step = step;
}

public Integer getMax() {
return max;
}

public void setMax(Integer max) {
this.max = max;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.vml.es.aem.acm.core.util;

import java.io.Serializable;

public class RangeArgumentObject<T extends Comparable<T>> implements Serializable {
private T start;

private T end;

public RangeArgumentObject(T start, T end) {
this.start = start;
this.end = end;
}

public T getStart() {
return start;
}

public void setStart(T start) {
this.start = start;
}

public T getEnd() {
return end;
}

public void setEnd(T end) {
this.end = end;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
group: Argument
name: argument_color
content: |
args.color("${1:name}") { label = "${2:label}"; value = ${3:value} }
documentation: |
An argument that allows to choose a value from color picker.<br>
It returns a string with the color in selected format, RGBA is the default<br>
<br>
**Example**:<br>
```groovy
args.color("color") { label = "background color"; value = "#ff0000"; hex() }
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
group: Argument
name: argument_decimal
content: |
args.decimalNumber("${1:name}") { label = "${2:label}"; value = "${3:value}" }
args.decimalNumber("${1:name}") { label = "${2:label}"; value = ${3:value} }
documentation: |
An argument holding a decimal number value.<br>

For example:
can be displayed as an input and slider.<br>
**Example**:<br>
```groovy
args.decimalNumber("discount") { label = "Discount (%)"; value = 15.5 }
args.decimalNumber("weight") { label = "Weight (kg)"; value = 75.3 }
```
args.decimalNumber("proportion") { label = "Proportion"; value = 20.00; min = 10.00; max = 60.00; step = 0.5; slider() }
```
Loading
0