Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
eraser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenLicht
eraser
Commits
41902a6e
Commit
41902a6e
authored
6 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
Make TupleHSB immutable.
parent
1200d613
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
eraser-base/src/main/jastadd/Item.jrag
+5
-7
5 additions, 7 deletions
eraser-base/src/main/jastadd/Item.jrag
eraser-base/src/main/java/de/tudresden/inf/st/eraser/jastadd/model/TupleHSB.java
+27
-3
27 additions, 3 deletions
...va/de/tudresden/inf/st/eraser/jastadd/model/TupleHSB.java
with
32 additions
and
10 deletions
eraser-base/src/main/jastadd/Item.jrag
+
5
−
7
View file @
41902a6e
...
@@ -26,7 +26,7 @@ aspect ItemHandling {
...
@@ -26,7 +26,7 @@ aspect ItemHandling {
// TupleHSB and String work like default
// TupleHSB and String work like default
eq ColorItem.getStateAsDouble() {
eq ColorItem.getStateAsDouble() {
logger.warn("getStateAsDouble called on item " + getLabel() + ". Using brightness.");
logger.warn("getStateAsDouble called on item " + getLabel() + ". Using brightness.");
return getState().
b
rightness;
return getState().
getB
rightness
()
;
}
}
eq DateTimeItem.getStateAsDouble() = getState().getTime();
eq DateTimeItem.getStateAsDouble() = getState().getTime();
eq ItemWithBooleanState.getStateAsDouble() = getState() ? 1 : 0;
eq ItemWithBooleanState.getStateAsDouble() = getState() ? 1 : 0;
...
@@ -87,7 +87,7 @@ aspect ItemHandling {
...
@@ -87,7 +87,7 @@ aspect ItemHandling {
public abstract void Item.setStateFromLong(long value);
public abstract void Item.setStateFromLong(long value);
public void ColorItem.setStateFromLong(long value) {
public void ColorItem.setStateFromLong(long value) {
// only set brightness
// only set brightness
this.setState(
TupleHSB.of(getState().hue, getState().saturation,
Math.toIntExact(value)));
this.setState(
getState().withDifferentBrightness(
Math.toIntExact(value)));
}
}
public void DateTimeItem.setStateFromLong(long value) {
public void DateTimeItem.setStateFromLong(long value) {
this.setState(new Date(value));
this.setState(new Date(value));
...
@@ -167,10 +167,10 @@ aspect ItemHandling {
...
@@ -167,10 +167,10 @@ aspect ItemHandling {
logger.warn("Ignoring color update using {} for {}", this, value);
logger.warn("Ignoring color update using {} for {}", this, value);
}
}
public void ItemWithBooleanState.setStateFromColor(TupleHSB value) {
public void ItemWithBooleanState.setStateFromColor(TupleHSB value) {
this.setState(value != null && value.
b
rightness > 0);
this.setState(value != null && value.
getB
rightness
()
> 0);
}
}
public void ItemWithDoubleState.setStateFromColor(TupleHSB value) {
public void ItemWithDoubleState.setStateFromColor(TupleHSB value) {
this.setState(value.
b
rightness);
this.setState(value.
getB
rightness
()
);
}
}
public void ItemWithStringState.setStateFromColor(TupleHSB value) {
public void ItemWithStringState.setStateFromColor(TupleHSB value) {
this.setState(value.toString());
this.setState(value.toString());
...
@@ -358,9 +358,7 @@ aspect ItemHandling {
...
@@ -358,9 +358,7 @@ aspect ItemHandling {
}
}
private void ColorItem.setBrightness(int value) {
private void ColorItem.setBrightness(int value) {
TupleHSB newState = getState().clone();
setState(getState().withDifferentBrightness(value));
newState.brightness = value;
setState(newState);
}
}
//--- ItemPreference.apply ---
//--- ItemPreference.apply ---
...
...
This diff is collapsed.
Click to expand it.
eraser-base/src/main/java/de/tudresden/inf/st/eraser/jastadd/model/TupleHSB.java
+
27
−
3
View file @
41902a6e
...
@@ -8,9 +8,9 @@ import java.util.Objects;
...
@@ -8,9 +8,9 @@ import java.util.Objects;
* @author rschoene - Initial contribution
* @author rschoene - Initial contribution
*/
*/
public
class
TupleHSB
implements
Cloneable
{
public
class
TupleHSB
implements
Cloneable
{
p
ublic
int
hue
;
p
rivate
int
hue
;
p
ublic
int
saturation
;
p
rivate
int
saturation
;
p
ublic
int
brightness
;
p
rivate
int
brightness
;
public
static
TupleHSB
of
(
int
hue
,
int
saturation
,
int
brightness
)
{
public
static
TupleHSB
of
(
int
hue
,
int
saturation
,
int
brightness
)
{
TupleHSB
result
=
new
TupleHSB
();
TupleHSB
result
=
new
TupleHSB
();
result
.
hue
=
hue
;
result
.
hue
=
hue
;
...
@@ -19,6 +19,30 @@ public class TupleHSB implements Cloneable {
...
@@ -19,6 +19,30 @@ public class TupleHSB implements Cloneable {
return
result
;
return
result
;
}
}
public
int
getHue
()
{
return
hue
;
}
public
int
getSaturation
()
{
return
saturation
;
}
public
int
getBrightness
()
{
return
brightness
;
}
public
TupleHSB
withDifferentHue
(
int
hue
)
{
return
TupleHSB
.
of
(
hue
,
this
.
saturation
,
this
.
brightness
);
}
public
TupleHSB
withDifferentSaturation
(
int
saturation
)
{
return
TupleHSB
.
of
(
this
.
hue
,
saturation
,
this
.
brightness
);
}
public
TupleHSB
withDifferentBrightness
(
int
brightness
)
{
return
TupleHSB
.
of
(
this
.
hue
,
this
.
saturation
,
brightness
);
}
public
String
toString
()
{
public
String
toString
()
{
return
String
.
format
(
"%s,%s,%s"
,
hue
,
saturation
,
brightness
);
return
String
.
format
(
"%s,%s,%s"
,
hue
,
saturation
,
brightness
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment