/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protegex.widget.contains;

import java.awt.*;

import javax.swing.*;

import edu.stanford.smi.protege.model.*;
import edu.stanford.smi.protege.util.*;

/**
 *  Number of slot values in a panel
 *
 * @author    William Grosso <grosso@smi.stanford.edu>
 */
public class SummaryPanel extends LabeledComponent {
    private ContainsWidget _widget;
    private ContainsWidgetState _state;
    private JPanel _interior;
    private NumberOfSlotValuesComponent _numberOfSlotValuesComponent;

    public SummaryPanel(ContainsWidget widget) {
        super("Summary Information", new JPanel(new GridBagLayout()), true);
        _interior = (JPanel) getCenterComponent();
        _widget = widget;
        _state = _widget.getState();
        GridBagConstraints runningConstraint = getGridBagConstraints();
        if (_state.isDisplayTotalNumberOfSubordinateInstances()) {
            addNumberOfSlotValuesComponent(runningConstraint);
        }
        if (_state.isDisplayBrowserKeysOfSubordinateInstances()) {
            addListOfBrowserKeys(runningConstraint);
        }
        // more summary stuff is easy to add via same code pattern
    }

    private void addListOfBrowserKeys(GridBagConstraints constraint) {

    }

    private void addNumberOfSlotValuesComponent(GridBagConstraints constraint) {
        _numberOfSlotValuesComponent = new NumberOfSlotValuesComponent(_widget.getInstance(), _widget.getSlot());
        _interior.add(_numberOfSlotValuesComponent, constraint);
        constraint.gridx++;
    }

    public void dispose() {
        if (null != _numberOfSlotValuesComponent) {
            _numberOfSlotValuesComponent.dispose();
        }
    }

    private GridBagConstraints getGridBagConstraints() {
        GridBagConstraints returnValue = new GridBagConstraints();
        returnValue.gridx = 0;
        returnValue.gridy = 0;
        returnValue.gridheight = 1;
        returnValue.gridwidth = 1;
        returnValue.weightx = 1;
        returnValue.weighty = 0;
        returnValue.fill = GridBagConstraints.BOTH;
        return returnValue;
    }

    public void setInstance(Instance newInstance) {
        if (null != _numberOfSlotValuesComponent) {
            _numberOfSlotValuesComponent.setInstance(newInstance);
        }
    }
}
