<?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; PixelBounds</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/pixelbounds/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 02 Feb 2012 00:24:18 +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>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</title><link>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/</link> <comments>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/#comments</comments> <pubDate>Wed, 06 Jan 2010 21:06:33 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[PixelBounds]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=892</guid> <description><![CDATA[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.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/' rel='bookmark' title='FindJObj GUI &#8211; display container hierarchy'>FindJObj GUI &#8211; display container hierarchy</a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-type-selection-components/' rel='bookmark' title='Plot-type selection components'>Plot-type selection components</a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>In a previous post, I explained that all Matlab GUI (except the axes plotting engine) is based on Java components, and showed how we can use this information to <a
target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">display HTML contents in Matlab <b><i>uicontrol</i></b>s</a>. In <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/findjobj/">other posts</a>, I have shown how a utility called <b><i>findjobj</i></b> can be used to access the underlying Java components to enable customizations that are unavailable in standard Matlab: <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/">setting the line location in an edit-box</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/button-customization/">customizing button appearance</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/">setting uicontrol callbacks</a>, or <a
target="_blank" href="http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/">setting list-box mouse actions</a>. I have also shown how <b><i>findjobj</i></b> can be used to display the component hierarchy of complex Matlab containers such as the <a
target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-customizations/">figure window</a>, <a
target="_blank" href="http://undocumentedmatlab.com/blog/guide-customization/">GUIDE</a> or the <a
target="_blank" href="http://undocumentedmatlab.com/blog/accessing-the-matlab-editor/">Editor</a>.</p><p>The time is therefore well overdue for a formal introduction of <b><i>findjobj</i></b>, explaining its uses and internal mechanism. Of course, readers are welcome to continue using <b><i>findjobj</i></b> as a black-box utility, but I think important insight can be gained from understanding its inner details. <b><i>Findjobj</i></b>&#8216;s code is available for free download on the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">MathWorks File Exchange</a>. It is one of my favorite submissions and is apparently well-liked by users, being highly reviewed and highly downloaded.</p><p><b><i>Findjobj</i></b> has two main purposes:</p><ol><li>Find the underlying Java object reference of a given Matlab handle &#8211; Historically this was the original purpose, hence the utility&#8217;s name. <b><i>Findjobj</i></b> was meant to extend Matlab&#8217;s standard <b><i>findobj</i></b> function, which does not expose Java components.</li><li>Display a container&#8217;s internal components hierarchy in a graphical user interface, to facilitate visualization of complex containers. This was later extended to also display and allow modification of the sub-components&#8217; properties and callbacks.</li></ol><p>Today I will focus on the first (programmatic) aspect;  next week I will describe the second (GUI) aspect.</p><p><b><i>Findjobj</i></b>&#8216;s heart is finding a control&#8217;s underlying Java handle. Unfortunately, this is not exposed by Matlab except in very rare cases. As hard as I tried, I could not find a way to directly access the underlying Java-peer handle. I therefore resorted to getting the control&#8217;s enclosing Java frame (window) reference, and then working down its sub-components hierarchy until finding the Java object(s) which satisfy the position and/or class criteria. To get the enclosing Java frame (aka <i>TopLevelAncestor</i>), I use the Matlab figure&#8217;s undocumented <b>JavaFrame</b> property. Using this property issues a standard warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release. Since it worked so far, I have turned off this warning in <b><i>findjobj</i></b>&#8216;s code, but note that this code may well fail in some future Matlab version. If and when <b>JavaFrame</b> does become obsolete, be sure to look in this blog for workarounds…</p><p>Traversing the frame&#8217;s hierarchy presents several challenges: Main-menu items are accessed using different functions than other Swing components or sub-containers, and are not automatically accessible until first displayed. I have overcome this latter challenge by simulating a menu-open action in case menus should be searched (this is off by default since it takes several seconds and also changes the GUI focus). For &#8220;regular&#8221; sub-containers, sometimes we need to loop over <i>getComponent(&#8230;)</i> and in some other cases over <i>getChildAt(&#8230;)</i>.</p><p>Another challenge was presented by the fact that Java positions start at (0,0) in the <u>top</u> left corner increasing rightward and <u>downward</u>, rather than starting at (1,1) in the bottom left and increasing upward as in Matlab. Moreover, Java positions are always pixel-based and relative to their parent container, which is different from Matlab (if the Matlab units is &#8216;pixels&#8217; then the value is absolute; if &#8216;normalized&#8217; then it returns a non-pixel value). To further complicate matters, some Matlab controls have a different size than their Java counterparts: some controls have a 5-pixel margins while others not, some controls are shifted by a pixel or two from their container&#8217;s border (for a total offset of up to 7 pixels), while some controls (such as popup-menus) have an entirely different reported size. In theory, we could use the Matlab component&#8217;s undocumented <b>PixelBounds</b> property (much faster than <b><i>getpixelposition</i></b>), but unfortunately <b>PixelBounds</b> turns out to be unreliable and returns erroneous values in many cases. Finally, different Java containers/components have different ways of returning their position: for some it is a <i>getLocation()</i> method, for others it is <i>getX()/getY()</i> and for others it is the <b>X</b> and <b>Y</b> properties (that sometimes have no corresponding <i>getX()/getY()</i> accessor methods!).</p><p>Having finally overcome all these challenges (and quite a few smaller ones, documented within the source code), I have wrapped the algorithm in a function interface that tries to emulate <b><i>findobj</i></b>&#8216;s. Using <b><i>findjobj</i></b> can now be as easy as:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Modify the mouse cursor when over the button</span>
hButton = <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: #080;">&#41;</span>;
jButton = findjobj<span style="color: #080;">&#40;</span>hButton<span style="color: #080;">&#41;</span>;
jButton.<span style="">setCursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span>.<span style="">HAND_CURSOR</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 260px"><img
alt="Modified uicontrol cursor - a Java property" src="http://UndocumentedMatlab.com/images/button_cursor_hand.png" title="Modified uicontrol cursor - a Java property" width="105" height="66" /><p
class="wp-caption-text">Modified uicontrol cursor - a Java property</p></div></center></p><p>&#8230;or as complex as:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Find all non-button controls with the specified label</span>
jControls = findjobj<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'property'</span>,<span style="color: #080;">&#123;</span><span style="color:#A020F0;">'text'</span>,<span style="color:#A020F0;">'click me!'</span><span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'not'</span>,<span style="color:#A020F0;">'class'</span>,<span style="color:#A020F0;">'button'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Space here is limited and <b><i>findjobj</i></b> is over 2500 lines long, so I have obviously not covered everything. I encourage you to <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">download the utility</a> and explore the code, and I gladly welcome your feedback.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy/' rel='bookmark' title='FindJObj GUI &#8211; display container hierarchy'>FindJObj GUI &#8211; display container hierarchy</a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-status-bar-components/' rel='bookmark' title='Setting status-bar components'>Setting status-bar components</a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li><li><a
href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-type-selection-components/' rel='bookmark' title='Plot-type selection components'>Plot-type selection components</a> <small>Several built-in components enable programmatic plot-type selection in Matlab GUI - this article explains how...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>Displaying hidden handle properties</title><link>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/</link> <comments>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/#comments</comments> <pubDate>Tue, 05 May 2009 23:03:55 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Hidden property]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[OuterPosition]]></category> <category><![CDATA[PixelBounds]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=237</guid> <description><![CDATA[I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</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/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/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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab Handle Graphics (HG) is a great way to manipulate GUI objects. HG handles often have some undocumented hidden properties. One pretty well-known example is the <strong>JavaFrame</strong> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object.  We can use hidden properties just like any other handle property, using the built-in <b><i>get</i></b> and <b><i>set</i></b> functions.</p><p>But how can we know about these properties? Here are two methods to do so. Like the hidden properties, these two methods are themselves undocumented&#8230;</p><p>1. use the desktop&#8217;s hidden <strong>HideUndocumented</strong> property:</p><blockquote><pre><span style="color: #000000">set(0,</span><span style="color: #800080">'HideUndocumented','off'</span><span style="color: #000000">);</pre></blockquote><p>From now on, when displaying handle properties using <b><i>get</i></b> and <b><i>set</i></b> you&#8217;ll see the hidden properties.</p><p>Note that some of the properties might display a warning indication:</p><blockquote><pre><span style="color: #000000">>> get(gcf)</span>
	Alphamap = [ (1 by 64) double array]
	BackingStore = on
	CloseRequestFcn = closereq
	Color = [0.8 0.8 0.8]
	Colormap = [ (64 by 3) double array]
	CurrentAxes = []
	CurrentCharacter =
	CurrentKey =
	CurrentModifier = [ (1 by 0) cell array]
	CurrentObject = []
	CurrentPoint = [0 0]
	Dithermap<span style="color: #800000">Warning: figure Dithermap is no longer useful
 with TrueColor displays, and will be removed in a future release.</span>
 = [ (64 by 3) double array]
        ...
</pre></blockquote><p>2. Access the properties&#8217; definition in the handle&#8217;s class definition:</p><blockquote><pre><span style="color: #000000">>> ch = classhandle(handle(gcf));
>> props = get(ch,</span><span style="color: #800080">'Properties'</span><span style="color: #000000">);
>> propsVisibility = get(props,</span><span style="color: #800080">'Visible'</span><span style="color: #000000">)';
>> hiddenProps = props(strcmp(propsVisibility,</span><span style="color: #800080">'off'</span><span style="color: #000000">));
>> sort(get(hiddenProps,</span><span style="color: #800080">'Name'</span><span style="color: #000000">))</span>
ans =
    'ALimInclude'
    'ActivePositionProperty'
    'ApplicationData'
    'BackingStore'
    'Behavior'
    'CLimInclude'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'ExportTemplate'
    'HelpFcn'
    'HelpTopicKey'
    'HelpTopicMap'
    'IncludeRenderer'
    'JavaFrame'
    'OuterPosition'
    'PixelBounds'
    'PrintTemplate'
    'Serializable'
    'ShareColors'
    'UseHG2'
    'WaitStatus'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
</pre></blockquote><p>Different HG handles have different hidden properties. Not all these properties are useful. For example, I have found the <strong>PixelBounds</strong> property to be problematic &#8211; (it sometimes reports incorrect values!). Other properties (like <strong>Dithermap</strong> or <strong>ShareColors</strong>) are deprecated and display a warning wherever they are accessed.</p><p>But every so often we find a hidden property that can be of some actual benefit. Let&#8217;s take the figure handle&#8217;s <strong>OuterPosition</strong> property for example. It provides the figure&#8217;s external position values, including the space used by the window frame, toolbars etc., whereas the regular documented <strong>Position</strong> property only reports the <b>internal</b> bounds:</p><blockquote><pre><span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'pos'</span>)
ans =
   232   246   560   420
<span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'outer'</span>)
ans =
   228   242   568   502
</pre></blockquote><p>In future posts I will sometimes use such hidden properties. You can find the latest list by looking at this blog&#8217;s <a
href="http://undocumentedmatlab.com/blog/category/Hidden-property/" target="_blank">&#8220;Hidden property&#8221;</a> category page.</p><p>Note: Like the rest of Matlab&#8217;s undocumented items, all hidden properties are undocumented, unsupported and may well change in future Matlab releases so use them with care.</p><p>Did you find any useful hidden property? If so, then please leave your finding in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</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/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/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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           tag
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-04 03:41:06 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/pixelbounds/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.750s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328352066; expires=Sun, 03-Feb-2013 10:41:06 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:41:06 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:41:06 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               0cbf7838e14abc0bb845c61ebc8d88a6
Content-Encoding:   gzip
-->
