www.gusucode.com > sloptim工具箱matlab源码程序 > sloptim/sloptguis/@srocsdgui/@requirementpnl/dataChanged.m

    function dataChanged(this,Src,Data,whatChanged)
% DATACHANGED  method to handle data changed callbacks for requirements
% panel
%

%Revisit: Method should be private but is called from within a callback 
%created in the constructor and needs to be public
 
% Author(s): A. Stothert 01-Sep-2005
% Copyright 2005 The MathWorks, Inc.

if nargin < 4, whatChanged = 'TableData'; end

h   = this.JavaHandle;        %Handle to java table
if strcmpi(whatChanged,'TableData')
   col = Data.JavaEvent.getColumn+1;       %Column changed
   row = Data.JavaEvent.getFirstRow+1;     %Single row select table so first==last
else
   %Tuned column header changed
   col = 1;
   row = 0;               %Header row;
end

%Compute useful Resp row indices
RespIdx    = double(h.getResponseIndices)+1;
isRespRow  = (row == RespIdx);
RespIdxIdx = row > RespIdx;

switch col
   case 1
      %Tuned check box changed, check if it was the header or a table row
      if(row==0)
         %Header changed, change response row settings
         for ct=1:numel(RespIdx)
            h.setData(h.getTunedColumnCheckBox.isSelected,RespIdx(ct),col);
         end
      else
         %Normal row changed,
         if any(isRespRow)
            %Is a response row need to set all 'Tuned' values for requirements below
            isRespRow = find(isRespRow);
            ct_start  = RespIdx(isRespRow)+1;  %First parameter below compensator
            if isRespRow+1 <= numel(RespIdx)
               ct_end = RespIdx(isRespRow+1)-1;
            else
               ct_end = Data.JavaEvent.getSource.getRowCount;
            end
            for ct = ct_start:ct_end
               value = h.getData(row,col);
               h.setData(value,ct,col);
               localSetDataObject(this,ct,value)
            end
         elseif ~any(isRespRow)
            %Dealing with a response row
            value = h.getData(row,col);
            if ~value
               %Need to make sure response known check box is off
               RespRow = RespIdx(find(RespIdxIdx,1,'last'));
               if h.getData(RespRow,col)
                  this.Listeners(1).Enabled = 'off';
                  h.setData(false,RespRow,col);
                  %h.repaint; %Force data set before reenabling listener
                  drawnow; %Force data set before reenabling listener
                  this.Listeners(1).Enabled = 'on';
               end
               if h.getTunedColumnCheckBox.isSelected
                  this.Listeners(2).Enabled = 'off';
                  h.setTunedColumnCheckBox(0);
                  %h.repaint; %Force data set before reenabling listener
                  drawnow; %Force data set before reenabling listener
                  this.Listeners(2).Enabled = 'on';
               end
            end
            %Update the data object
            localSetDataObject(this,row,value)
         end
      end
   otherwise
      %Do nothing
end

%--------------------------------------------------------------------------
function localSetDataObject(this,row,value)

h = this.JavaHandle;

%Compute useful Resp row indices
RespIdx    = double(h.getResponseIndices)+1;
RespIdxIdx = row > RespIdx;

%Retrive data object
requirementdata = this.Data;

if this.groupByResponse
   %Get requirement and response being changed
   reqName  = h.getData(row,3);
   reqName  = reqName(4:end);    %Strip out leading 'indent' space
   plotName = h.getData(row,2); 
   plotName = plotName(4:end);   %Strip out leading 'indent' space
   respName = h.getData(RespIdx(find(RespIdxIdx,1,'last')),2);
   
   Requirements = requirementdata.Requirements;
   ct    = 1;
   found = false;
   while ~found && ct <= numel(Requirements) 
      if strcmp(Requirements(ct).hGUI.describe('detail'),reqName) && ...
            strcmp(Requirements(ct).hView.Axes.Title,plotName)
         %Found potential requirement
         if (isa(Requirements(ct).hResp,'ctrlguis.csdesignerapp.data.responses.internal.Response') || ...
                 isa(Requirements(ct).hResp,'ctrlguis.csdesignerapp.data.architectures.internal.TunableBlock')) ...
             && strcmp(Requirements(ct).hResp.getName,respName)
            %Found requirement 
            this.Data.Requirements(ct).Tuned = value;
            found = true;
         end
      end
      %Increment counter if haven't found requirement
      if ~found, ct = ct + 1; end
   end
end