-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinOnTop.m
87 lines (68 loc) · 2.48 KB
/
WinOnTop.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
function WasOnTop = WinOnTop( FigureHandle, IsOnTop )
%WINONTOP allows to trigger figure's "Always On Top" state
% INPUT ARGUMENTS:
% * FigureHandle - Matlab's figure handle, scalar
% * IsOnTop - logical scalar or empty array
%
% USAGE:
% * WinOnTop( hfigure, bool );
% * WinOnTop( hfigure ); - equal to WinOnTop( hfigure,true);
% * WinOnTop(); - equal to WinOnTop( gcf, true);
% * WasOnTop = WinOnTop(...); - returns boolean value "if figure WAS on top"
% * IsOnTop = WinOnTop(hfigure,[]) - gets "if figure is on top" property
%
% LIMITATIONS:
% * java enabled
% * figure must be visible
% * figure's "WindowStyle" should be "normal"
%
%
% Written by Igor
%
% 16 June 2013 - Initial version
% 27 June 2013 - removed custom "ishandle_scalar" function call
%
%% Parse Inputs
if ~exist('FigureHandle','var');FigureHandle = gcf; end
assert(...
isscalar( FigureHandle ) && ishandle( FigureHandle ) && strcmp(get(FigureHandle,'Type'),'figure'),...
'WinOnTop:Bad_FigureHandle_input',...
'%s','Provided FigureHandle input is not a figure handle'...
);
assert(...
strcmp('on',get(FigureHandle,'Visible')),...
'WinOnTop:FigInisible',...
'%s','Figure Must be Visible'...
);
assert(...
strcmp('normal',get(FigureHandle,'WindowStyle')),...
'WinOnTop:FigWrongWindowStyle',...
'%s','WindowStyle Must be Normal'...
);
if ~exist('IsOnTop','var');IsOnTop=true;end
assert(...
islogical( IsOnTop ) && isscalar( IsOnTop) || isempty( IsOnTop ), ...
'WinOnTop:Bad_IsOnTop_input',...
'%s','Provided IsOnTop input is neither boolean, nor empty'...
);
%% Pre-checks
error(javachk('swing',mfilename)) % Swing components must be available.
%% Action
% Flush the Event Queue of Graphic Objects and Update the Figure Window.
drawnow expose
warnStruct=warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
jFrame = get(handle(FigureHandle),'JavaFrame');
warning(warnStruct.state,'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
drawnow
v=ver('Matlab');
if str2double(v.Version) >= 8.4
jFrame_fHGxClient = jFrame.fHG2Client;
else
jFrame_fHGxClient = jFrame.fHG1Client;
end
WasOnTop = jFrame_fHGxClient.getWindow.isAlwaysOnTop;
if ~isempty(IsOnTop)
jFrame_fHGxClient.getWindow.setAlwaysOnTop(IsOnTop);
end
end