Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to intercept pasting from clipboard  RSS feed

 
Slavko Perevalov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I need some help with pasting components from clipboard.
Is there any way to intercept data that is to be pasted before pasting completes ?

Code fragment below shows how I implemented working with clipboard:

JToolBar toolbar = new JToolBar();
toolbar.setFloatable(false);
........
paste = new EventRedirector(graph,
javax.swing.TransferHandler.getPasteAction(),
loadIconFromPath("resources/paste.gif"));
toolbar.add(paste);
........

where EventRedirector looks like

public class EventRedirector extends AbstractAction {
.........
public EventRedirector(Object source, Action action, ImageIcon icon) {
super("", icon);
this.action = action;
this.source = source;
}

.........
public void actionPerformed(ActionEvent event) {
event =
new ActionEvent(source, event.getID(),
event.getActionCommand(), event.getModifiers());
action.actionPerformed(event);
}
.........
}

This question caused by the following: created copy of the component holds link to the data model of the origin so when we edit copy all changes will be displayed for both objects.

The only idea visited my far from brilliant head was to add a listener that would get reference to the copy and clones data model for it. Can I do it or may be you suggest another decision.

Thank you!
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.awt.datatransfer.ClipboardOwner
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!