-
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: the initial framework for PropertyMapView is implemented, closes …
- Loading branch information
Showing
9 changed files
with
224 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 0 additions & 125 deletions
125
fxgl-scene/src/main/java/com/almasb/fxgl/ui/PropertyMapView.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
fxgl-scene/src/main/java/com/almasb/fxgl/ui/property/Point2DPropertyViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* FXGL - JavaFX Game Library. The MIT License (MIT). | ||
* Copyright (c) AlmasB ([email protected]). | ||
* See LICENSE for details. | ||
*/ | ||
|
||
package com.almasb.fxgl.ui.property; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.geometry.Point2D; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.HBox; | ||
|
||
/** | ||
* // TODO: read-only version? | ||
* | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
public class Point2DPropertyViewFactory implements PropertyViewFactory<Point2D, HBox> { | ||
|
||
private boolean ignoreChangeView = false; | ||
private boolean ignoreChangeProperty = false; | ||
|
||
@Override | ||
public HBox makeView(ObjectProperty<Point2D> value) { | ||
var fieldX = new TextField(); | ||
var fieldY = new TextField(); | ||
HBox view = new HBox(fieldX, fieldY); | ||
|
||
value.addListener((obs, o, newValue) -> { | ||
if (ignoreChangeProperty) | ||
return; | ||
|
||
onPropertyChanged(value, view); | ||
}); | ||
|
||
fieldX.textProperty().addListener((obs, o, x) -> { | ||
if (ignoreChangeView) | ||
return; | ||
|
||
onViewChanged(value, view); | ||
}); | ||
|
||
fieldY.textProperty().addListener((obs, o, y) -> { | ||
if (ignoreChangeView) | ||
return; | ||
|
||
onViewChanged(value, view); | ||
}); | ||
|
||
onPropertyChanged(value, view); | ||
|
||
return view; | ||
} | ||
|
||
@Override | ||
public void onPropertyChanged(ObjectProperty<Point2D> value, HBox view) { | ||
var fieldX = (TextField) view.getChildren().get(0); | ||
var fieldY = (TextField) view.getChildren().get(1); | ||
|
||
ignoreChangeView = true; | ||
|
||
fieldX.setText(Double.toString(value.getValue().getX())); | ||
fieldY.setText(Double.toString(value.getValue().getY())); | ||
|
||
ignoreChangeView = false; | ||
} | ||
|
||
@Override | ||
public void onViewChanged(ObjectProperty<Point2D> value, HBox view) { | ||
var fieldX = (TextField) view.getChildren().get(0); | ||
var fieldY = (TextField) view.getChildren().get(1); | ||
|
||
ignoreChangeProperty = true; | ||
|
||
var newPoint = new Point2D( | ||
Double.parseDouble(fieldX.getText()), | ||
Double.parseDouble(fieldY.getText()) | ||
); | ||
|
||
value.setValue(newPoint); | ||
|
||
ignoreChangeProperty = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,32 @@ | |
* See LICENSE for details. | ||
*/ | ||
|
||
package com.almasb.fxgl.ui; | ||
package com.almasb.fxgl.ui.property; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.scene.Node; | ||
|
||
/** | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
public interface PropertyViewChangeListener<T, V extends Node> { | ||
public interface PropertyViewFactory<T, V extends Node> { | ||
|
||
default V makeViewInternal(ObjectProperty<?> v) { | ||
return makeView((ObjectProperty<T>) v); | ||
} | ||
|
||
/** | ||
* @return the visual representation of the property [value] | ||
*/ | ||
V makeView(ObjectProperty<T> value); | ||
|
||
|
||
/** | ||
* Called when the property has changed, so that the view can be updated. | ||
*/ | ||
void onPropertyChanged(ObjectProperty<T> value, V view); | ||
|
||
|
||
/** | ||
* Called when the view has changed, so that the property can be updated. | ||
*/ | ||
void onViewChanged(ObjectProperty<T> value, V view); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,17 @@ | |
|
||
import com.almasb.fxgl.core.collection.UpdatableObjectProperty; | ||
import com.almasb.fxgl.core.math.Vec2; | ||
import com.almasb.fxgl.ui.PropertyViewChangeListener; | ||
import javafx.beans.property.ObjectProperty; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.HBox; | ||
|
||
/** | ||
* // TODO: read-only version? | ||
* // TODO: empty String check when view is updated | ||
* | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
public class Vec2PropertyViewChangeListener implements PropertyViewChangeListener<Vec2, HBox> { | ||
public class Vec2PropertyViewFactory implements PropertyViewFactory<Vec2, HBox> { | ||
|
||
private boolean ignoreChangeView = false; | ||
private boolean ignoreChangeProperty = false; | ||
|
Oops, something went wrong.