feat(renderer): add last control data update time tracking to various control implementations

This commit is contained in:
extio-de
2026-01-28 22:16:13 +01:00
parent bb4d8ffd61
commit e9ec0009c2
8 changed files with 40 additions and 4 deletions

View File

@@ -9,5 +9,7 @@ public interface CustomControlConfiguration<T extends G2DBaseControlImpl> {
T createControl();
void setCustomData(T controlImpl, Object data);
void setLastControlDataUpdateTime(T controlImpl, long time);
}

View File

@@ -76,6 +76,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
private SetFocusData setFocusData;
private Object customData;
private long lastControlDataUpdateTime;
private boolean visible;
@@ -122,6 +124,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
@Override
public ControlRenderingBo setControlData(final Object data) {
this.lastControlDataUpdateTime = System.currentTimeMillis();
if (data instanceof final LabelData labelData) {
this.labelData = labelData;
}
@@ -332,12 +335,15 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
((LabelControl) control).setCustomData(this.labelData);
}
else if (this.clazz == ToggleButtonControl.class && this.toggleButtonData != null) {
((ToggleButtonControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
((ToggleButtonControl) control).setCustomData(this.toggleButtonData);
}
else if (this.clazz == SwitchControl.class && this.switchData != null) {
((SwitchControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
((SwitchControl) control).setCustomData(this.switchData);
}
else if (this.clazz == ButtonControl.class && this.buttonData != null) {
((ButtonControl) control).setLastControlDataUpdateTime(this.lastControlDataUpdateTime);
((ButtonControl) control).setCustomData(this.buttonData);
}
else if (this.clazz == WindowCloseButtonControl.class && this.windowCloseButtonData != null) {
@@ -373,6 +379,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
else {
for (final var customControlConfiguration : this.customControlConfigurations) {
if (customControlConfiguration.getControlClass().equals(this.clazz)) {
((CustomControlConfiguration) customControlConfiguration).setLastControlDataUpdateTime(control, this.lastControlDataUpdateTime);
((CustomControlConfiguration) customControlConfiguration).setCustomData(control, this.customData);
break;
}
@@ -410,6 +417,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.visibleArea = o.visibleArea;
this.controlArea = o.controlArea;
this.customControlConfigurations = o.customControlConfigurations;
this.lastControlDataUpdateTime = o.lastControlDataUpdateTime;
}
}
@@ -442,6 +450,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.visibleArea = null;
this.controlArea = null;
this.customControlConfigurations = null;
this.lastControlDataUpdateTime = 0L;
}
@Override

View File

@@ -60,6 +60,8 @@ public abstract class CustomAbstractButton extends Component {
protected StaticResourceService staticResourceService;
protected CoordI2 lastMousePosition;
protected long lastControlDataUpdateTime;
public void setCaption(final String caption) {
this.caption = caption;
@@ -113,6 +115,10 @@ public abstract class CustomAbstractButton extends Component {
}
super.setEnabled(b);
}
public void setLastControlDataUpdateTime(final long time) {
this.lastControlDataUpdateTime = time;
}
public CustomAbstractButton(final boolean toggle, final ActionListener listener) {
this.setIgnoreRepaint(true);

View File

@@ -14,14 +14,20 @@ public abstract class G2DAbstractToggleButtonControlImpl extends G2DButtonContro
protected void applyToggleButtonData(final ToggleButtonData data) {
if (data != null) {
this.setToggled(data.toggled());
if (this.lastControlDataUpdateTimeInternal < this.lastControlDataUpdateTime) {
this.setToggled(data.toggled());
this.lastControlDataUpdateTimeInternal = this.lastControlDataUpdateTime;
}
this.setIconResource(data.iconResource());
}
}
protected void applySwitchData(final SwitchData data) {
if (data != null) {
this.setToggled(data.toggled());
if (this.lastControlDataUpdateTimeInternal < this.lastControlDataUpdateTime) {
this.setToggled(data.toggled());
this.lastControlDataUpdateTimeInternal = this.lastControlDataUpdateTime;
}
this.setIconResource(data.iconResource());
this.setDrawBorder(data.drawBorder());
}

View File

@@ -18,7 +18,11 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo
protected StaticResource iconResource;
private RgbaColor backgroundColor;
protected RgbaColor backgroundColor;
protected long lastControlDataUpdateTime;
protected long lastControlDataUpdateTimeInternal;
@Override
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
public void build() {
super.build();
@@ -110,5 +119,5 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo
this.modified |= !Objects.equals(this.backgroundColor, backgroundColor);
this.backgroundColor = backgroundColor;
}
}

View File

@@ -21,6 +21,7 @@ public class G2DSwitchControlImpl extends G2DAbstractToggleButtonControlImpl {
protected void createControl() {
this.control = new CustomSwitch(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
this.control.setName(this.id);
this.lastControlDataUpdateTimeInternal = 0;
}
@Override

View File

@@ -21,6 +21,7 @@ public class G2DToggleButtonControlImpl extends G2DAbstractToggleButtonControlIm
protected void createControl() {
this.control = new CustomButton(true, event -> this.performAction(), (G2DThemeManager) this.rendererData.getThemeManager());
this.control.setName(this.id);
this.lastControlDataUpdateTimeInternal = 0;
}
}

View File

@@ -117,6 +117,8 @@ public interface ControlRenderingBo extends RenderingBoHasDimension {
public static interface ButtonControl extends BaseControl {
void setCustomData(ButtonData data);
void setLastControlDataUpdateTime(long time);
}