/*
 * $Source: c:\\cvshome/website/explicit_2_0/ContainerFractionDemo.java,v $
 * $Revision: 1.1 $
 * $Date: 2001/08/08 12:18:56 $
 *
 * Copyright (c) 2001 Zooki Technologies. All rights reserved.
 *
 */
package com.zookitec.layout.demo;

import java.awt.*;
import java.awt.event.*;
import com.zookitec.layout.*;

/**
 * Demonstrates how to set component widths equal to a fraction of
 * the container's width.
 */
public class ContainerFractionDemo extends Container {

    private DemoLabel label1 = new DemoLabel("1 (0.5)");
    private DemoLabel label2 = new DemoLabel("2 (0.3)");
    private DemoLabel label3 = new DemoLabel("3 (fill)");

    private ExplicitLayout layout = new ExplicitLayout();

    public ContainerFractionDemo() {
        ExplicitConstraints ec;
        ExplicitConstraints defaultConstrains = new ExplicitConstraints();

        defaultConstrains.setY(ContainerEF.top());
        defaultConstrains.setHeight(ContainerEF.height());

        setLayout(layout);

        //Add label 1 to the left of the container and set ist width equal to
        //0.5 * the container's width.
        ec = new ExplicitConstraints(label1, defaultConstrains);
        ec.setX(ContainerEF.left());
        ec.setWidth(ContainerEF.widthFraction(0.5));
        add(label1, ec);

        //Add label 2 adjacent to label 1 and set its width equal to
        //0.3 * the container's width.
        ec = new ExplicitConstraints(label2, defaultConstrains);
        ec.setX(ComponentEF.right(label1));
        ec.setWidth(ContainerEF.widthFraction(0.3));
        add(label2, ec);

        //Add label 3 adjacent to label 2 and set its width to fill
        //the remaining space in the container.
        ec = new ExplicitConstraints(label3, defaultConstrains);
        ec.setX(ComponentEF.right(label2));
        ec.setWidth(ContainerEF.right().subtract(ComponentEF.right(label2)));
        add(label3, ec);
    }
}


