feat(renderer): add last control data update time tracking to various control implementations
This commit is contained in:
@@ -10,4 +10,6 @@ public interface CustomControlConfiguration<T extends G2DBaseControlImpl> {
|
|||||||
|
|
||||||
void setCustomData(T controlImpl, Object data);
|
void setCustomData(T controlImpl, Object data);
|
||||||
|
|
||||||
|
void setLastControlDataUpdateTime(T controlImpl, long time);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
|
|
||||||
private Object customData;
|
private Object customData;
|
||||||
|
|
||||||
|
private long lastControlDataUpdateTime;
|
||||||
|
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
|
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
@@ -122,6 +124,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ControlRenderingBo setControlData(final Object data) {
|
public ControlRenderingBo setControlData(final Object data) {
|
||||||
|
this.lastControlDataUpdateTime = System.currentTimeMillis();
|
||||||
if (data instanceof final LabelData labelData) {
|
if (data instanceof final LabelData labelData) {
|
||||||
this.labelData = labelData;
|
this.labelData = labelData;
|
||||||
}
|
}
|
||||||
@@ -332,12 +335,15 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
((LabelControl) control).setCustomData(this.labelData);
|
((LabelControl) control).setCustomData(this.labelData);
|
||||||
}
|
}
|
||||||
else if (this.clazz == ToggleButtonControl.class && this.toggleButtonData != null) {
|
else if (this.clazz == ToggleButtonControl.class && this.toggleButtonData != null) {
|
||||||
|
((ToggleButtonControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
|
||||||
((ToggleButtonControl) control).setCustomData(this.toggleButtonData);
|
((ToggleButtonControl) control).setCustomData(this.toggleButtonData);
|
||||||
}
|
}
|
||||||
else if (this.clazz == SwitchControl.class && this.switchData != null) {
|
else if (this.clazz == SwitchControl.class && this.switchData != null) {
|
||||||
|
((SwitchControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
|
||||||
((SwitchControl) control).setCustomData(this.switchData);
|
((SwitchControl) control).setCustomData(this.switchData);
|
||||||
}
|
}
|
||||||
else if (this.clazz == ButtonControl.class && this.buttonData != null) {
|
else if (this.clazz == ButtonControl.class && this.buttonData != null) {
|
||||||
|
((ButtonControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
|
||||||
((ButtonControl) control).setCustomData(this.buttonData);
|
((ButtonControl) control).setCustomData(this.buttonData);
|
||||||
}
|
}
|
||||||
else if (this.clazz == WindowCloseButtonControl.class && this.windowCloseButtonData != null) {
|
else if (this.clazz == WindowCloseButtonControl.class && this.windowCloseButtonData != null) {
|
||||||
@@ -373,6 +379,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
else {
|
else {
|
||||||
for (final var customControlConfiguration : this.customControlConfigurations) {
|
for (final var customControlConfiguration : this.customControlConfigurations) {
|
||||||
if (customControlConfiguration.getControlClass().equals(this.clazz)) {
|
if (customControlConfiguration.getControlClass().equals(this.clazz)) {
|
||||||
|
((CustomControlConfiguration) customControlConfiguration).setLastControlDataUpdateTime(control, this.lastControlDataUpdateTime);
|
||||||
((CustomControlConfiguration) customControlConfiguration).setCustomData(control, this.customData);
|
((CustomControlConfiguration) customControlConfiguration).setCustomData(control, this.customData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -410,6 +417,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
this.visibleArea = o.visibleArea;
|
this.visibleArea = o.visibleArea;
|
||||||
this.controlArea = o.controlArea;
|
this.controlArea = o.controlArea;
|
||||||
this.customControlConfigurations = o.customControlConfigurations;
|
this.customControlConfigurations = o.customControlConfigurations;
|
||||||
|
this.lastControlDataUpdateTime = o.lastControlDataUpdateTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +450,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
|||||||
this.visibleArea = null;
|
this.visibleArea = null;
|
||||||
this.controlArea = null;
|
this.controlArea = null;
|
||||||
this.customControlConfigurations = null;
|
this.customControlConfigurations = null;
|
||||||
|
this.lastControlDataUpdateTime = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ public abstract class CustomAbstractButton extends Component {
|
|||||||
|
|
||||||
protected CoordI2 lastMousePosition;
|
protected CoordI2 lastMousePosition;
|
||||||
|
|
||||||
|
protected long lastControlDataUpdateTime;
|
||||||
|
|
||||||
public void setCaption(final String caption) {
|
public void setCaption(final String caption) {
|
||||||
this.caption = caption;
|
this.caption = caption;
|
||||||
}
|
}
|
||||||
@@ -114,6 +116,10 @@ public abstract class CustomAbstractButton extends Component {
|
|||||||
super.setEnabled(b);
|
super.setEnabled(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastControlDataUpdateTime(final long time) {
|
||||||
|
this.lastControlDataUpdateTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public CustomAbstractButton(final boolean toggle, final ActionListener listener) {
|
public CustomAbstractButton(final boolean toggle, final ActionListener listener) {
|
||||||
this.setIgnoreRepaint(true);
|
this.setIgnoreRepaint(true);
|
||||||
this.setBackground(Color.BLACK);
|
this.setBackground(Color.BLACK);
|
||||||
|
|||||||
@@ -14,14 +14,20 @@ public abstract class G2DAbstractToggleButtonControlImpl extends G2DButtonContro
|
|||||||
|
|
||||||
protected void applyToggleButtonData(final ToggleButtonData data) {
|
protected void applyToggleButtonData(final ToggleButtonData data) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
if (this.lastControlDataUpdateTimeInternal < this.lastControlDataUpdateTime) {
|
||||||
this.setToggled(data.toggled());
|
this.setToggled(data.toggled());
|
||||||
|
this.lastControlDataUpdateTimeInternal = this.lastControlDataUpdateTime;
|
||||||
|
}
|
||||||
this.setIconResource(data.iconResource());
|
this.setIconResource(data.iconResource());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void applySwitchData(final SwitchData data) {
|
protected void applySwitchData(final SwitchData data) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
if (this.lastControlDataUpdateTimeInternal < this.lastControlDataUpdateTime) {
|
||||||
this.setToggled(data.toggled());
|
this.setToggled(data.toggled());
|
||||||
|
this.lastControlDataUpdateTimeInternal = this.lastControlDataUpdateTime;
|
||||||
|
}
|
||||||
this.setIconResource(data.iconResource());
|
this.setIconResource(data.iconResource());
|
||||||
this.setDrawBorder(data.drawBorder());
|
this.setDrawBorder(data.drawBorder());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo
|
|||||||
|
|
||||||
protected StaticResource iconResource;
|
protected StaticResource iconResource;
|
||||||
|
|
||||||
private RgbaColor backgroundColor;
|
protected RgbaColor backgroundColor;
|
||||||
|
|
||||||
|
protected long lastControlDataUpdateTime;
|
||||||
|
|
||||||
|
protected long lastControlDataUpdateTimeInternal;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCustomData(final ButtonData data) {
|
public void setCustomData(final ButtonData data) {
|
||||||
@@ -28,6 +32,11 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLastControlDataUpdateTime(final long time) {
|
||||||
|
this.lastControlDataUpdateTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() {
|
public void build() {
|
||||||
super.build();
|
super.build();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class G2DSwitchControlImpl extends G2DAbstractToggleButtonControlImpl {
|
|||||||
protected void createControl() {
|
protected void createControl() {
|
||||||
this.control = new CustomSwitch(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
|
this.control = new CustomSwitch(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
|
||||||
this.control.setName(this.id);
|
this.control.setName(this.id);
|
||||||
|
this.lastControlDataUpdateTimeInternal = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class G2DToggleButtonControlImpl extends G2DAbstractToggleButtonControlIm
|
|||||||
protected void createControl() {
|
protected void createControl() {
|
||||||
this.control = new CustomButton(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
|
this.control = new CustomButton(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
|
||||||
this.control.setName(this.id);
|
this.control.setName(this.id);
|
||||||
|
this.lastControlDataUpdateTimeInternal = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ public interface ControlRenderingBo extends RenderingBoHasDimension {
|
|||||||
|
|
||||||
void setCustomData(ButtonData data);
|
void setCustomData(ButtonData data);
|
||||||
|
|
||||||
|
void setLastControlDataUpdateTime(long time);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user