Comments (8)
For the record, HG1 (R2014a and older) also supports dot-notation, if you simply ensure that all the relevant GUI/graphic handles are handle() objects rather than numeric. For example, the following code runs ok on HG1:
hFig = handle(gcf); % trick to enable dot-notation on GUI/graphic objects
hFig.Color = 'w';
hFig.CloseRequestFcn = @myCallback;
The nice thing about this is that it's fully backward-compatible, meaning that hFig=handle(gcf)
is transparent to HG2 and meaningful to HG1, so it can be used in Matlab code on both HG1 and HG2.
from mlapp2classdef.
It actually even improves performance in some cases:
https://undocumentedmatlab.com/blog/performance-accessing-handle-properties
from mlapp2classdef.
A caveat to this conversion is that the GUIs will still likely require R2014b or newer. The App Designer makes extensive use of dot notation to access properties of UI objects rather than set
or get
. A warning to this effect will be included for users running mlapp2classdef
in MATLAB versions prior to R2014b.
Though a fun project idea on its own, creating a parser to robustly handle these compatibility issues is beyond the scope of this project.
from mlapp2classdef.
Another consideration is that a lot of the object properties and callbacks are new to R2016a, which isn't something that can be reliably caught without significant effort
from mlapp2classdef.
For posterity: it may be possible to convert some App Designer elements to Java Swing components, e.g.:
%% List of JComponents:
% https://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html
%% Spinner - https://docs.oracle.com/javase/8/docs/api/javax/swing/JSpinner.html
jSp = javaObjectEDT('javax.swing.JSpinner');
% Get available methods & fields:
M = methods(jSp);
F = fields(jSp); % fields often contain the allowable settings for methods.
% Set some properties:
jSp.setAlignmentX(jSp.LEFT_ALIGNMENT);
% Display component
[jSpinner, hSpContainer] = javacomponent(jSp,'South');
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SwingConstants.html
%% Scrollbar (example based on Altman-2012)
% Create and initialize a JScrollBar object
jSb = javaObjectEDT('javax.swing.JScrollBar');
% Set some properties:
jSb.setOrientation(jSb.HORIZONTAL);
% Display component
[jScrollbar, hSbContainer] = javacomponent(jSb,'North');
from mlapp2classdef.
Here's a better demo of how to make a spinner and attach a callback to it:
function hFig = spinnerDemo
%% javacomponent "docs": Delete lines 2-3 from javacomponent.m to get access to docs using F1 (help browser)
%% Spinner - https://docs.oracle.com/javase/8/docs/api/javax/swing/JSpinner.html
hFig = figure();
% Create a spinner (w/o model):
jJSpinnerNM = javacomponent(javax.swing.JSpinner,[50,40,80,30],hFig);
jJSpinnerNM.StateChangedCallback = @(hObject,eventdata)onSpinnerValueChanged(hObject,eventdata);
% Create a spinner (w/ model):
spModel = javax.swing.SpinnerListModel({'item1','item2','item3'});
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SpinnerModel.html
jJSpinnerM = javacomponent(javax.swing.JSpinner(spModel),[50,80,80,30],hFig);
jJSpinnerM.StateChangedCallback = @(hObject,eventdata)onSpinnerValueChanged(hObject,eventdata);
%% Get available methods & fields, and set some properties:
M = methods(jJSpinnerM);
F = fields(jJSpinnerM); % fields often contain the allowable settings for methods.
% Set some arbitrary property:
jJSpinnerNM.getEditor.getTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SwingConstants.html
jJSpinnerM.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
% Crazier demo: http://www.mathworks.com/matlabcentral/fileexchange/26970-spinnerdemo
end
function onSpinnerValueChanged(hObject, eventdata)
disp(['Spinner value is now: ' num2str(hObject.Value)]);
end
from mlapp2classdef.
Whoa, I didn't know that, very interesting! When I get some time this week I'll poke around and test out some changes. Haven't looked at this in a while...
from mlapp2classdef.
Before you modify stuff, note that the @Dev-iL's fork is 11 commits ahead, so you might want to merge his fixes first before proceeding. I'm just mentioning it since both of you did these changes 2 years ago and probably forgot about it...
from mlapp2classdef.
Related Issues (8)
- Regex removes characters following all end statements HOT 1
- No Cell Array Preallocation
- XML Parsing Assumes Static Location & Name HOT 2
- Linux and Mac Line Counting Implementation Potentially Insecure HOT 2
- Converted GUIs may still require R2016a HOT 3
- Builtin `type` can be used for .mlapp -> .m conversion on new MATLAB HOT 6
- Maybe I'm missing something? Conversion issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mlapp2classdef.