-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFigureHandler.m
124 lines (98 loc) · 3.66 KB
/
FigureHandler.m
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
% Property Descriptions:
%
% ID (valid variable name)
% Identifier for saving and loading window positions. The default saves a single window position for all figure
% handlers of the same class. A unique ID distinguishes two figure handlers of the same class and saves their window
% positions separately.
% Copyright (c) 2012 Howard Hughes Medical Institute.
% All rights reserved.
% Use is subject to Janelia Farm Research Campus Software Copyright 1.1 license terms.
% http://license.janelia.org/license/jfrc_copyright_1_1.html
classdef FigureHandler < handle
properties (Constant, Abstract)
figureType
end
properties
protocolPlugin
figureHandle
id
end
events
FigureClosed
end
methods
function obj = FigureHandler(protocolPlugin, varargin)
ip = inputParser;
ip.addParamValue('ID', [], @(x)isvarname(x));
ip.parse(varargin{:});
obj = obj@handle();
obj.protocolPlugin = protocolPlugin;
obj.id = ip.Results.ID;
% Restore the previous window position.
if isempty(obj.id)
prefName = [class(obj) '_Position'];
else
prefName = [class(obj) '_' obj.id '_Position'];
end
if ispref('Symphony', prefName)
addlProps = {'Position', getpref('Symphony', prefName)};
else
addlProps = {};
end
obj.figureHandle = figure('Name', [obj.protocolPlugin.displayName ': ' obj.figureType], ...
'NumberTitle', 'off', ...
'Toolbar', 'none', ...
'CloseRequestFcn', @(source, event)closeRequestFcn(obj, source, event), ...
addlProps{:});
axes('Position', [0.1 0.1 0.85 0.85]);
end
function showFigure(obj)
figure(obj.figureHandle);
end
function a = axes(obj)
children = get(obj.figureHandle, 'Children');
a = [];
for i = 1:length(children)
child = children(i);
if strcmp(get(child, 'Type'), 'axes') && ~strcmp(get(child, 'Tag'), 'Colorbar') && ~strcmp(get(child, 'Tag'), 'legend')
a(end+1) = child; %#ok<AGROW>
end
end
end
function a = axesHandle(obj)
axesList = obj.axes();
if isempty(axesList)
a = [];
else
a = axesList(1);
end
end
function clearFigure(obj)
axes = obj.axes();
for i = 1:length(axes)
set(get(axes(i), 'Title'), 'String', '');
cla(axes(i));
end
end
function close(obj)
if ~isempty(obj.figureHandle)
close(obj.figureHandle);
end
end
function closeRequestFcn(obj, ~, ~)
% Remember the window position.
if isempty(obj.id)
prefName = [class(obj) '_Position'];
else
prefName = [class(obj) '_' obj.id '_Position'];
end
setpref('Symphony', prefName, get(obj.figureHandle, 'Position'));
delete(obj.figureHandle);
obj.figureHandle = [];
notify(obj, 'FigureClosed');
end
end
methods (Abstract)
handleCurrentEpoch(obj);
end
end