/***********************************************************************

GECCO, a platform for command and control gaming

Copyright (C) 2001 Henrik Bäärnhielm, Andreas Enblom, Niklas
Hallenfur, Karl Hasselström, Henrik Hägerström, Oskar Linde, Jing Fu
Zi and Jon Åslund

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

***********************************************************************/

package gecco.client.infopanels;
import gecco.client.*;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 *  This panel contains the properties of a piece.
 *
 * @author     Jing Fu Zi
 * @author     Andreas Enblom
 * @created    June 27, 2001
 */
public class PropertyDisplay extends JPanel {
    /**
     *  Description of the Field
     */
    Piece piece;
    /**
     *  Description of the Field
     */
    JTextArea propertyNames;
    /**
     *  Description of the Field
     */
    JTextArea propertyValues;
    /**
     *  Description of the Field
     */
    JPanel inner = new JPanel();


    /**
     *  Constructor for the PropertyDisplay object
     */
    public PropertyDisplay() {
        propertyNames = new JTextArea();
        propertyNames.setEditable(false);
        propertyNames.setBackground(getBackground());
        propertyValues = new JTextArea();
        propertyValues.setEditable(false);
        propertyValues.setBackground(getBackground());
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        add(Box.createHorizontalStrut(10));
        add(propertyNames);
        add(propertyValues);
        add(Box.createHorizontalStrut(10));
        setBorder(
                BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.black),
                "Properties",
                TitledBorder.CENTER,
                TitledBorder.TOP));
    }


    /**
     *  Sets the piece whose information is displayed.
     *
     * @param  p  The new Piece value
     */
    public void setPiece(Piece p) {
        piece = p;
        if (p == null) {
            propertyNames.setText("");
            propertyValues.setText("");
            return;
        }
        Property pro[] = piece.getProperties();
        String names = "";
        String values = "";
        for (int i = 0; i < pro.length; i++) {
            names = names + pro[i].getName() + "\n";
            values = values + pro[i].getValue() + "\n";
        }
        propertyValues.setText(values);
        propertyNames.setText(names);
    }
}
