/*
 * @(#)FtpProgressEvent.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * 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.inet.ftp;

/**
 * Fired on significant progress in upload and download operations in Ftp class.
 */
public class FtpProgressEvent
        extends FtpEvent {

    /**
     * Indicates UPLOAD process
     */
    public static final int UPLOAD = 0;

    /**
     * Indicates DOWNLOAD process
     */
    public static final int DOWNLOAD = 1;
    private long bytes;
    private long totalBytes;
    private long readBytes;
    private String filename;
    private String path;
    private String localFilePath;
    private int mode;

    /**
     * Constructs new <code>FtpProgressEvent</code>.
     *
     * @param source     the source of this event
     * @param filename   the name of file being transferred
     * @param mode       the direction of transfer
     * @param bytes      the number of bytes transferred
     * @param totalBytes the number of bytes for the file being transferred
     */
    public FtpProgressEvent(Object source, String filename, String path, int mode, long bytes, long readBytes, long totalBytes) {
        super(source);
        this.filename = filename;
        this.path = path;
        this.mode = mode;
        this.bytes = bytes;
        this.readBytes = readBytes;
        this.totalBytes = totalBytes;
    }

    /**
     * Constructor.
     *
     * @param source
     * @param filename
     * @param path
     * @param localFilePath
     * @param mode
     * @param bytes
     * @param readBytes
     * @param totalBytes
     */
    public FtpProgressEvent(Object source, String filename, String path, String localFilePath, int mode, long bytes, long readBytes, long totalBytes) {
        super(source);
        this.filename = filename;
        this.path = path;
        this.localFilePath = localFilePath;
        this.mode = mode;
        this.bytes = bytes;
        this.readBytes = readBytes;
        this.totalBytes = totalBytes;
    }

    public String getLocalFilePath() {
        return this.localFilePath;
    }

    /**
     * Get the number of bytes read at one time.
     *
     * @return bytes
     */
    public long getReadBytes() {
        return this.readBytes;
    }


    /**
     * Gets mode of transfer, upload or download.
     *
     * @return mode
     *
     * @see #UPLOAD
     * @see #DOWNLOAD
     */
    public int getMode() {
        return mode;
    }

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


    /**
     * Gets absolute path of file transferred.
     *
     * @return absolute path
     */
    public String getAbsolutePath() {
        return path;
    }

    /**
     * Gets the number of bytes transferred so far.
     *
     * @return bytes
     */
    public long getBytes() {
        return bytes;
    }

    /**
     * Gets the number of bytes for the file being transferred
     *
     * @return bytes
     */
    public long getTotalBytes() {
        return totalBytes;
    }

    public void accept(FtpListener listener) {
        if (listener != null) {
            listener.progress(this);
        }
    }
}
