<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
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/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Undocumented Matlab &#187; Figure window</title> <atom:link href="http://undocumentedmatlab.com/blog/category/figure-window/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Wed, 08 Feb 2012 18:40:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>Docking figures in compiled applications</title><link>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/</link> <comments>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#comments</comments> <pubDate>Wed, 15 Jun 2011 18:00:56 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Compiler]]></category> <category><![CDATA[Docking]]></category> <category><![CDATA[Figure]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2341</guid> <description><![CDATA[Figures in compiled applications cannot officially be docked since R2008a, but this can be done using a simple undocumented trick.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/jmi-wrapper-local-matlabcontrol-part-2/' rel='bookmark' title='JMI wrapper &#8211; local MatlabControl part 2'>JMI wrapper &#8211; local MatlabControl part 2</a> <small>An example using matlabcontrol for calling Matlab from within a Java class is explained and discussed...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Up until Matlab release R2008a, the Matlab compiler enabled compiled Matlab applications to have dockable figure windows, which docked into a &#8220;Figures&#8221; container. <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-A6XFET/">Starting with R2008a</a>, the compiler removed the figure&#8217;s docking capability and figures can no longer be docked.</p><p>Well, at least not officially <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p>The following trick restores the docking controls to figures in R2008a-compiled applications, enabling figure docking. Simply add one or both of the following alternatives in your application, after the figure has been created:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternative #1 - uses pure Matlab</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'DockControls'</span>, <span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative #2 - uses the underlying Java frame</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">try</span>
   <span style="color: #228B22;">% This works up to R2011a</span>
   jFrame.<span style="">fFigureClient</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #228B22;">% This works from R2008b and up</span>
   jFrame.<span style="">fHG1Client</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>where <code>hFig</code> is the figure handle. This will have no effect for the regular interpreted (non-compiled) run of the application, where these controls are &#8216;on&#8217; by default. But in the compiled application, although it may erroneously report that the controls are &#8216;on&#8217;, they are in fact &#8216;off&#8217;, so turning them &#8216;on&#8217; fixes the problem.</p><p><center><div
class="wp-caption aligncenter" style="width: 478px"><img
alt="Matlab figure docking control" src="http://UndocumentedMatlab.com/images/dock4.png" title="Matlab figure docking control" width="468" /><p
class="wp-caption-text">Matlab figure docking control</p></div></center></p><p><u>Note</u>: the two variants in alternative #2 above are actually identical, it is simply that the relevant field name has changed: Up to R2008a, only the <code>fFigureClient</code> existed; in R2008b, the <code>fHG1Client</code> field was added, which was simply an alias for <code>fFigureClient</code>, holding the same reference handle, so either of these fields could be used (a corresponding fHG2Client was also added &#8211; more on HG1 and HG2 <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/hg2/">here</a>). In R2011b (at least the pre-release), the <code>fFigureClient</code> alias field was dropped and only <code>fHG1Client</code> remained. While the field name has changed, the underlying docking functionality appears to have remained stable over all these releases. For the record, in answer to a <a
href="http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#comment-48632">user question below</a>, these fields can be listed using the built in <i><b>fieldnames</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% R2008b - R2011a:</span>
&gt;&gt; <span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span>jFrame<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
    <span style="color:#A020F0;">'fFigureClient'</span>
    <span style="color:#A020F0;">'fHG2Client'</span>
    <span style="color:#A020F0;">'fHG1Client'</span>
    <span style="color:#A020F0;">'fUseHG2'</span>
    <span style="color:#A020F0;">'UICONTROLBACKGROUND_OS'</span>
    <span style="color:#A020F0;">'UICONTROLBACKGROUND_COMPATIBLE'</span></pre></div></div><p>I was reminded of this trick by <a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/#comment-47197">Aurélien&#8217;s recent comment</a>, where he mentions MathWorks so-called workaround for this problem, which (IMHO) is really not a work-around at all: MathWorks advises to modify our application to use &#8211; would you believe this &#8211; tabbed panels to &#8220;dock&#8221; the separate figures contents onto separate panels. Not to mention the fact that this so-called &#8220;solution&#8221; relies on undocumented and unsupported Matlab functionality (that of <a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/">tabbed-panels</a>) and requires major rework of existing applications, it also results in far inferior look-and-feel than simple docking as G-d intended&#8230;</p><p>Since I have demonstrated above that the docking functionality actually exists in compiled apps just as in the interpreted m-file apps, I do not understand why MathWorks took such great pains to prevent this important functionality in the compiler. There must be some important reason for this, but I cannot think of any. Perhaps if there is enough public demand, MathWorks will agree to return the docking functionality.</p><p>Unfortunately, I recently discovered that in the most recent compiler, that ships with R2011a, alternative #1 above (which uses pure Matlab) no longer works. Sometime between R2008a and R2011a MathWorks discovered my first back-door and closed it. Such a pity&#8230;</p><p>Luckily, alternative #2 (which uses the underlying Java frame object) seems to still work, even on R2011a.</p><p>I still haven&#8217;t tested this on R2011b&#8217;s compiler (whose pre-release has become available for download yesterday), but hopefully the trick above will continue to work on R2011b and on subsequent releases &#8211; please <a
href="http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#respond">tell me</a> if you find out otherwise.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/jmi-wrapper-local-matlabcontrol-part-2/' rel='bookmark' title='JMI wrapper &#8211; local MatlabControl part 2'>JMI wrapper &#8211; local MatlabControl part 2</a> <small>An example using matlabcontrol for calling Matlab from within a Java class is explained and discussed...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>Minimize/maximize figure window</title><link>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#comments</comments> <pubDate>Wed, 18 May 2011 23:08:07 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2310</guid> <description><![CDATA[Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Over the past couple of years, I posted <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/javaframe/">several articles</a> using the <b>JavaFrame</b> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object. Today, I show how using <b>JavaFrame</b> we can solve a very frequent user request on the Matlab CSSM forum.</p><h3 id="Problem">The problem</h3><p>Matlab figures can be maximized, minimized and restored by <em>interactively</em> clicking the corresponding icon (or menu item) on the figure window&#8217;s frame (the title bar). However, we often need to create maximized main-application windows, and wish to save the users the need to manually maximize the window. Moreover, we may sometimes even wish to prevent users from resizing a maximized main window.</p><p>Unfortunately, Matlab does not contain any documented or supported way to <em>programmatically</em> maximize, minimize or restore a figure window.</p><p>This is very strange considering the fact that these are such elementary figure operations. Moreover, these operations are supported internally (and have been for many releases already), as shown below. It is therefore difficult for me to understand why they were not added to the documented Matlab HG wrapper functionality a long time ago. I fail to understand why obscure features such as docking were added to the wrapper, but standard minimization and maximization were not.</p><h3 id="Maximization">Maximization</h3><p><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/?term=maximize+window">Several solutions</a> have been presented to this problem over the years. Let us start with the pressing question of figure maximization:</p><p>Solutions that rely on documented Matlab features tend to compute the available screen size and resize the figure accordingly. The result is lacking in many respects: it does not account for the taskbar (neither in size nor in location, which is not necessarily at the bottom of the screen); it does not remove the window border as in regular maximized figures; and it often ignores extended desktops (i.e. an attached additional monitor).</p><p>The solutions that do work properly all rely on undocumented features: Some use platform-specific native Windows API in a mex-file (Jan Simon&#8217;s recent <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi">WindowAPI</a> submission really pushes the limit in this and other regards). Alternately, we can easily use the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>
jFrame =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigurePeer</span>@cdbd96
&nbsp;
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to maximize the figure</span>
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-maximize the figure</span></pre></div></div><h3 id="Minimization">Minimization</h3><p>To the best of my knowledge, there are no solutions for minimizing figure windows that use documented Matlab features. Again, this can be done using either native Windows API, or the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to minimize the figure</span>
&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-minimize the figure</span></pre></div></div><h3 id="Notes">Usage notes</h3><p><b>Maximized</b> and <b>Minimized</b> are mutually-exclusive, meaning that no more than one of them can be 1 (or true) at any time. This is automatically handled – users only need to be aware that a situation in which a window is both maximized and minimized at the same time is impossible (duh!).</p><p>There are several equivalent manners of setting <code>jFrame</code>&#8216;s <b>Maximized</b> and <b>Minimized</b> property values, and your choice may simply be a matter of aesthetics and personal taste:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Three alternative possibilities of setting Maximized:</span>
jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Maximized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% note interchangeable 1&lt; =&gt;true, 0&lt; =&gt;false</span>
jFrame.<span style="">handle</span>.<span style="">Maximized</span> = <span style="color: #33f;">1</span>;</pre></div></div><p><code>jFrame</code> follows Java convention: the accessor method that retrieves boolean values is called <i>is&lt;Propname&gt;()</i> instead of <i>get&lt;Propname&gt;</i>. In our case: <i>isMaximized()</i> and <i>isMinimized()</i>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">flag</span> = jFrame.<span style="">isMinimized</span>;        <span style="color: #228B22;">% Note: isMinimized, not getMinimized</span>
<span style="color: #0000FF;">flag</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Minimized'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">flag</span> = jFrame.<span style="">handle</span>.<span style="">Minimized</span>;</pre></div></div><p>In some old Matlab releases, <code>jFrame</code> did not possess the <b>Maximized</b> and <b>Minimized</b> properties, and their associated accessor methods. In this case, use the internal <code>FrameProxy</code> which has always contained them:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrameProxy = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> 
jFrameProxy =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigureFrameProxy</span>$FigureFrame<span style="color: #080;">&#91;</span>fClientProxyFrame,<span style="color: #33f;">227</span>,<span style="color: #33f;">25</span>,568x502,invalid,layout=java.<span style="">awt</span>.<span style="">BorderLayout</span>,<span style="color: #0000FF;">title</span>=<span style="color: #0000FF;">Figure</span> <span style="color: #33f;">1</span>,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,<span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; <span style="color: #228B22;">% Three alternative possibilities of setting Minimized:</span>
&gt;&gt; jFrameProxy.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrameProxy,<span style="color:#A020F0;">'Minimized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; jFrameProxy.<span style="">handle</span>.<span style="">Minimized</span> = <span style="color: #0000FF;">true</span>;</pre></div></div><p>Using <code>FrameProxy</code> for figure minimization and maximization works correctly on both old and new Matlab releases; using <code>jFrame</code> is slightly simpler but only works on recent Matlab releases. Depending on your needs you may choose to use either of these. They are entirely equivalent.</p><p>When either the <b>Maximized</b> or <b>Minimized</b> properties are changed back to false, the window is restored to regular mode, which is the <code>FrameProxy</code>&#8216;s <b>RestoredLocation</b> and <b>RestoredSize</b>.</p><h3 id="JavaFrame">Use of the JavaFrame property</h3><p>Note that all this relies on the undocumented hidden figure property <b>JavaFrame</b>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release (HG2?):</p><div
class="wp_syntax"><div
class="code"><pre style="font-family: monospace;"><span style="color: #000000;">>> jFrame = </span><span style="color: #0000ff;">get</span>(<span style="color: #0000ff;">gcf</span>,<span style="color: #800080;">'JavaFrame'</span>)
<span style="color: #ff0000;">Warning: figure JavaFrame property will be obsoleted in a future release.</span>
<span style="color: #000000;">For more information see the JavaFrame resource on the MathWorks web site.
(Type "warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame" to suppress this warning.) 

jFrame =
com.mathworks.hg.peer.FigurePeer@1ffbad6</span>
</pre></div></div><p>To remove the above warning I have used (note the <i><b>handle</b></i> wrapper, as <a
target="_blank" href="http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comment-2756">suggested</a> by Donn Shull):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span></pre></div></div><p>If and when <b>JavaFrame</b> does become obsolete in some future Matlab version, be sure to look in this blog for workarounds.</p><p>You may also wish to inform MathWorks on the dedicated webpage that they have set up for specifically this reason (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/javaframe">http://www.mathworks.com/javaframe</a>), how you are using <b>JavaFrame</b> and why it is important for you. This may help them to decide whether to keep <b>JavaFrame</b> or possibly add the functionality using other means.</p><p>Do you have a smart use for the figure&#8217;s minimization or maximization feature? or another use for <b>JavaFrame</b>? If so, please share your ideas in a <a
target="_blank" href="http://UndocumentedMatlab.com/blog/minimize-maximize-figure-window#respond">comment</a> below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Blurred Matlab figure window</title><link>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/#comments</comments> <pubDate>Wed, 20 Apr 2011 18:58:12 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2259</guid> <description><![CDATA[Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Following my post two weeks ago about <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">disabling an entire Matlab figure window</a>, and my article last week about <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/">setting the transparency of a figure window</a>, I would like to combine these two functionalities into a blurred-window effect for a disabled window.</p><h3 id="basic">The basic idea</h3><p>The basic idea, as reader Mory <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#comment-40154">pointed out</a> in a comment, is to overlay a semi-transparent empty figure window, having just the right size and position, on top of the main (disabled) figure window:</p><p><center><div
class="wp-caption aligncenter" style="width: 640px"><img
alt="Main (unblurred) window" src="http://UndocumentedMatlab.com/images/blurFigure1a.png" title="Main (unblurred) window" width="190" /> + <img
alt="Semi-transparent window" src="http://UndocumentedMatlab.com/images/blurFigure1b.png" title="Semi-transparent window" width="190" /> = <img
alt="Blurred window effect" src="http://UndocumentedMatlab.com/images/blurFigure1c.png" title="Blurred window effect" width="190" /><p
class="wp-caption-text">Main (unblurred) window + semi-transparent window = blurred window effect</p></div></center></p><p>In addition to ensuring the correct figure size and position, there are several other things we should care for: We need to synchronize the figure/blurring color, menubar/toolbar, and title. We also need to handle docking, resizing and figure movement. Finally we need to connect the two figures so that whenever one is closed then so is the other.</p><h3 id="blurFigure">blurFigure</h3><p>My <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30666-blurfigure-blurs-and-prevents-interaction-on-a-figure-window"><i><b>blurFigure</b></i> utility</a> on the Matlab File Exchange attempts to handle all these setups for the user. The utility is quite simple to use:</p><p><i><b>blurFigure</b>(hFig)</i> blurs figure <i>hFig</i> and prevents interaction with it. The only interaction possible is with user-created controls on the blurring panel (see below).</p><p>hFigBlur = <i><b>blurFigure</b>(hFig)</i> returns the overlaid blurred figure pane. This is useful to present a progress bar or other GUI controls, for user interaction during the blur phase (see the demo below).</p><p><i><b>blurFigure</b>(hFig,STATE)</i> sets the blur status of figure <i>hFig</i> to <i>STATE</i>, where state is &#8216;on&#8217;,'off&#8217;,true or false (default=&#8217;on&#8217;/true). <i><b>blurFigure</b>(hFig,&#8217;on&#8217;)</i> or <i><b>blurFigure</b>(hFig,true)</i> is the same as: <i><b>blurFigure</b>(hFig)</i>; <i><b>blurFigure</b>(hFig,&#8217;off&#8217;)</i> or <i><b>blurFigure</b>(hFig,false)</i> is the same as: <i><b>close</b>(hFigBlur)</i>.</p><p><i><b>blurFigure</b>(&#8216;demo&#8217;)</i> displays a simple demo of the blurring. In fact, this runs the following simple code:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create the main (blurred) figure window</span>
hFigMain = <span style="color: #0000FF;">figure</span>;
&nbsp;
<span style="color: #228B22;">% Display some GUI controls in the main window</span>
<span style="color: #0000FF;">try</span> oldWarn = <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'off'</span>,<span style="color:#A020F0;">'MATLAB:uitree:MigratingFunction'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
hTree = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'root'</span>,<span style="color:#A020F0;">'c:\'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">drawnow</span>;
<span style="color: #0000FF;">try</span> hTree.<span style="">getTree</span>.<span style="">expandRow</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span>oldWarn<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'click me!'</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">300</span>,<span style="color: #33f;">50</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">axes</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,<span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">230</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">300</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">surf</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">peaks</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'ToolBar'</span>,<span style="color:#A020F0;">'figure'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% restore the toolbar that was removed by the uicontrol() call above</span>
&nbsp;
<span style="color: #228B22;">% Call blurFigure() to add a semi-transparent overlaid window</span>
hFigBlurTemp = blurFigure<span style="color: #080;">&#40;</span>hFigMain<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add some non-blurred controls on top of the blur</span>
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hFigBlurTemp, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'text'</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'pixel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">130</span>,<span style="color: #33f;">85</span>,<span style="color: #33f;">390</span>,<span style="color: #33f;">80</span><span style="color: #080;">&#93;</span>, <span style="color: #F0F;">...</span>
          <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Processing - please wait...'</span>, <span style="color:#A020F0;">'FontSize'</span>,<span style="color: #33f;">12</span>, <span style="color:#A020F0;">'FontWeight'</span>,<span style="color:#A020F0;">'bold'</span>,<span style="color:#A020F0;">'Fore'</span>,<span style="color:#A020F0;">'red'</span>,<span style="color:#A020F0;">'Back'</span>,<span style="color:#A020F0;">'yellow'</span><span style="color: #080;">&#41;</span>;
jProgressBar = javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JProgressBar'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">180</span>,<span style="color: #33f;">115</span>,<span style="color: #33f;">310</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>, hFigBlurTemp<span style="color: #080;">&#41;</span>;
jProgressBar.<span style="">setValue</span><span style="color: #080;">&#40;</span><span style="color: #33f;">67</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hFigBlurTemp, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Cancel'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">280</span>,<span style="color: #33f;">90</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'Callback'</span>,<span style="color:#A020F0;">'close(gcbf)'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 410px"><img
alt="Non-blurred controls displayed over a blurred figure window" src="http://UndocumentedMatlab.com/images/blurFigure.png" title="Non-blurred controls displayed over a blurred figure window" width="400" /><p
class="wp-caption-text">Non-blurred controls displayed over a blurred figure window</p></div></center></p><p>Do you have some other interesting uses for window transparency in Matlab? If so, please share your thought in a <a
href="http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/#respond">comment</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Transparent Matlab figure window</title><link>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#comments</comments> <pubDate>Wed, 13 Apr 2011 23:22:38 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Desktop]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2246</guid> <description><![CDATA[Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Every now and then, a user asks whether it is possible to make an entire Matlab window transparent (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/280394">example</a>). This could be used, for example, for window fade-in/fade-out effects. The short answer is that there is no supported way of doing this with pure documented Matlab, but it is trivially easy to achieve using just a bit of Java magic powder (surprise, surprise).</p><h3 id="transparency">Matlab figure window transparency</h3><p>Following an idea I got from Malcolm Lidierth&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28326-mutilities">MUtilities</a> submission on the Matlab File Exchange, the solution for setting Matlab figure window transparency is quite simple: Get the figure&#8217;s underlying Java window reference handle, as in <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">last week&#8217;s</a> article. Then use Java&#8217;s <a
target="_blank" rel="nofollow" href="http://www.pushing-pixels.org/2008/02/27/translucent-and-shaped-windows-in-core-java.html"><i>setWindowOpacity</i> method</a> to set the window&#8217;s transparency value. Actually, <i>setWindowOpacity</i> sets the opacity level, rather than transparency, but they are obviously complementary and I personally find &#8220;transparency&#8221; to be more easily understandable.</p><p>By default, windows are created with an opacity of 1.0 (= not transparent). They can be set to any floating-point value between 0.0-1.0, where an opacity of 0.0 means full transparency, and any value in between means partial transparency (i.e., translucency):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jWindow = jFigPeer.<span style="">fFigureClient</span>.<span style="">getWindow</span>;
com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,<span style="color: #33f;">0.7</span><span style="color: #080;">&#41;</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 510px"><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fx_files/30583/1/setFigTransparency.png"><img
alt="Semi-transparent (translucent) Matlab figure (click to enlarge)" src="http://www.mathworks.com/matlabcentral/fx_files/30583/1/setFigTransparency.png" title="Semi-transparent (translucent) Matlab figure (click to enlarge)" width="500" /></a><p
class="wp-caption-text">Semi-transparent (translucent) Matlab figure (click to enlarge)</p></div></center></p><p>Similarly, you can set the entire Matlab Desktop&#8217;s transparency/opacity value:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jDesktop = com.<span style="">mathworks</span>.<span style="">mde</span>.<span style="">desk</span>.<span style="">MLDesktop</span>.<span style="">getInstance</span>.<span style="">getMainFrame</span>;
com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jDesktop, <span style="color: #33f;">0.8</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Note that the <code>com.sun.awt.AWTUtilities</code> class also enables <a
target="_blank" rel="nofollow" href="http://today.java.net/pub/a/today/2008/03/18/translucent-and-shaped-swing-windows.html">other GUI effects</a> that would make a Matlab GUI developer&#8217;s mouth to start drooling: shaped windows, per-pixel transparency values, mirroring/reflection, window shadows, <a
target="_blank" rel="nofollow" href="http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/">gradients</a> etc. Perhaps I&#8217;ll explore their adaptation for Matlab figures someday.</p><h3 id="Fade">Fade-in / fade-out</h3><p>Window fade-in/fade-out effects can easily be achieved using transparency: Simply invoke the <i>setWindowOpacity</i> method several times, with progressively higher or lower values. This is easily done in a simple blocking loop. For example, to fade-out a window:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">for</span> stepIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">5</span>
   newAlpha = <span style="color: #33f;">1.0</span> - <span style="color: #33f;">0.2</span>*stepIdx;
   com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,newAlpha<span style="color: #080;">&#41;</span>;
   jWindow.<span style="">repaint</span>;
   <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.2</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% seconds</span>
<span style="color: #0000FF;">end</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
alt="Gradual window fade-out" src="http://UndocumentedMatlab.com/images/transparent_figure_animated.gif" title="Gradual window fade-out" width="300" /><p
class="wp-caption-text">Gradual window fade-out</p></div></center></p><p>A more general example dynamically computes the opacity step size/duration and also enables non-blocking fade effects using an asynchronous timer:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Compute the required opacity-setting steps</span>
fadeDuration = <span style="color: #33f;">1.5</span>;  <span style="color: #228B22;">% seconds</span>
oldAlpha = com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">getWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow<span style="color: #080;">&#41;</span>;
newAlpha = <span style="color: #33f;">0.0</span>;
deltaAlpha = newAlpha - oldAlpha;
maxStepAlpha = <span style="color: #33f;">0.03</span>;
steps = <span style="color: #0000FF;">fix</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">abs</span><span style="color: #080;">&#40;</span>deltaAlpha<span style="color: #080;">&#41;</span> / maxStepAlpha<span style="color: #080;">&#41;</span> + <span style="color: #33f;">1</span>;
stepAlpha = deltaAlpha / steps;
stepDuration = fadeDuration / <span style="color: #080;">&#40;</span>steps-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% If blocking, do the fade effect immediately</span>
<span style="color: #0000FF;">if</span> blockingFlag <span style="color: #F0F;">||</span> steps==<span style="color: #33f;">1</span>
   <span style="color: #0000FF;">for</span> stepIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> steps
      newAlpha = oldAlpha + stepAlpha*stepIdx;
      com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jWindow,newAlpha<span style="color: #080;">&#41;</span>;
      jWindow.<span style="">repaint</span>;
      <span style="color: #0000FF;">if</span> stepIdx &lt; steps,  <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span>stepDuration<span style="color: #080;">&#41;</span>;  <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">else</span>
   <span style="color: #228B22;">% non-blocking: fade in/out asynchronously using a dedicated timer</span>
   start<span style="color: #080;">&#40;</span>timer<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'ExecutionMode'</span>,<span style="color:#A020F0;">'fixedRate'</span>, <span style="color:#A020F0;">'Period'</span>,<span style="color: #33f;">0.1</span>, <span style="color:#A020F0;">'TasksToExecute'</span>,steps, <span style="color: #F0F;">...</span>
               <span style="color:#A020F0;">'TimerFcn'</span>, <span style="color: #080;">&#123;</span>@timerFcn,jWindow,oldAlpha,stepAlpha<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Timer function for non-blocking fade-in/fade-out effect</span>
<span style="color: #0000FF;">function</span> timerFcn<span style="color: #080;">&#40;</span>hTimer,eventData,jFrame,currentAlpha,stepAlpha<span style="color: #080;">&#41;</span>  <span style="color: #228B22;">%#ok&lt;INUSL&gt; eventData</span>
  stepIdx = hTimer.<span style="">TasksExecuted</span>;
  newAlpha = currentAlpha + stepAlpha*stepIdx;
  com.<span style="">sun</span>.<span style="">awt</span>.<span style="">AWTUtilities</span>.<span style="">setWindowOpacity</span><span style="color: #080;">&#40;</span>jFrame,newAlpha<span style="color: #080;">&#41;</span>;
  jFrame.<span style="">repaint</span>;
  <span style="color: #0000FF;">if</span> stepIdx == hTimer.<span style="">TasksToExecute</span>
      stop<span style="color: #080;">&#40;</span>hTimer<span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>hTimer<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% timerFcn</span></pre></div></div><p>Of course, you can also fade-in/out to intermediate values such as 0.3 or 0.8. If you fade-out completely (i.e., to a value of 0.0), it might be a good idea to actually <i><b>close</b></i> the figure window once it gets the totally-transparent value of 0.0.</p><p>I&#8217;ve prepared a Matlab utility that contains all these options, including optional blocking/non-blocking fade effects, in my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30583-setfigtransparency-set-figure-transparency-fading"><i><b>setFigTransparency</b></i> utility</a>, which is available for download on the Matlab File Exchange. You may also wish to use Malcolm Lidierth&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28326-mutilities">MUtilities</a>, which also has similar functionalities (plus some other goodies).</p><h3 id="Limitations">Limitations</h3><p>Setting a figure window&#8217;s transparency requires using Java Run-time Engine (JRE) 1.6.0_10 (also called &#8220;Java 6 update 10&#8243;) or higher. This means that it&#8217;s supported on Matlab release 7.9 (R2009b) and higher by default, and on earlier releases using a JRE retrofit.</p><p>If you are using an earlier Matlab release, consider a retrofit of JRE 1.6.0_10 or any later version (e.g., the latest available version today is 1.6 update 24). The JRE can be downloaded from <a
target="_blank" rel="nofollow" href="http://java.com/en/download/manual.jsp">here</a>, and you can configure Matlab to use it according to the instructions <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-1812J/">here</a>. As noted, Matlab R2009b (7.9) and onward, at least on Microsoft Windows, pre-bundle a JRE version that does support transparency/opacity and so do not require a retrofit.</p><p>You can check your current Java version in Matlab as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">&gt;&gt; version -java
ans =
Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode</pre></div></div><p>Unfortunately, Matlab plot axes cannot be made transparent. If you have any axes in your GUI, the axes area will simply appear as a shaded axes, whose intensity depends on the selected alpha (transparency) value; the contents beneath the window will not be merged in the axes area as it is in the non-axes areas.</p><p>Finally, note that <code>com.sun.awt.AWTUtilities</code> is itself an undocumented Java class. It is bundled with the standard Java release since 2008 (1.6.0_10), and yet is not part of the official release because its API has not yet settled. In fact, in the upcoming Java 7 release, which is expected in a few months, and which I expect to be available in Matlab sometime in 2012, the set of transparency/opacity methods have <a
target="_blank" rel="nofollow" href="http://www.pushing-pixels.org/2009/05/03/translucent-and-shaped-windows-in-jdk-7.html">migrated</a> to the fully-documented <code>java.awt.Window</code> class.</p><h3 id="blurring">Blurred figure window</h3><p>So here&#8217;s a riddle for you: using figure window transparency, can you guess how to make a Matlab figure appear blurred for <a
target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/">disabled figures</a> (see the screenshot there)? There are several possible ways to do this &#8211; can you find the simplest? The first one to <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#respond">post a comment</a> with a correct answer gets a smiley&#8230; My answer will appear in next week&#8217;s article.</p><h3 id="upgrade">Upgraded website</h3><p>Also, did you notice my new website design? It&#8217;s supposed to be much more readable (yes &#8211; also on <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2010/05/24/introducing-matlab-mobile-%E2%80%93-an-iphone-app-to-connect-remotely-to-your-matlab/#comments">Android</a>&#8230;). It now also runs on a multi-server cloud, which means more stability and faster response times. Do you like the new design? hate it? I would love to hear your feedback via <a
target="_blank" href="http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/#respond">comment</a> or <a
href="mailto:%20altmany%20@gmail.com?subject=Undocumented%20Matlab&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Undocumented Matlab&amp;body=Hi Yair, '); return false;">email</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Enable/disable entire figure window</title><link>http://undocumentedmatlab.com/blog/disable-entire-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/disable-entire-figure-window/#comments</comments> <pubDate>Wed, 06 Apr 2011 18:00:20 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[JavaFrame]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2089</guid> <description><![CDATA[Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Some time ago, a reader on the CSSM newsgroup <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/300200">asked</a> whether it is possible to disable an entire figure window while some processing is taking place. Last week, Mike posted an article about the built-in functions <b><i>uiwait</i></b> and <b><i>uiresume</i></b> on <a
rel="nofollow" target="_blank" href="http://blogs.mathworks.com/desktop/2011/03/28/using-uiwaituiresume-to-control-program-flow/">MathWork&#8217;s Matlab Desktop blog</a>, which more-or-less answers this need. Today I will expand the answer based on several undocumented/unsupported mechanisms.</p><h3 id="uiwait">Uiwait and uiresume</h3><p>We start with a short review of the supported mechanism: We can use the built-in <b><i>uiwait</i></b> function to suspend Matlab processing until either the specified handle (typically a figure handle) is deleted/closed, a user callback programmatically calls <b><i>uiresume</i></b>, or Ctrl-C is pressed. A short example, adapted from <b><i>uiwait</i></b>&#8216;s help section (the official help section has a bug, so if anyone reads this at TMW, please fix):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">h = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Position'</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">20</span> <span style="color: #33f;">20</span> <span style="color: #33f;">200</span> <span style="color: #33f;">40</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'String'</span>, <span style="color:#A020F0;">'Continue'</span>, <span style="color:#A020F0;">'Callback'</span>, <span style="color:#A020F0;">'uiresume(gcbf)'</span><span style="color: #080;">&#41;</span>;
f = <span style="color: #0000FF;">gcf</span>;
<span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'This will print immediately'</span><span style="color: #080;">&#41;</span>;
uiwait<span style="color: #080;">&#40;</span>f<span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'This will print after you click Continue or close the window'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Close the figure (use try-catch in case f is already closed)</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">close</span><span style="color: #080;">&#40;</span>f<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>, <span style="color: #0000FF;">end</span></pre></div></div><p>Unfortunately, the side effect is that <b><i>uiwait</i></b> blocks the regular (non-callback&#8217;ed) processing until the lock is released. This is great for simple cases where we require a user to respond to a popup window (e.g., message-box or input dialog) before being allowed to proceed. In more complex situations we may wish to suspend interaction on certain figure windows while continuing to process Matlab functionality &#8211; this is impossible to do using <b><i>uiwait</i></b>.</p><p>Matlab does not have any documented way to disable an entire figure window. You can set the figure&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/figure_props.html#WindowStyle"><b>WindowStyle</b> property</a> to &#8216;modal&#8217; but this is not the same: (1) it removes the toolbar and menu-bar (2) it still enables interaction with all the figure&#8217;s GUI controls and (3) it prevents access to any other Matlab window or desktop until the modal figure is closed. This is certainly NOT what we need.</p><p>Of course, we could always loop over all the relevant GUI handles and set their <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#Enable"><b>Enable</b> property</a> to &#8216;inactive&#8217; or &#8216;off&#8217;. But this is tedious, lengthy, and in complex GUIs that have multiple layers of nested panels, it also requires careful recursive programming. We also need to take care to disable hidden handles, toolbars, menu-bars, context-menus, Java components &#8211; all these have different ways of being accessed and disabled. And once we <b><i>uiresume</i></b> from the lock, we need to remember each handle&#8217;s pre-<b><i>uiwait</i></b> state, so that if it was disabled before the call to <b><i>uiwait</i></b>, it will remain so after <b><i>uiresume</i></b>. In short, this is not a trivial exercise at all.</p><h3 id="uisuspend">Uisuspend and uirestore</h3><p>To complicate things, the fully-documented and supported <b><i>uiwait</i></b> and <b><i>uiresume</i></b> functions have the <a
target="_blank" href="http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> unsupported built-in counterparts <b><i>uisuspend</i></b> and <b><i>uirestore</i></b>, which are very similar in functionality and name. It is important not to confuse between these two function sets, and most importantly, not to confuse between <b><i>uiresume</i></b> and <b><i>uirestore</i></b> after using their counterparts earlier in the code – odd things might happen if you do&#8230;</p><p>Hopefully, in a nearby Matlab release these inconsistencies between the two function sets will disappear and they will be merged, because the current situation is prone to errors and confusion. For backward compatibility considerations, I hope that <b><i>uisuspend</i></b> and <b><i>uirestore</i></b> would not be discontinued but rather be modified to simply call <b><i>uiwait</i></b> and <b><i>uiresume</i></b>.</p><p>Note that in Matlab releases up to R2010b, <b><i>uirestore</i></b> had a <a
rel="nofollow" target="_blank" href="http://www.mathworks.com/support/bugreports/646025 ">minor bug</a> in that it overwrites the figure&#8217;s <b>WindowScrollWheelFcn</b> callback with the <b>WindowKeyPressFcn</b> value. This bug was finally fixed in R2011a.</p><h3 id="Method">How to enable/disable a figure window</h3><p>So going back to the main question, we want to find a way to disable an entire figure window, in one simple stroke, and without blocking the Matlab processing.</p><p>As usual, we turn to Java and the solution is trivially simple:</p><p>First, get the figure window&#8217;s underlying Java reference. Note that we need the top-level container reference, rather than the proxy peer handle returned by the <b>JavaFrame</b> hidden property:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>
jFigPeer =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigurePeer</span>@1ffbad6
&nbsp;
&gt;&gt; jWindow = jFigPeer.<span style="">fFigureClient</span>.<span style="">getWindow</span>
<span style="color: #0000FF;">ans</span> =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigureFrameProxy</span>$FigureFrame<span style="color: #080;">&#91;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span></pre></div></div><p>Now remember that all Java GUI components (on which Matlab GUI is based) contain an <a
target="_blank" rel="nofollow" href="http://download.oracle.com/javase/6/docs/api/java/awt/Component.html#setEnabled%28boolean%29"><b>Enabled</b> property</a>. So, simply set this property on the jWindow reference to true or false:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jWindow.<span style="">setEnabled</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or true</span>
&nbsp;
<span style="color: #228B22;">% an equivalent alternative</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>jWindow<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Enabled'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% or true</span></pre></div></div><p>By the way, if you only need to disable the figure&#8217;s content area (i.e., not the toolbar and menu bar), simply use a different reference handle:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer.<span style="">getFigurePanelContainer</span>.<span style="">setEnabled</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or true</span></pre></div></div><p>Notes:</p><ul><li>While the window looks the same when it is disabled, in reality none of its GUI elements can be clicked or activated (try it!). If you also want the figure to appear blurred you could try using something like a <a
target="_blank" rel="nofollow" href="http://java.net/projects/jxlayer/">JXLayer</a> semi-translucent glass pane.</li><li>The Java components&#8217; property is called <b>Enabled</b>, not <b>Enable</b> as in pure-Matlab Handle-Graphics controls. Also, the Java property expects true/false (or 0/1), rather than Matlab&#8217;s &#8216;on&#8217;/'off&#8217; (there are some fine details here that are release-specific so I will skip them)</li><li>For docked windows the top-level window is the figure&#8217;s group container window or the desktop window, which we do not want to disable. Detecting this is easy (check whether the figure&#8217;s <b>WindowStyle</b> is &#8216;docked&#8217;), and in such cases simply disable/enable the figure&#8217;s content area as shown above.</li></ul><h3 id="JavaFrame">Use of the JavaFrame property</h3><p>Note that all this relies on the undocumented hidden figure property <b>JavaFrame</b>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release (HG2?):</p><div
class="wp_syntax"><div
class="code"><pre style="font-family: monospace;"><span style="color: #000000;">>> jFigPeer = </span><span style="color: #0000ff;">get</span>(<span style="color: #0000ff;">gcf</span>,<span style="color: #800080;">'JavaFrame'</span>)
<span style="color: #ff0000;">Warning: figure JavaFrame property will be obsoleted in a future release.</span>
<span style="color: #000000;">For more information see the JavaFrame resource on the MathWorks web site.
(Type "warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame"
to suppress this warning.) 

jFigPeer =
com.mathworks.hg.peer.FigurePeer@1ffbad6</span>
</div>
</div>
</pre><p>To remove the above warning I have used (note the <i><b>handle</b></i> wrapper, as <a
target="_blank" href="http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comment-2756">suggested</a> by Donn Shull):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jFigPeer = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span></pre></div></div><p>If and when <b>JavaFrame</b> does become obsolete in some future Matlab version, be sure to look in this blog for workarounds.</p><p>You may also wish to inform MathWorks on the dedicated webpage that they have set up for specifically this reason (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/javaframe">http://www.mathworks.com/javaframe</a>), how you are using <b>JavaFrame</b> and why it is important for you. This may help them to decide whether to keep <b>JavaFrame</b> or possibly add the functionality using other means.</p><h3 id="enableDisableFig">The enableDisableFig utility</h3><p>In 2007, I created the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15895-enabledisable-figure"><i><b>enableDisableFig</b></i> utility</a> that wraps the above code in an easy-to-use Matlab utility that I have uploaded to the File Exchange.</p><p><i><b>enableDisableFig</b></i> returns the current state of the specified figure handle (or <i><b>gcf</b></i> if no handle is specified), and optionally sets the figure&#8217;s enabled/disabled state to a new value (&#8216;on&#8217;,'off&#8217;, true or false):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; oldState = enableDisableFig<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>
oldState =
on
&nbsp;
&gt;&gt; enableDisableFig<span style="color: #080;">&#40;</span>oldState<span style="color: #080;">&#41;</span>;
&gt;&gt; enableDisableFig<span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% an alternative</span></pre></div></div><p><i><b>enableDisableFig</b></i> also provides some sanity checks and error handling that should always appear in any real-world application. In this blog I generally tend to provide only bare-bones code snippets (as above). But in any respected application we must check the validity of input arguments and return values, catch run-time errors, compensate for incompatibilities with older Matlab release and so on. Take a look at <i><b>enableDisableFig</b></i>&#8216;s source code to see how I have done this.</p><h3 id="visual">Visual aid</h3><p>When any GUI control is disabled, the accepted convention is to shade it in a gray color as a visual aid to the user that the control is currently disabled. This is automatically done by Matlab when any control&#8217;s <b>Enable</b> property is set to &#8216;off&#8217;. In our case, it would be very helpful to display a similar blurring effect for the disabled figure window.</p><p>Would you be very surprised if I told you that this is impossible to do with regular Matlab, but trivially easy to achieve using a tiny bit of Java magic powder? I&#8217;ll expand on this in my next post, but here&#8217;s something to keep you waiting:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="A blurred disabled figure" src="http://UndocumentedMatlab.com/images/blurFigure.png" title="A blurred disabled figure" width="450" /><p
class="wp-caption-text">A blurred disabled figure</p></div></center></p><h3 id="upgrade">Server upgrade</h3><p>This weekend (9-10 April, 2011) I plan to upgrade the website. This will entail moving to a different webserver, database, upgraded blogging application, new design etc. This site may be down or &#8220;goofy&#8221; for quite a few hours. Hopefully all will be back to normal by Monday and I hope you will like the new design.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/disable-entire-figure-window/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>FIG files format</title><link>http://undocumentedmatlab.com/blog/fig-files-format/</link> <comments>http://undocumentedmatlab.com/blog/fig-files-format/#comments</comments> <pubDate>Wed, 22 Dec 2010 18:00:56 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2013</guid> <description><![CDATA[FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reading-non-latin-text-files/' rel='bookmark' title='Reading non-Latin text files'>Reading non-Latin text files</a> <small>A workaround that enables reading non-Latin text files in Matlab is shown...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Modifying default toolbar/menubar actions'>Modifying default toolbar/menubar actions</a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A short while ago, a StackOverflow user asked <a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/2976505/how-can-i-extract-data-from-a-fig-file-in-matlab">how to extract data from FIG files in Matlab</a>. The answer to this question is easy, but I wish to use the opportunity to show how this can be useful in Matlab applications.</p><h3 id="The_Need">The need: load a FIG without displaying it</h3><p>In data-processing applications, we often present data in graphs that can then be manipulated and saved for later use. In Matlab, saving is done interactively (via the figure&#8217;s File/Save menu option or via the figure&#8217;s Save toolbar button), or programmatically (via the <i><b>hgsave</b></i> function). In all cases, the data is stored in a *.FIG file (the FIG extension can actually be changed, but I really don&#8217;t see why).</p><p>The point is that in order to re-load the stored data, we need to use <i><b>hgload</b></i>, which has a nasty side-effect of actually displaying the stored figure.</p><p>This is bad in terms of performance and memory, especially for heavily-laden GUI figures, not to mention the fact that sometimes we do not want to display the GUI at all. We often just need to extract a sub-set of the stored information (for example, the plot values), <strong>without</strong> having to display the figure.</p><h3 id="FIG_Format">The answer: FIGs are simply MATs in disguise</h3><p>Here&#8217;s where the undocumented stuff enters:</p><p>It seems that a FIG file is simply a hierarchical structure of all the non-default properties of the stored figure and its descendant handles, all this stored within a simple MAT file.</p><p>This is hinted in several places, for example in <i><b>hgsave</b></i>&#8216;s doc page, and in the MAT-file preferences panel:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="MAT-file preferences (note the FIG clarification)" src="http://UndocumentedMatlab.com/images/FIG_MAT.png" title="MAT-file preferences (note the FIG clarification)" width="450" height="274" /><p
class="wp-caption-text">MAT-file preferences (note the FIG clarification)</p></div></center></p><p>Knowing this, we can easily load the data, <strong>without</strong> displaying the figure, by using <i><b>load</b>(filename,&#8217;-mat&#8217;)</i> rather than <i><b>hgload</b></i>. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create and store a simple plot figure</span>
&gt;&gt; <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'Test #1'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">9</span>, <span style="color: #0000FF;">sqrt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">9</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; hgsave<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'testFig'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Load the figure data</span>
&gt;&gt; d = <span style="color: #0000FF;">load</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'testFig.fig'</span>,<span style="color:#A020F0;">'-mat'</span><span style="color: #080;">&#41;</span>
d = 
    hgS_070000<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>   <span style="color: #228B22;">% a Matlab 7 figure</span>
&nbsp;
<span style="color: #228B22;">% Investigate the figure data</span>
&gt;&gt; d.<span style="">hgS_070000</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'figure'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'axes'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">176.08251953125</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>4x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'graph2d.lineseries'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">177.0830078125</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>.<span style="">properties</span>
<span style="color: #0000FF;">ans</span> = 
              Color<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>
              XData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">2</span> <span style="color: #33f;">3</span> <span style="color: #33f;">4</span> <span style="color: #33f;">5</span> <span style="color: #33f;">6</span> <span style="color: #33f;">7</span> <span style="color: #33f;">8</span> <span style="color: #33f;">9</span><span style="color: #080;">&#93;</span>
              YData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1.4142</span> <span style="color: #33f;">1.7321</span> <span style="color: #33f;">2</span> <span style="color: #33f;">2.2361</span> <span style="color: #33f;">2.4495</span> <span style="color: #33f;">2.6458</span> <span style="color: #33f;">2.8284</span> <span style="color: #33f;">3</span><span style="color: #080;">&#93;</span>
    ApplicationData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
        XDataJitter<span style="color: #F0F;">:</span> <span style="color: #33f;">0</span>
          XDataMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'manual'</span>
      ObeyXDataMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'auto'</span>
                <span style="color: #F0F;">...</span>
&nbsp;
<span style="color: #228B22;">% Extract plot data</span>
&gt;&gt; YData = d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>.<span style="">properties</span>.<span style="">YData</span>
YData =
  <span style="color: #33f;">1.0000</span>  <span style="color: #33f;">1.4142</span>  <span style="color: #33f;">1.7321</span>  <span style="color: #33f;">2.0000</span>  <span style="color: #33f;">2.2361</span>  <span style="color: #33f;">2.4495</span>  <span style="color: #33f;">2.6458</span>  <span style="color: #33f;">2.8284</span>  <span style="color: #33f;">3.0000</span></pre></div></div><p>We see a couple of interesting things in this simple example:</p><p>First, note that the top-level structure node is called &#8220;hgS_070000&#8243; &#8211; we&#8217;ll dig into this next week. Basically, it indicates that the structure holds a Matlab 7 figure.</p><p>Secondly, we see <a
target="_blank" href="http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/">hidden/undocumented properties</a> of the stored objects (for example, the lineseries&#8217; <strong>XDataJitter</strong> and <strong>ObeyXDataMode</strong> properties). <strong>ApplicationData</strong> is such a hidden handle, which is widely used as a substitute for any handle&#8217;s <strong>UserData</strong> property (the built-in <i><b>setappdata</b></i> and <i><b>getappdata</b></i> functions are simply wrappers for accessing this property using standard <i><b>set</b></i> and <i><b>get</b></i> functions).</p><p>Have you used the FIG/MAT feature for any useful functionality? If so, please do share your experience in a <a
href="http://undocumentedmatlab.com/blog/fig-files-format/#respond">comment</a>.</p><p><em>Next week, I will explain how looking under <i><b>hgsave</b></i>&#8216;s hood leads to useful functions and to an interesting insight about Matlab&#8217;s future. Merry Christmas everybody!</em></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reading-non-latin-text-files/' rel='bookmark' title='Reading non-Latin text files'>Reading non-Latin text files</a> <small>A workaround that enables reading non-Latin text files in Matlab is shown...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Modifying default toolbar/menubar actions'>Modifying default toolbar/menubar actions</a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/fig-files-format/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>uisplittool &amp; uitogglesplittool callbacks</title><link>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/</link> <comments>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/#comments</comments> <pubDate>Wed, 15 Dec 2010 18:00:35 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Callbacks]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Toolbar]]></category> <category><![CDATA[uitools]]></category> <category><![CDATA[uiundo]]></category> <category><![CDATA[Undocumented function]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1999</guid> <description><![CDATA[Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-callbacks/' rel='bookmark' title='Uicontrol callbacks'>Uicontrol callbacks</a> <small>This post details undocumented callbacks exposed by the underlying Java object of Matlab uicontrols, that can be used to modify the control's behavior in a multitude of different events...</small></li><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Last week, I presented the undocumented <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> functions and showed how they can be added to a Matlab figure toolbar. Today I wish to conclude this topic by explaining how these controls can be customized with user-defined callbacks and pop-up menus.</p><h3 id="Callbacks">Callback functionality</h3><p>Both <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> have a <strong>Callback</strong> property, in addition to the standard <strong>ClickedCallback</strong> property that is available in <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s.</p><p>The standard <strong>ClickedCallback</strong> is invoked when the main button is clicked, while <strong>Callback</strong> is invoked when the narrow arrow button is clicked. <i><b>uitogglesplittool</b></i>, like <i><b>uitoggletool</b></i>, also has settable <strong>OnCallback</strong> and <strong>OffCallback</strong> callback properties.</p><p>The accepted convention is that <strong>ClickedCallback</strong> should invoke the default control action (in our case, an Undo/Redo of the topmost <a
target="_blank" href="http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/">uiundo action stack</a>), while <strong>Callback</strong> should display a drop-down of selectable actions.</p><p>While this can be done programmatically using the <strong>Callback</strong> property, this functionality is already pre-built into <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> for our benefit. To access it, we need to get the control&#8217;s underlying Java component.</p><p>Accessing the underlying Java component is normally done using the <a
target="_blank" href="http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/">findjobj utility</a>, but in this case we have a shortcut: the control handle&#8217;s hidden <strong>JavaContainer</strong> property that holds the underlying <i>com.mathworks.hg.peer.SplitButtonPeer</i> (or <i>.ToggleSplitButtonPeer</i>) Java reference handle. This Java object&#8217;s <strong>MenuComponent</strong> property returns a reference to the control&#8217;s drop-down sub-component (which is a <i>com.mathworks.mwswing.MJPopupMenu</i> object):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jUndo = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUndo,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>
jUndo =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">SplitButtonPeer</span>@f09ad5
&nbsp;
&gt;&gt; jMenu = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jUndo,<span style="color:#A020F0;">'MenuComponent'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% or: =jUndo.getMenuComponent</span>
jMenu =
com.<span style="">mathworks</span>.<span style="">mwswing</span>.<span style="">MJPopupMenu</span><span style="color: #080;">&#91;</span>Dropdown Picker ButtonMenu,<span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span></pre></div></div><p>Let&#8217;s add a few simple textual options:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jOption1 = jMenu.<span style="">add</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Option #1'</span><span style="color: #080;">&#41;</span>;
jOption1 = jMenu.<span style="">add</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Option #2'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jOption1, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, <span style="color:#A020F0;">'disp('</span><span style="color:#A020F0;">'option #1'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jOption2, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, <span style="color: #080;">&#123;</span>@myCallbackFcn, extraData<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 320px"><img
alt="setting uisplittool &amp; uitogglesplittool popup-menus" src="http://UndocumentedMatlab.com/images/uisplittool3.png" title="setting uisplittool &amp; uitogglesplittool popup-menus" width="99" height="72" /><p
class="wp-caption-text">setting <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> popup-menus</p></div></center></p><p>Popup-menus are described in more detail elsewhere (and in future articles). In the past I have already explained how icons and HTML markup can be added to menu items. Sub-menus can also be added.</p><h3 id="Example">A complete example</h3><p>Let&#8217;s now use this information, together with last year&#8217;s <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/uiundo/">set of articles</a> about Matlab&#8217;s undocumented <i><b>uiundo</b></i> functionality, to generate a complete and more realistic example, of undo/redo toolbar buttons.</p><p>Undo and redo are actions that are particularly suited for <i><b>uisplittool</b></i>, since its main button enables us to easily undo/redo the latest action (like a simple toolbar button, by clicking the main <i><b>uisplittool</b></i> button) as well as select items from the actions drop-down (like a combo-box, by clicking the attached arrow button) – all this using a single component.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Display our GUI</span>
hEditbox = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">20</span>,<span style="color: #33f;">60</span>,<span style="color: #33f;">40</span>,<span style="color: #33f;">40</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hEditbox, <span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'off'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'0'</span><span style="color: #080;">&#41;</span>;
hSlider = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'slider'</span>,<span style="color:#A020F0;">'userdata'</span>,hEditbox<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSlider,<span style="color:#A020F0;">'Callback'</span>,@test_uiundo<span style="color: #080;">&#41;</span>;  
&nbsp;
<span style="color: #228B22;">% Display the figure toolbar that was hidden by the uicontrol function</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'Toolbar'</span>,<span style="color:#A020F0;">'figure'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add the Undo/Redo buttons</span>
hToolbar = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'FigureToolBar'</span><span style="color: #080;">&#41;</span>;
hUndo = uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>;
hRedo = uitogglesplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Load the Redo icon</span>
icon = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/toolbox/matlab/icons/greenarrowicon.gif'</span><span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>cdata,map<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">imread</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Convert white pixels into a transparent background</span>
map<span style="color: #080;">&#40;</span><span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>==<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> = <span style="color: #0000FF;">NaN</span>;
&nbsp;
<span style="color: #228B22;">% Convert into 3D RGB-space</span>
cdataRedo = ind2rgb<span style="color: #080;">&#40;</span>cdata,map<span style="color: #080;">&#41;</span>;
cdataUndo = cdataRedo<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">16</span><span style="color: #F0F;">:</span>-<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add the icon (and its mirror image = undo) to latest toolbar</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo, <span style="color:#A020F0;">'cdata'</span>,cdataUndo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'undo'</span>,<span style="color:#A020F0;">'Separator'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execUndo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hRedo, <span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'redo'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execRedo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Re-arrange the Undo/Redo buttons  </span>
jToolbar = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'ComponentPeer'</span><span style="color: #080;">&#41;</span>;
jButtons = jToolbar.<span style="">getComponents</span>;
<span style="color: #0000FF;">for</span> buttonIdx = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#41;</span>-<span style="color: #33f;">3</span> <span style="color: #F0F;">:</span> -<span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">7</span>  <span style="color: #228B22;">% end-to-front</span>
   jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>buttonIdx<span style="color: #080;">&#41;</span>, buttonIdx+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">5</span><span style="color: #080;">&#41;</span>;    <span style="color: #228B22;">% Separator</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">6</span><span style="color: #080;">&#41;</span>;    <span style="color: #228B22;">% Undo</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>;      <span style="color: #228B22;">% Redo</span>
jToolbar.<span style="">revalidate</span>;
&nbsp;
<span style="color: #228B22;">% Retrieve redo/undo object</span>
undoObj = <span style="color: #0000FF;">getappdata</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'uitools_FigureToolManager'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>undoObj<span style="color: #080;">&#41;</span>
   undoObj = uitools.<span style="">FigureToolManager</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'uitools_FigureToolManager'</span>,undoObj<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Populate Undo actions drop-down list</span>
jUndo = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hUndo,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>;
jMenu = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jUndo,<span style="color:#A020F0;">'MenuComponent'</span><span style="color: #080;">&#41;</span>;
undoActions = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>undoObj.<span style="">CommandManager</span>.<span style="">UndoStack</span>,<span style="color:#A020F0;">'Name'</span><span style="color: #080;">&#41;</span>;
jMenu.<span style="">removeAll</span>;
<span style="color: #0000FF;">for</span> actionIdx = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>undoActions<span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> -<span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>    <span style="color: #228B22;">% end-to-front</span>
    jActionItem = jMenu.<span style="">add</span><span style="color: #080;">&#40;</span>undoActions<span style="color: #080;">&#40;</span>actionIdx<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jActionItem, <span style="color:#A020F0;">'ActionPerformedCallback'</span>, @myUndoCallbackFcn<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
jToolbar.<span style="">revalidate</span>;
&nbsp;
<span style="color: #228B22;">% Drop-down callback function</span>
<span style="color: #0000FF;">function</span> myUndoCallbackFcn<span style="color: #080;">&#40;</span>jActionItem,hEvent<span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">% user processing needs to be placed here</span>
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myUndoCallbackFcn</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 405px"><img
alt="undo/redo buttons implemented using uisplittool" src="http://UndocumentedMatlab.com/images/uisplittool4b.png" title="undo/redo buttons implemented using uisplittool" width="395" height="257" /><p
class="wp-caption-text">undo/redo buttons implemented using <i><b>uisplittool</b></i></p></div></center></p><p>In a real-world application, the code-segment above that populated the drop-down list would be placed within the slider&#8217;s <em>test_uiundo()</em> callback function, and we would set a similar drop-down for the hRedu button. In addition, we would dynamically modify the button tooltips. As a final customization, we could modify the figure&#8217;s main menu. Menu customization will be discussed in a future separate set of articles.</p><p>Have you used <i><b>uisplittool</b></i> or <i><b>uitogglesplittool</b></i> in your GUI? If so, please tell us what use you have made of them, in a comment <a
href="http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/#respond">below</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-callbacks/' rel='bookmark' title='Uicontrol callbacks'>Uicontrol callbacks</a> <small>This post details undocumented callbacks exposed by the underlying Java object of Matlab uicontrols, that can be used to modify the control's behavior in a multitude of different events...</small></li><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>uisplittool &amp; uitogglesplittool</title><link>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/</link> <comments>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/#comments</comments> <pubDate>Thu, 09 Dec 2010 00:06:33 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Desktop]]></category> <category><![CDATA[Figure window]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Toolbar]]></category> <category><![CDATA[uitools]]></category> <category><![CDATA[uiundo]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1994</guid> <description><![CDATA[Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-uiundo/' rel='bookmark' title='Customizing uiundo'>Customizing uiundo</a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab 7.6 (R2008a) and onward contain a reference to <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> in the javacomponent.m and %matlabroot%/bin/registry/hg.xml files. These are reported as built-in functions by the <i><b>which</b></i> function, although they have no corresponding m-file as other similar built-in functions (note the double &#8216;t&#8217;, as in <i>split-tool</i>):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">which</span> uisplittool
built-in <span style="color: #080;">&#40;</span>C<span style="color: #F0F;">:</span>\Matlab\R2010b\toolbox\matlab\uitools\uisplittool<span style="color: #080;">&#41;</span></pre></div></div><p>These uitools are entirely undocumented, even today (R2010b). They puzzled me for a very long time. An acute reader (Jeremy Raymonds) suggested they are related to toolbars, like other uitools such as the <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>. This turned out to be the missing clue that unveiled these useful tools:</p><h3 id="Intro">So what are <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i>?</h3><p>Both <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> are basic Handle-Graphics building blocks used in Matlab toolbars, similarly to the well-documented <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>.</p><p><i><b>uisplittool</b></i> presents a simple drop-down, whereas <i><b>uitogglesplittool</b></i> presents a drop-down that is also selectable.</p><p>The Publish and Run controls on the Matlab Editor&#8217;s toolbar are examples of <i><b>uisplittool</b></i>, and so are the Brush / Select-Data control on the figure toolbar, and the plot-selection drop-down on the Matlab Desktop&#8217;s Workspace toolbar:<br
/><center><div
class="wp-caption aligncenter" style="width: 371px"><img
alt="uisplittool in action in the Matlab Desktop" src="http://UndocumentedMatlab.com/images/uisplittool.png" title="uisplittool in action in the Matlab Desktop" width="361" height="221" /><p
class="wp-caption-text"><i><b>uisplittool</b></i> in action in the Matlab Desktop</p></div></center></p><h3 id="Appearance">Adding <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar</h3><p>Adding a <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar is done in a similar manner to adding <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hToolbar = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'FigureToolBar'</span><span style="color: #080;">&#41;</span>;
hUndo=uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>;       <span style="color: #228B22;">% uisplittool</span>
hRedo=uitogglesplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% uitogglesplittool</span></pre></div></div><p>Like <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>, <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> also have unique <strong>Type</strong> property values, &#8216;uisplittool&#8217; and &#8216;uitogglesplittool&#8217; respectively. The handles can also be tested using the built-in <i><b>isa</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">isa</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hUndo<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'uisplittool'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% or: 'uitogglesplittool'</span>
<span style="color: #0000FF;">ans</span> =
     <span style="color: #33f;">1</span>
&gt;&gt; <span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hUndo<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
uisplittool</pre></div></div><p>Just as with <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s, the new buttons have an empty button-face appearance, until we fix their <strong>CData</strong>, <strong>Tooltip</strong> and similar settable properties:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Load the Redo icon</span>
icon = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/toolbox/matlab/icons/greenarrowicon.gif'</span><span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>cdata,map<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">imread</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Convert white pixels into a transparent background</span>
map<span style="color: #080;">&#40;</span><span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>==<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> = <span style="color: #0000FF;">NaN</span>;
&nbsp;
<span style="color: #228B22;">% Convert into 3D RGB-space</span>
cdataRedo = ind2rgb<span style="color: #080;">&#40;</span>cdata,map<span style="color: #080;">&#41;</span>;
cdataUndo = cdataRedo<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">16</span><span style="color: #F0F;">:</span>-<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add the icon (and its mirror image = undo) to latest toolbar</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo, <span style="color:#A020F0;">'cdata'</span>,cdataUndo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'undo'</span>,<span style="color:#A020F0;">'Separator'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execUndo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hRedo, <span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'redo'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execRedo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="User-created uisplittool &amp; uitogglesplittool toolbar buttons" src="http://UndocumentedMatlab.com/images/uisplittool2b2.png" title="User-created uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="107" /><p
class="wp-caption-text">User-created <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons</p></div></center></p><p>Note that the controls can be created with these properties in a single command:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hUndo = uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar, <span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Arranging">Re-arranging the toolbar controls placement</h3><p>Let us now re-arrange our toolbar buttons. Unfortunately, a bug causes <i><b>uisplittool</b></i>s and <i><b>uitogglesplittool</b></i>s to always be placed flush-left when the toolbar&#8217;s children are re-arranged (anyone at TMW reading this in time for the R2011a bug-parade selection?).</p><p>So, we can&#8217;t re-arrange the buttons at the HG-children level. Luckily, we can re-arrange directly at the Java level (note that until now, the entire discussion of <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> was purely Matlab-based):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jToolbar = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'ComponentPeer'</span><span style="color: #080;">&#41;</span>;
jButtons = jToolbar.<span style="">getComponents</span>;
<span style="color: #0000FF;">for</span> buttonId = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#41;</span>-<span style="color: #33f;">3</span> <span style="color: #F0F;">:</span> -<span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">7</span>  <span style="color: #228B22;">% end-to-front</span>
   jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>buttonId<span style="color: #080;">&#41;</span>, buttonId+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">5</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% Separator</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">6</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% Undo</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>;     <span style="color: #228B22;">% Redo</span>
jToolbar.<span style="">revalidate</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" src="http://UndocumentedMatlab.com/images/uisplittool2c2.png" title="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="106" /><p
class="wp-caption-text">Re-arranged <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons<br/>(not as simple as it may sound)</p></div></center></p><p>Next week, I will combine the information in this article, with <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/uiundo/">last year&#8217;s articles</a> about <i><b>uiundo</b></i>, and show how we can create a dynamic figure toolbar drop-down of undo/redo events. Here is a preview to whet your appetite:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="undo/redo buttons implemented using uisplittool" src="http://UndocumentedMatlab.com/images/uisplittool4.png" title="undo/redo buttons implemented using uisplittool" width="450" height="226" /><p
class="wp-caption-text">undo/redo buttons implemented using <i><b>uisplittool</b></i></p></div></center></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</small></li><li><a
href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-uiundo/' rel='bookmark' title='Customizing uiundo'>Customizing uiundo</a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Accessing plot brushed data</title><link>http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/</link> <comments>http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/#comments</comments> <pubDate>Wed, 06 Oct 2010 18:00:45 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Callbacks]]></category> <category><![CDATA[Menubar]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[scribe]]></category> <category><![CDATA[UIInspect]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1911</guid> <description><![CDATA[Plot data brushing can be accessed programmatically using very simple pure-Matlab code<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/controlling-plot-data-tips/' rel='bookmark' title='Controlling plot data-tips'>Controlling plot data-tips</a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li><li><a
href='http://undocumentedmatlab.com/blog/accessing-the-matlab-editor/' rel='bookmark' title='Accessing the Matlab Editor'>Accessing the Matlab Editor</a> <small>The Matlab Editor can be accessed programmatically, for a wide variety of possible uses - this article shows how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A few days ago, a reader of the Matlab Desktop blog <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2008/05/12/brush-up-on-your-data/#comment-7364">asked</a> whether it is possible to store plot brushed data in a separate variable for later processing. <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/data_analysis/brh7_p3-1.html#brh7_p3-3">Data Brushing</a>, first introduced in R2008a, enables interactive selection and marking of plot data points. The brushed data can then be stored in a variable using the context (right-click) menu, or the figure&#8217;s Tools/Brushing menu.</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Saving brushed data to a variable" src="http://UndocumentedMatlab.com/images/Brushing1b.png" title="Saving brushed data to a variable" width="450" height="325" /><p
class="wp-caption-text">Saving brushed data to a variable</p></div></center></p><p>The said reader has specifically wanted programmatic access, rather than interactivity. The official answer is that data brushing was designed to be an interactive tool, and so this cannot be done. However, this has never stopped us before. So off I went to launch my favorite inspection tool, the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">UIInspect utility</a> on the figure above (UIInspect will be described in a near-future article), which can be recreated with the following simple code:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">t=<span style="color: #33f;">0</span><span style="color: #F0F;">:</span><span style="color: #33f;">0.2</span><span style="color: #F0F;">:</span><span style="color: #33f;">25</span>; <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>t,<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>t<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'.-'</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% Now brush some data points...</span>
uiinspect<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 460px"><a
target="_blank" href="http://UndocumentedMatlab.com/images/Brushing2a.png"><img
alt="UIInspect-ion of a data-brushed plot" src="http://UndocumentedMatlab.com/images/Brushing2a.png" title="UIInspect-ion of a data-brushed plot" width="450" height="389" /></a><p
class="wp-caption-text">UIInspect-ion of a data-brushed plot (click for details)</p></div></center></p><p>A couple of alternative answers to the reader&#8217;s question were immediately apparent:</p><h3 id="data">Directly accessing brushed data</h3><p>First, we notice that data brushing added data-brushing context menus, both of which are called <i>BrushSeriesContextMenu</i> (the duplication is an internal Matlab bug, that does not affect usability as far as I can tell).</p><p>Also, an invisible scribe overlay axes has been added to hold the new annotations (data brushing is considered an annotation; scribe axes deserve a separate article, which they will indeed get someday).</p><p>More importantly for our needs, we see a new <i><b>line</b></i> item called &#8216;Brushing&#8217;, which displays the red lines and data points that we seek. We can now easily get the brushed data using this line&#8217;s <b>XData</b> and <b>YData</b> properties: <u>non</u>-brushed data points simply have NaN values:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="UIInspect-ion of the data-brushing line" src="http://UndocumentedMatlab.com/images/Brushing2b.png" title="UIInspect-ion of the data-brushing line" width="450" height="325" /><p
class="wp-caption-text">UIInspect-ion of the data-brushing line</p></div></center></p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hBrushLine = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'Brushing'</span><span style="color: #080;">&#41;</span>;
brushedData = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hBrushLine, <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Xdata'</span>,<span style="color:#A020F0;">'Ydata'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
brushedIdx = ~<span style="color: #0000FF;">isnan</span><span style="color: #080;">&#40;</span>brushedData<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
brushedXData = brushedData<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#40;</span>brushedIdx<span style="color: #080;">&#41;</span>;
brushedYData = brushedData<span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#40;</span>brushedIdx<span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% and similarly for ZData in 3D plots</span></pre></div></div><h3 id="callbacks">Accessing brushing callbacks</h3><p>Yet another way of approaching the problem is to use the available callback functions built-into the data-brushing functionality. We can access either the <i>BrushSeriesContextMenu</i> or the figure&#8217;s Tools/Brushing menu. I will leave the former (context-menu) approach as an exercise to the reader, and just describe the figure&#8217;s menu approach.</p><p>As I have already explained in a <a
target="_blank" href="http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/">dedicated article</a>, figure menu-bar actions are accessible via their handles, and we can retrieve that using a unique tag (well, most of the time &#8211; read that article for details). In our case, the Tools/Brushing/Create-new-variable menu item has the unique tag &#8216;figDataManagerNewVar&#8217;. So let&#8217;s use it:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hNewVarMenuItem = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'figDataManagerNewVar'</span><span style="color: #080;">&#41;</span>
hNewVarMenuItem =
          <span style="color: #33f;">742.000244140625</span>
&nbsp;
&gt;&gt; hNewVarCallback = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hNewVarMenuItem,<span style="color:#A020F0;">'callback'</span><span style="color: #080;">&#41;</span>
hNewVarCallback = 
    @datamanager.<span style="">newvar</span>
&nbsp;
&gt;&gt; hNewVarCallback<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% activate the callback</span>
<span style="color: #228B22;">% =&gt; set 'ans' as the new variable holding the brushed data</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">ans</span>
<span style="color: #0000FF;">ans</span> =
                       <span style="color: #33f;">6.4</span>         <span style="color: #33f;">0.116549204850494</span>
                       <span style="color: #33f;">6.6</span>         <span style="color: #33f;">0.311541363513379</span>
                       <span style="color: #33f;">6.8</span>         <span style="color: #33f;">0.494113351138609</span>
                         <span style="color: #33f;">7</span>         <span style="color: #33f;">0.656986598718789</span>
                       <span style="color: #33f;">7.2</span>         <span style="color: #33f;">0.793667863849153</span>
                       <span style="color: #33f;">7.4</span>         <span style="color: #33f;">0.898708095811627</span>
                       <span style="color: #33f;">7.6</span>         <span style="color: #33f;">0.967919672031486</span>
                       <span style="color: #33f;">7.8</span>         <span style="color: #33f;">0.998543345374605</span>
                       <span style="color: #F0F;">...</span>         <span style="color: #F0F;">...</span></pre></div></div><p>Of course, we could also have gone the hard way, via the scribe axes and the annotations route. For masochistic people like me it could even be a worthwhile challenge. But for all other normal people, why bother when there are such simple alternatives, if we only knew how to find them. <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/controlling-plot-data-tips/' rel='bookmark' title='Controlling plot data-tips'>Controlling plot data-tips</a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li><li><a
href='http://undocumentedmatlab.com/blog/accessing-the-matlab-editor/' rel='bookmark' title='Accessing the Matlab Editor'>Accessing the Matlab Editor</a> <small>The Matlab Editor can be accessed programmatically, for a wide variety of possible uses - this article shows how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>GUI automation utilities</title><link>http://undocumentedmatlab.com/blog/gui-automation-utilities/</link> <comments>http://undocumentedmatlab.com/blog/gui-automation-utilities/#comments</comments> <pubDate>Wed, 22 Sep 2010 18:00:28 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Kesh Ikuma]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1877</guid> <description><![CDATA[This article explains a couple of Matlab utilities that use Java's Robot class to programmatically control mouse and keyboard actions<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/gui-automation-robot/' rel='bookmark' title='GUI automation using a Robot'>GUI automation using a Robot</a> <small>This article explains how Java's Robot class can be used to programmatically control mouse and keyboard actions...</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/' rel='bookmark' title='Matlab-Java interface using a static control'>Matlab-Java interface using a static control</a> <small>The switchyard function design pattern can be very useful when setting Matlab callbacks to Java GUI controls. This article explains why and how....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><em>Once again, I welcome guest writer <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/36665">Takeshi (Kesh) Ikuma</a>. Last week, Kesh described how <a
target="_blank" href="http://undocumentedmatlab.com/blog/gui-automation-robot/">Java&#8217;s Robot class can be used to automate Matlab GUI</a>. Today, Kesh will describe two Matlab utilities that help this automation process.</em></p><p><center><img
alt="" src="http://UndocumentedMatlab.com/images/robot.gif" title="" width="96" height="156" /></center></p><p>jMouseEmu and inputEmu are both available on the Matlab File Exchange. There is a large overlap between these utilities. As their name suggests, jMouseEmu is geared to control the mouse, while inputEmu emulates both mouse and keyboard inputs.</p><h3 id="jMouseEmu">jMouseEmu</h3><p>The <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28357-jMouseEmu">jMouseEmu utility</a> is an interface function to simplify the programmatic execution of mouse actions (movements, clicks and wheel scrolls). jmouseemu features include accepting relative position with regards to a specified Handle Graphics control, supporting the Shift and Control click modifier keys, supporting double clicking and mouse dragging, controlling mouse wheel turns and allowing multiple command execution with interval timing specification.</p><p>jmouseemu has two operating modes: single- or multi-command. In this respect, a single jmouseemu command consists of a cursor position and a click option &#8211; multiple such commands can be specified to jmouseemu in the multi-command mode.</p><p>In the single-command mode, the function takes the cursor position information and click options. The click options can be any of the possible <strong>SelectionType</strong> property strings, or &#8220;none&#8221; if no clicking is desired. For example,</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">500</span>,<span style="color: #33f;">250</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'normal'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>places the mouse cursor at the coordinate (500, 250) with respect to the current figure (in Matlab coordinates) and then clicks the left mouse button. If no figure is currently open, the cursor is placed at (500,250) with respect to the bottom-left corner of the screen.</p><p>The reference graphics handle can be added as the first argument. For example, if hEdit is a <i><b>uicontrol</b></i> editbox handle, then</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span>hEdit,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'open'</span><span style="color: #080;">&#41;</span>;
jmouseemu<span style="color: #080;">&#40;</span>hEdit,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'normal'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>provides a simple way to select the entire text in the edit box: the double-click <i><b>jmouseemu</b></i> call selects the first word, then the following single-click <i><b>jmouseemu</b></i> extends the selection to the entire text. If the position argument omitted, the cursor is placed on the upper-left hand corner of the object, unless hEdit=0, in which case the cursor stays at the current position.</p><p>To turn the mouse wheel 600 notches down (towards you), run:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span>-<span style="color: #33f;">600</span>,<span style="color:#A020F0;">'wheel'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Multi-command mode extends the single-command mode by accepting a cell array of commands along with the update interval T in seconds. The command array must have three columns, and its k-th row specifies the mouse command at time (k–1)T second.</p><p>Using the multi-command mode, the above example can be executed with a single <i><b>jmouseemu</b></i> call, placing the commands in a cell array:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span>h,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'open'</span>; <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'normal'</span><span style="color: #080;">&#125;</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% T=0</span></pre></div></div><p>Here, if you omit handles (i.e., the first column of command array) for the second or later commands, it defaults to the handle of the previous command.</p><p>Multi-command mode enables mouse cursor to follow a predefined path. For example, to make the mouse cursor travel in a full circle:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">T = <span style="color: #33f;">0.01</span>; <span style="color: #228B22;">% update every 10 milliseconds</span>
x = <span style="color: #0000FF;">pi</span> * <span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #F0F;">:</span>T<span style="color: #F0F;">:</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>';
pos = <span style="color: #33f;">100</span>*<span style="color: #080;">&#91;</span><span style="color: #0000FF;">cos</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>,<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span> + <span style="color: #33f;">250</span>;
N = numel<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>;
cmds = <span style="color: #0000FF;">cell</span><span style="color: #080;">&#40;</span>N,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% empty click option -&gt; no click</span>
cmds<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#125;</span> = <span style="color: #0000FF;">gcf</span>; <span style="color: #228B22;">% position w.r.t. current figure</span>
cmds<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span> = mat2cell<span style="color: #080;">&#40;</span>pos,<span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span>N,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
jmouseemu<span style="color: #080;">&#40;</span>cmds,T<span style="color: #080;">&#41;</span>;</pre></div></div><p>The command interval is realized by calling robot.<em>delay</em>(T*1e3) between commands. This example updates the mouse position every 10 msecs and completes the circle in 2 seconds.</p><p>In multi-command mode, there are two additional click options, &#8220;drag_on&#8221; and &#8220;drag_off&#8221;, available to enable mouse dragging. Dragging must be initiated and terminated within a single <i><b>jmouseemu</b></i> call, and &#8220;drag_off&#8221; and &#8220;none&#8221; are the only two acceptable click options during dragging.</p><p>Lastly, to pause mouse movement for a moment (longer than the update interval) , a &#8220;delay&#8221; command may be used:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color: #F0F;">...</span>; <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>,<span style="color: #33f;">1.0</span>,<span style="color:#A020F0;">'delay'</span>; <span style="color: #F0F;">...</span><span style="color: #080;">&#125;</span>, T<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% pause for 1 second</span></pre></div></div><h3 id="warning">Using jMouseEmu to trigger multiple Matlab HG callbacks</h3><p><i><b>jmouseemu</b></i> (or more broadly the Matlab handling of Java Robot commands) has a major drawback: If <i><b>jmouseemu</b></i> is used to trigger a Matlab GUI callback during a sequence of mouse maneuver, the callback will not be executed until the entire maneuver is completed. Moreover, since <b>SelectionType</b> property is not logged for every callback event, the incorrect <b>SelectionType</b> property may be reported during callback execution.</p><p>For example, add a double click at the beginning of the circular movement:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">cmds<span style="color: #080;">&#123;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#125;</span> = <span style="color:#A020F0;">'open'</span>;
jmouseemu<span style="color: #080;">&#40;</span>cmds,T<span style="color: #080;">&#41;</span>;</pre></div></div><p>Running this code, you can observe the figure&#8217;s <b>WindowsButtonDownFcn</b> callback, which has been set to echo <b>SelectionType</b> property from earlier, does not kick in until the circle is completed. Now, introduce &#8220;extend&#8221; click at the end of the circle:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">cmds<span style="color: #080;">&#123;</span><span style="color: #0000FF;">end</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#125;</span> = <span style="color:#A020F0;">'extend'</span>;
jmouseemu<span style="color: #080;">&#40;</span>cmds,T<span style="color: #080;">&#41;</span>;</pre></div></div><p>Again, no callback displaying <b>SelectionType</b> echo occurs during the mouse movement. When the callbacks are finally executed, they return in the order – &#8220;normal&#8221;, &#8220;extend&#8221;, &#8220;open&#8221; – instead of expected &#8220;normal&#8221;, &#8220;open&#8221;, &#8220;extend&#8221;. To correct this behavior, <i><b>jmouseemu</b></i> must be called twice:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jmouseemu<span style="color: #080;">&#40;</span>cmds<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>,T<span style="color: #080;">&#41;</span>;
jmouseemu<span style="color: #080;">&#40;</span>cmds<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">end</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>,T<span style="color: #080;">&#41;</span>;</pre></div></div><p>The key here is for each <i><b>jmouseemu</b></i> call to have only one callback triggering mouse click command and to place it at the end of the command sequence.</p><h3 id="inputEmu">inputEmu</h3><p>The <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28603-inputEmu">inputEmu utility</a> is similar to jMouseEmu, with extended support for keyboard inputs. The support for relative mouse cursor position with respect to an HG object, however, has been turned off in the current version of inputEmu (it may get turned on in a future version). Position information in inputEmu is always given in pixels with respect to the lower-left corner of the main display screen. Also, the user must note that the input arguments are flipped between jMouseEmu and inputEmu.</p><p>In addition to the left mouse click commands from jMouseEmu, inputEmu can emulate the right and middle mouse button clicks. For example, to perform the right click (e.g., to open a context menu):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">inputemu<span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'right_down'</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>; <span style="color:#A020F0;">'right_up'</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#125;</span>'<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% execute right button click</span></pre></div></div><p>inputEmu&#8217;s main feature is keyboard support. There are 4 basic commands (the behavior may be somewhat different on non-windows platforms):</p><ul><li>key_normal &#8211; Normal key press</li><li>key_ctrl	- CONTROL + key press</li><li>key_alt &#8211; ALT + key press</li><li>key_win &#8211; WIN + key press</li></ul><p>One other obvious key press, SHIFT + key press, is conspicuously missing from this list. This is because the SHIFT key is automatically pressed when a SHIFT modified character (e.g., an upper-case alphabet) is entered. For example, executing</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">inputemu<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'key_normal'</span>,<span style="color:#A020F0;">'Hello World'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% emulates typing &quot;Hello World&quot;</span></pre></div></div><p>directly in Matlab prompt displays &#8220;Hello World&#8221; in the next command line. The text is first decoded to a sequence of key press and release pairs, including SHIFT key presses and releases as needed, then the sequence of key commands are sent to the java Robot object.</p><p>In addition to all the characters on the keyboard, non-character keys can be stroked by using escape characters:</p><ul><li>&#8216;\SHIFT&#8217;</li><li>&#8216;\CTRL&#8217;</li><li>&#8216;\ALT&#8217;</li><li>&#8216;\WINDOWS&#8217;</li><li>&#8216;\BACKSPACE&#8217;</li><li>&#8216;\TAB&#8217;</li><li>&#8216;\ENTER&#8217;</li><li>&#8216;\ESC&#8217;</li><li>&#8216;\PAGEUP&#8217;</li><li>&#8216;\PAGEDOWN&#8217;</li><li>&#8216;\END&#8217;</li><li>&#8216;\HOME&#8217;</li><li>&#8216;\LEFT&#8217;</li><li>&#8216;\UP&#8217;</li><li>&#8216;\RIGHT&#8217;</li><li>&#8216;\DOWN&#8217;</li><li>&#8216;\INSERT&#8217;</li><li>&#8216;\DELETE&#8217;</li><li>&#8216;\CAPSLOCK&#8217;</li><li>&#8216;\NUMLOCK&#8217;</li><li>&#8216;\SCROLLLOCK&#8217;</li><li>&#8216;\PRINTSCREEN&#8217;</li><li>&#8216;\PAUSE&#8217;</li></ul><p>Also, use &#8216;\\&#8217; for the forward slash character and &#8216;\F1&#8242; – &#8216;\F12&#8242; for the Function keys. For example, to execute a Matlab &#8220;<i><b>ver</b></i>&#8221; command automatically via command window, run</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">inputemu<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'key_normal'</span>,<span style="color:#A020F0;">'ver\ENTER'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% runs the ver command</span></pre></div></div><p>Lastly, as mentioned in the previous article, java.awt.Robot is sensitive to the keyboard locale, and the inputEmu utility is programmed specifically for the US QWERTY keyboard. To use the inputEmu for another keyboard layout, the program has to be modified accordingly. If anyone&#8217;s interested using this utility for different keyboard layout, I&#8217;d be glad to provide assistance.</p><p>Do you use Java&#8217;s Robot class or any of the utilities above in your work? Yair and I would love to hear about your experience in a short <a
href="http://undocumentedmatlab.com/blog/gui-automation-utilities/#respond">comment</a> below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/gui-automation-robot/' rel='bookmark' title='GUI automation using a Robot'>GUI automation using a Robot</a> <small>This article explains how Java's Robot class can be used to programmatically control mouse and keyboard actions...</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li><li><a
href='http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/' rel='bookmark' title='Matlab-Java interface using a static control'>Matlab-Java interface using a static control</a> <small>The switchyard function design pattern can be very useful when setting Matlab callbacks to Java GUI controls. This article explains why and how....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/gui-automation-utilities/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           category
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-09 04:35:53 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/category/figure-window/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      2.485s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328787351; expires=Fri, 08-Feb-2013 11:35:51 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Thu, 09 Feb 2012 11:35:53 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Thu, 09 Feb 2012 12:35:53 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               763c9a31e32c202249ba4b71d5db8e7c
Content-Encoding:   gzip
-->
