/*
* Created on 2004/08/16
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.commons.swt.ui;
import java.io.File;
import java.util.List;
import java.util.Vector;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
/**
*
*
*/
public class FileStatusChanger {
private List fileListChangeListener=new Vector();
private DropTargetListener monitor=new DropMonitor();
public synchronized void removeFileListChangeListener(FileStatusChangeListener listener){
fileListChangeListener.remove(listener);
}
public synchronized void addFileListChangeListener(FileStatusChangeListener listener){
fileListChangeListener.add(listener);
}
public void fireRemoveFile(String file){
FileStatusChangeEvent event=new FileStatusChangeEvent(this,file);
synchronized(this){
FileStatusChangeListener[] listeners=(FileStatusChangeListener[])fileListChangeListener.toArray(new FileStatusChangeListener[fileListChangeListener.size()]);
for (int i = 0; i < listeners.length; i++) {
listeners[i].removeList(event);
}
}
}
public void fireAddFile(String file){
FileStatusChangeEvent event=new FileStatusChangeEvent(this,file);
synchronized(this){
FileStatusChangeListener[] listeners=(FileStatusChangeListener[])fileListChangeListener.toArray(new FileStatusChangeListener[fileListChangeListener.size()]);
for (int i = 0; i < listeners.length; i++) {
listeners[i].addList(event);
}
}
}
protected void addDirectoryPath(String path){}
protected void addFilePath(String path){}
public class DropMonitor extends DropTargetAdapter{
public void dragEnter(DropTargetEvent event){
//System.out.println("drag enter:"+event.data);
}
public void dragOver(DropTargetEvent event){
//System.out.println("drag over:"+event.data);
}
public void drop(DropTargetEvent event){
//System.out.println("drop:"+event.data);
//System.out.println(event.data.getClass().getName());
String files[]=(String[])event.data;
for(int i=0;i<files.length;i++){
addDragAndDropFile(files[i]);
}
}
}
public void addDragAndDropFile(String path){
File file=new File(path);
if(file.isDirectory()){
addDirectoryPath(path);
}else{
addFilePath(path);
}
}
/**
* @return
*/
public DropTargetListener getMonitor() {
// TODO Auto-generated method stub
return monitor;
}
}
|