/**
 * 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.ontology;

import javax.swing.BoxLayout;
import org.inb.biomoby.client.gui.DynamicMobyComponent;
import org.inb.biomoby.shared.datatypes.MobyInteger;
import org.inb.biomoby.shared.message.AbstractMobyObject;
import org.inb.biomoby.shared.ontology.Annotation;
import org.inb.biomoby.client.gui.swing.RoundedMultilineLabel;

/**
 * @author DmitryRepchevsky
 */

public class AnnotationComponent<T extends Annotation> extends DynamicMobyComponent
{
    private T annotation;

    RoundedMultilineLabel label;

    public AnnotationComponent(T annotation)
    {
        this.annotation = annotation;

        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS ));

        label = new RoundedMultilineLabel();
        label.setBackground(this.getBackground());
        label.setForeground(this.getForeground());

        String html = getHtml(annotation);

        label.setText(html);

        add(label);
    }

    @Override
    public AbstractMobyObject getData()
    {
        return annotation;
    }

//    @Override
//    public Dimension getPreferredSize()
//    {
//    }
//
//    @Override
//    public Dimension getMaximumSize()
//    {
//    }

    protected String getHtml(T annotation)
    {
        StringBuilder sb = new StringBuilder();

        sb.append("<html>");
        sb.append("<font style='color: blue'>");

        MobyInteger startMobyInteger = annotation.getStart();

        if (startMobyInteger != null)
        {
            sb.append(startMobyInteger.getInteger());
        }

        sb.append(" - ");

        MobyInteger endMobyInteger = annotation.getEnd();

        if (endMobyInteger != null)
        {
            sb.append(endMobyInteger.getInteger());
        }

        sb.append("</font>");
        sb.append("</html>");

        return sb.toString();
    }
}
