<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Matlab callbacks for Java events	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-callbacks-for-java-events</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 08 Feb 2019 15:21:35 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: RichardST		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-460786</link>

		<dc:creator><![CDATA[RichardST]]></dc:creator>
		<pubDate>Fri, 08 Feb 2019 15:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-460786</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-460774&quot;&gt;RichardST&lt;/a&gt;.

Hello All,
Ok, I see that I was doing wrong.  I needed to:
i) wrap the event in a handle, as per the advice above
ii) change the callback to display the event&#039;s properties
&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; evt = EventTest
evt =
EventTest@5d332969
&gt;&gt; h = handle(evt,&#039;Callbackproperties&#039;)
h =
	javahandle_withcallbacks.EventTest
&gt;&gt; set(evt,&#039;TestEventCallback&#039;,@(h,e)disp([e.newValue e.oldValue]))
&gt;&gt; evt.notifyMyTest
     1     0
&gt;&gt; get(evt)
                    Class: [1×1 java.lang.Class]
        TestEventCallback: @(h,e)disp([e.newValue,e.oldValue])
    TestEventCallbackData: []
&lt;/pre&gt;
Thank you for your help, Yair.
Richard]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-460774">RichardST</a>.</p>
<p>Hello All,<br />
Ok, I see that I was doing wrong.  I needed to:<br />
i) wrap the event in a handle, as per the advice above<br />
ii) change the callback to display the event&#8217;s properties</p>
<pre lang="matlab">
>> evt = EventTest
evt =
EventTest@5d332969
>> h = handle(evt,'Callbackproperties')
h =
	javahandle_withcallbacks.EventTest
>> set(evt,'TestEventCallback',@(h,e)disp([e.newValue e.oldValue]))
>> evt.notifyMyTest
     1     0
>> get(evt)
                    Class: [1×1 java.lang.Class]
        TestEventCallback: @(h,e)disp([e.newValue,e.oldValue])
    TestEventCallbackData: []
</pre>
<p>Thank you for your help, Yair.<br />
Richard</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: RichardST		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-460774</link>

		<dc:creator><![CDATA[RichardST]]></dc:creator>
		<pubDate>Fri, 08 Feb 2019 14:01:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-460774</guid>

					<description><![CDATA[Hello Yair,
Is this still meant to work in later versions of MATLAB?

With my version of
MATLAB  Version 9.4  (R2018a)
My results are:
&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; evt = EventTest
evt =
EventTest@71652c98
&gt;&gt; get(evt)
    Class: [1×1 java.lang.Class]
&gt;&gt; set(evt,&#039;TestEventCallback&#039;,@(h,e)disp(h))
&gt;&gt; evt.notifyMyTest
	javahandle_withcallbacks.EventTest
&lt;/pre&gt;
Have I done something silly?
Thank you for your help.
Richard S-T (who owns both &#039;Undocumented&#039; and &#039;Accelerating&#039;)]]></description>
			<content:encoded><![CDATA[<p>Hello Yair,<br />
Is this still meant to work in later versions of MATLAB?</p>
<p>With my version of<br />
MATLAB  Version 9.4  (R2018a)<br />
My results are:</p>
<pre lang="matlab">
>> evt = EventTest
evt =
EventTest@71652c98
>> get(evt)
    Class: [1×1 java.lang.Class]
>> set(evt,'TestEventCallback',@(h,e)disp(h))
>> evt.notifyMyTest
	javahandle_withcallbacks.EventTest
</pre>
<p>Have I done something silly?<br />
Thank you for your help.<br />
Richard S-T (who owns both &#8216;Undocumented&#8217; and &#8216;Accelerating&#8217;)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jim Hokanson		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-418911</link>

		<dc:creator><![CDATA[Jim Hokanson]]></dc:creator>
		<pubDate>Mon, 05 Feb 2018 04:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-418911</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-230482&quot;&gt;Florian Franzen&lt;/a&gt;.

See http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt

Specifically the callbackOnEDTQueue at the end.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-230482">Florian Franzen</a>.</p>
<p>See <a href="http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt" rel="ugc">http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt</a></p>
<p>Specifically the callbackOnEDTQueue at the end.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Zangdaarr		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-385754</link>

		<dc:creator><![CDATA[Zangdaarr]]></dc:creator>
		<pubDate>Mon, 15 Aug 2016 13:30:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-385754</guid>

					<description><![CDATA[Hi,

This class is really great and helpful, thanks for this ! 
There are however some issues with types and types checking, so I made a small refactor to adress those issues. Changes are essentially not using raw types, and some changes to the &lt;code&gt;notifyMatlab(Object obj, MatlabAction action)&lt;/code&gt; method. Also, I split the sub interface and class in their own files.

&lt;pre lang=&quot;java&quot;&gt;
package com.opalrt.efpgasim.gui.matlablistener;

import java.util.Vector;
import com.opalrt.efpgasim.gui.enumerations.MatlabAction;
/**
 * 
 * @author http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events
 */

public class MatlabEvent {
	
	public interface MatlabListener extends java.util.EventListener {
		void testEvent(MatlabEventObject event);
	}
	
	private Vector data = new Vector();

	public synchronized void addMatlabListener(MatlabListener lis) {
		data.addElement(lis);
	}

	public synchronized void removeMatlabListener(MatlabListener lis) {
		data.removeElement(lis);
	}
	
	public synchronized void printMatlabListener()
	{
		System.out.println(data.toString());
		for (int i = 0; i &lt; data.size(); i++) {
			System.out.println(&quot;i = &quot; + i + &quot; is &quot; + data.elementAt(i).toString());
		}
	}

	public void notifyMatlab(Object obj, MatlabAction action) {
		Vector dataCopy;
		synchronized (this) {
			dataCopy = new Vector(data);
		}

		for (int i = 0; i &lt; dataCopy.size(); i++) {
			MatlabEventObject matlabEvent = new MatlabEventObject(this, obj, action);
			((MatlabListener) dataCopy.elementAt(i)).testEvent(matlabEvent);
		}
	}
	
	public class MatlabEventObject extends java.util.EventObject {
		private static final long serialVersionUID = 1L;
		private Object obj;
		private MatlabAction action;
		
		public MatlabEventObject(Object source, Object obj, MatlabAction action) {
			super(source);
			this.obj = obj;
			this.action = action;
		}

		public Object getObj() {
			return obj;
		}

		public void setObj(Object obj) {
			this.obj = obj;
		}

		public MatlabAction getAction() {
			return action;
		}

		public void setAction(MatlabAction action) {
			this.action = action;
		}		
	}	
}
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>This class is really great and helpful, thanks for this !<br />
There are however some issues with types and types checking, so I made a small refactor to adress those issues. Changes are essentially not using raw types, and some changes to the <code>notifyMatlab(Object obj, MatlabAction action)</code> method. Also, I split the sub interface and class in their own files.</p>
<pre lang="java">
package com.opalrt.efpgasim.gui.matlablistener;

import java.util.Vector;
import com.opalrt.efpgasim.gui.enumerations.MatlabAction;
/**
 * 
 * @author http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events
 */

public class MatlabEvent {
	
	public interface MatlabListener extends java.util.EventListener {
		void testEvent(MatlabEventObject event);
	}
	
	private Vector data = new Vector();

	public synchronized void addMatlabListener(MatlabListener lis) {
		data.addElement(lis);
	}

	public synchronized void removeMatlabListener(MatlabListener lis) {
		data.removeElement(lis);
	}
	
	public synchronized void printMatlabListener()
	{
		System.out.println(data.toString());
		for (int i = 0; i < data.size(); i++) {
			System.out.println("i = " + i + " is " + data.elementAt(i).toString());
		}
	}

	public void notifyMatlab(Object obj, MatlabAction action) {
		Vector dataCopy;
		synchronized (this) {
			dataCopy = new Vector(data);
		}

		for (int i = 0; i < dataCopy.size(); i++) {
			MatlabEventObject matlabEvent = new MatlabEventObject(this, obj, action);
			((MatlabListener) dataCopy.elementAt(i)).testEvent(matlabEvent);
		}
	}
	
	public class MatlabEventObject extends java.util.EventObject {
		private static final long serialVersionUID = 1L;
		private Object obj;
		private MatlabAction action;
		
		public MatlabEventObject(Object source, Object obj, MatlabAction action) {
			super(source);
			this.obj = obj;
			this.action = action;
		}

		public Object getObj() {
			return obj;
		}

		public void setObj(Object obj) {
			this.obj = obj;
		}

		public MatlabAction getAction() {
			return action;
		}

		public void setAction(MatlabAction action) {
			this.action = action;
		}		
	}	
}
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Gogacz		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375604</link>

		<dc:creator><![CDATA[Adam Gogacz]]></dc:creator>
		<pubDate>Tue, 03 May 2016 16:53:15 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-375604</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375590&quot;&gt;Adam Gogacz&lt;/a&gt;.

@Yair
I just checked that &quot;augmentedmatlab.com&quot; domain name is still available :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375590">Adam Gogacz</a>.</p>
<p>@Yair<br />
I just checked that &#8220;augmentedmatlab.com&#8221; domain name is still available 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375597</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 03 May 2016 14:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-375597</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375595&quot;&gt;Adam Gogacz&lt;/a&gt;.

@Adam - if TMW linked to my blog it wouldn&#039;t be &quot;undocumented&quot; Matlab any longer, would it? :-)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375595">Adam Gogacz</a>.</p>
<p>@Adam &#8211; if TMW linked to my blog it wouldn&#8217;t be &#8220;undocumented&#8221; Matlab any longer, would it? 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Gogacz		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375595</link>

		<dc:creator><![CDATA[Adam Gogacz]]></dc:creator>
		<pubDate>Tue, 03 May 2016 13:46:30 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-375595</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375590&quot;&gt;Adam Gogacz&lt;/a&gt;.

@mySelf
The answer is here (http://undocumentedmatlab.com/blog/uicontrol-callbacks#memory_leak) thanks for that post. BTW, I wish Mathworks linked to your articles :).
Thanks again.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375590">Adam Gogacz</a>.</p>
<p>@mySelf<br />
The answer is here (<a href="http://undocumentedmatlab.com/blog/uicontrol-callbacks#memory_leak" rel="ugc">http://undocumentedmatlab.com/blog/uicontrol-callbacks#memory_leak</a>) thanks for that post. BTW, I wish Mathworks linked to your articles :).<br />
Thanks again.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam Gogacz		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-375590</link>

		<dc:creator><![CDATA[Adam Gogacz]]></dc:creator>
		<pubDate>Tue, 03 May 2016 13:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-375590</guid>

					<description><![CDATA[Hi,
Yair, can you comment on the memory leakage associated with using &quot;set&quot; on Java objects( http://www.mathworks.com/help/matlab/ref/set.html )? I frequently use &quot;set&quot; on &quot;ActionPerformedCallback&quot; for Java objects, any workarounds?
KR,
Adam]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
Yair, can you comment on the memory leakage associated with using &#8220;set&#8221; on Java objects( <a href="http://www.mathworks.com/help/matlab/ref/set.html" rel="nofollow ugc">http://www.mathworks.com/help/matlab/ref/set.html</a> )? I frequently use &#8220;set&#8221; on &#8220;ActionPerformedCallback&#8221; for Java objects, any workarounds?<br />
KR,<br />
Adam</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-373933</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 07 Apr 2016 22:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-373933</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-371918&quot;&gt;Dims&lt;/a&gt;.

@Dims - see http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-371918">Dims</a>.</p>
<p>@Dims &#8211; see <a href="http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a" rel="ugc">http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-373932</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 07 Apr 2016 22:22:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1987#comment-373932</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-373920&quot;&gt;Tianxiao Jiang&lt;/a&gt;.

@Tianxiao - see http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a

(and thanks for the note on the dataCopy typo - I fixed it)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events#comment-373920">Tianxiao Jiang</a>.</p>
<p>@Tianxiao &#8211; see <a href="http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a" rel="ugc">http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events-in-r2014a</a></p>
<p>(and thanks for the note on the dataCopy typo &#8211; I fixed it)</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
