function m_movetext(inp) % M_MOVETEXT changing text objects in figures (toolbox M_NAMEBOX) % % m_movetext(input); % % inp Optional input for special purposes % % Moves, rotates, resizes, deletes and changes appearance of current (text) % object, at the touch of a key. Call M_MOVETEXT once (for each figure), % choose any text-object with a mouseclick, and use controls on your % keyboard. NUM-LOCK needs to be on to use the NUM-PAD. % % Press key 'h' for help dialog box with all the functions listed. % % On an M_MAP, M_MOVETEXT can be used to adjust the appearance and position % of place-names and long/lat-labels, but M_MOVETEXT can be used in any % figure and on any text object. M_MOVETEXT is also an important tool in % adding, editing and saving new place-names for your maps. % % See also M_NAMES M_NEWNAME M_SAVENAME M_MAP M_NAMEBOX M_NAME_DEMO %Time-stamp: %File: global MAP_VAR_LIST CAS figure(gcf); if isempty(findstr('m_movetext',get(gcf,'KeyPressFcn'))) % if not set before, make this set(gcf,'KeyPressFcn','m_movetext'); % function the keypressfunction, %movehelp; % display help, return % AND EXIT end type=get(gco,'Type'); % Check the current object answer=get(gcf,'CurrentCharacter'); % CHECK THE INPUT KEY %if isempty(answer), answer='h'; end % no keypress in figure yet % CHECK THE CURRENT OBJECT: if ~isempty(findstr(type,'uicontrol')) % listbox is curr.obj. % if ~any(findstr(get(MAP_VAR_LIST.name.boxhandle,'enable'),'on')) % disp('was disabled') % set(MAP_VAR_LIST.name.boxhandle,'enable','on'); return % else % disp('was enabled') % set(MAP_VAR_LIST.name.boxhandle,'enable','off'); % end get(MAP_VAR_LIST.name.boxhandle,'Value'); h=MAP_VAR_LIST.name.handles_all(ans); set(gcf,'CurrentObject',h); %get(gco,'type'), get(gco,'string') % set(h,'Visible','on','color','r'); figure(gcf); return elseif answer=='n' | answer=='h'... % those choices don't need | answer=='l' | answer=='a'... % a text-object... | answer=='' elseif isempty(findstr(type,'text')) %errordlg('Current object is not a text-object!'); return % else error else h=gco; % the other keys need pos=get(h,'Position'); % text-object-info size=get(h,'Fontsize'); rot=get(h,'Rotation'); if ~isempty(findstr(get(h,'Units'),'data')) axis;xstep=(ans(2)-ans(1))/200;ystep=(ans(4)-ans(3))/200; else xstep=5;ystep=xstep; end thisname=getnamelist(gco); end switch answer % RESOLVE THE KEYPRESS: case 'e' ans=inputdlg('Name:','Edit name?',3,thisname,'on'); if isempty(char(ans)) if ~isempty(ans) errordlg('Empty input! Make invisible instead (use ''5'')!'); return; end else thisname=cellstr(ans{1})'; set(h,'string',thisname); end case 'h' movehelp; case 'n' m_newname; case 's' quest=[ 'Store "',char(thisname),... '" and it''s position in database?']; basefile = char(inputdlg(quest,'Save to file',1,... cellstr(MAP_VAR_LIST.name.base),'on')); if ~isempty(basefile) MAP_VAR_LIST.name.base=basefile; m_savename(h,basefile); end % button = questdlg(quest,'Save to file','Yes','No','No'); % if strcmp(button,'Yes'), m_savename(h); end case 'a' quest= 'Store all visible names on map and their positions in database?'; basefile = char(inputdlg(quest,'Save to file',1,... cellstr(MAP_VAR_LIST.name.base),'on')); if ~isempty(basefile) MAP_VAR_LIST.name.base=basefile; % set it to be the current basefile findobj('tag','m_name','visible','on'); % find visible m_names on map m_savename(ans,basefile); % save them end % button = questdlg(quest,'Save to file','Yes','No','No'); % if strcmp(button,'Yes'), m_savename(MAP_VAR_LIST.name.handles); end case 'w' string=char(get(h,'String')); set(h,'String',cellstr(wordcase(string))); case 'c' string=char(get(h,'String')); if isempty(CAS) | ~exist(CAS) CAS='lower'; set(h,'String',cellstr(lower(string))); else CAS=''; set(h,'String',cellstr(upper(string))); end case 'b' if findstr(get(h,'FontWeight'),'bold') set(h,'FontWeight','normal'); else set(h,'FontWeight','bold'); end case 'i' if findstr(get(h,'FontAngle'),'normal') set(h,'FontAngle','italic'); else set(h,'FontAngle','normal'); end case 'r' if get(h,'Color')==[1 0 0] % red set(h,'Color','k'); % -> black elseif get(h,'Color')==[0 0 0] % black set(gco,'color',[.9 .9 .9]) % -> 'white' else % anything else set(h,'Color','r'); % -> red end case 'l' if isempty(MAP_VAR_LIST.name.boxhandle), return; end if ~findstr(get(MAP_VAR_LIST.name.boxhandle,'enable'),'on'); % not on set(MAP_VAR_LIST.name.boxhandle,'enable','on'); elseif findstr(get(MAP_VAR_LIST.name.boxhandle,'Visible'),'on'); % on and visible set(MAP_VAR_LIST.name.boxhandle,'Visible','off'); else % on but invisible set(MAP_VAR_LIST.name.boxhandle,'Visible','on'); end case '+' size=size+1;set(h,'Fontsize',size); case '-' if size>1, size=size-1;set(h,'Fontsize',size); end case '4' pos(1)=pos(1)-xstep;set(h,'Position',pos); case '6' pos(1)=pos(1)+xstep;set(h,'Position',pos); case '2' pos(2)=pos(2)-ystep;set(h,'Position',pos); case '8' pos(2)=pos(2)+ystep;set(h,'Position',pos); case '7' pos(1)=pos(1)-xstep*10.5;set(h,'Position',pos); case '1' pos(1)=pos(1)+xstep*10.5;set(h,'Position',pos); case '3' pos(2)=pos(2)-ystep*10.5;set(h,'Position',pos); case '9' pos(2)=pos(2)+ystep*10.5;set(h,'Position',pos); case '/' rot=rot+5;set(h,'Rotation',rot); case '*' rot=rot-5;set(h,'Rotation',rot); case '0' rot=0; set(h,'Rotation',rot); case ',' quest=[ 'This will remove ',upper(char(thisname)),... ' from figure (5 can make it invisible but present). Continue?']; del = questdlg(quest,'Delete object','Yes','No','No'); if strcmp(del,'Yes'), delete(h); MAP_VAR_LIST.name.handles=... MAP_VAR_LIST.name.handles(find(MAP_VAR_LIST.name.handles~=h)); MAP_VAR_LIST.name.handles_all=... MAP_VAR_LIST.name.handles_all(find(MAP_VAR_LIST.name.handles_all~=h)); set(gcf,'currentobject',MAP_VAR_LIST.name.handles(1)); end case '5' if findstr(get(h,'Visible'),'on'); set(h,'Visible','off'); MAP_VAR_LIST.name.handles=... MAP_VAR_LIST.name.handles(find(MAP_VAR_LIST.name.handles~=h)); else set(h,'Visible','on'); MAP_VAR_LIST.name.handles=[MAP_VAR_LIST.name.handles;h]; end end % Alphabetize names and update uicontrol [ans,is]=sort(getnamelist(MAP_VAR_LIST.name.handles_all)); MAP_VAR_LIST.name.handles_all=MAP_VAR_LIST.name.handles_all(is); set(MAP_VAR_LIST.name.boxhandle,... 'string',getnamelist(MAP_VAR_LIST.name.handles_all)) set(MAP_VAR_LIST.name.boxhandle,... 'value',find(MAP_VAR_LIST.name.handles_all==gco)) %------------------------------------------------------------------ function list=getnamelist(h) % GETNAMELIST makes string from object's cellstring-array 'String' for i = 1:length(h) lis=''; str=get(h(i),'String'); for j=1:length(str) lis=strcat(lis,str(j),{' '}); end list(i,1)=cellstr(char(lis)); % strip away trailing spaces end %------------------------------------------------------------------ function movehelp() % help dialog for M_MOVETEXT global MAP_VAR_LIST % how on earth can I get this tabulated properly? % can't find the textbox handle to change the fontname to fixedwidth s={... 'NUM-PAD arrows - move text'; 'Home,End,PgUp,PgDn - move in larger steps'; '+ - increase font-size'; '- - decrease font-size'; '/ - rotate anticlockwise'; '* - rotate clockwise'; '0 - rotate to horizontal'; '5 - toggle object (in)visible'; % 'Del (,) - delete object alltogether(!)'; 'b - toggle bold'; 'i - toggle italic'; 'c - toggle case'; 'w - word case'; 'r - toggle colour (black-grey-red)'; 'l - toggle listbox-visible'; ' (should be off when printing)'; 'n - add new name'; 'e - edit name'; 's - save this name to mapname-base'; 'a - save all visible names on map'; 'h - help (this box)'}; %c1=str2mat(s(:,1)); %c2=str2mat(s(:,2)); %c1=s(:,1); %c2=s(:,2) %disp([c1,c2]); hbx=msgbox(s,'M_MOVETEXT-controls','none','replace'); %get(hbx,'position'); set(hbx,'position',[10 10 ans(3:4)]); %%set(hbx,'units','normalized'); %%get(hbx,'position'); set(hbx,'position',[.05 .5 ans(3:4)]); %get(hbx) %ax=get(hbx,'children') %axch=get(ax(1),'children') %childr=get(h,'children') %ax=get(childr(1)) %------------------------------------------------------------------- function text=wordcase(text); % WORDCASE captializes first letters of words % in a (cell)string. Trailing spaces are also removed. % % text=wordcase(text); % % See also UPPER DEBLANK cll=0; error(nargchk(1,1,nargin)); % INPUT-TEST if isnumeric(text), error('String input only'); end text=deblank(text); if isempty(text), return; end if iscell(text) cll=1; text=char(text); end text=lower(text); [M,N]=size(text); for i=1:M %if M>1 % caps=1; % text(:,caps)=upper(text(:,caps)) %else linje=deblank(text(i,:)); spc=[findstr(' ',linje) findstr('-',linje)]; caps=[0 spc]+1; text(i,caps)=upper(linje(caps)); end if cll, text=cellstr(text); end