source: MML/trunk/applications/common/makeurl.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.2 KB
Line 
1function makeurl(h,url,varargin)
2%MAKEURL Make a URL from a uicontrol of style text.
3%   MAKEURL(h,url) adjusts the properties of the text style UICONTROL
4%   object to make it act like a typical URL hyperlink.  The hyperlink's
5%   target is given by the string url.
6%
7%   MAKEURL(...,'ForeGroundColor',C1,'ClickedColor',C2) will set the
8%   unclicked text color to C1 and the clicked text color to C2 where
9%   C1 and C2 are valid colorspecs.  The default values are C1 = 'b'
10%   and C2 = 'm'.
11%   
12%   Ex.
13%
14%      h = uicontrol('style','text','string','MathWorks');
15%      makeurl(h,'http://www.mathworks.com');
16
17% Jordan Rosenthal, jr@ll.mit.edu
18% Initial Version, 08-Dec-1999
19%            Rev., 18-Dec-2001 Added -browser switch and changed email contact.
20
21%----------------------------------------------------------------------------
22% Default Parameters
23%----------------------------------------------------------------------------
24FOREGROUNDCOLOR = 'b';
25CLICKEDCOLOR    = 'm';
26
27%----------------------------------------------------------------------------
28% Parse Inputs
29%----------------------------------------------------------------------------
30if nargin < 2, error('Not enough input arguments.'); end
31if ~strcmp(get(h,'style'),'text'), error('The UICONTROL h must be of style text.'); end
32if exist('varargin','var')
33   L = length(varargin);
34   if rem(L,2) ~= 0, error('Parameters/Values must come in pairs.'); end
35   for i = 1:2:L
36      switch lower(varargin{i}(1))
37      case 'f', FOREGROUNDCOLOR = varargin{i+1};
38      case 'c',    CLICKEDCOLOR = varargin{i+1};
39      end
40   end
41end
42%---  Add quotes around the color if given as a character  ---%
43if ischar(CLICKEDCOLOR), CLICKEDCOLOR = ['''' CLICKEDCOLOR '''']; end
44
45%----------------------------------------------------------------------------
46% Swicth units and get the pertinent parameters
47%----------------------------------------------------------------------------
48OldUnits = get(h,'Units'); set(h,'Units','pixels');
49Ext   = get(h,'Extent');
50Pos   = get(h,'Pos');
51Horiz = get(h,'HorizontalAlignment');
52
53%----------------------------------------------------------------------------
54% Add an underline by creating a 1 pixel high frame
55%----------------------------------------------------------------------------
56Bottom = Pos(2) + Pos(4) - Ext(4) + 2;
57Width  = Ext(3);
58Height = 1;
59switch lower(Horiz)
60case 'left'
61   Left = Pos(1);
62case 'center'
63   Left = Pos(1) + Pos(3)/2 - Ext(3)/2;
64case 'right'
65   Left = Pos(1) + Pos(3) - Ext(3);
66end
67fPos = [Left Bottom Width Height];
68hFrame = uicontrol('style','Frame','pos',fPos,'ForegroundColor',FOREGROUNDCOLOR);
69setappdata(h,'hFrame',hFrame);
70
71%----------------------------------------------------------------------------
72% Setup callback
73%----------------------------------------------------------------------------
74ButtonDownFcn =  ...
75   ['set([gcbo getappdata(gcbo,''hFrame'')],''ForeGroundColor'', ' CLICKEDCOLOR ');'];
76ButtonDownFcn = [ ButtonDownFcn 'web(''' url ''',''-browser'');' ];
77
78%----------------------------------------------------------------------------
79% Adjust the properties and restore units
80%----------------------------------------------------------------------------
81set(h,'ForegroundColor',FOREGROUNDCOLOR, ...
82   'ButtonDownFcn',ButtonDownFcn,'Enable','Inactive','Units',OldUnits);
Note: See TracBrowser for help on using the repository browser.