Implementing Cut/Copy/Paste

J

Jason Cavett

I am reading this tutorial on Data Transfer in Java:
http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html

So far, this is the way I understand it...

1. Data is bundled into a Transferable object. This is done via a
TransferHandler.
2. The Transferable object is stored on the clipboard.
3. When the clipboard is accessed, the TransferHandler extracts the
Transferable object and does whatever needs to be done with this
object.

Also, many/most of the components already have cut/copy/paste
available and ready to be used.

I'm confused about quite a few things, though...

1. I need a generic way to handle all cut/copy/paste methods from
various different objects - JTextField, JTree, JLabels on a JPanel.
The JTextField (sorta) works right now. I'm guessing that's the cut/
copy/paste that's already been implemented. But my JTree holds its
own type of data and my JLabels that I want to cut/copy/paste from the
JPanel do not respond at all. I'm not sure where to begin.

2. Is the TraferHandler a separate class? Is the Transferable object
a separate class or is Transferable implemented by my data object?
What does DataFlavor have to do with anything?

The discussion of drag/drop in the tutorial is confusing me somewhat
and I've searched for some simple examples (all I care about is cut/
copy/paste - I do not care about drag and drop) but I haven't come up
with a whole lot.

Any clarification or simple examples that can be provided would be
much appreciated. I'll keep reading the tutorial and trying things
out.


Thanks
 
A

Andrew Thompson

I am reading this tutorial on Data Transfer in Java:http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html

So far, this is the way I understand it...

I do not have much time (nor a detailed experience
of D'n'D) but can comment..
...
What does DataFlavor have to do with anything?

If you copy text from a table in HTML, it might
be availabe as either an HTML formatted table
(as HTML format) or raw text (with each table
row in a single line). Those are two different
DataFlavors.

(snip)
Any clarification or simple examples that can be provided would be
much appreciated. I'll keep reading the tutorial and trying things
out.

One example that touches o part of what you are
doing is one I did to demonstrate the JNLP API
copy/paste functionality - it is designed to
show DataFlavors.
<http://www.physci.org/jws/#cbs>

HTH

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top