Package de.kout.wlFxp.view

Source Code of de.kout.wlFxp.view.MainListModel

/**
* Copyright (C) 2003 Alexander Kout
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package de.kout.wlFxp.view;

import javax.swing.*;
import java.io.*;
import javax.swing.event.*;
import java.util.*;

import de.kout.wlFxp.ftp.FtpFile;
import de.kout.wlFxp.Utilities;

/**
*  the special implementation of a list model for file lists
*
*@author     Alexander Kout
*@created    30. M�rz 2002
*/

public class MainListModel
     implements ListModel {
  Vector files;
  MainPanel panel;


  /**
   *  Constructor for the MainListModel object
   *
   *@param  panel       Description of Parameter
   *@param  files       Description of Parameter
   *@param  showHidden  Description of the Parameter
   */
  public MainListModel(MainPanel panel, boolean showHidden) {
    this.panel = panel;
  }


  /**
   *  Gets the size attribute of the MainListModel object
   *
   *@return    The size value
   */
  public int getSize() {
    if (panel.mode == panel.FTP && !panel.ftpSession.connected()) {
      return 0;
    }
    if (files != null) {
      return files.size() + 1;
    } else {
      return 0;
    }
  }


  /**
   *  Gets the elementAt attribute of the MainListModel object
   *
   *@param  index  Description of Parameter
   *@return        The elementAt value
   */
  public Object getElementAt(int index) {
    if (index == 0) {
      return "..";
    }
    if (files.size() >= index && index > 0) {
      return files.elementAt(index - 1);
    } else {
      return new FtpFile();
    }
  }


  /**
   *  Adds a feature to the ListDataListener attribute of the MainListModel
   *  object
   *
   *@param  l  The feature to be added to the ListDataListener attribute
   */
  public void addListDataListener(ListDataListener l) { }


  /**
   *  Description of the Method
   *
   *@param  l  Description of Parameter
   */
  public void removeListDataListener(ListDataListener l) { }


  public void removeElementAt(int i) {
    files.removeElementAt(i);
  }

  public void removeElement(FtpFile f) {
    files.removeElement(f);
  }

  public void addElement(FtpFile f) {
    files.addElement(f);
    ((MainList) panel.view).repaint();
    panel.scrollPane.revalidate();
    panel.scrollPane.repaint();
  }

  /**
   *  Sets the files attribute of the MainTableModel object
   *
   *@param  files       The new files value
   *@param  showHidden  The new files value
   */
  public void setFiles(Vector files, boolean showHidden) {
    if (showHidden) {
      this.files = files;
    } else {
      for (int i = files.size()-1; i >= 0; i--) {
        if (!((FtpFile) files.elementAt(i)).isVisible()) {
          files.removeElementAt(i);
        } else {
          if (((FtpFile) files.elementAt(i)).isFile()) {
            panel.dirSize += ((FtpFile) files.elementAt(i)).getSize();
          }
        }
      }
      this.files = files;
    }
    Utilities.sortFiles(this.files, "Name", false, null);
    ((MainList) panel.view).repaint();
    panel.scrollPane.revalidate();
    panel.scrollPane.repaint();
  }
}
TOP

Related Classes of de.kout.wlFxp.view.MainListModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.