Download this file

346 lines (242 with data), 10.9 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
classdef ( Hidden ) Divider < matlab.mixin.SetGet
%uix.Divider Draggable divider
%
% d = uix.Divider() creates a divider.
%
% d = uix.Divider(p1,v1,p2,v2,...) creates a divider and sets
% specified property p1 to value v1, etc.
% Copyright 2009-2016 The MathWorks, Inc.
% $Revision: 1601 $ $Date: 2018-05-01 10:22:53 +0100 (Tue, 01 May 2018) $
properties( Dependent )
Parent % parent
Units % units [inches|centimeters|characters|normalized|points|pixels]
Position % position
Visible % visible [on|off]
BackgroundColor % background color [RGB]
HighlightColor % border highlight color [RGB]
ShadowColor % border shadow color [RGB]
Orientation % orientation [vertical|horizontal]
Markings % markings [pixels]
end
properties( Access = private )
Control % uicontrol
BackgroundColor_ = get( 0, 'DefaultUicontrolBackgroundColor' ) % backing for BackgroundColor
HighlightColor_ = [1 1 1] % backing for HighlightColor
ShadowColor_ = [0.7 0.7 0.7] % backing for ShadowColor
Orientation_ = 'vertical' % backing for Orientation
Markings_ = zeros( [0 1] ) % backing for Markings
SizeChangedListener % listener
end
methods
function obj = Divider( varargin )
%uix.Divider Draggable divider
%
% d = uix.Divider() creates a divider.
%
% d = uix.Divider(p1,v1,p2,v2,...) creates a dividerand sets
% specified property p1 to value v1, etc.
% Create control
control = matlab.ui.control.UIControl( ...
'Style', 'checkbox', 'Internal', true, ...
'Enable', 'inactive', 'DeleteFcn', @obj.onDeleted,...
'Tag', 'uix.Divider' );
% Store control
obj.Control = control;
% Set properties
try
uix.set( obj, varargin{:} )
catch e
delete( obj )
e.throwAsCaller()
end
% Force update
obj.update()
% Create listener
sizeChangedListener = event.listener( control, 'SizeChanged', ...
@obj.onSizeChanged );
% Store listener
obj.SizeChangedListener = sizeChangedListener;
end % constructor
function delete( obj )
%delete Destructor
control = obj.Control;
if isgraphics( control ) && strcmp( control.BeingDeleted, 'off' )
delete( control )
end
end % destructor
end % structors
methods
function value = get.Parent( obj )
value = obj.Control.Parent;
end % get.Parent
function set.Parent( obj, value )
obj.Control.Parent = value;
end % set.Parent
function value = get.Units( obj )
value = obj.Control.Units;
end % get.Units
function set.Units( obj, value )
obj.Control.Units = value;
end % set.Units
function value = get.Position( obj )
value = obj.Control.Position;
end % get.Position
function set.Position( obj, value )
obj.Control.Position = value;
end % set.Position
function value = get.Visible( obj )
value = obj.Control.Visible;
end % get.Visible
function set.Visible( obj, value )
obj.Control.Visible = value;
end % set.Visible
function value = get.BackgroundColor( obj )
value = obj.BackgroundColor_;
end % get.BackgroundColor
function set.BackgroundColor( obj, value )
% Check
assert( isa( value, 'double' ) && ...
isequal( size( value ), [1 3] ) && ...
all( value >= 0 ) && all( value <= 1 ), ...
'uix:InvalidArgument', ...
'Property ''BackgroundColor'' must be a valid colorspec.' )
% Set
obj.BackgroundColor_ = value;
% Update
obj.update()
end % set.BackgroundColor
function value = get.HighlightColor( obj )
value = obj.HighlightColor_;
end % get.HighlightColor
function set.HighlightColor( obj, value )
% Check
assert( isnumeric( value ) && isequal( size( value ), [1 3] ) && ...
all( isreal( value ) ) && all( value >= 0 ) && all( value <= 1 ), ...
'uix:InvalidPropertyValue', ...
'Property ''HighlightColor'' must be an RGB triple.' )
% Set
obj.HighlightColor_ = value;
% Update
obj.update()
end % set.HighlightColor
function value = get.ShadowColor( obj )
value = obj.ShadowColor_;
end % get.ShadowColor
function set.ShadowColor( obj, value )
% Check
assert( isnumeric( value ) && isequal( size( value ), [1 3] ) && ...
all( isreal( value ) ) && all( value >= 0 ) && all( value <= 1 ), ...
'uix:InvalidPropertyValue', ...
'Property ''ShadowColor'' must be an RGB triple.' )
% Set
obj.ShadowColor_ = value;
% Update
obj.update()
end % set.ShadowColor
function value = get.Orientation( obj )
value = obj.Orientation_;
end % get.Orientation
function set.Orientation( obj, value )
% Check
assert( ischar( value ) && ismember( value, ...
{'horizontal','vertical'} ) )
% Set
obj.Orientation_ = value;
% Update
obj.update()
end % set.Orientation
function value = get.Markings( obj )
value = obj.Markings_;
end % get.Markings
function set.Markings( obj, value )
% Check
assert( isa( value, 'double' ) && ndims( value ) == 2 && ...
size( value, 2 ) == 1 && all( isreal( value ) ) && ...
all( ~isinf( value ) ) && all( ~isnan( value ) ) && ...
all( value > 0 ), 'uix:InvalidPropertyValue', ...
'Property ''Markings'' must be a vector of positive values.' ) %#ok<ISMAT>
% Set
obj.Markings_ = value;
% Update
obj.update()
end % set.Markings
end % accessors
methods
function tf = isMouseOver( obj, eventData )
%isMouseOver Test for mouse over
%
% tf = d.isMouseOver(wmd) tests whether the WindowMouseData
% wmd is consistent with the mouse pointer being over the
% divider d.
%
% This method returns false for dividers that are being
% deleted.
tf = isvalid( obj ); % initialize
for ii = 1:numel( obj )
tf(ii) = tf(ii) && obj(ii).Control == eventData.HitObject;
end
end % isMouseOver
end % methods
methods( Access = private )
function onDeleted( obj, ~, ~ )
%onDeleted Event handler
% Call destructor
obj.delete()
end % onDeleted
function onSizeChanged( obj, ~, ~ )
%onSizeChanged Event handler
% Update
obj.update()
end % onSizeChanged
end % event handlers
methods( Access = private )
function update( obj )
%update Update divider
%
% d.update() updates the divider markings.
% Get properties
control = obj.Control;
position = control.Position;
backgroundColor = obj.BackgroundColor;
highlightColor = obj.HighlightColor;
shadowColor = obj.ShadowColor;
orientation = obj.Orientation;
markings = obj.Markings;
% Assemble mask
mask = zeros( floor( position([4 3]) ) - [1 1] ); % initialize
switch orientation
case 'vertical'
markings(markings < 4) = [];
markings(markings > position(4)-6) = [];
for ii = 1:numel( markings )
marking = markings(ii);
mask(floor( marking ) + [-3 0 3],1:end-1) = 1;
mask(floor( marking ) + [-2 1 4],1:end-1) = 2;
end
case 'horizontal'
markings(markings < 4) = [];
markings(markings > position(3)-6) = [];
for ii = 1:numel( markings )
marking = markings(ii);
mask(2:end,floor( marking ) + [-3 0 3]) = 1;
mask(2:end,floor( marking ) + [-2 1 4]) = 2;
end
end
% Assemble color data
cData1 = repmat( backgroundColor(1), size( mask ) );
cData1(mask==1) = highlightColor(1);
cData1(mask==2) = shadowColor(1);
cData2 = repmat( backgroundColor(2), size( mask ) );
cData2(mask==1) = highlightColor(2);
cData2(mask==2) = shadowColor(2);
cData3 = repmat( backgroundColor(3), size( mask ) );
cData3(mask==1) = highlightColor(3);
cData3(mask==2) = shadowColor(3);
cData = cat( 3, cData1, cData2, cData3 );
% Set properties
control.ForegroundColor = backgroundColor;
control.BackgroundColor = backgroundColor;
control.CData = cData;
end % update
end % methods
end % classdef