Coding Workspace Objects with Java Components
From Rave Documentation
Revision as of 22:59, 26 February 2013 by Matt (Talk | contribs) (Created page with "Coding workspace objects that use java components is complicated by the fact that java objects cannot be saved in a .rve project file. Because of this limitation, you need to fol...")
Coding workspace objects that use java components is complicated by the fact that java objects cannot be saved in a .rve project file. Because of this limitation, you need to follow certain rules to make sure that ravesavestate can correctly save a .rve project file, and that raveloadstate can load .rve files that use your object.
The rules
- Java objects cannot be saved in the .rve project file, so ravesavestate deletes them first, then raveloadstate recreates them by calling ravecreateWORKSPACEOBJECT. Because of this:
- Your ravecreateWORKSPACEOBJECT.m function must be able to recreate the java objects from just the information stored in udata. For example, if you have a java-based text box in which the user can enter text, this text must be stored in udata in addition to being stored in the java text box itself.
- Your ravecreateWORKSPACEOBJECT.m function must not give errors if the java objects have been deleted (since they WILL be deleted by ravesavestate). If your workspace object creates the java object only once during raveinitializeWORKSPACEOBJECT, then ravecreateWORKSPACEOBJECT must have a check that if the java objects do not exist, it recreates them in the same way they initially get created by raveinitializeWORKSPACEOBJECT.
- Similarly, if you recreate your java objects each time ravecreateWORKSPACEOBJECT.m is called, you probably delete them at the beginning of that function. Make sure you properly code this so it doesnt give an error if they've already been deleted.
- Java objects that appear on screen (e.g., swing objects) MUST be children of either handles.fig, handles.wspanel, or a uipanel whose handle is stored in handles.allgraphs, handles.fakeax, or handles.fakerax. These are the only places that ravesavestate will look for java objects to be deleted.
- You MUST include a property in your graphpropertiesWORKSPACEOBJECT.m file named "unsaveablehandles". This is a cell array of strings that are the field names in udata (including the "udata." part) where java objects have been stored. All non-graphical java objects must ONLY be stored in a udata field that appears in this list (i.e. do not store them in handles, only store them in udata, and then include the place that you store them in this list.) Any stored handles to graphical java objects that you placed using javacomponent may ONLY be stored in udata in a field that appears in this list.