/*

The Thistle Diagram Editor

By Jo Calder and Richard Tobin (and others where acknowledged).

This code is copyright (C) 1997 The Authors and The University of
Edinburgh, Human Communication Research Centre.  All rights reserved. 

RCS Information 
$Header: /opt_local/opt/cvs/Thistle/uk/ac/ed/ltg/thistle/graphic/tmp,v 1.1.1.1 2001/10/13 16:33:09 vannoord Exp $

*/ 

package uk.ac.ed.ltg.thistle;

import java.lang.*;
import java.util.*;
import java.awt.*;

public class Vbox extends VHbox
{
    static final int Left = 0, Right = 1, Centre = 2, Center = 2;

    int array_max_left = 0;
    int array_max_right = 0;



    void findAlignOption(Vector options)
    {
	Object _align = findOptionValue(options, s.align);
	if(_align == s.left) align = Left;
	else if(_align == s.right) align = Right;
	else if(_align == s.centre || _align == s.center) align = Centre;
	else if(_align == null) align = Centre;
	else throw new RuntimeException("Bad Vbox alignment: " + _align);
    }

    void size1(Graphics g) 
    {
	width = 0;
	height = 0;

	for(Enumeration e = children.elements(); e.hasMoreElements(); )
	{
	    Graphic gr = ((Graphic)e.nextElement());
	    gr.size1(g);
	    if(gr.width > width)
		width = gr.width;
	    height += gr.height;
	}

	width = Math.max(array_max_right + 5 + array_max_left, width);
	padding.size1(g);
	width += 2 * padding.width;
	height += 2 * padding.height;
//System.out.println("size1: " + width + "x" + height);
    }

    void size2(int w, int h)
    {
	// Always expand to fill horizontal space, so that
	// alignment does the right thing.

	width = w;

	for(Enumeration e = children.elements(); e.hasMoreElements(); )
	{
	    Graphic g = ((Graphic)e.nextElement());	
	    g.size2(width - 2 * padding.width, g.height);
	}
//System.out.println("size2: " + width + "x" + height);
    }

    void position(int l, int hm, int r, int t, int vm, int b)
    {
	super.position(l, hm, r, t, vm, b);

	int y = top + padding.height;

	for(Enumeration e = children.elements(); e.hasMoreElements(); )
	{
	    Graphic g = ((Graphic)e.nextElement());	

	    switch(align)
	    {
	    case Left:
		g.position(left+padding.width, NOPOS, NOPOS, y, NOPOS, NOPOS);
		break;
	    case Centre:
		g.position(NOPOS, left + width / 2, NOPOS, y, NOPOS, NOPOS);
		break;
	    case Right:
		g.position(NOPOS, NOPOS, left + width - padding.width,
			   y, NOPOS, NOPOS);
		break;
	    }
	    
	    y += g.height;
	}
    }
}

