/**
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 *
 * Copyright (C)
 * <a href="http://www.inab.org">Spanish National Institute of Bioinformatics (INB)</a>
 * <a href="http://www.bsc.es">Barcelona Supercomputing Center (BSC)</a>
 * <a href="http://inb.bsc.es">Computational Node 6</a>
 */

package org.inb.biomoby.client.gui;

import java.awt.BorderLayout;
import java.io.StringWriter;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.xml.bind.Marshaller;
import org.inb.biomoby.MobyMessageContext;
import org.inb.biomoby.shared.message.AbstractMobyObject;

/**
 * @author Dmitry Repchevsky
 */

public class DefaultMobyComponent<T extends AbstractMobyObject> extends AbstractMobyComponent<T>
{
    public DefaultMobyComponent(T object)
    {
        super(object);

        setLayout(new BorderLayout());

        String xml;
        try
        {
            Marshaller m = MobyMessageContext.getContext().createMarshaller();

            StringWriter sw = new StringWriter();
            m.marshal(object, sw);

            xml = sw.toString();
        }
        catch(Exception ex)
        {
            xml = ex.getMessage();
        }

        JEditorPane editor = new JEditorPane("text/plain", xml);
        editor.setEditable(false);

        add(new JScrollPane(editor), BorderLayout.CENTER);
    }
}
