Code covered by the BSD License  

4.64706

4.6 | 17 ratings Rate this file 27 Downloads (last 30 days) File Size: 1.05 MB File ID: #32697
image thumbnail

Making MATLAB Swing

by

 

26 Aug 2011 (Updated )

TabbedPanes, SplitPanes, SideBars, ScrollPanes etc for MATLAB

| Watch this File

File Information
Description

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/

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Code has been tested on Windows XP/7, Mac Snow Leopard and Ubuntu 11.04
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (56)
17 Nov 2013 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.

24 Oct 2013 David

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!

19 Jan 2013 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

19 Jan 2013 Doug

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!

22 Nov 2012 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/

08 Nov 2012 Jonathan Lister  
26 Oct 2012 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

26 Oct 2012 Aurelien Queffurust

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

17 Jul 2012 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).

12 Jul 2012 Sebastian Arslanogullari

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.

11 Jul 2012 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.

11 Jul 2012 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.

11 Jul 2012 Sebastian Arslanogullari

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.

11 Jul 2012 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.

11 Jul 2012 Sebastian Arslanogullari

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.

11 Jul 2012 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.

11 Jul 2012 Sebastian Arslanogullari

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?

21 Jun 2012 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.

21 Jun 2012 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?

21 Jun 2012 Malcolm Lidierth

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

20 Jun 2012 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.

12 Jun 2012 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/

08 Jun 2012 Malcolm Lidierth

@ 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.

07 Jun 2012 Nilimb

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

31 May 2012 Malcolm Lidierth

@ Nilimb
Could you post some example code?

31 May 2012 Nilimb

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!!

22 Dec 2011 Malcolm Lidierth

Link for GImport on the FEX
http://www.mathworks.com/matlabcentral/fileexchange/34235-making-matlab-swing-more

16 Dec 2011 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.

13 Dec 2011 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

13 Dec 2011 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?

03 Dec 2011 Corey

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

03 Dec 2011 Malcolm Lidierth

@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.

02 Dec 2011 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...?)

12 Nov 2011 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.

11 Nov 2011 Jveer

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?

12 Oct 2011 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.

11 Oct 2011 NK University

Can works based on waterfoo be mcc to exes?

10 Oct 2011 NK University

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

27 Sep 2011 Aurelien Queffurust

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

26 Sep 2011 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.

19 Sep 2011 Aurelien Queffurust

super merci

19 Sep 2011 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.

19 Sep 2011 Aurelien Queffurust

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.

15 Sep 2011 Malcolm Lidierth

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

15 Sep 2011 Aurelien Queffurust

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 .

15 Sep 2011 Sven Koerner

This is a very good peace of work! Excellent!

01 Sep 2011 Brett Baker  
31 Aug 2011 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.

31 Aug 2011 Corey

Outstanding!

31 Aug 2011 David

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!

30 Aug 2011 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].

30 Aug 2011 David

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!

27 Aug 2011 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.

27 Aug 2011 Bruno Luong

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.

26 Aug 2011 Etienne Coetzee

Very impressive!

26 Aug 2011 Yair Altman

Exceptional work!

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

Updates
29 Aug 2011

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

31 Aug 2011

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

14 Sep 2011

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

26 Sep 2011

Change submission to PDF with link in description

30 Sep 2011

Update description re: removed old files

Contact us