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
This commit is contained in:
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user