/*
 * $Source: c:\\cvshome/website/explicit_2_0/AlignDemo.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 align components.
 */
public class AlignDemo extends Container {

    //The DemoLabel constructor takes a hard-coded preferred size for
    //the purposes of demonstration.
    private DemoLabel label1 = new DemoLabel("1", 100, 30);
    private DemoLabel label2 = new DemoLabel("2", 50, 30);
    private DemoLabel label3 = new DemoLabel("3", 150, 30);
    private DemoLabel label4 = new DemoLabel("4", 200, 30);
    private DemoLabel label5 = new DemoLabel("5", 100, 30);
    private DemoLabel label6 = new DemoLabel("6", 150, 30);

    private ExplicitLayout layout = new ExplicitLayout();

    public AlignDemo() {
        setLayout(layout);
        Expression rowHeight = ContainerEF.heightFraction(1 / 6.0);

        add(label1, createConstraints(label1, ContainerEF.left(), 0, rowHeight, 0.0));
        add(label2, createConstraints(label2, ContainerEF.left(), 1, rowHeight, 0.0));
        add(label3, createConstraints(label3, ContainerEF.xFraction(0.5), 2, rowHeight, 0.5));
        add(label4, createConstraints(label4, ContainerEF.xFraction(0.5), 3, rowHeight, 0.5));
        add(label5, createConstraints(label5, ContainerEF.right(), 4, rowHeight, 1.0));
        add(label6, createConstraints(label6, ContainerEF.right(), 5, rowHeight, 1.0));

    }


    /**
     * Create constraints for specified component
     */
    private ExplicitConstraints createConstraints(Component c, Expression x, int row,
                                                  Expression rowHeight, double originX) {
        return new ExplicitConstraints(c, x, ContainerEF.gridY(row, rowHeight),
            MathEF.min(ComponentEF.preferredWidth(c), ContainerEF.width()),
            MathEF.min(ComponentEF.preferredHeight(c), rowHeight),
            originX, 0.0, true, true);
    }

}


