source: trunk/src/msgbox_uvmat.m @ 386

Last change on this file since 386 was 296, checked in by sommeria, 13 years ago

various

File size: 8.6 KB
Line 
1%'msgbox_uvmat': associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
2% msgbox_uvmat(title,display)
3%
4% OUTPUT:
5% answer  (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
6%
7%INPUT:
8% title: string indicating the type of message box:
9%          title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N', default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
10%          if title='INPUT_TXT', input data is asked in an edit box
11%          if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains  opened until a button 'OK' is pressed
12%          if title='INPUT_Y-N', an answer Yes/No is requested
13% display, displayed text
14% default_answer: default answer in the edit box (only used with title='INPUT_TXT')
15
16function varargout = msgbox_uvmat(varargin)
17
18% Last Modified by GUIDE v2.5 24-Oct-2009 21:55:17
19
20% Begin initialization code - DO NOT EDIT
21gui_Singleton = 1;
22gui_State = struct('gui_Name',       mfilename, ...
23                   'gui_Singleton',  gui_Singleton, ...
24                   'gui_OpeningFcn', @msgbox_uvmat_OpeningFcn, ...
25                   'gui_OutputFcn',  @msgbox_uvmat_OutputFcn, ...
26                   'gui_LayoutFcn',  [] , ...
27                   'gui_Callback',   []);
28if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
29    gui_State.gui_Callback = str2func(varargin{1});%for running msgbox_uvmat from a Callback
30end
31
32if nargout
33    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
34else
35    gui_mainfcn(gui_State, varargin{:});
36end
37% End initialization code - DO NOT EDIT
38
39% --- Executes just before msgbox_uvmat is made visible.
40function msgbox_uvmat_OpeningFcn(hObject, eventdata, handles,title,display,default_answer,Position)
41% This function has no output args, see OutputFcn.
42
43% Choose default command line output for msgbox_uvmat
44handles.output = 'Cancel';
45set(handles.figure1,'Units','pixels')
46FigPos=[100 150 500 50];%default position
47if exist('Position','var')
48    FigPos(1)=Position(1);
49    FigPos(2)=Position(2)-FigPos(4);% upper left corner set by input Position
50    set(handles.figure1,'Position',FigPos)
51end
52set(handles.OK,'Units','pixels')
53set(handles.OK,'Position',[100 2 60 30])
54set(handles.OK,'FontSize',15)
55set(handles.No,'Units','pixels')
56set(handles.No,'Position',[200 2 60 30])
57set(handles.No,'FontSize',15)
58set(handles.Cancel,'Units','pixels')
59set(handles.Cancel,'Position',[300 2 60 30])
60set(handles.Cancel,'FontSize',15)
61
62
63% Update handles structure
64guidata(hObject, handles);
65testNo=0;
66testCancel=0;
67testinputstring=0;
68icontype='quest';%default question icon (text input asked)
69if exist('title','var')
70    set(hObject, 'Name', title);
71    switch title
72        case {'CONFIRMATION'}
73            icontype='';
74        case 'ERROR'
75            icontype='error';
76        case 'WARNING'
77            icontype='warn';
78        case 'INPUT_Y-N'
79            icontype='quest';
80            testCancel=1; %no cancel button
81            testNo=1; % button No activated
82        case {'RULER'}
83            icontype='';
84            testinputstring=1;
85        case 'INPUT_TXT'
86            testinputstring=1;
87            testCancel=1; %no cancel button
88        otherwise
89          %  testinputstring=1;
90            icontype='';
91            testinputstring=exist('default_answer','var');
92    end
93end
94if exist('display','var')
95    set(handles.text1, 'String', display);
96end
97% if testinputstring
98%     set(handles.edit_box, 'Visible', 'on');
99% else
100%     set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
101% end
102if testinputstring
103    % set(handles.figure1,'Position',[40,80,20*length(default_answer),50])
104    set(handles.edit_box, 'Visible', 'on');
105    if ~exist('default_answer','var');
106        default_answer='';
107    end
108    set(handles.edit_box, 'String', default_answer);
109    if exist('Position','var')
110    if iscell(default_answer)
111        widthstring=max(cellfun('length',default_answer));
112        heightstring=size(default_answer,1);
113        set(handles.edit_box,'Max',2);
114    else
115        widthstring=length(default_answer);
116        heightstring=1;
117    end
118    widthstring=max(widthstring,length(title));
119    boxsize=[10*widthstring 20*heightstring];%size of the display edit box
120    set(handles.edit_box,'Units','pixels')
121    set(handles.edit_box,'FontUnits','pixels')
122    set(handles.edit_box,'FontSize',12) 
123   set(handles.edit_box,'Position',[5,34,boxsize(1),boxsize(2)])
124   FigPos(3)=10+boxsize(1);
125   FigPos(4)=36+boxsize(2);
126   FigPos(2)=Position(2)-FigPos(4)-25;
127   set(handles.figure1,'Position',FigPos)
128    end
129%     set(handles.figure1,'Position',[40,40,20*length(default_answer),50])
130else
131    set(handles.text1, 'Position', [0.15 0.3 0.85 0.7]);
132end
133% Determine the position of the dialog - centered on the screen
134% FigPos=get(0,'DefaultFigurePosition');
135% OldUnits = get(hObject, 'Units');
136% set(hObject, 'Units', 'pixels');
137% OldPos = get(hObject,'Position');
138% FigWidth = OldPos(3);
139% FigHeight = OldPos(4);
140% ScreenUnits=get(0,'Units');
141% set(0,'Units','pixels');
142% ScreenSize=get(0,'ScreenSize');
143% set(0,'Units',ScreenUnits);
144%
145% FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
146% FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
147% FigPos(3:4)=[FigWidth FigHeight];
148% set(hObject, 'Position', FigPos);
149% set(hObject, 'Units', OldUnits);
150
151% Show a question icon from dialogicons.mat - variables questIconData and questIconMap
152if isequal(icontype,'')
153    hima=findobj(handles.axes1,'Type','image');
154    if ~isempty(hima)
155        delete(hima)
156    end
157else
158    load dialogicons.mat
159    eval(['IconData=' icontype 'IconData;'])
160    eval(['IconCMap=' icontype 'IconMap;'])
161    questIconMap(256,:) = get(handles.figure1, 'Color');
162    Img=image(IconData, 'Parent', handles.axes1);
163    set(handles.figure1, 'Colormap', IconCMap);
164    set(handles.axes1, ...
165        'Visible', 'off', ...
166        'YDir'   , 'reverse'       , ...
167        'XLim'   , get(Img,'XData'), ...
168        'YLim'   , get(Img,'YData')  ...
169        );
170end
171if testCancel
1