forked from BiomedNMR/arrShow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asInfoTextClass.m
166 lines (124 loc) · 5.34 KB
/
asInfoTextClass.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
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
% Copyright (C) 2009-2013 Biomedizinische NMR Forschungs GmbH
% http://www.biomednmr.mpg.de
% Author: Tilman Johannes Sumpf <[email protected]>
%
% Distributed under the Boost Software License, Version 1.0.
% (See accompanying file LICENSE_1_0.txt or copy at
% http://www.boost.org/LICENSE_1_0.txt)
classdef asInfoTextClass < handle
properties (GetAccess = private, SetAccess = private)
ph = 0; % panel handle
cmh = 0; % context menu handle
lwfh = 0; % large window figure handle
lwph = 0; % large window panel handle
text = '';
end
methods
function obj = asInfoTextClass(parentPanelHandle, panelPosition)
obj.ph = uicontrol('Style','edit',...
'Parent',parentPanelHandle,...
'Units','normalized',...
'Position',panelPosition,...
'Max',2,...
'HorizontalAlignment','left',...
'Visible','off',...
'callback',@(src,evnt)copyInfoTextCb(obj,src),...
'Tag','asInfoClassPanel');
function copyInfoTextCb(obj,src)
obj.text = get(src,'String');
set(obj.ph,'String',obj.text);
if ishandle(obj.lwfh)
if obj.lwfh ~= 0
set(obj.lwph,'String',obj.text);
end
end
end
obj.cmh = uicontextmenu;
uimenu(obj.cmh,'Label','open large window' ,...
'callback',@(src,evnt)obj.openLargeWindow);
uimenu(obj.cmh,'Label','close large window' ,...
'callback',@(src,evnt)obj.closeLargeWindow);
set(obj.ph,'uicontextmenu',obj.cmh);
end
function setInfotext(obj, infoText)
% infoText can be either a string or a struct
if isstruct(infoText) || isobject(infoText)
infoText = asInfoTextClass.parseStruct(infoText);
end
obj.setString(infoText);
end
function addInfotext(obj, newText)
if isstruct(newText) || isobject(newText)
newText = asInfoTextClass.parseStruct(newText);
end
obj.setString( [obj.getString; newText]);
end
function setString(obj, str)
obj.text = str;
set(obj.ph,'String',obj.text);
end
function str = getString(obj)
str = obj.text;
end
function setVisible(obj, OnOffStr)
set(obj.ph,'Visible',OnOffStr);
end
function OnOffStr = getVisible(obj)
OnOffStr = get(obj.ph,'Visible');
end
function openLargeWindow(obj)
parentFigureHandle = get(get(obj.ph,'Parent'),'Parent');
parentFigureTitle = get(parentFigureHandle,'name');
if verLessThan('matlab','8.4.0')
lwTitle = sprintf('asO %d: infoText (%s)',parentFigureHandle,parentFigureTitle);
else
lwTitle = sprintf('asO %d: infoText (%s)',parentFigureHandle.Number,parentFigureTitle);
end
obj.lwfh = figure( 'MenuBar','none',...
'ToolBar','none',...
'NumberTitle','off',...
'Name',lwTitle);
obj.lwph = uicontrol('Style','edit',...
'Parent',obj.lwfh,...
'Units','normalized',...
'Position',[0,0,1,1],...
'Max',2,...
'HorizontalAlignment','left',...
'Visible','on',...
'String', obj.text,...
'callback',@(src,evnt)copyInfoTextCb(obj,src));
function copyInfoTextCb(obj,src)
obj.text = get(src,'String');
set(obj.ph,'String',obj.text);
end
end
function closeLargeWindow(obj)
if ishandle(obj.lwfh)
if obj.lwfh ~= 0
delete(obj.lwfh);
end
end
end
end
methods (Access = private)
function lwCloseRequest(obj) %large window close request
% ...doesn't work yet
figure(get(parentPanelHandle,'Parent'));
obj.setString(get(obj.lwph,'String'));
delete(obj.lwfh);
end
end % (end private methods)
methods(Static)
function txt = parseStruct(struct)
if isstruct(struct) || isobject(struct)
names = evalc('disp(struct)');
names = strread(names,'%s','delimiter','\n');
txt = [ {'-- struct: --'};...
names;...
{'-end struct-'}];
else
error('first argument has to be a struct');
end
end
end % (end static methods)
end