/*
 * @(#)FileTransferDownloadEvent.java
 *
 * Copyright (c) 1999-2007 JSCAPE LLC
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */
package com.jscape.filetransfer;

/**
 * Fired when file is downloaded from server.
 */
public class FileTransferDownloadEvent
        extends FileTransferEvent {

    private final String filename;
    private final String path;
    private final String localPath;
    private final long size;
    private final long time;
    private final boolean interrupted;

    /**
     * Creates a new event instance.
     *
     * @param source      the source of the event
     * @param filename    the file downloaded
     * @param path        the remote directory path file was downloaded from
     * @param localPath   the local file path
     * @param size        the size of the file downloaded in bytes
     * @param time        the time to download in milliseconds
     * @param interrupted interrupted flag
     */
    public FileTransferDownloadEvent(FileTransfer source,
                                     String filename,
                                     String path,
                                     String localPath,
                                     long size,
                                     long time,
                                     boolean interrupted) { // why?
        super(source);

        this.filename = filename;
        this.path = path;
        this.localPath = localPath;
        this.size = size;
        this.time = time;
        this.interrupted = interrupted;
    }

    public FileTransferDownloadEvent(FileTransfer source, String filename, String path, String localPath, long size, long time) {
        this(source, filename, path, localPath, size, time, false);
    }

    /**
     * Gets name of file downloaded.
     *
     * @return filename
     */
    public String getFilename() {
        return this.filename;
    }

    /**
     * Gets remote directory path that file was downloaded from.
     *
     * @return the remote directory path
     */
    public String getPath() {
        return this.path;
    }

    /**
     * Returns downloaded file local path.
     *
     * @return downloaded file local path
     */
    public String getLocalPath() {
        return this.localPath;
    }

    /**
     * Gets total bytes transmitted.
     *
     * @return bytes transmitted
     */
    public long getSize() {
        return this.size;
    }

    /**
     * Gets total time to transfer file measured in milliseconds.
     *
     * @return total time
     */
    public long getTime() {
        return this.time;
    }

    /**
     * Indicates if the download operations was interrupted by the user or network connection.
     *
     * @return <code>true</code> if the transfer was interrupted.
     */
    public boolean isInterrupted() {
        return this.interrupted;
    }

    /**
     * {@inheritDoc}
     */
    public void accept(FileTransferListener listener) {
        listener.download(this);
    }

    @Override
    public String toString() {
        return "FileTransferDownloadEvent {"
                + "filename='" + this.filename + '\''
                + ", path='" + this.path + '\''
                + ", localPath='" + this.localPath + '\''
                + ", size=" + this.size
                + ", time=" + this.time
                + ", interrupted=" + this.interrupted
                + '}';
    }
}
