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
|
* 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;
|
public int weight = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new constraints object with the specified
|
* Constructs a new constraints object with the specified weight,
|
||||||
* fixedness and weight.
|
* which is only applicable with the STRETCH policy.
|
||||||
*/
|
|
||||||
public Constraints (boolean fixed)
|
|
||||||
{
|
|
||||||
this.fixed = fixed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new constraints object with the specified
|
|
||||||
* fixedness and weight.
|
|
||||||
*/
|
*/
|
||||||
public Constraints (int weight)
|
public Constraints (int weight)
|
||||||
{
|
{
|
||||||
this.weight = 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. */
|
/** A class used to make our policy constants type-safe. */
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ public class HGroupLayout extends GroupLayout
|
|||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
if (freecount > 0) {
|
if (freecount > 0) {
|
||||||
int freewid = b.width - info.fixwid - totgap;
|
int freewid = b.width - info.fixwid - totgap;
|
||||||
defwid = freewid / freecount;
|
defwid = freewid / info.totweight;
|
||||||
freefrac = freewid % freecount;
|
freefrac = freewid % info.totweight;
|
||||||
totwid = b.width;
|
totwid = b.width;
|
||||||
} else {
|
} else {
|
||||||
totwid = info.fixwid + totgap;
|
totwid = info.fixwid + totgap;
|
||||||
@@ -150,7 +150,11 @@ public class HGroupLayout extends GroupLayout
|
|||||||
if (_policy == NONE || isFixed(child)) {
|
if (_policy == NONE || isFixed(child)) {
|
||||||
newwid = info.dimens[i].width;
|
newwid = info.dimens[i].width;
|
||||||
} else {
|
} 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
|
// clear out the extra pixels the first time they're used
|
||||||
freefrac = 0;
|
freefrac = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ public class VGroupLayout extends GroupLayout
|
|||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
if (freecount > 0) {
|
if (freecount > 0) {
|
||||||
int freehei = b.height - info.fixhei - totgap;
|
int freehei = b.height - info.fixhei - totgap;
|
||||||
defhei = freehei / freecount;
|
defhei = freehei / info.totweight;
|
||||||
freefrac = freehei % freecount;
|
freefrac = freehei % info.totweight;
|
||||||
tothei = b.height;
|
tothei = b.height;
|
||||||
} else {
|
} else {
|
||||||
tothei = info.fixhei + totgap;
|
tothei = info.fixhei + totgap;
|
||||||
@@ -150,7 +150,11 @@ public class VGroupLayout extends GroupLayout
|
|||||||
if (_policy == NONE || isFixed(child)) {
|
if (_policy == NONE || isFixed(child)) {
|
||||||
newhei = info.dimens[i].height;
|
newhei = info.dimens[i].height;
|
||||||
} else {
|
} 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
|
// clear out the extra pixels the first time they're used
|
||||||
freefrac = 0;
|
freefrac = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user