Package de.kout.wlFxp.view

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

/**
* 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.awt.*;
import java.awt.event.*;
import java.util.*;

import de.kout.wlFxp.ftp.Transfer;
import de.kout.wlFxp.*;

/**
*  Queue
*
*@author     Alexander Kout
*@created    03. April 2002
*/

public class QueueList
     extends JList
     implements MouseListener, wlQueueList {

  QueueContextMenu contextMenu;
  Vector vfiles;
  MainFrame frame;
  boolean transfering;
  long size;
 


  /**
   *  Constructor for the QueueList object
   *
   *@param  frame  Description of the Parameter
   */
  public QueueList(MainFrame frame) {
    super();
    this.frame = frame;
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    setFont(new Font("SansSerif", Font.PLAIN, 12));
    setFixedCellHeight(20);
    // custom CellRenderer
    setCellRenderer(new QueueCellRenderer());
    addMouseListener(this);

    contextMenu = new QueueContextMenu(this);
    vfiles = new Vector(150);
    setModel(new CustomListModel(vfiles));
  }
 
  public int getCount() {
    return vfiles.size();
  }
 
  public long getQueueSize() {
    return size;
  }


  /**
   *  Sets the data attribute of the QueueList object
   *
   *@param  v  The new data value
   */
  public void setData(Vector v) {
    if (vfiles != v) {
      vfiles = v;
      setModel(new CustomListModel(vfiles));
      size = 0;
      for (int i = 0; i < vfiles.size(); i++)
        size += ((Transfer) vfiles.elementAt(i)).getSource().getSize();
    } else
      updateView();
  }


  /**
   *  Gets the data attribute of the QueueList object
   *
   *@return    The data value
   */
  public Vector getData() {
    return vfiles;
  }


  /**
   *  Adds a feature to the AtBegin attribute of the QueueList object
   *
   *@param  transfer  The feature to be added to the AtBegin attribute
   */
  public void addAtBegin(Transfer transfer) {
    vfiles.insertElementAt(transfer, 0);
    size += transfer.getSource().getSize();
  }


  /**
   *  Adds a feature to the Element attribute of the QueueList object
   *
   *@param  transfer  The feature to be added to the Element attribute
   */
  public void addElement(Transfer transfer) {
    vfiles.addElement(transfer);
    size += transfer.getSource().getSize();
  }


  /**
   *  Description of the Method
   *
   *@param  t  Description of the Parameter
   *@param  i  Description of the Parameter
   */
  public void insertElementAt(Transfer t, int i) {
    vfiles.insertElementAt(t, i);
    size += t.getSource().getSize();
  }


  /**
   *  Gets the element attribute of the QueueList object
   *
   *@return    The element value
   */
  public Transfer getElement() {
    Transfer t = (Transfer) vfiles.firstElement();
    return t;
  }


  /**
   *  Description of the Method
   *
   *@param  i  Description of the Parameter
   *@return    Description of the Return Value
   */
  public Transfer elementAt(int i) {
    return (Transfer) vfiles.elementAt(i);
  }


  /**
   *  Description of the Method
   */
  public void removeFirst() {
    if (vfiles.size() > 0) {
      size -= ((Transfer) vfiles.elementAt(0)).getSource().getSize();
      vfiles.removeElementAt(0);
    }
  }


  /**
   *  Description of the Method
   *
   *@param  i  Description of the Parameter
   */
  public void removeElementAt(int i) {
    size -= ((Transfer) vfiles.elementAt(i)).getSource().getSize();
    vfiles.removeElementAt(i);
  }


  /**
   *  Description of the Method
   *
   *@param  rows  Description of the Parameter
   */
  public void delete(int[] rows) {
    int[] index = new int[rows.length];
    for (int i = 0; i < rows.length; i++) {
      index[i] = vfiles.size() - rows[i];
    }
    for (int i = 0; i < index.length; i++) {
      if (!transfering && index[i] <= vfiles.size() && index[i] > -1) {
        removeElementAt(vfiles.size() - index[i]);
      } else if (index[i] < vfiles.size() && index[i] > -1) {
        removeElementAt(vfiles.size() - index[i]);
      }
    }
    updateView();
  }


  /**
   *  Description of the Method
   *
   *@param  a  Description of the Parameter
   */
  public void moveUp(int[] a) {
    int[] index = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      index[i] = vfiles.size() - a[i];
    }
    for (int i = 0; i < a.length; i++) {
      int b = index[i];
      if (b > -1 && b < vfiles.size()) {
        Transfer t = (Transfer) vfiles.elementAt(vfiles.size() - b);
        if (!transfering || b < vfiles.size() - 1) {
          vfiles.removeElementAt(vfiles.size() - b);
          vfiles.insertElementAt(t, vfiles.size() - b);
        }
        updateView();
      }
    }
  }


  /**
   *  Description of the Method
   *
   *@param  a  Description of the Parameter
   */
  public void moveDown(int[] a) {
    int[] index = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      index[i] = vfiles.size() - a[i];
    }
    for (int i = a.length - 1; i >= 0; i--) {
      int b = index[i];
      if (b > 1 && b <= vfiles.size()) {
        Transfer t = (Transfer) vfiles.elementAt(vfiles.size() - b);
        if (!transfering || b != vfiles.size()) {
          vfiles.removeElementAt(vfiles.size() - b);
          vfiles.insertElementAt(t, vfiles.size() - b + 2);
        }
        updateView();
      }
    }
  }


  /**
   *  Description of the Method
   *
   *@param  a  Description of the Parameter
   */
  public void moveTop(int[] a) {
    int[] index = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      index[i] = vfiles.size() - a[i];
    }
    for (int i = 0; i < a.length; i++) {
      int b = index[i];
      if (b > -1 && b < vfiles.size()) {
        Transfer t = (Transfer) vfiles.elementAt(vfiles.size() - b);
        if (!transfering) {
          vfiles.removeElementAt(vfiles.size() - b);
          vfiles.insertElementAt(t, i);
        } else if (b < vfiles.size() - 1) {
          vfiles.removeElementAt(vfiles.size() - b);
          vfiles.insertElementAt(t, i + 1);
        }
        updateView();
      }
    }
  }


  /**
   *  Description of the Method
   *
   *@param  a  Description of the Parameter
   */
  public void moveBottom(int[] a) {
    int[] index = new int[a.length];
    for (int i = 0; i < a.length; i++) {
      index[i] = vfiles.size() - a[i];
    }
    for (int i = a.length - 1; i >= 0; i--) {
      int b = index[i];
      if (b > 1 && b <= vfiles.size()) {
        Transfer t = (Transfer) vfiles.elementAt(vfiles.size() - b);
        if (!transfering || b != vfiles.size()) {
          vfiles.removeElementAt(vfiles.size() - b);
          vfiles.insertElementAt(t, vfiles.size());
        }
        updateView();
      }
    }
  }


  /**
   *  Sets the transfering attribute of the QueueList object
   *
   *@param  t  The new transfering value
   */
  public void setTransfering(boolean t) {
    transfering = t;
    contextMenu.edit.setEnabled(!t);
    contextMenu.load.setEnabled(!t);
    contextMenu.save.setEnabled(!t);
  }


  /**
   *  Sets the loadSave attribute of the QueueList object
   *
   *@param  b  The new loadSave value
   */
  public void setLoadSave(boolean b) {
    contextMenu.load.setEnabled(b);
    contextMenu.save.setEnabled(b);
  }


  /**
   *  Description of the Method
   */
  public void clear() {
    vfiles.clear();
    size = 0;
    updateView();
  }


  /**
   *  Gets the empty attribute of the QueueList object
   *
   *@return    The empty value
   */
  public boolean isEmpty() {
    return vfiles.isEmpty();
  }


  /**
   *  Description of the Method
   */
  public void updateView() {
    Runnable update =
      new Runnable() {
        public void run() {
          revalidate();
          frame.queueScrollPane.revalidate();
          frame.queueScrollPane.repaint();
        }
      };
    SwingUtilities.invokeLater(update);
  }


  // MouseListener
  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mouseClicked(MouseEvent e) {
    checkPopupMenu(e);
  }


  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mouseEntered(MouseEvent e) { }


  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mouseExited(MouseEvent e) { }


  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mousePressed(MouseEvent e) {
    checkPopupMenu(e);
  }


  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mouseReleased(MouseEvent e) {
    checkPopupMenu(e);
  }


  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   *@return    Description of the Returned Value
   */
  public int checkPopupMenu(MouseEvent e) {
    if (e.isPopupTrigger()) {
      if (getSelectedIndices().length > 1) {
        addSelectionInterval(locationToIndex(e.getPoint()), locationToIndex(e.getPoint()));
      } else {
        setSelectedIndex(locationToIndex(e.getPoint()));
      }
      // Men� anzeigen
      contextMenu.show(
          e.getComponent(),
          e.getX(),
          e.getY());
      return 0;
    }
    return -1;
  }

}
TOP

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

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.