function edit(h,parent)

%% Opens the editor dialog box which defines this M logging session

import com.mathworks.toolbox.timeseries.*;

if isempty(h.Dialog)
    jf = get(parent, 'JavaFrame');
    if ~isempty(jf)
        jframe = javax.swing.SwingUtilities.getWindowAncestor(jf.getAxisComponent);
    else
        errordlg('Java Figures must be enabled for this dialog to open',...
            'Time Series Tool','modal')
        return
    end
    h.Dialog = macroRecorder(jframe);
    % Define the start and stop button callbacks
    set(handle(h.Dialog.BTNStart,'callbackproperties'), ...
        'actionperformedcallback',{@localGetJavaProps h});
    set(handle(h.Dialog.BTNStop,'callbackproperties'), ...
        'actionperformedcallback',{@localStopLogging h})
end
awtinvoke(h.Dialog,'setVisible(Z)',true)


function localGetJavaProps(es,ed,h)

%% Synch the @recorder props to the java dialog
try
    set(h,'Filename',char(h.Dialog.COMBMfile.getSelectedItem),'Path',...
        char(h.Dialog.TXTpath.getText));
catch
    errordlg('Invalid file or pathname','Time Series Tool','modal')
    return
end

%% Open the file to make sure that the logging will not fail for file
%% access reasons
filepath = fullfile(h.Path,h.Filename);
mfilepath = sprintf('%s.m',filepath);
[fid,msg] = fopen(mfilepath,'wt');
if ~isempty(msg)
    errordlg('Cannot open the specified file for write',...
        'Time Series Tool','modal')
    return
else
    fclose(fid);
end

%% Put the java dialog into the logging state
h.Recording = 'on';
awtinvoke(h.Dialog,'startLogging');

function localStopLogging(es,ed,h)

%% Stop logging callback - turns off logging and writes the data to file

%% Set the dialog state
awtinvoke(h.Dialog,'stopLogging');

%% Write the data
h.write

%% Clear logging status
set(h,'Saveddata','off','Recording','off','Tsnames',{});