Making new Flavors : Making a custom transferhandler for and drop applications  
Author Message
ebby83





PostPosted: 2005-1-12 15:56:00 Top

java-programmer, Making new Flavors : Making a custom transferhandler for and drop applications Hi all .. im trying to make a simple application thru which i can
accept files of any kind via a drag and drop interface .

I tried making my own transferhandler , but it gives a compilation
problem saying
cannot parse java.io.File

here is the code

--------------------------
//FileTransferHandler.java

package com.tcs.search.classes;

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.*;

public class FileTransferHandler extends javax.swing.TransferHandler {
DataFlavor fileFlavor ;

public FileTransferHandler() {
try {
fileFlavor = new DataFlavor("java.io.File");
}
catch(ClassNotFoundException c)
{ System.out.println(c.getMessage()); }
}

public boolean importData(JComponent c, Transferable t)
{
if (hasFileFlavor(t.getTransferDataFlavors())) {
try {
File f = (File)t.getTransferData(fileFlavor);
return true;
} catch (UnsupportedFlavorException ufe) {
} catch (IOException ioe) { }
}
return false;
}


protected boolean hasFileFlavor(DataFlavor[] flavors)
{
if (fileFlavor == null) {
return false;
}

for (int i = 0; i < flavors.length; i++) {
if (fileFlavor.equals(flavors[i])) {
return true;
}
}
return false;
}
}

--------------------------
//FrontLauncher.java

package com.tcs.search;

import javax.swing.*;
import java.awt.*;
import com.tcs.search.classes.*;

public class FrontLauncher extends JFrame {

public FrontLauncher() {


Container c = this.getContentPane();
JEditorPane ep = new JEditorPane();
c.add(ep);
ep.setDragEnabled(true);
//ep.setDropTarget(this);

ep.setTransferHandler(new FileTransferHandler());
}

public static void main(String[] args) {
FrontLauncher frame = new FrontLauncher();
frame.setSize(500, 400);
frame.setTitle("FrontLauncher");
frame.setVisible(true);
}


}

--------------------------

 
Andrew Thompson





PostPosted: 2005-1-12 16:30:00 Top

java-programmer >> Making new Flavors : Making a custom transferhandler for and drop applications On 11 Jan 2005 23:55:55 -0800, email***@***.com wrote:

> public class FileTransferHandler extends javax.swing.TransferHandler {
> DataFlavor fileFlavor ;

Please indent code (with 2 or three spaces, rather than tabs) you post.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
ebby83





PostPosted: 2005-1-12 17:16:00 Top

java-programmer >> Making new Flavors : Making a custom transferhandler for and drop applications Well I tried some changes .. and this version works ( well it compiled
) but I still am unable to drag and drop files from the system to this
application

FrontLauncher.java ::
-----------------------------
package com.tcs.search;

import javax.swing.*;
import java.awt.*;
import com.tcs.search.classes.*;

public class FrontLauncher extends JFrame {

public FrontLauncher()
{
Container c = this.getContentPane();
JEditorPane ep = new JEditorPane();
c.add(ep);
ep.setDragEnabled(true);


ep.setTransferHandler(new FileTransferHandler());
}

public static void main(String[] args) {
FrontLauncher frame = new FrontLauncher();
frame.setSize(500, 400);
frame.setTitle("FrontLauncher");
frame.setVisible(true);
}
}
-----------------------------



FileTransferHandler.java::
-----------------------------
package com.tcs.search.classes;

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

public class FileTransferHandler extends javax.swing.TransferHandler {
DataFlavor fileFlavor ;

public FileTransferHandler()
{
fileFlavor = DataFlavor.javaFileListFlavor;
}

public boolean importData(JComponent c, Transferable t)
{
if (hasFileFlavor(t.getTransferDataFlavors())) {
try {
java.util.List fileList =
(java.util.List)t.getTransferData(fileFlavor);
return true;
} catch (UnsupportedFlavorException ufe) {
} catch (IOException ioe) { }
}
return false;
}


protected boolean hasFileFlavor(DataFlavor[] flavors)
{
if (fileFlavor == null) {
return false;
}

for (int i = 0; i < flavors.length; i++) {
if (fileFlavor.equals(flavors[i])) {
return true;
}
}
return false;
}
}
-----------------------------

PS -- Sorry about the format of the CODE , but when i post the message
part of the indentation mysteriously dissapears !!!

 
 
Andrew Thompson





PostPosted: 2005-1-12 17:49:00 Top

java-programmer >> Making new Flavors : Making a custom transferhandler for and drop applications On 12 Jan 2005 01:15:55 -0800, email***@***.com wrote:

(snip horridly unindented code)

> } catch (UnsupportedFlavorException ufe) {
> } catch (IOException ioe) { }
> }

(Begin to) find out what is happening..
<http://www.physci.org/codes/javafaq.jsp#stacktrace>

> PS -- Sorry about the format of the CODE , but when i post the message
> part of the indentation mysteriously dissapears !!!

Please change your software or get it fixed* by the manufacturer.

[ * Please lodge a bug report. ]

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
 
ebby83





PostPosted: 2005-1-12 19:01:00 Top

java-programmer >> Making new Flavors : Making a custom transferhandler for and drop applications its googles fault ... not my editor or any other software ...

 
 
Andrew Thompson





PostPosted: 2005-1-12 19:10:00 Top

java-programmer >> Making new Flavors : Making a custom transferhandler for and drop applications On 12 Jan 2005 03:00:55 -0800, email***@***.com wrote:

> its googles fault ...

I realise that Google is the source of the problem.

[ But as an aside, you can also change usenet internet-portal
and stop the problem from happening. It is ultimately *your*
decision as to whether to continue using such a broken
interface, (and potentially get less answers,) or change
to another provider that does not cause the problem. ]

>...not my editor or any other software ...

So *report* it to *Google*. (Please)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane