//------------------------------------------------------------------------------
// ColorBars.java:
//		Implementation of "control creator" class ColorBars
//------------------------------------------------------------------------------
import java.awt.*;
import DialogLayout;

public class ColorBars
{
	Container    m_Parent       = null;
	boolean      m_fInitialized = false;
	DialogLayout m_Layout;

	// Control definitions
	//--------------------------------------------------------------------------
	Scrollbar     Red_Bar;
	Scrollbar     Green_Bar;
	Scrollbar     Blue_Bar;
	Label         Red_Lab;
	Label         Green_Lab;
	Label         Blue_Lab;
	Button        CButton;


	// Constructor
	//--------------------------------------------------------------------------
	public ColorBars (Container parent)
	{
		m_Parent = parent;
	}

	// Initialization.
	//--------------------------------------------------------------------------
	public boolean CreateControls()
	{
		// CreateControls should be called only once
		//----------------------------------------------------------------------
		if (m_fInitialized || m_Parent == null)
			return false;

		// m_Parent must be extended from the Container class
		//----------------------------------------------------------------------
		if (!(m_Parent instanceof Container))
			return false;

		// Since a given font may not be supported across all platforms, it
		// is safe to modify only the size of the font, not the typeface.
		//----------------------------------------------------------------------
	    Font OldFnt = m_Parent.getFont();
	    if (OldFnt != null)
	    {
			Font NewFnt = new Font(OldFnt.getName(), OldFnt.getStyle(), 8);

    		m_Parent.setFont(NewFnt);
	    }

		// All position and sizes are in dialog logical units, so we use a
		// DialogLayout as our layout manager.
		//----------------------------------------------------------------------
		m_Layout = new DialogLayout(m_Parent, 100, 207);
		m_Parent.setLayout(m_Layout);
		m_Parent.addNotify();

		Dimension size   = m_Layout.getDialogSize();
		Insets    insets = m_Parent.insets();
		
		m_Parent.resize(insets.left + size.width  + insets.right,
                        insets.top  + size.height + insets.bottom);

		// Control creation
		//----------------------------------------------------------------------
		Red_Bar = new Scrollbar (Scrollbar.HORIZONTAL, 0, 1, 0, 255);
		m_Parent.add(Red_Bar);
		m_Layout.setShape(Red_Bar, 7, 56, 86, 16);

		Green_Bar = new Scrollbar (Scrollbar.HORIZONTAL, 0, 1, 0, 255);
		m_Parent.add(Green_Bar);
		m_Layout.setShape(Green_Bar, 7, 96, 86, 16);

		Blue_Bar = new Scrollbar (Scrollbar.HORIZONTAL, 0, 1, 0, 255);
		m_Parent.add(Blue_Bar);
		m_Layout.setShape(Blue_Bar, 7, 135, 86, 16);

		Red_Lab = new Label ("Red", Label.LEFT);
		m_Parent.add(Red_Lab);
		m_Layout.setShape(Red_Lab, 42, 80, 16, 8);

		Green_Lab = new Label ("Green", Label.LEFT);
		m_Parent.add(Green_Lab);
		m_Layout.setShape(Green_Lab, 39, 118, 20, 8);

		Blue_Lab = new Label ("Blue", Label.LEFT);
		m_Parent.add(Blue_Lab);
		m_Layout.setShape(Blue_Lab, 42, 158, 15, 8);

		CButton = new Button ("Reset");
		m_Parent.add(CButton);
		m_Layout.setShape(CButton, 37, 177, 27, 13);

		m_fInitialized = true;
		return true;
	}
}
