summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-09 15:21:21 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-09 15:21:21 +0200
commit43948381eee2eafae4865a087d87a898c4a9b97d (patch)
tree8f06c6aceeec537e1bf53c0f28fef87a21802465 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils
parent8736033b6460b2f88b22d85fe01276c3cee68235 (diff)
downloadpdf-over-43948381eee2eafae4865a087d87a898c4a9b97d.tar.gz
pdf-over-43948381eee2eafae4865a087d87a898c4a9b97d.tar.bz2
pdf-over-43948381eee2eafae4865a087d87a898c4a9b97d.zip
remove need to call AnchorSetter::set
(in SWTUtils)
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java
index a95cd7f5..980710e3 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java
@@ -78,18 +78,24 @@ public final class SWTUtils {
public static class AnchorSetter {
private final Control c;
- private final FormData fd = new FormData();
- private boolean didSet = false;
- private AnchorSetter(Control c) { this.c = c; }
-
- @Override
- protected void finalize() {
- if (!didSet)
- log.warn("AnchorSetter: you did not call set()!");
+ private final FormData fd;
+ private AnchorSetter(Control c, boolean isNew)
+ {
+ this.c = c;
+ if (isNew) {
+ this.fd = new FormData();
+ this.c.setLayoutData(this.fd);
+ } else {
+ Object layoutData = this.c.getLayoutData();
+ try {
+ this.fd = (FormData)layoutData;
+ } catch (ClassCastException e) {
+ log.error("Tried to reanchor() object with layout data of type {} (not FormData)", layoutData.getClass().getSimpleName(), e);
+ throw new RuntimeException("Invalid reanchor() use");
+ }
+ }
}
- public void set() { this.c.setLayoutData(this.fd); didSet = true; }
-
public AnchorSetter height(int h) { fd.height = h; return this; }
public AnchorSetter width(int w) { fd.width = w; return this; }
@@ -122,7 +128,8 @@ public final class SWTUtils {
public AnchorSetter bottom(int num, int offset) { return bottom(new FormAttachment(num, offset)); }
public AnchorSetter bottom(int num) { return bottom(new FormAttachment(num)); }
}
- public static AnchorSetter anchor(Control c) { return new AnchorSetter(c); }
+ public static AnchorSetter anchor(Control c) { return new AnchorSetter(c, true); }
+ public static AnchorSetter reanchor(Control c) { return new AnchorSetter(c, false); }
/**
* functional-interface wrapper around swtObj.addSelectionListener