Package getfacts.conf

Source Code of getfacts.conf.ConfigurationPanel

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package getfacts.conf;

import getfacts.ConfigurationItem;
import getfacts.ConfigurationItems;
import getfacts.config.ComboBoxItem;
import getfacts.config.TextFieldItem;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
*
* @author jmc15
*/
public class ConfigurationPanel
extends JPanel
{
    private final ConfigurationItems items;
    private final GridBagLayout layout;
   
    public ConfigurationPanel(ConfigurationItems config)
    {
        items = config;
        layout = new GridBagLayout();
        this.setLayout(layout);
       
        populate();
    }
   

   
    private void populate()
    {
        ConfigurationItem[] list = items.getItems();
        GridBagConstraints constraints = new GridBagConstraints();
       
        for(int row=0; row<list.length; row++)
        {
            ConfigurationItem item = list[row];
           
            JLabel label = new JLabel();
            label.setText( item.getName() );
           
            constraints.gridx=0;
            constraints.gridy=row;
            this.add(label, constraints);
                       
            if( item instanceof ComboBoxItem)
            {
                constraints.gridx=1;
                JComboBox comboBox = new JComboBox( (ComboBoxItem)item );
                this.add(comboBox, constraints);
            }
           
            else if(item instanceof TextFieldItem)
            {               
                constraints.gridx=1;
                JTextField textField = new JTextField();
                textField.setDocument( (TextFieldItem)item );
                this.add(textField, constraints);
            }
           
            else
            {
                constraints.gridx=1;
                JLabel lb2 = new JLabel();
                lb2.setText("not configurable");
                this.add(lb2, constraints);
            }
        }
    }
}
TOP

Related Classes of getfacts.conf.ConfigurationPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.