/**
 *  RELOAD TOOLS
 *
 *  Copyright (c) 2003 Oleg Liber, Bill Olivier, Phillip Beauvoir
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  Project Management Contact:
 *
 *  Oleg Liber
 *  Bolton Institute of Higher Education
 *  Deane Road
 *  Bolton BL3 5AB
 *  UK
 *
 *  e-mail:   o.liber@bolton.ac.uk
 *
 *
 *  Technical Contact:
 *
 *  Phillip Beauvoir
 *  e-mail:   p.beauvoir@bolton.ac.uk
 *
 *  Web:      http://www.reload.ac.uk
 *
 */

package uk.ac.reload.editor.contentpackaging.editor.resourceview.metadata;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.Component;

import javax.swing.*;

import uk.ac.reload.dweezil.gui.layout.XYConstraints;
import uk.ac.reload.dweezil.gui.layout.XYLayout;
import uk.ac.reload.dweezil.gui.DweezilComboBox;
import uk.ac.reload.dweezil.gui.ErrorDialogBox;
import uk.ac.reload.dweezil.menu.UndoMenuManager;
import uk.ac.reload.dweezil.gui.GradientPanel;
import uk.ac.reload.editor.Messages;
import uk.ac.reload.editor.menu.Menu_Edit;
import uk.ac.reload.editor.metadata.editor.formview.MD_FormPanel;
import uk.ac.reload.editor.metadata.editor.tableview.MD_TablePanel;
import uk.ac.reload.editor.metadata.xml.Metadata;
import uk.ac.reload.editor.properties.EditorProperties;
import uk.ac.reload.moonunit.ProfiledSchemaController;

/**
 * The Core Metadata Editor
 *
 *
 * @author Phillip Beauvoir
 * @version $Id: MD_EditorPanel.java,v 1.2 2004/11/06 18:04:29 phillipus Exp $
 */
public class MD_EditorPanel
extends JPanel
{
    /**
     * The Metadata Document
     */
    private Metadata _metadata;
    

     /**
     * The Form View
     */
    private MD_FormPanel _formPanel;
    
    private GradientPanel _byKeyPanel;

    private JTabbedPane tabPane;
    
    private JTextField textoTF;
 
    /**
     * Constructor
     * @param editMenu
     */
    public MD_EditorPanel() {

        setLayout(new BorderLayout());

        _formPanel = new MD_FormPanel();
        _byKeyPanel = new GradientPanel(new XYLayout());
        setBackground(new Color(250, 250, 250));
        JLabel explainsLabel = new JLabel(Messages.getString("uk.ac.reload.editor.contentpackaging.resourceview.metadata.CP_ResourcesByMetadata.11"));
        JLabel textoLabel = new JLabel(Messages.getString("uk.ac.reload.editor.contentpackaging.resourceview.metadata.CP_ResourcesByMetadata.12"));
        textoTF = new JTextField("");
        textoTF.setColumns(50);
		textoTF.setBorder(BorderFactory.createLineBorder(Color.GRAY));

        _byKeyPanel.add(explainsLabel, new XYConstraints(38, 4, 0, 0));
        _byKeyPanel.add(textoLabel, new XYConstraints(50, 30 + 2, 0, 0));
        _byKeyPanel.add(textoTF, new XYConstraints(140, 30, 0, 0));

        // Tab Pane
        tabPane = new JTabbedPane();
        tabPane.addTab(Messages.getString("uk.ac.reload.editor.contentpackaging.resourceview.metadata.CP_ResourcesByMetadata.5"), null, new JScrollPane(_formPanel), null); //$NON-NLS-1$ //$NON-NLS-2$
        tabPane.addTab(Messages.getString("uk.ac.reload.editor.contentpackaging.resourceview.metadata.CP_ResourcesByMetadata.10"), null, new JScrollPane(_byKeyPanel), null); //$NON-NLS-1$ //$NON-NLS-2$
        add(tabPane, BorderLayout.CENTER);
    }

    /**
     * Get the Metadata Document
     * @return Metadata
     */
    public Metadata getMetadata() {
        return _metadata;
    }

    /**
     * Set the Editor to a Metadata Document
     * @param metadata The Metadata Document
     */
    public void setDocument(Metadata metadata) {
        _metadata = metadata;

        // Tell Panels
        _formPanel.setDocument(metadata);
    }

    public int getSelectedTab() {
    	return tabPane.getSelectedIndex();
    }
    
    public String getKeyword() {
    	
    	return textoTF.getText();
    }
    

    /**
     * Clean up
     */
    public void cleanup() {
        try {
            // Have to check for nulls.  Since launching this Editor is on a thread,
            // if user closes the app before this window appears then these objects will be null
 
            if(_formPanel != null) {
                _formPanel.cleanup();
            }
            if(_metadata != null) {
                _metadata.destroy();
            }
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    

    }
}
