<?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>UIInspect &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/uiinspect/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 13 Feb 2013 18:00:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Getting default HG property values</title>
		<link>https://undocumentedmatlab.com/articles/getting-default-hg-property-values?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-default-hg-property-values</link>
					<comments>https://undocumentedmatlab.com/articles/getting-default-hg-property-values#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 13 Feb 2013 18:00:01 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3622</guid>

					<description><![CDATA[<p>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values">Getting default HG property values</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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>
<li><a href="https://undocumentedmatlab.com/articles/plot-linesmoothing-property" rel="bookmark" title="Plot LineSmoothing property">Plot LineSmoothing property </a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>All Matlab&#8217;s Handle Graphics (HG) property have default values. These values are used unless we specifically override the property value. For example, in R2012a, Matlab <i><b>figure</b></i> handles have 62 documented and 28 <a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/">undocumented</a> properties, all of which have some default value. When we create a new Matlab figure, we typically override only a handful of these properties.<br />
<figure style="width: 259px" class="wp-caption alignright"><img fetchpriority="high" decoding="async" alt="How Matlab determines an HG property value" src="https://undocumentedmatlab.com/images/hg_objects7.gif" title="How Matlab determines an HG property value" width="259" height="543" /><figcaption class="wp-caption-text">How Matlab determines an HG property value</figcaption></figure><br />
For example, we might override the figure&#8217;s <b>Name</b>, <b>NumberTitle</b>, <b>Position</b>, <b>Visible</b>, <b>Colormap</b> and perhaps a few other properties. All the others are either read-only (i.e., un-settable), or left at their default values. This is also true for all HG objects: axes, images, plots, patches, uicontrols, annotations, Java control containers etc.<br />
Matlab makes a distinction between <i>factory</i> and <i>default</i> values. Users can modify the default values, but not the factory values, which makes sense. In essence, user-specified property values override the default values, which in turn override the factory values. I find that this makes the process of using default values quite intuitive. I like this factory/default design.<br />
Matlab has a dedicated <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/setting-default-property-values.html">doc page</a> explaining how we can use, set and reset the default property values.<br />
Unfortunately, MathWorks has not seen fit to explain how to get the full list of current default defaults, nor how to get the factory values. Today&#8217;s article provides the missing manual pages and completes the picture.<br />
<span id="more-3622"></span></p>
<h3 id="accessing">Accessing default and factory property values</h3>
<p>To access any specific property&#8217;s default value, we need to compose a fictitious property name from the string &#8216;Default&#8217; or &#8216;Factory&#8217;, followed by the object&#8217;s type (&#8216;Figure&#8217;, &#8216;Axes&#8217;, &#8216;Line&#8217; etc., as reported by the object&#8217;s <b>Type</b> property), and lastly the property name. For example: <b>DefaultFigureColor</b> or <b>FactoryAxesUnits</b>. As with all HG properties, these names are case insensitive. These fictitious properties all belong to Matlab&#8217;s root (0) handle.<br />
We can now <i><b>get</b></i> and <i><b>set</b></i> the values of any of these fictitious properties (naturally, factory properties cannot be set):</p>
<pre lang='matlab'>
>> get(0,'FactoryFigureUnits')
ans =
pixels
>> get(0,'FactoryFigureColor')
ans =
     0     0     0
>> get(0,'DefaultFigureColor')
ans =
                       0.8                       0.8                       0.8
>> set(0,'DefaultFigureColor','y');  % new figures will now have a yellow background color...
>> set(0,'DefaultFigureColor','factory');  % resets the default value to the factory value [0,0,0]=black
</pre>
<p>Note that since the default and factory property names are fictitious (i.e., dynamic properties that are parsed on-the-fly), they do not appear when you <i><b>get(0)</b></i>, <i><b>getundoc(0)</b></i> or even <i><b>uiinspect(0)</b></i>.<br />
My <a target="_blank" href="/articles/uiinspect/"><i><b>uiinspect</b></i> utility</a> reports the factory values in its property-details panel, along with additional meta-data such as whether the properties are settable, readable etc.<br />
<center><figure style="width: 495px" class="wp-caption aligncenter"><img decoding="async" alt="uiinspect's 'Other properties' meta-data table" src="https://undocumentedmatlab.com/images/uiinspect_properties2.gif" title="uiinspect's 'Other properties' meta-data table" width="495" height="317" /><figcaption class="wp-caption-text">uiinspect's 'Other properties' meta-data table</figcaption></figure></center></p>
<h3 id="list">Getting the full list of factory/default values</h3>
<p>To get the long list of factory values, simply <i><b>get</b></i> a partial fictitious property name:</p>
<pre lang='matlab'>
>> get(0,'factory')
ans =
                         factoryFigureAlphamap: [1x64 double]
                       factoryFigureBusyAction: 'queue'
                    factoryFigureButtonDownFcn: ''
                         factoryFigureClipping: 'on'
                  factoryFigureCloseRequestFcn: 'closereq'
                            factoryFigureColor: [0 0 0]
                        (... 655 additional properties ...)
>> get(0,'default')
ans =
               defaultTextColor: [0 0 0]
              defaultAxesXColor: [0 0 0]
              defaultAxesYColor: [0 0 0]
              defaultAxesZColor: [0 0 0]
          defaultPatchFaceColor: [0 0 0]
          defaultPatchEdgeColor: [0 0 0]
               defaultLineColor: [0 0 0]
    defaultFigureInvertHardcopy: 'on'
             defaultFigureColor: [0.8 0.8 0.8]
               defaultAxesColor: [1 1 1]
          defaultAxesColorOrder: [7x3 double]
          defaultFigureColormap: [64x3 double]
        defaultSurfaceEdgeColor: [0 0 0]
         defaultFigurePaperType: 'A4'
        defaultFigurePaperUnits: 'centimeters'
         defaultFigurePaperSize: [20.98404194812 29.67743169791]
          defaultFigurePosition: [200 200 560 420]
>> get(0,'DefaultAxes')
ans =
        defaultAxesXColor: [0 0 0]
        defaultAxesYColor: [0 0 0]
        defaultAxesZColor: [0 0 0]
         defaultAxesColor: [1 1 1]
    defaultAxesColorOrder: [7x3 double]
</pre>
<p>We can see that the defaults list is much shorter than the factory list. There are very few actual default overrides of the factory values. In fact, if we try to get the default value of a property that was not overridden (e.g., <b>DefaultFigureNumberTitle</b>), Matlab is smart enough to return the factory value (in this case, <b>FactoryFigureNumberTitle</b>=&#8217;on&#8217;).</p>
<h3 id="hidden">Hidden properties</h3>
<p>Hidden (undocumented) properties are not shown by default, but you can always access them <a target="_blank" href="/articles/plot-linesmoothing-property/#comment-8807">directly</a>, and their list can also be seen if we set the root handle&#8217;s <a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/"><b>HideUndocumented</b> property</a>:</p>
<pre lang='matlab'>
>> get(0,'FactoryAxesLooseInset')
ans =
         0.13         0.11         0.095         0.075
>> get(0,'DefaultPatchLineSmoothing')
ans =
off
>> set(0,'DefaultLineLineSmoothing','on');  % default appears to be 'off' for Windows, 'on' for Macs
>> set(0,'HideUndocumented','off')
>> allPropDefaults = get(0,'factory');
>> length(fieldnames(allPropDefaults))   % 661 documented + 277 undocumented properties
ans =
   938
</pre>
<h3 id="factory">Factory values internals</h3>
<p>For those interested in some internals, the factory values are stored (and can be accessed) via the object&#8217;s UDD reference, or rather the <i><b>schema.prop</b></i> reference of the properties (additional information on UDD properties can be found <a target="_blank" href="/articles/udd-properties/">here</a>). For example:</p>
<pre lang='matlab'>
>> get(0,'FactoryFigurePosition')
ans =
   100   100   660   520
>> hProp = findprop(handle(gcf),'pos')
hProp =
	schema.prop
>> get(hProp)
            Name: 'Position'
     Description: ''
        DataType: 'figurePositionType'
    FactoryValue: [100 100 660 520]
     AccessFlags: [1x1 struct]
         Visible: 'on'
     GetFunction: []
     SetFunction: []
>> hProp.FactoryValue
ans =
   100   100   660   520
</pre>
<p>Note that in this example, the <b>FactoryFigurePosition</b> value ([100 100 660 520]) is different than the <b>DefaultFigurePosition</b> value ([200 200 560 420]), which overrides it.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Setting default values enables easy setup of property values for all instances of an HG property in a Matlab session. It could be very tempting to add such setup to the <i>startup.m</i> file, so that such customizations automatically occur for all Matlab sessions. However, I strongly suggest against this: the moment you will try to run your application on any other computer or Matlab installation, you may find that your GUI/graphics look entirely different.<br />
A much safer approach is to understand how these default values affect your application and then specifically set the desired property values in your m-code. This way, whatever the installation&#8217;s default values are, your application will always retain a consistent look-and-feel.<br />
Have you found or ever used any interesting default or factory property value? If so, please share your experience in a <a href="/articles/getting-default-hg-property-values/#respond">comment</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values">Getting default HG property values</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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>
<li><a href="https://undocumentedmatlab.com/articles/plot-linesmoothing-property" rel="bookmark" title="Plot LineSmoothing property">Plot LineSmoothing property </a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/getting-default-hg-property-values/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>uiinspect</title>
		<link>https://undocumentedmatlab.com/articles/uiinspect?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uiinspect</link>
					<comments>https://undocumentedmatlab.com/articles/uiinspect#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 23 Jan 2013 18:00:09 +0000</pubDate>
				<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[COM]]></category>
		<category><![CDATA[Dot-Net]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3477</guid>

					<description><![CDATA[<p>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiinspect">uiinspect</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/propertiesgui" rel="bookmark" title="propertiesGUI">propertiesGUI </a> <small>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>After several years in which I have mentioned my <i><b>uiinspect</b></i> utility in posts, I figured it is high time to actually describe this utility in detail.<br />
<figure style="width: 500px" class="wp-caption alignright"><img decoding="async" alt="uiinspect in action (Java, HG, COM)" src="https://undocumentedmatlab.com/images/uiinspect.gif" title="uiinspect in action (Java, HG, COM)" width="500" height="387"/><figcaption class="wp-caption-text">uiinspect in action (Java, HG, COM)</figcaption></figure><br />
<i><b>uiinspect</b></i>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">downloadable</a> from the Matlab file Exchange, is a Matlab GUI utility that inspects the specified object and provides detailed information about its super-classes, methods, properties, static fields and callbacks in a unified Matlab window. <i><b>uiinspect</b></i> works on a very wide variety of inputs: Matlab/Java/Dot-Net class names and class objects; COM/DCOM objects, Handle Graphics handles etc.<br />
In essence, <i><b>uiinspect</b></i> incorporates the information presented by the following built-in Matlab functions: <i><b>inspect</b></i>, <i><b>get</b></i>, and <i><b>methodsview</b></i>. <i><b>uiinspect</b></i> also presents additional aspects that are not available in any built-in Matlab function (for example, inheritance information, undocumented hidden properties, properties meta-data, grouping of callbacks by type).<br />
<i><b>uiinspect</b></i> displays hidden properties and fields that are not normally displayed in Matlab (see my related <a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/">getundoc</a> utility). Property meta-data such as type, accessibility, visibility and default value are also displayed. Object properties and callbacks may be modified interactively within the <i><b>uiinspect</b></i> window.<br />
Of over 40 utilities that I have so-far submitted to the File Exchange, <i><b>uiinspect</b></i> is one of my most complex (together with <a target="_blank" href="/articles/findjobj"><i><b>findjobj</b></i></a>). It has undergone 24 revisions since its initial release in 2007. The latest revision has nearly 3000 source-code lines, of which 75% are code lines, 20% are comment lines and the rest are empty spacer lines. That&#8217;s a pretty complex utility to describe, and it relies on plenty of undocumented aspects, so today&#8217;s post will only highlight the important aspects. Readers are more than welcome to have a look at the source code for additional details. It is pretty-well documented, if I may say so myself.<br />
<span id="more-3477"></span></p>
<h3 id="syntax">Usage syntax</h3>
<p>The basic syntax is:</p>
<pre lang='matlab'>hFig = uiinspect(handle)</pre>
<p>Examples:</p>
<pre lang='matlab'>
hFig = uiinspect(0);                         % the root handle
hFig = uiinspect(handle(0));
hFig = uiinspect(gcf);                       % current figure
hFig = uiinspect(handle(gcf));
uiinspect('java.lang.String');               % Java classname
uiinspect(java.lang.String('yes'));          % Java object
uiinspect(get(gcf,'JavaFrame'));             % Java object
uiinspect(classhandle(handle(gcf)));         % UDD class object
uiinspect(findprop(handle(gcf),'MenuBar'));  % UDD property
uiinspect(actxserver('Excel.Application'));  % COM object
uiinspect(Employee)                          % Matlab class object
uiinspect(?handle)                           % Matlab metaclass object
uiinspect('meta.class')                      % Matlab class name
uiinspect(System.DateTime.Now)               % Dot-Net object
</pre>
<p><i><b>uiinspect</b></i> returns a handle to the created figure window. <i><b>uiinspect</b></i> opens a regular Matlab figure window which may be accessed via hFig (unlike Matlab&#8217;s <i><b>methodsview</b></i> and <i><b>inspect</b></i> functions which open Java frame that is not accessible from Matlab).<br />
Unlike Matlab&#8217;s functions, multiple <i><b>uiinspect</b></i> windows can be opened simultaneously, for different objects. The differentiation is done based on figure title, which contains the inspected object&#8217;s name (if available) and its class &#8211; reinspecting the same object will reuse the existing figure window, but in all other cases a new figure window will be created.</p>
<h3 id="panels">Main panels</h3>
<p><i><b>uiinspect</b></i> includes the following information panels, that shall be described separately below:</p>
<ul>
<li>Class information (including superclasses, if applicable)</li>
<li>Methods (for objects) or graphic handle hierarchy (for Handle Graphics)</li>
<li>Callbacks (where applicable)</li>
<li>Inspectable properties</li>
<li>Other properties plus full meta-data (where applicable)</li>
</ul>
<p>The panels are fully resizable. We can drag the divider lines up/down or left/right and the contents automatically adjust accordingly. Each panel has a minimal viewable width/height, and the dividers cannot be dragged to squeeze the panels below these minimums &#8211; they can only be minimized, which hides the relevant panel entirely. To minimize a panel, simply click the relevant small arrow mark on the divider. The opposite arrow mark next to it maximizes the panel, effectively minimizing the panel on the other side. Once minimized/maximized, the divider can be restored by simply clicking it once, or by dragging it (again, panel minimum sizes apply).<br />
<i><b>uiinspect</b></i> only uses Java panels, so implementing the dividers required use of the simple <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html">JSplitPane</a>. In a general case where we might wish to embed Matlab graphs in one of the side panels, we would need to employ a more sophisticated solution (see my <a target="_blank" href="/articles/uisplitpane/">UISplitPane</a> utility).</p>
<h3 id="class">Class information</h3>
<p>The top-left panel displays a label with information about the object&#8217;s class and super-classes inheritance (where applicable).<br />
The class name itself is hyper-linked to the class&#8217;s documentation: if this is a standard Java class, then to the official online javadoc for this class which opens up in Matlab&#8217;s internal web browser. In fact, since different Matlab releases use different JVM versions (1.3 through 1.6), the link points to the documentation page corresponding to the JVM version actually used.<br />
If the class is non-Java, the hyperlink displays the class&#8217;s help section in Matlab&#8217;s Command Window / console. The panel&#8217;s tooltip displays the same information in a slightly different manner.<br />
The hyperlink in the label is actually an optical illusion. In fact, the entire label is hyper-linked, and clicking any part of it will display the relevant documentation (a similar optical illusion is used to display the hyperlink at the footer of the utility window). The illusion is achieved using <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">Matlab&#8217;s HTML formatting</a>, where the part of the label string consisting of the class name is underlined. The cursor was dynamically modified to a pointed hand-finger when the mouse hovers over the label, using the following simple Java-based command:</p>
<pre lang='matlab'>methodsLabel.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));</pre>
<p>Special treatment is done to extract the class&#8217;s superclass, the interfaces that it implements and any possible class qualifiers (for example, &#8220;final&#8221;).<br />
For those interested to dig within the code, all this is done in <i><b>uiinspect</b></i>&#8216;s <i>getMethodsPane</i> function.<br />
Next to the class label, a checkbox is presented (&#8220;Extra&#8221;). Clicking this checkbox displays additional meta-data information (qualifiers, interrupts and inheritance) in the methods pane beneath. Not all classes have all these extra meta-data fields &#8211; only the relevant extra meta-information fields are displayed. If there are is extra meta-data, then the checkbox is not displayed. This is done in the <i>getMethodsTable</i> function.</p>
<h3 id="methods">Methods or HG hierarchy panel</h3>
<p>The utility&#8217;s main panel displays either a table of methods (functions) for a class object, or a tree hierarchy for an HG handle.</p>
<h4 id="class-methods">Class object methods</h4>
<p>The methods table takes the information from the <i>getObjMethods</i> function, which is an adaptation of Matlab&#8217;s built-in <i><b>methodsview</b></i> function. Part of the adaptation is to hyperlink all class references (used in the methods&#8217; inputs, outputs and meta-data), such that clicking them will open new corresponding <i><b>uiinspect</b></i> windows.<br />
<figure style="width: 468px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Class object methods panel" src="https://undocumentedmatlab.com/images/uiinspect_methods.gif" title="Class object methods panel" width="468" height="219" /><figcaption class="wp-caption-text">Class object methods panel</figcaption></figure><br />
The methods data is displayed within a non-editable Java table (in the <i>getMethodsTable</i> function) that auto-resizes the columns. The table columns are sortable, even sortable on multiple columns by CTRL-clicking (<i><b>methodsview</b></i> allows only simple sorting). This is done using JIDE&#8217;s <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/TreeTable.html">TreeTable</a> component. The table is placed within a scroll-pane having <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html#scrollbars">automatic scrollbars</a> that only appear as needed.<br />
The table&#8217;s <b>MouseMovedCallback</b> property is set to <i>tbMouseMoved</i>, which updates the mouse cursor (either regular or pointed finger) based on the current mouse position in the table (whether over a hyperlinked cell or not).<br />
The table&#8217;s <b>MousePressedCallback</b> property is set to <i>tbMousePressed</i>, which opens new <i><b>uiinspect</b></i> figure windows for the hyperlinked classes (if any) in the clicked cell.</p>
<h4 id="HG-hierarchy">HG hierarchy tree</h4>
<p>For HG handles, <i>getHandleTree</i> creates a Java tree that displays the hierarchy of HG children (as recursively reported by any HG handle&#8217;s <b>Children</b> property). For convenience, I have chosen to use the built-in component <code>com.mathworks.hg.peer.UITreePeer</code> that underlies the built-in <a target="_blank" href="/articles/uitree/"><i><b>uitree</b></i></a> function. For performance reasons, the tree is not fully evaluated: the inspected handle&#8217;s <b>Parent</b> is set as the tree&#8217;s <b>Root</b>. The root node is expanded to get all the parent&#8217;s <b>Children</b> (i.e., the inspected handle&#8217;s siblings), and then the inspected handle&#8217;s tree node is again expanded to display its direct descendents.<br />
<figure style="width: 283px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Normal dynamic HG handle tooltip" src="https://undocumentedmatlab.com/images/uiinspect_HG_tooltip1.gif" title="Normal dynamic HG handle tooltip" width="283" height="115" /><figcaption class="wp-caption-text">Normal dynamic HG handle tooltip</figcaption></figure><br />
A <b>MouseMovedCallback</b> is set on the tree to process mouse hover events in the <i>treeMouseMovedCallback</i> function. This function updates the tree tooltip dynamically, in the sense that it presents a different tooltip for different handles (tree nodes).<br />
Invalid HG handles (this can happen if the HG handle was deleted since the time that <i><b>uiinspect</b></i> generated the tree) are displayed with a special warning message.<br />
<figure style="width: 350px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Invalid HG handle tooltip" src="https://undocumentedmatlab.com/images/uiinspect_HG_tooltip2.gif" title="Invalid HG handle tooltip" width="350" height="44" /><figcaption class="wp-caption-text">Invalid HG handle tooltip</figcaption></figure><br />
This dynamic tree behavior is achieved by storing the relevant handle information in the <b>UserData</b> of the different tree nodes. Unfortunately, starting in R2012a, Matlab has made a change in the internal support of Java objects, and the <b>UserData</b> property is no longer available. Such a case is detected and the data is stored in the tree nodes&#8217; <b>ApplicationData</b> property instead (using <i><b>setappdata</b>(node,&#8217;userdata&#8217;,&#8230;)</i> ).<br />
<figure style="width: 630px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Dynamic context (right-click) menu" src="https://undocumentedmatlab.com/images/uiinspect3.gif" title="Dynamic context (right-click) menu" width="630" height="488" /><figcaption class="wp-caption-text">Dynamic context (right-click) menu</figcaption></figure><br />
A <b>MousePressedCallback</b> is set on the tree to process context (right-click) events in the <i>treeMousePressedCallback</i> function. The context-menu is also dynamic, in the sense that it presents a different context menu for different handles (tree nodes), again based on their user-data.<br />
Left-clicking a node is not processed by <i>treeMousePressedCallback</i>, but rather by the tree&#8217;s <b>NodeSelectedCallback</b> which is processed in <i>nodeSelected</i>, and by <b>NodeExpandedCallback</b> which is processed by <i>nodeExpanded</i>. <i>nodeSelected</i> reloads <i><b>uiinspect</b></i> for the selected handle; <i>nodeExpanded</i> merely displays the expanded handle&#8217;s children.<br />
Since the &#8216;+&#8217; sign (which triggers <i>nodeExpanded</i>) and the handle icon (which triggers <i>nodeSelected</i>) are so close, we should be careful to click the &#8216;+&#8217;, otherwise the entire <i><b>uiinspect</b></i> window will reload the tree based on the clicked node&#8230; If anyone has a good idea how to solve this dilemma, then I&#8217;m all ears.<br />
Like the methods table, the tree is also placed in a dynamic scroll-pane that displays scrollbars only as needed.</p>
<h3 id="callbacks">Callbacks panel</h3>
<p>The callbacks panel, computed in <i>getCbsData</i> is based on a reflection of the object&#8217;s data as reported by the undocumented built-in <i><b>classhandle</b></i> function. I aggregate all the object&#8217;s events, as well as all the object property names that end with &#8216;Fcn&#8217; or &#8216;Callback&#8217;. This takes care (I hope) of all the different manners by which different kinds of objects raise events that are trappable in Matlab callbacks. Specifically, it takes care of Java/Matlab classes as well as HG handles and COM objects. If anyone thinks that I have forgotten something, please let me know.<br />
The <i>getCbsPane</i> function then displays the callbacks data (callbacks&#8217; property name and value) in a Java table (JIDE <a target="_blank" href="/articles/jide-property-grids/">PropertyTable</a>, JIDE TreeTable, or failing those a simple JTable).<br />
<figure style="width: 551px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Modifiable object callbacks" src="https://undocumentedmatlab.com/images/uiinspect_callbacks.gif" title="Modifiable object callbacks" width="551" height="337" /><figcaption class="wp-caption-text">Modifiable object callbacks</figcaption></figure><br />
The callbacks are automatically grouped by name into logical groups (in <i>getTreeData</i>). For example, all callbacks whose names start with &#8220;Mouse*&#8221; are grouped in the &#8220;Mouse callbacks&#8221; group. The last group is always called &#8220;Other callbacks&#8221; and contains all callbacks for which a matching sibling callback has not been found. The groups are automatically collapsed by default; if only a single group is found then this group is automatically opened (for example, in the case of <i><b>uiinspect</b>(0)</i> ).<br />
The callbacks table&#8217;s toolbar enables displaying the callbacks by groups or sorted alphabetically. It also has &#8220;expand&#8221; and &#8220;collapse&#8221; icons that affect all the groups.<br />
A checkbox next to the table&#8217;s toolbar enables hiding <a target="_blank" href="/articles/uicontrol-callbacks/">standard Java Swing callbacks</a>. This is important when we inspect Java controls and only wish to see its unique callbacks. When using this checkbox, red Java exceptions are sometimes displayed in the Matlab console &#8211; these are harmless and you can safely ignore them (I hope to find a way to prevent them one day).<br />
The table&#8217;s right column displays the callback properties values (if available). This column is editable and we can interactively modify any callback&#8217;s property. As shown, we can enter callback value in either of Matlab&#8217;s supported formats: string, function handle and (for non-COM objects only!) a cell array of function handle and additional data. An error message will be displayed if the callback value is invalid or cannot be set for some reason.<br />
If it is determined that there are no callbacks, then the callbacks panel is automatically minimized, to enable maximum space for the methods panel above it.</p>
<h3 id="inspector">Properties inspector panel</h3>
<p>The properties inspection panel, prepared in <i>getPropsPane</i>, is actually composed of two separate panes: the top pane uses the built-in Matlab component <code>com.mathworks.mlwidgets.inspector.PropertyView</code>, which in turn uses JIDE&#8217;s <a target="_blank" href="/articles/jide-property-grids/">PropertyTable</a>. <code>PropertyView</code> is the same component used by Matlab&#8217;s standard <i><b>inspect</b></i> function (that&#8217;s how I came to know it, if anyone wonders).<br />
<figure style="width: 351px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="uiinspect's property inspector table" src="https://undocumentedmatlab.com/images/PropertyTable.gif" title="uiinspect's property inspector table" width="351" height="216" /><figcaption class="wp-caption-text">uiinspect's property inspector table</figcaption></figure><br />
The benefit of using Matlab&#8217;s <code>PropertyView</code> component rather than JIDE&#8217;s <code>PropertyTable</code> is that <code>PropertyView</code> has the very useful method <i>setObject</i> which I use to point the component at the inspected object, which automatically infers its non-hidden properties and updates the table, saving me a lot of work.<br />
There are two drawbacks of using Matlab&#8217;s <code>PropertyView</code>:</p>
<ul>
<li><code>PropertyView</code> only displays non-hidden properties. One day when I have time, I intent to add the hidden properties to the resulting JIDE <code>PropertyTable</code>. But for now it only shows non-hidden properties.</li>
<li><code>PropertyView</code> causes a Matlab crash on some Matlab releases, in case <i><b>dbstop if error</b></i> is active (this can be replicated using Matlab&#8217;s standard <i><b>inspect</b></i>). I therefore regrettably need to disable this specific <i><b>dbstop</b></i>.</li>
</ul>
<p>I&#8217;ve been meaning to do these two fixes ever since I released <i><b>uiinspect</b></i> back in 2007, but for now that&#8217;s the way it is&#8230;<br />
The properties data is retrieved via the <i>getPropsData</i> function. This function uses the built-in Matlab functions <i><b>meta.class.fromName</b>(className)</i> and <i><b>metaclass</b>(classObject)</i> to get the class handle of Matlab classes (in <i>getMetaClass</i>); similarly, <i>loadClass</i> loads the class definition for a Java class. I inspect these class handles for their contained properties. I then use the <i><b>fieldnames</b></i> function to add static class fields, which are not standard properties (for example, &#8220;RED&#8221; is a static field of the <code>java.awt.Color</code> class).<br />
From the class handle, I retrieve the full definition of each property. This includes meta-data such as whether the property is regular or hidden (undocumented); settable or not; gettable or not; and any additional qualifiers (e.g., Sealed, Dependent, Constant, Abstract, Transient, Default (factory) value).<br />
<figure style="width: 450px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Object properties tooltip" src="https://undocumentedmatlab.com/images/uiinspect_properties1.gif" title="Object properties tooltip" width="450" height="297"/><figcaption class="wp-caption-text">Object properties tooltip</figcaption></figure><br />
We now have a list of all properties and static fields, and this is used to display the entire properties data in the properties panel&#8217;s title (&#8220;Inspectable object properties&#8221;) tooltip. This tooltip, created in <i>updateObjTooltip</i> and <i>getPropsHtml</i>, uses some fancy HTML formatting to display all the object&#8217;s properties and values, color- and font-style-coded to show which of the properties is read-only, hidden, undefined etc.<br />
<figure style="width: 495px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="The 'Other properties' meta-data table" src="https://undocumentedmatlab.com/images/uiinspect_properties2.gif" title="The 'Other properties' meta-data table" width="495" height="317" /><figcaption class="wp-caption-text">The 'Other properties' meta-data table</figcaption></figure><br />
The entire information is also displayed in the properties meta-data pane (&#8220;Other properties&#8221;) beneath JIDE&#8217;s inspector pane. Here we use a simple Java table to display the information in color-coding (gray for read-only properties; blue for static fields; red for irretrievable properties).<br />
Separate checkboxes enable displaying all properties (by default only the properties that are NOT displayed in JIDE&#8217;s inspector table are displayed); and whether or not to display the extra meta-data in the properties table (by default only the property name and current value are displayed).<br />
In some cases (e.g., Dot-Net objects), Matlab&#8217;s inspector does not know how to extract the property-bean information and so the <code>PropertyView</code> inspector is not shown, only the &#8220;other properties&#8221; table.<br />
Both JIDE&#8217;s inspector table and the &#8220;other properties&#8221; table enable the user to modify existing values. Note that in some cases Matlab prevents interactive update of some properties, and in some other cases I have seen Matlab hang when trying to update a few specific properties. But in most cases updating the value does work as expected.<br />
The combination of the inspector table, the meta-data table and the tooltip, enable users to fully understand the accessible properties of the inspected object. Of course, it would have been much better to merge the JIDE inspector table with the hidden properties (=additional rows) and meta-data (=additional columns). But let&#8217;s leave something for the future, shall we?</p>
<h3 id="update">Auto-update mechanism</h3>
<p><figure style="width: 519px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="uiinspect auto-update notice" src="https://undocumentedmatlab.com/images/uiinspect_update.gif" title="uiinspect auto-update notice" width="519" height="190" /><figcaption class="wp-caption-text">uiinspect auto-update notice</figcaption></figure><br />
<i><b>uiinspect</b></i> employs the same auto-update background mechanism used by <i><b>findjobj</b></i> &#8211; after presenting the GUI, the utility silently checks the File Exchange webpage to see whether any newer version of this utility has been uploaded. If so, then a popup notice is presented with the date and description of the latest version. The popup enables users to download the newer version into their Matlab path, or skip. There is also an option to skip the update and not to remind ever again.<br />
I find this background auto-update mechanism quite useful and generic. In fact, I uploaded it as a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/39993-checkVersion">separate File Exchange utility</a> today, following <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2012/12/14/a-conversation-about-managing-file-exchange-downloads/#comment-17358">Brett Shoelson&#8217;s suggestion</a> last month. You can find the underlying code in the <i>checkVersion</i> function.</p>
<h3 id="TODO">TODO</h3>
<ul>
<li>cleanup internal functions, remove duplicates etc.</li>
<li>link property objects to another <i><b>uiinspect</b></i> window for these objects</li>
<li>display object children (&#038; link to them) &#8211; COM/Java</li>
<li>find a way to merge the other-properties table with the inspector table (hidden props + meta-data)</li>
<li>find a way to use the inspector without disabling <i><b>dbstop if error</b></i></li>
<li>Fix: some fields generate a Java Exception from: <code>com.mathworks.mlwidgets.inspector.PropertyRootNode$PropertyListener$1$1.run</code></li>
<li>Fix: using the &#8220;Hide standard callbacks&#8221; checkbox sometimes issues Java Exceptions on the console</li>
<li>Fix: In HG tree view, sometimes the currently-inspected handle is not automatically selected</li>
</ul>
<p>I would be happy if anyone can help with any of these.</p>
<h3 id="conclusion">Conclusion</h3>
<p>I believe that this has been my longest blog post ever; certainly the one that I have labored most over. This correlates well with the <i><b>uiinspect</b></i> utility, which has been one of my most complex tasks. I&#8217;m guessing I must have invested 100-200 man-hours developing and improving it over the years.<br />
I hope you find <i><b>uiinspect</b></i> as useful and as fun as I do. I believe that its source-code is certainly worth reading if you are interested in any advanced Matlab GUI programming, showing how Java GUI components can be combined in Matlab. Go ahead and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">download <i><b>uiinspect</b></i></a> from the Matlab file Exchange.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uiinspect">uiinspect</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jide-property-grids" rel="bookmark" title="JIDE Property Grids">JIDE Property Grids </a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/propertiesgui" rel="bookmark" title="propertiesGUI">propertiesGUI </a> <small>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uiinspect/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Pinning annotations to graphs</title>
		<link>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pinning-annotations-to-graphs</link>
					<comments>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 12 Dec 2012 18:00:51 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[getundoc]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[scribe]]></category>
		<category><![CDATA[UDD]]></category>
		<category><![CDATA[UIInspect]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3398</guid>

					<description><![CDATA[<p>Annotation object can be programmatically set at, and pinned-to, plot axes data points. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs">Pinning annotations to graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bug-and-workaround-in-timeseries-plot" rel="bookmark" title="Bug and workaround in timeseries plot">Bug and workaround in timeseries plot </a> <small>Matlab's internal hgconvertunits function has a bug that affects timeseries plots. Luckily there is a simple workaround....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Many Matlab users are aware of Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/how-to-annotate-graphs.html">annotation functionality</a>, which enables us to assign graphic elements such as arrows, lines, ellipses and text labels to Matlab figures. Matlab has a corresponding built-in function, <i><b>annotation</b></i>, that enables creation of annotation objects. Through the handle returned by <i><b>annotation</b></i> we can customize the annotation&#8217;s appearance (for example, line width/style or text font properties).</p>
<h3 id="limitations">Limitations of Matlab annotations</h3>
<p>Unfortunately, <i><b>annotation</b></i> has several major deficiencies, that are in fact related:<br />
<figure style="width: 406px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="A Matlab text-arrow annotation (unpinned)" src="https://undocumentedmatlab.com/images/Annotation_unpinned_animated.gif" title="A Matlab text-arrow annotation (unpinned)" width="406" height="298" /><figcaption class="wp-caption-text">A Matlab text-arrow annotation (unpinned)</figcaption></figure></p>
<ol>
<li><i><b>annotation</b></i> requires us to specify the annotation&#8217;s position in normalized <u>figure</u> units. Often, we are interested in an annotation on a plot axes that does NOT span the entire figure&#8217;s content area. To correctly convert the position from plot axes data coordinates to figure coordinates requires non-trivial calculations.</li>
<li>The created annotation is NOT pinned to the plot axes by default. This means that the annotation retains its relative position in the figure when the plot is zoomed, panned or rotated. This results in unintelligible and misleading annotations. We can indeed pin the annotation to the graph, but this requires delicate manual interaction (click the Edit Plot toolbar icon, then right-click the relevant annotation end-point, then select &#8220;Pin to Axes&#8221; from context menu). Unfortunately, the annotation handle does not provide a documented way to do this programmatically.</li>
<li>Finally, the annotation objects are only displayed on top of plot axes &#8211; they are obscured by any GUI uicontrols that may happen to be present in the figure.</li>
</ol>
<p>All of these limitations originate from the underlying implementation of annotation objects in Matlab. This is based on a transparent hidden axes that spans the entire figure&#8217;s content area, on which the annotations are being drawn (also called the <i>scribe layer</i>). The annotations may appear to be connected to the plot axes, but this is merely a visual illusion. In fact, they are located in a separate axes layer. For this reason, <i><b>annotation</b></i> requires figure position &#8211; in fact, the annotation has no information about the axes beneath it. Since plot axes are always obscured by uicontrols, so too is the annotation layer.<br />
Matlab&#8217;s implementation of annotation is an attempt to replicate Java&#8217;s standard <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html">glass-pane mechanism</a>. But whereas the Java glass-pane is a true transparent layer, on top of all other window components (<a target="_blank" rel="nofollow" href="http://www.codebeach.com/2008/03/introduction-to-glass-panes-in-swing.html">examples</a>), Matlab&#8217;s implementation only works for axes.<br />
Oh well, it&#8217;s better than nothing, I guess. But still, it would be nice if we could specify the annotation in graph (plot axes) data units, and have it pinned automatically without requiring manual user interaction.<br />
<span id="more-3398"></span></p>
<h3 id="Debugging">Debugging the problem</h3>
<p>The obvious first place to start debugging this issue is to go to the annotation handle&#8217;s context-menu (accessible via the <b>UIContextMenu</b> property), drill down to the &#8220;Pin&#8221; menu item and take a look at its callback. We could then use the <i><b><a target="_blank" href="/articles/hgfeval/">hgfeval</a></b></i> function to execute this callback programmatically. Unfortunately, this does not work well, because the context-menu is empty when the annotation is first created. A context-menu is only assigned to the annotation after the Edit Plot toolbar button and then the annotation object are clicked.<br />
Being too lazy in nature to debug this all the way through, I opted for an easier route: I started the Profiler just prior to clicking the context-menu&#8217;s &#8220;Pin to Axes&#8221;, and stopped it immediately afterwards. This showed me the code path (beneath <i>%matlabroot%/toolbox/matlab/scribe/</i>), and placing breakpoints in key code lines enabled me to debug the process step-by-step. This in turn enabled me to take the essence of the pinning code and implement it in my stand-alone application code.<br />
Believe me when I say that the scribe code is complex (anyone say convoluted?). So I&#8217;ll spare you the gruesome details and skip right to the chase.</p>
<h3 id="solution">The solution</h3>
<h5 id="positioning">Positioning the annotation in axes data units</h5>
<p>The first step is to ensure that the initial annotation position is within the figure bounds. Otherwise, the <i><b>annotation</b></i> function will shout. Note that it is ok to move the annotation outside the figure bounds later on (via panning/zooming) &#8211; it is only the initial annotation creation that must be within the figure bounds (i.e., between 0.0-1.0 in normalized X and Y units):</p>
<pre lang='matlab'>
% Prepare the annotation's X position
% Note: we need 2 X values: one for the annotation's head, another for the tail
x = [xValue, xValue];
xlim = get(hAxes,'XLim');
% Prepare the annotation's Y position
% Note: we need 2 Y values: one for the annotation's head, another for the tail
% Note: we use a static Y position here, spanning the center of the axes.
% ^^^^  We could have used some other Y data value for this
yLim = get(hAxes,'YLim');
y = yLim(1) + 0*sum(yLim) + [0.1,0]*diff(ylim);  % TODO: handle reverse, log Y axes
% Ensure that the annotation fits in the window by enlarging
% the axes limits as required
if xValue < xlim(1) || xValue > xlim(2)
    hold(hAxes,'on');
    plot(hAxes,xValue,y(2),'-w');
    drawnow;
    % YLim may have changed, so recalculate y
    yLim = get(hAxes,'YLim');
    y = yLim(1) + 0*sum(yLim) + [0.1,0]*diff(ylim);  % TODO: handle reverse, log Y-axes
end
</pre>
<p>Next, we convert our plot data units, in order to get the annotation&#8217;s requested position in the expected figure units. For this we use <i>%matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m</i>. This is an internal method of the <code>scribepin</code> UDD class, so in order to use it we need to create a dummy <code>scribepin</code> object. <i>topixels</i> then converts the dummy object&#8217;s position from axes data units to pixel units. We then use the undocumented <i><b><a target="_blank" href="/articles/bug-and-workaround-in-timeseries-plot/">hgconvertunits</a></b></i> function to convert from pixel units into normalized figure units:</p>
<pre lang='matlab'>
% Convert axes data position to figure normalized position
% uses %matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m
scribepin = scribe.scribepin('parent',hAxes,'DataAxes',hAxes,'DataPosition',[x;y;[0,0]]');
figPixelPos = scribepin.topixels;
hFig = ancestor(hAxes,'figure');
figPos = getpixelposition(hFig);
figPixelPos(:,2) = figPos(4) - figPixelPos([2,1],2);
figNormPos = hgconvertunits(hFig,[figPixelPos(1,1:2),diff(figPixelPos)],'pixels','norm',hFig);
annotationX = figNormPos([1,1]);
annotationY = figNormPos([2,2]) + figNormPos(4)*[1,0];
</pre>
<h5 id="pinning">Pinning the annotation to the axes data</h5>
<p>Finally, we use the annotation handle&#8217;s <i>pinAtAffordance()</i> method and set the <b>Pin.DataPosition</b> property to the requested X,Y values (we need to do both of these, otherwise the annotation will jump around when we zoom/pan):<br />
<center><figure style="width: 406px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="A Matlab text-arrow annotation (pinned)" src="https://undocumentedmatlab.com/images/Annotation_pinned_animated.gif" title="A Matlab text-arrow annotation (pinned)" width="406" height="298" /><figcaption class="wp-caption-text">A Matlab text-arrow annotation (pinned)</figcaption></figure></center></p>
<pre lang='matlab'>
% Ensure that the annotation is within the axes bounds, then display it
if any([annotationX,annotationY] < 0) || any([annotationX,annotationY] > 1)
    % Annotation position is outside axes boundaries, so bail out without drawing
    hAnnotation = handle([]);
elseif ~isempty(annotationObj)
    % Create a text-arrow annotation with the requested string at the requested position
    hAnnotation = handle(annotation('textarrow', annotationX, annotationY, ...
                                    'String',annotationStr, 'TextColor','b', 'Tag','annotation'));
    % Example for setting annotation properties
    hAnnotation.TextEdgeColor = [.8,.8,.8];
    % Pin the annotation object to the required axes position
    % Note: some of the following could fail in certain cases - never mind
    try
        hAnnotation.pinAtAffordance(1);
        hAnnotation.pinAtAffordance(2);
        hAnnotation.Pin(1).DataPosition = [xValue, y(1), 0];
        hAnnotation.Pin(2).DataPosition = [xValue, y(2), 0];
    catch
        % never mind - ignore (no error)
    end
end
</pre>
<p>p.s. Notice that all this relies on pure Matlab code (i.e., no mention of the dreaded J-word&#8230;). In fact, practically the entire scribe code is available in m-file format in the base Matlab installation. Masochistic readers may find many hours of pleasure sifting through the scribe code functionality for interesting nuggets such as the one above. If you ever find any interesting items, please drop me an email, or post a comment below.</p>
<h3 id="undocumented">Undocumented annotation properties</h3>
<p>Annotation objects have a <u>huge</u> number of undocumented properties. In fact, they have more undocumented properties than documented ones. You can see this using my <i><b><a target="_blank" href="/articles/uiinspect/">uiinspect</a></b></i> or <i><b><a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/">getundoc</a></b></i> utilities. Here is the list for a simple text-arrow annotation, such as the one that we used above:</p>
<pre lang='matlab'>
>> getundoc(hAnnotation)
ans =
              ALimInclude: 'on'
                   Afsize: 6
          ApplicationData: [1x1 struct]
                 Behavior: [1x1 struct]
              CLimInclude: 'on'
               ColorProps: {5x1 cell}
     EdgeColorDescription: 'Color'
        EdgeColorProperty: 'Color'
                  Editing: 'off'
                EraseMode: 'normal'
     FaceColorDescription: 'Head Color'
        FaceColorProperty: 'HeadColor'
             FigureResize: 0
            HeadBackDepth: 0.35
                HeadColor: [0 0 0]
            HeadColorMode: 'auto'
            HeadEdgeColor: [0 0 0]
            HeadFaceAlpha: 1
            HeadFaceColor: [0 0 0]
               HeadHandle: [1x1 patch]
         HeadHypocycloidN: 3
            HeadLineStyle: '-'
            HeadLineWidth: 0.5
               HeadRosePQ: 2
                 HeadSize: 10
             HelpTopicKey: ''
          IncludeRenderer: 'on'
                 MoveMode: 'mouseover'
                    NormX: [0.2 0.4]
                    NormY: [0.5 0.7]
                      Pin: [0x1 double]
                   PinAff: [1 2]
           PinContextMenu: [2x1 uimenu]
                PinExists: [0 0]
              PixelBounds: [0 0 0 0]
        PropertyListeners: [8x1 handle.listener]
        ScribeContextMenu: [9x1 uimenu]
                 Selected: 'off'
             Serializable: 'on'
                ShapeType: 'textarrow'
                    Srect: [2x1 line]
           StoredPosition: []
                TailColor: [0 0 0]
               TailHandle: [1x1 line]
            TailLineStyle: '-'
            TailLineWidth: 0.5
     TextColorDescription: 'Text Color'
            TextColorMode: 'auto'
        TextColorProperty: 'TextColor'
        TextEdgeColorMode: 'manual'
            TextEraseMode: 'normal'
               TextHandle: [1x1 text]
         UpdateInProgress: 0
    VerticalAlignmentMode: 'auto'
              XLimInclude: 'on'
              YLimInclude: 'on'
              ZLimInclude: 'on'
</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs">Pinning annotations to graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bug-and-workaround-in-timeseries-plot" rel="bookmark" title="Bug and workaround in timeseries plot">Bug and workaround in timeseries plot </a> <small>Matlab's internal hgconvertunits function has a bug that affects timeseries plots. Luckily there is a simple workaround....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Accessing plot brushed data</title>
		<link>https://undocumentedmatlab.com/articles/accessing-plot-brushed-data?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-plot-brushed-data</link>
					<comments>https://undocumentedmatlab.com/articles/accessing-plot-brushed-data#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 06 Oct 2010 18:00:45 +0000</pubDate>
				<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[<p>Plot data brushing can be accessed programmatically using very simple pure-Matlab code</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data">Accessing plot brushed data</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></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.<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Saving brushed data to a variable" src="https://undocumentedmatlab.com/images/Brushing1b.png" title="Saving brushed data to a variable" width="450" height="325" /><figcaption class="wp-caption-text">Saving brushed data to a variable</figcaption></figure></center><br />
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>
<pre lang="matlab">
t=0:0.2:25; plot(t,sin(t),'.-');
% Now brush some data points...
uiinspect(gca);
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" href="/images/Brushing2a.png"><img loading="lazy" decoding="async" alt="UIInspect-ion of a data-brushed plot" src="https://undocumentedmatlab.com/images/Brushing2a.png" title="UIInspect-ion of a data-brushed plot" width="450" height="389" /></a><figcaption class="wp-caption-text">UIInspect-ion of a data-brushed plot (click for details)</figcaption></figure></center><br />
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).<br />
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).<br />
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:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="UIInspect-ion of the data-brushing line" src="https://undocumentedmatlab.com/images/Brushing2b.png" title="UIInspect-ion of the data-brushing line" width="450" height="325" /><figcaption class="wp-caption-text">UIInspect-ion of the data-brushing line</figcaption></figure></center></p>
<pre lang="matlab">
hBrushLine = findall(gca,'tag','Brushing');
brushedData = get(hBrushLine, {'Xdata','Ydata'});
brushedIdx = ~isnan(brushedData{1});
brushedXData = brushedData{1}(brushedIdx);
brushedYData = brushedData{2}(brushedIdx);
% and similarly for ZData in 3D plots
</pre>
<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.<br />
As I have already explained in a <a target="_blank" href="/articles/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>
<pre lang="matlab">
>> hNewVarMenuItem = findall(gcf,'tag','figDataManagerNewVar')
hNewVarMenuItem =
          742.000244140625
>> hNewVarCallback = get(hNewVarMenuItem,'callback')
hNewVarCallback =
    @datamanager.newvar
>> hNewVarCallback(gcf)   % activate the callback
% => set 'ans' as the new variable holding the brushed data
>> ans
ans =
                       6.4         0.116549204850494
                       6.6         0.311541363513379
                       6.8         0.494113351138609
                         7         0.656986598718789
                       7.2         0.793667863849153
                       7.4         0.898708095811627
                       7.6         0.967919672031486
                       7.8         0.998543345374605
                       ...         ...
</pre>
<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. 🙂</p>
<h3 id="hg2">Updates for HG2 (R2014b+)</h3>
<p>In HG2 (R2014b+), <code>findall(gca,'tag','Brushing')</code> returns empty data since the way that brushed data is stored has changed. You can access the brushing data using the plot line&#8217;s hidden <b>BrushHandles</b> property, as follows:</p>
<pre lang='matlab'>
hLine = plot(...);
hBrushHandles = hLine.BrushHandles;
hBrushChildrenHandles = hBrushHandles.Children;  % Marker, LineStrip
</pre>
<p>I described the new <code>Marker</code> objects <a href="/articles/plot-markers-transparency-and-color-gradient" target="_blank">here</a>, and <code>LineStrip</code> objects <a href="/articles/customizing-axes-rulers#Axle" target="_blank">here</a>. The brushed vertex data can be retrieved from either of them. For example:</p>
<pre lang='matlab'>
>> hBrushChildrenHandles(1).VertextData
ans =
     1     2     3     4   % X-data of 4 data points
     1     2     3     4   % Y-data of 4 data points
     0     0     0     0   % Z-data of 4 data points
</pre>
<p>If you only need the brushed data points (not the handles for the <code>Markers</code> and <code>LineStrip</code>, you can get them directly from the line handle, using the hidden <b>BrushData</b> property:</p>
<pre lang='matlab'>
>> brushedIdx = logical(hLine.BrushData);  % logical array
>> brushedXData = hLine.XData(brushedIdx);
>> brushedYData = hLine.YData(brushedIdx)
brushedYData =
     1     2     3     4
</pre>
<p><b><u>Addendum 28 Feb, 2018:</u></b> MathWorks posted an official post on Matlab Answers that references the BrushData functionality &#8211; <a href="https://www.mathworks.com/matlabcentral/answers/385226-how-to-use-the-data-brush-tool-to-automatically-save-selected-points-in-multiple-line-plots" rel="nofollow" target="_blank">see here</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data">Accessing plot brushed data</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality" rel="bookmark" title="Accessing hidden HG2 plot functionality">Accessing hidden HG2 plot functionality </a> <small>In HG2, some of the plot functionality is hidden in undocumented properties. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/accessing-plot-brushed-data/feed</wfw:commentRss>
			<slash:comments>25</slash:comments>
		
		
			</item>
		<item>
		<title>JIDE Property Grids</title>
		<link>https://undocumentedmatlab.com/articles/jide-property-grids?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jide-property-grids</link>
					<comments>https://undocumentedmatlab.com/articles/jide-property-grids#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 22 Apr 2010 00:37:52 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Levente Hunyadi]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1287</guid>

					<description><![CDATA[<p>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/jide-property-grids">JIDE Property Grids</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-jide-combo-boxes" rel="bookmark" title="Using JIDE combo-boxes">Using JIDE combo-boxes </a> <small>Matlab includes many custom JIDE combo-box controls that can be used in Matlab GUIs out of the box. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to welcome guest blogger <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/60898">Levente Hunyadi</a>.</i></p>
<h3>Matlab&#8217;s property inspector</h3>
<p>We often wish to edit properties of heterogeneous objects using a common interface. Matlab&#8217;s property inspector, invoked with the built-in <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/inspect.html"><i><b>inspect</b></i></a> function, answers this need. The inspector is based on a two-column table of property names and values. Properties and their values are populated automatically, and the user can edit values in-place. The inspector enables property categorization, sub-categorization and sorting, which help users find and modify properties easily. For each property, the inspector displays a matching edit control: editbox/combobox/checkbox etc. This simplifies property value editing and prevents illegal value entry. Matlab&#8217;s GUI builder, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f7-998368.html">GUIDE</a>, uses the inspector to let users edit GUI properties such as position, color etc. It is also used by other tools such as the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f9-47085.html#f9-43456">Plot Editor</a>.<br />
<center><figure style="width: 355px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's built-in property inspector" src="https://undocumentedmatlab.com/images/Inspector_mde_cropped.gif" title="Matlab's built-in property inspector" width="355" height="271" /><figcaption class="wp-caption-text">Matlab's built-in property inspector</figcaption></figure></center><br />
The Matlab inspector can be embedded, with not-too-much effort, within Matlab GUI applications. Examples of this can be found in the <a target="_blank" href="/articles/findjobj-gui-display-container-hierarchy/">FindJObj</a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect</a> utilities.<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/findjobj.png" target="_blank"><img loading="lazy" decoding="async" alt="FindJObj - embedded property inspector" src="https://undocumentedmatlab.com/images/findjobj.png" title="FindJObj - embedded property inspector" width="450" height="405" /></a><figcaption class="wp-caption-text">FindJObj - embedded property inspector</figcaption></figure></center><br />
Unfortunately, Matlab&#8217;s property inspector is limited to Handle Graphics, Java and COM objects, and cannot be used for structures or user-defined Matlab classes. We shall see below how to set up our own property grid, populate it with data, and subscribe to property change events. This is a rather procedural approach. It is usually more convenient to use a declarative approach in which a structure or Matlab class is passed to a function that automatically discovers its properties and their meta-information. The <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28732">Property Grid</a> utility at Matlab File Exchange provides these services.</p>
<h3 id="simple">A simple property grid</h3>
<p>Matlab&#8217;s property inspector is based on a property grid control by <a target="_blank" rel="nofollow" href="http://www.jidesoft.com">JIDE Software</a>. JIDE Grids is a collection of components that extend the standard Java Swing <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">JTable</a> component, and is included in each Matlab installation (/java/jarext/jide/jide-grids.jar under the Matlab root). In particular, JIDE Grids includes the <em>PropertyTable</em> class, which is a fully customizable property grid component. You can find further details on JIDE Grids in the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf">Developer Guide</a> and the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/">Javadoc documentation</a>.<br />
There are several related classes associated with the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/PropertyTable.html"><em>PropertyTable</em></a> class. First, a <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/PropertyTableModel.html"><em>PropertyTableModel</em></a> encapsulates all properties that are visualized in the property grid. Each property derives from the <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/Property.html"><em>Property</em></a> abstract class, which features some common actions to properties, most notably to get and set property value. <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/DefaultProperty.html"><em>DefaultProperty</em></a> is a default concrete subclass of <em>Property</em>. Finally, <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/PropertyPane.html"><em>PropertyPane</em></a> decorates a property grid with icons for changing category view to alphabetically sorted view as well as expanding and collapsing categories, and a description text box at the bottom that can be shown or hidden.<br />
Here are the <i>DefaultProperty</i> fields and their respective roles:</p>
<table>
<tbody>
<tr>
<th>Field</th>
<th>Role</th>
</tr>
<tr>
<td>Name</td>
<td>Interal property name, not necessarily displayed, used as a key to identify the property.</td>
</tr>
<tr>
<td>DisplayName</td>
<td>A short property name shown in the left column of the property grid.</td>
</tr>
<tr>
<td>Description</td>
<td>A concise description of the property, shown at the bottom of the property pane, below the grid.</td>
</tr>
<tr>
<td>Type</td>
<td>The Java type associated with the property, used to invoke the appropriate renderer or editor.</td>
</tr>
<tr>
<td>EditorContext</td>
<td>An editor context object. If set, both the type and the context are used to look up the renderer or editor to use. This lets, for instance, one flag value to display as a true/false label, while another as a checkbox.</td>
</tr>
<tr>
<td>Category</td>
<td>A string specifying the property&#8217;s category, for grouping purposes.</td>
</tr>
<tr>
<td>Editable</td>
<td>Specifies whether the property value is modifiable or read-only.</td>
</tr>
<tr>
<td>Value</td>
<td>The current property value, as a Java object.</td>
</tr>
</tbody>
</table>
<p>Just as with any Java object, these fields may either be accessed with the Java get/set semantics (e.g. <i>getName()</i> or <i>setName(name)</i>), or the Matlab <i><b>get/set</b></i> semantics (e.g. <i><b>get</b>(prop,&#8217;Name&#8217;)</i> or <i><b>set</b>(prop,&#8217;Name&#8217;,name)</i>). When using the Matlab syntax, remember to wrap the Java object in a <i><b>handle()</b></i> call, to prevent a <a target="_blank" href="/articles/uicontrol-callbacks/#memory_leak">memory leak</a>.<br />
To use a property grid in Matlab, first construct a set of <i>DefaultProperty</i> objects. For each object, set at least the name, type and initial value. Next, add the properties to a table model. Finally, construct a property grid with the given table model and encapsulate in a property pane:</p>
<pre lang="matlab">
% Initialize JIDE's usage within Matlab
com.mathworks.mwswing.MJUtilities.initJIDE;
% Prepare the properties list
list = java.util.ArrayList();
prop1 = com.jidesoft.grid.DefaultProperty();
prop1.setName('stringProp');
prop1.setType(javaclass('char',1));
prop1.setValue('initial value');
prop1.setCategory('My Category');
prop1.setDisplayName('Editable string property');
prop1.setDescription('A concise description for my property.');
prop1.setEditable(true);
list.add(prop1);
prop2 = com.jidesoft.grid.DefaultProperty();
prop2.setName('flagProp');
prop2.setType(javaclass('logical'));
prop2.setValue(true);
prop2.setCategory('My Category');
prop2.setDisplayName('Read-only flag property');
prop2.setEditable(false);
list.add(prop2);
% Prepare a properties table containing the list
model = com.jidesoft.grid.PropertyTableModel(list);
model.expandAll();
grid = com.jidesoft.grid.PropertyTable(model);
pane = com.jidesoft.grid.PropertyPane(grid);
% Display the properties pane onscreen
hFig = figure;
panel = uipanel(hFig);
javacomponent(pane, [0 0 200 200], panel);
% Wait for figure window to close & display the prop value
uiwait(hFig);
disp(prop1.getValue());
</pre>
<p>Here, <em>com.mathworks.mwswing.MJUtilities.initJIDE</em> is called to initialize JIDE&#8217;s usage within Matlab. Without this call, we may see a JIDE warning message in some Matlab releases. We only need to <em>initJIDE</em> once per Matlab session, although there is no harm in repeated calls.<br />
<i><b>javaclass</b></i> is a function (included in the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28732">Property Grid</a> utility, or directly downloadable from <a target="_blank" rel="nofollow" href="/files/javaclass.m">here</a>) that returns a Java class for the corresponding Matlab type with the given dimension: <em><b>javaclass</b>(&#8216;logical&#8217;)</em> or <em><b>javaclass</b>(&#8216;logical&#8217;,0)</em> (a single logical flag value) returns a <em>java.lang.Boolean</em> class; <em><b>javaclass</b>(&#8216;char&#8217;,1)</em> (a character array) returns a <em>java.lang.String</em> class; <em><b>javaclass</b>(&#8216;double&#8217;,2)</em> (a matrix of double-precision floating point values) returns <em>double[][]</em>.<br />
<i><b>javacomponent</b></i> is the undocumented built-in Matlab function that adds Java Swing components to a Matlab figure, using the given dimensions and parent handle. When the user closes the figure, prop.<em>getValue()</em> fetches and displays the new property value.<br />
<center><figure style="width: 302px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="A simple user-defined property grid" src="https://undocumentedmatlab.com/images/PropertyGrid_simple2.png" title="A simple user-defined property grid" width="302" height="294" /><figcaption class="wp-caption-text">A simple user-defined property grid</figcaption></figure></center><br />
Next week&#8217;s article will show how to add more complex renderers and editors (display the flag value as a checkbox for example), define nested properties, and subscribe to property value change events. So stay tuned&#8230;</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/jide-property-grids">JIDE Property Grids</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids" rel="bookmark" title="Advanced JIDE Property Grids">Advanced JIDE Property Grids </a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-jide-combo-boxes" rel="bookmark" title="Using JIDE combo-boxes">Using JIDE combo-boxes </a> <small>Matlab includes many custom JIDE combo-box controls that can be used in Matlab GUIs out of the box. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/jide-property-grids/feed</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
			</item>
		<item>
		<title>Accessing the Matlab Editor</title>
		<link>https://undocumentedmatlab.com/articles/accessing-the-matlab-editor?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-the-matlab-editor</link>
					<comments>https://undocumentedmatlab.com/articles/accessing-the-matlab-editor#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 19 Oct 2009 18:00:20 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=671</guid>

					<description><![CDATA[<p>The Matlab Editor can be accessed programmatically, for a wide variety of possible uses - this article shows how.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-the-matlab-editor">Accessing the Matlab Editor</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor" rel="bookmark" title="Spicing up the Matlab Editor">Spicing up the Matlab Editor </a> <small>Matlab's Editor and Workspace can be enhanced quite significantly using an open-source utility. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/non-textual-editor-actions" rel="bookmark" title="Non-textual editor actions">Non-textual editor actions </a> <small>The UIINSPECT utility can be used to expand EditorMacro capabilities to non-text-insertion actions. This is how:...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/variables-editor-scrolling" rel="bookmark" title="Variables Editor scrolling">Variables Editor scrolling </a> <small>The Matlab Variables Editor can be accessed to provide immediate scrolling to a specified cell location. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Matlab&#8217;s built-in editor, like most other Matlab GUI, is Java-based. As such, it can easily be accessed programmatically. ImageAnalyst, a well-respected member of the Matlab community and a frequent CSSM (newsgroup) and FEX (File Exchange) contributor, <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/263329#687602">recently asked</a> whether it is possible to retrieve the name of the Editor&#8217;s currently edited file. The answer is that this is very easy, but I decided to use this opportunity to show how other interesting things can be done with the Editor.<br />
Before we start, it should be made clear that this entire article relies on MathWorks internal implementation of the Editor and Desktop, which may change without prior notice in future Matlab releases. The code below appears to work under Matlab 6 &#038; 7, but users who rely on forward compatibility should be aware of this warning.<br />
We start by retrieving the Editor handle. This can be done in a number of ways. The easiest is via the Matlab desktop:</p>
<pre lang="matlab">
try
    % Matlab 7
    desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
    jEditor = desktop.getGroupContainer('Editor').getTopLevelAncestor;
    % we get a com.mathworks.mde.desk.MLMultipleClientFrame object
catch
    % Matlab 6
    % Unfortunately, we can't get the Editor handle from the Desktop handle in Matlab 6:
    %desktop = com.mathworks.ide.desktop.MLDesktop.getMLDesktop;
    % So here's the workaround for Matlab 6:
    openDocs = com.mathworks.ide.editor.EditorApplication.getOpenDocuments;  % a java.util.Vector
    firstDoc = openDocs.elementAt(0);  % a com.mathworks.ide.editor.EditorViewContainer object
    jEditor = firstDoc.getParent.getParent.getParent;
    % we get a com.mathworks.mwt.MWTabPanel or com.mathworks.ide.desktop.DTContainer object
end
</pre>
<p>Now that we have the Editor handle, let&#8217;s retrieve its currently open (active) file name from the Editor&#8217;s title:</p>
<pre lang="matlab">
title = jEditor.getTitle;
currentFilename = char(title.replaceFirst('Editor - ',''));
</pre>
<p>The entire list of open file names can be retrieved in several ways:</p>
<pre lang="matlab">
% Alternative #1:
edhandle = com.mathworks.mlservices.MLEditorServices;
allEditorFilenames = char(edhandle.builtinGetOpenDocumentNames);
% Alternative #2:
openFiles = desktop.getWindowRegistry.getClosers.toArray.cell;
allEditorFilenames = cellfun(@(c)c.getTitle.char,openFiles,'un',0);
</pre>
<p>At the top-level Editor-window level, we can prevent its resizing, update its status bar, modify its toolbar/menu-bar, control docking and do other similar fun things:</p>
<pre lang="matlab">
% Actions via built-in methods:
jEditor.setResizable(0);
jEditor.setStatusText('testing 123...');
jEditor.setTitle('This is the Matlab Editor');
% Equivalent actions via properties:
set(jEditor, 'Resizable', 'off');
set(jEditor, 'StatusText', 'testing 123...');
set(jEditor, 'Title', 'This is the Matlab Editor');
</pre>
<p>Actually, the jEditor handle has over 300 invokable methods and close to 200 properties that we can get/set. Perhaps the easiest way to find interesting things we can programmatically do with the Editor handle, is to use my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect</a> utility on the File Exchange:</p>
<pre lang="matlab">
uiinspect(jEditor);  % or: jEditor.uiinspect
</pre>
<p><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/Editor_uiinspect.png" target="_blank"><img loading="lazy" decoding="async" alt="Matlab Editor methods, callbacks and properties as seen by uiinspect (click to zoom)" src="https://undocumentedmatlab.com/images/Editor_uiinspect.png" title="Matlab Editor methods, callbacks and properties as seen by uiinspect (click to zoom)" width="450" height="403" /></a><figcaption class="wp-caption-text">Matlab Editor methods, callbacks and properties as seen by <b><i>uiinspect</i></b><br />(click to zoom)</figcaption></figure><br />
The Editor handle is actually a container for many internal panels (toolbars etc.) and documents. The entire object hierarchy can be seen with another of my File Exchange utilities, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj</a>:</p>
<pre lang="matlab">
findjobj(jEditor);  % or: jEditor.findjobj
</pre>
<p><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/Editor_findjobj.png" target="_blank"><img loading="lazy" decoding="async" alt="Matlab Editor object hierarchy as seen by findjboj (click to zoom)" src="https://undocumentedmatlab.com/images/Editor_findjobj.png" title="Matlab Editor object hierarchy as seen by findjboj (click to zoom)" width="450" height="391" /></a><figcaption class="wp-caption-text">Matlab Editor object hierarchy as seen by <b><i>findjboj</i></b> (click to zoom)</figcaption></figure><br />
We can modify text within the open Editor documents, and instrument these document to handle event callbacks. To see how, I refer users to my <a target="_blank" href="/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor/">EditorMacro</a> utility on the Matlab File Exchange.<br />
If you find some other nifty and/or useful things that can be done using the Editor handle, please post them in the comments section below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-the-matlab-editor">Accessing the Matlab Editor</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor" rel="bookmark" title="Spicing up the Matlab Editor">Spicing up the Matlab Editor </a> <small>Matlab's Editor and Workspace can be enhanced quite significantly using an open-source utility. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/non-textual-editor-actions" rel="bookmark" title="Non-textual editor actions">Non-textual editor actions </a> <small>The UIINSPECT utility can be used to expand EditorMacro capabilities to non-text-insertion actions. This is how:...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/variables-editor-scrolling" rel="bookmark" title="Variables Editor scrolling">Variables Editor scrolling </a> <small>The Matlab Variables Editor can be accessed to provide immediate scrolling to a specified cell location. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/accessing-the-matlab-editor/feed</wfw:commentRss>
			<slash:comments>50</slash:comments>
		
		
			</item>
		<item>
		<title>Detecting window focus events</title>
		<link>https://undocumentedmatlab.com/articles/detecting-window-focus-events?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=detecting-window-focus-events</link>
					<comments>https://undocumentedmatlab.com/articles/detecting-window-focus-events#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 09 Sep 2009 20:49:51 +0000</pubDate>
				<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[FindJObj]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=584</guid>

					<description><![CDATA[<p>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/detecting-window-focus-events">Detecting window focus events</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fixing-a-java-focus-problem" rel="bookmark" title="Fixing a Java focus problem">Fixing a Java focus problem </a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A CSSM reader <a target="_blank rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/260078#678945">recently asked</a> whether it is possible to detect window focus events (specifically, the focus-gain event) asynchronously, so that such events can trigger a callback without necessitating a polling thread to constantly monitor the windows state.<br />
The user correctly mentioned the fact that although mouse-clicks within the window frame can be detected using the documented figure callback <b><i>WindowButtonDownFcn</i></b>, there are other methods by which a window can gain focus: keyboard (&lt;Alt&gt;-&lt;Tab&gt; on Windows, for example), clicking the window frame edge etc. These methods are all undetected by <b><i>WindowButtonDownFcn</i></b>.<br />
This problem is, to the best of my knowledge, insoluble using standard documented Matlab. However, there is indeed a simple solution using undocumented/unsupported Matlab features. The solution relies on the fact that all Matlab windows are basically Java Swing objects, and these objects have dozens of standard callback hooks that can be utilized (Matlab only exposes a few callbacks). The list of standard Swing callbacks was detailed in my earlier article about <a target="_blank" href="/articles/uicontrol-callbacks/">uicontrol callbacks</a>, which is also relevant for Java window frames.<br />
In this specific case, we are interested in <b><i>FocusGainedCallback</i></b>. This callback is invoked for the figure Frame&#8217;s AxisComponent (a part of the Frame that will be explained in another article). For each of our monitored figure windows, we set this callback to a predefined Matlab function. We may also wish to set its companion <b><i>FocusLostCallback</i></b>.<br />
Here&#8217;s the resulting code snippet (hFig is our Matlab figure handle):</p>
<pre lang="matlab">
% Prepare the figure
hFig = figure;  % etc. - prepare the figure
% Get the underlying Java reference
warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame
jFig = get(hFig, 'JavaFrame');
jAxis = jFig.getAxisComponent;
% Set the focus event callback
set(jAxis,'FocusGainedCallback',{@myMatlabFunc,hFig});
% perhaps also set the FocusLostCallback here
</pre>
<p>Whenever any of the monitored figures now gets focus, by whichever means, the user-defined Matlab function myMatlabFunc() will be invoked. This function should be defined as follows:</p>
<pre lang="matlab">
function myMatlabFunc(jAxis, jEventData, hFig)
   % do whatever you wish with the event/hFig information
end
</pre>
<p>Extra input parameters can be added during callback setup and definition, as follows:</p>
<pre lang="matlab">
set(jAxis,'FocusLostCallback',{@myMatlabFunc,hFig,data1,data2})
...
function myMatlabFunc(jAxis, jEventData, hFig, data1, data2)
   % do whatever you wish with the event/hFig/data information
end
</pre>
<p>A very similar technique can detect other windowing events (maximization/minimization/movement etc.). Depending on the case, you may need to use <i>jFig.fFigureClient.getWindow</i> instead of <i>jFig.getAxisComponent</i>. The list of available callbacks for each of these objects can be seen using a simple <i><b>set</b>(jFig.getAxisComponent)</i> command, or via my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect</a> or <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj</a> utilities on the Matlab File Exchange.<br />
Note that all this relies on the undocumented hidden figure property <a target="_blank" href="/articles/tag/javaframe/"><b><i>JavaFrame</i></b></a>, which issues a standing 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 the code above, but note that this code may well fail in some future Matlab version. If and when JavaFrame does become obsolete, be sure to look in this blog for workarounds&#8230;<br />
<b><u>Addendum Aug 21, 2015</u></b>: In in HG2 (R2014b onward), setting the Focus events (FocusGained, FocusLost etc.) on the AxisComponent does not work. Instead, we can simply set the callbacks on the AxisComponent&#8217;s direct child, as follows:</p>
<pre lang='matlab'>set(jAxis.getComponent(0),'FocusGainedCallback',{@myMatlabFunc,hFig});</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/detecting-window-focus-events">Detecting window focus events</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/fixing-a-java-focus-problem" rel="bookmark" title="Fixing a Java focus problem">Fixing a Java focus problem </a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/detecting-window-focus-events/feed</wfw:commentRss>
			<slash:comments>41</slash:comments>
		
		
			</item>
		<item>
		<title>Figure toolbar customizations</title>
		<link>https://undocumentedmatlab.com/articles/figure-toolbar-customizations?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=figure-toolbar-customizations</link>
					<comments>https://undocumentedmatlab.com/articles/figure-toolbar-customizations#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 Sep 2009 16:00:14 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=564</guid>

					<description><![CDATA[<p>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/figure-toolbar-customizations">Figure toolbar customizations</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-window-customizations" rel="bookmark" title="Figure window customizations">Figure window customizations </a> <small>Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar" rel="bookmark" title="Adding a search box to figure toolbar">Adding a search box to figure toolbar </a> <small>An interactive search-box can easily be added to a Matlab figure toolbar for enhanced user experience. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week, I <a target="_blank" href="/articles/figure-toolbar-components/">described</a> how to access existing Matlab figure toolbar icons and how to add non-button toolbar components. Today, I describe how the toolbar itself can be customized using undocumented functionality and properties.<br />
All the important undocumented customizations can only be accessed via the toolbar&#8217;s Java handle, which is retrieved so:</p>
<pre lang="matlab">
hToolbar = findall(hFig,'tag','FigureToolBar');
jToolbar = get(get(hToolbar,'JavaContainer'),'ComponentPeer');
</pre>
<p>One interesting functionality is enabling a floating toolbar, via <i>jToolbar.setFloatable(1)</i>. The toolbar can then be dragged from its docked position at the top of the figure menu, becoming enclosed in an independent floating window (a non-modal javax.swing.JDialog child of the parent figure, to be exact). Since this toolbar window has a very small initial size and no name, a simple immediate fix is required:</p>
<pre lang="matlab">
% Modify Java toolbar properties
jToolbar.setFloatable(1);
hjToolbar = handle(jToolbar,'CallbackProperties');
set(hjToolbar,'AncestorAddedCallback',@dockUndockCallbackFcn);
% Sample dockUndockCallbackFcn function
function dockUndockCallbackFcn(hjToolbar, eventdata)
   if hjToolbar.isFloating
      jToolbarWin = hjToolbar.getTopLevelAncestor;
      jToolbarWin.setTitle('Toolbar');
      %jToolbarWin.setResizable(1); %if you wish manual resize
      jToolbarWin.setPreferredSize(java.awt.Dimension(380,57));
      jToolbarWin.setSize(java.awt.Dimension(380,57));
      jToolbar.revalidate;  %repaint toolbar
      jToolbarWin.getParent.validate; %repaint parent figure
   end
end
</pre>
<p><center><figure style="width: 415px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Floating toolbar" src="https://undocumentedmatlab.com/images/toolbar5.png" title="Floating toolbar" width="102" height="118" />&nbsp;&nbsp;&nbsp;<img loading="lazy" decoding="async" alt="...and after minor fixes" src="https://undocumentedmatlab.com/images/toolbar6.png" title="...and after minor fixes" width="307" height="118" /><figcaption class="wp-caption-text">Floating toolbar &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ...and after minor fixes &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</figcaption></figure></center><br />
Re-docking a floating toolbar can be done by simply closing the floating window – the toolbar then reappears in its default (top) position within the parent figure window.<br />
There are other interesting functions/properties available via the Java interface – readers are encouraged to explore via the <b><i>methods</i></b>, <b><i>methodsview</i></b>, <b><i>inspect</i></b> functions, or my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">uiinspect</a> utility.<br />
For example, <i>addGap()</i> can be used to add a transparent gap between the rightmost toolbar component and the window border: this gap is kept even if the window is shrunk to a smaller width – the rightmost components disappear, maintaining the requested gap.<br />
<i>setBackground()</i> sets the background color that is seen beneath transparent pixels of button images and gaps. Non-transparent (opaque or colored) pixels are not modified. If the button icons are improperly created, the result looks bad:</p>
<pre lang="matlab">
jToolbar.setBackground(java.awt.Color.cyan); %or: Color(0,1,1)
</pre>
<p><center><figure style="width: 422px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Default figure toolbar with cyan background" src="https://undocumentedmatlab.com/images/toolbar9.png" title="Default figure toolbar with cyan background" width="422" height="62" /><figcaption class="wp-caption-text">Default figure toolbar with cyan background</figcaption></figure></center><br />
This problem can be fixed by looping over the toolbar icons and modifying the pixel values from their default gray background to transparent. An example for this practice was given at the beginning of <a target="_blank" href="/articles/figure-toolbar-components/">last week&#8217;s article</a>.<br />
<i>setMorePopupEnabled()</i> is used to specify the behavior when the window resizes to such a small width that one or more toolbar buttons need to disappear – by default (=1 or true) the chevron (&gt;&gt;) mark appears on the toolbar&#8217;s right, enabling display of the missing buttons, but this behavior can be overridden (0 or false) to simply crop the extra buttons.<br />
<i>setRollover()</i> controls the behavior when the mouse passes (&#8220;rolls&#8221;) over toolbar buttons. The default parameter (1 or true), displays a 3-dimensional button border, creating an embossing effect; this can be overridden (0 or false) to use a different 3D effect:</p>
<pre lang="matlab">
% Set non-default Rollover, MorePopupEnabled
jToolbar.setRollover(0);         % or: set(jToolbar,'Rollover','off');
jToolbar.setMorePopupEnabled(0); % or: set(jToolbar,'MorePopupEnabled','off');
</pre>
<p><center><figure style="width: 309px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="default Rollover &#038; MorePopupEnabled properties" src="https://undocumentedmatlab.com/images/toolbar7.png" title="default Rollover &#038; MorePopupEnabled properties" width="309" height="108" /><br />
<img loading="lazy" decoding="async" alt="non-default Rollover &#038; MorePopupEnabled properties" src="https://undocumentedmatlab.com/images/toolbar8.png" title="non-default Rollover &#038; MorePopupEnabled properties" width="309" height="108" /><figcaption class="wp-caption-text">default (top) and non-default (bottom)<br />Rollover &amp; MorePopupEnabled properties</figcaption></figure></center><br />
Remember that toolbars are simply containers for internal components, generally buttons and separators. These components may be accessed individually and manipulated. An example of such manipulation can be found in my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj utility</a> on the File Exchange, that lists the individual figure components: whenever the user selects a toolbar button (or any other Java component for that matter), its border is temporarily modified to a flashing red rectangle helping users understand the component&#8217;s location. Here&#8217;s the relevant code snip and screenshot (readers are encouraged to look at the actual code, which is more complex &#8211; FindJObj sub-function flashComponent()):</p>
<pre lang="matlab">
% Prepare the red border panel
oldBorder = jComponent.getBorder;
redBorder = javax.swing.border.LineBorder(java.awt.Color.red,2,0);
redBorderPanel = javax.swing.JPanel;
redBorderPanel.setBorder(redBorder);
redBorderPanel.setOpaque(0);  % transparent interior, red border
redBorderPanel.setBounds(jComponent.getBounds);
isSettable(compIdx) = ismethod(jComponent,'setBorder');
% flash by periodically displaying/hiding the panel
for idx = 1 : 2*numTimes
   if idx>1,  pause(delaySecs);  end  % don't pause at start
   visible = mod(idx,2);
   jParent = jComponent.getParent;
   % Most Java components allow modifying their borders
   if isSettable
      if visible
         % Set a red border
         jComp.setBorder(redBorder);
         try jComponent.setBorderPainted(1); catch, end
      else %if ~isempty(oldorder)
         % Remove red border by restoring the original border
         jComp.setBorder(oldBorder);
      end
      jComp.repaint;
   % Other Java components are highlighted by a transparent red-
   % border panel, placed on top of them in their parent's space
   elseif ~isempty(jParent)
      if visible
         % place the transparent red-border panel on top
         jParent.add(redBorderPanel);
         jParent.setComponentZOrder(redBorderPanel,0);
      else
         jParent.remove(redBorderPanel);
      end
      jParent.repaint;
   end
end  % idx flash loop
</pre>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/findjobj.png"><img loading="lazy" decoding="async" alt="FindJObj - flashing red border around a toolbar icon" src="https://undocumentedmatlab.com/images/findjobj.png" title="FindJObj - flashing red border around a toolbar icon" width="450" height="405" /></a><figcaption class="wp-caption-text">FindJObj - flashing red border around a toolbar icon</figcaption></figure></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/figure-toolbar-customizations">Figure toolbar customizations</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/figure-window-customizations" rel="bookmark" title="Figure window customizations">Figure window customizations </a> <small>Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-a-search-box-to-figure-toolbar" rel="bookmark" title="Adding a search box to figure toolbar">Adding a search box to figure toolbar </a> <small>An interactive search-box can easily be added to a Matlab figure toolbar for enhanced user experience. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/figure-toolbar-customizations/feed</wfw:commentRss>
			<slash:comments>24</slash:comments>
		
		
			</item>
		<item>
		<title>Non-textual editor actions</title>
		<link>https://undocumentedmatlab.com/articles/non-textual-editor-actions?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=non-textual-editor-actions</link>
					<comments>https://undocumentedmatlab.com/articles/non-textual-editor-actions#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 17 Jul 2009 13:55:39 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=454</guid>

					<description><![CDATA[<p>The UIINSPECT utility can be used to expand EditorMacro capabilities to non-text-insertion actions. This is how:</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/non-textual-editor-actions">Non-textual editor actions</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor" rel="bookmark" title="Spicing up the Matlab Editor">Spicing up the Matlab Editor </a> <small>Matlab's Editor and Workspace can be enhanced quite significantly using an open-source utility. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings" rel="bookmark" title="EditorMacro v2 &#8211; setting Command Window key-bindings">EditorMacro v2 &#8211; setting Command Window key-bindings </a> <small>The EditorMacro utility was extended to support built-in Matlab Editor and Command-Window actions and key-bindings. This post describes the changes and the implementation details....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Following my <a href="/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor/" target="_blank">EditorMacro post</a> a couple of weeks ago, which showed how to assign a keyboard macro to the integrated Matlab Editor, several people have asked me whether it is possible to assign a macro to non-textual actions, in addition to the text insertion/replacement which <b><i>EditorMacro</i></b> supports.<br />
The quick answer is yes, with some careful programming. Instead of specifying the end result, I will use this opportunity to illustrate how Java objects (not just the editor) can be inspected for their supported actions/properties.<br />
Our first step is to get the requested Java reference handle. This can be done via the Matlab Command Window (interested readers can look at the EditorMacro.m source code, specifically at its getJEditor() function). However, a much easier way is to assign some macro using <b><i>EditorMacro</i></b> and then simply place a breakpoint in EditorMacro&#8217;s keyPressedCallback() callback function. Then press an arrow key (or any other key) in the editor, and wait for the breakpoint focus to arrive (don&#8217;t forget to clear the breakpoint&#8230;). From here on, all our actions will be done in the Command Window.<br />
We now have a variable called jEditorPane, which is a reference to a Java object of type javahandle_withcallbacks. com.mathworks.mde.editor.EditorSyntaxTextPane (in Matlab 7 &#8211; it&#8217;s something similar in Matlab 6). This is a Matlab wrapper for the basic Java object, used for <a href="/articles/uicontrol-callbacks/" target="_blank">accessing the callback hooks, as explained in a previous post.</a> In our case we are not interested in this wrapper but in its wrapped object, which is retrieved via Matlab&#8217;s built-in <b><i>java</i></b> function (java(jEditorPane) or jEditorPane.java). The inspection itself is done using Matlab&#8217;s standard tools (<b><i>inspect</i></b>, <b><i>methodsview</i></b> etc.) or via my <a href="http://www.mathworks.com/matlabcentral/fileexchange/17935" target="_blank" rel="nofollow">UIINSPECT utility</a>. I suggest using <b><i>UIINSPECT</i></b>, which displays all the information of the standard tools and lots extra, but I&#8217;m of course biased&#8230;</p>
<blockquote>
<pre lang="matlab">
uiinspect(jEditorPane.java);
</pre>
</blockquote>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/uiinspect_jeditor.png" target="_blank"><img loading="lazy" decoding="async" alt="jEditorPane inspection using UIINSPECT (click to see details)" src="https://undocumentedmatlab.com/images/uiinspect_jeditor.png" title="jEditorPane inspection using UIINSPECT (click to see details)" width="450" height="355" /></a><figcaption class="wp-caption-text">jEditorPane inspection using <b><i>UIINSPECT</i></b> (click to see details)</figcaption></figure></center><br />
Without diving into all the <b><i>UIINSPECT</i></b> options (I shall do this in a dedicated post), we see the supported methods/actions on the left, and properties on the right. It is true that none of them are documented, but many are self-explanatory. For example, the <i>cut()/copy()/paste()</i> methods or the <i>caretPosition/caretColor</i> properties. Any combination of these methods and properties can be used in a user-defined macro.<br />
Let&#8217;s do a simple example, setting the &lt;Ctrl-E&gt; combination to a macro moving to the end-of-line (unix-style &#8211; equivalent to &lt;End&gt; on Windows), and &lt;Ctrl-Shift-E&gt; to a similar macro doing the same while also selecting the text (like &lt;Shift-End&gt; on Windows). We shall even use the same macro code, by simply checking in the eventData whether the &lt;Shift&gt; key is depressed:</p>
<pre lang="matlab">
function EOL_Macro(hDocument,eventData)
  % Find the position of the next EOL mark
  currentPos = hDocument.getCaretPosition;
  docLength = hDocument.getLength;
  textToEOF = char(hDocument.getTextStartEnd(currentPos,docLength));
  nextEOLPos = currentPos+find(textToEOF<=13,1)-1;  % next CR/LF pos
  if isempty(nextEOLPos)
      % no EOL found (=> move to end-of-file)
      nextEOLPos = docLength;
  end
  % Do action based on whether <shift> was pressed or not
  %get(eventData);
  if eventData.isShiftDown
      % Select to EOL
      hDocument.moveCaretPosition(nextEOLPos);
  else
      % Move to EOL (without selection)
      hDocument.setCaretPosition(nextEOLPos);
  end
end  % EOL_Macro
</pre>
<p>&#8230;and now let&#8217;s activate this macro in the Matlab Command Window:</p>
<pre lang="matlab">
>> macros = EditorMacro('ctrl-e',@EOL_Macro,'run');
>> macros = EditorMacro('ctrl-shift-e',@EOL_Macro,'run')
macros =
    'ctrl alt pressed T'      @(a,b)datestr(now)    'text'
    'ctrl pressed E'          @EOL_Macro            'run'
    'shift ctrl pressed E'    @EOL_Macro            'run'
</pre>
<p>Please do explore all the possible actions/properties exposed by the jEditorPane object. Probably the worst that could happen (and very rarely) is that you&#8217;ll crash Matlab and need to restart it &#8211; no biggy. If you find an interesting macro combination, please post it to the File Excahnge, and/or let us all know by placing a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/non-textual-editor-actions">Non-textual editor actions</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor" rel="bookmark" title="Spicing up the Matlab Editor">Spicing up the Matlab Editor </a> <small>Matlab's Editor and Workspace can be enhanced quite significantly using an open-source utility. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings" rel="bookmark" title="EditorMacro v2 &#8211; setting Command Window key-bindings">EditorMacro v2 &#8211; setting Command Window key-bindings </a> <small>The EditorMacro utility was extended to support built-in Matlab Editor and Command-Window actions and key-bindings. This post describes the changes and the implementation details....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/non-textual-editor-actions/feed</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>GUIDE customization</title>
		<link>https://undocumentedmatlab.com/articles/guide-customization?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=guide-customization</link>
					<comments>https://undocumentedmatlab.com/articles/guide-customization#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 Jun 2009 17:00:43 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=383</guid>

					<description><![CDATA[<p>Matlab's GUI Design Editor (GUIDE) has several interesting undocumented features. This post describes how to customize GUIDE rulers.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/guide-customization">GUIDE customization</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotedit-context-menu-customization" rel="bookmark" title="PlotEdit context-menu customization">PlotEdit context-menu customization </a> <small>A combination of Matlab and Java Robot commands to automate a certain animation can be used when we cannot access underlying GUI/graphics code. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>GUIDE is the acronym for Matlab&#8217;s Graphical User Interface Design Editor. It is very handy for designing simple GUI figures, although my experience has shown that it has limitations for complex GUIs. Nevertheless, GUIDE is the tool used by most Matlab developers when designing GUIs. In this post, I will show a few undocumented customizations that could help make GUIDE sessions more productive.<br />
The starting point is GUIDE&#8217;s undocumented return value, which is a Java reference to the Layout Editor panel within the GUIDE figure frame:</p>
<blockquote>
<pre>
<span style="color: #000000;">&gt;&gt; h = guide</span>
h =
Layout Document [untitled]
<span style="color: #000000;">&gt;&gt; h.getClass</span>
ans =
class com.mathworks.toolbox.matlab.guide.LayoutEditor
</pre>
</blockquote>
<p>This return handle can be used to access GUIDE components and functionality. We can start by inspecting the interesting GUIDE layout hierarchy using my <a rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj utility</a>, and the associated properties and method using my <a rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect utility</a>:</p>
<blockquote>
<pre><span style="color: #000000;">&gt;&gt; h.findjobj;
&gt;&gt; h.uiinspect;
</span></pre>
</blockquote>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Hierarchy of Layout Editor within the GUIDE frame" src="https://undocumentedmatlab.com/images/guide_ruler1.png" title="Hierarchy of Layout Editor within the GUIDE frame" width="450" height="351" /><figcaption class="wp-caption-text">Hierarchy of Layout Editor within the GUIDE frame</figcaption></figure></center><br />
Note: If you wish to see the hierarchy of the entire GUIDE figure frame, simply run FindJObj on the frame reference, by either of the two following methods (and similarly for UIInspect):</p>
<blockquote>
<pre><span style="color: #000000;">&gt;&gt; findjobj(h.getFrame);
&gt;&gt; findjobj(h.getTopLevelWindow);
</span></pre>
</blockquote>
<p>We see that the Layout Editor contains, in addition to the expected LayoutArea and two MWScrollbars, several objects that relate to a ruler. These rulers can be activated via the GUIDE menu (Tools / Grid and Rulers), or via the Matlab Command Prompt as described below:<br />
Looking at the ruler properties in FindJObj or UIInspect, we can see a settable boolean property called &#8220;RulerState&#8221;. If we turn it on we can see that a very handy pixels-ruler appears. Once we set this property, it remains in effect for every future GUIDE session:<br />
<center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Before: GUIDE with no rulers" src="https://undocumentedmatlab.com/images/guide_ruler2.png" title="Before: GUIDE with no rulers" width="430" height="286" /><figcaption class="wp-caption-text">Before: GUIDE with no rulers</figcaption></figure></center></p>
<blockquote>
<pre lang="matlab">
h.getComponent(0).getComponent(4).setRulerState(true);  % Horizontal
h.getComponent(0).getComponent(5).setRulerState(true);  % Vertical
</pre>
</blockquote>
<p>Note: RulerState actually controls a system preference (LayoutShowRulers, a boolean flag) that controls the visibility of both rulers, and persists across Matlab/GUIDE sessions.  To change the visibility of only a single ruler for this GUIDE session only, or on old Matlab versions (e.g. Matlab 7.1 aka R14 SP3) that do not have the &#8216;RulerState&#8217; property, use the hide()/show()/setVisible(flag) methods, or set the &#8216;Visible&#8217; property:</p>
<blockquote>
<pre lang="matlab">
% Equivalent ways to show horizontal ruler for this GUIDE session only
hRuler = h.getComponent(0).getComponent(4);  % =top horizontal ruler
set(hRuler, 'Visible','on');
hRuler.setVisible(true);  % or: hRuler.setVisible(1)
hRuler.show();
</pre>
</blockquote>
<p><center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="After: GUIDE with pixel rulers" src="https://undocumentedmatlab.com/images/guide_ruler3.png" title="After: GUIDE with pixel rulers" width="430" height="286" /><figcaption class="wp-caption-text">After: GUIDE with pixel rulers</figcaption></figure></center><br />
Using this method, we can customize the rulers &#8211; options which are unavailable using the standard GUIDE menu options: We can specify horizontal/vertical grid size, tick &#038; label interval and similar ruler properties. For example, let&#8217;s set a 5-pixel minor tick interval, 25-pixel major interval, labels every 50 pixels, starting offset of 40 pixels and a ruler size limited at 260 pixels:</p>
<blockquote>
<pre lang="matlab">
hRuler = h.getComponent(0).getComponent(4);  % =top horizontal ruler
set(hRuler, 'MinorInterval',5, 'MajorInterval',25);
set(hRuler, 'LabelInterval',50, 'LabelUnit',50);
set(hRuler, 'Margin',40, 'Length',260);
</pre>
</blockquote>
<p><center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="GUIDE with modified pixel rulers" src="https://undocumentedmatlab.com/images/guide_ruler4.png" title="GUIDE with modified pixel rulers" width="430" height="286" /><figcaption class="wp-caption-text">GUIDE with modified pixel rulers</figcaption></figure></center><br />
Note that the vertical ruler&#8217;s labels start (=LabelStart property) at the figure&#8217;s height, and have a <em>decreasing</em> LabelInterval of -50. This is done because Java coordinates start counting from the top-left corner <em>downward</em>, whereas Matlab counts from the bottom-left <em>upward</em>. In GUIDE, we naturally wish to display the Matlab coordinates, hence the transformation.<br />
Note: unfortunately, most of these properties do not have equivalent settable system properties that I could find. Here is a list of all the GUIDE-related system properties that I found:</p>
<ul>
<li><strong>LayoutShowRulers</strong> &#8211; boolean, controls display of both rulers</li>
<li><strong>LayoutShowGuides</strong> &#8211; boolean, controls display of blue guidelines</li>
<li><strong>LayoutShowGrid</strong> &#8211; boolean, controls display of gray gridlines</li>
<li><strong>LayoutGridWidth</strong> &#8211; integer, controls the size of the grid boxes</li>
<li><strong>LayoutSnapToGrid</strong> &#8211; boolean, controls snap-to-grid behavior</li>
<li><strong>LayoutActivate</strong> &#8211; boolean, controls ability to run (activate) unsaved figures without confirmation</li>
<li><strong>LayoutChangeDefaultCallback</strong> &#8211; boolean, ??? (I can see this preference in my matlab.prf file but I have no idea what it does or how it got there&#8230;)</li>
<li><strong>LayoutExport</strong> &#8211; boolean, controls ability to export unsaved figures without confirmation</li>
<li><strong>LayoutExtension</strong> &#8211; boolean, controls display of file extension in the GUIDE window title</li>
<li><strong>LayoutFullPath</strong> &#8211; boolean, controls display of file path in the GUIDE window title</li>
<li><strong>LayoutMCodeComments</strong> &#8211; boolean, controls generation of comments for m-file callbacks</li>
<li><strong>LayoutToolBar</strong> &#8211; boolean, controls display of the GUIDE widow toolbar</li>
<li><strong>LayoutToolNames</strong> &#8211; boolean, controls display of tool names in the components palette</li>
</ul>
<p>Have you discovered other undocumented features in GUIDE? If so, please share your findings in the comments section below.<br />
<strong><u>Warning</u></strong>: These undocumented features are way deep in unsupported territory. They depend heavily on Matlab&#8217;s internal implementation, which may change without any prior notice between Matlab releases. They work ok on Matlab versions 7.1 (R14 SP3) through 7.6 (R2008a), and perhaps on other versions as well. However, the very next Matlab release might break these features, so beware.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/guide-customization">GUIDE customization</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotedit-context-menu-customization" rel="bookmark" title="PlotEdit context-menu customization">PlotEdit context-menu customization </a> <small>A combination of Matlab and Java Robot commands to automate a certain animation can be used when we cannot access underlying GUI/graphics code. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/guide-customization/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
