I would like to add a 'display-all' hyperlink functionality to a class.

3 vues (au cours des 30 derniers jours)
Steve
Steve le 13 Fév 2019
Réponse apportée : moali le 22 Juin 2020
I've created a series of classes which serve as a convienient front end for some standard data sources which are ubiquitous in our organization.
I've been storing the data in a structure [in it's native form] and I've created alot of dependent properties to access the data convieniently. In addition, many of these dependent properties do alot of indexing in and [sometimes time consuming] calculations to identify good/bad/ugly regions and other things.... stuff which I want to only see sometimes.
I've tried hiding some properties, but it's easy to forget what they are and it's harder to hand off data to someone who maybe isn't as intimate with the source.
Currently, I've defined some custom display routines so not all of the data is displayed when something is queried in the command line. I can over-ride the custom display and use MATLAB's builtin display routines when I need to.
What would be very helpful is to add a hyperlink (like the display for graphic handle objects below) to quickly display various subsets (or groups of properites) of my data.
I haven't figured out how to get a hyperlink reference to a specific instance of my class... it appears to only have access to the base workspace.... Any thoughts?
K>> foo = figure
foo =
Figure (3) with properties:
Number: 3
Name: ''
Color: [1×3 double]
Position: [680 678 560 420]
Units: 'pixels'
Show all properties
classdef foo < matlab.mixin.CustomDisplay
properties
this = 1;
that = 2;
theother = 'harbinger to lots of other properties';
end
methods (Access = protected)
function g = getPropertyGroups(obj)
g = matlab.mixin.util.PropertyGroup({'this','that'},'important stuff:');
end
function f = getFooter(obj)
f = sprintf('<a href = "??matlab: CAN-ONLY-ACCESS-BASE-SPACE-FROM-HERE??" >display all</a>');
end
end
end

Réponse acceptée

Yair Altman
Yair Altman le 16 Fév 2019
It is true that desktop hyperlinks only work at the base workspace level, but you can still access specific object instances if you store them somewhere that is accessible from the base workspace. For example, if your object instance include a unique ID:
uniqueId = char(java.util.UUID.randomUUID); % e.g. '221a5ecd-437e-4fa2-b4dd-de1bff77c9fd'
Then you can create a public static method that searches for and displays this object using its ID. For example, you can store all the active object references (list of uniqueIds vs. handles) in some global variable, and then the hyperlink will run a Matlab function that searches for the specific uniqueId, fetches the corresponding instance reference, and then displays its internals as you wish.

Plus de réponses (2)

Steve
Steve le 19 Fév 2019
Hmmmm..... I'll try that. Thanks for the randomUUID reference, that will be key to making something work.
Thanks for your help!

moali
moali le 22 Juin 2020
Hey Steve, I was trying to do the same thing. I took your example of foo = figure, and went over the hyperlink 'all properties'. In the status bar, it showed matlabs code. Using that, plus this help topic:
I came up with the following code:
function footer = getFooter(sec)
if isscalar(sec)
varName = inputname(1);
link=sprintf(['matlab:if isvalid(%s), ', ...
'MyCustomDisplayFunction(%s), ', ...
'else, ', ...
'fprintf(''Unable to display properties. %s refers to a deleted object.\\n''), ', ...
'end'], ...
varName,varName,varName);
linkStr = sprintf('<a href="%s">all properties</a>',link);
footer = sprintf('Show %s\n',linkStr);
else
footer = '';
end
end

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by