/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.spark.component.tabbedPane;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;

/**
 * Represent one tab in a SparkTabbedPane.
 *
 * @author Derek DeMoro
 */
public class SparkTab extends TabPanel {
    private JLabel iconLabel;
    private JLabel textLabel;

    private String actualText;

    private Color backgroundColor;
    private Color selectedBorderColor;
    private boolean selected;
    private boolean boldWhenActive;

    private Font defaultFont;

    private Icon previousIcon;

    public SparkTab(Icon icon, String text) {
        setLayout(new GridBagLayout());


        selectedBorderColor = new Color(173, 0, 0);

        //  setBackground(backgroundColor);

        this.actualText = text;

        iconLabel = new JLabel(icon);
        iconLabel.setOpaque(false);
        textLabel = new JLabel(text);

        // add Label
        add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));

        // add text label
        add(textLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 2, 3, 10), 0, 0));

        // Set fonts
        defaultFont = new Font("Dialog", Font.PLAIN, 11);
        textLabel.setFont(defaultFont);
    }

    public void addComponent(Component component) {
        // add Component
        add(component, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 0, 3, 2), 0, 0));
    }

    public void addPop(JComponent comp) {
        add(comp, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));
    }

    public String getActualText() {
        return actualText;
    }


    public void setSelected(boolean selected) {
        super.setSelected(selected);
        this.selected = selected;

        if (boldWhenActive && selected) {
            textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD));
        }
        else if (boldWhenActive && !selected) {
            textLabel.setFont(defaultFont);
        }


        invalidate();
        validate();
        repaint();

        textLabel.invalidate();
        textLabel.validate();
        textLabel.repaint();
    }

    public Font getDefaultFont() {
        return defaultFont;
    }

    public JLabel getTitleLabel() {
        return textLabel;
    }

    public void setIcon(Icon icon) {
        if(iconLabel.getIcon() != null){
            previousIcon = iconLabel.getIcon();
        }
        iconLabel.setIcon(icon);
    }

    public void setBoldWhenActive(boolean boldWhenActive) {
        this.boldWhenActive = boldWhenActive;
    }

    public boolean isBoldWhenActive(){
        return boldWhenActive;
    }

    public Icon getPreviousIcon(){
        return previousIcon;
    }


}

@@ -992,16 +992,47 @@
 usIcon;%0D
+%0A    private Icon defaultIcon;%0D
 %0A%0D%0A    p
@@ -1185,42 +1185,31 @@
     
-//  setBackground(backgroundColor)
+this.defaultIcon = icon
 ;%0D%0A%0D
@@ -3093,16 +3093,17 @@
       if
+ 
 (iconLab
@@ -3123,16 +3123,17 @@
 != null)
+ 
 %7B%0D%0A     
@@ -3384,19 +3384,20 @@
 Active()
+ 
 %7B%0D%0A
-
         
@@ -3462,16 +3462,17 @@
 usIcon()
+ 
 %7B%0D%0A     
@@ -3505,13 +3505,87 @@
    %7D%0D%0A%0D%0A
+    public Icon getDefaultIcon() %7B%0D%0A        return defaultIcon;%0D%0A    %7D%0D%0A%0D%0A
 %0D%0A%7D%0D%0A

Allow for default icon retrieval in tabs.