Home > m > mysql > logindlg.m

logindlg

PURPOSE ^

LOGINDLG presents the user with a username/password login dialog box.

SYNOPSIS ^

function [varargout]=logindlg(varargin)

DESCRIPTION ^

 LOGINDLG presents the user with a username/password login dialog box.
 
 CALL: [username, password] = logindlg()
 
 This is a modification of the logindlg function posted at
 
 http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8499&objectType=file
 
 Changed to use jcontrol and a java swing password text field
 (JPasswordField)
 
 Requires jcontrol to be installed:
 
 http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15580&objectType=file
 
 M Hewitson 02-03-08
 
 $Id: logindlg.m,v 1.7 2008/03/02 13:17:04 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [varargout]=logindlg(varargin)
0002 
0003 % LOGINDLG presents the user with a username/password login dialog box.
0004 %
0005 % CALL: [username, password] = logindlg()
0006 %
0007 % This is a modification of the logindlg function posted at
0008 %
0009 % http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8499&objectType=file
0010 %
0011 % Changed to use jcontrol and a java swing password text field
0012 % (JPasswordField)
0013 %
0014 % Requires jcontrol to be installed:
0015 %
0016 % http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15580&objectType=file
0017 %
0018 % M Hewitson 02-03-08
0019 %
0020 % $Id: logindlg.m,v 1.7 2008/03/02 13:17:04 hewitson Exp $
0021 %
0022 
0023 if nargin == 2
0024   Login    = varargin{1};
0025   password = varargin{2};
0026 else
0027   Login    = '';
0028   password = '';
0029 end
0030 
0031 % Get Properties
0032 Color = 'w'; %get(0,'DefaultUicontrolBackgroundcolor');
0033 
0034 set(0,'Units','normalized')
0035 Screen = get(0,'screensize');
0036 Position = [Screen(3)/2 Screen(4)/2 0.2 0.2];
0037 set(0,'Units','pixels')
0038 
0039 
0040 % Create the GUI
0041 gui.main = figure('HandleVisibility','on',...
0042   'IntegerHandle','off',...
0043   'Menubar','none',...
0044   'Name','LTPDA Repository Login',...
0045   'NumberTitle','off',...
0046   'Tag','logindlg',...
0047   'Color',Color,...
0048   'Units','normalized',...
0049   'Userdata','logindlg',...
0050   'Position',Position);
0051 
0052 set(gui.main,'Closerequestfcn',{@Cancel,gui.main},'Keypressfcn',{@Escape,gui.main})
0053 
0054 fsize = getappdata(0, 'ltpda_passwd_win_fontsize');
0055 
0056 % Texts
0057 gui.login_text = uicontrol(gui.main,'Style','text',...
0058   'FontSize',fsize,...
0059   'HorizontalAlign','center',...
0060   'Units','normalized',...
0061   'BackgroundColor','w',...
0062   'String','Login',...
0063   'Position',[0 .7 1 .2]);
0064 gui.password_text = uicontrol(gui.main,'Style','text',...
0065   'FontSize',fsize,...
0066   'HorizontalAlign','center',...
0067   'BackgroundColor','w',...
0068   'Units','normalized',...
0069   'String','Password',...
0070   'Position',[0 .35 1 .2]);
0071 
0072 % Edits
0073 gui.edit1 = uicontrol(gui.main,'Style','edit',...
0074   'FontSize',fsize,...
0075   'HorizontalAlign','left',...
0076   'BackgroundColor','w',...
0077   'Units','normalized',...
0078   'String',Login,...
0079   'Position',[0.05 .6 0.9 .15]);
0080 
0081 gui.edit2 = jcontrol(gui.main, 'javax.swing.JPasswordField',...
0082   'BackgroundColor','w',...
0083   'Units','normalized',...
0084   'Position',[0.05 0.3 0.9 0.15]);
0085 
0086 % Buttons
0087 gui.OK = uicontrol(gui.main,'Style','push',...
0088   'FontSize',fsize,...
0089   'Units','normalized',...
0090   'String','OK',...
0091   'Position',[0.1 0.05 0.3 0.2],...
0092   'Callback',{@OK,gui.main});
0093 
0094 gui.Cancel = uicontrol(gui.main,'Style','push',...
0095   'FontSize',fsize,...
0096   'Units','normalized',...
0097   'String','Cancel',...
0098   'Position',[0.6 0.05 0.3 0.2],...
0099   'Callback',{@Cancel,gui.main});
0100 
0101 setappdata(0,'logindlg',gui) % Save handle data
0102 setappdata(gui.main,'Check',0) % Error check setup. If Check remains 0 an empty cell array will be returned
0103 
0104 uicontrol(gui.edit1) % Make the first edit box active
0105 
0106 % Pause the GUI and wait for a button to be pressed
0107 uiwait(gui.main)
0108 
0109 Check = getappdata(gui.main,'Check'); % Check to see if a button was pressed
0110 
0111 % Format output
0112 if Check == 1
0113   Login = get(gui.edit1,'String');
0114   Password = get(get(gui.edit2, 'hgcontrol'), 'Text');
0115 
0116   varargout(1) = {Login};
0117   varargout(2) = {Password};
0118 else % If OK wasn't pressed output nothing
0119   varargout(1) = {[]};
0120   varargout(2) = {[]};
0121 end
0122 
0123 delete(gui.main) % Close the GUI
0124 setappdata(0,'logindlg',[]) % Erase handles from memory
0125 
0126 
0127 %% Cancel
0128   function Cancel(h,eventdata,fig)
0129     uiresume(fig)
0130   end
0131 
0132 %% OK
0133   function OK(h,eventdata,fig)
0134     % Set the check and resume
0135     setappdata(fig,'Check',1)
0136     uiresume(fig)
0137   end
0138 
0139 %% Escape
0140   function Escape(h,eventdata,fig)
0141     % Close the login if the escape button is pushed and neither edit box is
0142     % active
0143     key = get(fig,'currentkey');
0144 
0145     if isempty(strfind(key,'escape')) == 0 && h == fig
0146       Cancel([],[],fig)
0147     end
0148   end
0149 
0150 end

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003