Download this file

546 lines (354 with data), 14.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
classdef ( Hidden ) Text < matlab.mixin.SetGet
%uix.Text Text control
%
% t = uix.Text(p1,v1,p2,v2,...) constructs a text control and sets
% parameter p1 to value v1, etc.
%
% A text control adds functionality to a uicontrol of Style text:
% * Set VerticalAlignment to 'top', 'middle' or 'bottom'
% * Fire a Callback when the user clicks on the text
%
% See also: uicontrol
% Copyright 2009-2015 The MathWorks, Inc.
% $Revision: 1574 $ $Date: 2017-11-07 11:42:03 +0000 (Tue, 07 Nov 2017) $
properties( Dependent )
BackgroundColor
end
properties( Dependent, SetAccess = private )
BeingDeleted
end
properties( Dependent )
Callback
DeleteFcn
Enable
end
properties( Dependent, SetAccess = private )
Extent
end
properties( Dependent )
FontAngle
FontName
FontSize
FontUnits
FontWeight
ForegroundColor
HandleVisibility
HorizontalAlignment
Parent
Position
String
Tag
TooltipString
end
properties( Dependent, SetAccess = private )
Type
end
properties( Dependent )
UIContextMenu
Units
UserData
VerticalAlignment
Visible
end
properties( Access = private )
Container % container
Checkbox % checkbox, used for label
Screen % text, used for covering checkbox
VerticalAlignment_ = 'top' % backing for VerticalAlignment
Dirty = false % flag
FigureObserver % observer
FigureListener % listener
end
properties( Constant, Access = private )
Margin = checkBoxLabelOffset() % checkbox size
end
methods
function obj = Text( varargin )
%uix.Text Text control
%
% t = uix.Text(p1,v1,p2,v2,...) constructs a text control and
% sets parameter p1 to value v1, etc.
% Create graphics
container = uicontainer( 'Parent', [], ...
'Units', get( 0, 'DefaultUicontrolUnits' ), ...
'Position', get( 0, 'DefaultUicontrolPosition' ), ...
'SizeChangedFcn', @obj.onResized );
checkbox = uicontrol( 'Parent', container, ...
'HandleVisibility', 'off', ...
'Style', 'checkbox', 'Units', 'pixels', ...
'HorizontalAlignment', 'center', ...
'Enable', 'inactive' );
screen = uicontrol( 'Parent', container, ...
'HandleVisibility', 'off', ...
'Style', 'text', 'Units', 'pixels' );
% Create observers and listeners
figureObserver = uix.FigureObserver( container );
figureListener = event.listener( figureObserver, ...
'FigureChanged', @obj.onFigureChanged );
% Store properties
obj.Container = container;
obj.Checkbox = checkbox;
obj.Screen = screen;
obj.FigureObserver = figureObserver;
obj.FigureListener = figureListener;
% Set properties
try
uix.set( obj, varargin{:} )
catch e
delete( obj )
e.throwAsCaller()
end
end % constructor
function delete( obj )
%delete Destructor
delete( obj.Container )
end % destructor
end % structors
methods
function value = get.BackgroundColor( obj )
value = obj.Checkbox.BackgroundColor;
end % get.BackgroundColor
function set.BackgroundColor( obj, value )
obj.Container.BackgroundColor = value;
obj.Checkbox.BackgroundColor = value;
obj.Screen.BackgroundColor = value;
end % set.BackgroundColor
function value = get.BeingDeleted( obj )
value = obj.Checkbox.BeingDeleted;
end % get.BeingDeleted
function value = get.Callback( obj )
value = obj.Checkbox.Callback;
end % get.Callback
function set.Callback( obj, value )
obj.Checkbox.Callback = value;
end % set.Callback
function value = get.DeleteFcn( obj )
value = obj.Checkbox.DeleteFcn;
end % get.DeleteFcn
function set.DeleteFcn( obj, value )
obj.Checkbox.DeleteFcn = value;
end % set.DeleteFcn
function value = get.Enable( obj )
value = obj.Checkbox.Enable;
end % get.Enable
function set.Enable( obj, value )
obj.Checkbox.Enable = value;
end % set.Enable
function value = get.Extent( obj )
value = obj.Checkbox.Extent;
end % get.Extent
function value = get.FontAngle( obj )
value = obj.Checkbox.FontAngle;
end % get.FontAngle
function set.FontAngle( obj, value )
% Set
obj.Checkbox.FontAngle = value;
% Mark as dirty
obj.setDirty()
end % set.FontAngle
function value = get.FontName( obj )
value = obj.Checkbox.FontName;
end % get.FontName
function set.FontName( obj, value )
% Set
obj.Checkbox.FontName = value;
% Mark as dirty
obj.setDirty()
end % set.FontName
function value = get.FontSize( obj )
value = obj.Checkbox.FontSize;
end % get.FontSize
function set.FontSize( obj, value )
% Set
obj.Checkbox.FontSize = value;
% Mark as dirty
obj.setDirty()
end % set.FontSize
function value = get.FontUnits( obj )
value = obj.Checkbox.FontUnits;
end % get.FontUnits
function set.FontUnits( obj, value )
obj.Checkbox.FontUnits = value;
end % set.FontUnits
function value = get.FontWeight( obj )
value = obj.Checkbox.FontWeight;
end % get.FontWeight
function set.FontWeight( obj, value )
% Set
obj.Checkbox.FontWeight = value;
% Mark as dirty
obj.setDirty()
end % set.FontWeight
function value = get.ForegroundColor( obj )
value = obj.Checkbox.ForegroundColor;
end % get.ForegroundColor
function set.ForegroundColor( obj, value )
obj.Checkbox.ForegroundColor = value;
end % set.ForegroundColor
function value = get.HandleVisibility( obj )
value = obj.Container.HandleVisibility;
end % get.HandleVisibility
function set.HandleVisibility( obj, value )
obj.Container.HandleVisibility = value;
end % set.HandleVisibility
function value = get.HorizontalAlignment( obj )
value = obj.Checkbox.HorizontalAlignment;
end % get.HorizontalAlignment
function set.HorizontalAlignment( obj, value )
% Set
obj.Checkbox.HorizontalAlignment = value;
% Mark as dirty
obj.setDirty()
end % set.HorizontalAlignment
function value = get.Parent( obj )
value = obj.Container.Parent;
end % get.Parent
function set.Parent( obj, value )
obj.Container.Parent = value;
end % set.Parent
function value = get.Position( obj )
value = obj.Container.Position;
end % get.Position
function set.Position( obj, value )
obj.Container.Position = value;
end % set.Position
function value = get.String( obj )
value = obj.Checkbox.String;
end % get.String
function set.String( obj, value )
% Set
obj.Checkbox.String = value;
% Mark as dirty
obj.setDirty()
end % set.String
function value = get.Tag( obj )
value = obj.Checkbox.Tag;
end % get.Tag
function set.Tag( obj, value )
obj.Checkbox.Tag = value;
end % set.Tag
function value = get.TooltipString( obj )
value = obj.Checkbox.TooltipString;
end % get.TooltipString
function set.TooltipString( obj, value )
obj.Checkbox.TooltipString = value;
end % set.TooltipString
function value = get.Type( obj )
value = obj.Checkbox.Type;
end % get.Type
function value = get.UIContextMenu( obj )
value = obj.Checkbox.UIContextMenu;
end % get.UIContextMenu
function set.UIContextMenu( obj, value )
obj.Checkbox.UIContextMenu = value;
end % set.UIContextMenu
function value = get.Units( obj )
value = obj.Container.Units;
end % get.Units
function set.Units( obj, value )
obj.Container.Units = value;
end % set.Units
function value = get.UserData( obj )
value = obj.Checkbox.UserData;
end % get.UserData
function set.UserData( obj, value )
obj.Checkbox.UserData = value;
end % set.UserData
function value = get.VerticalAlignment( obj )
value = obj.VerticalAlignment_;
end % get.VerticalAlignment
function set.VerticalAlignment( obj, value )
% Check
assert( ischar( value ) && ...
any( strcmp( value, {'top','middle','bottom'} ) ), ...
'uix:InvalidPropertyValue', ...
'Property ''VerticalAlignment'' must be ''top'', ''middle'' or ''bottom''.' )
% Set
obj.VerticalAlignment_ = value;
% Mark as dirty
obj.setDirty()
end % set.VerticalAlignment
function value = get.Visible( obj )
value = obj.Container.Visible;
end % get.Visible
function set.Visible( obj, value )
obj.Container.Visible = value;
end % set.Visible
end % accessors
methods( Access = private )
function onResized( obj, ~, ~ )
%onResized Event handler
% Rooted, so redraw
obj.redraw()
end % onResized
function onFigureChanged( obj, ~, eventData )
% If rooted, redraw
if isempty( eventData.OldFigure ) && ...
~isempty( eventData.NewFigure ) && obj.Dirty
obj.redraw()
end
end % onFigureChanged
end % event handlers
methods( Access = private )
function setDirty( obj )
%setDirty Mark as dirty
%
% t.setDirty() marks the text control t as dirty. If the text
% control is rooted then it is redrawn immediately. If not
% then the redraw is queued for when it is next rooted.
if isempty( obj.FigureObserver.Figure )
obj.Dirty = true; % set flag
else
obj.Dirty = false; % unset flag
obj.redraw() % redraw
end
end % setDirty
function redraw( obj )
%redraw Redraw
%
% t.redraw() redraws the text control t. Note that this
% requires the text control to be rooted. Methods should
% request redraws using setDirty, rather than calling redraw
% directly.
c = obj.Container;
b = obj.Checkbox;
s = obj.Screen;
bo = hgconvertunits( ancestor( obj, 'figure' ), ...
[0 0 1 1], 'normalized', 'pixels', c ); % bounds
m = obj.Margin;
e = b.Extent;
switch b.HorizontalAlignment
case 'left'
x = 1 - m;
case 'center'
x = 1 + bo(3)/2 - e(3)/2 - m;
case 'right'
x = 1 + bo(3) - e(3) - m;
end
w = e(3) + m;
switch obj.VerticalAlignment_
case 'top'
y = 1 + bo(4) - e(4);
case 'middle'
y = 1 + bo(4)/2 - e(4)/2;
case 'bottom'
y = 1;
end
h = e(4);
b.Position = [x y w h];
s.Position = [x y m h];
end % redraw
end % helpers
end % classdef
function o = checkBoxLabelOffset()
%checkBoxLabelOffset Horizontal offset to checkbox label
if ismac
o = 20;
else
if verLessThan( 'MATLAB', '8.6' ) % R2015b
o = 18;
else
o = 16;
end
end
end % margin