www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@xregmonitorplotproperties/editPropertiesDlg.m

    function [obj,OK] = editPropertiesDlg(obj, index, data, hParent)
%EDITPROPERTIESLDG Open a dialog for editing the plot setup
%
%  OBJ = EDITPROPERTIESLDG(OBJ, INDEX, DATA, HPARENT)

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


[OK, newPlot] = i_create(obj.plots(index), data, hParent);
if OK
    obj.plots(index) = newPlot;
end

%--------------------------------------------------------------------------
function [OK, newPlot] = i_create(plot, data, hParent)

SC = xregGui.SystemColorsDbl;

dataNames = get(data, 'Name');

% Need to do initial setup
[~, selectedXIndex] = intersect(dataNames, plot.xName);
[~, selectedYIndex] = intersect(dataNames, plot.yNames);

% Remove the currently selected names from the list
dataNames([selectedXIndex; selectedYIndex]) = [];
if isgraphics(hParent)
    hParent = ancestor(hParent,'figure');
end
% Create the dialog
dlg = mbcgui.container.Dialog(...
    'Size',[420 450],...
    'Owner',hParent,...
    'Buttons','OK_CANCEL_HELP',...
    'HelpCode','xreg_monitorSetup',...
    'Name','Plot Variables Setup');
f = dlg.Figure;
%--------------------------------------------------------------------------
% Create the Controls
%--------------------------------------------------------------------------

% Labels
label(1) = mbcgui.widget.Label(...
    'Parent',f,...
    'String','Y variable(s):',...
    'HorizontalAlignment','left');
label(2) = mbcgui.widget.Label(...
    'Parent',f,...
    'String','X variable:',...
    'HorizontalAlignment','left');
label(3) = mbcgui.widget.Label(...
    'Parent',f,...
    'String','Available plot variables:',...
    'HorizontalAlignment','left');

removexButton = uicontrol(...
    'Parent',f,...
    'String','No X Data',...
    'Tag','NoXData',...
    'Callback',{@i_remove_x,f},...
    'Enable','off');
if ~isempty(plot.xName)
    set(removexButton,'Enable','on');
end

% X variable editbox
xvaredit = uicontrol(...
    'Parent',f,...
    'Style','edit',...
    'String',plot.xName,...
    'BackgroundColor',SC.WINDOW_BG,...
    'Enable','inactive',...
    'HorizontalAlignment','left');

% All variables list
allvariablesList = uicontrol(...
    'Parent',f,...
    'Style','list',...
    'Tag','AllVariables',...
    'String',dataNames,...
    'Min',0,'Max',2,...
    'BackgroundColor',SC.WINDOW_BG);

% Y variables list
yvariablesList = uicontrol(...
    'Parent',f,...
    'Tag','YVariables',...
    'Style','list',...
    'String',plot.yNames,...
    'Min',0,'Max',2,...
    'BackgroundColor',SC.WINDOW_BG);


% Selection buttons
yselectButton = uicontrol(...
    'Parent',f,...
    'String','Add >',...
    'Tag','addY',...
    'TooltipString','Add Y variable',...
    'Callback',{@i_add,f});
ydeselectButton = uicontrol(...
    'Parent',f,...
    'String','< Remove',...
    'Tag','removeY',...
    'TooltipString','Remove Y variable',...
    'Callback',{@i_remove,f});
xselectButton = uicontrol(...
    'Parent',f,...
    'String','Select >',...
    'Tag','XVariable',...
    'TooltipString','Select X variable',...
    'Callback',{@i_xdata,f});

div = xregGui.dividerline('parent', f);

%
% Set up userdata
%

ud.buttons.yselect = yselectButton;
ud.buttons.ydeselect = ydeselectButton;
ud.buttons.xselect = xselectButton;
ud.buttons.xremove = removexButton;
ud.lists.all = allvariablesList;
ud.lists.y = yvariablesList;
ud.lists.x = xvaredit;
ud.plot = plot;
ud.OK = false;

set(f,'UserData',ud);

%--------------------------------------------------------------------------
% Layouts
%--------------------------------------------------------------------------


yselectlyt = xreggridbaglayout(f, ...
    'packstatus', 'off', ...
    'dimension', [7 2], ...
    'rowsizes', [15 2 -1 25 10 25 -1], ...
    'colsizes', [65 -1], ...
    'gapx', 20, ...
    'mergeblock', {[3 7], [2 2]}, ...
    'elements', {[], [], [], yselectButton, [], ydeselectButton, [], ...
    label(1), [], yvariablesList});
xselectlyt = xreggridbaglayout(f, ...
    'dimension', [5 4], ...
    'rowsizes', [15 2 3 20 2], ...
    'colsizes', [65 0 -1  65], ...
    'gapx', 10, ...
    'mergeblock', {[1 1], [3 4]}, ...
    'mergeblock', {[3 5], [1 1]}, ...
    'mergeblock', {[3 5], [4 4]}, ...
    'elements', {[], [], xselectButton, [], [], ...
    [], [], [], [], [], ...
    label(2), [], [], xvaredit, [], ...
    [], [], removexButton});
editlyt = xreggridbaglayout(f, ...
    'dimension', [7 3], ...
    'rowsizes', [15 2 -1 10 2 10 42], ...
    'colsizes', [-1 65 -1], ...
    'gapx', 20, ...
    'border', [7 7 7 7], ...
    'mergeblock', {[3 7], [1 1]}, ...
    'mergeblock', {[1 3], [2 3]}, ...
    'mergeblock', {[5 5], [2 3]}, ...
    'mergeblock', {[7 7], [2 3]}, ...
    'elements', {label(3), [], allvariablesList, [], [], [], [], ...
    yselectlyt, [], [], [], div, [], xselectlyt});

dlg.Content = editlyt;

closeMode = dlg.showDialog();

%Implicit waifor on visible property!
OK = strcmp(closeMode,'OK');
if OK
    % Update the plot info
    ud = get(f,'UserData');
    ud.plot.yNames = get(ud.lists.y, 'String');
    ud.plot.xName  = get(ud.lists.x, 'String');
    
    if length(ud.plot.yNames)>1
        % turn on legend if there are more than one y variable
        ud.plot.properties.showLegend = 'on';
    else
        ud.plot.properties.showLegend = 'off';
    end
    
end
    
newPlot = ud.plot;
delete(dlg);

%--------------------------------------------------------------------------
% Callbacks
%--------------------------------------------------------------------------
function i_add(~, ~, dlg)
% get current vars from allvariables list and move to yvariables
% Get userdata
ud = get(dlg,'UserData');

% get selected values from all
selv = get(ud.lists.all, 'Value');
allstr = get(ud.lists.all, 'String');

if ~isempty(allstr)
    % Add selected variables to the y list
    set(ud.lists.y, 'String', sort([get(ud.lists.y, 'String') ; allstr(selv)]));
    
    % remove variables from all
    allstr(selv) = [];
    set(ud.lists.all, 'String', allstr, 'Value', 1);
end


%--------------------------------------------------------------------------
function i_remove(~, ~, dlg)
% remove current y vars
% Get userdata
ud = get(dlg,'UserData');

% Get selected values from y
selv = get(ud.lists.y, 'Value');
ystr = get(ud.lists.y, 'String');

if ~isempty(ystr)
    % Add selected variables to the all list
    set(ud.lists.all, 'String', sort([get(ud.lists.all, 'String') ; ystr(selv)]));
   
    % remove variables from y
    ystr(selv) = [];
    set(ud.lists.y, 'String', ystr, 'Value', 1);
end



%--------------------------------------------------------------------------
function i_xdata(~, ~, dlg)
% take current var into xvaredit
ud = get(dlg, 'UserData');

% Get first selected values from all
selv = get(ud.lists.all, 'Value');
selv = selv(1);
allstr = get(ud.lists.all, 'String');

if ~isempty(allstr)
    newXstr = allstr{selv};
    allstr(selv) = [];
    
    % Get old xstr
    oldXstr = get(ud.lists.x, 'String');
    if ~isempty(oldXstr)
        % Construct new all str
        allstr = sort([allstr ; {oldXstr}]);    
    end
    % Set all without newXstr and with oldXstr
    set(ud.lists.all, 'String', allstr, 'Value', 1);
    % Set newXstr
    set(ud.lists.x, 'String', newXstr);
    % Enable remove XData
    set(ud.buttons.xremove, 'Enable', 'on');
end

%--------------------------------------------------------------------------
function i_remove_x(~, ~, dlg)

ud = get(dlg,'UserData');

% get oldXstr
oldXstr = get(ud.lists.x, 'String');

if ~isempty(oldXstr)
    set(ud.lists.all, 'String', sort([get(ud.lists.all, 'String'); {oldXstr}]));
    
    % Ensure that this is a cell array
    set(ud.lists.x, 'String', '');
    % Disable remove XData
    set(ud.buttons.xremove, 'Enable', 'off');
end