/**
 * 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.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import org.inb.biomoby.client.gui.AbstractMobyComponent;
import org.inb.biomoby.shared.datatypes.MobyString;
import org.inb.biomoby.shared.ontology.MotifMatrix;
import org.inb.biomoby.shared.ontology.Pattern;
import org.inb.biomoby.shared.ontology.PrositeMotif;
import org.inb.biomoby.shared.ontology.Rules;
import org.inb.biomoby.client.gui.swing.CollapsablePanel;
import org.inb.biomoby.client.gui.swing.border.RoundedBorder;

/**
 * @author Dmitry Repchevsky
 */

public class PrositeMotifComponent<T extends PrositeMotif> extends AbstractMobyComponent<T>
{
    public PrositeMotifComponent(T prositeMotif)
    {
        super(prositeMotif);

        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        setBorder(new RoundedBorder(4));

        addLabel(prositeMotif.getAC());
        addLabel(prositeMotif.getDoc());
        addLabel(prositeMotif.getID());
        addLabel(prositeMotif.getDescription());
        addLabel(prositeMotif.getCC());

        Rules rules = prositeMotif.getRules();
        if (rules != null)
        {
            RulesComponent c = new RulesComponent(rules);
            CollapsablePanel panel = new CollapsablePanel(c, "Rules", false);
            add(panel);
        }

        Pattern pattern = prositeMotif.getPattern();
        if (pattern != null)
        {
            PatternComponent c = new PatternComponent(pattern);
            CollapsablePanel panel = new CollapsablePanel(c, "Pattern", false);
            add(panel);
        }

        MotifMatrix motifMatrix = prositeMotif.getMatrix();
        if (motifMatrix != null)
        {
            MotifMatrixComponent c = new MotifMatrixComponent(motifMatrix);
            CollapsablePanel panel = new CollapsablePanel(c, "Matrix", false);
            add(panel);
        }

        add(Box.createGlue());
    }

    private void addLabel(MobyString mobyString)
    {
        if (mobyString != null)
        {
            String string = mobyString.getString();

            if (string != null && string.length() > 0)
            {
                add(new JLabel(string));
            }
        }
    }
}
