/**
 * MediaSniper 3.0 (2008-08-02)
 * Copyright 2007 - 2008 Zach Scrivena
 * zachscrivena@gmail.com
 * http://mediasniper.sourceforge.net/
 *
 * Simple program for downloading media files from popular websites.
 *
 * TERMS AND CONDITIONS:
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.freeshell.zs.mediasniper;

import javax.swing.JLabel;


/**
 * Represent a table cell that contains a string.
 */
class TableStringCell
        implements Comparable<TableStringCell>
{
    /** corresponding Download object */
    final Download download;

    /** text string for this cell */
    String text = "";

    /** value associated to this cell, for sorting purpose */
    int value = -1;

    /** horizontal alignment for this cell */
    int align = JLabel.LEFT;


    /**
    * Constructor.
    *
    * @param ac
    *      corresponding Account object
    */
    TableStringCell(
            final Download download)
    {
        this.download = download;
    }


    /**
    * Compare this table cell content to the specified table cell content,
    * by value first, and then by text.
    */
    public int compareTo(
            TableStringCell o)
    {
        if (value == o.value)
        {
            return text.compareToIgnoreCase(o.text);
        }
        else if (value < o.value)
        {
            return -1;
        }
        else
        {
            return 1;
        }
    }


    /**
    * Check for equality between this table cell content and the
    * specified table cell content, using only the value and text fields.
    */
    @Override
    public boolean equals(
            Object o)
    {
        if (o instanceof TableStringCell)
        {
            final TableStringCell c = (TableStringCell) o;
            return (value == c.value) && text.equals(c.text);
        }
        else
        {
            return false;
        }
    }


    /**
    * Generate a hash code for this table cell content, using the value and text fields.
    */
    @Override
    public
    int hashCode()
    {
        int hash = 7;
        hash = 83 * hash + (text != null ? text.hashCode() : 0);
        hash = 83 * hash + value;
        return hash;
    }
}