dndlist.java

来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 214 行

JAVA
214
字号
/**  * File and FTP Explorer  * Copyright 2002  * BOESCH Vincent  *  * 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 javaexplorer.gui.dnd;import java.awt.*;import java.awt.datatransfer.*;import java.awt.dnd.*;import java.awt.event.*;import java.io.IOException;import javaexplorer.Launcher;import javaexplorer.model.*;/** *@author     BOESCH Vincent *@created    21 janvier 2002 *@version    3.3 */public class DNDList extends XList implements DragSourceListener,    DragGestureListener, DropTargetListener {    private Launcher _launcher = null;    /**     *  enables this component to be a dropTarget     */    DropTarget dropTarget = null;    /**     *  constructor - initializes the DropTarget     *  and DragSource.     *     *@param  launcher  Description of the     *      Parameter     */    public DNDList(Launcher launcher) {        _launcher = launcher;        dropTarget = new DropTarget(this, this);        //dragSource.createDragGestureRecognizer( MouseRightDragGestureRecognizer.class, this, DnDConstants.ACTION_COPY_OR_MOVE, this);        DragGestureRecognizer dgr = _launcher.getDragSource()                                             .createDragGestureRecognizer(MouseRightDragGestureRecognizer.class,                this, DnDConstants.ACTION_COPY_OR_MOVE, this);        if (dgr == null) {            _launcher.getDragSource().createDefaultDragGestureRecognizer(this,                DnDConstants.ACTION_COPY_OR_MOVE, this);        }        this.addMouseListener(new MouseAdapter() {            });    }    /**     *  this message goes to DragSourceListener,     *  informing it that the dragging has     *  ended     *     *@param  event  Description of the Parameter     */    public void dragDropEnd(DragSourceDropEvent event) {    }    /**     *  is invoked when you are dragging over     *  the DropSite     *     *@param  event  Description of the Parameter     */    public void dragEnter(DropTargetDragEvent event) {        event.acceptDrag(DnDConstants.ACTION_MOVE);    }    /**     *  this message goes to DragSourceListener,     *  informing it that the dragging has     *  entered the DropSite     *     *@param  event  Description of the Parameter     */    public void dragEnter(DragSourceDragEvent event) {    }    /**     *  is invoked when you are exit the DropSite     *  without dropping     *     *@param  event  Description of the Parameter     */    public void dragExit(DropTargetEvent event) {    }    /**     *  this message goes to DragSourceListener,     *  informing it that the dragging has     *  exited the DropSite     *     *@param  event  Description of the Parameter     */    public void dragExit(DragSourceEvent event) {    }    /**     *  a drag gesture has been initiated     *     *@param  event  Description of the Parameter     */    public void dragGestureRecognized(DragGestureEvent event) {        Object[] objs = getSelectedValues();        if (objs == null) {            return;        }        XFile[] efs = new XFile[objs.length];        for (int i = 0; i < objs.length; i++) {            efs[i] = (XFile) objs[i];        }        XFTransferable xft = new XFTransferable(efs);        // as the name suggests, starts the dragging        _launcher.getDragSource().startDrag(event, DragSource.DefaultMoveDrop,            xft, this);    }    /**     *  is invoked when a drag operation is     *  going on     *     *@param  event  Description of the Parameter     */    public void dragOver(DropTargetDragEvent event) {    }    /**     *  this message goes to DragSourceListener,     *  informing it that the dragging is currently     *  ocurring over the DropSite     *     *@param  event  Description of the Parameter     */    public void dragOver(DragSourceDragEvent event) {    }    /**     *  is invoked when the user changes the     *  dropAction     *     *@param  event  Description of the Parameter     */    public void dropActionChanged(DragSourceDragEvent event) {    }    public void dropActionChanged(DropTargetDragEvent dtde) {    }    public void drop(DropTargetDropEvent event) {        XFile[] tbxf = null;        XFile f = null;        Point p = null;        try {            p = event.getLocation();            if (this.getModel().getSize() == 0) {                f = this.getRoot();            } else {                int index = this.locationToIndex(p);                if (index >= 0) {                    f = (XFile) this.getModel().getElementAt(index);                } else {                    f = this.getRoot();                }            }            if (f == null) {                return;            }            if (!f.isDirectory()) {                f = f.getXParent();            }            Transferable transferable = event.getTransferable();            // we accept only Strings            if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {                event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);                tbxf = (XFile[]) transferable.getTransferData(DataFlavor.stringFlavor);                f.setLauncher(_launcher);                //Fin du drop pour mise 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?