/**
* 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.io.*;
import de.kout.wlFxp.ftp.FtpFile;
/**
* checks for enters and changes directory in view accordingly
*
*@author Alexander Kout
*@created 29. Juli 2003
*/
class ViewKeyListener implements KeyListener {
MainPanel panel;
/**
* Constructor for the ViewKeyListener object
*
*@param panel Description of the Parameter
*/
public ViewKeyListener(MainPanel panel) {
this.panel = panel;
}
/**
* method that is called by the KeyListener
*
*@param e the KeyEvent
*/
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
int row = panel.view.getSelectedIndex();
if (panel.mode == panel.LOCAL) {
if (row == 0) {
if (new File(panel.dir).getParent() != null) {
panel.setDir(new File(panel.dir).getParent());
}
} else {
FtpFile entry = (FtpFile) panel.view.getElementAt(row);
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 (row == 0) {
panel.ftpSession.cdup();
} else {
FtpFile entry = (FtpFile) panel.view.getElementAt(row);
if (entry.isDirectory() || entry.isLink()) {
// add entry
if (panel.ftpDir.endsWith("/")) {
panel.setDir(panel.ftpDir + entry.getName());
} else {
panel.setDir(panel.ftpDir + "/" + entry.getName());
}
}
}
}
}
}
/**
* another mothod of the KeyListener
*
*@param event KeyEvent
*/
public void keyReleased(KeyEvent event) { }
/**
* another mothod of the KeyListener
*
*@param event KeyEvent
*/
public void keyTyped(KeyEvent event) { }
}