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 setLastControlDataUpdateTime(T controlImpl, long time);
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
|
||||
|
||||
private Object customData;
|
||||
|
||||
private long lastControlDataUpdateTime;
|
||||
|
||||
private boolean visible;
|
||||
|
||||
private boolean enabled = true;
|
||||
@@ -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
|
||||
|
||||
@@ -61,6 +61,8 @@ public abstract class CustomAbstractButton extends Component {
|
||||
|
||||
protected CoordI2 lastMousePosition;
|
||||
|
||||
protected long lastControlDataUpdateTime;
|
||||
|
||||
public void setCaption(final String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
@@ -114,6 +116,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);
|
||||
this.setBackground(Color.BLACK);
|
||||
|
||||
@@ -14,14 +14,20 @@ public abstract class G2DAbstractToggleButtonControlImpl extends G2DButtonContro
|
||||
|
||||
protected void applyToggleButtonData(final ToggleButtonData data) {
|
||||
if (data != null) {
|
||||
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) {
|
||||
if (this.lastControlDataUpdateTimeInternal < this.lastControlDataUpdateTime) {
|
||||
this.setToggled(data.toggled());
|
||||
this.lastControlDataUpdateTimeInternal = this.lastControlDataUpdateTime;
|
||||
}
|
||||
this.setIconResource(data.iconResource());
|
||||
this.setDrawBorder(data.drawBorder());
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,6 +118,8 @@ public interface ControlRenderingBo extends RenderingBoHasDimension {
|
||||
|
||||
void setCustomData(ButtonData data);
|
||||
|
||||
void setLastControlDataUpdateTime(long time);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user