1 | classdef DecoratedPanel < handle |
---|
2 | %DecoratedPanel Abstract panel class that manages fonts and colors |
---|
3 | % |
---|
4 | % See also: uiextras.Panel |
---|
5 | % uiextras.BoxPanel |
---|
6 | % uiextras.TabPanel |
---|
7 | |
---|
8 | % Copyright 2009-2010 The MathWorks, Inc. |
---|
9 | % 1.1 |
---|
10 | % 2012/05/08 08:02:58 |
---|
11 | |
---|
12 | properties( SetObservable = true ) % should also have 'AbortSet' but this is only available on later releases |
---|
13 | FontAngle % Title font angle [normal|italic|oblique] |
---|
14 | FontName % Title font name |
---|
15 | FontSize % Title font size |
---|
16 | FontUnits % Title font units [inches|centimeters|normalized|points|pixels] |
---|
17 | FontWeight % Title font weight [light|normal|demi|bold] |
---|
18 | ForegroundColor % Title font color and/or color of 2-D border line |
---|
19 | HighlightColor % 3-D frame highlight color [r g b] |
---|
20 | ShadowColor % 3-D frame shadow color [r g b] |
---|
21 | end % public properties |
---|
22 | |
---|
23 | properties( Constant, GetAccess = private ) |
---|
24 | AllowedFontAngle = set( 0, 'DefaultUIPanelFontAngle' ) |
---|
25 | AllowedFontName = listfonts(0) |
---|
26 | AllowedFontUnits = set( 0, 'DefaultUIPanelFontUnits' ) |
---|
27 | AllowedFontWeight = set( 0, 'DefaultUIPanelFontWeight' ) |
---|
28 | end % private constant properties |
---|
29 | |
---|
30 | methods |
---|
31 | |
---|
32 | function obj = DecoratedPanel( varargin ) |
---|
33 | % Find the parent figure |
---|
34 | parent = uiextras.findArg( 'Parent', varargin{:} ); |
---|
35 | if isempty( parent ) |
---|
36 | parent = gcf(); |
---|
37 | elseif isa( parent, 'uiextras.Container' ) |
---|
38 | parent = double( parent ); |
---|
39 | end |
---|
40 | % Set some defaults |
---|
41 | obj.setPropertyFromDefaultOrHG( parent, 'FontAngle' ); |
---|
42 | obj.setPropertyFromDefaultOrHG( parent, 'FontName' ); |
---|
43 | obj.setPropertyFromDefaultOrHG( parent, 'FontSize' ); |
---|
44 | obj.setPropertyFromDefaultOrHG( parent, 'FontUnits' ); |
---|
45 | obj.setPropertyFromDefaultOrHG( parent, 'FontWeight' ); |
---|
46 | obj.setPropertyFromDefaultOrHG( parent, 'ForegroundColor' ); |
---|
47 | obj.setPropertyFromDefaultOrHG( parent, 'HighlightColor' ); |
---|
48 | obj.setPropertyFromDefaultOrHG( parent, 'ShadowColor' ); |
---|
49 | end % DecoratedPanel |
---|
50 | |
---|
51 | end % public methods |
---|
52 | |
---|
53 | methods |
---|
54 | |
---|
55 | function set.FontAngle( obj, value ) |
---|
56 | idx = find( strcmpi( value, obj.AllowedFontAngle ) ); |
---|
57 | if isempty( idx ) |
---|
58 | list = sprintf( '%s, ', obj.AllowedFontAngle{:} ); |
---|
59 | list(end-1:end) = []; |
---|
60 | error( 'GUILayout:InvalidPropertyValue', ... |
---|
61 | 'Property ''FontAngle'' must be one of: %s.', list ); |
---|
62 | else |
---|
63 | obj.FontAngle = obj.AllowedFontAngle{idx}; |
---|
64 | eventData = struct( ... |
---|
65 | 'Property', 'FontAngle', ... |
---|
66 | 'Value', obj.FontAngle ); |
---|
67 | obj.onPanelFontChanged( obj, eventData ); |
---|
68 | end |
---|
69 | end % set.FontAngle |
---|
70 | |
---|
71 | function set.FontName( obj, value ) |
---|
72 | idx = find( strcmpi( value, obj.AllowedFontName ) ); |
---|
73 | if isempty( idx ) |
---|
74 | error( 'GUILayout:InvalidPropertyValue', ... |
---|
75 | 'Property ''FontName'' must be a valid font name. See also ''listfonts''.' ); |
---|
76 | else |
---|
77 | obj.FontName = obj.AllowedFontName{idx}; |
---|
78 | eventData = struct( ... |
---|
79 | 'Property', 'FontName', ... |
---|
80 | 'Value', obj.FontName ); |
---|
81 | obj.onPanelFontChanged( obj, eventData ); |
---|
82 | end |
---|
83 | end % set.FontName |
---|
84 | |
---|
85 | function set.FontSize( obj, value ) |
---|
86 | obj.FontSize = value; |
---|
87 | eventData = struct( ... |
---|
88 | 'Property', 'FontSize', ... |
---|
89 | 'Value', value ); |
---|
90 | obj.onPanelFontChanged( obj, eventData ); |
---|
91 | end % set.FontSize |
---|
92 | |
---|
93 | function set.FontUnits( obj, value ) |
---|
94 | idx = find( strcmpi( value, obj.AllowedFontUnits ) ); |
---|
95 | if isempty( idx ) |
---|
96 | list = sprintf( '%s, ', obj.AllowedFontUnits{:} ); |
---|
97 | list(end-1:end) = []; |
---|
98 | error( 'GUILayout:InvalidPropertyValue', ... |
---|
99 | 'Property ''FontUnits'' must be one of: %s.', list ); |
---|
100 | else |
---|
101 | obj.FontUnits = obj.AllowedFontUnits{idx}; |
---|
102 | eventData = struct( ... |
---|
103 | 'Property', 'FontUnits', ... |
---|
104 | 'Value', obj.FontUnits ); |
---|
105 | obj.onPanelFontChanged( obj, eventData ); |
---|
106 | end |
---|
107 | end % set.FontUnits |
---|
108 | |
---|
109 | function set.FontWeight( obj, value ) |
---|
110 | idx = find( strcmpi( value, obj.AllowedFontWeight ) ); |
---|
111 | if isempty( idx ) |
---|
112 | list = sprintf( '%s, ', obj.AllowedFontWeight{:} ); |
---|
113 | list(end-1:end) = []; |
---|
114 | error( 'GUILayout:InvalidPropertyValue', ... |
---|
115 | 'Property ''FontWeight'' must be one of: %s.', list ); |
---|
116 | else |
---|
117 | obj.FontWeight = obj.AllowedFontWeight{idx}; |
---|
118 | eventData = struct( ... |
---|
119 | 'Property', 'FontWeight', ... |
---|
120 | 'Value', obj.FontWeight ); |
---|
121 | obj.onPanelFontChanged( obj, eventData ); |
---|
122 | end |
---|
123 | end % set.FontWeight |
---|
124 | |
---|
125 | function set.ForegroundColor( obj, value ) |
---|
126 | obj.ForegroundColor = uiextras.interpretColor( value ); |
---|
127 | eventData = struct( ... |
---|
128 | 'Property', 'ForegroundColor', ... |
---|
129 | 'Value', obj.ForegroundColor ); |
---|
130 | obj.onPanelColorChanged( obj, eventData ); |
---|
131 | end % set.ForegroundColor |
---|
132 | |
---|
133 | function set.HighlightColor( obj, value ) |
---|
134 | obj.HighlightColor = uiextras.interpretColor( value ); |
---|
135 | eventData = struct( ... |
---|
136 | 'Property', 'HighlightColor', ... |
---|
137 | 'Value', obj.HighlightColor ); |
---|
138 | obj.onPanelColorChanged( obj, eventData ); |
---|
139 | end % set.HighlightColor |
---|
140 | |
---|
141 | function set.ShadowColor( obj, value ) |
---|
142 | obj.ShadowColor = uiextras.interpretColor( value ); |
---|
143 | eventData = struct( ... |
---|
144 | 'Property', 'ShadowColor', ... |
---|
145 | 'Value', obj.ShadowColor ); |
---|
146 | obj.onPanelColorChanged( obj, eventData ); |
---|
147 | end % set.ShadowColor |
---|
148 | |
---|
149 | end % accessor methods |
---|
150 | |
---|
151 | methods ( Abstract = true, Access = protected ) |
---|
152 | onPanelColorChanged( obj, source, eventData ); |
---|
153 | onPanelFontChanged( obj, source, eventData ); |
---|
154 | end % abstract protected methods |
---|
155 | |
---|
156 | methods ( Access = private ) |
---|
157 | |
---|
158 | function setPropertyFromDefaultOrHG( obj, parent, propName ) |
---|
159 | %setPropertyDefault Retrieve a default property value. If the |
---|
160 | %value is not found in the parent or any of its ancestors the |
---|
161 | %default UIPanel equivalent in 'parent' is used |
---|
162 | error( nargchk( 3, 3, nargin ) ); |
---|
163 | |
---|
164 | myClass = class( obj ); |
---|
165 | if strncmp( myClass, 'uiextras.', 9 ) |
---|
166 | myClass = myClass(10:end); |
---|
167 | end |
---|
168 | defPropName = ['Default',myClass,propName]; |
---|
169 | try |
---|
170 | obj.(propName) = uiextras.get( parent, defPropName ); |
---|
171 | catch err %#ok<NASGU> |
---|
172 | % Go up the HG tree instead |
---|
173 | hgPropName = ['DefaultUIPanel',propName]; |
---|
174 | % We can't test for default properties, so just try it |
---|
175 | try |
---|
176 | obj.(propName) = get( parent, hgPropName ); |
---|
177 | catch err %#ok<NASGU> |
---|
178 | found = false; |
---|
179 | while ~found && ~isequal( parent, 0 ) |
---|
180 | parent = get( parent, 'Parent' ); |
---|
181 | try %#ok<TRYNC> |
---|
182 | obj.(propName) = get( parent, hgPropName ); |
---|
183 | found = true; |
---|
184 | end |
---|
185 | end |
---|
186 | end |
---|
187 | end |
---|
188 | end % setPropertyFromDefaultOrHG |
---|
189 | |
---|
190 | end % private methods |
---|
191 | |
---|
192 | end % classdef |
---|