Package de.kout.wlFxp.view

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

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

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

/**
*  MouseListener class for the view (Table/List)
*
*@author     Alexander Kout
*@created    29. Juli 2003
*/
class ViewMouseListener implements MouseListener {

  MainPanel panel;
  MouseEvent oldMouseClick;


  /**
   *  Constructor for the ViewMouseListener object
   *
   *@param  panel  Description of the Parameter
   */
  public ViewMouseListener(MainPanel panel) {
    this.panel = panel;
  }


  // MouseListener
  /**
   *  Description of the Method
   *
   *@param  e  Description of Parameter
   */
  public void mouseClicked(MouseEvent e) {
    checkDoubleClick(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
   */
  public void checkPopupMenu(MouseEvent e) {
    if (e.isPopupTrigger()) {
      if (panel.view.getSelectedIndices().length > 1) {
        panel.view.addSelectionInterval(e.getPoint(), e.getPoint());
      } else {
        panel.view.setSelectedIndex(e.getPoint());
      }
      // Men� anzeigen
      panel.contextMenu.show(
          e.getComponent(),
          e.getX(),
          e.getY());
    }
  }


  /**
   *  this method checks for doubleclicks and calls setDir
   *
   *@param  e  Description of Parameter
   */
  public void checkDoubleClick(MouseEvent e) {
    if (oldMouseClick != null && (e.getWhen() - oldMouseClick.getWhen()) < 500 && panel.view.rowAtPoint(e.getPoint()) == panel.view.rowAtPoint(oldMouseClick.getPoint())) {
      oldMouseClick = null;
      Point p = new Point(e.getPoint());
      if (panel.mode == panel.LOCAL) {
        if (panel.view.rowAtPoint(p) == 0) {
          if (new File(panel.dir).getParent() != null) {
            panel.setDir(new File(panel.dir).getParent());
          }
        } else {
          FtpFile entry = (FtpFile) panel.view.getElementAt(p);
          if (entry.isDirectory()) {
            // add the entry
            if (panel.dir.endsWith(File.separator)) {
              panel.setDir(panel.dir + entry.getName());
            } else {
              panel.setDir(panel.dir + File.separator + entry.getName());
            }
          }
        }
      } else if (panel.mode == panel.FTP) {
        // if is Directory
        // make parent
        if (panel.view.rowAtPoint(p) == 0) {
          panel.ftpSession.cdup();
        } else {
          FtpFile entry = (FtpFile) panel.view.getElementAt(p);
          if (entry.isDirectory() || entry.isLink()) {
            // add entry
            if (panel.ftpDir.endsWith("/")) {
              panel.setDir(panel.ftpDir + entry.getName());
            } else {
              panel.setDir(panel.ftpDir + "/" + entry.getName());
            }
          }
        }
      }
    } else {
      oldMouseClick = e;
    }
  }
}
TOP

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

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.