comparison m-toolbox/m/gui/gltpda/pan4import.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function pan4import(varargin)
2
3 % ========================================================================
4 % =============== Panel to import data from the workspace ================
5 % ========================================================================
6 %
7 % $Id: pan4import.m,v 1.8 2008/08/30 12:27:08 nicola Exp $
8
9 global LTPDAinvar
10
11 ImportObjList='';
12 UpdateListbox();
13
14 currPanel = varargin{1};
15 panelDimens = get(currPanel, 'Position');
16 backColor = get(currPanel, 'BackgroundColor');
17
18 DataPanPos = [20 panelDimens(4)-470 panelDimens(3)-40 450];
19 hDataPanel = uipanel(...
20 'Title','Data currently in the workspace',...
21 'BackgroundColor',[1,1,1],...
22 'FontSize',7,...
23 'Units','pixels',...
24 'Position',DataPanPos);
25
26 nbuttons = 3;
27 buttonWidth = (DataPanPos(3)-10*(nbuttons+1))/nbuttons;
28 buttonPos = [10 DataPanPos(4)-45 buttonWidth 25];
29 hPlotButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Plot','FontSize',8,'Visible','on','Callback','','Style','pushbutton','enable','off');
30 buttonPos(1) = buttonPos(1)+buttonWidth+10;
31 hRefreshButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Refresh','FontSize',8,'Visible','on','Callback',@UpdateListbox,'Style','pushbutton','enable','on');
32 buttonPos(1) = buttonPos(1)+buttonWidth+10;
33 hImportButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Import','FontSize',8,'Visible','on','Callback',@ImportCallback,'Style','pushbutton','enable','on');
34 % buttonPos(1) = buttonPos(1)+buttonWidth+10;
35 % hExploreButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Explore','FontSize',8,'Visible','on','UserData',ImportObjList,'Callback',@hExploreButtonCallback,'Style','pushbutton','enable','off');
36 % buttonPos(1) = buttonPos(1)+buttonWidth+10;
37 % hSaveOutButton = uicontrol('Parent',hDataPanel,'Units','pixels','HorizontalAlignment','center','Position',buttonPos,'String','Save','FontSize',8,'Visible','on','Enable','off','Callback',@SaveOutputCallback,'Style','pushbutton');
38 % clear nbuttons buttonWidth buttonPos
39
40
41 textWidth = (DataPanPos(3)-10*(3))/2;
42 textPos = [10 DataPanPos(4)-80 textWidth 25];
43 uicontrol('Parent',hDataPanel,'BackgroundColor',get(hDataPanel,'BackgroundColor'),'HorizontalAlignment','center','Position',textPos,'String','Objects:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
44 clear textWidth textPos
45
46 nlists = 2;
47 listWidth = (DataPanPos(3)-10*(nlists+1))/nlists;
48 listPos = [10 DataPanPos(4)-315 listWidth 240];
49 ImportObjList = uicontrol('Parent',hDataPanel,'BackgroundColor',[0.95,0.95,0.95],'HorizontalAlignment','center','Position',listPos,'String',listInput,'Value',[],'Max',10,'Min',0,'FontSize',8,'FontWeight','normal','Visible','on','Enable','on','Tag','ImportObjList','Callback',@hImportListCallback,'Style','listbox');
50 listPos(1) = listPos(1)+listWidth+10;
51 % Info panel:
52 uicontrol('Parent',hDataPanel,'BackgroundColor',[0.94,0.94,1],'Style','text','HorizontalAlignment', 'left','Fontsize', 7,'Units','pixels','Position',listPos,'Tag','infoPanel');
53 hImportListCallback(ImportObjList,1)
54 clear DataPanPos nlists listWidth listPos
55
56
57 %%
58 %----------------------------------------------------------------------
59 function UpdateListbox(varargin)
60 % Updates the listbox of objects in the current workspace
61
62 listInput = evalin('base','who');
63
64 for i=numel(listInput):-1:1
65 obj = evalin('base',listInput{i});
66 if ~isa(obj,'ltpda_uo') || isa(obj,'cell'), listInput(i)=[]; end
67 end
68
69 if isempty(listInput)
70 listInput = 'No LTPDA objects currently in the MATLAB workspace';
71 set(findobj('Tag', 'ImportObjList'),'Enable', 'off','Value',[],'String',listInput)
72 else
73 set(findobj('Tag', 'ImportObjList'),'Enable', 'on','Value',[],'String',listInput)
74 end
75
76 end
77 %----------------------------------------------------------------------
78
79 %%
80 %----------------------------------------------------------------------
81 function hImportListCallback(hObject, varargin)
82 % This callback is called whenever the user click upon one of the
83 % objects in the workspace
84
85 if ~isempty(varargin{1}) && varargin{1}==1 && ~isa(listInput,'char')
86 % This is a call only to update the info panel
87 val = get(hObject, 'Value');
88 if length(val) == 1
89 objLines = get(hObject, 'String');
90 if isempty(objLines)
91 objtxt = '';
92 else
93 objname = objLines{val};
94 obj = evalin('base',objname);
95 objtxt = display(obj);
96 end
97 else
98 objtxt = '';
99 end
100 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
101 elseif ~isa(listInput,'char')
102 if strcmp(get(gcf,'SelectionType'),'normal')
103 val = get(hObject, 'Value');
104 if length(val) == 1
105 objLines = get(hObject, 'String');
106 objname = objLines{val};
107 obj = evalin('base',objname);
108 objtxt = display(obj);
109 else
110 objtxt = '';
111 end
112 set(findobj('Tag', 'infoPanel'), 'String', objtxt)
113 end
114 if strcmp(get(gcf,'SelectionType'),'open') && ~isempty(get(hObject, 'String'))
115 val = get(hObject, 'Value');
116 objLines = get(hObject, 'String');
117 objname = objLines{val};
118 obj = evalin('base',objname);
119 try %#ok<ALIGN>
120 figure
121 plot(obj);
122 catch
123 close(gcf)
124 end
125 end
126 end
127
128 end
129 %----------------------------------------------------------------------
130
131 %----------------------------------------------------------------------
132 function ImportCallback(varargin)
133 % This callback is called whenever the user click the 'Import' button
134
135 objList = findobj('Tag', 'ImportObjList');
136 val = get(objList, 'Value');
137 objLines = get(objList, 'String');
138 for i = 1:numel(val)
139 objname = objLines{val(i)};
140 obj = evalin('base',objname);
141 nobj = numel(obj);
142 if nobj>1
143 for jj=1:nobj
144 objj = {obj(jj) , 0};
145 LTPDAinvar = [LTPDAinvar;objj];
146 end
147 else
148 obj = {obj , 0};
149 LTPDAinvar = [LTPDAinvar;obj];
150 end
151 end
152 set(findobj('Tag', 'ImportObjList'),'Value',[])
153
154 end
155 %----------------------------------------------------------------------
156
157 %%
158 end