update json data
This commit is contained in:
parent
8ad5f4fede
commit
dd37c9fc77
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -12,16 +14,18 @@ import com.google.gson.JsonSerializationContext;
|
|||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonAdapter(BaseInfoData.Serializer.class)
|
||||
public class BaseInfoData implements Cloneable {
|
||||
public class BaseInfoData implements Cloneable, Observable {
|
||||
|
||||
public enum SizeType {
|
||||
PERCENTAGE,
|
||||
|
@ -175,7 +179,7 @@ public class BaseInfoData implements Cloneable {
|
|||
}
|
||||
|
||||
public BaseInfoData() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -186,9 +190,23 @@ public class BaseInfoData implements Cloneable {
|
|||
absoluteWidthProperty.addListener(listener);
|
||||
absoluteHeightProperty.addListener(listener);
|
||||
percentageWidthProperty.addListener(listener);
|
||||
percentageWidthProperty.get().addPropertyChangedListener(listener);
|
||||
percentageHeightProperty.addListener(listener);
|
||||
percentageHeightProperty.get().addPropertyChangedListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -13,19 +15,21 @@ import com.google.gson.JsonSerializer;
|
|||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleBooleanProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonAdapter(ButtonEventData.Serializer.class)
|
||||
public class ButtonEventData implements Cloneable {
|
||||
public class ButtonEventData implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Press event
|
||||
|
@ -96,7 +100,7 @@ public class ButtonEventData implements Cloneable {
|
|||
}
|
||||
|
||||
public ButtonEventData() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -104,10 +108,22 @@ public class ButtonEventData implements Cloneable {
|
|||
longPressEventProperty.addListener(listener);
|
||||
clickEventProperty.addListener(listener);
|
||||
doubleClickEventProperty.addListener(listener);
|
||||
pressEventProperty.get().addPropertyChangedListener(listener);
|
||||
longPressEventProperty.get().addPropertyChangedListener(listener);
|
||||
clickEventProperty.get().addPropertyChangedListener(listener);
|
||||
doubleClickEventProperty.get().addPropertyChangedListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,7 +171,7 @@ public class ButtonEventData implements Cloneable {
|
|||
}
|
||||
|
||||
@JsonAdapter(Event.Serializer.class)
|
||||
public static class Event implements Cloneable {
|
||||
public static class Event implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Control mouse pointer
|
||||
|
@ -328,7 +344,7 @@ public class ButtonEventData implements Cloneable {
|
|||
}
|
||||
|
||||
public Event() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addKeycode(int keycode) {
|
||||
|
@ -377,6 +393,22 @@ public class ButtonEventData implements Cloneable {
|
|||
bindViewGroupProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event clone() {
|
||||
Event event = new Event();
|
||||
|
@ -432,8 +464,8 @@ public class ButtonEventData implements Cloneable {
|
|||
event.setSwitchTouchMode(Optional.ofNullable(obj.get("switchTouchMode")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
event.setInput(Optional.ofNullable(obj.get("input")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
event.setOutputText(Optional.ofNullable(obj.get("outputText")).map(JsonElement::getAsString).orElse(""));
|
||||
event.setOutputKeycodes(gson.fromJson(Optional.ofNullable(obj.get("outputKeycodes")).map(JsonElement::getAsString).orElse("{}"), new TypeToken<Integer>(){}.getType()));
|
||||
event.setBindViewGroup(gson.fromJson(Optional.ofNullable(obj.get("bindViewGroup")).map(JsonElement::getAsString).orElse("{}"), new TypeToken<String>(){}.getType()));
|
||||
event.setOutputKeycodes(gson.fromJson(Optional.ofNullable(obj.get("outputKeycodes")).map(JsonElement::getAsString).orElse(gson.toJson(new ArrayList<>())), new TypeToken<Integer>(){}.getType()));
|
||||
event.setBindViewGroup(gson.fromJson(Optional.ofNullable(obj.get("bindViewGroup")).map(JsonElement::getAsString).orElse(gson.toJson(new ArrayList<>())), new TypeToken<String>(){}.getType()));
|
||||
|
||||
return event;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -12,17 +14,19 @@ import com.google.gson.JsonSerializationContext;
|
|||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonAdapter(ControlButtonData.Serializer.class)
|
||||
public class ControlButtonData implements Cloneable {
|
||||
public class ControlButtonData implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Unique id
|
||||
|
@ -108,16 +112,31 @@ public class ControlButtonData implements Cloneable {
|
|||
|
||||
public ControlButtonData(String id) {
|
||||
this.id = id;
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
textProperty.addListener(listener);
|
||||
styleProperty.addListener(listener);
|
||||
styleProperty.get().addPropertyChangedListener(listener);
|
||||
baseInfoProperty.addListener(listener);
|
||||
baseInfoProperty.get().addPropertyChangedListener(listener);
|
||||
eventProperty.addListener(listener);
|
||||
eventProperty.get().addPropertyChangedListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -12,16 +14,18 @@ import com.google.gson.JsonSerializationContext;
|
|||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonAdapter(ControlButtonStyle.Serializer.class)
|
||||
public class ControlButtonStyle implements Cloneable {
|
||||
public class ControlButtonStyle implements Cloneable, Observable {
|
||||
|
||||
public static final ControlButtonStyle DEFAULT_BUTTON_STYLE = new ControlButtonStyle("Default");
|
||||
|
||||
|
@ -252,6 +256,8 @@ public class ControlButtonStyle implements Cloneable {
|
|||
|
||||
public ControlButtonStyle(String name) {
|
||||
this.nameProperty.set(name);
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -270,6 +276,22 @@ public class ControlButtonStyle implements Cloneable {
|
|||
fillColorPressedProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControlButtonStyle clone() {
|
||||
ControlButtonStyle style = new ControlButtonStyle(getName());
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -12,15 +14,17 @@ import com.google.gson.JsonSerializationContext;
|
|||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonAdapter(ControlDirectionData.Serializer.class)
|
||||
public class ControlDirectionData implements Cloneable {
|
||||
public class ControlDirectionData implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Unique id
|
||||
|
@ -89,15 +93,30 @@ public class ControlDirectionData implements Cloneable {
|
|||
|
||||
public ControlDirectionData(String id) {
|
||||
this.id = id;
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
styleProperty.addListener(listener);
|
||||
styleProperty.get().addPropertyChangedListener(listener);
|
||||
baseInfoProperty.addListener(listener);
|
||||
baseInfoProperty.get().addPropertyChangedListener(listener);
|
||||
eventProperty.addListener(listener);
|
||||
eventProperty.get().addPropertyChangedListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
|
@ -12,16 +14,18 @@ import com.google.gson.JsonSerializationContext;
|
|||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ControlDirectionStyle implements Cloneable {
|
||||
public class ControlDirectionStyle implements Cloneable, Observable {
|
||||
|
||||
public static final ControlDirectionStyle DEFAULT_DIRECTION_STYLE = new ControlDirectionStyle("Default");
|
||||
|
||||
|
@ -100,15 +104,31 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
|
||||
public ControlDirectionStyle(String name) {
|
||||
this.nameProperty.set(name);
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
nameProperty.addListener(listener);
|
||||
styleTypeProperty.addListener(listener);
|
||||
buttonStyleProperty.addListener(listener);
|
||||
buttonStyleProperty.get().addPropertyChangedListener(listener);
|
||||
rockerStyleProperty.addListener(listener);
|
||||
rockerStyleProperty.get().addPropertyChangedListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,7 +141,7 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
}
|
||||
|
||||
@JsonAdapter(ButtonStyle.Serializer.class)
|
||||
public static class ButtonStyle implements Cloneable {
|
||||
public static class ButtonStyle implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Button interval
|
||||
|
@ -350,7 +370,7 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
}
|
||||
|
||||
public ButtonStyle() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -369,6 +389,22 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
fillColorPressedProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButtonStyle clone() {
|
||||
ButtonStyle style = new ButtonStyle();
|
||||
|
@ -440,7 +476,7 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
}
|
||||
|
||||
@JsonAdapter(RockerStyle.Serializer.class)
|
||||
public static class RockerStyle implements Cloneable {
|
||||
public static class RockerStyle implements Cloneable, Observable {
|
||||
|
||||
/**
|
||||
* Percentage rocker size, max is 90%, min is 10%
|
||||
|
@ -601,7 +637,7 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
}
|
||||
|
||||
public RockerStyle() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -616,6 +652,22 @@ public class ControlDirectionStyle implements Cloneable {
|
|||
rockerFillColorProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RockerStyle clone() {
|
||||
RockerStyle style = new RockerStyle();
|
||||
|
|
|
@ -0,0 +1,307 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonAdapter(ControlViewGroup.Serializer.class)
|
||||
public class ControlViewGroup implements Cloneable, Observable {
|
||||
|
||||
public enum Visibility {
|
||||
VISIBLE,
|
||||
INVISIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique id
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean equals(ControlViewGroup viewGroup) {
|
||||
return viewGroup.getId().equals(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name
|
||||
*/
|
||||
private final StringProperty nameProperty = new SimpleStringProperty(this, "name", "");
|
||||
|
||||
public StringProperty nameProperty() {
|
||||
return nameProperty;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
nameProperty.set(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return nameProperty.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial visibility
|
||||
*/
|
||||
private final ObjectProperty<Visibility> visibilityProperty = new SimpleObjectProperty<>(this, "visibility", Visibility.VISIBLE);
|
||||
|
||||
public ObjectProperty<Visibility> visibilityProperty() {
|
||||
return visibilityProperty;
|
||||
}
|
||||
|
||||
public void setVisibility(Visibility visibility) {
|
||||
visibilityProperty.set(visibility);
|
||||
}
|
||||
|
||||
public Visibility getVisibility() {
|
||||
return visibilityProperty.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* View data
|
||||
*/
|
||||
private final ObjectProperty<ViewData> viewDataProperty = new SimpleObjectProperty<>(this, "viewData", new ViewData());
|
||||
|
||||
public ObjectProperty<ViewData> viewDataProperty() {
|
||||
return viewDataProperty;
|
||||
}
|
||||
|
||||
public void setViewData(ViewData viewData) {
|
||||
viewDataProperty.set(viewData);
|
||||
}
|
||||
|
||||
public ViewData getViewData() {
|
||||
return viewDataProperty.get();
|
||||
}
|
||||
|
||||
public ControlViewGroup(String id) {
|
||||
this.id = id;
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
nameProperty.addListener(listener);
|
||||
visibilityProperty.addListener(listener);
|
||||
viewDataProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControlViewGroup clone() {
|
||||
ControlViewGroup viewGroup = new ControlViewGroup(UUID.randomUUID().toString());
|
||||
viewGroup.setName(getName());
|
||||
viewGroup.setVisibility(getVisibility());
|
||||
viewGroup.setViewData(getViewData());
|
||||
return viewGroup;
|
||||
}
|
||||
|
||||
public static class Serializer implements JsonSerializer<ControlViewGroup>, JsonDeserializer<ControlViewGroup> {
|
||||
@Override
|
||||
public JsonElement serialize(ControlViewGroup src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src == null) return JsonNull.INSTANCE;
|
||||
JsonObject obj = new JsonObject();
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
obj.addProperty("id", src.getId());
|
||||
obj.addProperty("name", src.getName());
|
||||
obj.addProperty("visibility", src.getVisibility().toString());
|
||||
obj.addProperty("viewData", gson.toJson(src.getViewData()));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControlViewGroup deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json == JsonNull.INSTANCE || !(json instanceof JsonObject))
|
||||
return null;
|
||||
JsonObject obj = (JsonObject) json;
|
||||
|
||||
ControlViewGroup viewGroup = new ControlViewGroup(Optional.ofNullable(obj.get("id")).map(JsonElement::getAsString).orElse(UUID.randomUUID().toString()));
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
viewGroup.setName(Optional.ofNullable(obj.get("name")).map(JsonElement::getAsString).orElse(""));
|
||||
viewGroup.setVisibility(Optional.ofNullable(obj.get("visibility")).map(JsonElement::getAsString).orElse(Visibility.VISIBLE.toString()).equals(Visibility.INVISIBLE.toString()) ? Visibility.INVISIBLE : Visibility.VISIBLE);
|
||||
viewGroup.setViewData(gson.fromJson(Optional.ofNullable(obj.get("viewData")).map(JsonElement::getAsString).orElse(gson.toJson(new ViewData())), ViewData.class));
|
||||
|
||||
return viewGroup;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonAdapter(ViewData.Serializer.class)
|
||||
public static class ViewData implements Cloneable {
|
||||
|
||||
/**
|
||||
* Button data list
|
||||
*/
|
||||
private final ObjectProperty<ArrayList<ControlButtonData>> buttonListProperty = new SimpleObjectProperty<>(this, "buttonList", new ArrayList<>());
|
||||
|
||||
public ObjectProperty<ArrayList<ControlButtonData>> buttonListProperty() {
|
||||
return buttonListProperty;
|
||||
}
|
||||
|
||||
public void setButtonList(ArrayList<ControlButtonData> buttonList) {
|
||||
buttonListProperty.set(buttonList);
|
||||
}
|
||||
|
||||
public ArrayList<ControlButtonData> getButtonList() {
|
||||
return buttonListProperty.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Direction data list
|
||||
*/
|
||||
private final ObjectProperty<ArrayList<ControlDirectionData>> directionListProperty = new SimpleObjectProperty<>(this, "directionList", new ArrayList<>());
|
||||
|
||||
public ObjectProperty<ArrayList<ControlDirectionData>> directionListProperty() {
|
||||
return directionListProperty;
|
||||
}
|
||||
|
||||
public void setDirectionList(ArrayList<ControlDirectionData> directionList) {
|
||||
directionListProperty.set(directionList);
|
||||
}
|
||||
|
||||
public ArrayList<ControlDirectionData> getDirectionList() {
|
||||
return directionListProperty.get();
|
||||
}
|
||||
|
||||
public void addButton(ControlButtonData data) {
|
||||
ArrayList<ControlButtonData> list = getButtonList();
|
||||
boolean exist = false;
|
||||
for (ControlButtonData buttonData : list) {
|
||||
if (buttonData.equals(data)) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
list.add(data);
|
||||
setButtonList(list);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeButton(ControlButtonData data) {
|
||||
ArrayList<ControlButtonData> list = getButtonList();
|
||||
for (ControlButtonData buttonData : list) {
|
||||
if (buttonData.equals(data)) {
|
||||
list.remove(buttonData);
|
||||
setButtonList(list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addDirection(ControlDirectionData data) {
|
||||
ArrayList<ControlDirectionData> list = getDirectionList();
|
||||
boolean exist = false;
|
||||
for (ControlDirectionData directionData : list) {
|
||||
if (directionData.equals(data)) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
list.add(data);
|
||||
setDirectionList(list);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDirection(ControlDirectionData data) {
|
||||
ArrayList<ControlDirectionData> list = getDirectionList();
|
||||
for (ControlDirectionData directionData : list) {
|
||||
if (directionData.equals(data)) {
|
||||
list.remove(directionData);
|
||||
setDirectionList(list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ViewData() {
|
||||
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
buttonListProperty.addListener(listener);
|
||||
directionListProperty.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewData clone() {
|
||||
ViewData data = new ViewData();
|
||||
data.setButtonList(getButtonList());
|
||||
data.setDirectionList(getDirectionList());
|
||||
return data;
|
||||
}
|
||||
|
||||
public static class Serializer implements JsonSerializer<ViewData>, JsonDeserializer<ViewData> {
|
||||
@Override
|
||||
public JsonElement serialize(ViewData src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src == null) return JsonNull.INSTANCE;
|
||||
JsonObject obj = new JsonObject();
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
obj.addProperty("buttonList", gson.toJson(src.getButtonList()));
|
||||
obj.addProperty("directionList", gson.toJson(src.getDirectionList()));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json == JsonNull.INSTANCE || !(json instanceof JsonObject))
|
||||
return null;
|
||||
JsonObject obj = (JsonObject) json;
|
||||
|
||||
ViewData data = new ViewData();
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
data.setButtonList(gson.fromJson(Optional.ofNullable(obj.get("buttonList")).map(JsonElement::getAsString).orElse(gson.toJson(new ArrayList<>())), new TypeToken<String>(){}.getType()));
|
||||
data.setDirectionList(gson.fromJson(Optional.ofNullable(obj.get("directionList")).map(JsonElement::getAsString).orElse(gson.toJson(new ArrayList<>())), new TypeToken<String>(){}.getType()));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.tungsten.fcl.control.data;
|
||||
|
||||
import static com.tungsten.fcl.util.FXUtils.onInvalidating;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
|
@ -11,18 +13,20 @@ import com.google.gson.JsonSerializer;
|
|||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fclauncher.FCLKeycodes;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleBooleanProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.util.fakefx.ObservableHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonAdapter(DirectionEventData.Serializer.class)
|
||||
public class DirectionEventData implements Cloneable {
|
||||
public class DirectionEventData implements Cloneable, Observable {
|
||||
|
||||
public enum FollowOption {
|
||||
FIX,
|
||||
|
@ -154,7 +158,7 @@ public class DirectionEventData implements Cloneable {
|
|||
}
|
||||
|
||||
public DirectionEventData() {
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addPropertyChangedListener(InvalidationListener listener) {
|
||||
|
@ -167,6 +171,22 @@ public class DirectionEventData implements Cloneable {
|
|||
sneakKeycodeProperty.addListener(listener);
|
||||
}
|
||||
|
||||
private ObservableHelper observableHelper = new ObservableHelper(this);
|
||||
|
||||
@Override
|
||||
public void addListener(InvalidationListener listener) {
|
||||
observableHelper.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InvalidationListener listener) {
|
||||
observableHelper.removeListener(listener);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
observableHelper.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectionEventData clone() {
|
||||
DirectionEventData data = new DirectionEventData();
|
||||
|
|
|
@ -14,13 +14,16 @@ import com.google.gson.JsonParseException;
|
|||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.tungsten.fcl.control.data.ControlViewGroup;
|
||||
import com.tungsten.fcl.util.Constants;
|
||||
import com.tungsten.fclauncher.FCLPath;
|
||||
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
|
||||
import com.tungsten.fclcore.fakefx.beans.Observable;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.IntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.ReadOnlyIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleIntegerProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleObjectProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.SimpleStringProperty;
|
||||
import com.tungsten.fclcore.fakefx.beans.property.StringProperty;
|
||||
import com.tungsten.fclcore.util.ToStringBuilder;
|
||||
|
@ -31,6 +34,7 @@ import com.tungsten.fclcore.util.io.FileUtils;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonAdapter(Controller.Serializer.class)
|
||||
|
@ -102,6 +106,20 @@ public class Controller implements Observable {
|
|||
return controllerVersion.get();
|
||||
}
|
||||
|
||||
private final SimpleObjectProperty<ArrayList<ControlViewGroup>> viewGroups;
|
||||
|
||||
public ObjectProperty<ArrayList<ControlViewGroup>> viewGroupsProperty() {
|
||||
return viewGroups;
|
||||
}
|
||||
|
||||
public ArrayList<ControlViewGroup> getViewGroups() {
|
||||
return viewGroups.get();
|
||||
}
|
||||
|
||||
public void setViewGroups(ArrayList<ControlViewGroup> viewGroups) {
|
||||
this.viewGroups.set(viewGroups);
|
||||
}
|
||||
|
||||
public Controller(String name) {
|
||||
this(name, "");
|
||||
}
|
||||
|
@ -119,16 +137,47 @@ public class Controller implements Observable {
|
|||
}
|
||||
|
||||
public Controller(String name, String version, String author, String description, int controllerVersion) {
|
||||
this(name, version, author, description, controllerVersion, new ArrayList<>());
|
||||
}
|
||||
|
||||
public Controller(String name, String version, String author, String description, int controllerVersion, ArrayList<ControlViewGroup> viewGroups) {
|
||||
this.name = new SimpleStringProperty(this, "name", name);
|
||||
this.version = new SimpleStringProperty(this, "version", version);
|
||||
this.author = new SimpleStringProperty(this, "author", author);
|
||||
this.description = new SimpleStringProperty(this, "description", description);
|
||||
this.viewGroups = new SimpleObjectProperty<>(this, "viewGroups", viewGroups);
|
||||
|
||||
this.controllerVersion.set(controllerVersion);
|
||||
|
||||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public void addViewGroup(ControlViewGroup viewGroup) {
|
||||
ArrayList<ControlViewGroup> list = getViewGroups();
|
||||
boolean exist = false;
|
||||
for (ControlViewGroup group : list) {
|
||||
if (viewGroup.getId().equals(group.getId())) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
list.add(viewGroup);
|
||||
setViewGroups(list);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeViewGroup(ControlViewGroup viewGroup) {
|
||||
ArrayList<ControlViewGroup> list = getViewGroups();
|
||||
for (ControlViewGroup group : list) {
|
||||
if (viewGroup.getId().equals(group.getId())) {
|
||||
list.remove(group);
|
||||
setViewGroups(list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -146,6 +195,7 @@ public class Controller implements Observable {
|
|||
version.addListener(listener);
|
||||
author.addListener(listener);
|
||||
description.addListener(listener);
|
||||
viewGroups.addListener(listener);
|
||||
controllerVersion.addListener(listener);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue