Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Java drag & drop
Date: Wed, 22 Aug 2007 15:51:14 +0000 (UTC)
Organization: King's College London
Lines: 78
Message-ID: <fahm1i$5e7$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187797874 5575 172.30.248.38 (22 Aug 2007 15:51:14 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 22 Aug 2007 15:51:14 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1477
Xref: news.mathworks.com comp.soft-sys.matlab:424979



Here are two attempts to implement drop & drag. The second 
method is successful in invoking the callback, but access 
to hObj and EventData (e,g, through get) then cause 
exceptions. Does anyone (are you there Yair) have any ideas?

function droptrial()
f=figure();
j=javacomponent('javax.swing.JComboBox',[],f);
j.setEditable(true);
e=get(j.Editor,'EditorComponent');

% METHOD 1
% This produces an exception and fails:
dnd=e.getDropTarget();
set(dnd, 'DropCallback', @MyCallback);

% METHOD 2
% This works but calls like get(hObj) produce exceptions in 
the callback
dnd=java.awt.dnd.DropTarget();
set(dnd, 'DropCallback', @MyCallback);
e.setDropTarget(dnd);
return
end

function MyCallback(hObj, Ev)
get(hObj);
return
end

METHOD1 produces
java.lang.IllegalAccessException: Class 
com.mathworks.jmi.bean.MatlabBeanInterface can not access a 
member of class javax.swing.TransferHandler$SwingDropTarget 
with modifiers "public"
	at sun.reflect.Reflection.ensureMemberAccess
(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at 
com.mathworks.jmi.bean.MatlabBeanInterface.addCallback
(MatlabBeanInterface.java:691)
	at 
com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback
(MatlabCallbackInterface.java:128)


METHOD2, when get(hObj) is called from the callback after 
making a drop (from a JTree) produces
K>> get(hObj)
	Active = on
	Class = [ (1 by 1) java.lang.Class array]
	Component = [ (1 by 1) 
javax.swing.plaf.metal.MetalComboBoxEditor$1 array]
	DefaultActions = [3]
	DropTargetContext = [ (1 by 1) 
java.awt.dnd.DropTargetContext array]
	FlavorMap = [ (1 by 1) 
java.awt.datatransfer.SystemFlavorMap array]
	DropCallback = [ (1 by 1) function_handle array]
	DropCallbackDatajava.lang.reflect.InvocationTargetEx
ception
	at sun.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke
(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke
(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.mathworks.jmi.bean.ClassInfo.getObjectField
(ClassInfo.java:323)
Caused by: java.awt.dnd.InvalidDnDOperationException: The 
operation requested cannot be performed by the DnD system 
since it is not in the appropriate state
	at java.awt.dnd.DropTargetContext.getTransferable
(Unknown Source)
	at java.awt.dnd.DropTargetDropEvent.getTransferable
(Unknown Source)
	... 5 more