/**
 * 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 java.awt.Color;
import javax.swing.OverlayLayout;
import org.inb.biomoby.client.gui.AbstractMobyComponent;
import org.inb.biomoby.client.gui.auxiliary.ArrayFloatChartPane;
import org.inb.biomoby.client.gui.IDynamicComponent;
import org.inb.biomoby.client.gui.IDynamicComponent.MobyComponentListener;
import org.inb.biomoby.client.gui.ISequenceCoordinateTransformer;
import org.inb.biomoby.client.gui.ISequenceDependent;
import org.inb.biomoby.client.gui.ITransformable;
import org.inb.biomoby.client.gui.ontology.CommentedAASequenceComponent.CommentedAASequenceListener;
import org.inb.biomoby.client.gui.ontology.FeatureAASequenceComponent.FeatureAASequenceListener;
import org.inb.biomoby.shared.ontology.FeatureAASequence;

/**
 * @author Dmitry Repchevsky
 */

public class FeatureAASequenceComponent extends AbstractMobyComponent
        implements IDynamicComponent<FeatureAASequenceListener>,
                   ISequenceDependent,
                   ITransformable
{
    private CommentedAASequenceComponent commentedAASequencePanel;
    private ArrayFloatChartPane arrayFloatChartPane;
    
    private FeatureAASequenceComponent(CommentedAASequenceComponent commentedAASequencePanel)
    {
        setLayout(new OverlayLayout(this));

        commentedAASequencePanel.setOpaque(false);
        commentedAASequencePanel.setBackground(new Color(0, true));
        add(commentedAASequencePanel);

        arrayFloatChartPane = new ArrayFloatChartPane();
        arrayFloatChartPane.setTransformer(commentedAASequencePanel.getTransformer());
        add(arrayFloatChartPane);
        
        this.commentedAASequencePanel = commentedAASequencePanel;
    }
    
    public FeatureAASequenceComponent()
    {
        this(new CommentedAASequenceComponent());
    }
    
    public FeatureAASequenceComponent(FeatureAASequence sequence)
    {
        this(new CommentedAASequenceComponent(sequence));
        
        if (sequence != null)
        {
            arrayFloatChartPane.setArrayFloat(sequence.getFeature());
        }
    }

    public FeatureAASequence getData()
    {
        return (FeatureAASequence)commentedAASequencePanel.getData();
    }

    public void setColor(Color color)
    {
        arrayFloatChartPane.setColor(color);
    }
    
    public void setFontStyle(int style)
    {
        commentedAASequencePanel.setFontStyle(style);
    }
    
    @Override
    public void setOpaque(boolean isOpaque)
    {
        super.setOpaque(isOpaque);
        
        if (commentedAASequencePanel != null)
        {
            commentedAASequencePanel.setOpaque(isOpaque);
        }
    }
    
    @Override
    public void addListener(MobyComponentListener listener)
    {
        commentedAASequencePanel.addListener(listener);
    }

    @Override
    public void removeListener(MobyComponentListener listener)
    {
        commentedAASequencePanel.removeListener(listener);
    }

    @Override
    public void setPosition(int position)
    {
        commentedAASequencePanel.setPosition(position);
    }

    @Override
    public void setSequenceVisible(boolean isVisible)
    {
        commentedAASequencePanel.setSequenceVisible(isVisible);
        
        arrayFloatChartPane.setTransformer(isVisible ? commentedAASequencePanel.getTransformer() : null);
    }

    @Override
    public void setTransformer(ISequenceCoordinateTransformer transformer)
    {
        arrayFloatChartPane.setTransformer(transformer);
    }

    @Override
    public ISequenceCoordinateTransformer getTransformer()
    {
        return arrayFloatChartPane.getTransformer();
    }
    
    public static interface FeatureAASequenceListener 
            extends CommentedAASequenceListener
    {
        
    }
}
