File Exchange

image thumbnail

Making MATLAB Swing

version 1.13 (1.05 MB) by

TabbedPanes, SplitPanes, SideBars, ScrollPanes etc for MATLAB

4.64706
17 Ratings

2 Downloads

Updated

View License

A short summary of the features available in the Project Waterloo Swing Library.

This collection of MATLAB classes provide support for TabbedPanes, SplitPanes, ScrollPanes, SideBars, Accordions etc within MATLAB.

Both MATLAB and Java Swing graphics can be added to the containers

This library includes several files that were previously available separately on the FEX:

JCONTROL CLASS
For adding Java Swing components to MATLAB figures

MOUSEMOTIONHANDLER
For extending mouse motion callbacks to all MATLAB components

GCOLOR
Static class for RGB/HSL/Java/MATLAB color conversions + manipulation. Color series.

MUTILITIES
AWT/Swing/MATLAB graphics utilities. Figure transparency etc

Project Waterloo is free and open-source and is available from:

http://sigtool.sourceforge.net/

Comments and Ratings (56)

Malcolm Lidierth

@David
Not sure if that is possible. As I recall GScroller only worked because of a quirk in the MATLAB code that let me set normalized sizes >1. I doubt uicontrols would allow that.

David

David (view profile)

Thank you very much!!

I would like to use the GScroller but instead of putting imagesc inside the uipanels, I would like to put uicontrol. With uicontrols, when I use the scroll bar, they are still visible even when they are outside the uipanel. I think there is a clipping problem but I checked and I can't see anything...
Could you help me on that subject?

Thank you!

Malcolm Lidierth

@Doug

Many thanks. Looks like MATLAB is insisting on pass-by-value syntax in R2012b:
For backwards compatibility, I avoid [~], but your fix seems to work equally well with:

obj.hgcontainer=subsasgn(obj.hgcontainer, index, val);

Same problem could also arise at line 38. Change to:

obj.(index(1).subs)=subsasgn(obj.(index(1).subs), index(2:end), val);

FYI: Latest code for this is now in a GIT repo. See:

http://waterloo.sourceforge.net

Regards
Malcolm

Doug

Doug (view profile)

New in 2012b I'm getting getting the following warning in a waterloo(1.08) dependent GUI:

Warning: SUBSASGN must be called with an output.
> In jcontrol.subsasgn at 57
In GSplitPaneDivider>GSplitPaneDivider.GSplitPaneDivider at 62
In GSplitPane>GSplitPane.GSplitPane at 97
etc.

Temporary fix was to modify line 57 on subsasgn.m to include a dummy assignment, e.g.

[~] = subsasgn(obj.hgcontainer, index, val);

Just passing the word back. Great tool, thanks guys!

Malcolm Lidierth

An "alpha" version of Waterloo 1.1 is now available on SourceForge. This includes a new Java library for scientific graphics that can be called from Java, Groovy, Scala, MATLAB, the R statistical environment and SciLab.

For MATLAB, a MATLAB-like API is provider using custom MATLAB OOP wrappers.

For details and downloads see the new website at:

http://waterloo.sourceforge.net/

Jonathan Lister

Malcolm Lidierth

@ Aurelien

w=com.mathworks.mde.desk.MLDesktop.getInstance().getMainFrame().getWindows()

returns a list of Windows including those for GWait.

Call
w(N).dispose()
to close the relevant windows.

Note that releases system resources, but does not delete the reference as per Java docs. The window can be reconstructed with a call to show.

Accepted - I should make that easier.

Malcolm

hello Malcolm,
Just one question : how to delete several Gwait ?

Lets' say I build 2 Gwait w/o using output argument:
>>GWait('','first',' ...')
>>GWait('','second')
I do not manage to find these objects using findobj.

Thanks

Malcolm Lidierth

An updated version (1.08) is on sourceforge with accumulated fixes.
This now includes the Swing, Swing "more" and file utilities in a single zip (for easy maintenance).

Thanks for your help. I will try to solve or work around this issue with your suggestions in mind (or just change the design, avoiding too many nested components!). You have been very helpfull, thanks again.

Malcolm Lidierth

@Sebastian

I thought about this a bit more. The only problem I can see is in setting the visibility property for hgjavacomponents– everything else seems to work as intended. The problem is that GCardPane is generic – it has no “knowledge” of whether its contents are another GCardPane or a single layer uipanel. It manages OK regardless until undocumented components such as hgjavacomponents are added (which are not "seen" by all MATLAB search functions).

The quickest approach might be to create a couple of custom-subclasses: [1] of GTabContainer using [2] a GCardPane that “knows” the contents of the container. e.g by adding a new property (you could probably just use the appdata area but that would be less consistent with the overall design).
The outer tab pane would simply need to store a reference to the inner tabbed pane. Then overload setSelectedIndex for the outer card pane to look at the selection on the inner tab container before setting the visible properties to ‘on’ only for those hgjavacomponents that are children of the selected card in the inner container.
That would mean changing 1 method – setSelectedIndex - and adding support via a method (or the constructor) for the new property. Everything else would work (I think) so could just be inherited from the superclass. It should also allow nesting to arbitrary levels if you might need that later.

I think nested panels with undocumented features at the inner levels is probably stretching things a bit beyond what most users want - so I'll not put this on the TODO list.

Malcolm Lidierth

@Sebastian
That helps to track the issue down.
The problem is with lines 160-163 of GCardPane. These use findall, to get the hgjavacomponent handles and take no account of the possibility of nested cards.
I'll add this to the TODO list. Any suggestions wellcome.

Hi again;
Thanks but unfortunutely, it only works during creation time but not thereafter, i.e. if you switch between the upper Views, it is still visible under the wrong subView when you switch back.

Malcolm Lidierth

@Sebastian
This may be better:

j2 = jcontrol(tabbedPane.getComponentAt(1), javax.swing.JPanel(),'Visible', 'off'...

Visibility will be set 'on' automatically when the appropriate tab is selected.

Malcolm;
Thank you for your fast reply.
Yes, I also thought of the fix you suggested but the trouble is that when I have a more complex structure, e.g. when I add nested tabs, I get this behavior every time I switch back and forth between tabs. For example, add a control to subview 1 (that is part of View 3) in stage 4 of your demo., i.e.

j4 = jcontrol(nestedTab.getComponentAt(1), javax.swing.JPanel(), 'Position', [0.01 0.45 0.1 0.16]);

Then change the view in the upper tab (e.g. from view 3 to view 2). If you then switch back to view 3, the component is visible under subview 2 even though its parent is subview 1. This happens everytime you switch between the upper tabs. Strangely enough if I add a component with matlabs uitool, I do not get this behavior. Any suggestions?

And again, it is really an excellent piece of work.

Malcolm Lidierth

@Sebastian
I think I see the issue. The JPanel is correctly added to tab1 and everything works fine when tabs are selected.

But, during creation of the jcontrol it gets rendered to screen, and as tab2 is visible at that moment it appears to be in that tab until the tab selection is changed.

A workaround is to make sure tab1 is visible while the additions are done:

tabbedPane.setSelectedIndex(1);

j2 = jcontrol(tabbedPane.getComponentAt(1), javax.swing.JPanel(),'Position',..

tabbedPane.setSelectedIndex(2);

Not ideal I know, and if I can think of a better way I'll include a fix.

Excelent piece of work, very impressive indeed.
I seem to have some issues with adding components with jcontrol to a GTabContainer though. To give a simple example: I run your waterloodemo until Stage3 and there, instead of adding a matlab figure to tab2, I try to add a JPanel to tab1, i.e. I substituted the code that says

ax=axes('Parent', tabbedPane.getComponentAt(2))

with

j2 = jcontrol(tabbedPane.getComponentAt(1), javax.swing.JPanel(),’Position’ …)

then this control, on creation, shows up on top of tab2 instead of tab1. Its gets added to tab1 correctly but shows up on tab2 on addition. If I instead add a matlab control (e.g. using uicontrol) I do not get this behavior. This is a simple example just for illustration but it becomes an issue when trying to build a more complicated GUI with many nested tabs. Components created with jcontrol (or Yair Altmans uicomponent or by direct addition with javacomponent) seem to be stuck on top of some of the tabs while components created with MATLAB's uitools (e.g. uicontrol or uitable) does not excibit this behaviour. Any suggestions of what could be the problem?

Malcolm Lidierth

@Dirk
Agreed. The project was moved to Lesser GPL v3 on SourceForge a few weeks ago but I have not updated the docs yet. LGPL permits use in proprietary code - only requiring a user to share modifications to this code.

Dirk Engel

After reading the manual I must say I'm impressed. This is a nice piece of software. However, license type GPL v3 seems to be a very poor choice in my opinion. Please correct me if I'm wrong, but wouldn't this force any work which just "uses" this library to be published under GPL as well? This is weird for something that abstract as a GUI container and is a reason for me not to use it. Therefore, 1 star only.

Are there any chances switching to BSD? If not, what is the reason for GPL?

Malcolm Lidierth

Rename the file to MUtilities.m.
Note that GTool and its subclasses require R2008+

Jaya Singh

This is an excellent work. Very helpful and meets my needs.

I have a question regarding the GUI deployment. I tried to make a standalone GUI but I get the following error message:
-------------------------------
Depfun error: 'Error: File: C:\Program Files\MATLAB\R2010a\toolbox\waterloo\Waterloo Swing Library\@MUtilities\MUtilities_R2006b_onwards.m Line: 1 Column: 10

Class name and filename do not agree.'
-------------------------------

Could you please help me with this?
Thanks a lot.

Malcolm Lidierth

A patch with some replacement files has been posted on SourecForge.
Fixes: Responsiveness of GTabbedPane buttons, getBackground wrongly included as static method in GTool
Files at full details at:
http://sourceforge.net/projects/waterloo/files/Waterloo%20MATLAB%20Swing%20Library%201.07/

@ Nilimb

I see the problem. As far as MATLAB is concerned, the inner components are not generally visible - whether you can see them on screen or not - and will not respond to mouse clicks. GScroller uses clipping and panels that extend beyond the normalized [0 0 1 1] limits to do its job.

A solution might be to add a mouse button callback to the outer panel of the GScroller. Within that, the mouse position could be used to calculate which components are displayed and which was clicked on. I'll add it to the TODO list.

Nilimb

Nilimb (view profile)

using the code below...if i run it...i can click on the first 3 panels and change thier color on mouseclick but if i click on the 4th or 5th panel the callback is not generated

function Untitled
h=figure('Units', 'normalized', 'Position', [0.1 0.1 0.8 0.8], 'Name', 'Slidertest', 'Color', [0.9 0.9 0.9]);
gpanel=uipanel('Parent',h,'Position',[0 0.072 0.2 0.927],'BackgroundColor',...
[0.314 0.314 0.314]);
filters=3;
gscroll=GScroller(gpanel,'right',filters);
leftpanels=[];leftaxes=[];
for k=1:filters+2
p=gscroll.add();
set(p,'BackgroundColor',[0.314 0.314 0.314],'ButtonDownFcn',{@leftpanelaction,h});
leftpanels=[leftpanels,p];
if k>1
axes('Parent',p);
hIm=imshow([]);
set(hIm,'ButtonDownFcn',{@leftaxesaction,h});
leftaxes=[leftaxes,hIm];
axis('off');
title('\color{white}Filter')
else
axes('Parent',p);
hIm=imagesc([]);
set(hIm,'ButtonDownFcn',{@leftaxesaction,h});
leftaxes=[leftaxes,hIm];
axis('off');
title('\color{white}Result')
end
setappdata(h,'leftaxes',leftaxes);
setappdata(h,'leftpanels',leftpanels);
end

%
end
function leftpanelaction(varargin)
h=varargin{3};
panel=varargin{1};
p=getappdata(h,'leftpanels');
idx= p==panel;
set(p,'BackgroundColor',[0.314 0.314 0.314]);
set(p(idx),'BackgroundColor',[0.314 0.314 0.9]);
end
function leftaxesaction(varargin)
h=varargin{3};
hIm=varargin{1};
panel=get(get(hIm,'Parent'),'Parent');
p=getappdata(h,'leftpanels');
idx= p==panel;
set(p,'BackgroundColor',[0.314 0.314 0.314]);
set(p(idx),'BackgroundColor',[0.314 0.314 0.9]);
end

Malcolm Lidierth

@ Nilimb
Could you post some example code?

Nilimb

Nilimb (view profile)

while using GScroller(panel,'left',4), if i add 10 images and assign a callback to each. when i click on a image which is visible, the callback gets executed. but if i scroll down to image no 5 onwards, their callbacks do not get executed...any workaround. excellent submission though!!

Malcolm Lidierth

An update (1.07) is now on SourceForge.
This includes a new GImport class for installing GUIs designed in Eclipse/NetBeans/IntelliJ GUI designers. GImport is also posted to the FEX under the BSD licence.

The full project now includes the correct (non-dev) jar file - so GradientPaints etc will be available.

Malcolm Lidierth

@Jorge
1. Swing components can be added to MATLAB containers using the existing jcontrol class that is in the present distribution. GImport provides a convenient wrapper that also takes over some isses like layout management to get MATLAB-like behaviour.
If you want things the other way round, i.e. to put a MATLAB figure into Swing panel, I am not sure that can be done easily/to ggod effect.

2. I do not use SimuLink and do not know the answer.

Regards
ML

Jorge Durán

Great Work! Congratulations. I have two questions about the MATLAB/JAVA integration with this library.

1- Is it possible to use the library to include a figure obtained with matlab into a pure JaVa-Swing interface?

2- Is it possible to load a Simulink Model into figure created with your library?

I have just read your last comment so i think that my first cuestion is answered.

Thanks for the work. I looking forward for the next version and the new issues. Which is the release date?

Corey

Corey (view profile)

Malcolm,
Your next submission sounds substantial....looking forward to it!

@Romesh
Glad it worked. I'll look at the permissions issue.
The reason for GNU GPL is that Waterloo will eventually include third-party code distributed under GPL.
The next component, GImport, will be released shortly and provides a way to avoid GUIDE. GImport lets you import Java Swing GUIs designed with the tools in Netbeans, Eclipse, IntelliJ etc. GImport manages the layouts to give MATLAB-like resize behaviour and provides mechanisms for modifying/querying/managing the GUIs easily from within MATLAB.

Romesh

Fantastic work. I'm also interested in the MCC, and successfully compiled the demo on Mac OS R2011a with only one issue:

Depfun error: 'Method 'getBackground' in class 'GSideBar' uses different access permissions than its super-class 'GTool'.'

The compiled code seems to run fine after I deleted this file. I ran waterloo.m before mcc. I guess I'll need to send some emails to work out exactly what constitutes a derivative work/whether including the source code for just the waterloo part of the project is sufficient (my current impression is that this would be acceptable...?)

Malcolm Lidierth

@Jveer.

As waterloo.m dynamically sets up the MATLAB path in a MATLAB session, it is inherently non-deployable. Does calling it before mcc not do the trick? The main library may or may not be deployable - I have not tried and do not have mcc.

As mcc is often used to protect proprietary rights over code, I did not imagine this library would see much use there. The code is distributed under GNU GPL v3 (which is why only a PDF is on the FEX) and propagation of the code, mcc'd or otherwise, would need to comply with the terms of that license.

Jveer

Jveer (view profile)

This is great but doesn't not work with mcc:

"MCC does not permit the ADDPATH function"

Could you please update waterloo.m so that it can be deployed?

Malcolm Lidierth

@NK University
I do not use mcc but having looked at the spec I see no reason not to use it with this code.
Maybe you could try and let me know how you get on.

NK University

Can works based on waterfoo be mcc to exes?

NK University

It is very usfull for me! Thank your for your kindly works!!!

Super! Good job for the PDF and the new question "Do you really want to sop procesing?" for the GProgressbar! Thanks a lot

Malcolm Lidierth

@Aurelien
Aha. I have seen the problem. Fixed properly in version 1.06, see http://sigtool.sourceforge.net/.
The progress bar and text are now the same width.
The new version includes several other updates: e.g. addition of scroll panes and a short PDF describing the library.

super merci

Malcolm Lidierth

@ Aurelien. There is a FEX post in the pipeline (on SourceForge already) that probably fixes this problem - text set/get off the EDT - but I will shorten as suggested.

Thanks Malcom. Another remark (not important)
In GProgressBar.m line 205 , I would change the word "remaining" by a smaller word like "left" when computation is greater than 1 mn. It allows to have the text centered and see correctly the text in progress bar.

Malcolm Lidierth

@ Aurelien. Many thanks - I'll fix that.

Just a remark : I think the if-test of nargin in line 80 of GWait.m is wrong. It should be 4 instead of 3 .

Sven Koerner

Sven Koerner (view profile)

This is a very good peace of work! Excellent!

Brett Baker

Malcolm Lidierth

@David
All the code is now much tidier (I hope). The problems were related to too many drawnow() calls in individual object methods which showed up particularly in the animations. Removing them may mean that you need the odd drawnow() in your own code to use these.
The animations are also now much tidier if you turn them on. You can do that from the command line:
GTool.getDefaults().put('GCardPane.Animated', true);
[NB Only affects objects created subsequently].
The speed can be adjusted using
GTool.getDefaults().put('Timer.Interval', T);
where T is an interval in seconds (default 0.05).

I'll document all of this properly once the code is stable.

Also TODO is a drop-in GTabbedPane alternative that better suits MATLAB - using the JTabbedPane gives the right OS Look and Feel but the JTabbedPane is not Swing's best designed or most easily customised component.

Corey

Corey (view profile)

Outstanding!

David

David (view profile)

Thanks Malcolm. Turning the animation off between tabs provided a huge performance increase. Now I can quickly switch between several tabs with no issues. I also reran the demo and everything works great! Everything loads almost instantly!

Malcolm Lidierth

@David
It's a bug. myTabbedPane.setAnimated(false);
is not doing anything useful. I'll fix that, but for the present

myTabbedPane.getComponent(1).setAnimated(false);

should do the trick (Component 1 is the GCardPane).

I will be looking to improve performance through profiling. For the demo, compilation time seems to be an issue as it runs much faster on a 2nd run through especially on WIndows XP: e.g. the split pane dividers can be sluggish until they have been moved a few times. If you have a simple example that performs particularly badly I'd appreciate a copy [sigtool(at) kcl(dot) ac(dot )uk].

David

David (view profile)

Great work! Things individually seems to work very nicely. However, when running the demo and clicking through the various tabs, there seem to be a performance issue. Sometimes the screen will hang after clicking a tab and sometimes the "Next" button will not be functional until everything is fully loaded (takes several seconds between tabs). I am running the demo on Windows XP on a Core i7 computer with 4 GB of ram so I don't think my computer specs is the issue. I also got the same problem when building my own GUI with a few simple plots using GTabbedPane. Do you know what might be causing this issue?

Also how do you turn off the animation between tabs? I've looked through the GTabbedPane comments and it only says you can turn it off but not how. Maybe this is contributing to the performance issue?

Awesome work though!

Malcolm Lidierth

@Bruno
The GElasticPane null pointer issue has now been fixed and I'll post an update. The flashing button is not something I have seen - what OS/ML version did you see that with. It may well be caused by the fixed GElasticPane issue - probably a mismatch between MATLAB stack and Java ZOrder.

Bruno Luong

Bruno Luong (view profile)

Quite promising.

The Java crash on Window when using GElasticPane is a minor issue.

I notice during the Demo the NEXT button is blinking. What is the reason?

Excellent work.

Very impressive!

Yair Altman

Yair Altman (view profile)

Exceptional work!

A very useful set of tools for anyone who wishes to develop professional-looking GUI in Matlab.

Updates

1.13

Update description re: removed old files

1.12

Change submission to PDF with link in description

1.8

Improvied performance. GTabContainer added. GWait/GProgressBar improved. Added support for themes.

1.7

Now much faster. Animations improved and set off by default.

1.6

Fix Windows null pointer problems. Numerous improvements/additions from feedback (thanks Yair!).

MATLAB Release
MATLAB 7.6 (R2008a)
Acknowledgements

Inspired: SPECCHIO Fluspect GUI

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video