Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Making new Flavors : Making a custom transferhandler for and drop applications

Reply
Thread Tools

Making new Flavors : Making a custom transferhandler for and drop applications

 
 
ebby83@gmail.com
Guest
Posts: n/a
 
      01-12-2005
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);
}


}

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

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-12-2005
On 11 Jan 2005 23:55:55 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
ebby83@gmail.com
Guest
Posts: n/a
 
      01-12-2005
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 !!!

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-12-2005
On 12 Jan 2005 01:15:55 -0800, (E-Mail Removed) 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
 
Reply With Quote
 
ebby83@gmail.com
Guest
Posts: n/a
 
      01-12-2005
its googles fault ... not my editor or any other software ...

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-12-2005
On 12 Jan 2005 03:00:55 -0800, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between 1984kbps and 2048kbps (two flavors of E1) lalitgoyal Cisco 0 12-18-2008 07:27 AM
Question on two 'flavors' of data access layers kbutterly ASP .Net 3 01-30-2007 07:54 PM
What to name container "flavors"? Michael Olea C++ 2 07-01-2005 04:25 AM
Detecting Unix flavors Andrew Thompson Java 21 09-08-2004 02:07 AM
OT: CSV flavors Jeff Thies HTML 2 07-22-2004 02:26 AM



Advertisments