<?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>Levente Hunyadi &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/levente-hunyadi/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 30 Jan 2013 18:00:44 +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>propertiesGUI</title>
		<link>https://undocumentedmatlab.com/articles/propertiesgui?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=propertiesgui</link>
					<comments>https://undocumentedmatlab.com/articles/propertiesgui#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Jan 2013 18:00:44 +0000</pubDate>
				<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[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Levente Hunyadi]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3511</guid>

					<description><![CDATA[<p>propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/propertiesgui">propertiesGUI</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/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiinspect" rel="bookmark" title="uiinspect">uiinspect </a> <small>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I presented a detailed explanation of the <a target="_blank" href="/articles/uiinspect/"><i><b>uiinspect</b></i> utility</a>, which displays a GUI listing all the properties, callbacks and internal methods of an inspected object. Something like Matlab&#8217;s <i><b>inspect</b></i> tool on steroids. I explained that <i><b>uiinspect</b></i> uses <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> automatically extracts the inspected object&#8217;s properties and displays them using a corresponding renderer in the <code>PropertyTable</code>.<br />
<figure style="width: 508px" class="wp-caption alignright"><img fetchpriority="high" decoding="async" alt="propertiesGUI demo" src="https://undocumentedmatlab.com/images/propertiesGUI.gif" title="propertiesGUI demo" width="508" height="603" /><figcaption class="wp-caption-text">propertiesGUI demo</figcaption></figure><br />
We often need to present a non-object Matlab construct. For example, it is very common to store an application&#8217;s configuration properties in a struct (using Matlab objects is often impractical and unwarranted) &#8212; it would be very useful to present this configuration dynamically, without having to programmatically scan all struct fields and build a dedicated GUI table. Unfortunately, <code>PropertyView</code> cannot automatically retrospect Matlab structs, which is the reason that the built-in <i><b>inspect</b></i> function fails for such objects. In the general case, we may wish to present a <code>PropertyTable</code> using row-specific renderers and editors, when we have such an un-inspectable object (struct, cell array etc.), or even for a dynamically-created table of properties that is not stored in any single object.<br />
Another limitation of <code>PropertyView</code> is that it immediately assigns updated property values to the inspected object, without allowing any sanity checks to be conducted on the new values, and without enabling the user to cancel property changes.<br />
Last but not least, <code>PropertyView</code> does not enable users to easily modify the way that certain properties are presented. Boolean properties (true/false) always use a checkbox cell-renderer/editor, while we may wish to display a string (on/off) or combo-box instead.<br />
In short, <code>PropertyView</code> is great unless you want to customize stuff, or do something slightly out-of-the-ordinary.<br />
Enter <i><b>propertiesGUI</b></i>, the subject of today&#8217;s article.<br />
<span id="more-3511"></span></p>
<h3 id="utility">The propertiesGUI utility</h3>
<p><i><b>propertiesGUI</b></i>, which can be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/38864-propertiesgui-display-properties-in-an-editable-context-aware-table">downloaded</a> from the Matlab File Exchange, presents a generic solution to this problem. <i><b>propertiesGUI</b></i> is based on Levente Hunyadi&#8217;s articles <a target="_blank" href="/articles/tag/levente-hunyadi/">here</a> back in 2010, and on his <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28732-property-grid-using-jide-implementation">&#8220;Property grid&#8221; utility</a> on the File Exchange.<br />
<i><b>propertiesGUI</b></i> expects the following syntax:</p>
<pre lang='matlab'>[hPropsPane, parameters] = propertiesGUI(hParent, parameters)</pre>
<p>where:</p>
<ul>
<li><code>hParent</code> (input) is an optional handle of a parent GUI container (figure/uipanel/uitab) in which the properties table will appear. If missing or empty or 0, the table will be shown in a new modal dialog window; otherwise it will be embedded in the parent container.</li>
<li><code>parameters</code> (input) is an optional struct or object with data fields. The fields are processed separately to determine their corresponding cell renderer and editor. If <code>parameters</code> is not specified, then the global <code>test_data</code> will be used. If <code>test_data</code> is also empty, then a demo of several different data types will be used.</li>
<li><code>hPropsPane</code> (output) is the handle of the generated properties panel widget, which can be customized to display field descriptions, toolbar, etc.</li>
<li><code>parameters</code> (output) is the resulting (possibly-updated) parameters struct. Naturally, this is only relevant in case of a modal dialog.</li>
</ul>
<p>When passing the properties in an input <code>parameters</code> struct, <i><b>propertiesGUI</b></i> automatically inspects each struct field and assigns a corresponding cell-editor with no description and a field label that reflects the field name. The properties are automatically set as modifiable (editable) and assigned a default callback function (<i>propUpdatedCallback</i> sub-function).<br />
The global <code>test_data</code> variable is updated internally when the &lt;OK&gt; button is clicked. It is meant to enable easy data passing between the properties GUI and other application component. Using global vars is generally <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Action_at_a_distance_%28computer_programming%29">discouraged</a> as bad programming, but it simplifies GUI component interaction and has performance advantages. In this specific case I decided that the benefits of simplicity outweigh the pedagogical aspects. After all, <i><b>propertiesGUI</b></i> is meant to illustrate how to customize/use a properties pane, not to teach GUI programming best practices. In your real-world application you should consider using other information-sharing mechanisms (<i><b>getappdata</b></i> or <i><b>guidata</b></i>, for example).</p>
<h3 id="demo">Usage demo</h3>
<p>For an illustration of <i><b>propertiesGUI</b></i>, simply run it without any parameters to display its demo (see screenshot above):</p>
<pre lang='matlab'>propertiesGUI;</pre>
<p>This creates (in the <i>demoParameters</i> sub-function) the following demo <code>parameters</code> struct:</p>
<pre lang='matlab'>
      floating_point_property: 3.14159265358979
      signed_integer_property: 12
    unsigned_integer_property: 12
                flag_property: 1
                file_property: ''
              folder_property: 'C:\Yair'
                text_property: 'Sample text'
        fixed_choice_property: {'Yes'  'No'  'Maybe'}
     editable_choice_property: {'Yes'  'No'  'Maybe'  ''}
                date_property: [1x1 java.util.Date]
        another_date_property: 734895.957829132
                time_property: '22:59:16'
            password_property: '*****'
          IP_address_property: '10.20.30.40'
                  my_category: [1x1 struct]
               color_property: [0.4 0.5 0.6]
       another_color_property: [1x1 java.awt.Color]
</pre>
<h3 id="template">A template for customization</h3>
<p><i><b>propertiesGUI</b></i> is meant to be used either as stand-alone, or as a template for customization. For example, we can attach a unique description to each property that will be shown in an internal sub-panel: see the <i>customizePropertyPane</i> and <i>preparePropsList</i> sub-functions.<br />
We can have specific control over each property&#8217;s description, label, editability, cell-editor and callback function. See the <i>preparePropsList</i> sub-functions for some examples. Additional cell-editors/renderers can be added in the <i>newProperty</i> sub-function.<br />
Specific control over the acceptable property values can be achieved by entering custom code into the <i>checkProp</i> sub-function. For example, <i>checkProp</i> already contains skeleton code to highlight missing mandatory field values in yellow, and non-editable properties in gray (see highlighted lines; the necessary modifications to make it work should be self-evident):</p>
<pre lang='matlab' highlight="9-11,13-14">
function isOk = checkProp(prop)
  isOk = true;
  oldWarn = warning('off','MATLAB:hg:JavaSetHGProperty');
  warning off MATLAB:hg:PossibleDeprecatedJavaSetHGProperty
  propName = get(prop, 'UserData');
  renderer = com.jidesoft.grid.CellRendererManager.getRenderer(get(prop,'Type'), get(prop,'EditorContext'));
  warning(oldWarn);
  mandatoryFields = {};  % TODO - add the mandatory field-names here
  if any(strcmpi(propName, mandatoryFields)) && isempty(get(prop,'Value'))
      propColor = java.awt.Color.yellow;
      isOk = false;
  elseif ~prop.isEditable
      %propColor = java.awt.Color.gray;
      propColor = renderer.getBackground();
  else
      propColor = java.awt.Color.white;
  end
  renderer.setBackground(propColor);
end  % checkProp
</pre>
<p>So if we wish to check the validity of the input or user updates, we simply need to enter the relevant checks into <i>checkProp</i>.<br />
Additional control over the appearance and functionality can be achieved via the <code>hPropsPane</code> reference that is returned by <i><b>propertiesGUI</b></i>.</p>
<div id="example"></div>
<p>As an example for such customizations, here is a variant of the properties pane, embedded within a <a target="_blank" href="/articles/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a> panel. Note the unique description of the properties, and the absence of the OK/Cancel buttons:<br />
<center><figure style="width: 500px" class="wp-caption aligncenter"><img decoding="async" alt="Properties panel Integrated within a GUI" src="https://undocumentedmatlab.com/images/Champ_animated.gif" title="Properties panel Integrated within a GUI" width="500" /><figcaption class="wp-caption-text">Properties panel Integrated within a GUI</figcaption></figure></center></p>
<h3 id="TODO">TODO</h3>
<p>Even as a template for customization, <i><b>propertiesGUI</b></i> is still far from perfect. Some potential items on my TODO list for this utility include:</p>
<ul>
<li>Fix the renderer/editor for numeric and cell arrays</li>
<li>Enable more control over appearance and functionality via input parameters (for example: display or hide the OK/Cancel buttons)</li>
<li>Add additional built-in cell editors/renderers: time, slider, point, rectangle (=position), font, &#8230;</li>
</ul>
<p>Do you find <i><b>propertiesGUI</b></i> useful in your work? If so then please share your experience in a comment <a href="/articles/propertiesgui/#respond">below</a>. Suggestions for improvement of the utility will also be gladly accepted.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/propertiesgui">propertiesGUI</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/color-selection-components" rel="bookmark" title="Color selection components">Color selection components </a> <small>Matlab has several internal color-selection components that can easily be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uiinspect" rel="bookmark" title="uiinspect">uiinspect </a> <small>uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-sorting" rel="bookmark" title="Uitable sorting">Uitable sorting </a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/propertiesgui/feed</wfw:commentRss>
			<slash:comments>34</slash:comments>
		
		
			</item>
		<item>
		<title>Advanced JIDE Property Grids</title>
		<link>https://undocumentedmatlab.com/articles/advanced-jide-property-grids?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=advanced-jide-property-grids</link>
					<comments>https://undocumentedmatlab.com/articles/advanced-jide-property-grids#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 22 Apr 2010 06:01:19 +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[Callbacks]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Levente Hunyadi]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1316</guid>

					<description><![CDATA[<p>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids">Advanced 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/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/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/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again, 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 id="renderers">Non-standard property renderers and editors</h3>
<p>Last week, I discussed JIDE&#8217;s property table and showed how we can add custom properties and present this table in our Matlab GUI. Today, I will extend the previous week&#8217;s example to include more sophisticated renderers and editors.<br />
<a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender">Cell renderers and editors</a> are the backbone of JTable implementations, JIDE&#8217;s property grid included. Each property is associated with a type, and a renderer and an editor may be registered for a type. The cell renderer controls how the property value is displayed, while the editor determines how it is edited. For example, flags (Java <em>Boolean</em>s) are often both rendered and edited using a checkbox, but can also use a text renderer with a combo-box editor. <em>PropertyTable</em> automatically assigns a default renderer and editor to each property, based on its type: Flags are assigned a combo-box editor of true/false values, and similarly for other types.<br />
Let us now modify the preassigned editor. First, let&#8217;s set a <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#checkbox">checkbox</a> editor (<a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/BooleanCheckBoxCellEditor.html"><em>BooleanCheckBoxCellEditor</em></a>) for flags and a <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html">spinner</a> for numbers:</p>
<pre lang="matlab">
% Initialize JIDE's usage within Matlab
com.mathworks.mwswing.MJUtilities.initJIDE;
% Prepare the properties list:
% First two logical values (flags)
list = java.util.ArrayList();
prop1 = com.jidesoft.grid.DefaultProperty();
prop1.setName('mylogical');
prop1.setType(javaclass('logical'));
prop1.setValue(true);
list.add(prop1);
prop2 = com.jidesoft.grid.DefaultProperty();
prop2.setName('mycheckbox');
prop2.setType(javaclass('logical'));
prop2.setValue(true);
prop2.setEditorContext(com.jidesoft.grid.BooleanCheckBoxCellEditor.CONTEXT);
list.add(prop2);
% Now integers (note the different way to set property values):
prop3 = com.jidesoft.grid.DefaultProperty();
javatype = javaclass('int32');
set(prop3,'Name','myinteger','Type',javatype,'Value',int32(1));
list.add(prop3);
prop4 = com.jidesoft.grid.DefaultProperty();
set(prop4,'Name','myspinner','Type',javatype,'Value',int32(1));
set(prop4,'EditorContext',com.jidesoft.grid.SpinnerCellEditor.CONTEXT);
list.add(prop4);
% 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);
</pre>
<p><center><figure style="width: 300px" class="wp-caption aligncenter"><img decoding="async" alt="A property grid with checkbox and spinner controls" src="https://undocumentedmatlab.com/images/PropertyGrid_types.png" title="A property grid with checkbox and spinner controls" width="200" height="165" /><figcaption class="wp-caption-text">A property grid with checkbox and spinner controls</figcaption></figure></center><br />
Notice how the <b>EditorContext</b> is used to specify a non-standard renderer/editor for myspinner and mycheckbox: The mylogical flag displays as a string label, while mycheckbox displays as a checkbox; myinteger uses a regular integer editor that accepts whole numbers, while myspinner uses a spinner control to modify the value.<br />
Note that instead of creating an entirely new properties list and table, we could have run last week&#8217;s example, modified <em>list</em> and then simply called <em>model.refresh()</em> to update the display.<br />
Also note that Matlab types are automatically converted to Java types, but we must be careful that the results of the conversion should match our <em>setType</em> declaration. The logical value <i><b>true</b></i> converts to <em>java.lang.Boolean</em>, but 1 by default would be a double, which is the standard numeric type in Matlab. The <i><b>int32</b></i> wrapper is needed to force a conversion to a <em>java.lang.Integer</em>.<br />
Spinners with indefinite value bounds are seldom useful. The following shows how to register a new editor to restrict values to a fixed range. Remember to unregister the editor when it is no longer used:</p>
<pre lang="matlab">
javatype = javaclass('int32');
value  = int32(0);
minVal = int32(-2);
maxVal = int32(5);
step   = int32(1);
spinner = javax.swing.SpinnerNumberModel(value, minVal, maxVal, step);
editor = com.jidesoft.grid.SpinnerCellEditor(spinner);
context = com.jidesoft.grid.EditorContext('spinnereditor');
com.jidesoft.grid.CellEditorManager.registerEditor(javatype, editor, context);
prop = com.jidesoft.grid.DefaultProperty();
set(prop, 'Name','myspinner', 'Type',javatype, ...
          'Value',int32(1), 'EditorContext',context);
% [do something useful here...]
com.jidesoft.grid.CellEditorManager.unregisterEditor(javatype, context);
</pre>
<p>The principle is the same for <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html">combo-boxes</a>:</p>
<pre lang="matlab">
javatype = javaclass('char', 1);
options = {'spring', 'summer', 'fall', 'winter'};
editor = com.jidesoft.grid.ListComboBoxCellEditor(options);
context = com.jidesoft.grid.EditorContext('comboboxeditor');
com.jidesoft.grid.CellEditorManager.registerEditor(javatype, editor, context);
prop = com.jidesoft.grid.DefaultProperty();
set(prop, 'Name','season', 'Type',javatype, ...
          'Value','spring', 'EditorContext',context);
% [do something useful here...]
com.jidesoft.grid.CellEditorManager.unregisterEditor(javatype, context);
</pre>
<p><center><figure style="width: 250px" class="wp-caption aligncenter"><img decoding="async" alt="A property grid with a combobox control" src="https://undocumentedmatlab.com/images/PropertyGrid_combobox.png" title="A property grid with a combobox control" width="200" height="165" /><figcaption class="wp-caption-text">A property grid with a combobox control</figcaption></figure></center></p>
<h3 id="nested">Nested properties</h3>
<p>Properties can act as a parent node for other properties. A typical example is an object&#8217;s dimensions: a parent node value may be edited as a 2-by-1 matrix, but width and height may also be exposed individually. Nested properties are created as regular properties. However, rather than adding them directly to a <em>PropertyTableModel</em>, they are added under a <em>Property</em> instance using its <em>addChild</em> method:</p>
<pre lang="matlab">
propdimensions = com.jidesoft.grid.DefaultProperty();
propdimensions.setName('dimensions');
propdimensions.setEditable(false);
propwidth = com.jidesoft.grid.DefaultProperty();
propwidth.setName('width');
propwidth.setType(javaclass('int32'));
propwidth.setValue(int32(100));
propdimensions.addChild(propwidth);
propheight = com.jidesoft.grid.DefaultProperty();
propheight.setName('height');
propheight.setType(javaclass('int32'));
propheight.setValue(int32(100));
propdimensions.addChild(propheight);
</pre>
<p><center><figure style="width: 200px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="A property grid with nested property" src="https://undocumentedmatlab.com/images/PropertyGrid_nested.png" title="A property grid with nested property" width="200" height="165" /><figcaption class="wp-caption-text">A property grid with nested property</figcaption></figure></center><br />
<em>PropertyTableModel</em> accesses properties in a hierarchical naming scheme. This means that the parts of nested properties are separated with a dot (.). In the above example, these two fully-qualified names are <em>dimensions.width</em> and <em>dimensions.height</em>.</p>
<h3 id="callback">Trapping property change events</h3>
<p>Sometimes it is desirable to subscribe to the PropertyChange event. This event is fired by <em>PropertyTableModel</em> whenever any property value is updated. To expose Java events to Matlab, we use the two-parameter form of the <i><b>handle</b></i> function with the optional CallbackProperties parameter.</p>
<pre lang="matlab">
hModel = handle(model, 'CallbackProperties');
set(hModel, 'PropertyChangeCallback', @callback_onPropertyChange);
</pre>
<p>The callback function receives two input arguments: The first is the <em>PropertyTableModel</em> object that fired the event, the second is a <em>PropertyChangeEvent</em> object with properties <b>PropertyName</b>, <b>OldValue</b> and <b>NewValue</b>. The <em>PropertyTableModel</em>&#8216;s <em>getProperty(PropertyName)</em> method may be used to fetch the <em>Property</em> instance that has changed.<br />
Callbacks enable property value validation: <b>OldValue</b> can be used to restore the original property value, if <b>NewValue</b> fails to meet some criteria that cannot be programmed into the cell editor. We may, for instance, set the property type to a string; then, in our callback function, use <i><b>str2num</b></i> as a validator to try to convert <b>NewValue</b> to a numeric matrix. If the conversion fails, we restore the <b>OldValue</b>:</p>
<pre lang="matlab">
function callback_onPropertyChange(model, event)
   string = event.getNewValue();
   [value, isvalid] = str2num(string); %#ok
   prop = model.getProperty(event.getPropertyName());
   if isvalid  % standardize value entered
      string = mat2str(value);
   else  % restore previous value
      string = event.getOldValue();
   end
   prop.setValue(string);
   model.refresh();  % refresh value onscreen
</pre>
<p>The JIDE packages that are pre-bundled in Matlab contain numerous other useful classes. Some of these will be described in future articles.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/advanced-jide-property-grids">Advanced 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/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/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/simple-gui-tabs-for-advanced-matlab-trading-app" rel="bookmark" title="Simple GUI Tabs for Advanced Matlab Trading App">Simple GUI Tabs for Advanced Matlab Trading App </a> <small>A new File Exchange utility enables to easily design GUI tabs using Matlab's GUIDE...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/advanced-jide-property-grids/feed</wfw:commentRss>
			<slash:comments>54</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>
	</channel>
</rss>
