refactor(renderer): add lastCaptionUpdateTime tracking to G2DDrawControl and G2DTextfieldControlImpl2

This commit is contained in:
extio-de
2026-01-12 21:07:13 +01:00
parent 59c81f86c3
commit 9821926e36
2 changed files with 21 additions and 5 deletions

View File

@@ -43,6 +43,8 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
private String caption; private String caption;
private long lastCaptionUpdateTime;
private String controlGroup; private String controlGroup;
private int fontSize = G2DDrawFont.FONT_SIZE_DEFAULT; private int fontSize = G2DDrawFont.FONT_SIZE_DEFAULT;
@@ -96,6 +98,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
@Override @Override
public ControlRenderingBo setCaption(final String caption) { public ControlRenderingBo setCaption(final String caption) {
this.caption = caption; this.caption = caption;
this.lastCaptionUpdateTime = System.currentTimeMillis();
return this; return this;
} }
@@ -336,6 +339,9 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
} }
else if (this.clazz == TextfieldControl.class && this.textfieldData != null) { else if (this.clazz == TextfieldControl.class && this.textfieldData != null) {
((TextfieldControl) control).setCustomData(this.textfieldData); ((TextfieldControl) control).setCustomData(this.textfieldData);
if (control instanceof final G2DTextfieldControlImpl2 tfc2) {
tfc2.setLastCaptionUpdateTime(this.lastCaptionUpdateTime);
}
} }
else { else {
for (final var customControlConfiguration : this.customControlConfigurations) { for (final var customControlConfiguration : this.customControlConfigurations) {
@@ -355,6 +361,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.id = o.id; this.id = o.id;
this.clazz = o.clazz; this.clazz = o.clazz;
this.caption = o.caption; this.caption = o.caption;
this.lastCaptionUpdateTime = o.lastCaptionUpdateTime;
this.controlGroup = o.controlGroup; this.controlGroup = o.controlGroup;
this.fontSize = o.fontSize; this.fontSize = o.fontSize;
this.labelData = o.labelData; this.labelData = o.labelData;
@@ -384,6 +391,7 @@ public class G2DDrawControl extends G2DAbstractRenderingBo implements ControlRen
this.id = null; this.id = null;
this.clazz = null; this.clazz = null;
this.caption = null; this.caption = null;
this.lastCaptionUpdateTime = 0L;
this.controlGroup = null; this.controlGroup = null;
this.fontSize = G2DDrawFont.FONT_SIZE_DEFAULT; this.fontSize = G2DDrawFont.FONT_SIZE_DEFAULT;
this.labelData = null; this.labelData = null;

View File

@@ -35,6 +35,10 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
private String lastCaption = ""; private String lastCaption = "";
private long lastCaptionUpdateTime;
private long lastCaptionUpdateTimeInternal;
private String lastText = ""; private String lastText = "";
protected RgbaColor backgroundColor; protected RgbaColor backgroundColor;
@@ -82,9 +86,6 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
if (this.multiLine) { if (this.multiLine) {
this.modified |= caption != null && !caption.equals(this.caption); this.modified |= caption != null && !caption.equals(this.caption);
} }
else {
this.modified |= caption != null && (!caption.equals(this.caption) || !caption.equals(this.textComponent.getText()));
}
if (caption != null) { if (caption != null) {
this.lastCaption = caption; this.lastCaption = caption;
} }
@@ -92,6 +93,13 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
return this; return this;
} }
public void setLastCaptionUpdateTime(final long lastCaptionUpdateTime) {
if (! this.multiLine) {
this.modified |= this.lastCaptionUpdateTime != lastCaptionUpdateTime;
}
this.lastCaptionUpdateTime = lastCaptionUpdateTime;
}
@Override @Override
public void build() { public void build() {
super.build(); super.build();
@@ -301,7 +309,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
} }
} }
else { else {
if (this.caption != null && !this.textComponent.getText().equals(this.caption)) { if (this.caption != null && !this.textComponent.getText().equals(this.caption) && (this.lastCaptionUpdateTimeInternal == 0L || this.lastCaptionUpdateTimeInternal < this.lastCaptionUpdateTime)) {
final var pos = this.textComponent.getCaretPosition(); final var pos = this.textComponent.getCaretPosition();
this.safeInvoke(() -> this.textComponent.setText(this.caption)); this.safeInvoke(() -> this.textComponent.setText(this.caption));
if (pos < this.textComponent.getText().length()) { if (pos < this.textComponent.getText().length()) {
@@ -309,6 +317,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
} }
this.lastText = this.caption; this.lastText = this.caption;
this.lastCaptionUpdateTimeInternal = this.lastCaptionUpdateTime;
} }
} }
} }
@@ -382,5 +391,4 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text
this.scrollbar.setControlId(id + "_scroll"); this.scrollbar.setControlId(id + "_scroll");
return super.setControlId(id); return super.setControlId(id);
} }
} }