www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetnode/creategui.m

    function [lyt,tblyt,d]= creategui(nd,info)
%CREATEGUI Create a view layout for the node
%
%  [lyt,tblyt,data]= creategui(nd,info);

%  Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc.


d = [];
d.standalone = 1;
d.nd = nd;
[lyt,tblyt,d] = i_Base(info,d);
d = ToolsMenu(d);
d = GuiUtilities(nd,'create',d);

ViewFunctions = {@factors,@data,@plot,@FillTable};
for i=1:length(ViewFunctions)
    [d,newview] = ViewFunctions{i}(d.nd,'createpage',d);
    d = i_AddView(d,newview);
end

% Now for the dialog views
DlgFunctions = {@DrawDlg,@ImportDlg,@Inputs,@LinkDlg,@AssignDlg};
for i=1:length(DlgFunctions)
    [d,newview] = DlgFunctions{i}(d.nd,'createpage',d);
    d = i_AddView(d,newview);
end

% And a different bottom view 
% ... and another one for the table filling view !!
d = i_TableFillView(d);
d = pr_ChangeView(d,'factors','setup');
d.Handles.ViewToolbar.setRedraw(true);
d.Handles.ViewToolbar.drawToolBar;

% Toggle on redrawing for this layout packgroup
setBoolPackstatus(lyt,true);
return

function [lyt,tblyt,d] = i_Base(info,d)

% Create menus
cgb=info.browserH;
menus=cgb.createmenu(guid(d.nd),2);
set(menus,{'Label'},{'&View';'&Data'});


Handles.Figure = info.Figure;
Handles.ViewParent = info.ViewParent;
parent = Handles.ViewParent;
d.ViewMenu = menus(1);
d.ToolsMenu = menus(2);

% ------- layout

set(d.ViewMenu,'Callback',@cb_SetupViewMenu);
set(d.ToolsMenu,'Callback',@cb_SetupToolsMenu);

% views toolbar
Handles.ViewToolbar = cgb.createToolbar();
Handles.ViewToolbar.setRedraw(false);
Handles.ViewToggle = [];
Handles.ViewMenuItems = [];
d.ViewInfo = [];

Handles.TopCard = xregcardlayout(parent, ...
    'packstatus', 'off', ...
    'numcards',1,...
    'visible','off', ...
    'currentcard', 1);

Handles.BottomCard = xregcardlayout(parent, ...
    'numcards',4,...
    'visible','off', ...
    'currentcard', 1);

% message window for failures...
Handles.Message = uicontrol('Parent', parent,...
    'Style','text',...
    'FontWeight','bold',...
    'FontSize',10,...
    'Enable','inactive',...
    'Visible','off');
messagelyt = xreggridlayout(parent,'correctalg','on',...
    'visible','off',...
    'dimension',[2 1],...
    'elements',{[] Handles.Message});
d.Handles = Handles;
% -------- message window
newview.ID = 'message';
newview.layout = messagelyt;
d = i_AddView(d,newview);
% Start in the blank view
set(Handles.TopCard,'currentcard',get(Handles.TopCard,'numcards'));

Handles = d.Handles;

%Get the main ImageList control

d.ILmanager = get(cgbrowser,'ILmanager');

mfile = 'cgdatasetnodecb';
callbacks = {'rightclick',mfile;...
    'columnclick',mfile;...
    'click',mfile;...
    'keyup',mfile;...
    'dblclick',mfile;...
    'MouseMove','MotionManager'};
d.CB.actx = callbacks;

Handles.TopTB.Toolbar = Handles.ViewToolbar;

Handles.FactorList = cgDatasetList(parent, 'top');
attach(Handles.TopCard, Handles.FactorList.Layout, 1);

% bottom expression list
Handles.ExprList = cgDatasetList(parent, 'bottom');
attach(Handles.BottomCard, Handles.ExprList.Layout, 1);
Handles.BottomTB.Toolbar = [];




Handles.SplitLayout=xregsplitlayout(parent,'visible','off',...
    'split',[0.65 0.35],...
    'orientation','ud',...
    'top',Handles.TopCard,...
    'bottom',Handles.BottomCard,...
    'minwidth',[30 30],...
    'dividerstyle','flat',...
    'dividerwidth',4);

lyt = Handles.SplitLayout;

% put copy menus here
Handles.Copy = [];
Handles.Paste = [];
Handles.CurDatasetView = 1;
Handles.DlgButton = [];
d.Handles = Handles;

d.CB.View = [];
d.currentviewinfo = 1;
d.CheckUnits = 0;


tblyt = Handles.ViewToolbar;



%------------------------------------------------------------------
function d = i_TableFillView(d)
%------------------------------------------------------------------

% Imagey List Manager
d.ILmanager = get(cgbrowser,'ILmanager');

% Callbacks for lists
mfile = 'cgdatasetnodecb';
callbacks = {'rightclick',mfile;...
        'columnclick',mfile;...
        'click',mfile;...
        'keyup',mfile;...
        'dblclick',mfile;...
        'MouseMove','MotionManager'};

[d, TFBtmLyt] = FillTable(d.nd, 'create', d,  d.ILmanager, callbacks);

attach(d.Handles.BottomCard, TFBtmLyt, 4);

%-----------------------------------------------------------------------
function d = i_AddView(d,newview)
%-----------------------------------------------------------------------
viewdata = struct('ID','',...
    'label','',...
    'icon',[],...
    'tooltip','',...
    'cdata',[],...
    'card',[],...
    'view',[],...
    'show',[],...
    'copy',[],...
    'paste',[],...
    'layout',[],...
    'dialog',0,...
    'enablestatus',[],...
    'button',[],...
    'menuitem',[],...
    'drawcb',[],...
    'tplist',0,...
    'tpmenu',[],...
    'tpcolclick',[],...
    'tpclick',[],...
    'tpdblclick',[],...
    'tpselection',[],...
    'showindex',[],...
    'bmlist',0,...
    'bmmenu',[],...
    'bmclick',[],...
    'bmdblclick',[],...
    'drawn',0,...
    'tlenable',[], ...
    'bmcolclick', []);
% copy relevant data into structure
fn = fieldnames(newview);
for i = 1:length(fn)
    viewdata.(fn{i}) = newview.(fn{i});
end

if ~isempty(viewdata.icon)
    cdata = cgresload(viewdata.icon,'bmp');
elseif ~isempty(viewdata.cdata)
    cdata = viewdata.cdata;
else 
    cdata = [];
end

% label non-empty -> create menu item
if ~isempty(viewdata.label)
    if viewdata.dialog
        hnd = d.ToolsMenu;
    else
        hnd = d.ViewMenu;
    end
    mm = uimenu(hnd,'Label',viewdata.label,...
        'Callback',{@cb_ChangeView,viewdata.ID});
    viewdata.menuitem = mm;
    d.Handles.ViewMenuItems = [d.Handles.ViewMenuItems mm];
end

% icon | cdata non-empty -> create toolbar button
if ~isempty(cdata)
    t = xregGui.uitoggletool(d.Handles.ViewToolbar,...
        'CData',cdata,...
        'TooltipString',viewdata.tooltip,...
        'ClickedCallback', {@cb_ChangeView,viewdata.ID},...
        'transparentcolor',[0 255 0]);
    d.Handles.ViewToggle = [d.Handles.ViewToggle t];
    viewdata.button = length(d.Handles.ViewToggle);
    if viewdata.dialog && isempty(d.Handles.DlgButton)
        d.Handles.DlgButton = 1;
        set(t,'Separator','on');
    end
end

% layout non-empty -> create new card
if ~isempty(viewdata.layout)
    num = get(d.Handles.TopCard,'numcards');
    set(d.Handles.TopCard,'numcards',num+1);
    if isempty(viewdata.card)
        viewdata.card = num+1;
    else
        error('mbc:cgdatasetnode:InvalidState', 'card already set');
    end 
    if ~isnumeric(viewdata.layout)
        attach(d.Handles.TopCard, viewdata.layout, viewdata.card);
    end
elseif ischar(viewdata.card)
    f = find( strcmp( viewdata.card,{ d.ViewInfo.ID } ) );
    if length(f)==1
        % Do this later - check that the card is drawn first.
        %viewdata.card = d.ViewInfo(f).card;
    else
        viewdata.card = [];
    end
end
if isempty(viewdata.card) && ~viewdata.dialog
    error(message('mbc:cgdatasetnode:InvalidState1'));
end
d.ViewInfo = [d.ViewInfo viewdata];

%------------------------------------------------------------------
function d = ToolsMenu(d)
%------------------------------------------------------------------
mm = uimenu(d.ToolsMenu , 'Label' , '&Import');
uimenu(mm , 'Label' , 'Import from &Table...' , ...
   'Callback' , @i_ImportTable);
uimenu(mm , 'Label' , '&Merge Data Sets...' , ...
   'Callback' , @i_AppendDataSet);

%------------------------------------------------------------------
function i_ImportTable(varargin)
%------------------------------------------------------------------
d=pr_GetViewData;

if ~d.pD.isempty
    but = questdlg({'Current data set is not empty.',...
        'Fill from table, overwrite or cancel?'},...
        'Data Set Viewer','Fill','Overwrite','Cancel','Fill');
    switch but
        case 'Fill'
            opt = 'fill_existing';
        case 'Overwrite'
            opt = 'create_new';
        otherwise
            return
    end
else
    opt = 'create_new';
end

%do import table gui
PR=xregGui.PointerRepository;
ID=PR.stackSetPointer(d.Handles.Figure, 'watch');
h = ImportTable(d.nd,'create',d.Handles.Figure,opt,d.pD.info);
uiwait(h);
[ok,oppoint] = ImportTable(d.nd,'return_data');
ImportTable(d.nd,'close');
PR.stackRemovePointer(d.Handles.Figure, ID);

if ok
    % fill/overwrite are done within importtable
    d.pD.info = oppoint;
    
    % Refresh view
    d.Exprs.recalc = [0 1 1 0];
    d.CGBH.doDrawTree(address(d.nd));
    pr_SetViewData(d);
    ViewNode(d.CGBH);
end

%-----------------------------------------------------------------------
function i_AppendDataSet(~, ~)
%-----------------------------------------------------------------------

% Get view data
d = pr_GetViewData;

% Launch a GUI to select a source data set to merge into the current data
% set
c = cgbrowser;
pPROJ = c.RootNode;
titleStr = 'Merge Data Sets';
descStr = 'Select a data set to merge:';
[fH, dsList] = cgProjectItemSelector(pPROJ, cgtypes.cgdatasettype, ...
    titleStr, descStr, 'CGMERGEDATASET');
done = false;
while ~done
    % GUI blocks here
    fH.showDialog();
    tg = get(fH, 'Tag');
    if strcmp(tg, 'ok')
        % OK pressed
        dsNode = dsList.selectedItems;
        if isempty(dsNode)
            DOAPPEND = false;
        else
            DOAPPEND = true;
            pOpSource = getdata(dsNode.info);
            opSource = pOpSource.info;
        end
    else
        % Cancel pressed
        DOAPPEND = false;
    end
    done = true;
end

if DOAPPEND
    % Perform the appending
    [d.pD.info, dataAppended, warnMsg] = append(d.pD.info, opSource);
    if dataAppended
        % Refresh view
        d.Exprs.recalc = [0 1 1 0];
        d.CGBH.doDrawTree(address(d.nd));
        pr_SetViewData(d);
        ViewNode(d.CGBH);
    else
        % Inform the user that no data has been appended
        uiwait(warndlg(warnMsg, titleStr, 'modal'));
    end
end

%-----------------------------------------------------------------------
function cb_ChangeView(varargin)
%-----------------------------------------------------------------------
% Callback from toolbar button
% arguments: d , cardID, top buttons, bottom buttons
% set up view
if nargin==1
    ID = varargin{1};
else
    ID = varargin{3};
end
d = pr_GetViewData;
d = pr_ChangeView(d,ID);
pr_SetViewData(d);

%-----------------------------------------------------------------------
function cb_SetupViewMenu(varargin)
%-----------------------------------------------------------------------
% Set check mark beside current view
d = pr_GetViewData;
page = d.ViewInfo(d.currentviewinfo);
set(d.Handles.ViewMenuItems,'Checked','off');
if ~isempty(page.menuitem)
    set(page.menuitem,'Checked','on');
end

%-----------------------------------------------------------------------
function cb_SetupToolsMenu(varargin)
%-----------------------------------------------------------------------
% Call appropriate menu setup routine
d = pr_GetViewData;
page = d.ViewInfo(d.currentviewinfo);

% Tools menu enable
set(d.Handles.tm.h,'Enable','off');

set(d.Handles.tm.NotLinkBits,'Enable','on');
set(d.Handles.tm.LinkBits,'Enable','off');
set(page.tlenable,'Enable','on');
    
% 25/ix/01 - Get plot menu enabled 
ind = d.Handles.ExprList.Selected;
if ~isempty(ind) && d.currentviewinfo==4
    set(d.Handles.tm.Plot, 'Enable', 'on');
    % 25/ix/01 - Disable Plot -> swap axes for any situation except
    % an existing single plot
    if length(get(d.Handles.DataDisplay, 'UserData'))==1 && d.currentviewinfo==4
        % Can swap axes on the current plot
        set(d.Handles.plm.SwapAxes, 'Enable', 'on');    
    else
        set(d.Handles.plm.SwapAxes, 'Enable', 'off');    
    end
end