/*
 * BoxContentPane.java
 * 
 * Copyright (c) 2003-2004 Digi International
 * This program and the information contained in it is confidential and
 * proprietary to Digi International and may not be used, copied, or re-
 * produced without the prior written permission of Digi International.
 * 
 */

package com.digi.config.ui;

import com.digi.config.core.*;
import com.digi.config.util.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;




/** 
 * This class is a panel that holds controls in a vertical manner. Views
 * can imbed this panel anywhere they want a vertical of controls. The class
 * has helper methods for inserting entries into the view. 
 */
public class BoxContentPanel extends JPanel {
    public BoxContentPanel() {
        this.setOpaque(true);
        this.setBackground(Color.PINK);
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    }

    public void addHeadingBar(String headingTag) {
        Box hbox = Box.createHorizontalBox();
        hbox.setAlignmentX(Component.LEFT_ALIGNMENT);
        hbox.setOpaque(true);
        hbox.setBackground(Color.YELLOW);
        hbox.setBorder(BorderFactory.createEtchedBorder());
        String text = ConfigResource.getUiRbString(headingTag);
        JLabel heading = new JLabel(text);
        heading.setOpaque(true);
        heading.setBackground(new Color(197, 214, 252));
        heading.setAlignmentX(Component.LEFT_ALIGNMENT);
        hbox.add(heading);
        hbox.add(Box.createHorizontalGlue());
        this.add(hbox);
    }

    public void addVGlue() {
        this.add(Box.createVerticalGlue());
    }

    public void addAction(String prefixTag, Action action, String postfixTag) {
        JLabel label;
        JButton button;
        Box hbox = Box.createHorizontalBox();
        hbox.setAlignmentX(Component.LEFT_ALIGNMENT);
        // Add the prefix string
        hbox.add(Box.createRigidArea(new Dimension(20, 0)));
        if (prefixTag!=null) {
            label = new JLabel(ConfigResource.getUiRbString(prefixTag));
            hbox.add(label);
        }

        // add the action button 
        hbox.add(Box.createRigidArea(new Dimension(10, 0)));
        button = new JButton(action);
        hbox.add(button);

        // add the action description text
        if (postfixTag!=null) {
            hbox.add(Box.createRigidArea(new Dimension(10, 0)));
            label = new JLabel(ConfigResource.getUiRbString(postfixTag));
            hbox.add(label);
        }
        hbox.add(Box.createHorizontalGlue());
        this.add(hbox);
    }

    public void addField(String fieldTag, Component fieldComponent, String fieldDescTag) {
        JLabel label;
        Box hbox = Box.createHorizontalBox();
        hbox.setAlignmentX(Component.LEFT_ALIGNMENT);
        // Add the prefix string
        hbox.add(Box.createRigidArea(new Dimension(20, 0)));
        if (fieldTag!=null) {
            label = new JLabel(ConfigResource.getUiRbString(fieldTag));
            hbox.add(label);
        }
        // add the field component 
        hbox.add(Box.createRigidArea(new Dimension(10, 0)));
        hbox.add(fieldComponent);

        // add the field description text
        if (fieldDescTag!=null) {
            hbox.add(Box.createRigidArea(new Dimension(10, 0)));
            label = new JLabel(ConfigResource.getUiRbString(fieldDescTag));
            hbox.add(label);
        }
        hbox.add(Box.createHorizontalGlue());
        this.add(hbox);
    }

}


