classdef uitank < hgsetget
%UITANK Create graphics user interface object for a fluid container.
% Example for creating custom UI-Objects using MATLAB OOP class system.
% This example code shows how to create an own UI-Object which allows
% almost the same workflow (SET/GET) as the usual MATLAB UI-Objects.
%
% UICONTROL(FIG,...) creates a user interface control in the
% specified figure.
%
% UITANK('PropertyName1',value1,'PropertyName2',value2,...)
% creates a user interface control in the current figure
% window and returns a object handle to it.
%
% UITANK properties can be set at object creation time using
% PropertyName/PropertyValue pair arguments to UICONTROL, or
% changed later using the SET command.
%
% Execute GET(H) to see a list of UICONTROL object properties and
% their current values. Execute SET(H) to see a list of UICONTROL
% object properties and legal property values.
%
% Property list:
% --------------
% type Class of graphics object (read only)
% style Type of uicontrol object (read only)
% parent Uicontrol object's parent
% children Vector of graphics object handles
% lim Y-Axis limits
% value Current value of uicontrol object
% tick Vector of data values locating Y-tick marks
% ticklabel a matrix of strings to use as labels for tick marks
% title Axes title
% position Position of UITANK-object
% grid Gridline mode.
% axislocation Location of Y-axis tick marks and labels.
% foregroundcolor Fluid color
% backgroundcolor Object Background color
% axescolor Object Color
% fontangle Character slant
% fontname Font family
% fontsize Font size
% fontunits Font size units
% fontweight Weight of text characters
%
% Example 1
% figure
% hTank = uitank
%
% Example 2
% figure
% hTank = uitank('position',[50 100 20 200], ...
% 'lim',[0 100], ...
% 'tick',[0:10:100])
% for c=1:100
% set(hTank,'value',c)
% pause(0.05)
% end
%
% Example 3
% figure
% hTank = uitank('position',[150 100 10 200], ...
% 'lim',[-10 50], ...
% 'tick',[-10 0 10 30 50], ...
% 'ticklabel',{'too cold' '0' 'cold' 'hot 30' 'really hot'})
% for c=0:0.02:4*pi
% set(hTank,'value',sin(c)*25+20)
% pause(0.01)
% end
%
% See also UICONTROL.
%
% Author: Elmar Tarajan (MCommander@gmx.de)
% Version: 1.0.01
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do not expect too much from this example. This is my first approach to create
% custom UI objects using the new MATLAB Object Oriented Programming.
% I'm sure there are many other implementation tricks possible!
%
% Please let me know if you have a suggestion, hint or if something is missing.
% My aim is to create a template class file for implementing custom UI
% graphic interfaces.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
properties
type = 'uigroup'
style = 'uitank'
parent
children
lim = [0 1]
value = 0
tick = 0:0.2:1
ticklabel= 0:0.2:1
units = 'pixel'
position = [40 30 15 150]
grid = 'on'
axislocation = 'left'
foregroundcolor = [1 0 0]
backgroundcolor = [0.8 0.7 0.7]
axescolor = [.3 .3 .3]
title
fontangle = get(0,'defaultAxesfontangle')
fontname = get(0,'defaultAxesfontname')
fontsize = get(0,'defaultAxesfontsize')
fontunits = get(0,'defaultAxesfontunits')
fontweight = get(0,'defaultAxesfontweight')
end
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CREATE
function obj = uitank(varargin)
%
obj.parent = gcf;
if nargin & ishandle(varargin{1})
obj.parent = varargin{1};
varargin = varargin(2:end);
end% if
%
% Create UI-Objekts with default settings
obj.children(1) = axes( ...
'parent', obj.parent, ...
'visible', 'off', ...
'handlevisibility', 'off', ...
'units', 'pixel', ...
'position', obj.position, ...
'layer', 'top', ...
'box', 'on', ...
'tickdir', 'out', ...
'xtick', [], ...
'xticklabel', [], ...
'xlim', [0 1], ...
'ytick', obj.tick, ...
'yticklabel', obj.ticklabel, ...
'ylim', obj.lim, ...
'ygrid', obj.grid, ...
'yaxislocation', obj.axislocation, ...
'LineWidth',1, ...
'color', obj.backgroundcolor);
%
obj.children(2) = line( ...
'parent', obj.children(1), ...
'visible', 'off', ...
'handlevisibility', 'off', ...
'Linewidth', obj.position(3), ...
'color', obj.foregroundcolor, ...
'XData', [0.5 0.5], ...
'YData', [0 obj.value]);
%
obj.children(3) = line( ...
'parent', obj.children(1), ...
'visible', 'off', ...
'handlevisibility', 'off', ...
'color', [.9 .9 .9], ...
'XData', [0.2 0.2], ...
'YData', [obj.lim], ...
'Linewidth', obj.position(3)/10);
%
% Overwrite default settings with user specified settings
set(obj,varargin{:});
%
% Make UI-Group visible
set(obj.children,'visible','on')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GET
function out = get(obj,prop)
if exist('prop','var')
tmp = fields(obj);
tmp = tmp(strcmpi(tmp,prop));
switch length(tmp)
case 0
fprintf(2,['??? Error using ==> get\n' ...
'There is no ''%s'' property in the '...
'''uitank'' class.\n\n'],prop)
case 1
out = obj.(prop);
end% switch
else
disp(obj);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SET
function set(obj,varargin)
proplist = fields(obj);
%
% ('PropertyName1',value1,'PropertyName2',value2,...)
for n = 1:2:length(varargin)
tmp1 = proplist(strcmpi(proplist,varargin{n}));
switch length(tmp1)
case 1
obj.(char(tmp1)) = varargin{n+1};
value = varargin{n+1};
switch char(tmp1)
case 'parent'
set(obj.children(1),'Parent',value)
%
case 'foregroundcolor'
set(obj.children(2),'color',value)
%
case 'backgroundcolor'
set(obj.children(1),'color',value)
%
case 'axescolor'
set(obj.children(1),'xcolor',value, ...
'ycolor',value)
%
case {'fontsize' 'fontname' 'fontangle' ...
'fontUnits' 'fontweight'}
set(obj.children(1),varargin{n},value)
%
case 'value'
set(obj.children(2),'YData',[0 value])
%
case 'units'
set(obj.children(1),'units',value)
obj.position = get(obj.children(1),'position');
%
case 'position'
set(obj.children(1),'position',value)
pos = getpixelposition(obj.children(1));
set(obj.children(2),'linewidth',pos(3))
set(obj.children(3),'linewidth',pos(3)/10)
%
case 'lim'
set(obj.children(1),'ylim',value, ...
'ytickmode','auto','YTickLabelMode','auto')
set(obj.children(3),'ydata',value)
%
case 'tick'
set(obj.children(1),'ytick',value, ...
'yticklabel',value)
%
case 'title'
set(get(obj.children(1),'Title'),'String',value)
%
case 'ticklabel'
set(obj.children(1),'yticklabel',value)
%
case 'grid'
set(obj.children(1),'ygrid',value)
%
case 'axislocation'
set(obj.children(1),'yaxislocation',value)
%
otherwise
fprintf(2,['??? Error using ==> set\n' ...
'Attempt to modify read-only root property:', ...
' ''%s''.\n\n'],varargin{n})
end
case 0
fprintf(2,['??? Error using ==> set\n' ...
'There is no ''%s'' property in the '...
'''uitank'' class.\n\n'],varargin{n})
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DISPLAY
function obj = display(obj)
disp(sprintf('\n%s =\n\n\t%s - Custom UIGROUP\n',inputname(1),obj.style))
disp('properties:')
disp(obj)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DELETE
function delete(obj)
if ishandle(obj.children(1))
delete(obj.children(1))
end
end
end
end