Incompatibilidade

Ola pessoal

Eu criei um visualizador de figuras em que para ve-las o usuario deve fazer drag and drop de um arquivo

No Win2000 Advanced Server a aplicacao funcionou perfeitamente mas no Red Hat Linux 8 a excecao UnsupportedFlavorException esta ocorrendo. Alguem sabe por que? Alguem sabe como eu poderia consertar isso?
O mesmo problema segue com um web Browser que criei que permitia o drag and drop de arquivo .html

Segue abaixo o codigo completo da app:

// Visualizador.java
// Visualizador de figuras

import javax.swing.filechooser.;
import java.awt.
;
import javax.swing.;
import java.io.
;
import java.util.;
import java.awt.dnd.
;
import java.awt.datatransfer.*;

public class Visualizador extends JFrame
{
JPanel panel;
Container c;
JOptionPane jop;
public ImageViewerLabel l;
String image;

public Visualizador()
{
	super("Visualizador de figuras");
	l = new ImageViewerLabel();

	jop = new JOptionPane();
	setImage("figura.jpg", l);
	c = getContentPane();
	c.add(l);

}

public void setImage(String i, ImageViewerLabel label)
{
	image = i;
	label.setIcon(new ImageIcon(image));
	pack();
	
}

	// inner class to handle DropTargetEvents
private class ImageViewerLabel extends JLabel implements DropTargetListener 
{ 
	private DropTarget dropTarget = null;
	private ImageViewerLabel()
	{
		super();
		dropTarget = new DropTarget(this,DnDConstants.ACTION_COPY_OR_MOVE, this, true);

	}

	// handle drop operation
	public void drop( DropTargetDropEvent event )
	{
		event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
		
		// get dropped Transferable object
		Transferable transferable = event.getTransferable();


			// process list of files
			try 
			{
				// if Transferable is a List of Files, accept drop
				if (((event.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) ) 
				{
					// get List of Files
					java.util.List imageList =  (java.util.List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
					File file = (File)imageList.get(0);
					String sFileName = file.getAbsolutePath();
					System.out.println("Dropped File:"+sFileName);
					setIcon(new ImageIcon(sFileName));
					pack();
					

					// indicate successful drop
					event.dropComplete( true );
				}

				else
				{
					event.rejectDrop();
					jop.showMessageDialog(null, "File type not supported", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}

			// handle exception if DataFlavor not supported
			catch ( UnsupportedFlavorException flavorException ) 
			{
				flavorException.printStackTrace();
				event.dropComplete( false );
				jop.showMessageDialog(null, "File type not supported", "Error", JOptionPane.ERROR_MESSAGE);

			}

			// handle exception reading Transferable data
			catch ( IOException ioException ) 
			{
				ioException.printStackTrace();
				event.dropComplete( false );
			}
			

			// if dropped object is not file list, reject drop
	
		}

		// handle drag operation entering DropTarget
		public void dragEnter( DropTargetDragEvent event )
		{
     		event.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);       
		}

	// invoked when drag operation exits DropTarget
	public void dragExit( DropTargetEvent event ) {}

	// invoked when drag operation occurs over DropTarget
	public void dragOver( DropTargetDragEvent event ) {}

	// invoked if dropAction changes (e.g., from COPY to LINK)
	public void dropActionChanged( DropTargetDragEvent event )
	{}

} // end class DropTargetHandler

public static void main(String[] args)
{
	Visualizador v = new Visualizador();
	v.setDefaultCloseOperation( EXIT_ON_CLOSE );
	v.pack();
	v.setVisible( true );
}

}

Agradeco e desculpem-me pelo codigo gigante…

Wellington

Não tenho muita certeza, mas me parece que o flavor DataFlavor.javaFileListFlavor não é suportado pelo DnD do Linux. Aliás, convenhamos, Drag-n-Drop no X Window é um lixo :slight_smile:

Funciona (ou pelo menos para de dar essa exception) se vc muda de flavor?