Sie sind auf Seite 1von 3

function setup(block)

%% Register a single dialog parameter


block.NumDialogPrms = 1 ;
%% Register number of input and output ports
block.NumInputPorts = 1 ;
block.NumOutputPorts = 1 ;
%% Setup functional port properties to dynamically
%% inherited.
block.SetPreCompInpPortInfoToDynamic; block.SetPreCompOutPortInfoToDynamic;
%% Hard-code certain port properties
block.InputPort(1).Dimensions = 1 ;
block.InputPort(1).DirectFeedthrough = false
block.OutputPort(1).Dimensions = 1;
%% Set block sample time to inherited
block.SampleTimes = [0.1 0] ;
%% Register methods
block.RegBlockMethod('PostPropagationSetup',@DoPostPropSetup);
block.RegBlockMethod('InitializeConditions',@InitConditions);
block.RegBlockMethod('Outputs', @Output);
block.RegBlockMethod('Update', @Update);
function addCallbacks(this)
% ADDCALLBACKS Add Java related callbacks

% Author(s): Bora Eryilmaz


% Revised:
% Copyright 2000-2011 The MathWorks, Inc.
% $Revision: 1.1.6.12 $ $Date: 2011/08/09 19:05:20 $

% Add event listeners


h = handle( this.Explorer, 'callbackproperties' );
h.WindowClosingCallback = { @LocalWindowClosing, this };

h = handle( this.ExplorerPanel.getSelector, 'callbackproperties' );


h.SelectionChangedCallback = { @LocalSelectionChanged, this };
h.PopupTriggeredCallback = { @LocalPopupTriggered, this };

% ---------------------------------------------------------------------------- %
function LocalWindowClosing(~, ~, this)
% Do not allow closing the Explorer when the manager is busy; for example,
% when an estimation is running.
if this.isBusy
msg = getString(message('SLControllib:explorer:msgApplicationBusy'));
dlg = errordlg( msg, char(this.Explorer.getTitle), 'modal' );
% In case the dialog is closed before uiwait blocks MATLAB.
if ishandle(dlg)
uiwait(dlg)
end
return
end

% Force the focus to the frame so that ant focusloast events are processed
% before the save and none of the focuslost callbacks will fire after nodes
% have been deleted
this.Explorer.requestFocus
drawnow

% Get the children of the workspace


children = this.Root.getChildren;
for k = 1:length(children)
abortFlag = LocalSaveProject(this, children(k));
if abortFlag
return;
end
end

% Remove all children


for k = length(children):-1:1
this.Root.removeNode( children(k) );
end

% Clean up
drawnow
this.delete;

% ---------------------------------------------------------------------------- %
function abortFlag = LocalSaveProject(this, node)
abortFlag = false;
if node.Dirty
msg = getString(message('SLControllib:explorer:msgSaveChanges',node.Label));
selection = questdlg(msg, ...
getString(message('SLControllib:explorer:lblSaveProject')), ...
getString(message('SLControllib:explorer:lblYes')), ...
getString(message('SLControllib:explorer:lblNo')), ...
getString(message('SLControllib:explorer:lblCancel')), ...
getString(message('SLControllib:explorer:lblYes')));

switch selection
case getString(message('SLControllib:explorer:lblYes'))
this.saveas(node, true)
case getString(message('SLControllib:explorer:lblNo'))
% no action
case getString(message('SLControllib:explorer:lblCancel'))
abortFlag = true;
end
end

% ---------------------------------------------------------------------------- %
function LocalPopupTriggered(~, hData, this)
h = handle( hData.getNode.getObject );
e = hData.getEvent;

popup = h.getPopupInterface( this );


if ~isempty(popup) && ~this.Explorer.getGlassPane.isVisible
awtinvoke( popup, 'show(Ljava/awt/Component;II)', ...
hData.getSource, e.getX, e.getY );
popup.repaint;
end

% ---------------------------------------------------------------------------- %
function LocalSelectionChanged(~, hData, this)
h = handle( hData.getNode.getObject );
ExplorerPanel = this.ExplorerPanel;
Explorer = this.Explorer;

% Set explorer components


[menubar, toolbar] = getMenuToolBarInterface( h.getRoot, this );
Explorer.setExplorerComponents( menubar, toolbar, h.Status );
% Block all inputs (mouse & keyboard) to CETM GUI. No active component is set.
Explorer.setBlocked(true, []);

try
% Get the panel
Panel = getDialogInterface( h, this );
catch E
util = slcontrol.Utilities;
beep;

% Thread-safe message dialog.


awtinvoke('javax.swing.JOptionPane', ...

'showMessageDialog(Ljava/awt/Component;Ljava/lang/Object;Ljava/lang/String;I)', ...
Explorer, util.getLastError(E), ...
getString(message('SLControllib:explorer:errToolsManager')), ...
javax.swing.JOptionPane.WARNING_MESSAGE);
Panel = com.mathworks.mwswing.MJPanel;
end

% Set the panel


ExplorerPanel.getDisplayer.setDialog( Panel );

% Allow all inputs (mouse & keyboard) to CETM GUI.


Explorer.setBlocked(false, []);

Das könnte Ihnen auch gefallen