11

I extended the functionality of a line object using a class which takes a line handle as an input argument to its constructor. This class then creates a WindowMouseMotion listener to detect a mouseover the line which highlights the line and displays a panel containing controls for setting some line/data properties. This is working well.

I am now trying to make this class detect and respond to the line being deleted by listening for the line's ObjectBeingDestroyed event. My question is whether linking this class to the line object by storing the line's handle is the best solution or is it possible to extend the line class by inheriting from it? I have looked through the MATLAB documentation and searched online but can't find definitive information on inheriting from graphics classes.

b3.
  • 7,094
  • 2
  • 33
  • 48
  • This is a pretty detailed one and you might not see an answer anytime soon. [You might want to ask Mathworks this one](http://www.mathworks.com/matlabcentral/answers/?s_cid=HP_FR_answers). – Chris A. May 18 '11 at 20:09
  • @Chris A. - Thanks for the link. I knew about the MATLAB Central newsgroup but I somehow missed the Answers section. Here is a link to my post there: http://www.mathworks.com/matlabcentral/answers/7737-is-it-possible-to-extend-graphics-objects-functionality-through-inheritance – b3. May 18 '11 at 20:45
  • Prefer Composition Over Inheritance: http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance – Mikhail Poda May 26 '11 at 19:44
  • @b3: It might be better if you put down your latest edit as an answer and accept it. – abcd May 30 '11 at 17:42

2 Answers2

2

It is possible to subclass the builtin handle graphics classes. There is an example at http://undocumentedmatlab.com/blog/udd-properties/ . It uses the specifically undocumented UDD mechanism. The MathWorks has stated on numerous occasions that UDD is for internal development and use only and unsupported. It is worth noting however that there are numerous examples of UDD subclassing in the m code that The MathWorks provides. Also IF they feel that there is a specific reason to keep something in UDD secret it is either built-in or pcoded. So I feel that if you find examples of how to do things in the source code provided by The MathWorks you should feel free to use them.

Donn
  • 36
  • 2
1

Got this response over at MATLAB Central Answers: "There is no documented way to inherit from (/subclass) handle graphic objects. I guess the rule is that if you cannot find it in the documentation it is not supported."

There is a suggestion that it may be possible to extend the new HG2 classes here but this is not official Mathworks information.

b3.
  • 7,094
  • 2
  • 33
  • 48
  • 1
    You could indeed listen to the line’s ObjectBeingDestroyed event. This is what Matlab does internally numerous times in its code (take a look at javacomponent.m for example). Perhaps a simpler approach is to simply set a callback function in the line’s DeleteFcn property. – Yair Altman Sep 08 '11 at 10:54