package CH.ifa.draw.io.exportFormats;

import java.io.File;
import javax.swing.filechooser.FileFilter;

import de.renew.draw.storables.ontology.Drawing;


/**
 * Abstract implementation of the ExportFormat interface.
 * @deprecated This type is not to be used anymore. Please use {@link de.renew.ioontology.exporting.ExportFormatAbstract} and its subtypes instead.
 */
@Deprecated(since = "5.0", forRemoval = true)
@SuppressWarnings("removal")
public abstract class ExportFormatAbstract implements ExportFormat {
    // The name of the format.
    private String _formatName;

    // The FileFilter of the format.
    private FileFilter _fileFilter;

    /**
     * Constructs ExportFormatAbstract with a given name and a given file filter.
     * @param name the given name
     * @param fileFilter the given file filter
     */
    public ExportFormatAbstract(String name, FileFilter fileFilter) {
        setFormatName(name);
        setFileFilter(fileFilter);
    }

    /**
     * Sets _fileFilter to fileFilter.
     * @require fileFilter != null
     * @ensure fileFilter() != null
     * @ensure fileFilter().equals(fileFilter)
     * @param fileFilter the value to be set.
     */
    protected void setFileFilter(FileFilter fileFilter) {
        _fileFilter = fileFilter;
        assert (fileFilter() != null) : "Failure in ExportFormatAbstract: fileFilter() == null";
        assert (fileFilter().equals(fileFilter))
            : "Failure in ExportFormatAbstract: fileFilter() != fileFilter";
    }

    /**
     * Sets _formatName to formatName.
     * @require formatName != null
     * @ensure formatName() != null
     * @ensure formatName().equals(formatName)
     * @param formatName the value to be set.
     */
    protected void setFormatName(String formatName) {
        _formatName = formatName;
        assert (formatName() != null) : "Failure in ExportFormatAbstract: formatName() == null";
        assert (formatName().equals(formatName))
            : "Failure in ExportFormatAbstract: formatName() != fielFilter";
    }


    //	---------------------------------------------------------------------
    // Implementation of the ExportFormat interface
    // ---------------------------------------------------------------------

    @Override
    public FileFilter fileFilter() {
        assert (_fileFilter != null) : "Failure in ExportFormatAbstract: _fileFilter == null";
        return _fileFilter;
    }

    @Override
    public String formatName() {
        assert (_formatName != null) : "Failure in ExportFormatAbstract: _formatName == null";
        return _formatName;
    }

    @Override
    public File[] exportAll(Drawing[] drawings, File[] path) throws Exception {
        File[] result = null;
        if (drawings != null && path != null) {
            if (drawings.length == path.length) {
                result = new File[path.length];
                for (int pos = 0; pos < drawings.length; pos++) {
                    result[pos] = export(drawings[pos], path[pos]);
                }
            }
        }
        assert (result != null) : "Failure in ExportFormatAbstract : result == null";
        return result;
    }

    @Override
    public ExportFormat[] canExport(File path) {
        ExportFormat[] result = null;
        if (path != null) {
            if (fileFilter().accept(path)) {
                result = new ExportFormat[] { this };
            } else {
                result = new ExportFormat[0];
            }
        }
        assert (result != null) : "Failure in ExportFormatAbstract: result == null";
        return result;
    }

    @Override
    public int getShortCut() {
        return -1;
    }

    /* (non-Javadoc)
     * @see CH.ifa.draw.io.exportFormats.ExportFormat#getModifier()
     */
    @Override
    public int getModifier() {
        return -1;
    }

    @Override
    public boolean forceGivenName() {
        return false;
    }

    @Override
    public String toString() {
        return formatName();
    }
}