www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+project/InfoPane.m
classdef InfoPane < mbcgui.multiview.View %InfoPane panel containing recent files and examples. properties (Constant) %Examples list of examples to be displayed Examples = struct('FileName',{'gasolineOneStage.cag','CI_MultiInject.cag','Gasoline_optimization.cag'},... 'Description',{'Dual CAM gasoline engine with spark optimized during testing','Multi-injection diesel tested with pilot injection on and off','Dual CAM gasoline engine with spark'},... 'Type',{'One-stage','Point-by-point','Two-Stage'},... 'Icon',{'gloreg.bmp','modelSwitch.bmp','mle2.bmp'}); end properties (SetAccess=private) RecentList RecentFiles ExamplesList OpenRecentButton OldLocations Title end methods function obj = InfoPane(varargin) obj@mbcgui.multiview.View(varargin{:}) create(obj); end function t = gettitle(obj) t = 'Project Manager'; end function update(obj) AP = mbcprefs('mbc'); cgbprefs = getpref(AP,'cgbrowser'); LastOpened = cgbprefs.FileList; lbls = cell(1,length(LastOpened)); files = lbls; for i=1:length(LastOpened) [lbls{i},files{i}] = displayFileName(LastOpened(i)); end set(obj.OpenRecentButton,'Enable',mbconoff(~isempty(LastOpened))) set(obj.RecentList,'String',lbls); obj.RecentFiles = files; end function create(obj) %create create layout col = [ 0.8706 0.9216 0.9804]; backGround = mbcgui.container.layoutpanel('Parent',obj.Parent, ... 'LayoutBorder',[10 0 10 3],... 'BorderType','etchedin',... 'BackgroundColor', col); obj.Title = uicontrol('Parent',backGround,... 'Style','text',... 'HorizontalAlignment','left',... 'FontSize',10,... 'BackgroundColor',col,... 'FontWeight','bold',... 'String','Projects'); div1 = xregGui.dividerline('Parent',backGround); div2 = xregGui.dividerline('Parent',backGround); newButton =mbcWorkflowItem('Parent',backGround,... 'Label','New Project',... 'IconFile',xregrespath('fileNew.bmp'),... 'Callback',@obj.onNewProject,... 'TransparentColor', [0 255 0]); openButton =mbcWorkflowItem('Parent',backGround,... 'Label','Open Project',... 'Callback',@obj.onOpenProject,... 'IconFile',xregrespath('fileOpen.bmp'),... 'TransparentColor', [0 255 0]); t = uicontrol('Parent',backGround,...; 'Style','text',... 'HorizontalAlignment','left',... 'BackgroundColor',col,... 'FontSize',10,... 'String','Recent projects:'); obj.RecentList = uicontrol('Parent',backGround,... 'Callback',@obj.onOpenRecent,... 'Style','list'); obj.OpenRecentButton = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'Callback',@obj.onOpenRecentButton,... 'String','Open Recent Project'); obj.ExamplesList = mbcwidgets.List('Parent',backGround,... 'IconLocation',xregrespath,... 'ColumnWidths',250,... 'ActionPerformedCallback',@obj.onOpenExample); obj.ExamplesList.setData( {obj.Examples.Description}', {obj.Examples.Icon}'); obj.ExamplesList.ColumnHeaders = {'Examples'}; obj.ExamplesList.SelectedRows = 1; hOpenExample = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'Callback',@obj.onOpenExampleButton,... 'String','Open Example'); hHelp = uicontrol('Parent',backGround,... 'Style','pushbutton',... 'HorizontalAlignment','left',... 'String','Help'); lyt = xreggridbaglayout(backGround,... 'dimension',[12 2],... 'gapy',5,... 'gapx',10,... 'ColSizes',[-1 -1],... 'rowsizes',[18 3 25 25 3 18 120 25 2 120 25 -1],... 'elements',{obj.Title,[] div1,[] newButton,[] openButton,[] [] [] t [] obj.RecentList [] [] obj.OpenRecentButton div2 [] obj.ExamplesList [] hHelp hOpenExample [] []},... 'MergeBlock',{[1 1],[1 2]},... 'MergeBlock',{[2 2],[1 2]},... 'MergeBlock',{[3 3],[1 2]},... 'MergeBlock',{[4 4],[1 2]},... 'MergeBlock',{[7 7],[1 2]},... 'MergeBlock',{[9 9],[1 2]},... 'MergeBlock',{[10 10],[1 2]}); backGround.LayoutComponent = lyt; obj.ContentHandle = backGround; addMessageServiceListener(obj, 'NodeChanged',@obj.onNodeChanged) end function onNodeChanged(obj,~,~) %onNodeChanged update recent files on load update(obj) end function onNewProject(obj,~,~) newproject(cgbrowser); end function onOpenProject(obj,~,~) %#ok<INUSD> %onBrowse browse for a new project openproject(cgbrowser); end function onOpenRecent(obj,~,~) %onOpenRecent open recent file by double clicking on list fig = ancestor(obj.Parent,'figure'); if strcmp(fig.SelectionType,'open') openRecent(obj) end end function onOpenRecentButton(obj,~,~) %onOpenRecentButton open recent file by double clicking on button openRecent(obj) end function openRecent(obj) %onOpenRecent open recent file file = obj.RecentFiles{obj.RecentList.Value}; openproject(cgbrowser,file); end function onOpenExample(obj,~,evt) %onOpenExample open example by double clicking on list row = evt.Data.SelectedRows; openExample(obj,row) end function onOpenExampleButton(obj,~,~) %onOpenExample open example by button row = obj.ExampleList.SelectedRows; openExample(obj,row) end function openExample(obj,row) if isscalar(row) ex = obj.Examples(row); file = fullfile(mbcpath,'mbctraining',ex.FileName); openproject(cgbrowser,file,false,false); end end end end function [lbl,file] = displayFileName(LastOpened) %displayFileName display name for recent file file=LastOpened.File; [~,f,e]=fileparts(LastOpened.File); if length(file)>35 % replace inner folder names with ... lbl=[file(1:3) '...',filesep,f,'.',e]; else lbl = file; end end