/*
 * @(#)AcceptAllFileFilter.java 1.0  2002-02-12
 *
 * Copyright (c) 2002 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */

package ch.randelshofer.io;

import java.io.*;
import javax.swing.filechooser.*;

/**
 * A file filter that accepts all files.
 *
 * @author  Werner Randelshofer
 * @version 1.0 2002-02-12
 */
public class AcceptAllFileFilter
extends javax.swing.filechooser.FileFilter
implements Comparable {
    /**
     * The description of the filter.
     */
    private String description;
    
    /**
     * Creates a new instance of AcceptAllFileFilter.
     *
     * @param description The description of the filter.
     */
    public AcceptAllFileFilter(String description) {
        this.description = description;
    }
    
    /**
     * Whether the given file is accepted by this filter.
     *
     * @return Returns allways true.
     */
    public boolean accept(File f) {
        return true;
    }
    
    /**
     * The description of this filter.
     * @see FileView#getName
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.<p>
     *
     * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
     * <tt>y.compareTo(x)</tt> throws an exception.)<p>
     *
     * The implementor must also ensure that the relation is transitive:
     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
     * <tt>x.compareTo(z)&gt;0</tt>.<p>
     *
     * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
     * all <tt>z</tt>.<p>
     *
     * It is strongly recommended, but <i>not</i> strictly required that
     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
     * class that implements the <tt>Comparable</tt> interface and violates
     * this condition should clearly indicate this fact.  The recommended
     * language is "Note: this class has a natural ordering that is
     * inconsistent with equals."
     *
     * @param   o the Object to be compared.
     * @return  a negative integer, zero, or a positive integer as this object
     * 		is less than, equal to, or greater than the specified object.
     *
     * @throws ClassCastException if the specified object's type prevents it
     *        from being compared to this Object.
     */
    public int compareTo(Object o) {
        if (o instanceof AcceptAllFileFilter) {
            AcceptAllFileFilter that = (AcceptAllFileFilter) o;
            return this.description.compareTo(that.description);
        }
        throw new ClassCastException();
    }
    
    
    /**
     * Returns true when the given object is of the same type
     * and its description is equal.
     */
    public boolean equals(Object o) {
        if (o instanceof AcceptAllFileFilter) {
            AcceptAllFileFilter that = (AcceptAllFileFilter) o;
            return this.description.equals(that.description);
        }
        return false;
    }
    /**
     * Returns a hash code derived from the description of
     * this file filter.
     */
    public int hashCode() {
        return description.hashCode();
    }
    
}
