From 775310f1a36b1e50f7fa794c83de9aa11c29c03f Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 9 Sep 2005 22:39:12 +0000 Subject: [PATCH] Actually wired up the weights of Constraints. They are only used if the layout policy is STRETCH. It would probably also make sense to make them work with EQUALIZE, but that would require a few more changes. (If the maximum width component had a weight of 2 you could set the baseline width to half that.) git-svn-id: https://samskivert.googlecode.com/svn/trunk@1713 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/GroupLayout.java | 23 +++++++++---------- .../com/samskivert/swing/HGroupLayout.java | 10 +++++--- .../com/samskivert/swing/VGroupLayout.java | 10 +++++--- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java index 2db5d704..cf071e41 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java @@ -51,27 +51,26 @@ public abstract class GroupLayout /** * The weight of this component relative to the other components - * in the container. + * in the container. Only valid if the layout policy is STRETCH. */ public int weight = 1; /** - * Constructs a new constraints object with the specified - * fixedness and weight. - */ - public Constraints (boolean fixed) - { - this.fixed = fixed; - } - - /** - * Constructs a new constraints object with the specified - * fixedness and weight. + * Constructs a new constraints object with the specified weight, + * which is only applicable with the STRETCH policy. */ public Constraints (int weight) { this.weight = weight; } + + /** + * This constructor is not public, use the FIXED constant. + */ + protected Constraints (boolean fixed) + { + this.fixed = fixed; + } } /** A class used to make our policy constants type-safe. */ diff --git a/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java index 9c484dc4..76ac8df0 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java @@ -105,8 +105,8 @@ public class HGroupLayout extends GroupLayout if (_policy == STRETCH) { if (freecount > 0) { int freewid = b.width - info.fixwid - totgap; - defwid = freewid / freecount; - freefrac = freewid % freecount; + defwid = freewid / info.totweight; + freefrac = freewid % info.totweight; totwid = b.width; } else { totwid = info.fixwid + totgap; @@ -150,7 +150,11 @@ public class HGroupLayout extends GroupLayout if (_policy == NONE || isFixed(child)) { newwid = info.dimens[i].width; } else { - newwid = defwid + freefrac; + int wid = defwid; + if (_policy == STRETCH) { + wid *= getWeight(child); + } + newwid = wid + freefrac; // clear out the extra pixels the first time they're used freefrac = 0; } diff --git a/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java index 35bee6ae..f23c4431 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java @@ -105,8 +105,8 @@ public class VGroupLayout extends GroupLayout if (_policy == STRETCH) { if (freecount > 0) { int freehei = b.height - info.fixhei - totgap; - defhei = freehei / freecount; - freefrac = freehei % freecount; + defhei = freehei / info.totweight; + freefrac = freehei % info.totweight; tothei = b.height; } else { tothei = info.fixhei + totgap; @@ -150,7 +150,11 @@ public class VGroupLayout extends GroupLayout if (_policy == NONE || isFixed(child)) { newhei = info.dimens[i].height; } else { - newhei = defhei + freefrac; + int hei = defhei; + if (_policy == STRETCH) { + hei *= getWeight(child); + } + newhei = hei + freefrac; // clear out the extra pixels the first time they're used freefrac = 0; }