/*
* Created on 2005/02/05
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.commons.swt.ui;
import java.util.List;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
/**
*
*
*/
public class FileListImage extends Canvas implements FileStatusChangeListener{
private List eventListener=new Vector();
private DropTargetListener monitor=new DropMonitor();
public synchronized void removeFileListImageStatusChangeListener(FileListImageStatusChangeListener listener){
eventListener.remove(listener);
}
public synchronized void addFileListImageStatusListener(FileListImageStatusChangeListener listener){
eventListener.add(listener);
}
public void fireImageMode(){
synchronized(this){
FileListImageStatusChangeListener[] listeners=(FileListImageStatusChangeListener[])eventListener.toArray(new FileListImageStatusChangeListener[eventListener.size()]);
for (int i = 0; i < listeners.length; i++) {
listeners[i].imageMode();
}
}
}
public void fireFileMode(){
synchronized(this){
FileListImageStatusChangeListener[] listeners=(FileListImageStatusChangeListener[])eventListener.toArray(new FileListImageStatusChangeListener[eventListener.size()]);
for (int i = 0; i < listeners.length; i++) {
listeners[i].fileMode();
}
}
}
/**
* @param arg0
* @param arg1
* layout.topControl = bArray[index[0]];
parent.layout();
*/
ImageCanvas imageCanvas;
FileListTable fileListTable;
StackLayout layout;
public FileListImage(Composite arg0, int arg1) {
super(arg0, arg1);
layout=new StackLayout();
// TODO Auto-generated constructor stub
this.setLayout(layout);
fileListTable=new FileListTable(this,SWT.NULL);
fileListTable.addFileListChangeListener(this);
imageCanvas=new ImageCanvas(this);
imageMode();
Transfer[] types = new Transfer[] {FileTransfer.getInstance()};
int operations = DND.DROP_MOVE | DND.DROP_COPY ;
DropTarget target2 = new DropTarget (imageCanvas, operations);
target2.setTransfer(types);
target2.addDropListener(new DropMonitor());
}
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++){
fileListTable.addDragAndDropFile(files[i]);
}
checkMode();
}
}
public void setImage(Image img){
imageCanvas.setImage(img);
}
public void checkMode(){
if(fileListTable.getFileCount()>0){
fileMode();
}else{
imageMode();
}
}
public void imageMode(){
layout.topControl=imageCanvas;
this.layout();
fireImageMode();
}
public void fileMode(){
layout.topControl=fileListTable.getTable();
this.layout();
fireFileMode();
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.swt.ui.FileStatusChangeListener#removeList(org.jpn.xucker.commons.swt.ui.FileStatusChangeEvent)
*/
public void removeList(FileStatusChangeEvent event) {
checkMode();
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.swt.ui.FileStatusChangeListener#addList(org.jpn.xucker.commons.swt.ui.FileStatusChangeEvent)
*/
public void addList(FileStatusChangeEvent event) {
// TODO Auto-generated method stub
}
}
|