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

    function obj = lookup1editor(varargin)
%LOOKUP1EDITOR  Constructor for lookup1editor object
%
%  OBJ = LOOKUP1EDITOR(PROP, VALUE, ...)

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


if nargin && isa(varargin{1}, 'cgtools.lookup1editor')
    obj = varargin{1};
    varargin(1) = [];
else
    obj = cgtools.lookup1editor;
end

% Call the inherited constructor
abstractlayoutcomponent(obj, varargin{:});

wrapper = mbcgui.widget.AxesContainer(...
    'Parent',obj.Parent, ...
    'Visible', obj.Visible, ...
    'Border', [40 35 20 25]);
obj.Axes = wrapper.AxesHandle;
set(obj.Axes,'Position', [0 0 1 1], ...
    'Position', [0 0 1 1], ...
    'Box','on',...
    'XGrid', 'on', ...
    'YGrid', 'on');
set(get(obj.Axes,'XLabel'),'Interpreter','none');

uic = uicontextmenu('Parent',ancestor(obj.Parent,'figure'));
vmenu.PrintCopy = uimenu(uic, ...
    'Label', '&Print to Figure', ...
    'Callback', {@iPrintCopy, obj.Axes});

obj.ViewMenu = vmenu;
set(obj.Axes,'UIContextMenu', uic);


obj.Dragger = cgtools.cglinedragger('Parent', obj.Axes);

P = com.mathworks.toolbox.mbc.gui.peer.LookupTablePeer;
obj.Table = mbcwidgets.Table2D(P, ...
    'parent',obj.Parent, ...
    'visible', obj.Visible, ...
    'Position', [0 0 1 1], ...
    'Editable', true, ...
    'UIContextMenu', obj.TableContextMenu, ...
    'SelectionChangedCallback',{@i_SelectionChanged,obj.Dragger},...
    'ValueChangedCallback', {@i_EditCallback, obj, obj.Dragger});
obj.Table.Peer.setShowRegionMask(false);

obj.Display = xregsnapsplitlayout(obj.Parent,...
    'visible', obj.Visible, ...
    'position', obj.Position, ...
    'orientation','ud',...
    'split',[0.3 0.7], ...
    'barstyle', 1, ...
    'style', 'tobottom', ...
    'elements',{obj.Table,wrapper});

obj.addPropertyListeners('TableContextMenu', {@i_settablecontext, obj.Table});
obj.addListeners([...
    handle.listener(obj.Dragger,'PointGrab', {@i_PointGrab, obj.Table}); ...
    handle.listener(obj.Dragger,'PointDrag', {@i_PointDrag, obj.Table}); ...
    handle.listener(obj.Dragger,'Update', {@i_PointUpdate, obj, obj.Table}); ...
    ]);


function i_settablecontext(~, evt, hTable)
hTable.UIContextMenu = evt.NewValue;


function i_EditCallback(table, eventdata, obj, hDragger)
if length(eventdata.data.NewValue)>1
    % Paste event
    i_changevalue(obj, eventdata.data.Rows, eventdata.data.NewValue, table, hDragger, 'Paste Operation');
else
    i_changevalue(obj, eventdata.data.Rows, eventdata.data.NewValue, table, hDragger, 'Manual edit');
end

function i_SelectionChanged(~,evt,hDragger)

setTableData(hDragger, hDragger.XData, hDragger.YData, hDragger.LockData,evt.data.SelectedRows)


function i_PointGrab(~, evt, hTable)
hTable.selectCell(evt.data.DragIndex, 2);

function i_PointDrag(~, evt, hTable)
hTable.Peer.setTableDataAt(evt.data.DragIndex-1, 0, evt.data.DragValue);

function i_PointUpdate(src, evt, obj, hTable)
i_changevalue(obj, evt.data.ChangedIndex, evt.data.NewValue, hTable, src, 'Manual edit using graph');



function i_changevalue(obj, idx, newval, hTable, hDragger, ChangeString)
T = obj.TablePtr;
tbl = T.info;

table_data = get(tbl, 'values');
if all(table_data(idx)==newval | (isnan(table_data(idx)) & isnan(newval)))
    % Data has not been altered
    return
end

new_table_data = table_data;
new_table_data(idx) = newval;
tbl = set(tbl, 'values', {new_table_data, ChangeString});

% Use the table-filtered values for updating
new_table_data = get(tbl, 'values');

% Always update the line and table with the table-filtered values
hDragger.YData = new_table_data;
set(hDragger.Parent, 'YLim', mbcmakelimits(new_table_data, 'loose'));
hTable.Peer.setTableData(new_table_data);

if all(table_data(idx)==new_table_data(idx) ...
        | (isnan(table_data(idx)) & isnan(new_table_data(idx))))
    % The set operation filtered the value back to the original, so don't
    % record any change
    return
end

% Update table pointer
T.info = tbl;

% Send a change event
send(obj,'ValuesChanged', handle.EventData(obj, 'ValuesChanged') );


function iPrintCopy(~,~,hAxes)

f = figure;
ax = copyobj(hAxes,f);
set(ax,'Units','Normalized',...
    'Position',[0.1300 0.1100 0.7750 0.8150],...
    'UIContextMenu',[],...
    'ButtonDownFcn',[]);

set(findobj(ax),'ButtonDownFcn',[]);